https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ParsedVectorVectorRealReductionReporter.C
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
11#include <cstddef>
12
14
17{
19 params.addClassDescription("Use a parsed function to iterate through a rows of a vector of "
20 "vector and reduce it to a vector.");
21 params.addRequiredParam<ReporterName>("vector_of_vector_reporter_name",
22 "Reporter name with vector of vectors to reduce.");
23
24 params.addRequiredParam<Real>("initial_reduction_value",
25 "Value to intialize the reduction with.");
26
27 // vector_reporter_symbols are the two symbols for reduction value and current value for the
28 // reduction operation, these symbols are enforced in the constructor with a mooseError
29 params.set<std::vector<std::string>>("vector_reporter_symbols") = {"reduction_value",
30 "indexed_value"};
31 params.suppressParameter<std::vector<std::string>>("vector_reporter_symbols");
32 params.suppressParameter<std::vector<std::string>>("scalar_reporter_symbols");
33
34 return params;
35}
36
38 const InputParameters & parameters)
39 : ParsedReporterBase(parameters),
40 _initial_reduction_value(getParam<Real>("initial_reduction_value")),
41 _vec_of_vec_name(getParam<ReporterName>("vector_of_vector_reporter_name")),
42 _output_reporter(
43 declareValueByName<std::vector<Real>>(getParam<std::string>("name"), REPORTER_MODE_ROOT)),
44 _reporter_data(getReporterValueByName<std::vector<std::vector<Real>>>(
45 getParam<ReporterName>("vector_of_vector_reporter_name")))
46{
47 // parse function
48 std::string function = getParam<std::string>("expression");
49 // make sure the expression has the two required variables, vi and vplus
50 if (function.find("reduction_value") == std::string::npos ||
51 function.find("indexed_value") == std::string::npos)
53 "expression",
54 "Parsed function must contain the two symbols 'reduction_value' and 'indexed_value'.");
55}
56
57void
59{
60 std::size_t ncols = _reporter_data.size();
61 std::size_t nrows = 0;
62 if (!_reporter_data.empty())
63 nrows = _reporter_data[0].size();
64
65 for (auto & reporter_vector : _reporter_data)
66 {
67 if (reporter_vector.size() != nrows)
68 mooseError("Every vector in 'vector_of_vector_reporter_name=",
70 "' must be the same size.",
71 "\nFirst Vector size = ",
72 nrows,
73 "\nCurrent Vector size = ",
74 reporter_vector.size());
75 }
76
77 _output_reporter.clear();
79 for (const auto i_row : make_range(nrows))
80 {
81 Real reduction = _initial_reduction_value;
82 for (const auto j_col : make_range(ncols))
83 {
84 _func_params[0] = reduction;
85 _func_params[1] = _reporter_data[j_col][i_row];
86
87 if (_use_t)
88 _func_params[2] = _t;
89
90 reduction = evaluate(_func_F);
91 }
92 _output_reporter[i_row] = reduction;
93 }
94}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObject("MooseApp", ParsedVectorVectorRealReductionReporter)
const ReporterMode REPORTER_MODE_ROOT
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn't required or valid in the derived class...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
Reporter containing operation between vectors from another Reporter.
const bool _use_t
whether time is part of the parsed expression
SymFunctionPtr _func_F
function parser object
static InputParameters validParams()
Reporter containing row sum of a vector of vectors from another Reporter.
const std::vector< std::vector< Real > > & _reporter_data
Vector being operated on.
std::vector< Real > & _output_reporter
output containing reduction of vector of vector into a vector
ParsedVectorVectorRealReductionReporter(const InputParameters &parameters)
The Reporter system is comprised of objects that can contain any number of data values.