www.mooseframework.org
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
DerivativeKernelInterface< T > Class Template Reference

Interface class ("Veneer") to provide generator methods for derivative material property names, and guarded getMaterialPropertyPointer calls. More...

#include <DerivativeKernelInterface.h>

Inheritance diagram for DerivativeKernelInterface< T >:
[legend]

Public Member Functions

 DerivativeKernelInterface (const InputParameters &parameters)
 
template<typename U >
const MaterialProperty< U > & getDefaultMaterialProperty (const std::string &name)
 Fetch a material property if it exists, otherwise return getZeroMaterialProperty. More...
 
template<typename U >
const MaterialProperty< U > & getDefaultMaterialPropertyByName (const std::string &name)
 Fetch a material property by name if it exists, otherwise return getZeroMaterialProperty. More...
 
template<typename U >
void validateDerivativeMaterialPropertyBase (const std::string &base)
 Check if the material property base exists. More...
 
const MaterialPropertyName propertyName (const MaterialPropertyName &base, const std::vector< VariableName > &c) const
 Helper functions to generate the material property names for the arbitrary derivatives. More...
 
const MaterialPropertyName propertyNameFirst (const MaterialPropertyName &base, const VariableName &c1) const
 Helper functions to generate the material property names for the first derivatives. More...
 
const MaterialPropertyName propertyNameSecond (const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2) const
 Helper functions to generate the material property names for the second derivatives. More...
 
const MaterialPropertyName propertyNameThird (const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2, const VariableName &c3) const
 Helper functions to generate the material property names for the third derivatives. More...
 
template<typename U >
MaterialProperty< U > & declarePropertyDerivative (const std::string &base, const std::vector< VariableName > &c)
 Methods for declaring derivative material properties. More...
 
template<typename U >
MaterialProperty< U > & declarePropertyDerivative (const std::string &base, const VariableName &c1, const VariableName &c2="", const VariableName &c3="")
 
template<typename U >
const MaterialProperty< U > & getMaterialPropertyDerivative (const std::string &base, const std::vector< VariableName > &c)
 Methods for retreiving derivative material properties. More...
 
template<typename U >
const MaterialProperty< U > & getMaterialPropertyDerivative (const std::string &base, const VariableName &c1, const VariableName &c2="", const VariableName &c3="")
 
template<typename U >
const MaterialProperty< U > & getMaterialPropertyDerivativeByName (const MaterialPropertyName &base, const std::vector< VariableName > &c)
 Methods for retreiving derivative material properties. More...
 
template<typename U >
const MaterialProperty< U > & getMaterialPropertyDerivativeByName (const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2="", const VariableName &c3="")
 
template<typename U >
void validateCoupling (const MaterialPropertyName &base, const std::vector< VariableName > &c, bool validate_aux=true)
 check if derivatives of the passed in material property exist w.r.t a variable that is not coupled in to the current object More...
 
template<typename U >
void validateCoupling (const MaterialPropertyName &base, const VariableName &c1="", const VariableName &c2="", const VariableName &c3="")
 
template<typename U >
void validateNonlinearCoupling (const MaterialPropertyName &base, const VariableName &c1="", const VariableName &c2="", const VariableName &c3="")
 

Static Public Member Functions

static InputParameters validParams ()
 as partial template specialization is not allowed in C++ we have to implement this as a static method More...
 

Protected Attributes

unsigned int _nvar
 
std::string _F_name
 

Detailed Description

template<class T>
class DerivativeKernelInterface< T >

Interface class ("Veneer") to provide generator methods for derivative material property names, and guarded getMaterialPropertyPointer calls.

Definition at line 20 of file DerivativeKernelInterface.h.

Constructor & Destructor Documentation

◆ DerivativeKernelInterface()

template<class T >
DerivativeKernelInterface< T >::DerivativeKernelInterface ( const InputParameters parameters)

Definition at line 34 of file DerivativeKernelInterface.h.

35  : DerivativeMaterialInterface<T>(parameters),
36  _nvar(this->_coupled_moose_vars.size()),
37  _F_name(this->template getParam<std::string>("f_name"))
38 {
39 }
Interface class ("Veneer") to provide generator methods for derivative material property names...

Member Function Documentation

◆ declarePropertyDerivative() [1/2]

template<class T >
template<typename U >
MaterialProperty< U > & DerivativeMaterialInterface< T >::declarePropertyDerivative ( const std::string &  base,
const std::vector< VariableName > &  c 
)
inherited

Methods for declaring derivative material properties.

Template Parameters
UThe material property type
Parameters
baseThe name of the property to take the derivative of
cThe variable(s) to take the derivatives with respect to

Definition at line 219 of file DerivativeMaterialInterface.h.

221 {
222  return this->template declareProperty<U>(propertyName(base, c));
223 }
const MaterialPropertyName propertyName(const MaterialPropertyName &base, const std::vector< VariableName > &c) const
Helper functions to generate the material property names for the arbitrary derivatives.

◆ declarePropertyDerivative() [2/2]

template<class T >
template<typename U >
MaterialProperty< U > & DerivativeMaterialInterface< T >::declarePropertyDerivative ( const std::string &  base,
const VariableName &  c1,
const VariableName &  c2 = "",
const VariableName &  c3 = "" 
)
inherited

Definition at line 228 of file DerivativeMaterialInterface.h.

232 {
233  if (c3 != "")
234  return this->template declareProperty<U>(propertyNameThird(base, c1, c2, c3));
235  if (c2 != "")
236  return this->template declareProperty<U>(propertyNameSecond(base, c1, c2));
237  return this->template declareProperty<U>(propertyNameFirst(base, c1));
238 }
const MaterialPropertyName propertyNameThird(const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2, const VariableName &c3) const
Helper functions to generate the material property names for the third derivatives.
const MaterialPropertyName propertyNameFirst(const MaterialPropertyName &base, const VariableName &c1) const
Helper functions to generate the material property names for the first derivatives.
const MaterialPropertyName propertyNameSecond(const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2) const
Helper functions to generate the material property names for the second derivatives.

◆ getDefaultMaterialProperty()

template<class T >
template<typename U >
const MaterialProperty< U > & DerivativeMaterialInterface< T >::getDefaultMaterialProperty ( const std::string &  name)
inherited

Fetch a material property if it exists, otherwise return getZeroMaterialProperty.

Parameters
nameThe input parameter key of type MaterialPropertyName

Definition at line 189 of file DerivativeMaterialInterface.h.

190 {
191  // get the base property name
192  std::string prop_name = this->deducePropertyName(name);
193 
194  // Check if it's just a constant
195  const MaterialProperty<U> * default_property =
196  this->template defaultMaterialProperty<U>(prop_name);
197  if (default_property)
198  return *default_property;
199 
200  // if found return the requested property
201  return getDefaultMaterialPropertyByName<U>(prop_name);
202 }
Concrete definition of a parameter value for a specified type.

◆ getDefaultMaterialPropertyByName()

template<class T >
template<typename U >
const MaterialProperty< U > & DerivativeMaterialInterface< T >::getDefaultMaterialPropertyByName ( const std::string &  name)
inherited

Fetch a material property by name if it exists, otherwise return getZeroMaterialProperty.

Definition at line 207 of file DerivativeMaterialInterface.h.

208 {
209  // if found return the requested property
210  if (haveMaterialProperty<U>(prop_name))
211  return this->template getMaterialPropertyByName<U>(prop_name);
212 
213  return this->template getZeroMaterialProperty<U>(prop_name);
214 }

◆ getMaterialPropertyDerivative() [1/2]

template<class T >
template<typename U >
const MaterialProperty< U > & DerivativeMaterialInterface< T >::getMaterialPropertyDerivative ( const std::string &  base,
const std::vector< VariableName > &  c 
)
inherited

Methods for retreiving derivative material properties.

Template Parameters
UThe material property type
Parameters
baseThe name of the property to take the derivative of
cThe variable(s) to take the derivatives with respect to

Check if base is a default property and shortcut to returning zero, as derivatives of constants are zero.

Definition at line 243 of file DerivativeMaterialInterface.h.

Referenced by FunctionMaterialPropertyDescriptor::value().

245 {
246  // get the base property name
247  std::string prop_name = this->deducePropertyName(base);
248 
253  if (this->template defaultMaterialProperty<U>(prop_name))
254  return this->template getZeroMaterialProperty<U>(prop_name + "_zeroderivative");
255 
256  return getDefaultMaterialPropertyByName<U>(propertyName(prop_name, c));
257 }
const MaterialPropertyName propertyName(const MaterialPropertyName &base, const std::vector< VariableName > &c) const
Helper functions to generate the material property names for the arbitrary derivatives.

◆ getMaterialPropertyDerivative() [2/2]

template<class T >
template<typename U >
const MaterialProperty< U > & DerivativeMaterialInterface< T >::getMaterialPropertyDerivative ( const std::string &  base,
const VariableName &  c1,
const VariableName &  c2 = "",
const VariableName &  c3 = "" 
)
inherited

Check if base is a default property and shortcut to returning zero, as derivatives of constants are zero.

Definition at line 262 of file DerivativeMaterialInterface.h.

266 {
267  // get the base property name
268  std::string prop_name = this->deducePropertyName(base);
269 
274  if (this->template defaultMaterialProperty<U>(prop_name))
275  return this->template getZeroMaterialProperty<U>(prop_name + "_zeroderivative");
276 
277  if (c3 != "")
278  return getDefaultMaterialPropertyByName<U>(propertyNameThird(prop_name, c1, c2, c3));
279  if (c2 != "")
280  return getDefaultMaterialPropertyByName<U>(propertyNameSecond(prop_name, c1, c2));
281  return getDefaultMaterialPropertyByName<U>(propertyNameFirst(prop_name, c1));
282 }
const MaterialPropertyName propertyNameThird(const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2, const VariableName &c3) const
Helper functions to generate the material property names for the third derivatives.
const MaterialPropertyName propertyNameFirst(const MaterialPropertyName &base, const VariableName &c1) const
Helper functions to generate the material property names for the first derivatives.
const MaterialPropertyName propertyNameSecond(const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2) const
Helper functions to generate the material property names for the second derivatives.

◆ getMaterialPropertyDerivativeByName() [1/2]

template<class T >
template<typename U >
const MaterialProperty< U > & DerivativeMaterialInterface< T >::getMaterialPropertyDerivativeByName ( const MaterialPropertyName &  base,
const std::vector< VariableName > &  c 
)
inherited

Methods for retreiving derivative material properties.

Template Parameters
UThe material property type
Parameters
baseThe name of the property to take the derivative of
cThe variable(s) to take the derivatives with respect to

Definition at line 287 of file DerivativeMaterialInterface.h.

289 {
290  return getDefaultMaterialPropertyByName<U>(propertyName(base, c));
291 }
const MaterialPropertyName propertyName(const MaterialPropertyName &base, const std::vector< VariableName > &c) const
Helper functions to generate the material property names for the arbitrary derivatives.

◆ getMaterialPropertyDerivativeByName() [2/2]

template<class T >
template<typename U >
const MaterialProperty< U > & DerivativeMaterialInterface< T >::getMaterialPropertyDerivativeByName ( const MaterialPropertyName &  base,
const VariableName &  c1,
const VariableName &  c2 = "",
const VariableName &  c3 = "" 
)
inherited

Definition at line 296 of file DerivativeMaterialInterface.h.

301 {
302  if (c3 != "")
303  return getDefaultMaterialPropertyByName<U>(propertyNameThird(base, c1, c2, c3));
304  if (c2 != "")
305  return getDefaultMaterialPropertyByName<U>(propertyNameSecond(base, c1, c2));
306  return getDefaultMaterialPropertyByName<U>(propertyNameFirst(base, c1));
307 }
const MaterialPropertyName propertyNameThird(const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2, const VariableName &c3) const
Helper functions to generate the material property names for the third derivatives.
const MaterialPropertyName propertyNameFirst(const MaterialPropertyName &base, const VariableName &c1) const
Helper functions to generate the material property names for the first derivatives.
const MaterialPropertyName propertyNameSecond(const MaterialPropertyName &base, const VariableName &c1, const VariableName &c2) const
Helper functions to generate the material property names for the second derivatives.

◆ propertyName()

const MaterialPropertyName DerivativeMaterialPropertyNameInterface::propertyName ( const MaterialPropertyName &  base,
const std::vector< VariableName > &  c 
) const
inherited

Helper functions to generate the material property names for the arbitrary derivatives.

Definition at line 15 of file DerivativeMaterialPropertyNameInterface.C.

Referenced by FunctionMaterialPropertyDescriptor::getPropertyName(), DerivativeMaterialPropertyNameInterface::propertyNameSecond(), and DerivativeMaterialPropertyNameInterface::propertyNameThird().

17 {
18  // to obtain well defined names we sort alphabetically
19  std::vector<VariableName> a(c);
20  std::sort(a.begin(), a.end());
21 
22  // derivative order
23  unsigned int order = a.size();
24  if (order == 0)
25  return base;
26 
27  // build the property name as a stringstream
28  std::stringstream name;
29 
30  // build numerator
31  name << 'd';
32  if (order > 1)
33  name << '^' << order;
34  name << base << '/';
35 
36  // build denominator with 'pretty' names using exponents rather than repeat multiplication
37  unsigned int exponent = 1;
38  for (unsigned i = 1; i <= order; ++i)
39  {
40  if (i == order || a[i - 1] != a[i])
41  {
42  name << 'd' << a[i - 1];
43  if (exponent > 1)
44  name << '^' << exponent;
45  exponent = 1;
46  }
47  else
48  exponent++;
49  }
50 
51  return name.str();
52 }

◆ propertyNameFirst()

const MaterialPropertyName DerivativeMaterialPropertyNameInterface::propertyNameFirst ( const MaterialPropertyName &  base,
const VariableName &  c1 
) const
inherited

Helper functions to generate the material property names for the first derivatives.

Definition at line 55 of file DerivativeMaterialPropertyNameInterface.C.

Referenced by DerivativeFunctionMaterialBase::initialSetup().

57 {
58  return "d" + base + "/d" + c1;
59 }

◆ propertyNameSecond()

const MaterialPropertyName DerivativeMaterialPropertyNameInterface::propertyNameSecond ( const MaterialPropertyName &  base,
const VariableName &  c1,
const VariableName &  c2 
) const
inherited

Helper functions to generate the material property names for the second derivatives.

Definition at line 62 of file DerivativeMaterialPropertyNameInterface.C.

Referenced by DerivativeFunctionMaterialBase::initialSetup().

65 {
66  return propertyName(base, {c1, c2});
67 }
const MaterialPropertyName propertyName(const MaterialPropertyName &base, const std::vector< VariableName > &c) const
Helper functions to generate the material property names for the arbitrary derivatives.

◆ propertyNameThird()

const MaterialPropertyName DerivativeMaterialPropertyNameInterface::propertyNameThird ( const MaterialPropertyName &  base,
const VariableName &  c1,
const VariableName &  c2,
const VariableName &  c3 
) const
inherited

Helper functions to generate the material property names for the third derivatives.

Definition at line 70 of file DerivativeMaterialPropertyNameInterface.C.

Referenced by DerivativeFunctionMaterialBase::initialSetup().

74 {
75  return propertyName(base, {c1, c2, c3});
76 }
const MaterialPropertyName propertyName(const MaterialPropertyName &base, const std::vector< VariableName > &c) const
Helper functions to generate the material property names for the arbitrary derivatives.

◆ validateCoupling() [1/2]

template<class T >
template<typename U >
void DerivativeMaterialInterface< T >::validateCoupling ( const MaterialPropertyName &  base,
const std::vector< VariableName > &  c,
bool  validate_aux = true 
)
inherited

check if derivatives of the passed in material property exist w.r.t a variable that is not coupled in to the current object

Definition at line 352 of file DerivativeMaterialInterface.h.

355 {
356  // get the base property name
357  std::string prop_name = this->deducePropertyName(base);
358  // list of potentially missing coupled variables
359  std::vector<VariableName> missing;
360 
361  // iterate over all variables in the both the non-linear and auxiliary system (optional)
362  validateCouplingHelper<U>(
363  prop_name, c, _dmi_fe_problem.getNonlinearSystemBase().system(), missing);
364  if (validate_aux)
365  validateCouplingHelper<U>(prop_name, c, _dmi_fe_problem.getAuxiliarySystem().system(), missing);
366 
367  if (missing.size() > 0)
368  {
369  // join list of missing variable names
370  std::string list = missing[0];
371  for (unsigned int i = 1; i < missing.size(); ++i)
372  list += ", " + missing[i];
373 
374  mooseWarning("Missing coupled variables {",
375  list,
376  "} (add them to args parameter of ",
377  this->name(),
378  ")");
379  }
380 }
NonlinearSystemBase & getNonlinearSystemBase()
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:220
FEProblemBase & _dmi_fe_problem
Reference to FEProblemBase.
AuxiliarySystem & getAuxiliarySystem()
virtual System & system() override
Get the reference to the libMesh system.
virtual System & system() override
Get the reference to the libMesh system.

◆ validateCoupling() [2/2]

template<class T >
template<typename U >
void DerivativeMaterialInterface< T >::validateCoupling ( const MaterialPropertyName &  base,
const VariableName &  c1 = "",
const VariableName &  c2 = "",
const VariableName &  c3 = "" 
)
inherited

Definition at line 405 of file DerivativeMaterialInterface.h.

409 {
410  validateCoupling<U>(base, buildVariableVector(c1, c2, c3), true);
411 }
std::vector< VariableName > buildVariableVector(const VariableName &c1, const VariableName &c2, const VariableName &c3)
helper method to combine multiple VariableNames into a vector (if they are != "") ...

◆ validateDerivativeMaterialPropertyBase()

template<class T >
template<typename U >
void DerivativeMaterialInterface< T >::validateDerivativeMaterialPropertyBase ( const std::string &  base)
inherited

Check if the material property base exists.

Print a warning if it doesn't. This is useful in materials that pull in only derivative properties, which are optional. If the base property name has a typo all derivatives will be set to zero without the user ever knowing.

Definition at line 427 of file DerivativeMaterialInterface.h.

428 {
429  // resolve the input parameter name base to the actual material property name
430  const MaterialPropertyName prop_name = this->template getParam<MaterialPropertyName>(base);
431 
432  // check if the material property does not exist on the blocks of the current object,
433  // and check if it is not a plain number in the input file
434  if (!haveMaterialProperty<U>(prop_name) &&
435  this->template defaultMaterialProperty<U>(prop_name) == 0)
436  mooseWarning("The material property '",
437  prop_name,
438  "' does not exist. The kernel '",
439  this->name(),
440  "' only needs its derivatives, but this may indicate a typo in the input file.");
441 }
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:220

◆ validateNonlinearCoupling()

template<class T >
template<typename U >
void DerivativeMaterialInterface< T >::validateNonlinearCoupling ( const MaterialPropertyName &  base,
const VariableName &  c1 = "",
const VariableName &  c2 = "",
const VariableName &  c3 = "" 
)
inherited

Definition at line 416 of file DerivativeMaterialInterface.h.

420 {
421  validateCoupling<U>(base, buildVariableVector(c1, c2, c3), false);
422 }
std::vector< VariableName > buildVariableVector(const VariableName &c1, const VariableName &c2, const VariableName &c3)
helper method to combine multiple VariableNames into a vector (if they are != "") ...

◆ validParams()

template<class T >
InputParameters DerivativeKernelInterface< T >::validParams ( )
static

as partial template specialization is not allowed in C++ we have to implement this as a static method

Definition at line 43 of file DerivativeKernelInterface.h.

44 {
45  InputParameters params = ::validParams<T>();
46  params.addRequiredParam<std::string>(
47  "f_name", "Base name of the free energy function F defined in a DerivativeParsedMaterial");
48  return params;
49 }
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...

Member Data Documentation

◆ _F_name

template<class T >
std::string DerivativeKernelInterface< T >::_F_name
protected

Definition at line 30 of file DerivativeKernelInterface.h.

◆ _nvar

template<class T >
unsigned int DerivativeKernelInterface< T >::_nvar
protected

Definition at line 29 of file DerivativeKernelInterface.h.


The documentation for this class was generated from the following file: