libMesh
optimization_system.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_OPTIMIZATION_SYSTEM_H
21 #define LIBMESH_OPTIMIZATION_SYSTEM_H
22 
23 // Local Includes
24 #include "libmesh/implicit_system.h"
25 
26 // C++ includes
27 
28 namespace libMesh
29 {
30 
31 
32 // Forward declarations
33 template<typename T> class OptimizationSolver;
34 
35 
44 {
45 public:
46 
52  const std::string & name,
53  const unsigned int number);
54 
58  virtual ~OptimizationSystem ();
59 
64 
69 
75  {
76  public:
77  virtual ~ComputeObjective () {}
78 
86  virtual Number objective (const NumericVector<Number> & X,
87  sys_type & S) = 0;
88  };
89 
90 
96  {
97  public:
98  virtual ~ComputeGradient () {}
99 
106  virtual void gradient (const NumericVector<Number> & X,
107  NumericVector<Number> & grad_f,
108  sys_type & S) = 0;
109  };
110 
111 
117  {
118  public:
119  virtual ~ComputeHessian () {}
120 
127  virtual void hessian (const NumericVector<Number> & X,
128  SparseMatrix<Number> & H_f,
129  sys_type & S) = 0;
130  };
131 
136  {
137  public:
139 
144  virtual void equality_constraints (const NumericVector<Number> & X,
146  sys_type & S) = 0;
147  };
148 
154  {
155  public:
157 
163  sys_type & S) = 0;
164  };
165 
170  {
171  public:
173 
178  virtual void inequality_constraints (const NumericVector<Number> & X,
180  sys_type & S) = 0;
181  };
182 
188  {
189  public:
191 
197  sys_type & S) = 0;
198  };
199 
205  {
206  public:
208 
214  virtual void lower_and_upper_bounds (sys_type & S) = 0;
215  };
216 
220  sys_type & system () { return *this; }
221 
226  virtual void clear () override;
227 
231  virtual void init_data () override;
232 
237  virtual void reinit () override;
238 
242  virtual void solve () override;
243 
251  void initialize_equality_constraints_storage(const std::vector<std::set<numeric_index_type>> & constraint_jac_sparsity);
252 
257  void initialize_inequality_constraints_storage(const std::vector<std::set<numeric_index_type>> & constraint_jac_sparsity);
258 
263  virtual std::string system_type () const override { return "Optimization"; }
264 
268  std::unique_ptr<OptimizationSolver<Number>> optimization_solver;
269 
273  std::unique_ptr<NumericVector<Number>> C_eq;
274 
278  std::unique_ptr<SparseMatrix<Number>> C_eq_jac;
279 
283  std::unique_ptr<NumericVector<Number>> C_ineq;
284 
288  std::unique_ptr<SparseMatrix<Number>> C_ineq_jac;
289 
294  std::unique_ptr<NumericVector<Number>> lambda_eq;
295  std::unique_ptr<NumericVector<Number>> lambda_ineq;
296 
301  std::vector<std::set<numeric_index_type>> eq_constraint_jac_sparsity;
302  std::vector<std::set<numeric_index_type>> ineq_constraint_jac_sparsity;
303 };
304 
305 } // namespace libMesh
306 
307 #endif // LIBMESH_OPTIMIZATION_SYSTEM_H
libMesh::OptimizationSystem
This System subclass enables us to assemble an objective function, gradient, Hessian and bounds for o...
Definition: optimization_system.h:43
libMesh::OptimizationSystem::sys_type
OptimizationSystem sys_type
The type of system.
Definition: optimization_system.h:63
libMesh::OptimizationSystem::C_ineq
std::unique_ptr< NumericVector< Number > > C_ineq
The vector that stores inequality constraints.
Definition: optimization_system.h:283
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::OptimizationSystem::initialize_inequality_constraints_storage
void initialize_inequality_constraints_storage(const std::vector< std::set< numeric_index_type >> &constraint_jac_sparsity)
Initialize storage for the inequality constraints, as per initialize_equality_constraints_storage.
Definition: optimization_system.C:127
libMesh::OptimizationSystem::ComputeEqualityConstraintsJacobian::equality_constraints_jacobian
virtual void equality_constraints_jacobian(const NumericVector< Number > &X, SparseMatrix< Number > &C_eq_jac, sys_type &S)=0
This function will be called to evaluate the Jacobian of C_eq(X).
libMesh::OptimizationSystem::OptimizationSystem
OptimizationSystem(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
Definition: optimization_system.C:36
libMesh::ImplicitSystem
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...
Definition: implicit_system.h:57
libMesh::OptimizationSystem::ComputeHessian::hessian
virtual void hessian(const NumericVector< Number > &X, SparseMatrix< Number > &H_f, sys_type &S)=0
This function will be called to compute the Hessian of the objective function, and must be implemente...
libMesh::OptimizationSystem::ComputeInequalityConstraintsJacobian
Abstract base class to be used to calculate the Jacobian of the inequality constraints.
Definition: optimization_system.h:187
libMesh::OptimizationSystem::Parent
ImplicitSystem Parent
The type of the parent.
Definition: optimization_system.h:68
libMesh::OptimizationSystem::solve
virtual void solve() override
Solves the optimization problem.
Definition: optimization_system.C:162
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::OptimizationSystem::ComputeInequalityConstraints
Abstract base class to be used to calculate the inequality constraints.
Definition: optimization_system.h:169
libMesh::OptimizationSystem::ComputeObjective::~ComputeObjective
virtual ~ComputeObjective()
Definition: optimization_system.h:77
libMesh::OptimizationSystem::ComputeEqualityConstraintsJacobian::~ComputeEqualityConstraintsJacobian
virtual ~ComputeEqualityConstraintsJacobian()
Definition: optimization_system.h:156
libMesh::OptimizationSystem::ComputeHessian
Abstract base class to be used to calculate the Hessian of an objective function.
Definition: optimization_system.h:116
libMesh::System::number
unsigned int number() const
Definition: system.h:2075
libMesh::OptimizationSystem::init_data
virtual void init_data() override
Initializes new data members of the system.
Definition: optimization_system.C:71
libMesh::OptimizationSystem::system_type
virtual std::string system_type() const override
Definition: optimization_system.h:263
libMesh::OptimizationSystem::ComputeHessian::~ComputeHessian
virtual ~ComputeHessian()
Definition: optimization_system.h:119
libMesh::OptimizationSystem::lambda_ineq
std::unique_ptr< NumericVector< Number > > lambda_ineq
Definition: optimization_system.h:295
libMesh::SparseMatrix< Number >
libMesh::NumericVector< Number >
libMesh::OptimizationSystem::C_eq
std::unique_ptr< NumericVector< Number > > C_eq
The vector that stores equality constraints.
Definition: optimization_system.h:273
libMesh::OptimizationSystem::ComputeEqualityConstraints
Abstract base class to be used to calculate the equality constraints.
Definition: optimization_system.h:135
libMesh::OptimizationSystem::ComputeLowerAndUpperBounds
Abstract base class to be used to calculate the lower and upper bounds for all dofs in the system.
Definition: optimization_system.h:204
libMesh::OptimizationSystem::system
sys_type & system()
Definition: optimization_system.h:220
libMesh::OptimizationSystem::ComputeGradient::gradient
virtual void gradient(const NumericVector< Number > &X, NumericVector< Number > &grad_f, sys_type &S)=0
This function will be called to compute the gradient of the objective function, and must be implement...
libMesh::OptimizationSystem::C_ineq_jac
std::unique_ptr< SparseMatrix< Number > > C_ineq_jac
The sparse matrix that stores the Jacobian of C_ineq.
Definition: optimization_system.h:288
libMesh::OptimizationSystem::ComputeEqualityConstraintsJacobian
Abstract base class to be used to calculate the Jacobian of the equality constraints.
Definition: optimization_system.h:153
libMesh::OptimizationSystem::ComputeLowerAndUpperBounds::~ComputeLowerAndUpperBounds
virtual ~ComputeLowerAndUpperBounds()
Definition: optimization_system.h:207
libMesh::OptimizationSystem::optimization_solver
std::unique_ptr< OptimizationSolver< Number > > optimization_solver
The OptimizationSolver that is used for performing the optimization.
Definition: optimization_system.h:268
libMesh::OptimizationSystem::ComputeLowerAndUpperBounds::lower_and_upper_bounds
virtual void lower_and_upper_bounds(sys_type &S)=0
This function should update the following two vectors: this->get_vector("lower_bounds"),...
libMesh::OptimizationSystem::ineq_constraint_jac_sparsity
std::vector< std::set< numeric_index_type > > ineq_constraint_jac_sparsity
Definition: optimization_system.h:302
libMesh::OptimizationSystem::ComputeObjective::objective
virtual Number objective(const NumericVector< Number > &X, sys_type &S)=0
This function will be called to compute the objective function to be minimized, and must be implement...
libMesh::OptimizationSystem::C_eq_jac
std::unique_ptr< SparseMatrix< Number > > C_eq_jac
The sparse matrix that stores the Jacobian of C_eq.
Definition: optimization_system.h:278
libMesh::OptimizationSystem::reinit
virtual void reinit() override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
Definition: optimization_system.C:82
libMesh::OptimizationSystem::ComputeObjective
Abstract base class to be used to calculate the objective function for optimization.
Definition: optimization_system.h:74
libMesh::OptimizationSystem::ComputeInequalityConstraintsJacobian::inequality_constraints_jacobian
virtual void inequality_constraints_jacobian(const NumericVector< Number > &X, SparseMatrix< Number > &C_ineq_jac, sys_type &S)=0
This function will be called to evaluate the Jacobian of C_ineq(X).
libMesh::OptimizationSystem::ComputeGradient
Abstract base class to be used to calculate the gradient of an objective function.
Definition: optimization_system.h:95
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::OptimizationSystem::eq_constraint_jac_sparsity
std::vector< std::set< numeric_index_type > > eq_constraint_jac_sparsity
A copy of the equality and inequality constraint Jacobian sparsity patterns.
Definition: optimization_system.h:301
libMesh::OptimizationSystem::initialize_equality_constraints_storage
void initialize_equality_constraints_storage(const std::vector< std::set< numeric_index_type >> &constraint_jac_sparsity)
Initialize storage for the equality constraints, and the corresponding Jacobian.
Definition: optimization_system.C:91
libMesh::ExplicitSystem
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
Definition: explicit_system.h:48
libMesh::OptimizationSystem::ComputeEqualityConstraints::equality_constraints
virtual void equality_constraints(const NumericVector< Number > &X, NumericVector< Number > &C_eq, sys_type &S)=0
This function will be called to evaluate the equality constraints vector C_eq(X).
libMesh::OptimizationSystem::lambda_eq
std::unique_ptr< NumericVector< Number > > lambda_eq
Vectors to store the dual variables associated with equality and inequality constraints.
Definition: optimization_system.h:294
libMesh::System::name
const std::string & name() const
Definition: system.h:2067
libMesh::OptimizationSystem::ComputeGradient::~ComputeGradient
virtual ~ComputeGradient()
Definition: optimization_system.h:98
libMesh::OptimizationSystem::ComputeInequalityConstraints::~ComputeInequalityConstraints
virtual ~ComputeInequalityConstraints()
Definition: optimization_system.h:172
libMesh::OptimizationSystem::ComputeInequalityConstraintsJacobian::~ComputeInequalityConstraintsJacobian
virtual ~ComputeInequalityConstraintsJacobian()
Definition: optimization_system.h:190
libMesh::OptimizationSystem::ComputeInequalityConstraints::inequality_constraints
virtual void inequality_constraints(const NumericVector< Number > &X, NumericVector< Number > &C_ineq, sys_type &S)=0
This function will be called to evaluate the equality constraints vector C_ineq(X).
libMesh::OptimizationSystem::ComputeEqualityConstraints::~ComputeEqualityConstraints
virtual ~ComputeEqualityConstraints()
Definition: optimization_system.h:138
libMesh::OptimizationSystem::clear
virtual void clear() override
Clear all the data structures associated with the system.
Definition: optimization_system.C:61
libMesh::OptimizationSystem::~OptimizationSystem
virtual ~OptimizationSystem()
Destructor.
Definition: optimization_system.C:53