Skip to content
Permalink
Browse files

Merge pull request #13168 from dschwen/thermalexpansion_ad_13091

Thermal expansion Eigenstrain with AD
  • Loading branch information...
bwspenc committed Apr 8, 2019
2 parents 3c6a5d9 + 3f5f61e commit c55590fc3782722400cce81d88890b7b7d265d40
Showing with 784 additions and 130 deletions.
  1. +5 −14 framework/include/materials/DerivativeFunctionMaterialBase.h
  2. +13 −13 framework/include/materials/DerivativeMaterialInterface.h
  3. +39 −8 framework/include/materials/DerivativeMaterialPropertyNameInterface.h
  4. +4 −1 framework/include/utils/FunctionMaterialPropertyDescriptor.h
  5. +2 −1 framework/src/actions/MaterialDerivativeTestAction.C
  6. +5 −7 framework/src/materials/DerivativeFunctionMaterialBase.C
  7. +13 −13 framework/src/materials/DerivativeMaterialPropertyNameInterface.C
  8. +2 −1 modules/phase_field/src/action/PolycrystalElasticDrivingForceAction.C
  9. +1 −1 modules/phase_field/src/kernels/ADSplitCHParsed.C
  10. +2 −1 modules/phase_field/src/materials/ADMathFreeEnergy.C
  11. +3 −3 modules/phase_field/src/userobjects/ComputeExternalGrainForceAndTorque.C
  12. +4 −4 modules/phase_field/src/userobjects/ComputeGrainForceAndTorque.C
  13. +33 −0 modules/tensor_mechanics/doc/content/source/materials/ADComputeThermalExpansionEigenstrain.md
  14. +1 −1 modules/tensor_mechanics/doc/content/source/materials/ComputeThermalExpansionEigenstrain.md
  15. +2 −2 modules/tensor_mechanics/include/materials/ADComputeEigenstrain.h
  16. +3 −2 modules/tensor_mechanics/include/materials/ADComputeEigenstrainBase.h
  17. +39 −0 modules/tensor_mechanics/include/materials/ADComputeThermalExpansionEigenstrain.h
  18. +64 −0 modules/tensor_mechanics/include/materials/ADComputeThermalExpansionEigenstrainBase.h
  19. +36 −0 modules/tensor_mechanics/src/materials/ADComputeThermalExpansionEigenstrain.C
  20. +48 −0 modules/tensor_mechanics/src/materials/ADComputeThermalExpansionEigenstrainBase.C
  21. +3 −2 modules/tensor_mechanics/src/materials/ComputeVariableIsotropicElasticityTensor.C
  22. +3 −2 modules/tensor_mechanics/src/materials/ComputeVolumetricEigenstrain.C
  23. +147 −0 modules/tensor_mechanics/test/tests/thermal_expansion/ad_constant_expansion_coeff.i
  24. +248 −0 modules/tensor_mechanics/test/tests/thermal_expansion/ad_constant_expansion_stress_free_temp.i
  25. +3 −12 modules/tensor_mechanics/test/tests/thermal_expansion/constant_expansion_coeff.i
  26. +1 −4 modules/tensor_mechanics/test/tests/thermal_expansion/constant_expansion_coeff_restart.i
  27. +2 −8 modules/tensor_mechanics/test/tests/thermal_expansion/constant_expansion_stress_free_temp.i
  28. +1 −0 modules/tensor_mechanics/test/tests/thermal_expansion/gold/ad_constant_expansion_coeff_out.e
  29. +1 −0 ...s/tensor_mechanics/test/tests/thermal_expansion/gold/ad_constant_expansion_stress_free_temp_out.e
  30. BIN modules/tensor_mechanics/test/tests/thermal_expansion/gold/constant_expansion_coeff_out.e
  31. BIN modules/tensor_mechanics/test/tests/thermal_expansion/gold/constant_expansion_coeff_restart_out.e
  32. BIN modules/tensor_mechanics/test/tests/thermal_expansion/gold/constant_expansion_stress_free_temp_out.e
  33. BIN modules/tensor_mechanics/test/tests/thermal_expansion/gold/constant_thermal_expan_only.e
  34. BIN modules/tensor_mechanics/test/tests/thermal_expansion/gold/constant_thermal_expan_restart.e
  35. +0 −1 modules/tensor_mechanics/test/tests/thermal_expansion/gold/multiple_thermal_eigenstrains.e
  36. +1 −0 modules/tensor_mechanics/test/tests/thermal_expansion/gold/multiple_thermal_eigenstrains_out.e
  37. +3 −22 modules/tensor_mechanics/test/tests/thermal_expansion/multiple_thermal_eigenstrains.i
  38. +52 −7 modules/tensor_mechanics/test/tests/thermal_expansion/tests
@@ -19,26 +19,17 @@ template <>
InputParameters validParams<DerivativeFunctionMaterialBase>();

/**
* %Material base class central to compute the a phase free energy and
* its derivatives. Classes derived from this base class are central to
* the KKS system. The calculation of free energies is centralized here
* as the results are used in multiple kernels (KKSPhaseChemicalPotential
* and \ref KKSCHBulk).
* Material base class to compute a function and its derivatives.
*
* A DerivativeFunctionMaterialBase provides numerous material properties which contain
* the free energy and its derivatives. The material property names are
* constructed dynamically by the helper functions propertyNameFirst(),
* propertyNameSecond(), and propertyNameThird() in DerivativeMaterialInterface.
* constructed dynamically by the helper functions derivativePropertyNameFirst(),
* derivativePropertyNameSecond(), and derivativePropertyNameThird() in
* DerivativeMaterialPropertyNameInterface.
*
* A derived class needs to implement the computeF(), computeDF(),
* computeD2F(), and (optionally) computeD3F() methods.
*
* Note that DerivativeParsedMaterial provides a material for which a mathematical
* free energy expression can be provided in the input file (with the
* derivatives being calculated automatically).
*
* \see KKSPhaseChemicalPotential
* \see KKSCHBulk
* \see DerivativeParsedMaterial
* \see DerivativeMaterialInterface
*/
@@ -93,7 +84,7 @@ class DerivativeFunctionMaterialBase : public FunctionMaterialBase
* Override this method to calculate the third derivatives.
*
* @note The implementation of this method is optional. It is only evaluated when
* the 'third_derivatives' parameter is set to true.
* the 'derivative_order' parameter is set to 3.
*/
virtual Real computeD3F(unsigned int, unsigned int, unsigned int) { return 0.0; }

@@ -219,7 +219,7 @@ MaterialProperty<U> &
DerivativeMaterialInterface<T>::declarePropertyDerivative(const std::string & base,
const std::vector<VariableName> & c)
{
return this->template declareProperty<U>(propertyName(base, c));
return this->template declareProperty<U>(derivativePropertyName(base, c));
}

template <class T>
@@ -231,10 +231,10 @@ DerivativeMaterialInterface<T>::declarePropertyDerivative(const std::string & ba
const VariableName & c3)
{
if (c3 != "")
return this->template declareProperty<U>(propertyNameThird(base, c1, c2, c3));
return this->template declareProperty<U>(derivativePropertyNameThird(base, c1, c2, c3));
if (c2 != "")
return this->template declareProperty<U>(propertyNameSecond(base, c1, c2));
return this->template declareProperty<U>(propertyNameFirst(base, c1));
return this->template declareProperty<U>(derivativePropertyNameSecond(base, c1, c2));
return this->template declareProperty<U>(derivativePropertyNameFirst(base, c1));
}

template <class T>
@@ -253,7 +253,7 @@ DerivativeMaterialInterface<T>::getMaterialPropertyDerivative(const std::string
if (this->template defaultMaterialProperty<U>(prop_name))
return this->template getZeroMaterialProperty<U>(prop_name + "_zeroderivative");

return getDefaultMaterialPropertyByName<U>(propertyName(prop_name, c));
return getDefaultMaterialPropertyByName<U>(derivativePropertyName(prop_name, c));
}

template <class T>
@@ -275,10 +275,10 @@ DerivativeMaterialInterface<T>::getMaterialPropertyDerivative(const std::string
return this->template getZeroMaterialProperty<U>(prop_name + "_zeroderivative");

if (c3 != "")
return getDefaultMaterialPropertyByName<U>(propertyNameThird(prop_name, c1, c2, c3));
return getDefaultMaterialPropertyByName<U>(derivativePropertyNameThird(prop_name, c1, c2, c3));
if (c2 != "")
return getDefaultMaterialPropertyByName<U>(propertyNameSecond(prop_name, c1, c2));
return getDefaultMaterialPropertyByName<U>(propertyNameFirst(prop_name, c1));
return getDefaultMaterialPropertyByName<U>(derivativePropertyNameSecond(prop_name, c1, c2));
return getDefaultMaterialPropertyByName<U>(derivativePropertyNameFirst(prop_name, c1));
}

template <class T>
@@ -287,7 +287,7 @@ const MaterialProperty<U> &
DerivativeMaterialInterface<T>::getMaterialPropertyDerivativeByName(
const MaterialPropertyName & base, const std::vector<VariableName> & c)
{
return getDefaultMaterialPropertyByName<U>(propertyName(base, c));
return getDefaultMaterialPropertyByName<U>(derivativePropertyName(base, c));
}

template <class T>
@@ -300,10 +300,10 @@ DerivativeMaterialInterface<T>::getMaterialPropertyDerivativeByName(
const VariableName & c3)
{
if (c3 != "")
return getDefaultMaterialPropertyByName<U>(propertyNameThird(base, c1, c2, c3));
return getDefaultMaterialPropertyByName<U>(derivativePropertyNameThird(base, c1, c2, c3));
if (c2 != "")
return getDefaultMaterialPropertyByName<U>(propertyNameSecond(base, c1, c2));
return getDefaultMaterialPropertyByName<U>(propertyNameFirst(base, c1));
return getDefaultMaterialPropertyByName<U>(derivativePropertyNameSecond(base, c1, c2));
return getDefaultMaterialPropertyByName<U>(derivativePropertyNameFirst(base, c1));
}

template <class T>
@@ -327,7 +327,7 @@ DerivativeMaterialInterface<T>::validateCouplingHelper(const MaterialPropertyNam
cj.push_back(jname);

// if the derivative exists make sure the variable is coupled
if (haveMaterialProperty<U>(propertyName(base, cj)))
if (haveMaterialProperty<U>(derivativePropertyName(base, cj)))
{
// kernels and BCs to not have the variable they are acting on in coupled_moose_vars
bool is_missing = isNotObjectVariable(jname);
@@ -11,6 +11,7 @@
#define DERIVATIVEMATERIALPROPERTYNAMEINTERFACE_H

#include "MooseTypes.h"
#include "MooseError.h"

class DerivativeMaterialPropertyNameInterface
{
@@ -19,32 +20,62 @@ class DerivativeMaterialPropertyNameInterface
* Helper functions to generate the material property names for the
* arbitrary derivatives.
*/
const MaterialPropertyName propertyName(const MaterialPropertyName & base,
const std::vector<VariableName> & c) const;
const MaterialPropertyName derivativePropertyName(const MaterialPropertyName & base,
const std::vector<VariableName> & c) const;

/**
* Helper functions to generate the material property names for the
* first derivatives.
*/
const MaterialPropertyName propertyNameFirst(const MaterialPropertyName & base,
const VariableName & c1) const;
const MaterialPropertyName derivativePropertyNameFirst(const MaterialPropertyName & base,
const VariableName & c1) const;

/**
* Helper functions to generate the material property names for the
* second derivatives.
*/
const MaterialPropertyName propertyNameSecond(const MaterialPropertyName & base,
const VariableName & c1,
const VariableName & c2) const;
const MaterialPropertyName derivativePropertyNameSecond(const MaterialPropertyName & base,
const VariableName & c1,
const VariableName & c2) const;

/**
* Helper functions to generate the material property names for the
* third derivatives.
*/
const MaterialPropertyName derivativePropertyNameThird(const MaterialPropertyName & base,
const VariableName & c1,
const VariableName & c2,
const VariableName & c3) const;

///@{ aliases for the deprecated old function names
const MaterialPropertyName propertyName(const MaterialPropertyName & base,
const std::vector<VariableName> & c) const
{
mooseDeprecated("This function was renamed to 'derivativePropertyName'");
return derivativePropertyName(base, c);
}
const MaterialPropertyName propertyNameFirst(const MaterialPropertyName & base,
const VariableName & c1) const
{
mooseDeprecated("This function was renamed to 'derivativePropertyNameFirst'");
return derivativePropertyNameFirst(base, c1);
}
const MaterialPropertyName propertyNameSecond(const MaterialPropertyName & base,
const VariableName & c1,
const VariableName & c2) const
{
mooseDeprecated("This function was renamed to 'derivativePropertyNameSecond'");
return derivativePropertyNameSecond(base, c1, c2);
}
const MaterialPropertyName propertyNameThird(const MaterialPropertyName & base,
const VariableName & c1,
const VariableName & c2,
const VariableName & c3) const;
const VariableName & c3) const
{
mooseDeprecated("This function was renamed to 'derivativePropertyNameThird'");
return derivativePropertyNameThird(base, c1, c2, c3);
}
///@}
};

#endif // DERIVATIVEMATERIALPROPERTYNAMEINTERFACE_H
@@ -59,7 +59,10 @@ class FunctionMaterialPropertyDescriptor : public DerivativeMaterialPropertyName
void setSymbolName(const std::string & n) { _fparser_name = n; };

/// get the property name
const std::string getPropertyName() const { return propertyName(_base_name, _derivative_vars); };
const std::string getPropertyName() const
{
return derivativePropertyName(_base_name, _derivative_vars);
};

/// get the property reference
const MaterialProperty<Real> & value() const;
@@ -66,7 +66,8 @@ MaterialDerivativeTestAction::MaterialDerivativeTestAction(const InputParameters

// add derivative to list
derivative_table[n].push_back(derivative);
_derivatives.insert(std::make_pair(propertyName(_prop_name, derivative), derivative));
_derivatives.insert(
std::make_pair(derivativePropertyName(_prop_name, derivative), derivative));
}
}

@@ -30,9 +30,7 @@ validParams<DerivativeFunctionMaterialBase>()

DerivativeFunctionMaterialBase::DerivativeFunctionMaterialBase(const InputParameters & parameters)
: FunctionMaterialBase(parameters),
_third_derivatives(isParamValid("third_derivatives")
? getParam<bool>("third_derivatives")
: (getParam<unsigned int>("derivative_order") == 3))
_third_derivatives(getParam<unsigned int>("derivative_order") == 3)
{
// reserve space for material properties and explicitly initialize to NULL
_prop_dF.resize(_nargs, NULL);
@@ -90,23 +88,23 @@ DerivativeFunctionMaterialBase::initialSetup()

for (unsigned int i = 0; i < _nargs; ++i)
{
if (!_fe_problem.isMatPropRequested(propertyNameFirst(_F_name, _arg_names[i])))
if (!_fe_problem.isMatPropRequested(derivativePropertyNameFirst(_F_name, _arg_names[i])))
_prop_dF[i] = NULL;

// second derivatives
for (unsigned int j = i; j < _nargs; ++j)
{
if (!_fe_problem.isMatPropRequested(
propertyNameSecond(_F_name, _arg_names[i], _arg_names[j])))
derivativePropertyNameSecond(_F_name, _arg_names[i], _arg_names[j])))
_prop_d2F[i][j] = _prop_d2F[j][i] = NULL;

// third derivatives
if (_third_derivatives)
{
for (unsigned int k = j; k < _nargs; ++k)
{
if (!_fe_problem.isMatPropRequested(
propertyNameThird(_F_name, _arg_names[i], _arg_names[j], _arg_names[k])))
if (!_fe_problem.isMatPropRequested(derivativePropertyNameThird(
_F_name, _arg_names[i], _arg_names[j], _arg_names[k])))
_prop_d3F[i][j][k] = _prop_d3F[k][i][j] = _prop_d3F[j][k][i] = _prop_d3F[k][j][i] =
_prop_d3F[j][i][k] = _prop_d3F[i][k][j] = NULL;
else
@@ -12,8 +12,8 @@
#include <algorithm>

const MaterialPropertyName
DerivativeMaterialPropertyNameInterface::propertyName(const MaterialPropertyName & base,
const std::vector<VariableName> & c) const
DerivativeMaterialPropertyNameInterface::derivativePropertyName(
const MaterialPropertyName & base, const std::vector<VariableName> & c) const
{
// to obtain well defined names we sort alphabetically
std::vector<VariableName> a(c);
@@ -52,25 +52,25 @@ DerivativeMaterialPropertyNameInterface::propertyName(const MaterialPropertyName
}

const MaterialPropertyName
DerivativeMaterialPropertyNameInterface::propertyNameFirst(const MaterialPropertyName & base,
const VariableName & c1) const
DerivativeMaterialPropertyNameInterface::derivativePropertyNameFirst(
const MaterialPropertyName & base, const VariableName & c1) const
{
return "d" + base + "/d" + c1;
}

const MaterialPropertyName
DerivativeMaterialPropertyNameInterface::propertyNameSecond(const MaterialPropertyName & base,
const VariableName & c1,
const VariableName & c2) const
DerivativeMaterialPropertyNameInterface::derivativePropertyNameSecond(
const MaterialPropertyName & base, const VariableName & c1, const VariableName & c2) const
{
return propertyName(base, {c1, c2});
return derivativePropertyName(base, {c1, c2});
}

const MaterialPropertyName
DerivativeMaterialPropertyNameInterface::propertyNameThird(const MaterialPropertyName & base,
const VariableName & c1,
const VariableName & c2,
const VariableName & c3) const
DerivativeMaterialPropertyNameInterface::derivativePropertyNameThird(
const MaterialPropertyName & base,
const VariableName & c1,
const VariableName & c2,
const VariableName & c3) const
{
return propertyName(base, {c1, c2, c3});
return derivativePropertyName(base, {c1, c2, c3});
}
@@ -56,7 +56,8 @@ PolycrystalElasticDrivingForceAction::act()
std::string var_name = _var_name_base + Moose::stringify(op);

// Create Stiffness derivative name
MaterialPropertyName D_stiff_name = propertyNameFirst(_elasticity_tensor_name, var_name);
MaterialPropertyName D_stiff_name =
derivativePropertyNameFirst(_elasticity_tensor_name, var_name);

// Set name of kernel being created
std::string kernel_type = "ACGrGrElasticDrivingForce";
@@ -24,7 +24,7 @@ template <ComputeStage compute_stage>
ADSplitCHParsed<compute_stage>::ADSplitCHParsed(const InputParameters & parameters)
: ADSplitCHCRes<compute_stage>(parameters),
_f_name(adGetParam<MaterialPropertyName>("f_name")),
_dFdc(adGetADMaterialProperty<Real>(propertyNameFirst(_f_name, _var.name())))
_dFdc(adGetADMaterialProperty<Real>(derivativePropertyNameFirst(_f_name, _var.name())))
{
}

@@ -25,7 +25,8 @@ ADMathFreeEnergy<compute_stage>::ADMathFreeEnergy(const InputParameters & parame
_c(adCoupledValue("c")),
_f_name(adGetParam<MaterialPropertyName>("f_name")),
_prop_F(adDeclareADProperty<Real>(_f_name)),
_prop_dFdc(adDeclareADProperty<Real>(propertyNameFirst(_f_name, this->getVar("c", 0)->name())))
_prop_dFdc(adDeclareADProperty<Real>(
derivativePropertyNameFirst(_f_name, this->getVar("c", 0)->name())))
{
}

@@ -35,8 +35,8 @@ ComputeExternalGrainForceAndTorque::ComputeExternalGrainForceAndTorque(
_c_var(coupled("c")),
_dF_name(getParam<MaterialPropertyName>("force_density")),
_dF(getMaterialPropertyByName<std::vector<RealGradient>>(_dF_name)),
_dFdc(
getMaterialPropertyByName<std::vector<RealGradient>>(propertyNameFirst(_dF_name, _c_name))),
_dFdc(getMaterialPropertyByName<std::vector<RealGradient>>(
derivativePropertyNameFirst(_dF_name, _c_name))),
_op_num(coupledComponents("etas")),
_grain_tracker(getUserObject<GrainTrackerInterface>("grain_data")),
_vals_var(_op_num),
@@ -48,7 +48,7 @@ ComputeExternalGrainForceAndTorque::ComputeExternalGrainForceAndTorque(
_vals_var[i] = coupled("etas", i);
_vals_name[i] = getVar("etas", i)->name();
_dFdeta[i] = &getMaterialPropertyByName<std::vector<RealGradient>>(
propertyNameFirst(_dF_name, _vals_name[i]));
derivativePropertyNameFirst(_dF_name, _vals_name[i]));
}
}

@@ -34,8 +34,8 @@ ComputeGrainForceAndTorque::ComputeGrainForceAndTorque(const InputParameters & p
_c_var(coupled("c")),
_dF_name(getParam<MaterialPropertyName>("force_density")),
_dF(getMaterialPropertyByName<std::vector<RealGradient>>(_dF_name)),
_dFdc(
getMaterialPropertyByName<std::vector<RealGradient>>(propertyNameFirst(_dF_name, _c_name))),
_dFdc(getMaterialPropertyByName<std::vector<RealGradient>>(
derivativePropertyNameFirst(_dF_name, _c_name))),
_op_num(coupledComponents("etas")),
_grain_tracker(getUserObject<GrainTrackerInterface>("grain_data")),
_vals_var(_op_num),
@@ -46,8 +46,8 @@ ComputeGrainForceAndTorque::ComputeGrainForceAndTorque(const InputParameters & p
{
_vals_var[i] = coupled("etas", i);
_vals_name[i] = getVar("etas", i)->name();
_dFdgradeta[i] =
&getMaterialPropertyByName<std::vector<Real>>(propertyNameFirst(_dF_name, _vals_name[i]));
_dFdgradeta[i] = &getMaterialPropertyByName<std::vector<Real>>(
derivativePropertyNameFirst(_dF_name, _vals_name[i]));
}
}

Oops, something went wrong.

0 comments on commit c55590f

Please sign in to comment.
You can’t perform that action at this time.