https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FunctionMaterialBase.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
12template <bool is_ad>
15{
17 params.addClassDescription("Material providing a functionalized/parsed material property");
18
19 params.addDeprecatedParam<std::string>(
20 "f_name", "Name of the parsed material property", "f_name is deprecated, use property_name");
21 // TODO Make required once deprecation is handled, see #19119
22 params.addParam<std::string>("property_name", "F", "Name of the parsed material property");
23 return params;
24}
25
26template <bool is_ad>
29 _F_name(getRenamedParam<std::string>("f_name", "property_name")),
30 _prop_F(&declareGenericProperty<Real, is_ad>(_F_name))
31{
32 // fetch names and numbers of all coupled variables
33 _mapping_is_unique = true;
34 for (const auto & var_param : _pars.getCoupledVariableParamNames())
35 {
36 // find the variable in the list of coupled variables
37 const auto it = _coupled_vars.find(var_param);
38
39 // no MOOSE variable was provided for this coupling, add to a list of variables set to constant
40 // default values
41 if (it == _coupled_vars.end())
42 {
43 if (_pars.hasDefaultCoupledValue(var_param))
44 _arg_constant_defaults.push_back(var_param);
45 continue;
46 }
47 const auto & vars = it->second;
48
49 // check if we have a 1:1 mapping between parameters and variables
50 if (vars.size() != 1)
51 _mapping_is_unique = false;
52
53 // iterate over all components
54 for (const auto comp : index_range(vars))
55 {
56 mooseAssert(vars[comp], "Null variable");
57 const auto & var_name = vars[comp]->name();
58 // make sure each nonlinear variable is coupled in only once
59 if (std::find(_arg_names.begin(), _arg_names.end(), var_name) != _arg_names.end())
60 mooseError("A nonlinear variable can only be coupled in once.");
61
62 // insert the map values
63 const auto number = coupled(var_param, comp);
64 _arg_names.push_back(var_name);
65 _arg_numbers.push_back(number);
66 _arg_param_names.push_back(var_param);
67 if (_mapping_is_unique)
68 _arg_param_numbers.push_back(-1);
69 else
70 _arg_param_numbers.push_back(comp);
71
72 // populate number -> arg index lookup table
73 const auto idx = libMeshVarNumberRemap(number);
74 if (idx >= _arg_index.size())
75 _arg_index.resize(idx + 1, -1);
76
77 _arg_index[idx] = _args.size();
78
79 // get variable value
80 _args.push_back(&coupledGenericValue(var_param, comp));
81 }
82 }
83
84 _nargs = _arg_names.size();
85}
86
87template <bool is_ad>
89FunctionMaterialBase<is_ad>::coupledGenericValue(const std::string & var_name, unsigned int comp)
90{
91 return coupledValue(var_name, comp);
92}
93
94template <>
96FunctionMaterialBase<true>::coupledGenericValue(const std::string & var_name, unsigned int comp)
97{
98 return adCoupledValue(var_name, comp);
99}
100
101// explicit instantiation
102template class FunctionMaterialBase<false>;
103template class FunctionMaterialBase<true>;
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Moose::GenericType< VariableValue, is_ad > GenericVariableValue
Definition MooseTypes.h:712
char ** vars
Interface class ("Veneer") to provide generator methods for derivative material property names.
Material base class, central to all Materials that provide a Function as a material property value.
static InputParameters validParams()
const GenericVariableValue< is_ad > & coupledGenericValue(const std::string &var_name, unsigned int comp=0)
helper function for coupling ad/regular variable values
FunctionMaterialBase(const InputParameters &parameters)
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 addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
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.
Materials compute MaterialProperties.
Definition Material.h:36
static InputParameters validParams()
Definition Material.C:14
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
auto index_range(const T &sizable)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real