https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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
45void
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}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObject("MooseApp", ParsedVectorReporter)
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 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.
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
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition MooseBase.h:406
Reporter containing operation between vectors from another Reporter.
const std::vector< std::string > _vector_reporter_symbols
Get symbols to corresponding reporter names need symbols because reporter names have a "/" and that w...
const bool _use_t
whether time is part of the parsed expression
SymFunctionPtr _func_F
function parser object
std::vector< const Real * > _scalar_reporter_data
input scalar reporter vectors
static InputParameters validParams()
Reporter containing operation between vectors from another Reporter.
ParsedVectorReporter(const InputParameters &parameters)
virtual void finalize() override
Finalize.
std::vector< double > & _output_reporter
output vector
std::vector< const std::vector< Real > * > _vector_reporter_data
input reporter vectors
static InputParameters validParams()
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.