https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 "MooseEnum.h"
14#include "FunctionParserUtils.h"
17
18#include "libmesh/fparser_ad.hh"
19
20#include <optional>
21
22#define usingParsedMaterialHelperMembers(T) \
23 usingFunctionMaterialBaseMembers(T); \
24 usingFunctionParserUtilsMembers(T); \
25 using typename ParsedMaterialHelper<T>::VariableNameMappingMode; \
26 using typename ParsedMaterialHelper<T>::MatPropDescriptorList; \
27 using ParsedMaterialHelper<T>::functionParse; \
28 using ParsedMaterialHelper<T>::functionsPostParse; \
29 using ParsedMaterialHelper<T>::_func_F; \
30 using ParsedMaterialHelper<T>::_symbol_names; \
31 using ParsedMaterialHelper<T>::_mat_prop_descriptors; \
32 using ParsedMaterialHelper<T>::_tol; \
33 using ParsedMaterialHelper<T>::_postprocessor_values; \
34 using ParsedMaterialHelper<T>::_extra_symbols; \
35 using ParsedMaterialHelper<T>::_functors; \
36 using ParsedMaterialHelper<T>::_map_mode
37
42template <bool is_ad>
44{
45public:
47
48 CreateMooseEnumClass(VariableNameMappingMode, USE_MOOSE_NAMES, USE_PARAM_NAMES);
49 CreateMooseEnumClass(ExtraSymbols, x, y, z, t, dt);
50
52 const VariableNameMappingMode map_mode,
53 const std::optional<std::string> & function_param_name = {});
54
56
63 void functionParse(const std::string & function_expression);
64
75 void functionParse(const std::string & function_expression,
76 const std::vector<std::string> & constant_names,
77 const std::vector<std::string> & constant_expressions);
78
93 void functionParse(const std::string & function_expression,
94 const std::vector<std::string> & constant_names,
95 const std::vector<std::string> & constant_expressions,
96 const std::vector<std::string> & mat_prop_names,
97 const std::vector<std::string> & tol_names,
98 const std::vector<Real> & tol_values);
99
114 void functionParse(const std::string & function_expression,
115 const std::vector<std::string> & constant_names,
116 const std::vector<std::string> & constant_expressions,
117 const std::vector<std::string> & mat_prop_names,
118 const std::vector<PostprocessorName> & postprocessor_names,
119 const std::vector<std::string> & tol_names,
120 const std::vector<Real> & tol_values);
121
138 void functionParse(const std::string & function_expression,
139 const std::vector<std::string> & constant_names,
140 const std::vector<std::string> & constant_expressions,
141 const std::vector<std::string> & mat_prop_names,
142 const std::vector<PostprocessorName> & postprocessor_names,
143 const std::vector<std::string> & tol_names,
144 const std::vector<Real> & tol_values,
145 const std::vector<MooseFunctorName> & functor_names,
146 const std::vector<std::string> & functor_symbols);
147
148protected:
151
152 void initQpStatefulProperties() override;
153 void computeQpProperties() override;
154 virtual void initialSetup() override final;
155
159 void insertReservedNames(std::set<std::string> & reserved_names);
160
161 // tasks to perform after parsing the primary function
162 virtual void functionsPostParse();
163
166
173
175 const std::vector<ExtraSymbols> _extra_symbols;
176
178 std::vector<const Moose::Functor<Real> *> _functors;
179
182
185
187 std::vector<Real> _tol;
188
191
198 const VariableNameMappingMode _map_mode;
199
201 const std::optional<std::string> _function_param_name;
202
207 std::vector<MaterialName> _upstream_mat_names;
208
211
217
218private:
220 void parseError(const std::string & message) const;
221
224};
Real PostprocessorValue
various MOOSE typedefs
Definition MooseTypes.h:230
Material base class, central to all Materials that provide a Function as a material property value.
Material properties get fully described using this structure, including their dependent variables and...
std::shared_ptr< SymFunction > SymFunctionPtr
Shorthand for an smart pointer to an autodiff function parser object.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
MaterialBases compute MaterialProperties.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
Helper class to perform the parsing and optimization of the function expression.
virtual void initialSetup() override final
Gets called at the beginning of the simulation before this object is asked to do its job.
const VariableNameMappingMode _map_mode
Flag to indicate if MOOSE nonlinear variable names should be used as FParser variable names.
std::vector< const PostprocessorValue * > _postprocessor_values
List of coupled Postprocessors.
void initQpStatefulProperties() override
Initialize stateful properties at quadrature points.
void computeQpProperties() override
Users must override this method.
MatPropDescriptorList _mat_prop_descriptors
Material property descriptors (obtained by parsing _mat_prop_expressions)
const std::vector< ExtraSymbols > _extra_symbols
Extra symbols.
void parseError(const std::string &message) const
Helper for reporting a parse error with a much as context as possible.
void insertReservedNames(std::set< std::string > &reserved_names)
Populates the given set with names not to be used as user-defined symbol (e.g.
usingFunctionMaterialBaseMembers(is_ad)
usingFunctionParserUtilsMembers(is_ad)
virtual void functionsPostParse()
DerivativeMaterialPropertyNameInterface::SymbolName SymbolName
std::vector< const Moose::Functor< Real > * > _functors
Vector of pointers to functors.
const std::optional< std::string > _function_param_name
Optional parameter name that represents the function to associate errors with.
SymFunctionPtr _func_F
The undiffed free energy function parser object.
std::vector< MaterialBase * > _upstream_mat
Vector to hold list of materials that must be updated prior to evaluating current material (for compu...
const bool _error_on_missing_material_properties
This is true by default, but can be disabled to make non-existing properties default to zero.
static InputParameters validParams()
std::vector< Real > _tol
Tolerance values for all arguments (to protect from log(0)).
CreateMooseEnumClass(ExtraSymbols, x, y, z, t, dt)
CreateMooseEnumClass(VariableNameMappingMode, USE_MOOSE_NAMES, USE_PARAM_NAMES)
std::vector< MaterialName > _upstream_mat_names
Vector to hold list of material names that must be updated prior to evaluating current material (for ...
void functionParse(const std::string &function_expression)
This method sets up and parses the function string given by the user.
const InputParameters & _params
The underlying parameters.
std::vector< SymbolName > _symbol_names
Symbol names used in the expression (depends on the map_mode).
std::vector< FunctionMaterialPropertyDescriptor< is_ad > > MatPropDescriptorList
convenience typedef for the material property descriptors
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...