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 218 of file DerivativeMaterialInterface.h.

220 {
221  return this->template declareProperty<U>(propertyName(base, c));
222 }
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 227 of file DerivativeMaterialInterface.h.

231 {
232  if (c3 != "")
233  return this->template declareProperty<U>(propertyNameThird(base, c1, c2, c3));
234  if (c2 != "")
235  return this->template declareProperty<U>(propertyNameSecond(base, c1, c2));
236  return this->template declareProperty<U>(propertyNameFirst(base, c1));
237 }
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 188 of file DerivativeMaterialInterface.h.

189 {
190  // get the base property name
191  std::string prop_name = this->deducePropertyName(name);
192 
193  // Check if it's just a constant
194  const MaterialProperty<U> * default_property =
195  this->template defaultMaterialProperty<U>(prop_name);
196  if (default_property)
197  return *default_property;
198 
199  // if found return the requested property
200  return getDefaultMaterialPropertyByName<U>(prop_name);
201 }
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 206 of file DerivativeMaterialInterface.h.

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

◆ 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 242 of file DerivativeMaterialInterface.h.

Referenced by FunctionMaterialPropertyDescriptor::value().

244 {
245  // get the base property name
246  std::string prop_name = this->deducePropertyName(base);
247 
252  if (this->template defaultMaterialProperty<U>(prop_name))
253  return this->template getZeroMaterialProperty<U>(prop_name + "_zeroderivative");
254 
255  return getDefaultMaterialPropertyByName<U>(propertyName(prop_name, c));
256 }
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 261 of file DerivativeMaterialInterface.h.

265 {
266  // get the base property name
267  std::string prop_name = this->deducePropertyName(base);
268 
273  if (this->template defaultMaterialProperty<U>(prop_name))
274  return this->template getZeroMaterialProperty<U>(prop_name + "_zeroderivative");
275 
276  if (c3 != "")
277  return getDefaultMaterialPropertyByName<U>(propertyNameThird(prop_name, c1, c2, c3));
278  if (c2 != "")
279  return getDefaultMaterialPropertyByName<U>(propertyNameSecond(prop_name, c1, c2));
280  return getDefaultMaterialPropertyByName<U>(propertyNameFirst(prop_name, c1));
281 }
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 286 of file DerivativeMaterialInterface.h.

288 {
289  return getDefaultMaterialPropertyByName<U>(propertyName(base, c));
290 }
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 295 of file DerivativeMaterialInterface.h.

300 {
301  if (c3 != "")
302  return getDefaultMaterialPropertyByName<U>(propertyNameThird(base, c1, c2, c3));
303  if (c2 != "")
304  return getDefaultMaterialPropertyByName<U>(propertyNameSecond(base, c1, c2));
305  return getDefaultMaterialPropertyByName<U>(propertyNameFirst(base, c1));
306 }
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 351 of file DerivativeMaterialInterface.h.

354 {
355  // get the base property name
356  std::string prop_name = this->deducePropertyName(base);
357  // list of potentially missing coupled variables
358  std::vector<VariableName> missing;
359 
360  // iterate over all variables in the both the non-linear and auxiliary system (optional)
361  validateCouplingHelper<U>(
362  prop_name, c, _dmi_fe_problem.getNonlinearSystemBase().system(), missing);
363  if (validate_aux)
364  validateCouplingHelper<U>(prop_name, c, _dmi_fe_problem.getAuxiliarySystem().system(), missing);
365 
366  if (missing.size() > 0)
367  {
368  // join list of missing variable names
369  std::string list = missing[0];
370  for (unsigned int i = 1; i < missing.size(); ++i)
371  list += ", " + missing[i];
372 
373  mooseWarning("Missing coupled variables {",
374  list,
375  "} (add them to args parameter of ",
376  this->name(),
377  ")");
378  }
379 }
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 404 of file DerivativeMaterialInterface.h.

408 {
409  validateCoupling<U>(base, buildVariableVector(c1, c2, c3), true);
410 }
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 426 of file DerivativeMaterialInterface.h.

427 {
428  // resolve the input parameter name base to the actual material property name
429  const MaterialPropertyName prop_name = this->template getParam<MaterialPropertyName>(base);
430 
431  // check if the material property does not exist on the blocks of the current object,
432  // and check if it is not a plain number in the input file
433  if (!haveMaterialProperty<U>(prop_name) &&
434  this->template defaultMaterialProperty<U>(prop_name) == 0)
435  mooseWarning("The material property '",
436  prop_name,
437  "' does not exist. The kernel '",
438  this->name(),
439  "' only needs its derivatives, but this may indicate a typo in the input file.");
440 }
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 415 of file DerivativeMaterialInterface.h.

419 {
420  validateCoupling<U>(base, buildVariableVector(c1, c2, c3), false);
421 }
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: