www.mooseframework.org
FunctionMaterialBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #include "FunctionMaterialBase.h"
11 
12 template <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 
26 template <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 (std::set<std::string>::const_iterator it = _pars.coupledVarsBegin();
35  it != _pars.coupledVarsEnd();
36  ++it)
37  {
38  // find the variable in the list of coupled variables
39  auto vars = _coupled_vars.find(*it);
40 
41  // no MOOSE variable was provided for this coupling, add to a list of variables set to constant
42  // default values
43  if (vars == _coupled_vars.end())
44  {
46  _arg_constant_defaults.push_back(*it);
47  continue;
48  }
49 
50  // check if we have a 1:1 mapping between parameters and variables
51  if (vars->second.size() != 1)
52  _mapping_is_unique = false;
53 
54  // iterate over all components
55  for (unsigned int j = 0; j < vars->second.size(); ++j)
56  {
57  // make sure each nonlinear variable is coupled in only once
58  if (std::find(_arg_names.begin(), _arg_names.end(), vars->second[j]->name()) !=
59  _arg_names.end())
60  mooseError("A nonlinear variable can only be coupled in once.");
61 
62  // insert the map values
63  // unsigned int number = vars->second[j]->number();
64  unsigned int number = coupled(*it, j);
65  _arg_names.push_back(vars->second[j]->name());
66  _arg_numbers.push_back(number);
67  _arg_param_names.push_back(*it);
69  _arg_param_numbers.push_back(-1);
70  else
71  _arg_param_numbers.push_back(j);
72 
73  // populate number -> arg index lookup table
74  unsigned int idx = libMeshVarNumberRemap(number);
75  if (idx >= _arg_index.size())
76  _arg_index.resize(idx + 1, -1);
77 
78  _arg_index[idx] = _args.size();
79 
80  // get variable value
81  _args.push_back(&coupledGenericValue(*it, j));
82  }
83  }
84 
85  _nargs = _arg_names.size();
86 }
87 
88 template <bool is_ad>
90 FunctionMaterialBase<is_ad>::coupledGenericValue(const std::string & var_name, unsigned int comp)
91 {
92  return coupledValue(var_name, comp);
93 }
94 
95 template <>
97 FunctionMaterialBase<true>::coupledGenericValue(const std::string & var_name, unsigned int comp)
98 {
99  return adCoupledValue(var_name, comp);
100 }
101 
102 // explicit instantiation
103 template class FunctionMaterialBase<false>;
104 template class FunctionMaterialBase<true>;
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0) const
Returns the index for a coupled variable by name.
Definition: Coupleable.C:437
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
typename Moose::GenericType< VariableValue, is_ad > GenericVariableValue
Definition: MooseTypes.h:573
std::unordered_map< std::string, std::vector< MooseVariableFieldBase * > > _coupled_vars
Coupled vars whose values we provide.
Definition: Coupleable.h:1324
std::vector< unsigned int > _arg_numbers
Vector of all argument MOOSE variable numbers.
Material base class, central to all Materials that provide a Function as a material property value...
const GenericVariableValue< is_ad > & coupledGenericValue(const std::string &var_name, unsigned int comp=0)
helper function for coupling ad/regular variable values
std::vector< int > _arg_param_numbers
bool _mapping_is_unique
Flag that indicates if exactly one linear variable is coupled per input file coupling parameter...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::set< std::string >::const_iterator coupledVarsBegin() const
Methods returning iterators to the coupled variables names stored in this InputParameters object...
std::vector< std::string > _arg_names
String vector of all argument names.
static InputParameters validParams()
static InputParameters validParams()
Definition: Material.C:14
std::set< std::string >::const_iterator coupledVarsEnd() const
bool hasDefaultCoupledValue(const std::string &coupling_name) const
Return whether or not the requested parameter has a default coupled value.
std::vector< std::string > _arg_constant_defaults
coupled variables with default values
FunctionMaterialBase(const InputParameters &parameters)
std::vector< std::string > _arg_param_names
String vector of the input file coupling parameter name for each argument.
std::vector< unsigned int > _arg_index
Vector to look up the internal coupled variable index into arg* through the libMesh variable number...
Materials compute MaterialProperties.
Definition: Material.h:34
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Interface class ("Veneer") to provide generator methods for derivative material property names...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
unsigned int _nargs
Number of coupled arguments.
unsigned int libMeshVarNumberRemap(unsigned int var) const
map the variable numbers to an even/odd interspersed pattern
std::vector< const GenericVariableValue< is_ad > * > _args
Coupled variables for function arguments.
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)