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");
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 _pexp(getParam<std::string>("expression")),
46 _oldexp(getParam<std::string>("expression")),
47 _pcnames(getParam<std::vector<std::string>>("constant_names")),
48 _pcexps(getParam<std::vector<std::string>>("constant_expressions")),
49 _use_t(getParam<bool>("use_t")),
50 _value(0.0),
51 _postprocessors("")
52{
53 // build postprocessors argument
54 const std::vector<std::string> pp_symbols = getParam<std::vector<std::string>>("pp_symbols");
55 // sanity checks
56 if (!pp_symbols.empty() && (pp_symbols.size() != _n_pp))
57 paramError("pp_symbols", "pp_symbols must be the same length as pp_names.");
58
59 // coupled postprocessors with capacity for symbol inputs
60 std::vector<PostprocessorName> pp_names = getParam<std::vector<PostprocessorName>>("pp_names");
61 if (pp_symbols.empty())
62 {
63 for (std::size_t i = 0; i < _n_pp; ++i)
64 _postprocessors += (i == 0 ? "" : ",") + pp_names[i];
65 }
66 else
67 _postprocessors = MooseUtils::stringJoin(pp_symbols, ",");
68
69 // add time if required
70 if (_use_t)
71 _postprocessors += (_postprocessors.empty() ? "" : ",") + std::string("t");
72
73 // Create parsed function
74 _func_F = std::make_shared<SymFunction>();
76 getParam<std::string>("expression"),
78 getParam<std::vector<std::string>>("constant_names"),
79 getParam<std::vector<std::string>>("constant_expressions"),
80 comm());
81
82 // reserve storage for parameter passing buffer
83 _func_params.resize(_n_pp + _use_t);
84 _pp_values.resize(_n_pp);
85 for (unsigned int i = 0; i < _n_pp; i++)
86 _pp_values[i] = &getPostprocessorValue("pp_names", i);
87}
88
89void
93
94void
103
104void
106{
107 for (unsigned int i = 0; i < _n_pp; i++)
108 _func_params[i] = *_pp_values[i];
109
110 if (_use_t)
112
114}
115
118{
119 return _value;
120}
Real PostprocessorValue
various MOOSE typedefs
Definition MooseTypes.h:230
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition Moose.C:38
const ExecFlagType EXEC_INITIAL
Definition Moose.C:31
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 declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
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
const std::vector< std::string > & _pcexps
Reference to constant_expressions.
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
const std::string & _pexp
Reference to the expression.
std::string _postprocessors
Postprocessors argument for JIT compile.
std::vector< const PostprocessorValue * > _pp_values
values of the postprocessors part of the parsed expression
SymFunctionPtr _func_F
function parser object for the residual and on-diagonal Jacobian
static InputParameters validParams()
std::string _oldexp
previous expression saved as a string for recognizing controller intervention
const std::vector< std::string > & _pcnames
Reference to constant_names.
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.