https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ParsedPostprocessor.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 "ParsedPostprocessor.h"
11
13
16{
19
20 params.addRequiredCustomTypeParam<std::string>(
21 "expression", "FunctionExpression", "function expression");
22
23 params.addParam<std::vector<PostprocessorName>>("pp_names", {}, "Post-processors arguments");
24 params.addParam<std::vector<std::string>>(
25 "pp_symbols", {}, "Symbol associated with each post-processor argument");
26 params.addParam<std::vector<std::string>>(
27 "constant_names",
28 {},
29 "Vector of constants used in the parsed function (use this for kB etc.)");
30 params.addParam<std::vector<std::string>>(
31 "constant_expressions",
32 {},
33 "Vector of values for the constants in constant_names (can be an FParser expression)");
34 params.addParam<bool>(
35 "use_t", false, "Make time (t) variable available in the function expression.");
36
37 params.addClassDescription("Computes a parsed expression with post-processors");
38 return params;
39}
40
42 : GeneralPostprocessor(parameters),
43 FunctionParserUtils(parameters),
44 _n_pp(coupledPostprocessors("pp_names")),
45 _use_t(getParam<bool>("use_t")),
46 _value(0.0)
47{
48 // build postprocessors argument
49 std::string postprocessors;
50
51 const std::vector<std::string> pp_symbols = getParam<std::vector<std::string>>("pp_symbols");
52 // sanity checks
53 if (!pp_symbols.empty() && (pp_symbols.size() != _n_pp))
54 paramError("pp_symbols", "pp_symbols must be the same length as pp_names.");
55
56 // coupled postprocessors with capacity for symbol inputs
57 std::vector<PostprocessorName> pp_names = getParam<std::vector<PostprocessorName>>("pp_names");
58 if (pp_symbols.empty())
59 {
60 for (std::size_t i = 0; i < _n_pp; ++i)
61 postprocessors += (i == 0 ? "" : ",") + pp_names[i];
62 }
63 else
64 postprocessors = MooseUtils::stringJoin(pp_symbols, ",");
65
66 // add time if required
67 if (_use_t)
68 postprocessors += (postprocessors.empty() ? "" : ",") + std::string("t");
69
70 // Create parsed function
71 _func_F = std::make_shared<SymFunction>();
73 getParam<std::string>("expression"),
74 postprocessors,
75 getParam<std::vector<std::string>>("constant_names"),
76 getParam<std::vector<std::string>>("constant_expressions"),
77 comm());
78
79 // reserve storage for parameter passing buffer
80 _func_params.resize(_n_pp + _use_t);
81 _pp_values.resize(_n_pp);
82 for (unsigned int i = 0; i < _n_pp; i++)
83 _pp_values[i] = &getPostprocessorValue("pp_names", i);
84}
85
86void
90
91void
95
96void
98{
99 for (unsigned int i = 0; i < _n_pp; i++)
100 _func_params[i] = *_pp_values[i];
101
102 if (_use_t)
104
106}
107
110{
111 return _value;
112}
Real PostprocessorValue
various MOOSE typedefs
Definition MooseTypes.h:230
registerMooseObject("MooseApp", ParsedPostprocessor)
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
void parsedFunctionSetup(SymFunctionPtr &function, const std::string &expression, const std::string &variables, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions, const libMesh::Parallel::Communicator &comm) const
Performs setup steps on a SymFunction.
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
static InputParameters validParams()
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredCustomTypeParam(const std::string &name, const std::string &custom_type, const std::string &doc_string)
These methods add an option parameter and with a customer type to the InputParameters object.
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
Postprocessor that evaluates a parsed function expression.
const unsigned int _n_pp
number of postprocessors in parsed expression
ParsedPostprocessor(const InputParameters &parameters)
virtual void initialize() override final
Called before execute() is ever called so that data can be cleared.
Real _value
This post-processor value.
virtual void finalize() override final
This is called after execute() and after threadJoin()! This is probably where you want to do MPI comm...
virtual void execute() override final
Execute method.
virtual PostprocessorValue getValue() const override final
This will get called to actually grab the final value the postprocessor has calculated.
const bool _use_t
whether time is part of the parsed expression
std::vector< const PostprocessorValue * > _pp_values
values of the postprocessors part of the parsed expression
SymFunctionPtr _func_F
function parser object for the resudual and on-diagonal Jacobian
static InputParameters validParams()
const PostprocessorValue & getPostprocessorValue(const std::string &param_name, const unsigned int index=0) const
doco-normal-methods-begin Retrieve the value of a Postprocessor or one of it's old or older values
const Parallel::Communicator & comm() const
std::string stringJoin(const std::vector< std::string > &values, const std::string &separator=" ")
Concatenates value into a single string separated by separator.