libMesh
optimization_system.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 
51  const std::string & name,
52  const unsigned int number);
53 
59  OptimizationSystem (const OptimizationSystem &) = delete;
63  virtual ~OptimizationSystem ();
64 
69 
74 
80  {
81  public:
82  virtual ~ComputeObjective () = default;
83 
91  virtual Number objective (const NumericVector<Number> & X,
92  sys_type & S) = 0;
93  };
94 
95 
101  {
102  public:
103  virtual ~ComputeGradient () = default;
104 
111  virtual void gradient (const NumericVector<Number> & X,
112  NumericVector<Number> & grad_f,
113  sys_type & S) = 0;
114  };
115 
116 
122  {
123  public:
124  virtual ~ComputeHessian () = default;
125 
132  virtual void hessian (const NumericVector<Number> & X,
133  SparseMatrix<Number> & H_f,
134  sys_type & S) = 0;
135  };
136 
141  {
142  public:
143  virtual ~ComputeEqualityConstraints () = default;
144 
149  virtual void equality_constraints (const NumericVector<Number> & X,
151  sys_type & S) = 0;
152  };
153 
159  {
160  public:
161  virtual ~ComputeEqualityConstraintsJacobian () = default;
162 
168  sys_type & S) = 0;
169  };
170 
175  {
176  public:
177  virtual ~ComputeInequalityConstraints () = default;
178 
183  virtual void inequality_constraints (const NumericVector<Number> & X,
185  sys_type & S) = 0;
186  };
187 
193  {
194  public:
195  virtual ~ComputeInequalityConstraintsJacobian () = default;
196 
202  sys_type & S) = 0;
203  };
204 
210  {
211  public:
212  virtual ~ComputeLowerAndUpperBounds () = default;
213 
219  virtual void lower_and_upper_bounds (sys_type & S) = 0;
220  };
221 
225  sys_type & system () { return *this; }
226 
231  virtual void clear () override;
232 
236  virtual void init_data () override;
237 
242  virtual void reinit () override;
243 
247  virtual void solve () override;
248 
256  void initialize_equality_constraints_storage(const std::vector<std::set<numeric_index_type>> & constraint_jac_sparsity);
257 
262  void initialize_inequality_constraints_storage(const std::vector<std::set<numeric_index_type>> & constraint_jac_sparsity);
263 
268  virtual std::string system_type () const override { return "Optimization"; }
269 
273  std::unique_ptr<OptimizationSolver<Number>> optimization_solver;
274 
278  std::unique_ptr<NumericVector<Number>> C_eq;
279 
283  std::unique_ptr<SparseMatrix<Number>> C_eq_jac;
284 
288  std::unique_ptr<NumericVector<Number>> C_ineq;
289 
293  std::unique_ptr<SparseMatrix<Number>> C_ineq_jac;
294 
299  std::unique_ptr<NumericVector<Number>> lambda_eq;
300  std::unique_ptr<NumericVector<Number>> lambda_ineq;
301 
306  std::vector<std::set<numeric_index_type>> eq_constraint_jac_sparsity;
307  std::vector<std::set<numeric_index_type>> ineq_constraint_jac_sparsity;
308 };
309 
310 } // namespace libMesh
311 
312 #endif // LIBMESH_OPTIMIZATION_SYSTEM_H
Abstract base class to be used to calculate the inequality constraints.
This is the EquationSystems class.
OptimizationSystem sys_type
The type of system.
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.
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...
Abstract base class to be used to calculate the objective function for optimization.
std::unique_ptr< NumericVector< Number > > lambda_ineq
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...
ImplicitSystem Parent
The type of the parent.
virtual void solve() override
Solves the optimization problem.
virtual void init_data() override
Initializes new data members of the system.
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).
std::unique_ptr< NumericVector< Number > > C_eq
The vector that stores equality constraints.
The libMesh namespace provides an interface to certain functionality in the library.
std::unique_ptr< SparseMatrix< Number > > C_ineq_jac
The sparse matrix that stores the Jacobian of C_ineq.
virtual std::string system_type() const override
unsigned int number() const
Definition: system.h:2269
Abstract base class to be used to calculate the equality constraints.
OptimizationSystem & operator=(const OptimizationSystem &)=delete
This System subclass enables us to assemble an objective function, gradient, Hessian and bounds for o...
virtual void reinit() override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
std::vector< std::set< numeric_index_type > > ineq_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.
std::unique_ptr< SparseMatrix< Number > > C_eq_jac
The sparse matrix that stores the Jacobian of C_eq.
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). ...
std::unique_ptr< OptimizationSolver< Number > > optimization_solver
The OptimizationSolver that is used for performing the optimization.
std::unique_ptr< NumericVector< Number > > lambda_eq
Vectors to store the dual variables associated with equality and inequality constraints.
virtual void lower_and_upper_bounds(sys_type &S)=0
This function should update the following two vectors: this->get_vector("lower_bounds"), this->get_vector("upper_bounds").
Abstract base class to be used to calculate the gradient of an objective function.
Abstract base class to be used to calculate the Jacobian of the equality constraints.
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...
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).
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.
Abstract base class to be used to calculate the Hessian of an objective function. ...
virtual void clear() override
Clear all the data structures associated with the system.
const std::string & name() const
Definition: system.h:2261
OptimizationSystem(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
Abstract base class to be used to calculate the lower and upper bounds for all dofs in the system...
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).
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...
std::unique_ptr< NumericVector< Number > > C_ineq
The vector that stores inequality constraints.
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...
Abstract base class to be used to calculate the Jacobian of the inequality constraints.