https://mooseframework.inl.gov
OptimizationReporterBase.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "GeneralReporter.h"
13 #include "libmesh/petsc_matrix.h"
14 
15 namespace libMesh
16 {
17 template <typename Number>
18 class PetscVector;
19 }
20 
26 {
27 public:
30 
31  virtual void initialize() override {}
32  virtual void execute() override {}
33  virtual void finalize() override {}
38  virtual Real computeObjective() = 0;
39 
44  virtual void computeGradient(libMesh::PetscVector<Number> & gradient) const;
45 
50 
55  virtual void setMisfitToSimulatedValues(){};
56 
65 
70  virtual dof_id_type getNumParams() const { return _ndof; }
71 
76  virtual void computeEqualityConstraints(libMesh::PetscVector<Number> & eqs_constraints) const;
77 
82  virtual void computeInequalityConstraints(libMesh::PetscVector<Number> & ineqs_constraints) const;
83 
88  virtual void computeEqualityGradient(libMesh::PetscMatrix<Number> & gradient) const;
89 
94  virtual void computeInequalityGradient(libMesh::PetscMatrix<Number> & gradient) const;
95 
100  dof_id_type getNumEqCons() const { return _n_eq_cons; }
101 
107 
108 protected:
113  virtual void updateParameters(const libMesh::PetscVector<Number> & x);
114 
118  std::vector<Real>
119  parseInputData(std::string type, Real default_value, unsigned int param_id) const;
120 
122  virtual void setICsandBounds(){};
123 
125  const std::vector<ReporterValueName> & _parameter_names;
127  const unsigned int _nparams;
128 
130  std::vector<std::vector<Real> *> _parameters;
132  std::vector<std::vector<Real> *> _gradients;
133 
136 
138  const std::vector<ReporterValueName> * _equality_names;
140  const unsigned int _n_eq_cons;
142  std::vector<std::vector<Real> *> _eq_constraints;
144  std::vector<std::vector<Real> *> _eq_gradients;
145 
147  const std::vector<ReporterValueName> * _inequality_names;
149  const unsigned int _n_ineq_cons;
151  std::vector<std::vector<Real> *> _ineq_constraints;
153  std::vector<std::vector<Real> *> _ineq_gradients;
154 
156  std::vector<Real> _lower_bounds;
157  std::vector<Real> _upper_bounds;
158 
160  std::vector<dof_id_type> _nvalues;
163 
164 private:
165  friend class OptimizeSolve;
167 };
virtual void setICsandBounds()
Sets the initial conditions and bounds right before it is needed.
const std::vector< ReporterValueName > * _inequality_names
Inequality constraint names.
const std::vector< ReporterValueName > & _parameter_names
Parameter names.
virtual void setMisfitToSimulatedValues()
Function to override misfit values with the simulated values from the matrix free hessian forward sol...
const unsigned int _n_ineq_cons
Number of inequality constraint names.
virtual void computeInequalityConstraints(libMesh::PetscVector< Number > &ineqs_constraints) const
Function to compute the inequality constraints.
Real getLowerBound(dof_id_type i) const
std::vector< std::vector< Real > * > _ineq_gradients
Gradient values declared as reporter data.
dof_id_type getNumEqCons() const
Function to get the total number of equalities.
dof_id_type _ndof
Total number of parameters.
virtual void computeEqualityGradient(libMesh::PetscMatrix< Number > &gradient) const
Function to compute the gradient of the equality constraints/ This is the last call of the equality c...
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
virtual dof_id_type getNumParams() const
Function to get the total number of parameters.
const unsigned int _nparams
Number of parameter vectors.
std::vector< std::vector< Real > * > _ineq_constraints
Inequality values declared as reporter data.
Base class for optimization objects, implements routines for calculating misfit.
virtual void finalize() override
void setInitialCondition(libMesh::PetscVector< Number > &param)
Function to initialize petsc vectors from vpp data.
std::vector< std::vector< Real > * > _eq_gradients
Gradient values declared as reporter data.
virtual void execute() override
const std::vector< double > x
std::vector< dof_id_type > _nvalues
Number of values for each parameter.
const std::string & type() const
virtual Real computeObjective()=0
Function to compute objective.
std::vector< Real > parseInputData(std::string type, Real default_value, unsigned int param_id) const
Function to to parse bounds and initial conditions from input file.
std::vector< Real > _lower_bounds
Bounds of the parameters.
A UserObject that tests the requesting of Reporter values that are actually correct.
std::vector< std::vector< Real > * > _parameters
Parameter values declared as reporter data.
std::vector< std::vector< Real > * > _eq_constraints
Equality values declared as reporter data.
const unsigned int _n_eq_cons
Number of equality constraint names.
const std::vector< ReporterValueName > * _equality_names
Equality constraint names.
virtual void computeInequalityGradient(libMesh::PetscMatrix< Number > &gradient) const
Function to compute the gradient of the inequality constraints/ This is the last call of the inequali...
OptimizationReporterBase(const InputParameters &parameters)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void computeGradient(libMesh::PetscVector< Number > &gradient) const
Function to compute gradient.
std::vector< std::vector< Real > * > _gradients
Gradient values declared as reporter data.
virtual void updateParameters(const libMesh::PetscVector< Number > &x)
Function to set parameters.
const InputParameters & parameters() const
static InputParameters validParams()
Real getUpperBound(dof_id_type i) const
Upper and lower bounds for each parameter being controlled.
virtual void initialize() override
const Real _tikhonov_coeff
Tikhonov Coefficient for regularization.
virtual void computeEqualityConstraints(libMesh::PetscVector< Number > &eqs_constraints) const
Function to compute the equality constraints.
solveObject to interface with Petsc Tao
Definition: OptimizeSolve.h:28
dof_id_type getNumInEqCons() const
Function to get the total number of inequalities.
uint8_t dof_id_type