libMesh
Loading...
Searching...
No Matches
optimization_system.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
28namespace libMesh
29{
30
31
32// Forward declarations
33template<typename T> class OptimizationSolver;
34
35
44{
45public:
46
51 const std::string & name,
52 const unsigned int number);
53
64
69
74
80 {
81 public:
82 virtual ~ComputeObjective () = default;
83
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,
134 sys_type & S) = 0;
135 };
136
141 {
142 public:
143 virtual ~ComputeEqualityConstraints () = default;
144
151 sys_type & S) = 0;
152 };
153
170
175 {
176 public:
177 virtual ~ComputeInequalityConstraints () = default;
178
185 sys_type & S) = 0;
186 };
187
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
This is the EquationSystems class.
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
Abstract base class to be used to calculate the Jacobian of the equality constraints.
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).
Abstract base class to be used to calculate the 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).
Abstract base class to be used to calculate the gradient of an objective function.
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 Hessian of an objective function.
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...
Abstract base class to be used to calculate the Jacobian of the inequality constraints.
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).
Abstract base class to be used to calculate the 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).
Abstract base class to be used to calculate the lower and upper bounds for all dofs in the system.
virtual void lower_and_upper_bounds(sys_type &S)=0
This function should update the following two vectors: this->get_vector("lower_bounds"),...
Abstract base class to be used to calculate the objective function for optimization.
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...
This System subclass enables us to assemble an objective function, gradient, Hessian and bounds for o...
std::unique_ptr< NumericVector< Number > > C_ineq
The vector that stores inequality constraints.
OptimizationSystem sys_type
The type of system.
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.
std::unique_ptr< NumericVector< Number > > lambda_ineq
virtual void solve() override
Solves the optimization problem.
std::vector< std::set< numeric_index_type > > eq_constraint_jac_sparsity
A copy of the equality and inequality constraint Jacobian sparsity patterns.
std::vector< std::set< numeric_index_type > > ineq_constraint_jac_sparsity
std::unique_ptr< SparseMatrix< Number > > C_eq_jac
The sparse matrix that stores the Jacobian of C_eq.
std::unique_ptr< NumericVector< Number > > C_eq
The vector that stores equality constraints.
virtual void reinit() override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
OptimizationSystem & operator=(const OptimizationSystem &)=delete
OptimizationSystem(const OptimizationSystem &)=delete
Special functions.
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.
std::unique_ptr< SparseMatrix< Number > > C_ineq_jac
The sparse matrix that stores the Jacobian of C_ineq.
OptimizationSystem(OptimizationSystem &&)=default
virtual void init_data() override
Initializes new data members of the system.
std::unique_ptr< NumericVector< Number > > lambda_eq
Vectors to store the dual variables associated with equality and inequality constraints.
virtual void clear() override
Clear all the data structures associated with the system.
virtual std::string system_type() const override
std::unique_ptr< OptimizationSolver< Number > > optimization_solver
The OptimizationSolver that is used for performing the optimization.
ImplicitSystem Parent
The type of the parent.
Generic sparse matrix.
const std::string & name() const
Definition system.h:2385
unsigned int number() const
Definition system.h:2393
The libMesh namespace provides an interface to certain functionality in the library.