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/**@{*/
37struct MatOpsData : public boost::enable_shared_from_this<MatOpsData> {
38 virtual ~MatOpsData() = default;
39
40 using MatrixPtr = boost::shared_ptr<MatrixDouble>;
41 using StateMatrixPtr = boost::shared_ptr<MatrixAdaptor>;
42
43 /// Base for user-defined material data, supporting dynamic_pointer_cast.
44 struct UserData {
45 virtual ~UserData() = default;
46 };
47
48 /// Get the optional user-defined material data.
49 virtual boost::shared_ptr<UserData> getUserDataPtr() const = 0;
50
51 /// Set data owned by this container; back-references should be weak.
52 virtual void setUserDataPtr(boost::shared_ptr<UserData> user_data_ptr) = 0;
53
54 virtual std::pair<bool, MatrixPtr>
55 insertCommonData(const std::string &name,
56 const MatrixDouble &data = MatrixDouble(),
57 int shift = 0) = 0;
58
59 virtual std::pair<bool, MatrixPtr>
60 insertActiveData(const std::string &name,
61 const MatrixDouble &data = MatrixDouble(),
62 int shift = 0) = 0;
63
64 virtual std::pair<bool, MatrixPtr>
65 insertDependentData(const std::string &name,
66 const MatrixDouble &data = MatrixDouble(),
67 int shift = 0) = 0;
68
69 virtual std::pair<bool, MatrixPtr>
71 const MatrixDouble &data = MatrixDouble(),
72 int shift = 0) = 0;
73
74 virtual MatrixPtr getCommonDataPtr(const std::string &name) = 0;
75 virtual MatrixPtr getActiveDataPtr(const std::string &name) = 0;
76 virtual MatrixPtr getDependentDataPtr(const std::string &name) = 0;
77 virtual MatrixPtr getDependentDerivativesDataPtr(const std::string &name) = 0;
78 /// Start each integration-point sweep at gg == 0 to refresh cached tag storage.
79 virtual StateMatrixPtr getStateDataPtr(const std::string &name,
80 EntityHandle ent, int gg) = 0;
81 virtual StateTags getStateTags() const = 0;
82
84 const std::string &tag_name,
85 int num_components) = 0;
87
88 virtual MoFEMErrorCode
89 setActiveContinuousVector(std::vector<double> &active_variables) = 0;
90 virtual MoFEMErrorCode
91 setDependentContinuousVector(std::vector<double> &dependent_variables) = 0;
93 std::vector<double> &dependent_variables_derivatives) = 0;
94
95 virtual MoFEMErrorCode
96 getActiveContinuousVector(const std::vector<double> &active_variables) = 0;
98 const std::vector<double> &dependent_variables) = 0;
100 const std::vector<double> &dependent_variables_derivatives) = 0;
101};
102
103/**@}*/
104
105/** \name Physical Equation Interface */
106/**@{*/
108 static MoFEMErrorCode
109 evaluateVariable(boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag,
110 EntityHandle entity, int gg);
111 static MoFEMErrorCode
112 evaluateDerivatives(boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag,
113 EntityHandle entity, int gg);
114
115private:
116 inline static std::vector<double> activeVariables;
117 inline static std::vector<double> dependentVariables;
118 inline static std::vector<double> dependentVariablesDerivatives;
119 inline static std::vector<double *> jacPtrVec;
120};
121
123
126 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag,
127 boost::shared_ptr<std::map<int, Range>> tag_vs_range_ptr = nullptr)
128 : tAg(tag), tagVsRangePtr(tag_vs_range_ptr),
129 matOpsDataPtr(mat_ops_data_ptr) {}
130 virtual ~PhysicalEquations() = default;
131
132 virtual MoFEMErrorCode
133 getOptions(MoFEM::Interface *m_field_ptr = nullptr) = 0;
134 virtual MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) = 0;
136 virtual MoFEMErrorCode
137 addBlockParameters(MoFEM::Interface &m_field, const std::string &block_name,
138 int block_id, const Range &block_entities,
139 const std::vector<double> &block_data) {
140 (void)m_field;
141 (void)block_name;
142 (void)block_id;
143 paramVecByRange.push_back({block_entities, block_data});
144 return 0;
145 }
146
148 createOp(boost::shared_ptr<PhysicalEquations> physical_ptr, bool eval_stress,
149 bool eval_tangent, bool update) = 0;
150
151 using HookFunction = std::function<MoFEMErrorCode(
152 boost::shared_ptr<MatOpsData>, int, EntityHandle, int)>;
153
157
158 virtual MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity,
159 int gg) {
160 return hookEvaluateVariable(this->matOpsDataPtr, tag, entity, gg);
161 }
162
163 virtual MoFEMErrorCode evaluateDerivatives(int tag, EntityHandle entity,
164 int gg) {
165 return hookEvaluateDerivatives(matOpsDataPtr, tag, entity, gg);
166 }
167
168 virtual MoFEMErrorCode updateState(int tag, EntityHandle entity, int gg) {
169 return hookUpdateState(this->matOpsDataPtr, tag, entity, gg);
170 }
171
172 int tAg;
173 boost::shared_ptr<std::map<int, Range>> tagVsRangePtr;
174 std::vector<std::pair<Range, std::vector<double>>> paramVecByRange;
175
176 boost::shared_ptr<MatOpsData> matOpsDataPtr;
177};
178
179/**
180 * @brief Constitutive response expressed by first Piola stress.
181 *
182 * Implementations provide the deformation-gradient input, first Piola stress,
183 * and its derivative. This interface does not imply the existence of a stored
184 * energy; conservative elastic responses use MatElastic.
185 */
188
189 inline static bool useDeformationGradient =
190 false; ///< Otherwise the displacement gradient is supplied and I is added.
191};
192
193struct MatElastic;
194
195/**@}*/
196
197/** \name Data Factory */
198/**@{*/
199boost::shared_ptr<MatOpsData> createMatOpsDataPtr();
200boost::shared_ptr<MatOpsData>
201createMatOpsDataPtr(boost::weak_ptr<MatOpsData>,
202 DataDictionary common_data_dictionary = {},
203 DataDictionary state_data_dictionary = {});
204/**@}*/
205
206/** \name Generic Operator Factory */
207/**@{*/
214
215struct MODEL {
216 MODEL() = delete;
217};
218
219template <class MODEL, int MODEL_TYPE>
220boost::shared_ptr<PhysicalEquations>
221createMatOpsPhysicalEquationsPtr(boost::shared_ptr<MatOpsData> mat_ops_data_ptr,
222 int tag);
223
224template <class MODEL, int MODEL_TYPE> struct OpMaterialFactory {
226};
227/**@}*/
228
229} // namespace MatOps
230
231#endif // __MAT_OPS_HPP__
std::string name
std::map< std::string, std::string > DataDictionary
Definition MatOps.hpp:22
@ MODEL_AXISYMMETRIC
Definition MatOps.hpp:212
@ MODEL_3D
Definition MatOps.hpp:209
@ MODEL_2D_PLANE_STRESS
Definition MatOps.hpp:211
@ MODEL_2D_PLANE_STRAIN
Definition MatOps.hpp:210
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:118
static std::vector< double > dependentVariables
Definition MatOps.hpp:117
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:116
static std::vector< double * > jacPtrVec
Definition MatOps.hpp:119
MODEL()=delete
Conservative elastic response with a stored-energy density.
Base for user-defined material data, supporting dynamic_pointer_cast.
Definition MatOps.hpp:44
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
virtual MoFEMErrorCode getDependentDerivativesContinuousVector(const std::vector< double > &dependent_variables_derivatives)=0
virtual MoFEMErrorCode setDependentDerivativesContinuousVector(std::vector< double > &dependent_variables_derivatives)=0
virtual MatrixPtr getActiveDataPtr(const std::string &name)=0
virtual std::pair< bool, MatrixPtr > insertDependentData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
virtual MoFEMErrorCode setupStateData()=0
virtual std::pair< bool, MatrixPtr > insertActiveData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
boost::shared_ptr< MatrixAdaptor > StateMatrixPtr
Definition MatOps.hpp:41
virtual MoFEMErrorCode bindStateTag(MoFEM::Interface &m_field, const std::string &tag_name, int num_components)=0
virtual ~MatOpsData()=default
virtual MoFEMErrorCode getActiveContinuousVector(const std::vector< double > &active_variables)=0
virtual std::pair< bool, MatrixPtr > insertCommonData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
boost::shared_ptr< MatrixDouble > MatrixPtr
Definition MatOps.hpp:40
virtual MatrixPtr getCommonDataPtr(const std::string &name)=0
virtual StateTags getStateTags() const =0
virtual StateMatrixPtr getStateDataPtr(const std::string &name, EntityHandle ent, int gg)=0
Start each integration-point sweep at gg == 0 to refresh cached tag storage.
virtual MatrixPtr getDependentDataPtr(const std::string &name)=0
virtual MoFEMErrorCode setDependentContinuousVector(std::vector< double > &dependent_variables)=0
virtual MatrixPtr getDependentDerivativesDataPtr(const std::string &name)=0
virtual std::pair< bool, MatrixPtr > insertDependentDerivativesData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
virtual MoFEMErrorCode getDependentContinuousVector(const std::vector< double > &dependent_variables)=0
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:186
static bool useDeformationGradient
Otherwise the displacement gradient is supplied and I is added.
Definition MatOps.hpp:189
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:125
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:137
std::vector< std::pair< Range, std::vector< double > > > paramVecByRange
Definition MatOps.hpp:174
boost::shared_ptr< std::map< int, Range > > tagVsRangePtr
Definition MatOps.hpp:173
boost::shared_ptr< MatOpsData > matOpsDataPtr
Definition MatOps.hpp:176
virtual MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity, int gg)
Definition MatOps.hpp:158
virtual MoFEMErrorCode evaluateDerivatives(int tag, EntityHandle entity, int gg)
Definition MatOps.hpp:163
virtual ForcesAndSourcesCore::UserDataOperator * createOp(boost::shared_ptr< PhysicalEquations > physical_ptr, bool eval_stress, bool eval_tangent, bool update)=0
HookFunction hookUpdateState
Definition MatOps.hpp:156
HookFunction hookEvaluateVariable
Definition MatOps.hpp:154
HookFunction hookEvaluateDerivatives
Definition MatOps.hpp:155
virtual MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr)=0
std::function< MoFEMErrorCode(boost::shared_ptr< MatOpsData >, int, EntityHandle, int)> HookFunction
Definition MatOps.hpp:152
virtual MoFEMErrorCode updateState(int tag, EntityHandle entity, int gg)
Definition MatOps.hpp:168
std::string name
Definition MatOps.hpp:16
Deprecated interface functions.
Structure for user loop methods on finite elements.