https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ProjectedStatefulMaterialStorageAction.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "Action.h"
13#include "Registry.h"
14#include "Conversion.h"
15#include "SerialAccess.h"
18#include "libmesh/fe_type.h"
19
20// created types
24
29{
30public:
32
34
35 virtual void act() override;
36
38 virtual void addRelationshipManagers(Moose::RelationshipManagerType input_rm_type) override;
39
42
44 static MooseEnum getTypeEnum();
45
46 template <typename T, bool is_ad>
47 void processProperty(const MaterialPropertyName & prop_name);
48
49protected:
50 template <typename T, int I>
52 {
54 const MaterialPropertyName & prop_name)
55 {
56 self->processProperty<T, false>(prop_name);
57 self->processProperty<T, true>(prop_name);
58 }
59 };
60
61 template <typename... Ts>
63
65 const std::vector<MaterialPropertyName> & _prop_names;
66
69
71 FEType _fe_type;
72
74 const std::string _var_type;
75};
76
77template <typename... Ts>
80{
81 return MooseEnum(Moose::stringify(std::vector<std::string>{typeid(Ts).name()...}, " "));
82}
83
84template <typename T, bool is_ad>
85void
86ProjectedStatefulMaterialStorageAction::processProperty(const MaterialPropertyName & prop_name)
87{
88 // check if a property of type T exists
89 const auto & block_data = _problem->getMaterialData(Moose::BLOCK_MATERIAL_DATA);
90 const auto & boundary_data = _problem->getMaterialData(Moose::BOUNDARY_MATERIAL_DATA);
91 if (!block_data.haveGenericProperty<T, is_ad>(prop_name) &&
92 !boundary_data.haveGenericProperty<T, is_ad>(prop_name))
93 return;
94
95 // number of scalar components
96 const auto size = Moose::SerialAccess<T>::size();
97
98 // generate variable names
99 std::vector<VariableName> vars;
100 for (const auto i : make_range(size))
101 vars.push_back("_var_" + prop_name + '_' + Moose::stringify(i));
102
103 if (_current_task == "setup_projected_properties")
104 {
105 // add the AuxVars for storage
106 for (const auto & var : vars)
107 {
108 auto params = _factory.getValidParams(_var_type);
109 params.applyParameters(parameters());
110 params.set<std::vector<OutputName>>("outputs") = {"none"};
111 _problem->addAuxVariable(_var_type, var, params);
112 }
113
114 // add material
115 {
116 const auto type = Registry::getClassName<InterpolatedStatefulMaterialTempl<T>>();
117 auto params = _factory.getValidParams(type);
118 params.applySpecificParameters(parameters(), {"block"});
119 params.template set<std::vector<VariableName>>("old_state") = vars;
120 params.template set<MaterialPropertyName>("prop_name") = prop_name;
121 _problem->addMaterial(type, "_mat_" + prop_name, params);
122 }
123
124 // use nodal patch recovery for lagrange
125 if (_fe_type.family == LAGRANGE)
126 {
127 // nodal variables require patch recovery (add user object)
128 const auto & type =
129 Registry::getClassName<ProjectedStatefulMaterialNodalPatchRecoveryTempl<T, is_ad>>();
130 auto params = _factory.getValidParams(type);
131 params.applySpecificParameters(parameters(), {"block"});
132 params.template set<MaterialPropertyName>("property") = prop_name;
133 params.template set<MooseEnum>("patch_polynomial_order") = _order;
134 params.template set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
135 params.template set<bool>("force_preaux") = true;
136 _problem->addUserObject(type, "_npruo_" + prop_name, params);
137 }
138 }
139
140 if (_current_task == "add_aux_kernel")
141 {
142 // create variables
143 std::vector<std::string> auxnames;
144 for (const auto i : make_range(size))
145 auxnames.push_back("_aux_" + prop_name + '_' + Moose::stringify(i));
146
147 // use nodal patch recovery for lagrange
148 if (_fe_type.family == LAGRANGE)
149 {
150 // nodal variables require patch recovery (add aux kernel)
151 const auto & type = "ProjectedMaterialPropertyNodalPatchRecoveryAux";
152 for (const auto i : make_range(size))
153 {
154 auto params = _factory.getValidParams(type);
155 params.applySpecificParameters(parameters(), {"block"});
156 params.template set<AuxVariableName>("variable") = vars[i];
157 params.template set<unsigned int>("component") = i;
158 params.template set<UserObjectName>("nodal_patch_recovery_uo") = "_npruo_" + prop_name;
159 params.template set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
160 _problem->addAuxKernel(type, auxnames[i], params);
161 }
162 }
163 else
164 {
165 // elemental variables
166 const auto & type = Registry::getClassName<ProjectedStatefulMaterialAuxTempl<T, is_ad>>();
167 for (const auto i : make_range(size))
168 {
169 auto params = _factory.getValidParams(type);
170 params.applySpecificParameters(parameters(), {"block"});
171 params.template set<AuxVariableName>("variable") = vars[i];
172 params.template set<unsigned int>("component") = i;
173 params.template set<MaterialPropertyName>("prop") = prop_name;
174 params.template set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
175 _problem->addAuxKernel(type, auxnames[i], params);
176 }
177 }
178 }
179}
const ExecFlagType EXEC_TIMESTEP_END
Definition Moose.C:36
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
char ** vars
Base class for actions.
Definition Action.h:38
bool addRelationshipManagers(Moose::RelationshipManagerType when_type, const InputParameters &moose_object_pars)
Method to add a relationship manager for the objects being added to the system.
Definition Action.C:148
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition Action.h:178
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition Action.h:172
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void applySpecificParameters(const InputParameters &common, const std::vector< std::string > &include, bool allow_private=false)
Method for applying common parameters.
void applyParameters(const InputParameters &common, const std::vector< std::string > &exclude={}, const bool allow_private=false)
Method for applying common parameters.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Factory & _factory
The Factory associated with the MooseApp.
Set up AuxKernels and AuxVariables for projected material property storage (PoMPS).
static MooseEnum getTypeEnum()
get an enum with all supported types
void processProperty(const MaterialPropertyName &prop_name)
FEType _fe_type
FEType for the variables to project the properties into.
const std::vector< MaterialPropertyName > & _prop_names
Property names for which we will do stateful material property projection.
const MooseEnum _order
Variable order to project the properties into.
virtual void addRelationshipManagers(Moose::RelationshipManagerType input_rm_type) override
Method to add a relationship manager for the objects being added to the system.
const std::string _var_type
MooseObject name for the underlying variable type.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
Moose::TypeList< Real, RealVectorValue, RankTwoTensor, RankFourTensor > SupportedTypes
List of supported raw types (equivalent AD types are also supported)
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64
RelationshipManagerType
Main types of Relationship Managers.
@ BOUNDARY_MATERIAL_DATA
Definition MooseTypes.h:748
@ BLOCK_MATERIAL_DATA
Definition MooseTypes.h:747
Serial access requires object data to be stored contiguously.
Helper structure to hold a list of types.
static void apply(ProjectedStatefulMaterialStorageAction *self, const MaterialPropertyName &prop_name)