14 #include "libmesh/string_to_enum.h" 26 "Computes objective function, gradient and contains reporters for communicating between " 27 "optimizeSolve and subapps using mesh-based parameter definition.");
30 "parameter_meshes",
"Exodus file containing meshes describing parameters.");
37 "Specifies the family of FE shape functions for each group of parameters. If a single value " 39 "specified, then that value is used for all groups of parameters.");
45 "Specifies the order of FE shape functions for each group of parameters. If a single value " 47 "specified, then that value is used for all groups of parameters.");
50 "num_parameter_times", 1,
"The number of time points the parameters represent.");
52 params.
addParam<std::vector<std::string>>(
53 "initial_condition_mesh_variable",
54 "Name of variable on parameter mesh to use as initial condition.");
55 params.
addParam<std::vector<std::string>>(
56 "lower_bound_mesh_variable",
"Name of variable on parameter mesh to use as lower bound.");
57 params.
addParam<std::vector<std::string>>(
58 "upper_bound_mesh_variable",
"Name of variable on parameter mesh to use as upper bound.");
59 params.
addParam<std::vector<unsigned int>>(
60 "exodus_timesteps_for_parameter_mesh_variable",
61 "Timesteps to read all parameter group bounds and initial conditions from Exodus mesh. The " 62 "options are to give no timestep, a single timestep or \"num_parameter_times\" timesteps. " 63 "No timestep results in the final timestep from the mesh being used. A single timestep " 64 "results in values at that timestep being used for all timesteps. \"num_parameter_times\" " 65 "timesteps results in values from the mesh at those steps being used. The same timesteps " 66 "are used for all parameter groups and all meshes, the capability to define different " 67 "timesteps for different meshes is not supported.");
80 const std::string & mesh_var_name,
81 unsigned int ntimes)
const 83 unsigned int num_cont_params = pmesh.
size() * ntimes;
84 std::vector<Real> parsed_data;
87 for (
auto const & step : exodus_timestep)
90 parsed_data.insert(parsed_data.end(), data.begin(), data.end());
92 if (parsed_data.size() != num_cont_params)
93 mooseError(
"Number of parameters assigned by ",
95 " is not equal to the number of parameters on the mesh. Mesh contains ",
110 paramError(
"num_values_name or num_values should not be used with ParameterMeshOptimization. " 111 "Instead the number of dofs is set by the parameter meshes.");
115 const auto & meshes = getParam<std::vector<FileName>>(
"parameter_meshes");
116 const auto & families = getParam<MultiMooseEnum>(
"parameter_families");
117 const auto & orders = getParam<MultiMooseEnum>(
"parameter_orders");
118 const auto & ntimes = getParam<unsigned int>(
"num_parameter_times");
121 std::vector<std::string> initial_condition_mesh_variable;
122 std::vector<std::string> lower_bound_mesh_variable;
123 std::vector<std::string> upper_bound_mesh_variable;
125 initial_condition_mesh_variable =
126 getParam<std::vector<std::string>>(
"initial_condition_mesh_variable");
128 lower_bound_mesh_variable =
getParam<std::vector<std::string>>(
"lower_bound_mesh_variable");
130 upper_bound_mesh_variable =
getParam<std::vector<std::string>>(
"upper_bound_mesh_variable");
132 std::vector<unsigned int> exodus_timestep;
133 if (
isParamValid(
"exodus_timesteps_for_parameter_mesh_variable"))
135 getParam<std::vector<unsigned int>>(
"exodus_timesteps_for_parameter_mesh_variable");
137 exodus_timestep = {std::numeric_limits<unsigned int>::max()};
143 "There must be a mesh associated with each group of parameters.");
144 if (families.size() > 1 && families.size() !=
_nparams)
146 "There must be a family associated with each group of parameters.");
147 if (orders.size() > 1 && orders.size() !=
_nparams)
149 "There must be an order associated with each group of parameters.");
154 "Initial conditions for all parameter groups can only be defined by " 155 "initial_condition_mesh_variable or " 156 "initial_condition but not both.");
159 "lower_bound_mesh_variable",
160 "Lower bounds for all parameter groups can only be defined by lower_bound_mesh_variable or " 161 "lower_bounds but not both.");
164 "upper_bound_mesh_variable",
165 "Upper bounds for all parameter groups can only be defined by upper_bound_mesh_variable or " 166 "upper_bounds but not both.");
169 if (
isParamValid(
"exodus_timesteps_for_parameter_mesh_variable") &&
173 paramError(
"\"exodus_timesteps_for_parameter_mesh_variable\" should only be specified if " 174 "reading values from a mesh.");
175 else if (exodus_timestep.size() != ntimes && exodus_timestep.size() != 1)
176 paramError(
"exodus_timesteps_for_parameter_mesh_variable",
177 "Number of timesteps to read mesh data specified by " 178 "\"exodus_timesteps_for_parameter_mesh_variable\" incorrect. " 179 "\"exodus_timesteps_for_parameter_mesh_variable\" can specify a single timestep or " 180 "\"num_parameter_times\" timesteps.");
186 std::vector<std::string> var_names;
188 var_names.push_back(initial_condition_mesh_variable[param_id]);
190 var_names.push_back(lower_bound_mesh_variable[param_id]);
192 var_names.push_back(upper_bound_mesh_variable[param_id]);
194 const std::string family = families.size() > 1 ? families[param_id] : families[0];
195 const std::string order = orders.size() > 1 ? orders[param_id] : orders[0];
196 const FEType fetype(Utility::string_to_enum<Order>(order),
197 Utility::string_to_enum<FEFamily>(family));
207 exodus_timestep, pmesh, initial_condition_mesh_variable[param_id], ntimes);
214 std::vector<Real> lower_bound;
217 parseExodusData(exodus_timestep, pmesh, lower_bound_mesh_variable[param_id], ntimes);
219 lower_bound =
parseInputData(
"lower_bounds", std::numeric_limits<Real>::lowest(), param_id);
224 std::vector<Real> upper_bound;
227 parseExodusData(exodus_timestep, pmesh, upper_bound_mesh_variable[param_id], ntimes);
229 upper_bound =
parseInputData(
"upper_bounds", std::numeric_limits<Real>::max(), param_id);
std::vector< Real > parseExodusData(const std::vector< unsigned int > &exodus_timestep, const ParameterMesh &pmesh, const std::string &mesh_var_name, unsigned int ntimes) const
Read initialization data off of parameter mesh and error check.
Utility class to use an Exodus mesh to define controllable parameters for optimization problems This ...
static InputParameters validParams()
dof_id_type _ndof
Total number of parameters.
registerMooseObject("OptimizationApp", ParameterMeshOptimization)
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
std::string getRawNames() const
static MooseEnum getNonlinearVariableFamilies()
const unsigned int _nparams
Number of parameter vectors.
bool isParamValid(const std::string &name) const
static MooseEnum getNonlinearVariableOrders()
ParameterMeshOptimization(const InputParameters ¶meters)
std::vector< dof_id_type > _nvalues
Number of values for each parameter.
Number initial_condition(const Point &p, const Parameters ¶meters, const std::string &, const std::string &)
const T & getParam(const std::string &name) const
Mesh-based parameter optimization.
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.
void paramError(const std::string ¶m, Args... args) const
std::vector< std::vector< Real > * > _parameters
Parameter values declared as reporter data.
static InputParameters validParams()
std::vector< std::vector< Real > * > _gradients
Gradient values declared as reporter data.
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
std::vector< Real > _upper_bounds
std::vector< Real > getParameterValues(std::string var_name, unsigned int timestep) const
Initializes parameter data and sets bounds in the main optmiization application getParameterValues is...
virtual void setICsandBounds() override
Sets the initial conditions and bounds right before it is needed.
Optimization reporter that interfaces with TAO.