https://mooseframework.inl.gov
ParsedVectorReporter.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 
10 #include "ParsedVectorReporter.h"
11 
13 
16 {
18  params.addClassDescription("Apply parsed functions to vector entries held in reporters.");
19  params.addRequiredParam<std::vector<ReporterName>>("vector_reporter_names",
20  "Reporter names to apply function to.");
21  return params;
22 }
23 
25  : ParsedReporterBase(parameters),
26  _output_reporter(
27  declareValueByName<std::vector<Real>>(getParam<std::string>("name"), REPORTER_MODE_ROOT))
28 {
29  const std::vector<ReporterName> reporter_names(
30  getParam<std::vector<ReporterName>>("vector_reporter_names"));
31  if (reporter_names.size() != _vector_reporter_symbols.size())
32  paramError("vector_reporter_names",
33  "vector_reporter_names and vector_reporter_symbols must be the same size: Number "
34  "of vector_reporter_names=",
35  reporter_names.size(),
36  "; Number of vector_reporter_symbols=",
38 
39  _vector_reporter_data.resize(reporter_names.size());
40  for (const auto rep_index : index_range(_vector_reporter_data))
41  _vector_reporter_data[rep_index] =
42  &getReporterValueByName<std::vector<Real>>(reporter_names[rep_index], REPORTER_MODE_ROOT);
43 }
44 
45 void
47 {
48  // check vector sizes of reporters
49  const std::size_t entries(_vector_reporter_data[0]->size());
50  for (const auto rep_index : index_range(_vector_reporter_data))
51  if (entries != _vector_reporter_data[rep_index]->size())
52  {
53  const std::vector<ReporterName> reporter_names(
54  getParam<std::vector<ReporterName>>("vector_reporter_names"));
55  mooseError("All vectors being operated on must be the same size.",
56  "\nsize of ",
57  reporter_names[0].getCombinedName(),
58  " = ",
59  entries,
60  "\nsize of ",
61  reporter_names[rep_index].getCombinedName(),
62  " = ",
63  _vector_reporter_data[rep_index]->size());
64  }
65 
66  _output_reporter.resize(entries, 0.0);
67  for (const auto i : make_range(entries))
68  {
69  // this is the same order they are added to the symbol string in ParsedReporterBase
70  // first get vector data
71  for (const auto rep_index : index_range(_vector_reporter_data))
72  _func_params[rep_index] = _vector_reporter_data[rep_index]->at(i);
73  // next get scalar data
74  for (const auto rep_index : index_range(_scalar_reporter_data))
75  _func_params[_vector_reporter_data.size() + rep_index] = *(_scalar_reporter_data[rep_index]);
76 
77  if (_use_t)
79 
81  }
82 }
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
registerMooseObject("MooseApp", ParsedVectorReporter)
Reporter containing operation between vectors from another Reporter.
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 T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseBase.h:388
std::vector< const std::vector< Real > * > _vector_reporter_data
input reporter vectors
const T & getReporterValueByName(const ReporterName &reporter_name, const std::size_t time_index=0)
Returns read-only reference to a Reporter value that is provided by name directly.
const ReporterMode REPORTER_MODE_ROOT
std::vector< const Real * > _scalar_reporter_data
input scalar reporter vectors
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::vector< double > & _output_reporter
output vector
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...
ParsedVectorReporter(const InputParameters &parameters)
static InputParameters validParams()
static InputParameters validParams()
const std::vector< std::string > _vector_reporter_symbols
Get symbols to corresponding reporter names need symbols because reporter names have a "/" and that w...
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.
virtual void finalize() override
Finalize.
auto index_range(const T &sizable)