20 "Reporter to hold measurement and simulation data for optimization problems");
23 "Measurement values collected from locations given by measurement_points");
24 params.
addParam<std::vector<Point>>(
"measurement_points",
25 "Point locations corresponding to each measurement value");
26 params.
addParam<std::vector<Real>>(
"measurement_times",
27 "Times corresponding to each measurement value");
29 params.
addParam<FileName>(
"measurement_file",
30 "CSV file with measurement value and coordinates (value, x, y, z).");
32 "file_xcoord",
"x",
"x coordinate column name from measurement_file csv being read in.");
34 "file_ycoord",
"y",
"y coordinate column name from csv file being read in.");
36 "file_zcoord",
"z",
"z coordinate column name from csv file being read in.");
38 "file_time",
"time",
"time column name from csv file being read in.");
39 params.
addParam<std::vector<std::string>>(
40 "file_variable_weights", {},
"variable weight column names from csv file being read in.");
42 "file_value",
"value",
"measurement value column name from csv file being read in.");
44 params.
addParam<std::vector<std::string>>(
45 "variable_weight_names",
46 "Vector of weight reporter names that will create a reporter to transfer weights into. The "
47 "ordering of these weight reporter names corresponds to the ordering used in variable.");
48 params.
addParam<std::vector<VariableName>>(
49 "variable",
"Vector of variable names to sample at measurement points.");
50 params.
addParam<ReporterValueName>(
"objective_name",
51 "Name of reporter value defining the objective.");
53 "Input Measurement Data");
55 "file_value file_variable_weights",
56 "File Measurement Data");
76 _objective_val(isParamSetByUser(
"objective_name")
77 ? declareValueByName<Real>(getParam<ReporterValueName>(
"objective_name"),
79 : declareUnusedValue<Real>())
83 mooseError(
"Input file can only define a single input for measurement data. Use only "
84 "measurement_file or measurement_points, but never both");
94 std::vector<VariableName> var_names(
getParam<std::vector<VariableName>>(
"variable"));
95 for (
const auto &
name : var_names)
97 _tid,
name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD));
101 std::vector<std::string> weight_names(
102 getParam<std::vector<std::string>>(
"variable_weight_names"));
103 for (
const auto &
name : weight_names)
123 "The same number of names must be in both 'variable_weight_names' and 'variable'.");
149 for (
const auto var_index : make_range(
_var_vec.size()))
151 const auto & sys =
_var_vec[var_index]->sys().system();
152 const auto vnum =
_var_vec[var_index]->number();
158 for (
const auto & i : make_range(nvals))
168 const Real val = sys.point_value(vnum, point,
false);
180 std::string xName = getParam<std::string>(
"file_xcoord");
181 std::string yName = getParam<std::string>(
"file_ycoord");
182 std::string zName = getParam<std::string>(
"file_zcoord");
183 std::string tName = getParam<std::string>(
"file_time");
184 std::string valueName = getParam<std::string>(
"file_value");
185 std::vector<std::string> weightNames =
186 getParam<std::vector<std::string>>(
"file_variable_weights");
188 bool found_x =
false;
189 bool found_y =
false;
190 bool found_z =
false;
191 bool found_t =
false;
192 bool found_value =
false;
197 auto const & names = reader.
getNames();
198 auto const & data = reader.
getData();
200 const std::size_t rows = data[0].size();
201 for (std::size_t i = 0; i < names.size(); ++i)
204 if (data[i].size() != rows)
205 paramError(
"file",
"Mismatching column lengths in file");
207 if (names[i] == xName)
212 else if (names[i] == yName)
217 else if (names[i] == zName)
222 else if (names[i] == tName)
227 else if (names[i] == valueName)
232 else if (std::find(weightNames.begin(), weightNames.end(), names[i]) != weightNames.end())
242 paramError(
"measurement_file",
"Column with name '", xName,
"' missing from measurement file");
244 paramError(
"measurement_file",
"Column with name '", yName,
"' missing from measurement file");
246 paramError(
"measurement_file",
"Column with name '", zName,
"' missing from measurement file");
251 "measurement_file",
"Column with name '", valueName,
"' missing from measurement file");
254 std::string out(
"\n Measurement file column names: ");
255 for (
const auto &
name : names)
257 out +=
"\n file_variable_weights names: ";
258 for (
const auto &
name : weightNames)
261 "Not all of the file_variable_weights names were found in the measurement_file.",
269 if (!
getParam<std::vector<std::string>>(
"file_variable_weights").empty())
271 "file_variable_weights cannot be used with measurement data read from the input "
272 "file, use measure_file input instead.");
274 for (
const auto &
p : getParam<std::vector<Point>>(
"measurement_points"))
289 paramError(
"measurement_values",
"Input file must contain measurement points and values");
296 std::string msg =
"";
307 std::string(msg.begin(), msg.end() - 2),
308 " does not match number of entries in value data (",
309 std::to_string(nvals),
318 val += misfit * misfit;
registerMooseObject("OptimizationApp", OptimizationData)
const ReporterMode REPORTER_MODE_REPLICATED
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
static InputParameters validParams()
const std::string & name() const
void paramError(const std::string ¶m, Args... args) const
void mooseError(Args &&... args) const
const T & getParam(const std::string &name) const
bool isParamValid(const std::string &name) const
const std::vector< std::string > & getNames() const
const std::vector< std::vector< T > > & getData() const
std::vector< Real > & _measurement_xcoord
virtual void execute() override
std::vector< MooseVariableFieldBase * > _var_vec
variable
Real computeMisfitValue()
Compute half the sum of the misfit (squared) values.
static InputParameters validParams()
void readMeasurementsFromFile()
parse measurement data from csv file
std::vector< Real > & _simulation_values
simulated values at measurement xyzt
Real & _objective_val
Reporter value that will hold the objective value.
std::vector< Real > & _measurement_zcoord
std::vector< Real > & _measurement_time
std::vector< Real > & _misfit_values
difference between simulation and measurement values at measurement xyzt
std::vector< Real > & _measurement_ycoord
void readMeasurementsFromInput()
parse measurement data from input file
std::vector< std::vector< Real > * > _variable_weights
Weight names to reporter values.
OptimizationData(const InputParameters ¶meters)
void computeMisfit()
Compute misfit vectors from the simulations and measurement values.
std::map< std::string, std::vector< Real > * > _weight_names_weights_map
Weight names to reporter values map created from input file.
void errorCheckDataSize()
helper to check data sizes
std::vector< Real > & _measurement_values
T & declareValueByName(const ReporterValueName &value_name, Args &&... args)
FEProblemBase & _fe_problem