v0.16.3
Loading...
Searching...
No Matches
MatOps.hpp
Go to the documentation of this file.
1/**
2 * \file MatOps.hpp
3 * \example mofem/src/materials/MatOps.hpp
4 *
5 * @copyright Copyright (c) 2023
6 */
7
8#ifndef __MAT_OPS_HPP__
9#define __MAT_OPS_HPP__
10
11namespace MatOps {
12
13// One valid tag-info type for addTagDGProjectionOps(...).
14// Equivalent to std::tuple<std::string, Tag, int>.
15struct StateTag {
16 std::string name;
17 Tag tag = 0;
19};
20
21using StateTags = std::vector<StateTag>;
22using DataDictionary = std::map<std::string, std::string>;
23
25
26 static int atTagName(std::string name);
27 static int setTagName(std::string name, int tag = -1);
28 static std::string getTagName(int tag);
29
30protected:
31 static int getTagByName(std::string name);
32 static inline std::map<std::string, int> tagNameVsTag;
33};
34
35/** \name MatOps Data Interface */
36/**@{*/
37/** Named constitutive inputs, outputs and tag-backed integration-point state.
38 * State tags expose their current contents; callers manage physical time
39 * levels, acceptance and rollback. Insert methods report whether a name was
40 * added; existing entries are not overwritten.
41 */
42struct MatOpsData : public boost::enable_shared_from_this<MatOpsData> {
43 virtual ~MatOpsData() = default;
44
45 using MatrixPtr = boost::shared_ptr<MatrixDouble>;
46 using StateMatrixPtr = boost::shared_ptr<MatrixAdaptor>;
47
48 /// Base for user-defined material data, supporting dynamic_pointer_cast.
49 struct UserData {
50 virtual ~UserData() = default;
51 };
52
53 /// Get the optional user-defined material data.
54 virtual boost::shared_ptr<UserData> getUserDataPtr() const = 0;
55
56 /// Set data owned by this container; back-references should be weak.
57 virtual void setUserDataPtr(boost::shared_ptr<UserData> user_data_ptr) = 0;
58
59 /// Shared evaluation data, such as field values at quadrature points.
60 virtual std::pair<bool, MatrixPtr>
61 insertCommonData(const std::string &name,
62 const MatrixDouble &data = MatrixDouble(),
63 int shift = 0) = 0;
64
65 /// Independent constitutive variables, such as the deformation gradient.
66 virtual std::pair<bool, MatrixPtr>
67 insertActiveData(const std::string &name,
68 const MatrixDouble &data = MatrixDouble(),
69 int shift = 0) = 0;
70
71 /// Constitutive responses, such as stress, depending on the active variables.
72 virtual std::pair<bool, MatrixPtr>
73 insertDependentData(const std::string &name,
74 const MatrixDouble &data = MatrixDouble(),
75 int shift = 0) = 0;
76
77 /// Derivatives of the dependent responses with respect to active variables.
78 virtual std::pair<bool, MatrixPtr>
80 const MatrixDouble &data = MatrixDouble(),
81 int shift = 0) = 0;
82
83 /// Access shared evaluation storage by name.
84 virtual MatrixPtr getCommonDataPtr(const std::string &name) = 0;
85 /// Access independent-variable storage by name.
86 virtual MatrixPtr getActiveDataPtr(const std::string &name) = 0;
87 /// Access constitutive-response storage by name.
88 virtual MatrixPtr getDependentDataPtr(const std::string &name) = 0;
89 /// Access response-derivative storage by name.
90 virtual MatrixPtr getDependentDerivativesDataPtr(const std::string &name) = 0;
91 /** Writable view of one point's MOAB tag data, not a state copy.
92 * Start each sweep at gg == 0 to refresh cached storage; do not retain views
93 * across tag resizing or replacement.
94 */
95 virtual StateMatrixPtr getStateDataPtr(const std::string &name,
96 EntityHandle ent, int gg) = 0;
97 /// Bound state-tag descriptors, not copies of the stored values.
98 virtual StateTags getStateTags() const = 0;
99
100 /// Register a state name and its number of components per integration point.
102 const std::string &tag_name,
103 int num_components) = 0;
104 /// Find or create the registered MOAB state tags, preserving existing values.
106
107 /// Pack active matrices into a contiguous vector in registration order.
108 virtual MoFEMErrorCode
109 setActiveContinuousVector(std::vector<double> &active_variables) = 0;
110 /// Pack response matrices into a contiguous vector in registration order.
111 virtual MoFEMErrorCode
112 setDependentContinuousVector(std::vector<double> &dependent_variables) = 0;
113 /// Pack response derivatives into a contiguous vector in registration order.
115 std::vector<double> &dependent_variables_derivatives) = 0;
116
117 /// Unpack a contiguous vector into the registered active matrices.
118 virtual MoFEMErrorCode
119 getActiveContinuousVector(const std::vector<double> &active_variables) = 0;
120 /// Unpack a contiguous vector into the registered response matrices.
122 const std::vector<double> &dependent_variables) = 0;
123 /// Unpack a contiguous vector into the registered response derivatives.
125 const std::vector<double> &dependent_variables_derivatives) = 0;
126};
127
128/**@}*/
129
130/** \name Physical Equation Interface */
131/**@{*/
133 static MoFEMErrorCode
134 evaluateVariable(boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag,
135 EntityHandle entity, int gg);
136 static MoFEMErrorCode
137 evaluateDerivatives(boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag,
138 EntityHandle entity, int gg);
139
140private:
141 inline static std::vector<double> activeVariables;
142 inline static std::vector<double> dependentVariables;
143 inline static std::vector<double> dependentVariablesDerivatives;
144 inline static std::vector<double *> jacPtrVec;
145};
146
148
151 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag,
152 boost::shared_ptr<std::map<int, Range>> tag_vs_range_ptr = nullptr)
153 : tAg(tag), tagVsRangePtr(tag_vs_range_ptr),
154 matOpsDataPtr(mat_ops_data_ptr) {}
155 virtual ~PhysicalEquations() = default;
156
157 virtual MoFEMErrorCode
158 getOptions(MoFEM::Interface *m_field_ptr = nullptr) = 0;
159 virtual MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) = 0;
161 virtual MoFEMErrorCode
162 addBlockParameters(MoFEM::Interface &m_field, const std::string &block_name,
163 int block_id, const Range &block_entities,
164 const std::vector<double> &block_data) {
165 (void)m_field;
166 (void)block_name;
167 (void)block_id;
168 paramVecByRange.push_back({block_entities, block_data});
169 return 0;
170 }
171
173 createOp(boost::shared_ptr<PhysicalEquations> physical_ptr, bool eval_stress,
174 bool eval_tangent, bool update) = 0;
175
176 using HookFunction = std::function<MoFEMErrorCode(
177 boost::shared_ptr<MatOpsData>, int, EntityHandle, int)>;
178
182
183 virtual MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity,
184 int gg) {
185 return hookEvaluateVariable(this->matOpsDataPtr, tag, entity, gg);
186 }
187
188 virtual MoFEMErrorCode evaluateDerivatives(int tag, EntityHandle entity,
189 int gg) {
190 return hookEvaluateDerivatives(matOpsDataPtr, tag, entity, gg);
191 }
192
193 virtual MoFEMErrorCode updateState(int tag, EntityHandle entity, int gg) {
194 return hookUpdateState(this->matOpsDataPtr, tag, entity, gg);
195 }
196
197 int tAg;
198 boost::shared_ptr<std::map<int, Range>> tagVsRangePtr;
199 std::vector<std::pair<Range, std::vector<double>>> paramVecByRange;
200
201 boost::shared_ptr<MatOpsData> matOpsDataPtr;
202};
203
204/**
205 * @brief Constitutive response expressed by first Piola stress.
206 *
207 * Implementations provide the deformation-gradient input, first Piola stress,
208 * and its derivative. This interface does not imply the existence of a stored
209 * energy; conservative elastic responses use MatElastic.
210 */
213
214 inline static bool useDeformationGradient =
215 false; ///< Otherwise the displacement gradient is supplied and I is added.
216};
217
218struct MatElastic;
219
220/**@}*/
221
222/** \name Data Factory */
223/**@{*/
224boost::shared_ptr<MatOpsData> createMatOpsDataPtr();
225boost::shared_ptr<MatOpsData>
226createMatOpsDataPtr(boost::weak_ptr<MatOpsData>,
227 DataDictionary common_data_dictionary = {},
228 DataDictionary state_data_dictionary = {});
229/**@}*/
230
231/** \name Generic Operator Factory */
232/**@{*/
239
240struct MODEL {
241 MODEL() = delete;
242};
243
244template <class MODEL, int MODEL_TYPE>
245boost::shared_ptr<PhysicalEquations>
246createMatOpsPhysicalEquationsPtr(boost::shared_ptr<MatOpsData> mat_ops_data_ptr,
247 int tag);
248
249template <class MODEL, int MODEL_TYPE> struct OpMaterialFactory {
251};
252/**@}*/
253
254} // namespace MatOps
255
256#endif // __MAT_OPS_HPP__
Tag tag
std::string name
std::map< std::string, std::string > DataDictionary
Definition MatOps.hpp:22
@ MODEL_AXISYMMETRIC
Definition MatOps.hpp:237
@ MODEL_3D
Definition MatOps.hpp:234
@ MODEL_2D_PLANE_STRESS
Definition MatOps.hpp:236
@ MODEL_2D_PLANE_STRAIN
Definition MatOps.hpp:235
std::vector< StateTag > StateTags
Definition MatOps.hpp:21
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
boost::shared_ptr< MatOpsData > createMatOpsDataPtr()
Definition MatOps.cpp:709
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
UBlasMatrix< double > MatrixDouble
Definition Types.hpp:77
static MoFEMErrorCode evaluateVariable(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag, EntityHandle entity, int gg)
Definition MatOps.cpp:721
static std::vector< double > dependentVariablesDerivatives
Definition MatOps.hpp:143
static std::vector< double > dependentVariables
Definition MatOps.hpp:142
static MoFEMErrorCode evaluateDerivatives(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag, EntityHandle entity, int gg)
Definition MatOps.cpp:741
static std::vector< double > activeVariables
Definition MatOps.hpp:141
static std::vector< double * > jacPtrVec
Definition MatOps.hpp:144
MODEL()=delete
Conservative elastic response with a stored-energy density.
Base for user-defined material data, supporting dynamic_pointer_cast.
Definition MatOps.hpp:49
virtual ~UserData()=default
virtual boost::shared_ptr< UserData > getUserDataPtr() const =0
Get the optional user-defined material data.
virtual MoFEMErrorCode setActiveContinuousVector(std::vector< double > &active_variables)=0
Pack active matrices into a contiguous vector in registration order.
virtual MoFEMErrorCode getDependentDerivativesContinuousVector(const std::vector< double > &dependent_variables_derivatives)=0
Unpack a contiguous vector into the registered response derivatives.
virtual MoFEMErrorCode setDependentDerivativesContinuousVector(std::vector< double > &dependent_variables_derivatives)=0
Pack response derivatives into a contiguous vector in registration order.
virtual MatrixPtr getActiveDataPtr(const std::string &name)=0
Access independent-variable storage by name.
virtual std::pair< bool, MatrixPtr > insertDependentData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
Constitutive responses, such as stress, depending on the active variables.
virtual MoFEMErrorCode setupStateData()=0
Find or create the registered MOAB state tags, preserving existing values.
virtual std::pair< bool, MatrixPtr > insertActiveData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
Independent constitutive variables, such as the deformation gradient.
boost::shared_ptr< MatrixAdaptor > StateMatrixPtr
Definition MatOps.hpp:46
virtual MoFEMErrorCode bindStateTag(MoFEM::Interface &m_field, const std::string &tag_name, int num_components)=0
Register a state name and its number of components per integration point.
virtual ~MatOpsData()=default
virtual MoFEMErrorCode getActiveContinuousVector(const std::vector< double > &active_variables)=0
Unpack a contiguous vector into the registered active matrices.
virtual std::pair< bool, MatrixPtr > insertCommonData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
Shared evaluation data, such as field values at quadrature points.
boost::shared_ptr< MatrixDouble > MatrixPtr
Definition MatOps.hpp:45
virtual MatrixPtr getCommonDataPtr(const std::string &name)=0
Access shared evaluation storage by name.
virtual StateTags getStateTags() const =0
Bound state-tag descriptors, not copies of the stored values.
virtual StateMatrixPtr getStateDataPtr(const std::string &name, EntityHandle ent, int gg)=0
virtual MatrixPtr getDependentDataPtr(const std::string &name)=0
Access constitutive-response storage by name.
virtual MoFEMErrorCode setDependentContinuousVector(std::vector< double > &dependent_variables)=0
Pack response matrices into a contiguous vector in registration order.
virtual MatrixPtr getDependentDerivativesDataPtr(const std::string &name)=0
Access response-derivative storage by name.
virtual std::pair< bool, MatrixPtr > insertDependentDerivativesData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
Derivatives of the dependent responses with respect to active variables.
virtual MoFEMErrorCode getDependentContinuousVector(const std::vector< double > &dependent_variables)=0
Unpack a contiguous vector into the registered response matrices.
virtual void setUserDataPtr(boost::shared_ptr< UserData > user_data_ptr)=0
Set data owned by this container; back-references should be weak.
static int setTagName(std::string name, int tag=-1)
Definition MatOps.cpp:29
static std::string getTagName(int tag)
Definition MatOps.cpp:90
static int atTagName(std::string name)
Definition MatOps.cpp:25
static int getTagByName(std::string name)
Definition MatOps.cpp:80
static std::map< std::string, int > tagNameVsTag
Definition MatOps.hpp:32
Constitutive response expressed by first Piola stress.
Definition MatOps.hpp:211
static bool useDeformationGradient
Otherwise the displacement gradient is supplied and I is added.
Definition MatOps.hpp:214
PhysicalEquations(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag, boost::shared_ptr< std::map< int, Range > > tag_vs_range_ptr=nullptr)
Definition MatOps.hpp:150
virtual MoFEMErrorCode recordTape()=0
virtual ~PhysicalEquations()=default
virtual MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg)=0
virtual MoFEMErrorCode addBlockParameters(MoFEM::Interface &m_field, const std::string &block_name, int block_id, const Range &block_entities, const std::vector< double > &block_data)
Definition MatOps.hpp:162
std::vector< std::pair< Range, std::vector< double > > > paramVecByRange
Definition MatOps.hpp:199
boost::shared_ptr< std::map< int, Range > > tagVsRangePtr
Definition MatOps.hpp:198
boost::shared_ptr< MatOpsData > matOpsDataPtr
Definition MatOps.hpp:201
virtual MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity, int gg)
Definition MatOps.hpp:183
virtual MoFEMErrorCode evaluateDerivatives(int tag, EntityHandle entity, int gg)
Definition MatOps.hpp:188
virtual ForcesAndSourcesCore::UserDataOperator * createOp(boost::shared_ptr< PhysicalEquations > physical_ptr, bool eval_stress, bool eval_tangent, bool update)=0
HookFunction hookUpdateState
Definition MatOps.hpp:181
HookFunction hookEvaluateVariable
Definition MatOps.hpp:179
HookFunction hookEvaluateDerivatives
Definition MatOps.hpp:180
virtual MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr)=0
std::function< MoFEMErrorCode(boost::shared_ptr< MatOpsData >, int, EntityHandle, int)> HookFunction
Definition MatOps.hpp:177
virtual MoFEMErrorCode updateState(int tag, EntityHandle entity, int gg)
Definition MatOps.hpp:193
std::string name
Definition MatOps.hpp:16
Deprecated interface functions.
Structure for user loop methods on finite elements.