Skip to content

Commit

Permalink
Merge pull request #26054 from dschwen/projected_stateful_properties
Browse files Browse the repository at this point in the history
Projected stateful properties
  • Loading branch information
dschwen authored Dec 11, 2023
2 parents 53b2b79 + ddef998 commit fc5457f
Show file tree
Hide file tree
Showing 53 changed files with 2,003 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ProjectedStatefulMaterialStorageAction

## Description

The `ProjectedStatefulMaterialStorageAction` is the main action in the
[ProjectedStatefulMaterialStorage](/ProjectedStatefulMaterialStorage/index.md)
system which sets up all necessary objects to project material property
components onto nodal or elemental basis functions.

Projected and interpolated old state can be enabled using the
`use_inerpolated_state` parameter available in the `MaterialPropertyInterface`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ProjectedMaterialPropertyNodalPatchRecoveryAux

This AuxKernel performs nodal patch recovery of a material property component with data prepared by a [ProjectedStatefulMaterialNodalPatchRecovery](ProjectedStatefulMaterialNodalPatchRecovery.md) object with the purpose of projecting the property onto a nodal basis function (e.g. first order Lagrange).

This object is set up by the [ProjectedStatefulMaterialStorageAction](ProjectedStatefulMaterialStorageAction.md).

See also [ProjectedStatefulMaterialAux](ProjectedStatefulMaterialAux.md) for the AuxKernel that projects onto elemental basis functions.

!syntax description /AuxKernels/ProjectedMaterialPropertyNodalPatchRecoveryAux

!syntax parameters /AuxKernels/ProjectedMaterialPropertyNodalPatchRecoveryAux

!syntax inputs /AuxKernels/ProjectedMaterialPropertyNodalPatchRecoveryAux

!syntax children /AuxKernels/ProjectedMaterialPropertyNodalPatchRecoveryAux
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ProjectedStatefulMaterial...Aux

This AuxKernel simply returns the value of a given material property (or component of the property value) at a quadrature point with the purpose of projecting the property onto an elemental basis function (e.g. first order monomial).

Variants include:
- `ProjectedStatefulMaterialRealAux`
- `ProjectedStatefulMaterialRealVectorValueAux`
- `ProjectedStatefulMaterialRankTwoTensorAux`
- `ProjectedStatefulMaterialRankFourTensorAux`
- `ADProjectedStatefulMaterialRealAux`
- `ADProjectedStatefulMaterialRealVectorValueAux`
- `ADProjectedStatefulMaterialRankTwoTensorAux`
- `ADProjectedStatefulMaterialRankFourTensorAux`

At step zero this object will compute the material QP values by explicitly calling `initStatefulProperties` in order to project the state that will correspond to the *old state* in the first timestep.

This object is set up by the [ProjectedStatefulMaterialStorageAction](ProjectedStatefulMaterialStorageAction.md).

See also [ProjectedMaterialPropertyNodalPatchRecoveryAux](ProjectedMaterialPropertyNodalPatchRecoveryAux.md) for the AuxKernel that projects onto nodal basis functions.

!syntax description /AuxKernels/ProjectedStatefulMaterialRealAux

!syntax parameters /AuxKernels/ProjectedStatefulMaterialRealAux

!syntax inputs /AuxKernels/ProjectedStatefulMaterialRealAux

!syntax children /AuxKernels/ProjectedStatefulMaterialRealAux
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# InterpolatedStatefulMaterialPropertyInterface

The InterpolatedStatefulMaterialPropertyInterface provides the `getInterpolatedMaterialPropertyOld`
and `getInterpolatedMaterialPropertyOldByName` methods. This is likely to get integrated into the `MaterialPropertyInterface`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# InterpolatedStatefulMaterial...

!syntax description /Materials/InterpolatedStatefulMaterialReal

## Description

`InterpolatedStatefulMaterial` reconstitutes the old state of a material property from the old state of the AuxVariables holding the projected components of the material property.

Variants include:
- `InterpolatedStatefulMaterialReal`
- `InterpolatedStatefulMaterialRealVectorValue`
- `InterpolatedStatefulMaterialRankTwoTensor`
- `InterpolatedStatefulMaterialRankFourTensor`

This object is set up by the [ProjectedStatefulMaterialStorageAction](ProjectedStatefulMaterialStorageAction.md).

!syntax parameters /Materials/InterpolatedStatefulMaterialReal

!syntax inputs /Materials/InterpolatedStatefulMaterialReal

!syntax children /Materials/InterpolatedStatefulMaterialReal

!bibtex bibliography
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# NodalPatchRecoveryMaterialProperty

This user object performs the calculations and parallel communication to perform
the Zienkiewicz-Zhu nodal patch recovery for a scalar component of a provided
material property. Supported material property types are listed in
[IndexableProperty](IndexableProperty.md).

!syntax description /UserObjects/NodalPatchRecoveryMaterialProperty

!syntax parameters /UserObjects/NodalPatchRecoveryMaterialProperty

!syntax inputs /UserObjects/NodalPatchRecoveryMaterialProperty

!syntax children /UserObjects/NodalPatchRecoveryMaterialProperty
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ProjectedStatefulMaterialNodalPatchRecovery...

This user object performs patch recovery for a material property component. At step zero this object will compute the material QP values by explicitly calling `initStatefulProperties` in order to project the state that will correspond to the *old state* in the first time step.

Variants include:
- `ProjectedStatefulMaterialNodalPatchRecoveryReal`
- `ProjectedStatefulMaterialNodalPatchRecoveryRealVectorValue`
- `ProjectedStatefulMaterialNodalPatchRecoveryRankTwoTensor`
- `ProjectedStatefulMaterialNodalPatchRecoveryRankFourTensor`
- `ADProjectedStatefulMaterialNodalPatchRecoveryReal`
- `ADProjectedStatefulMaterialNodalPatchRecoveryRealVectorValue`
- `ADProjectedStatefulMaterialNodalPatchRecoveryRankTwoTensor`
- `ADProjectedStatefulMaterialNodalPatchRecoveryRankFourTensor`

This object is set up by the [ProjectedStatefulMaterialStorageAction](ProjectedStatefulMaterialStorageAction.md).

!syntax description /UserObjects/ProjectedStatefulMaterialNodalPatchRecoveryReal

!syntax parameters /UserObjects/ProjectedStatefulMaterialNodalPatchRecoveryReal

!syntax inputs /UserObjects/ProjectedStatefulMaterialNodalPatchRecoveryReal

!syntax children /UserObjects/ProjectedStatefulMaterialNodalPatchRecoveryReal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ProjectedStatefulMaterialStorage System

The `ProjectedStatefulMaterialStorage` Action sets up the required objects to
store old material state projected onto finite element basis functions. See the
documentation for
[ProjectedStatefulMaterialStorageAction](ProjectedStatefulMaterialStorageAction.md)
for details.

!syntax list /ProjectedStatefulMaterialStorage objects=True actions=False subsystems=False

!syntax list /ProjectedStatefulMaterialStorage objects=False actions=False subsystems=True

!syntax list /ProjectedStatefulMaterialStorage objects=False actions=True subsystems=False
179 changes: 179 additions & 0 deletions framework/include/actions/ProjectedStatefulMaterialStorageAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "Action.h"
#include "Registry.h"
#include "Conversion.h"
#include "SerialAccess.h"
#include "RankTwoTensorForward.h"
#include "RankFourTensorForward.h"
#include "libmesh/fe_type.h"

// created types
#include "InterpolatedStatefulMaterial.h"
#include "ProjectedStatefulMaterialAux.h"
#include "ProjectedStatefulMaterialNodalPatchRecovery.h"

/**
* Set up AuxKernels and AuxVariables for projected material property storage (PoMPS).
*/
class ProjectedStatefulMaterialStorageAction : public Action
{
public:
static InputParameters validParams();

ProjectedStatefulMaterialStorageAction(const InputParameters & parameters);

virtual void act() override;

using Action::addRelationshipManagers;
virtual void addRelationshipManagers(Moose::RelationshipManagerType input_rm_type) override;

/// List of supported raw types (equivalent AD types are also supported)
typedef Moose::TypeList<Real, RealVectorValue, RankTwoTensor, RankFourTensor> SupportedTypes;

/// get an enum with all supported types
static MooseEnum getTypeEnum();

template <typename T, bool is_ad>
void processProperty(const MaterialPropertyName & prop_name);

protected:
template <typename T, int I>
struct ProcessProperty
{
static void apply(ProjectedStatefulMaterialStorageAction * self,
const MaterialPropertyName & prop_name)
{
self->processProperty<T, false>(prop_name);
self->processProperty<T, true>(prop_name);
}
};

template <typename... Ts>
static MooseEnum getTypeEnum(typename Moose::TypeList<Ts...>);

/// Property names for which we will do stateful material property projection
const std::vector<MaterialPropertyName> & _prop_names;

/// Variable order to project the properties into
const MooseEnum _order;

/// FEType for the variables to project the properties into
FEType _fe_type;

/// MooseObject name for the underlying variable type
const std::string _var_type;
};

template <typename... Ts>
MooseEnum
ProjectedStatefulMaterialStorageAction::getTypeEnum(Moose::TypeList<Ts...>)
{
return MooseEnum(Moose::stringify(std::vector<std::string>{typeid(Ts).name()...}, " "));
}

template <typename T, bool is_ad>
void
ProjectedStatefulMaterialStorageAction::processProperty(const MaterialPropertyName & prop_name)
{
// check if a property of type T exists
const auto & block_data = _problem->getMaterialData(Moose::BLOCK_MATERIAL_DATA);
const auto & boundary_data = _problem->getMaterialData(Moose::BOUNDARY_MATERIAL_DATA);
if (!block_data.haveGenericProperty<T, is_ad>(prop_name) &&
!boundary_data.haveGenericProperty<T, is_ad>(prop_name))
return;

// number of scalar components
const auto size = Moose::SerialAccess<T>::size();

// generate variable names
std::vector<VariableName> vars;
for (const auto i : make_range(size))
vars.push_back("_var_" + prop_name + '_' + Moose::stringify(i));

if (_current_task == "setup_projected_properties")
{
// add the AuxVars for storage
for (const auto & var : vars)
{
auto params = _factory.getValidParams(_var_type);
params.applyParameters(parameters());
params.set<std::vector<OutputName>>("outputs") = {"none"};
_problem->addAuxVariable(_var_type, var, params);
}

// add material
{
const auto type = Registry::getClassName<InterpolatedStatefulMaterialTempl<T>>();
auto params = _factory.getValidParams(type);
params.applySpecificParameters(parameters(), {"block"});
params.template set<std::vector<VariableName>>("old_state") = vars;
params.template set<MaterialPropertyName>("prop_name") = prop_name;
_problem->addMaterial(type, "_mat_" + prop_name, params);
}

// use nodal patch recovery for lagrange
if (_fe_type.family == LAGRANGE)
{
// nodal variables require patch recovery (add user object)
const auto & type =
Registry::getClassName<ProjectedStatefulMaterialNodalPatchRecoveryTempl<T, is_ad>>();
auto params = _factory.getValidParams(type);
params.applySpecificParameters(parameters(), {"block"});
params.template set<MaterialPropertyName>("property") = prop_name;
params.template set<MooseEnum>("patch_polynomial_order") = _order;
params.template set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
params.template set<bool>("force_preaux") = true;
_problem->addUserObject(type, "_npruo_" + prop_name, params);
}
}

if (_current_task == "add_aux_kernel")
{
// create variables
std::vector<std::string> auxnames;
for (const auto i : make_range(size))
auxnames.push_back("_aux_" + prop_name + '_' + Moose::stringify(i));

// use nodal patch recovery for lagrange
if (_fe_type.family == LAGRANGE)
{
// nodal variables require patch recovery (add aux kernel)
const auto & type = "ProjectedMaterialPropertyNodalPatchRecoveryAux";
for (const auto i : make_range(size))
{
auto params = _factory.getValidParams(type);
params.applySpecificParameters(parameters(), {"block"});
params.template set<AuxVariableName>("variable") = vars[i];
params.template set<unsigned int>("component") = i;
params.template set<UserObjectName>("nodal_patch_recovery_uo") = "_npruo_" + prop_name;
params.template set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
_problem->addAuxKernel(type, auxnames[i], params);
}
}
else
{
// elemental variables
const auto & type = Registry::getClassName<ProjectedStatefulMaterialAuxTempl<T, is_ad>>();
for (const auto i : make_range(size))
{
auto params = _factory.getValidParams(type);
params.applySpecificParameters(parameters(), {"block"});
params.template set<AuxVariableName>("variable") = vars[i];
params.template set<unsigned int>("component") = i;
params.template set<MaterialPropertyName>("prop") = prop_name;
params.template set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
_problem->addAuxKernel(type, auxnames[i], params);
}
}
}
}
29 changes: 29 additions & 0 deletions framework/include/auxkernels/NodalPatchRecoveryAux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "NodalPatchRecoveryAuxBase.h"

/// Forward declare user object
class NodalPatchRecoveryBase;

class NodalPatchRecoveryAux : public NodalPatchRecoveryAuxBase
{
public:
static InputParameters validParams();

NodalPatchRecoveryAux(const InputParameters & parameters);

protected:
virtual Real nodalPatchRecovery() override;

private:
const NodalPatchRecoveryBase & _npr;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

class NodalPatchRecoveryBase;

class NodalPatchRecoveryAux : public AuxKernel
class NodalPatchRecoveryAuxBase : public AuxKernel
{
public:
static InputParameters validParams();

NodalPatchRecoveryAux(const InputParameters & parameters);
NodalPatchRecoveryAuxBase(const InputParameters & parameters);

/**
* Block restrict elements on which to perform the variable/property nodal recovery.
Expand All @@ -29,6 +29,9 @@ class NodalPatchRecoveryAux : public AuxKernel
protected:
virtual Real computeValue() override;

private:
const NodalPatchRecoveryBase & _npr;
/// Override this to get the fitted value from a Nodal Patch Recovery User Object
virtual Real nodalPatchRecovery() = 0;

/// local patch of elements used for recovery
std::vector<dof_id_type> _elem_ids;
};
Loading

0 comments on commit fc5457f

Please sign in to comment.