libMesh
Public Member Functions | Public Attributes | Private Attributes | List of all members
AssembleOptimization Class Referenceabstract

This class encapsulate all functionality required for assembling the objective function, gradient, and hessian. More...

Inheritance diagram for AssembleOptimization:
[legend]

Public Member Functions

 AssembleOptimization (OptimizationSystem &sys_in)
 Constructor. More...
 
void assemble_A_and_F ()
 The optimization problem we consider here is: min_U 0.5*U^T A U - U^T F. More...
 
virtual Number objective (const NumericVector< Number > &soln, OptimizationSystem &)
 Evaluate the objective function. More...
 
virtual void gradient (const NumericVector< Number > &soln, NumericVector< Number > &grad_f, OptimizationSystem &)
 Evaluate the gradient. More...
 
virtual void hessian (const NumericVector< Number > &soln, SparseMatrix< Number > &H_f, OptimizationSystem &)
 Evaluate the Hessian. More...
 
 AssembleOptimization (OptimizationSystem &sys_in)
 Constructor. More...
 
void assemble_A_and_F ()
 The optimization problem we consider here is: min_U 0.5*U^T A U - U^T F. More...
 
virtual Number objective (const NumericVector< Number > &soln, OptimizationSystem &)
 Evaluate the objective function. More...
 
virtual void gradient (const NumericVector< Number > &soln, NumericVector< Number > &grad_f, OptimizationSystem &)
 Evaluate the gradient. More...
 
virtual void hessian (const NumericVector< Number > &soln, SparseMatrix< Number > &H_f, OptimizationSystem &)
 Evaluate the Hessian. More...
 
virtual void equality_constraints (const NumericVector< Number > &X, NumericVector< Number > &C_eq, OptimizationSystem &)
 Evaluate the equality constraints. More...
 
virtual void equality_constraints_jacobian (const NumericVector< Number > &X, SparseMatrix< Number > &C_eq_jac, OptimizationSystem &)
 Evaluate the equality constraints Jacobian. More...
 
virtual void inequality_constraints (const NumericVector< Number > &X, NumericVector< Number > &C_ineq, OptimizationSystem &)
 Evaluate the inequality constraints. More...
 
virtual void inequality_constraints_jacobian (const NumericVector< Number > &X, SparseMatrix< Number > &C_ineq_jac, OptimizationSystem &)
 Evaluate the inequality constraints Jacobian. More...
 
virtual void lower_and_upper_bounds (OptimizationSystem &sys)
 Evaluate the lower and upper bounds vectors. More...
 
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 implemented by the user in a derived class. More...
 
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 implemented by the user in a derived class. More...
 
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 implemented by the user in a derived class. More...
 
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). More...
 
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). More...
 
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). More...
 
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). More...
 
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"). More...
 

Public Attributes

SparseMatrix< Number > * A_matrix
 Sparse matrix for storing the matrix A. More...
 
NumericVector< Number > * F_vector
 Vector for storing F. More...
 

Private Attributes

OptimizationSystem_sys
 Keep a reference to the OptimizationSystem. More...
 

Detailed Description

This class encapsulate all functionality required for assembling the objective function, gradient, and hessian.

This class encapsulate all functionality required for assembling the objective function, gradient, hessian, and constraints.

Definition at line 66 of file optimization_ex1.C.

Constructor & Destructor Documentation

◆ AssembleOptimization() [1/2]

AssembleOptimization::AssembleOptimization ( OptimizationSystem sys_in)

Constructor.

Definition at line 126 of file optimization_ex1.C.

126  :
127  _sys(sys_in)
128 {}
OptimizationSystem & _sys
Keep a reference to the OptimizationSystem.

◆ AssembleOptimization() [2/2]

AssembleOptimization::AssembleOptimization ( OptimizationSystem sys_in)

Constructor.

Member Function Documentation

◆ assemble_A_and_F() [1/2]

void AssembleOptimization::assemble_A_and_F ( )

The optimization problem we consider here is: min_U 0.5*U^T A U - U^T F.

In this method, we assemble A and F.

Definition at line 130 of file optimization_ex1.C.

References _sys, A_matrix, libMesh::SparseMatrix< T >::add_matrix(), libMesh::NumericVector< T >::add_vector(), libMesh::NumericVector< T >::close(), libMesh::SparseMatrix< T >::close(), libMesh::DofMap::constrain_element_matrix_and_vector(), libMesh::FEType::default_quadrature_order(), dim, libMesh::DofMap::dof_indices(), F_vector, libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::DofMap::is_constrained_dof(), mesh, libMesh::MeshBase::mesh_dimension(), libMesh::DenseVector< T >::resize(), libMesh::DenseMatrix< T >::resize(), libMesh::System::variable_number(), libMesh::DofMap::variable_type(), libMesh::NumericVector< T >::zero(), and libMesh::SparseMatrix< T >::zero().

Referenced by main().

131 {
132  A_matrix->zero();
133  F_vector->zero();
134 
135  const MeshBase & mesh = _sys.get_mesh();
136 
137  const unsigned int dim = mesh.mesh_dimension();
138  const unsigned int u_var = _sys.variable_number ("u");
139 
140  const DofMap & dof_map = _sys.get_dof_map();
141  FEType fe_type = dof_map.variable_type(u_var);
142  std::unique_ptr<FEBase> fe (FEBase::build(dim, fe_type));
143  QGauss qrule (dim, fe_type.default_quadrature_order());
144  fe->attach_quadrature_rule (&qrule);
145 
146  const std::vector<Real> & JxW = fe->get_JxW();
147  const std::vector<std::vector<Real>> & phi = fe->get_phi();
148  const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
149 
150  std::vector<dof_id_type> dof_indices;
151 
154 
155  for (const auto & elem : mesh.active_local_element_ptr_range())
156  {
157  dof_map.dof_indices (elem, dof_indices);
158 
159  const unsigned int n_dofs = dof_indices.size();
160 
161  fe->reinit (elem);
162 
163  Ke.resize (n_dofs, n_dofs);
164  Fe.resize (n_dofs);
165 
166  for (unsigned int qp=0; qp<qrule.n_points(); qp++)
167  {
168  for (unsigned int dof_i=0; dof_i<n_dofs; dof_i++)
169  {
170  for (unsigned int dof_j=0; dof_j<n_dofs; dof_j++)
171  {
172  Ke(dof_i, dof_j) += JxW[qp] * (dphi[dof_j][qp]* dphi[dof_i][qp]);
173  }
174  Fe(dof_i) += JxW[qp] * phi[dof_i][qp];
175  }
176  }
177 
178 #ifdef LIBMESH_ENABLE_CONSTRAINTS
179  // This will zero off-diagonal entries of Ke corresponding to
180  // Dirichlet dofs.
181  dof_map.constrain_element_matrix_and_vector (Ke, Fe, dof_indices);
182 
183  // We want the diagonal of constrained dofs to be zero too
184  for (unsigned int local_dof_index=0; local_dof_index<n_dofs; local_dof_index++)
185  {
186  dof_id_type global_dof_index = dof_indices[local_dof_index];
187  if (dof_map.is_constrained_dof(global_dof_index))
188  {
189  Ke(local_dof_index, local_dof_index) = 0.;
190  }
191  }
192 #endif // LIBMESH_ENABLE_CONSTRAINTS
193 
194  A_matrix->add_matrix (Ke, dof_indices);
195  F_vector->add_vector (Fe, dof_indices);
196  }
197 
198  A_matrix->close();
199  F_vector->close();
200 }
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:182
OptimizationSystem & _sys
Keep a reference to the OptimizationSystem.
void constrain_element_matrix_and_vector(DenseMatrix< Number > &matrix, DenseVector< Number > &rhs, std::vector< dof_id_type > &elem_dofs, bool asymmetric_constraint_rows=true) const
Constrains the element matrix and vector.
Definition: dof_map.h:2254
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
Definition: dof_map.C:1992
unsigned int dim
void resize(const unsigned int n)
Resize the vector.
Definition: dense_vector.h:374
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i]...
const FEType & variable_type(const unsigned int c) const
Definition: dof_map.h:2144
MeshBase & mesh
NumericVector< Number > * F_vector
Vector for storing F.
Order default_quadrature_order() const
Definition: fe_type.h:357
const MeshBase & get_mesh() const
Definition: system.h:2277
This is the MeshBase class.
Definition: mesh_base.h:74
virtual void zero()=0
Set all entries to zero.
unsigned int variable_number(std::string_view var) const
Definition: system.C:1557
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:169
SparseMatrix< Number > * A_matrix
Sparse matrix for storing the matrix A.
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols)=0
Add the full matrix dm to the SparseMatrix.
virtual void zero()=0
Set all entries to 0.
bool is_constrained_dof(const dof_id_type dof) const
Definition: dof_map.h:2182
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
Definition: dense_matrix.h:895
This class implements specific orders of Gauss quadrature.
unsigned int mesh_dimension() const
Definition: mesh_base.C:324
const DofMap & get_dof_map() const
Definition: system.h:2293
uint8_t dof_id_type
Definition: id_types.h:67

◆ assemble_A_and_F() [2/2]

void AssembleOptimization::assemble_A_and_F ( )

The optimization problem we consider here is: min_U 0.5*U^T A U - U^T F.

In this method, we assemble A and F.

◆ equality_constraints() [1/2]

void AssembleOptimization::equality_constraints ( const NumericVector< Number > &  X,
NumericVector< Number > &  C_eq,
OptimizationSystem  
)
virtual

Evaluate the equality constraints.

Definition at line 276 of file optimization_ex2.C.

References libMesh::ParallelObject::comm(), libMesh::NumericVector< T >::first_local_index(), libMesh::NumericVector< T >::init(), libMesh::NumericVector< T >::last_local_index(), libMesh::NumericVector< T >::localize(), libMesh::SERIAL, libMesh::NumericVector< T >::set(), libMesh::NumericVector< T >::size(), and libMesh::NumericVector< T >::zero().

279 {
280  C_eq.zero();
281 
282  std::unique_ptr<NumericVector<Number>> X_localized =
284  X_localized->init(X.size(), false, SERIAL);
285  X.localize(*X_localized);
286 
287  std::vector<Number> constraint_values(3);
288  constraint_values[0] = (*X_localized)(17);
289  constraint_values[1] = (*X_localized)(23);
290  constraint_values[2] = (*X_localized)(98) + (*X_localized)(185);
291 
292  for (std::size_t i=0; i<constraint_values.size(); i++)
293  if ((C_eq.first_local_index() <= i) &&
294  (i < C_eq.last_local_index()))
295  C_eq.set(i, constraint_values[i]);
296 }
virtual numeric_index_type size() const =0
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:43
const Parallel::Communicator & comm() const
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
virtual void zero()=0
Set all entries to zero.
virtual numeric_index_type first_local_index() const =0
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
virtual numeric_index_type last_local_index() const =0
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.

◆ equality_constraints() [2/2]

virtual void libMesh::OptimizationSystem::ComputeEqualityConstraints::equality_constraints ( const NumericVector< Number > &  X,
NumericVector< Number > &  C_eq,
sys_type S 
)
pure virtualinherited

This function will be called to evaluate the equality constraints vector C_eq(X).

This will impose the constraints C_eq(X) = 0.

Referenced by libMesh::__libmesh_nlopt_equality_constraints(), and libMesh::__libmesh_tao_equality_constraints().

◆ equality_constraints_jacobian() [1/2]

void AssembleOptimization::equality_constraints_jacobian ( const NumericVector< Number > &  X,
SparseMatrix< Number > &  C_eq_jac,
OptimizationSystem sys 
)
virtual

Evaluate the equality constraints Jacobian.

Definition at line 298 of file optimization_ex2.C.

References libMesh::OptimizationSystem::C_eq, libMesh::SparseMatrix< T >::set(), value, and libMesh::SparseMatrix< T >::zero().

301 {
302  C_eq_jac.zero();
303 
304  std::vector<std::vector<Number>> constraint_jac_values(3);
305  std::vector<std::vector<dof_id_type>> constraint_jac_indices(3);
306 
307  constraint_jac_values[0].resize(1);
308  constraint_jac_indices[0].resize(1);
309  constraint_jac_values[0][0] = 1.;
310  constraint_jac_indices[0][0] = 17;
311 
312  constraint_jac_values[1].resize(1);
313  constraint_jac_indices[1].resize(1);
314  constraint_jac_values[1][0] = 1.;
315  constraint_jac_indices[1][0] = 23;
316 
317  constraint_jac_values[2].resize(2);
318  constraint_jac_indices[2].resize(2);
319  constraint_jac_values[2][0] = 1.;
320  constraint_jac_values[2][1] = 1.;
321  constraint_jac_indices[2][0] = 98;
322  constraint_jac_indices[2][1] = 185;
323 
324  for (std::size_t i=0; i<constraint_jac_values.size(); i++)
325  for (std::size_t j=0; j<constraint_jac_values[i].size(); j++)
326  if ((sys.C_eq->first_local_index() <= i) &&
327  (i < sys.C_eq->last_local_index()))
328  {
329  dof_id_type col_index = constraint_jac_indices[i][j];
330  Number value = constraint_jac_values[i][j];
331  C_eq_jac.set(i, col_index, value);
332  }
333 }
std::unique_ptr< NumericVector< Number > > C_eq
The vector that stores equality constraints.
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value)=0
Set the element (i,j) to value.
virtual void zero()=0
Set all entries to 0.
static const bool value
Definition: xdr_io.C:54
uint8_t dof_id_type
Definition: id_types.h:67

◆ equality_constraints_jacobian() [2/2]

virtual void libMesh::OptimizationSystem::ComputeEqualityConstraintsJacobian::equality_constraints_jacobian ( const NumericVector< Number > &  X,
SparseMatrix< Number > &  C_eq_jac,
sys_type S 
)
pure virtualinherited

This function will be called to evaluate the Jacobian of C_eq(X).

Referenced by libMesh::__libmesh_nlopt_equality_constraints(), and libMesh::__libmesh_tao_equality_constraints_jacobian().

◆ gradient() [1/3]

void AssembleOptimization::gradient ( const NumericVector< Number > &  soln,
NumericVector< Number > &  grad_f,
OptimizationSystem  
)
virtual

Evaluate the gradient.

Definition at line 216 of file optimization_ex1.C.

References A_matrix, libMesh::NumericVector< T >::add(), F_vector, libMesh::SparseMatrix< T >::vector_mult(), and libMesh::NumericVector< T >::zero().

219 {
220  grad_f.zero();
221 
222  // Since we've enforced constraints on soln, A and F,
223  // this automatically sets grad_f to zero for constrained
224  // dofs.
225  A_matrix->vector_mult(grad_f, soln);
226  grad_f.add(-1, *F_vector);
227 }
void vector_mult(NumericVector< T > &dest, const NumericVector< T > &arg) const
Multiplies the matrix by the NumericVector arg and stores the result in NumericVector dest...
NumericVector< Number > * F_vector
Vector for storing F.
virtual void zero()=0
Set all entries to zero.
SparseMatrix< Number > * A_matrix
Sparse matrix for storing the matrix A.
virtual void add(const numeric_index_type i, const T value)=0
Adds value to the vector entry specified by i.

◆ gradient() [2/3]

virtual void AssembleOptimization::gradient ( const NumericVector< Number > &  soln,
NumericVector< Number > &  grad_f,
OptimizationSystem  
)
virtual

Evaluate the gradient.

◆ gradient() [3/3]

virtual void libMesh::OptimizationSystem::ComputeGradient::gradient ( const NumericVector< Number > &  X,
NumericVector< Number > &  grad_f,
sys_type S 
)
pure virtualinherited

This function will be called to compute the gradient of the objective function, and must be implemented by the user in a derived class.

Set grad_f to be the gradient at the iterate X.

Referenced by libMesh::__libmesh_nlopt_objective(), and libMesh::__libmesh_tao_gradient().

◆ hessian() [1/3]

virtual void AssembleOptimization::hessian ( const NumericVector< Number > &  soln,
SparseMatrix< Number > &  H_f,
OptimizationSystem  
)
virtual

Evaluate the Hessian.

◆ hessian() [2/3]

void AssembleOptimization::hessian ( const NumericVector< Number > &  soln,
SparseMatrix< Number > &  H_f,
OptimizationSystem sys 
)
virtual

Evaluate the Hessian.

Definition at line 230 of file optimization_ex1.C.

References A_matrix, libMesh::SparseMatrix< T >::add(), and libMesh::SparseMatrix< T >::zero().

233 {
234  LOG_SCOPE("hessian()", "AssembleOptimization");
235  H_f.zero();
236  H_f.add(1., *A_matrix);
237 }
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
SparseMatrix< Number > * A_matrix
Sparse matrix for storing the matrix A.
virtual void zero()=0
Set all entries to 0.

◆ hessian() [3/3]

virtual void libMesh::OptimizationSystem::ComputeHessian::hessian ( const NumericVector< Number > &  X,
SparseMatrix< Number > &  H_f,
sys_type S 
)
pure virtualinherited

This function will be called to compute the Hessian of the objective function, and must be implemented by the user in a derived class.

Set H_f to be the gradient at the iterate X.

Referenced by libMesh::__libmesh_tao_hessian().

◆ inequality_constraints() [1/2]

void AssembleOptimization::inequality_constraints ( const NumericVector< Number > &  X,
NumericVector< Number > &  C_ineq,
OptimizationSystem  
)
virtual

Evaluate the inequality constraints.

Definition at line 335 of file optimization_ex2.C.

References libMesh::ParallelObject::comm(), libMesh::NumericVector< T >::first_local_index(), libMesh::NumericVector< T >::init(), libMesh::NumericVector< T >::last_local_index(), libMesh::NumericVector< T >::localize(), libMesh::SERIAL, libMesh::NumericVector< T >::set(), libMesh::NumericVector< T >::size(), and libMesh::NumericVector< T >::zero().

338 {
339  C_ineq.zero();
340 
341  std::unique_ptr<NumericVector<Number>> X_localized =
343  X_localized->init(X.size(), false, SERIAL);
344  X.localize(*X_localized);
345 
346  std::vector<Number> constraint_values(1);
347  constraint_values[0] = (*X_localized)(200)*(*X_localized)(200) + (*X_localized)(201) - 5.;
348 
349  for (std::size_t i=0; i<constraint_values.size(); i++)
350  if ((C_ineq.first_local_index() <= i) && (i < C_ineq.last_local_index()))
351  C_ineq.set(i, constraint_values[i]);
352 }
virtual numeric_index_type size() const =0
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:43
const Parallel::Communicator & comm() const
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
virtual void zero()=0
Set all entries to zero.
virtual numeric_index_type first_local_index() const =0
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
virtual numeric_index_type last_local_index() const =0
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.

◆ inequality_constraints() [2/2]

virtual void libMesh::OptimizationSystem::ComputeInequalityConstraints::inequality_constraints ( const NumericVector< Number > &  X,
NumericVector< Number > &  C_ineq,
sys_type S 
)
pure virtualinherited

This function will be called to evaluate the equality constraints vector C_ineq(X).

This will impose the constraints C_ineq(X) >= 0.

Referenced by libMesh::__libmesh_nlopt_inequality_constraints(), and libMesh::__libmesh_tao_inequality_constraints().

◆ inequality_constraints_jacobian() [1/2]

void AssembleOptimization::inequality_constraints_jacobian ( const NumericVector< Number > &  X,
SparseMatrix< Number > &  C_ineq_jac,
OptimizationSystem sys 
)
virtual

Evaluate the inequality constraints Jacobian.

Definition at line 354 of file optimization_ex2.C.

References libMesh::OptimizationSystem::C_ineq, libMesh::ParallelObject::comm(), libMesh::NumericVector< T >::init(), libMesh::NumericVector< T >::localize(), libMesh::SERIAL, libMesh::SparseMatrix< T >::set(), libMesh::NumericVector< T >::size(), value, and libMesh::SparseMatrix< T >::zero().

357 {
358  C_ineq_jac.zero();
359 
360  std::unique_ptr<NumericVector<Number>> X_localized =
362  X_localized->init(X.size(), false, SERIAL);
363  X.localize(*X_localized);
364 
365  std::vector<std::vector<Number>> constraint_jac_values(1);
366  std::vector<std::vector<dof_id_type>> constraint_jac_indices(1);
367 
368  constraint_jac_values[0].resize(2);
369  constraint_jac_indices[0].resize(2);
370  constraint_jac_values[0][0] = 2.* (*X_localized)(200);
371  constraint_jac_values[0][1] = 1.;
372  constraint_jac_indices[0][0] = 200;
373  constraint_jac_indices[0][1] = 201;
374 
375  for (std::size_t i=0; i<constraint_jac_values.size(); i++)
376  for (std::size_t j=0; j<constraint_jac_values[i].size(); j++)
377  if ((sys.C_ineq->first_local_index() <= i) &&
378  (i < sys.C_ineq->last_local_index()))
379  {
380  dof_id_type col_index = constraint_jac_indices[i][j];
381  Number value = constraint_jac_values[i][j];
382  C_ineq_jac.set(i, col_index, value);
383  }
384 
385 }
virtual numeric_index_type size() const =0
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:43
const Parallel::Communicator & comm() const
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value)=0
Set the element (i,j) to value.
virtual void zero()=0
Set all entries to 0.
static const bool value
Definition: xdr_io.C:54
std::unique_ptr< NumericVector< Number > > C_ineq
The vector that stores inequality constraints.
uint8_t dof_id_type
Definition: id_types.h:67
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.

◆ inequality_constraints_jacobian() [2/2]

virtual void libMesh::OptimizationSystem::ComputeInequalityConstraintsJacobian::inequality_constraints_jacobian ( const NumericVector< Number > &  X,
SparseMatrix< Number > &  C_ineq_jac,
sys_type S 
)
pure virtualinherited

This function will be called to evaluate the Jacobian of C_ineq(X).

Referenced by libMesh::__libmesh_nlopt_inequality_constraints(), and libMesh::__libmesh_tao_inequality_constraints_jacobian().

◆ lower_and_upper_bounds() [1/2]

void AssembleOptimization::lower_and_upper_bounds ( OptimizationSystem sys)
virtual

Evaluate the lower and upper bounds vectors.

Definition at line 387 of file optimization_ex2.C.

References libMesh::DofMap::end_dof(), libMesh::DofMap::first_dof(), libMesh::System::get_dof_map(), libMesh::System::get_vector(), and libMesh::NumericVector< T >::set().

388 {
389  for (unsigned int i=sys.get_dof_map().first_dof(); i<sys.get_dof_map().end_dof(); i++)
390  {
391  sys.get_vector("lower_bounds").set(i, -2.);
392  sys.get_vector("upper_bounds").set(i, 2.);
393  }
394 }
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map.h:684
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:708
const DofMap & get_dof_map() const
Definition: system.h:2293
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:918

◆ lower_and_upper_bounds() [2/2]

virtual void libMesh::OptimizationSystem::ComputeLowerAndUpperBounds::lower_and_upper_bounds ( sys_type S)
pure virtualinherited

This function should update the following two vectors: this->get_vector("lower_bounds"), this->get_vector("upper_bounds").

◆ objective() [1/3]

virtual Number libMesh::OptimizationSystem::ComputeObjective::objective ( const NumericVector< Number > &  X,
sys_type S 
)
pure virtualinherited

This function will be called to compute the objective function to be minimized, and must be implemented by the user in a derived class.

Returns
The value of the objective function at iterate X.

Referenced by libMesh::__libmesh_nlopt_objective(), and libMesh::__libmesh_tao_objective().

◆ objective() [2/3]

virtual Number AssembleOptimization::objective ( const NumericVector< Number > &  soln,
OptimizationSystem  
)
virtual

Evaluate the objective function.

◆ objective() [3/3]

Number AssembleOptimization::objective ( const NumericVector< Number > &  soln,
OptimizationSystem  
)
virtual

Evaluate the objective function.

Definition at line 202 of file optimization_ex1.C.

References A_matrix, libMesh::NumericVector< T >::dot(), F_vector, libMesh::SparseMatrix< T >::vector_mult(), and libMesh::NumericVector< T >::zero_clone().

204 {
205  std::unique_ptr<NumericVector<Number>> AxU = soln.zero_clone();
206 
207  A_matrix->vector_mult(*AxU, soln);
208 
209  Number
210  UTxAxU = AxU->dot(soln),
211  UTxF = F_vector->dot(soln);
212 
213  return 0.5 * UTxAxU - UTxF;
214 }
void vector_mult(NumericVector< T > &dest, const NumericVector< T > &arg) const
Multiplies the matrix by the NumericVector arg and stores the result in NumericVector dest...
virtual std::unique_ptr< NumericVector< T > > zero_clone() const =0
NumericVector< Number > * F_vector
Vector for storing F.
virtual T dot(const NumericVector< T > &v) const =0
SparseMatrix< Number > * A_matrix
Sparse matrix for storing the matrix A.

Member Data Documentation

◆ _sys

OptimizationSystem & AssembleOptimization::_sys
private

Keep a reference to the OptimizationSystem.

Definition at line 76 of file optimization_ex1.C.

Referenced by assemble_A_and_F().

◆ A_matrix

SparseMatrix< Number > * AssembleOptimization::A_matrix

Sparse matrix for storing the matrix A.

We use this to facilitate computation of objective, gradient and hessian.

Definition at line 117 of file optimization_ex1.C.

Referenced by assemble_A_and_F(), gradient(), hessian(), main(), and objective().

◆ F_vector

NumericVector< Number > * AssembleOptimization::F_vector

Vector for storing F.

We use this to facilitate computation of objective, gradient and hessian.

Definition at line 123 of file optimization_ex1.C.

Referenced by assemble_A_and_F(), gradient(), main(), and objective().


The documentation for this class was generated from the following files: