https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ParsedFunctorMaterial.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
14
15template <bool is_ad>
18{
22 "Computes a functor material from a parsed expression of other functors.");
23 params.addRequiredCustomTypeParam<std::string>(
24 "expression", "FunctionExpression", "Expression to parse for the new functor material");
25 params.addParam<std::vector<std::string>>(
26 "functor_names", {}, "Functors to use in the parsed expression");
27 params.addParam<std::vector<std::string>>(
28 "functor_symbols",
29 {},
30 "Symbolic name to use for each functor in 'functor_names' in the parsed expression. If not "
31 "provided, then the actual functor names must be used in the parsed expression.");
32 params.addRequiredParam<std::string>("property_name",
33 "Name to give the new functor material property");
34
35 return params;
36}
37
38template <bool is_ad>
40 : FunctorMaterial(parameters),
41 FunctionParserUtils<is_ad>(parameters),
42 _expression(getParam<std::string>("expression")),
43 _functor_names(getParam<std::vector<std::string>>("functor_names")),
44 _n_functors(_functor_names.size()),
45 _functor_symbols(getParam<std::vector<std::string>>("functor_symbols")),
46 _property_name(getParam<std::string>("property_name"))
47{
48 // Check/modify 'functor_symbols'
49 if (_functor_symbols.size() != _n_functors)
50 {
51 if (_functor_symbols.size() == 0)
53 else
54 paramError("functor_symbols",
55 "The number of entries must be equal to either zero or the number of entries in "
56 "'functor_names'.");
57 }
58
59 // Get the functors
60 _functors.resize(_n_functors);
61 for (const auto i : index_range(_functor_names))
63
64 // Build the parsed function
66
67 // Add the functor material property
68 const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end());
69 addFunctorProperty<GenericReal<is_ad>>(
71 [this](const auto & r, const auto & t) -> GenericReal<is_ad>
72 {
73 // Store the functor values
74 for (const auto i : index_range(_functors))
75 _func_params[i] = (*_functors[i])(r, t);
76
77 // Store the space and time values
78 const auto r_point = r.getPoint();
79 for (const auto i : make_range(Moose::dim))
80 _func_params[_n_functors + i] = r_point(i);
82
83 // Evaluate the parsed function
85 },
86 clearance_schedule);
87}
88
89template <bool is_ad>
90void
92{
93 _parsed_function = std::make_shared<SymFunction>();
94
95 // Collect the symbols corresponding to the _func_params values
96 std::vector<std::string> symbols(_functor_symbols);
97 std::string symbols_str = Moose::stringify(symbols);
98 if (Moose::dim == 3)
99 symbols_str += symbols_str.empty() ? "x,y,z" : ",x,y,z";
100 else
101 mooseError("ParsedFunctorMaterial assumes the dimension is always equal to 3.");
102 symbols_str += symbols_str.empty() ? "t" : ",t";
103
104 // Create parsed function
105 this->parsedFunctionSetup(_parsed_function,
106 _expression,
107 symbols_str,
108 {"pi", "e"},
109 {std::to_string(libMesh::pi), std::to_string(std::exp(Real(1)))},
110 comm());
111
112 // Resize the values vector
113 _func_params.resize(_n_functors + Moose::dim + 1);
114}
115
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Moose::GenericType< Real, is_ad > GenericReal
Definition MooseTypes.h:698
registerMooseObject("MooseApp", ParsedFunctorMaterial)
Real getTimeFromStateArg(const Moose::StateArg &state) const
Returns the time associated with the requested state.
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.
static InputParameters validParams()
const Moose::Functor< T > & getFunctor(const std::string &name)
Retrieves a functor from the subproblem.
FunctorMaterials compute functor material properties.
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 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 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.
FEProblemBase & _fe_problem
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 std::string & _name
The name of this class.
Definition MooseBase.h:381
MooseEnumIterator end() const
MooseEnumIterator begin() const
Returns a begin/end iterator to all of the set values in the enum.
Computes a functor material from a parsed expression of other functors.
void buildParsedFunction()
Builds the parsed function.
const std::vector< std::string > & _functor_names
Functors to use in the parsed expression.
SymFunctionPtr _parsed_function
The parsed function.
ParsedFunctorMaterialTempl(const InputParameters &parameters)
static InputParameters validParams()
const std::string & _property_name
Name to give the new functor material property.
const unsigned int _n_functors
Number of functors.
std::vector< std::string > _functor_symbols
Symbolic name to use for each functor.
std::vector< const Moose::Functor< GenericReal< is_ad > > * > _functors
Functors.
const ExecFlagEnum & _execute_enum
Execute settings for this object.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition Moose.h:165
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64
const Real pi