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 #define usingParsedMaterialHelperMembers(T) \
20  usingFunctionMaterialBaseMembers(T); \
21  usingFunctionParserUtilsMembers(T); \
22  using typename ParsedMaterialHelper<T>::VariableNameMappingMode; \
23  using typename ParsedMaterialHelper<T>::MatPropDescriptorList; \
24  using ParsedMaterialHelper<T>::functionParse; \
25  using ParsedMaterialHelper<T>::functionsPostParse; \
26  using ParsedMaterialHelper<T>::_func_F; \
27  using ParsedMaterialHelper<T>::_symbol_names; \
28  using ParsedMaterialHelper<T>::_mat_prop_descriptors; \
29  using ParsedMaterialHelper<T>::_tol; \
30  using ParsedMaterialHelper<T>::_postprocessor_values; \
31  using ParsedMaterialHelper<T>::_extra_symbols; \
32  using ParsedMaterialHelper<T>::_functors; \
33  using ParsedMaterialHelper<T>::_map_mode
34 
39 template <bool is_ad>
41 {
42 public:
44 
46  {
49  };
50 
51  enum class ExtraSymbols
52  {
53  x,
54  y,
55  z,
56  t,
57  dt
58  };
59 
61 
63 
70  void functionParse(const std::string & function_expression);
71 
82  void functionParse(const std::string & function_expression,
83  const std::vector<std::string> & constant_names,
84  const std::vector<std::string> & constant_expressions);
85 
100  void functionParse(const std::string & function_expression,
101  const std::vector<std::string> & constant_names,
102  const std::vector<std::string> & constant_expressions,
103  const std::vector<std::string> & mat_prop_names,
104  const std::vector<std::string> & tol_names,
105  const std::vector<Real> & tol_values);
106 
121  void functionParse(const std::string & function_expression,
122  const std::vector<std::string> & constant_names,
123  const std::vector<std::string> & constant_expressions,
124  const std::vector<std::string> & mat_prop_names,
125  const std::vector<PostprocessorName> & postprocessor_names,
126  const std::vector<std::string> & tol_names,
127  const std::vector<Real> & tol_values);
128 
145  void functionParse(const std::string & function_expression,
146  const std::vector<std::string> & constant_names,
147  const std::vector<std::string> & constant_expressions,
148  const std::vector<std::string> & mat_prop_names,
149  const std::vector<PostprocessorName> & postprocessor_names,
150  const std::vector<std::string> & tol_names,
151  const std::vector<Real> & tol_values,
152  const std::vector<MooseFunctorName> & functor_names,
153  const std::vector<std::string> & functor_symbols);
154 
155 protected:
158 
159  void initQpStatefulProperties() override;
160  void computeQpProperties() override;
161  virtual void initialSetup() override final;
162 
166  void insertReservedNames(std::set<std::string> & reserved_names);
167 
168  // tasks to perform after parsing the primary function
169  virtual void functionsPostParse();
170 
173 
180 
183 
185  std::vector<const Moose::Functor<Real> *> _functors;
186 
189 
192 
194  std::vector<Real> _tol;
195 
198 
206 
211  std::vector<MaterialName> _upstream_mat_names;
212 
215 
221 };
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.
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...
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
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.
const InputParameters & parameters() const
Get the parameters of the 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
ParsedMaterialHelper(const InputParameters &parameters, VariableNameMappingMode map_mode)
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