Skip to content

Commit

Permalink
Proof of concept action (idaholab#26053)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen authored and oanaoana committed Dec 12, 2023
1 parent c5a247f commit fc2c2b3
Show file tree
Hide file tree
Showing 19 changed files with 951 additions and 10 deletions.
4 changes: 2 additions & 2 deletions framework/include/interfaces/BlockRestrictable.h
Expand Up @@ -137,14 +137,14 @@ class BlockRestrictable
/**
* Test if the supplied vector block ids are valid for this object
* @param ids A vector of SubdomainIDs ids to check
* @return True if the all of the given ids are found within the ids for this object
* @return True if all of the given ids are found within the ids for this object
*/
bool hasBlocks(const std::vector<SubdomainID> & ids) const;

/**
* Test if the supplied set of block ids are valid for this object
* @param ids A std::set of SubdomainIDs to check
* @return True if the all of the given ids are found within the ids for this object
* @return True if all of the given ids are found within the ids for this object
* \see isSubset
*/
bool hasBlocks(const std::set<SubdomainID> & ids) const;
Expand Down
@@ -0,0 +1,78 @@
//* 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

// Standard includes
#include <string>

// MOOSE includes
#include "MooseTypes.h"
#include "Material.h"

// Forward Declarations
class FEProblemBase;
class InputParameters;
class PostprocessorName;
class MooseObject;

/**
* Interface class for classes which interact with Postprocessors.
* Provides the getPostprocessorValueXYZ() and related interfaces.
*/
class InterpolatedStatefulMaterialPropertyInterface
{
public:
InterpolatedStatefulMaterialPropertyInterface(MooseObject * moose_object);

template <typename U>
const MaterialProperty<U> & getInterpolatedMaterialPropertyOld(const std::string & name);
template <typename U>
const MaterialProperty<U> & getInterpolatedMaterialPropertyOldByName(const std::string & name);

protected:
const std::string _pomps_prefix;

MooseObject * _moose_object;
MaterialPropertyInterface * _material_property_interface;
Material * _material;
};

InterpolatedStatefulMaterialPropertyInterface::InterpolatedStatefulMaterialPropertyInterface(
MooseObject * moose_object)
: _pomps_prefix("_pomps_"),
_moose_object(moose_object),
_material_property_interface(dynamic_cast<MaterialPropertyInterface *>(moose_object)),
_material(dynamic_cast<Material *>(moose_object))
{
if (!_material_property_interface && !_material)
mooseError("InterpolatedStatefulMaterialPropertyInterface can only be used from a class that "
"either derives from Material or MaterialPropertyInterface");
}

template <typename U>
const MaterialProperty<U> &
InterpolatedStatefulMaterialPropertyInterface::getInterpolatedMaterialPropertyOld(
const std::string & name)
{
return getInterpolatedMaterialPropertyOldByName<U>(
_material->getParam<MaterialPropertyName>(name));
}

template <typename U>
const MaterialProperty<U> &
InterpolatedStatefulMaterialPropertyInterface::getInterpolatedMaterialPropertyOldByName(
const std::string & name)
{
if (_material)
return _material->getMaterialPropertyByName<U>(_pomps_prefix + "mat_" + name);
else
return _material_property_interface->getMaterialPropertyOldByName<U>(_pomps_prefix + "mat_" +
name);
}
3 changes: 3 additions & 0 deletions framework/include/materials/MaterialPropertyInterface.h
Expand Up @@ -262,6 +262,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();

///@{
/**
* Check if the material property exists
Expand Down
2 changes: 2 additions & 0 deletions framework/src/base/Moose.C
Expand Up @@ -236,6 +236,7 @@ addActionTypes(Syntax & syntax)
registerTask("add_mortar_interface", false);
registerTask("coupling_functor_check", true);
registerTask("add_master_action_material", false);
registerTask("setup_projected_properties", false);

// Dummy Actions (useful for sync points in the dependencies)
registerTask("setup_function_complete", false);
Expand Down Expand Up @@ -336,6 +337,7 @@ addActionTypes(Syntax & syntax)
"(add_material)"
"(add_master_action_material)"
"(add_functor_material)"
"(setup_projected_properties)"
"(add_output_aux_variables)"
"(add_output)"
"(auto_checkpoint_action)"
Expand Down
36 changes: 30 additions & 6 deletions framework/src/materials/MaterialPropertyInterface.C
Expand Up @@ -134,12 +134,6 @@ MaterialPropertyInterface::statefulPropertiesAllowed(bool stateful_allowed)
_stateful_allowed = stateful_allowed;
}

MaterialBase &
MaterialPropertyInterface::getMaterial(const std::string & name)
{
return getMaterialByName(_mi_params.get<MaterialName>(name));
}

void
MaterialPropertyInterface::checkBlockAndBoundaryCompatibility(
std::shared_ptr<MaterialBase> discrete)
Expand Down Expand Up @@ -182,6 +176,12 @@ MaterialPropertyInterface::checkBlockAndBoundaryCompatibility(
}
}

MaterialBase &
MaterialPropertyInterface::getMaterial(const std::string & name)
{
return getMaterialByName(_mi_params.get<MaterialName>(name));
}

MaterialBase &
MaterialPropertyInterface::getMaterialByName(const std::string & name, bool no_warn)
{
Expand All @@ -192,6 +192,30 @@ MaterialPropertyInterface::getMaterialByName(const std::string & name, bool no_w
return *discrete;
}

std::set<MaterialBase *>
MaterialPropertyInterface::getSupplyerMaterials()
{
std::set<MaterialBase *> matches;
const auto & mwh = _mi_feproblem.getMaterialWarehouse();
for (const auto id : _mi_block_ids)
{
const auto & active_objects = mwh[_material_data_type].getActiveBlockObjects(id, _mi_tid);
for (const auto & mat : active_objects)
{
const auto & supplied_prop_ids = mat->getSuppliedPropIDs();
if (MooseUtils::setsIntersect(_material_property_dependencies.begin(),
_material_property_dependencies.end(),
supplied_prop_ids.begin(),
supplied_prop_ids.end()))
{
matches.insert(mat.get());
break;
}
}
}
return matches;
}

void
MaterialPropertyInterface::checkExecutionStage()
{
Expand Down
@@ -0,0 +1,66 @@
//* 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 "libmesh/fe_type.h"

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

ProjectedStatefulMaterialStorageAction(const InputParameters & parameters);

virtual void act() override;

protected:
/**
* Perform setup for a single scalar component of the material property prop_name, and gather the
* names of teh AuxVariables used to represent each component in `vars`.
*/
void processComponent(const std::string & prop_name,
std::vector<unsigned int> idx,
std::vector<VariableName> & vars,
bool is_ad);

/**
* Add the material object to obtain the interpolated old state (for use with
* InterpolatedStatefulMaterialPropertyInterface)
*/
void addMaterial(const std::string & prop_type,
const std::string & prop_name,
std::vector<VariableName> & vars);

enum class PropertyType
{
REAL,
REALVECTORVALUE,
RANKTWOTENSOR,
RANKFOURTENSOR
};
typedef std::pair<PropertyType, bool> PropertyInfo;

/**
* Return the property type and whether to use AD or not. If no property with a supported type is
* found, throw an error.
*/
PropertyInfo checkProperty(const std::string & prop_name);

const std::vector<MaterialPropertyName> & _prop_names;

const MooseEnum _order;
FEType _fe_type;
const std::string _var_type;
const std::string _pomps_prefix;
};
@@ -0,0 +1,37 @@
//* 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 "AuxKernel.h"
#include "IndexableProperty.h"

template <bool is_ad>
class ProjectedStatefulMaterialAuxTempl : public AuxKernel
{
public:
static InputParameters validParams();

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;
};

typedef ProjectedStatefulMaterialAuxTempl<false> ProjectedStatefulMaterialAux;
typedef ProjectedStatefulMaterialAuxTempl<true> ADProjectedStatefulMaterialAux;
@@ -0,0 +1,50 @@
//* 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 "Material.h"
#include "RankTwoTensorForward.h"
#include "RankFourTensorForward.h"

/**
* PowerLawSoftening is a smeared crack softening model that
* uses a power law equation to soften the tensile response.
* It is for use with ComputeSmearedCrackingStress.
*/
class InterpolatedStatefulMaterial : public Material
{
public:
static InputParameters validParams();

InterpolatedStatefulMaterial(const InputParameters & parameters);

virtual void computeQpProperties() override;

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

/// emitted property name
const MaterialPropertyName _prop_name;

/// Property type
enum class PropType
{
REAL,
REALVECTORVALUE,
RANKTWOTENSOR,
RANKFOURTENSOR
} _prop_type;

MaterialProperty<Real> * _prop_real;
MaterialProperty<RealVectorValue> * _prop_realvectorvalue;
MaterialProperty<RankTwoTensor> * _prop_ranktwotensor;
MaterialProperty<RankFourTensor> * _prop_rankfourtensor;
};
Expand Up @@ -11,8 +11,6 @@

#include "SmearedCrackSofteningBase.h"

// Forward declaration

/**
* PowerLawSoftening is a smeared crack softening model that
* uses a power law equation to soften the tensile response.
Expand Down
@@ -0,0 +1,35 @@
//* 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

// MOOSE includes
#include "NodalPatchRecoveryMaterialProperty.h"

/**
* Nodal patch recovery for material property components for projected stateful properties
*/
class ProjectedStatefulMaterialNodalPatchRecovery : public NodalPatchRecoveryMaterialProperty
{
public:
static InputParameters validParams();

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;
};

0 comments on commit fc2c2b3

Please sign in to comment.