www.mooseframework.org
FunctionMaterialBase.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 #include "FunctionMaterialBase.h"
8 
9 template <>
10 InputParameters
12 {
13  InputParameters params = validParams<Material>();
14  params.addClassDescription("Material to provide a function (such as a free energy)");
15  params.addParam<std::string>(
16  "f_name",
17  "F",
18  "Base name of the free energy function (used to name the material properties)");
19  return params;
20 }
21 
22 FunctionMaterialBase::FunctionMaterialBase(const InputParameters & parameters)
23  : DerivativeMaterialInterface<Material>(parameters),
24  _F_name(getParam<std::string>("f_name")),
25  _prop_F(&declareProperty<Real>(_F_name))
26 {
27  // fetch names and numbers of all coupled variables
28  _mapping_is_unique = true;
29  for (std::set<std::string>::const_iterator it = _pars.coupledVarsBegin();
30  it != _pars.coupledVarsEnd();
31  ++it)
32  {
33  // find the variable in the list of coupled variables
34  std::map<std::string, std::vector<MooseVariable *>>::iterator vars = _coupled_vars.find(*it);
35 
36  // no MOOSE variable was provided for this coupling, add to a list of variables set to constant
37  // default values
38  if (vars == _coupled_vars.end())
39  {
40  if (_pars.hasDefaultCoupledValue(*it))
41  _arg_constant_defaults.push_back(*it);
42  continue;
43  }
44 
45  // check if we have a 1:1 mapping between parameters and variables
46  if (vars->second.size() != 1)
47  _mapping_is_unique = false;
48 
49  // iterate over all components
50  for (unsigned int j = 0; j < vars->second.size(); ++j)
51  {
52  // make sure each nonlinear variable is coupled in only once
53  if (std::find(_arg_names.begin(), _arg_names.end(), vars->second[j]->name()) !=
54  _arg_names.end())
55  mooseError("A nonlinear variable can only be coupled in once.");
56 
57  // insert the map values
58  // unsigned int number = vars->second[j]->number();
59  unsigned int number = coupled(*it, j);
60  _arg_names.push_back(vars->second[j]->name());
61  _arg_numbers.push_back(number);
62  _arg_param_names.push_back(*it);
63 
64  // populate number -> arg index lookup table
65  unsigned int idx = libMeshVarNumberRemap(number);
66  if (idx >= _arg_index.size())
67  _arg_index.resize(idx + 1, -1);
68 
69  _arg_index[idx] = _args.size();
70 
71  // get variable value
72  _args.push_back(&coupledValue(*it, j));
73  }
74  }
75 
76  _nargs = _arg_names.size();
77 }
FunctionMaterialBase(const InputParameters &parameters)
std::vector< std::string > _arg_constant_defaults
coupled variables with default values
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...
unsigned int _nargs
Number of coupled arguments.
InputParameters validParams< FunctionMaterialBase >()
unsigned int libMeshVarNumberRemap(unsigned int var) const
map the variable numbers to an even/odd interspersed pattern
std::vector< const VariableValue * > _args
Coupled variables for function arguments.
std::vector< std::string > _arg_names
String vector of all argument names.
bool _mapping_is_unique
Flag that indicates if exactly one linear variable is coupled per input file coupling parameter...
std::vector< unsigned int > _arg_numbers
Vector of all argument MOOSE variable numbers.