https://mooseframework.inl.gov
ParsedVectorRealReductionReporter.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 
13 
16 {
18  params.addClassDescription(
19  "Use a parsed function to iterate through a vector and reduce it to a scalar.");
20  params.addRequiredParam<ReporterName>("vector_reporter_name",
21  "Reporter name with vector to reduce.");
22  params.addRequiredParam<Real>("initial_reduction_value",
23  "Value to intialize the reduction with.");
24 
25  // reporter_symbols are the two symbols for reduction value and current value for the reduction
26  // operation, these symbols are enforced in the constructor with a mooseError
27  params.set<std::vector<std::string>>("vector_reporter_symbols") = {"reduction_value",
28  "indexed_value"};
29  params.suppressParameter<std::vector<std::string>>("vector_reporter_symbols");
30  params.suppressParameter<std::vector<std::string>>("scalar_reporter_symbols");
31 
32  return params;
33 }
34 
36  const InputParameters & parameters)
37  : ParsedReporterBase(parameters),
38  _initial_reduction_value(getParam<Real>("initial_reduction_value")),
39  _vector_reporter_data(
40  getReporterValueByName<std::vector<Real>>(getParam<ReporterName>("vector_reporter_name"))),
41  _output_reporter(declareValueByName<Real>(getParam<std::string>("name"), REPORTER_MODE_ROOT))
42 {
43  // parse function
44  std::string function = getParam<std::string>("expression");
45  // make sure the expression has the two required variables, vi and vplus
46  if (function.find("reduction_value") == std::string::npos ||
47  function.find("indexed_value") == std::string::npos)
48  paramError(
49  "expression",
50  "Parsed function must contain the two symbols 'reduction_value' and 'indexed_value'.");
51 }
52 
53 void
55 {
56  Real reduction = _initial_reduction_value;
57  for (const auto i : index_range(_vector_reporter_data))
58  {
59  _func_params[0] = reduction;
61 
62  if (_use_t)
63  _func_params[2] = _t;
64 
65  reduction = evaluate(_func_F);
66  }
67  _output_reporter = reduction;
68 }
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
Reporter performing a reduction on a vector using a parsed function.
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
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.
Real & _output_reporter
output containing reduction of vector into a scalar
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...
ParsedVectorRealReductionReporter(const InputParameters &parameters)
const std::vector< Real > & _vector_reporter_data
Vector being operated on.
static InputParameters validParams()
registerMooseObject("MooseApp", ParsedVectorRealReductionReporter)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void finalize() override
Finalize.
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
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.
auto index_range(const T &sizable)
The Reporter system is comprised of objects that can contain any number of data values.
Definition: ReporterName.h:30