https://mooseframework.inl.gov
ParsedMaterialHelper.h
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 #pragma once
11 
12 #include "FunctionMaterialBase.h"
13 #include "FunctionParserUtils.h"
16 
17 #include "libmesh/fparser_ad.hh"
18 
19 #include <optional>
20 
21 #define usingParsedMaterialHelperMembers(T) \
22  usingFunctionMaterialBaseMembers(T); \
23  usingFunctionParserUtilsMembers(T); \
24  using typename ParsedMaterialHelper<T>::VariableNameMappingMode; \
25  using typename ParsedMaterialHelper<T>::MatPropDescriptorList; \
26  using ParsedMaterialHelper<T>::functionParse; \
27  using ParsedMaterialHelper<T>::functionsPostParse; \
28  using ParsedMaterialHelper<T>::_func_F; \
29  using ParsedMaterialHelper<T>::_symbol_names; \
30  using ParsedMaterialHelper<T>::_mat_prop_descriptors; \
31  using ParsedMaterialHelper<T>::_tol; \
32  using ParsedMaterialHelper<T>::_postprocessor_values; \
33  using ParsedMaterialHelper<T>::_extra_symbols; \
34  using ParsedMaterialHelper<T>::_functors; \
35  using ParsedMaterialHelper<T>::_map_mode
36 
41 template <bool is_ad>
43 {
44 public:
46 
48  {
51  };
52 
53  enum class ExtraSymbols
54  {
55  x,
56  y,
57  z,
58  t,
59  dt
60  };
61 
63  const VariableNameMappingMode map_mode,
64  const std::optional<std::string> & function_param_name = {});
65 
67 
74  void functionParse(const std::string & function_expression);
75 
86  void functionParse(const std::string & function_expression,
87  const std::vector<std::string> & constant_names,
88  const std::vector<std::string> & constant_expressions);
89 
104  void functionParse(const std::string & function_expression,
105  const std::vector<std::string> & constant_names,
106  const std::vector<std::string> & constant_expressions,
107  const std::vector<std::string> & mat_prop_names,
108  const std::vector<std::string> & tol_names,
109  const std::vector<Real> & tol_values);
110 
125  void functionParse(const std::string & function_expression,
126  const std::vector<std::string> & constant_names,
127  const std::vector<std::string> & constant_expressions,
128  const std::vector<std::string> & mat_prop_names,
129  const std::vector<PostprocessorName> & postprocessor_names,
130  const std::vector<std::string> & tol_names,
131  const std::vector<Real> & tol_values);
132 
149  void functionParse(const std::string & function_expression,
150  const std::vector<std::string> & constant_names,
151  const std::vector<std::string> & constant_expressions,
152  const std::vector<std::string> & mat_prop_names,
153  const std::vector<PostprocessorName> & postprocessor_names,
154  const std::vector<std::string> & tol_names,
155  const std::vector<Real> & tol_values,
156  const std::vector<MooseFunctorName> & functor_names,
157  const std::vector<std::string> & functor_symbols);
158 
159 protected:
162 
163  void initQpStatefulProperties() override;
164  void computeQpProperties() override;
165  virtual void initialSetup() override final;
166 
170  void insertReservedNames(std::set<std::string> & reserved_names);
171 
172  // tasks to perform after parsing the primary function
173  virtual void functionsPostParse();
174 
177 
184 
187 
189  std::vector<const Moose::Functor<Real> *> _functors;
190 
193 
196 
198  std::vector<Real> _tol;
199 
202 
210 
212  const std::optional<std::string> _function_param_name;
213 
218  std::vector<MaterialName> _upstream_mat_names;
219 
222 
228 
229 private:
231  void parseError(const std::string & message) const;
232 
235 };
void insertReservedNames(std::set< std::string > &reserved_names)
Populates the given set with names not to be used as user-defined symbol (e.g.
std::vector< MaterialBase * > _upstream_mat
Vector to hold list of materials that must be updated prior to evaluating current material (for compu...
virtual void initialSetup() override final
Gets called at the beginning of the simulation before this object is asked to do its job...
std::shared_ptr< SymFunction > SymFunctionPtr
Shorthand for an smart pointer to an autodiff function parser object.
ParsedMaterialHelper(const InputParameters &parameters, const VariableNameMappingMode map_mode, const std::optional< std::string > &function_param_name={})
std::vector< const Moose::Functor< Real > * > _functors
Vector of pointers to functors.
Material properties get fully described using this structure, including their dependent variables and...
std::vector< SymbolName > _symbol_names
Symbol names used in the expression (depends on the map_mode).
void computeQpProperties() override
Users must override this method.
Material base class, central to all Materials that provide a Function as a material property value...
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:127
const InputParameters & _params
The underlying parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MatPropDescriptorList _mat_prop_descriptors
Material property descriptors (obtained by parsing _mat_prop_expressions)
usingFunctionMaterialBaseMembers(is_ad)
usingFunctionParserUtilsMembers(is_ad)
static InputParameters validParams()
std::vector< const PostprocessorValue * > _postprocessor_values
List of coupled Postprocessors.
FunctorEnvelope< T > Functor
DerivativeMaterialPropertyNameInterface::SymbolName SymbolName
Real PostprocessorValue
various MOOSE typedefs
Definition: MooseTypes.h:202
void parseError(const std::string &message) const
Helper for reporting a parse error with a much as context as possible.
const std::vector< ExtraSymbols > _extra_symbols
Extra symbols.
const VariableNameMappingMode _map_mode
Flag to indicate if MOOSE nonlinear variable names should be used as FParser variable names...
void initQpStatefulProperties() override
Initialize stateful properties at quadrature points.
std::vector< Real > _tol
Tolerance values for all arguments (to protect from log(0)).
std::vector< MaterialName > _upstream_mat_names
Vector to hold list of material names that must be updated prior to evaluating current material (for ...
Helper class to perform the parsing and optimization of the function expression.
const bool _error_on_missing_material_properties
This is true by default, but can be disabled to make non-existing properties default to zero...
SymFunctionPtr _func_F
The undiffed free energy function parser object.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:62
virtual void functionsPostParse()
void functionParse(const std::string &function_expression)
This method sets up and parses the function string given by the user.
std::vector< FunctionMaterialPropertyDescriptor< is_ad > > MatPropDescriptorList
convenience typedef for the material property descriptors
const std::optional< std::string > _function_param_name
Optional parameter name that represents the function to associate errors with.