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 <>
15 {
17  params.addClassDescription("Material to provide a function (such as a free energy)");
18  params.addParam<std::string>(
19  "f_name",
20  "F",
21  "Base name of the free energy function (used to name the material properties)");
22  return params;
23 }
24 
27  _F_name(getParam<std::string>("f_name")),
28  _prop_F(&declareProperty<Real>(_F_name))
29 {
30  // fetch names and numbers of all coupled variables
31  _mapping_is_unique = true;
32  for (std::set<std::string>::const_iterator it = _pars.coupledVarsBegin();
33  it != _pars.coupledVarsEnd();
34  ++it)
35  {
36  // find the variable in the list of coupled variables
37  std::map<std::string, std::vector<MooseVariableFEBase *>>::iterator vars =
38  _coupled_vars.find(*it);
39 
40  // no MOOSE variable was provided for this coupling, add to a list of variables set to constant
41  // default values
42  if (vars == _coupled_vars.end())
43  {
45  _arg_constant_defaults.push_back(*it);
46  continue;
47  }
48 
49  // check if we have a 1:1 mapping between parameters and variables
50  if (vars->second.size() != 1)
51  _mapping_is_unique = false;
52 
53  // iterate over all components
54  for (unsigned int j = 0; j < vars->second.size(); ++j)
55  {
56  // make sure each nonlinear variable is coupled in only once
57  if (std::find(_arg_names.begin(), _arg_names.end(), vars->second[j]->name()) !=
58  _arg_names.end())
59  mooseError("A nonlinear variable can only be coupled in once.");
60 
61  // insert the map values
62  // unsigned int number = vars->second[j]->number();
63  unsigned int number = coupled(*it, j);
64  _arg_names.push_back(vars->second[j]->name());
65  _arg_numbers.push_back(number);
66  _arg_param_names.push_back(*it);
67 
68  // populate number -> arg index lookup table
69  unsigned int idx = libMeshVarNumberRemap(number);
70  if (idx >= _arg_index.size())
71  _arg_index.resize(idx + 1, -1);
72 
73  _arg_index[idx] = _args.size();
74 
75  // get variable value
76  _args.push_back(&coupledValue(*it, j));
77  }
78  }
79 
80  _nargs = _arg_names.size();
81 }
FunctionMaterialBase(const InputParameters &parameters)
std::vector< std::string > _arg_constant_defaults
coupled variables with default values
unsigned int libMeshVarNumberRemap(unsigned int var) const
map the variable numbers to an even/odd interspersed pattern
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_param_names
String vector of the input file coupling parameter name for each argument.
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
std::vector< unsigned int > _arg_index
Vector to look up the internal coupled variable index into arg* through the libMesh variable number...
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.
unsigned int _nargs
Number of coupled arguments.
InputParameters validParams< FunctionMaterialBase >()
std::map< std::string, std::vector< MooseVariableFEBase * > > _coupled_vars
Coupled vars whose values we provide.
Definition: Coupleable.h:737
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
Definition: MooseObject.h:174
virtual const VariableValue & coupledValue(const std::string &var_name, unsigned int comp=0)
Returns value of a coupled variable.
Definition: Coupleable.C:361
Materials compute MaterialProperties.
Definition: Material.h:46
Interface class ("Veneer") to provide generator methods for derivative material property names...
std::vector< const VariableValue * > _args
Coupled variables for function arguments.
std::vector< std::string > _arg_names
String vector of all argument names.
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...
bool _mapping_is_unique
Flag that indicates if exactly one linear variable is coupled per input file coupling parameter...
InputParameters validParams< Material >()
Definition: Material.C:22
std::vector< unsigned int > _arg_numbers
Vector of all argument MOOSE variable numbers.
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0)
Returns the index for a coupled variable by name.
Definition: Coupleable.C:253