13#include "libmesh/id_types.h"
24 "objective_name",
"Preferred name of reporter value defining the objective.");
25 params.
addParam<std::vector<dof_id_type>>(
27 "Number of parameter values associated with each parameter group in 'parameter_names'.");
28 params.
addParam<ReporterValueName>(
"num_values_name",
29 "Reporter that holds the number of parameter values "
30 "associated with each parameter group in 'parameter_names'.");
31 params.
addParam<std::vector<std::vector<Real>>>(
33 "Initial conditions for each parameter. A vector is given for each parameter group. A "
34 "single value can be given for each group and all parameters in that group will be set to "
35 "that value. The default value is 0.");
36 params.
addParam<std::vector<std::vector<Real>>>(
38 "Lower bound for each parameter. A vector is given for each parameter group. A single "
39 "value can be given for each group and all parameters in that group will be set to that "
41 params.
addParam<std::vector<std::vector<Real>>>(
43 "Upper bound for each parameter. A vector is given for each parameter group. A single "
44 "value can be given for each group and all parameters in that group will be set to that "
48 "constraint data, which are supplied by the reporters and "
49 "postprocessors from the forward and adjoint subapps.");
55 _objective_val(declareValueByName<Real>(getParam<ReporterValueName>(
"objective_name"),
58 isParamValid(
"num_values_name")
59 ? &declareValueByName<
std::vector<dof_id_type>>(
71 Real param_norm_sqr = 0;
73 for (
const auto & param_val : *data)
74 param_norm_sqr += param_val * param_val;
86 "The number of parameters you have is zero and this shouldn't happen. Make sure you are "
87 "running your forward problem on \'INITIAL\' if you are using a reporter transfer to "
101 paramError(
"Need to supply one and only one of num_values_name or num_values.");
106 _nvalues = getParam<std::vector<dof_id_type>>(
"num_values");
114 "There should be a number in \'num_parameters\' for each name in \'parameter_names\'.");
116 for (
const auto & param_id : make_range(
_nparams))
120 std::vector<Real> ic(
parseInputData(
"initial_condition", 0, param_id));
121 std::vector<Real> lb(
122 parseInputData(
"lower_bounds", std::numeric_limits<Real>::lowest(), param_id));
123 std::vector<Real> ub(
124 parseInputData(
"upper_bounds", std::numeric_limits<Real>::max(), param_id));
129 _parameters[param_id]->assign(ic.begin(), ic.end());
registerMooseObject("OptimizationApp", GeneralOptimization)
const ReporterMode REPORTER_MODE_REPLICATED
Optimization reporter that interfaces with TAO.
Real & _objective_val
Reporter that will hold the objective value.
virtual dof_id_type getNumParams() const override
Function to get the total number of parameters.
std::vector< dof_id_type > * _num_values_reporter
virtual void setICsandBounds() override
Sets the initial conditions and bounds right before it is needed.
GeneralOptimization(const InputParameters ¶meters)
virtual Real computeObjective() override
Function to compute objective.
static InputParameters validParams()
void paramError(const std::string ¶m, Args... args) const
void mooseError(Args &&... args) const
bool isParamValid(const std::string &name) 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.
const unsigned int _nparams
Number of parameter vectors.
std::vector< std::vector< Real > * > _gradients
Gradient values declared as reporter data.
std::vector< Real > _lower_bounds
Bounds of the parameters.
dof_id_type _ndof
Total number of parameters.
const std::vector< ReporterValueName > & _parameter_names
Parameter names.
const Real _tikhonov_coeff
Tikhonov Coefficient for regularization.
static InputParameters validParams()
std::vector< std::vector< Real > * > _parameters
Parameter values declared as reporter data.
std::vector< Real > _upper_bounds
std::vector< dof_id_type > _nvalues
Number of values for each parameter.