https://mooseframework.inl.gov
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)
52  paramError(
53  "expression",
54  "Parsed function must contain the two symbols 'reduction_value' and 'indexed_value'.");
55 }
56 
57 void
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 }
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
const std::vector< std::vector< Real > > & _reporter_data
Vector being operated on.
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:30
registerMooseObject("MooseApp", ParsedVectorVectorRealReductionReporter)
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:439
const ReporterMode REPORTER_MODE_ROOT
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
SymFunctionPtr _func_F
function parser object
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 suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn&#39;t required or valid in the derived class...
ParsedVectorVectorRealReductionReporter(const InputParameters &parameters)
std::vector< Real > & _output_reporter
output containing reduction of vector of vector into a vector
static InputParameters validParams()
Reporter containing row sum of a vector of vectors from another Reporter.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
const bool _use_t
whether time is part of the parsed expression
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:271
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...
Reporter containing operation between vectors from another Reporter.
The Reporter system is comprised of objects that can contain any number of data values.
Definition: ReporterName.h:30