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>
70 insertDependentDerivativesData(const std::string &name,
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
106/** \name Physical Equation Interface */
107/**@{*/
109 static MoFEMErrorCode
110 evaluateVariable(boost::shared_ptr<MatOpsData> mat_ops_data_ptr,
111 int tag, EntityHandle entity, int gg);
112 static MoFEMErrorCode
113 evaluateDerivatives(boost::shared_ptr<MatOpsData> mat_ops_data_ptr,
114 int tag, EntityHandle entity, int gg);
115
116private:
117 inline static std::vector<double> activeVariables;
118 inline static std::vector<double> dependentVariables;
119 inline static std::vector<double> dependentVariablesDerivatives;
120 inline static std::vector<double *> jacPtrVec;
121};
122
124
127 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag,
128 boost::shared_ptr<std::map<int, Range>> tag_vs_range_ptr = nullptr)
129 : matOpsDataPtr(mat_ops_data_ptr), tAg(tag),
130 tagVsRangePtr(tag_vs_range_ptr) {}
131 virtual ~PhysicalEquations() = default;
132
133 virtual MoFEMErrorCode
134 getOptions(MoFEM::Interface *m_field_ptr = nullptr) = 0;
135 virtual MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) = 0;
137 virtual MoFEMErrorCode
138 addBlockParameters(MoFEM::Interface &m_field, const std::string &block_name,
139 int block_id, const Range &block_entities,
140 const std::vector<double> &block_data) {
141 (void)m_field;
142 (void)block_name;
143 (void)block_id;
144 paramVecByRange.push_back({block_entities, block_data});
145 return 0;
146 }
147
149 createOp(boost::shared_ptr<PhysicalEquations> physical_ptr, bool eval_stress,
150 bool eval_tangent, bool update) = 0;
151
152 using HookFunction = std::function<MoFEMErrorCode(
153 boost::shared_ptr<MatOpsData>, int, EntityHandle, int)>;
154
158
159 virtual MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity, 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
181/** \name Data Factory */
182/**@{*/
183boost::shared_ptr<MatOpsData> createMatOpsDataPtr();
184boost::shared_ptr<MatOpsData> createMatOpsDataPtr(
185 boost::weak_ptr<MatOpsData>,
186 DataDictionary common_data_dictionary = {},
187 DataDictionary state_data_dictionary = {});
188/**@}*/
189
190/** \name Generic Operator Factory */
191/**@{*/
198
199struct MODEL {
200 MODEL() = delete;
201};
202
203template <class MODEL, int MODEL_TYPE>
204boost::shared_ptr<PhysicalEquations>
205createMatOpsPhysicalEquationsPtr(boost::shared_ptr<MatOpsData> mat_ops_data_ptr,
206 int tag);
207
208template <class MODEL, int MODEL_TYPE> struct OpMaterialFactory {
210};
211/**@}*/
212
213} // namespace MatOps
214
215
216#endif // __MAT_OPS_HPP__
std::map< std::string, std::string > DataDictionary
Definition MatOps.hpp:22
@ MODEL_AXISYMMETRIC
Definition MatOps.hpp:196
@ MODEL_3D
Definition MatOps.hpp:193
@ MODEL_2D_PLANE_STRESS
Definition MatOps.hpp:195
@ MODEL_2D_PLANE_STRAIN
Definition MatOps.hpp:194
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:119
static std::vector< double > dependentVariables
Definition MatOps.hpp:118
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:117
static std::vector< double * > jacPtrVec
Definition MatOps.hpp:120
MODEL()=delete
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
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:126
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:138
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:159
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:157
HookFunction hookEvaluateVariable
Definition MatOps.hpp:155
HookFunction hookEvaluateDerivatives
Definition MatOps.hpp:156
virtual MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr)=0
std::function< MoFEMErrorCode(boost::shared_ptr< MatOpsData >, int, EntityHandle, int)> HookFunction
Definition MatOps.hpp:153
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.