Skip to content

Commit

Permalink
Fix unity build, docs, and paralleleization (idaholab#26053)
Browse files Browse the repository at this point in the history
and move everything into framework
  • Loading branch information
dschwen committed Dec 2, 2023
1 parent e417194 commit 12d6008
Show file tree
Hide file tree
Showing 39 changed files with 295 additions and 309 deletions.
Expand Up @@ -24,6 +24,9 @@ class ProjectedStatefulMaterialStorageAction : public Action

virtual void act() override;

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

protected:
/**
* Perform setup for a single scalar component of the material property prop_name, and gather the
Expand Down
Expand Up @@ -12,6 +12,10 @@
#include "AuxKernel.h"
#include "IndexableProperty.h"

#include <deque>

class MaterialBase;

template <bool is_ad>
class ProjectedStatefulMaterialAuxTempl : public AuxKernel
{
Expand All @@ -21,16 +25,14 @@ class ProjectedStatefulMaterialAuxTempl : public AuxKernel
ProjectedStatefulMaterialAuxTempl(const InputParameters & parameters);

virtual void initialSetup() override;
virtual void subdomainSetup() override;

protected:
virtual Real computeValue() override;

const IndexableProperty<AuxKernel, is_ad> _prop;
const SubdomainID & _current_subdomain_id;

std::set<MaterialBase *> _all_materials;
std::vector<MaterialBase *> _active_materials;
std::map<SubdomainID, std::vector<MaterialBase *>> _required_materials;
};

typedef ProjectedStatefulMaterialAuxTempl<false> ProjectedStatefulMaterialAux;
Expand Down

This file was deleted.

Expand Up @@ -28,9 +28,12 @@ class InterpolatedStatefulMaterial : public Material
virtual void computeQpProperties() override;

protected:
/// Old state
/// Old projected state
const std::vector<const VariableValue *> _old_state;

/// Older projected state
const std::vector<const VariableValue *> _older_state;

/// emitted property name
const MaterialPropertyName _prop_name;

Expand All @@ -43,8 +46,17 @@ class InterpolatedStatefulMaterial : public Material
RANKFOURTENSOR
} _prop_type;

MaterialProperty<Real> * _prop_real;
MaterialProperty<RealVectorValue> * _prop_realvectorvalue;
MaterialProperty<RankTwoTensor> * _prop_ranktwotensor;
MaterialProperty<RankFourTensor> * _prop_rankfourtensor;
///@{ Old interpolated properties
MaterialProperty<Real> * _prop_old_real;
MaterialProperty<RealVectorValue> * _prop_old_realvectorvalue;
MaterialProperty<RankTwoTensor> * _prop_old_ranktwotensor;
MaterialProperty<RankFourTensor> * _prop_old_rankfourtensor;
///@}

///@{ Older interpolated properties
MaterialProperty<Real> * _prop_older_real;
MaterialProperty<RealVectorValue> * _prop_older_realvectorvalue;
MaterialProperty<RankTwoTensor> * _prop_older_ranktwotensor;
MaterialProperty<RankFourTensor> * _prop_older_rankfourtensor;
///@}
};
8 changes: 8 additions & 0 deletions framework/include/materials/Material.h
Expand Up @@ -274,6 +274,14 @@ const GenericMaterialProperty<T, is_ad> &
Material::getGenericMaterialPropertyByName(const std::string & prop_name_in,
const unsigned int state)
{
if (_use_interpolated_state)
{
if (state == 1)
return getGenericMaterialPropertyByName<T, is_ad>(prop_name_in + "_interpolated_old", 0);
if (state == 2)
return getGenericMaterialPropertyByName<T, is_ad>(prop_name_in + "_interpolated_older", 0);
}

MaterialBase::checkExecutionStage();

// The property may not exist yet, so declare it (declare/getMaterialProperty are referencing the
Expand Down
20 changes: 18 additions & 2 deletions framework/include/materials/MaterialPropertyInterface.h
Expand Up @@ -18,6 +18,8 @@
#include "InputParameters.h"
#include "SubProblem.h"

#include <deque>

// Forward declarations
class MooseObject;
class FEProblemBase;
Expand Down Expand Up @@ -262,8 +264,9 @@ class MaterialPropertyInterface
MaterialBase & getMaterialByName(const std::string & name, bool no_warn = false);
///@}

/// get a set of MaterialBase pointers for all material objects that this object depends on
std::set<MaterialBase *> getSupplyerMaterials();
/// get a map of MaterialBase pointers for all material objects that this object depends on for each block
std::map<SubdomainID, std::vector<MaterialBase *>>
buildRequiredMaterials(bool allow_stateful = true);

///@{
/**
Expand Down Expand Up @@ -532,6 +535,9 @@ class MaterialPropertyInterface

const MaterialPropertyName _get_suffix;

/// Use the interpolated state set up through the ProjectedStatefulMaterialStorageAction
const bool _use_interpolated_state;

private:
/**
* @returns The MaterialDataType given the interface's parameters
Expand Down Expand Up @@ -765,6 +771,16 @@ MaterialPropertyInterface::getGenericMaterialPropertyByName(const MaterialProper
MaterialData & material_data,
const unsigned int state)
{
if (_use_interpolated_state)
{
if (state == 1)
return getGenericMaterialPropertyByName<T, is_ad>(
name_in + "_interpolated_old", material_data, 0);
if (state == 2)
return getGenericMaterialPropertyByName<T, is_ad>(
name_in + "_interpolated_older", material_data, 0);
}

const auto name = _get_suffix.empty()
? static_cast<const std::string &>(name_in)
: MooseUtils::join(std::vector<std::string>({name_in, _get_suffix}), "_");
Expand Down
Expand Up @@ -12,6 +12,10 @@
// MOOSE includes
#include "NodalPatchRecoveryMaterialProperty.h"

#include <deque>

class MaterialBase;

/**
* Nodal patch recovery for material property components for projected stateful properties
*/
Expand All @@ -23,13 +27,11 @@ class ProjectedStatefulMaterialNodalPatchRecovery : public NodalPatchRecoveryMat
ProjectedStatefulMaterialNodalPatchRecovery(const InputParameters & parameters);

virtual void initialSetup() override;
virtual void subdomainSetup() override;

protected:
virtual Real computeValue() override;

const SubdomainID & _current_subdomain_id;

std::set<MaterialBase *> _all_materials;
std::vector<MaterialBase *> _active_materials;
std::map<SubdomainID, std::vector<MaterialBase *>> _required_materials;
};
Expand Up @@ -62,6 +62,14 @@ ProjectedStatefulMaterialStorageAction::ProjectedStatefulMaterialStorageAction(
{
}

void
ProjectedStatefulMaterialStorageAction::addRelationshipManagers(
Moose::RelationshipManagerType input_rm_type)
{
auto params = _factory.getValidParams("ProjectedStatefulMaterialNodalPatchRecovery");
addRelationshipManagers(input_rm_type, params);
}

void
ProjectedStatefulMaterialStorageAction::processComponent(const std::string & prop_name,
std::vector<unsigned int> idx,
Expand All @@ -79,6 +87,7 @@ ProjectedStatefulMaterialStorageAction::processComponent(const std::string & pro

const auto var_name = name("var");
vars.push_back(var_name);
const auto uo_name = name("uo");

if (_current_task == "setup_projected_properties")
{
Expand All @@ -87,38 +96,36 @@ ProjectedStatefulMaterialStorageAction::processComponent(const std::string & pro
params.applyParameters(parameters());
params.set<std::vector<OutputName>>("outputs") = {"none"};
_problem->addAuxVariable(_var_type, var_name, params);

// use nodal patch recovery for lagrange
if (_fe_type.family == LAGRANGE)
{
// nodal variables require patch recovery (add user object)
const auto & type_name = is_ad ? "ADProjectedStatefulMaterialNodalPatchRecovery"
: "ProjectedStatefulMaterialNodalPatchRecovery";
auto params = _factory.getValidParams(type_name);
params.applySpecificParameters(parameters(), {"block"});
params.set<std::vector<unsigned int>>("component") = idx;
params.set<MaterialPropertyName>("property") = prop_name;
params.set<MooseEnum>("patch_polynomial_order") = _order;
params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
params.set<bool>("force_preaux") = true;
_problem->addUserObject(type_name, uo_name, params);
}
}

if (_current_task == "add_aux_kernel")
{
// use nodal patch recovery for lagrange
if (_fe_type.family == LAGRANGE)
{
// nodal variables require patch recovery
const auto uo_name = name("uo");

{
// add user object
const auto & type_name = is_ad ? "ADProjectedStatefulMaterialNodalPatchRecovery"
: "ProjectedStatefulMaterialNodalPatchRecovery";
auto params = _factory.getValidParams(type_name);
params.applySpecificParameters(parameters(), {"block"});
params.set<std::vector<unsigned int>>("component") = idx;
params.set<MaterialPropertyName>("property") = prop_name;
params.set<MooseEnum>("patch_polynomial_order") = _order;
params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
_problem->addUserObject(type_name, uo_name, params);
}

{
// add aux kernel
auto params = _factory.getValidParams("NodalPatchRecoveryAux");
params.applySpecificParameters(parameters(), {"block"});
params.set<AuxVariableName>("variable") = var_name;
params.set<UserObjectName>("nodal_patch_recovery_uo") = uo_name;
params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
_problem->addAuxKernel("NodalPatchRecoveryAux", name("aux"), params);
}
// nodal variables require patch recovery (add aux kernel)
auto params = _factory.getValidParams("NodalPatchRecoveryAux");
params.applySpecificParameters(parameters(), {"block"});
params.set<AuxVariableName>("variable") = var_name;
params.set<UserObjectName>("nodal_patch_recovery_uo") = uo_name;
params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
_problem->addAuxKernel("NodalPatchRecoveryAux", name("aux"), params);
}
else
{
Expand Down Expand Up @@ -175,12 +182,11 @@ ProjectedStatefulMaterialStorageAction::addMaterial(const std::string & prop_typ
std::vector<VariableName> & vars)
{
auto params = _factory.getValidParams("InterpolatedStatefulMaterial");
const auto name = _pomps_prefix + "mat_" + prop_name;
params.applySpecificParameters(parameters(), {"block"});
params.set<std::vector<VariableName>>("old_state") = vars;
params.set<MooseEnum>("prop_type") = prop_type;
params.set<MaterialPropertyName>("prop_name") = name;
_problem->addMaterial("InterpolatedStatefulMaterial", name, params);
params.set<MaterialPropertyName>("prop_name") = prop_name;
_problem->addMaterial("InterpolatedStatefulMaterial", _pomps_prefix + "mat_" + prop_name, params);
}

void
Expand Down
Expand Up @@ -10,7 +10,7 @@
#include "NodalPatchRecoveryAux.h"
#include "NodalPatchRecoveryBase.h"

registerMooseObject("TensorMechanicsApp", NodalPatchRecoveryAux);
registerMooseObject("MooseApp", NodalPatchRecoveryAux);

InputParameters
NodalPatchRecoveryAux::validParams()
Expand Down
Expand Up @@ -10,9 +10,10 @@
#include "ProjectedStatefulMaterialAux.h"
#include "NodalPatchRecoveryBase.h"
#include "MaterialBase.h"
#include "Assembly.h"

registerMooseObject("TensorMechanicsApp", ProjectedStatefulMaterialAux);
registerMooseObject("TensorMechanicsApp", ADProjectedStatefulMaterialAux);
registerMooseObject("MooseApp", ProjectedStatefulMaterialAux);
registerMooseObject("MooseApp", ADProjectedStatefulMaterialAux);

template <bool is_ad>
InputParameters
Expand All @@ -39,26 +40,15 @@ ProjectedStatefulMaterialAuxTempl<is_ad>::initialSetup()
_prop.check();

// get all material classes that provide properties for this object
_all_materials = getSupplyerMaterials();
}

template <bool is_ad>
void
ProjectedStatefulMaterialAuxTempl<is_ad>::subdomainSetup()
{
// get materials for the current subdomain
_active_materials.clear();
for (const auto & mat : _all_materials)
if (mat->hasBlocks(_current_subdomain_id))
_active_materials.push_back(mat);
_required_materials = buildRequiredMaterials();
}

template <bool is_ad>
Real
ProjectedStatefulMaterialAuxTempl<is_ad>::computeValue()
{
if (_t_step == 0)
for (const auto & mat : _active_materials)
for (const auto & mat : _required_materials[_current_subdomain_id])
mat->initStatefulProperties(_qrule->size());

return MetaPhysicL::raw_value(_prop[_qp]);
Expand Down

0 comments on commit 12d6008

Please sign in to comment.