Skip to content

Commit

Permalink
Additional refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
vanwdani authored and aeslaughter committed Jun 2, 2021
1 parent 089f016 commit 627b4f7
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 87 deletions.
26 changes: 0 additions & 26 deletions framework/include/kernels/ADMaterialPropertyValue.h

This file was deleted.

24 changes: 19 additions & 5 deletions framework/include/kernels/MaterialPropertyValue.h
Expand Up @@ -10,18 +10,32 @@
#pragma once

#include "KernelValue.h"
#include "ADKernelValue.h"

class MaterialPropertyValue : public KernelValue
// switch parent class depending on is_ad value
template <bool is_ad>
using KernelValueParent = typename std::conditional<is_ad, ADKernelValue, KernelValue>::type;

template <bool is_ad>
class MaterialPropertyValueTempl : public KernelValueParent<is_ad>
{
public:
static InputParameters validParams();

MaterialPropertyValue(const InputParameters & parameters);
MaterialPropertyValueTempl(const InputParameters & parameters);

protected:
virtual Real precomputeQpResidual() override;
virtual Real precomputeQpJacobian() override;
virtual GenericReal<is_ad> precomputeQpResidual();
virtual Real precomputeQpJacobian();

const Real _kernel_sign;
const MaterialProperty<Real> & _prop;
const GenericMaterialProperty<Real, is_ad> & _prop;

using KernelValueParent<is_ad>::_qp;
using KernelValueParent<is_ad>::_u;
using KernelValueParent<is_ad>::_phi;
using KernelValueParent<is_ad>::_j;
};

using MaterialPropertyValue = MaterialPropertyValueTempl<false>;
using ADMaterialPropertyValue = MaterialPropertyValueTempl<true>;
38 changes: 0 additions & 38 deletions framework/src/kernels/ADMaterialPropertyValue.C

This file was deleted.

38 changes: 30 additions & 8 deletions framework/src/kernels/MaterialPropertyValue.C
Expand Up @@ -10,11 +10,13 @@
#include "MaterialPropertyValue.h"

registerMooseObject("MooseApp", MaterialPropertyValue);
registerMooseObject("MooseApp", ADMaterialPropertyValue);

template <bool is_ad>
InputParameters
MaterialPropertyValue::validParams()
MaterialPropertyValueTempl<is_ad>::validParams()
{
InputParameters params = KernelValue::validParams();
InputParameters params = KernelValueParent<is_ad>::validParams();
params.addClassDescription(
"Residual term (u - prop) to set variable u equal to a given material property prop");
params.addRequiredParam<MaterialPropertyName>(
Expand All @@ -24,21 +26,41 @@ MaterialPropertyValue::validParams()
return params;
}

MaterialPropertyValue::MaterialPropertyValue(const InputParameters & parameters)
: KernelValue(parameters),
_kernel_sign(getParam<bool>("positive") ? 1.0 : -1.0),
_prop(getMaterialProperty<Real>("prop_name"))
template <bool is_ad>
MaterialPropertyValueTempl<is_ad>::MaterialPropertyValueTempl(const InputParameters & parameters)
: KernelValueParent<is_ad>(parameters),
_kernel_sign(this->template getParam<bool>("positive") ? 1.0 : -1.0),
_prop(this->template getGenericMaterialProperty<Real, is_ad>("prop_name"))
{
}

template <>
Real
MaterialPropertyValue::precomputeQpResidual()
MaterialPropertyValueTempl<false>::precomputeQpResidual()
{
return _kernel_sign * (_prop[_qp] - _u[_qp]);
}

template <>
ADReal
MaterialPropertyValueTempl<true>::precomputeQpResidual()
{
return _kernel_sign * (_prop[_qp] - _u[_qp]);
}

template <>
Real
MaterialPropertyValue::precomputeQpJacobian()
MaterialPropertyValueTempl<false>::precomputeQpJacobian()
{
return -_kernel_sign * _phi[_j][_qp];
}

template <>
Real
MaterialPropertyValueTempl<true>::precomputeQpJacobian()
{
mooseError("This should never get called");
}

template class MaterialPropertyValueTempl<false>;
template class MaterialPropertyValueTempl<true>;
Expand Up @@ -107,6 +107,7 @@ class TensorMechanicsAction : public TensorMechanicsActionBase
bool _cylindrical_axis_point1_valid;
bool _cylindrical_axis_point2_valid;
bool _direction_valid;
bool _verbose;

/// points used to determine axis of rotation for cyclindrical stress/strain quantities
Point _cylindrical_axis_point1;
Expand Down
32 changes: 23 additions & 9 deletions modules/tensor_mechanics/src/actions/TensorMechanicsAction.C
Expand Up @@ -108,6 +108,7 @@ TensorMechanicsAction::TensorMechanicsAction(const InputParameters & params)
_cylindrical_axis_point1_valid(params.isParamSetByUser("cylindrical_axis_point1")),
_cylindrical_axis_point2_valid(params.isParamSetByUser("cylindrical_axis_point2")),
_direction_valid(params.isParamSetByUser("direction")),
_verbose(getParam<bool>("verbose")),
_auto_eigenstrain(getParam<bool>("automatic_eigenstrain_names"))
{
// determine if incremental strains are to be used
Expand Down Expand Up @@ -517,7 +518,17 @@ TensorMechanicsAction::actOutputGeneration()
_problem->addAuxKernel(
ad_prepend + "MaterialRealAux", _base_name + out + '_' + name(), params);
}
else
index++;
}
}
else if (_current_task == "add_kernel")
{
std::string ad_prepend = _use_ad ? "AD" : "";
// Loop through output aux variables
unsigned int index = 0;
for (auto out : _generate_output)
{
if (_material_output_family[index] != "MONOMIAL")
{
InputParameters params = emptyInputParameters();

Expand Down Expand Up @@ -681,10 +692,11 @@ TensorMechanicsAction::verifyOrderAndFamilyOutputs()
// For only one order, make all orders the same magnitude
if (order_check.size() == 1)
_material_output_order.assign(_generate_output.size(), _material_output_order[0]);
Moose::out << COLOR_CYAN << "*** Automatic applied material output orders ***"
<< "\n"
<< _name << ": " << Moose::stringify(_material_output_order) << "\n"
<< COLOR_DEFAULT;
if (_verbose)
Moose::out << COLOR_CYAN << "*** Automatic applied material output orders ***"
<< "\n"
<< _name << ": " << Moose::stringify(_material_output_order) << "\n"
<< COLOR_DEFAULT;
}

if (family_check.size() == _generate_output.size())
Expand All @@ -698,10 +710,11 @@ TensorMechanicsAction::verifyOrderAndFamilyOutputs()
_material_output_family.assign(_generate_output.size(), "MONOMIAL");
if (family_check.size() == 1)
_material_output_family.assign(_generate_output.size(), _material_output_family[0]);
Moose::out << COLOR_CYAN << "*** Automatic applied material output families ***"
<< "\n"
<< _name << ": " << Moose::stringify(_material_output_family) << "\n"
<< COLOR_DEFAULT;
if (_verbose)
Moose::out << COLOR_CYAN << "*** Automatic applied material output families ***"
<< "\n"
<< _name << ": " << Moose::stringify(_material_output_family) << "\n"
<< COLOR_DEFAULT;
}
}

Expand Down Expand Up @@ -730,6 +743,7 @@ TensorMechanicsAction::actOutputMatProp()
params.set<MaterialPropertyName>("rank_two_tensor") = _base_name + r2q.second;
params.set<unsigned int>("index_i") = a;
params.set<unsigned int>("index_j") = b;

params.applyParameters(parameters());
params.set<std::string>("property_name") = _base_name + out;
}
Expand Down
Expand Up @@ -153,6 +153,7 @@ TensorMechanicsActionBase::validParams()
"Specifies the family of FE shape functions to use for this variable.");
params.addParamNamesToGroup("generate_output material_output_order material_output_family",
"Output");
params.addParam<bool>("verbose", false, "Display extra information.");

return params;
}
Expand Down
@@ -1,5 +1,4 @@
# This input file is designed to test adding extra stress to ADComputeLinearElasticStress

[Mesh]
type = GeneratedMesh
dim = 2
Expand Down
3 changes: 3 additions & 0 deletions modules/tensor_mechanics/test/tests/action/tests
Expand Up @@ -130,6 +130,7 @@
type = RunApp
input = 'material_output_order.i'
expect_out = 'all: CONSTANT,CONSTANT,CONSTANT\n.*\nall: MONOMIAL,MONOMIAL,MONOMIAL\n'
cli_args ='Modules/TensorMechanics/Master/verbose=true'
design = 'syntax/Modules/TensorMechanics/Master/index.md'
requirement = 'The TensorMechanics MasterAction shall determine the necessary orders and families to apply to material outputs.'
[]
Expand All @@ -146,6 +147,8 @@
type = Exodiff
input = 'material_output_first_lagrange_manual.i'
exodiff = 'material_output_first_lagrange_manual_out.e'
max_parallel = 1
max_threads = 1
design = 'syntax/Modules/TensorMechanics/Master/index.md'
requirement = 'The TensorMechanics MasterAction shall determine the necessary orders and families to apply to material outputs.'
[]
Expand Down

0 comments on commit 627b4f7

Please sign in to comment.