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
57 Real getUpperBound(dof_id_type i) const;
58 Real getLowerBound(dof_id_type i) const;
59
64 virtual dof_id_type getNumParams() const { return _ndof; }
65
70 virtual void computeEqualityConstraints(libMesh::PetscVector<Number> & eqs_constraints) const;
71
76 virtual void computeInequalityConstraints(libMesh::PetscVector<Number> & ineqs_constraints) const;
77
82 virtual void computeEqualityGradient(libMesh::PetscMatrix<Number> & gradient) const;
83
88 virtual void computeInequalityGradient(libMesh::PetscMatrix<Number> & gradient) const;
89
94 dof_id_type getNumEqCons() const { return _n_eq_cons; }
95
100 dof_id_type getNumInEqCons() const { return _n_ineq_cons; }
101
102protected:
107 virtual void updateParameters(const libMesh::PetscVector<Number> & x);
108
112 std::vector<Real>
113 parseInputData(std::string type, Real default_value, unsigned int param_id) const;
114
116 virtual void setICsandBounds() {}
117
119 const std::vector<ReporterValueName> & _parameter_names;
121 const unsigned int _nparams;
122
124 std::vector<std::vector<Real> *> _parameters;
126 std::vector<std::vector<Real> *> _gradients;
127
129 const Real _tikhonov_coeff;
130
132 const std::vector<ReporterValueName> * _equality_names;
134 const unsigned int _n_eq_cons;
136 std::vector<std::vector<Real> *> _eq_constraints;
138 std::vector<std::vector<Real> *> _eq_gradients;
139
141 const std::vector<ReporterValueName> * _inequality_names;
143 const unsigned int _n_ineq_cons;
145 std::vector<std::vector<Real> *> _ineq_constraints;
147 std::vector<std::vector<Real> *> _ineq_gradients;
148
150 std::vector<Real> _lower_bounds;
151 std::vector<Real> _upper_bounds;
152
154 std::vector<dof_id_type> _nvalues;
156 dof_id_type _ndof;
157
158private:
159 friend class OptimizeSolve;
161};
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.
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...