https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
15namespace libMesh
16{
17template <typename Number>
18class PetscVector;
19}
20
26{
27public:
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
56
63 Real getUpperBound(dof_id_type i) const;
64 Real getLowerBound(dof_id_type i) const;
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
106 dof_id_type getNumInEqCons() const { return _n_ineq_cons; }
107
108protected:
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
135 const Real _tikhonov_coeff;
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;
162 dof_id_type _ndof;
163
164private:
165 friend class OptimizeSolve;
167};
const std::vector< double > x
const InputParameters & parameters() const
const std::string & type() const
Base class for optimization objects, implements routines for calculating misfit.
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.
virtual void setMisfitToSimulatedValues()
Function to override misfit values with the simulated values from the matrix free hessian forward sol...
void setInitialCondition(libMesh::PetscVector< Number > &param)
Function to initialize petsc vectors from vpp data.
const unsigned int _nparams
Number of parameter vectors.
std::vector< std::vector< Real > * > _ineq_gradients
Gradient values declared as reporter data.
virtual void setICsandBounds()
Sets the initial conditions and bounds right before it is needed.
std::vector< std::vector< Real > * > _gradients
Gradient values declared as reporter data.
std::vector< std::vector< Real > * > _ineq_constraints
Inequality values declared as reporter data.
std::vector< std::vector< Real > * > _eq_constraints
Equality values declared as reporter data.
virtual void computeGradient(libMesh::PetscVector< Number > &gradient) const
Function to compute gradient.
std::vector< Real > _lower_bounds
Bounds of the parameters.
dof_id_type _ndof
Total number of parameters.
virtual Real computeObjective()=0
Function to compute objective.
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...
const std::vector< ReporterValueName > & _parameter_names
Parameter names.
Real getLowerBound(dof_id_type i) const
std::vector< std::vector< Real > * > _eq_gradients
Gradient values declared as reporter data.
const Real _tikhonov_coeff
Tikhonov Coefficient for regularization.
virtual void finalize() override
const unsigned int _n_eq_cons
Number of equality constraint names.
virtual void execute() override
dof_id_type getNumEqCons() const
Function to get the total number of equalities.
static InputParameters validParams()
std::vector< std::vector< Real > * > _parameters
Parameter values declared as reporter data.
const std::vector< ReporterValueName > * _equality_names
Equality constraint names.
virtual void computeInequalityConstraints(libMesh::PetscVector< Number > &ineqs_constraints) const
Function to compute the inequality constraints.
const unsigned int _n_ineq_cons
Number of inequality constraint names.
virtual void updateParameters(const libMesh::PetscVector< Number > &x)
Function to set parameters.
Real getUpperBound(dof_id_type i) const
Upper and lower bounds for each parameter being controlled.
virtual dof_id_type getNumParams() const
Function to get the total number of parameters.
virtual void initialize() override
virtual void computeEqualityConstraints(libMesh::PetscVector< Number > &eqs_constraints) const
Function to compute the equality constraints.
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...
const std::vector< ReporterValueName > * _inequality_names
Inequality constraint names.
std::vector< dof_id_type > _nvalues
Number of values for each parameter.
dof_id_type getNumInEqCons() const
Function to get the total number of inequalities.
A UserObject that tests the requesting of Reporter values that are actually correct.
solveObject to interface with Petsc Tao
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...