v0.16.3
Loading...
Searching...
No Matches
MatMetaElastic.cpp
Go to the documentation of this file.
1/**
2 * @file MatMetaElastic.cpp
3 * @brief
4 * @version 0.1
5 * @date 2026-03-28
6 *
7 * @copyright Copyright (c) 2026
8 *
9 */
10
11namespace MatOps {
12
13template <int DIM,
14 int MODEL_TYPE =
16struct MatMetaElastic : public MatElasticImpl<DIM> {
17 using MatElasticImpl<DIM>::MatElasticImpl;
18
20
21 MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr = nullptr) override {
23
24 // Activate UMAT only for an explicit library or material block.
25 char umat_library[PETSC_MAX_PATH_LEN] = "";
26 CHKERR PetscOptionsGetString(PETSC_NULLPTR, PETSC_NULLPTR,
27 "-umat_library", umat_library,
28 sizeof(umat_library), PETSC_NULLPTR);
29
30 if (umat_library[0] ||
31 (m_field_ptr &&
32 !m_field_ptr->getInterface<MeshsetsManager>()
33 ->getCubitMeshsetPtr(std::regex("MAT_UMAT(.*)"))
34 .empty())) {
35 metaElasticAtPts.insert(
37 createMatOpsPhysicalEquationsPtr<UMAT, modelType>(
38 this->matOpsDataPtr,
40 }
41
42 for (auto &m : metaElasticAtPts) {
43 CHKERR m.second->getOptions(m_field_ptr);
44 }
45 A::tagVsRangePtr = boost::make_shared<std::map<int, Range>>();
46 for (const auto &m : metaElasticAtPts) {
47 A::tagVsRangePtr->insert(
48 {m.first, Range()}); // Initialize with empty range
49 for (auto &rp : m.second->paramVecByRange) {
50 A::tagVsRangePtr->at(m.first).merge(
51 rp.first); // Merge ranges for the same tag
52 }
53 }
55 }
56
57 MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override {
59 const auto ent = fe_ptr->getFEEntityHandle();
60
61 bool has_ranges = false;
62 if (A::tagVsRangePtr) {
63 for (const auto &tag_range : *A::tagVsRangePtr) {
64 has_ranges = has_ranges || !tag_range.second.empty();
65 }
66 }
67
68 if (!has_ranges) {
69 for (auto &m : metaElasticAtPts) {
70 CHKERR m.second->setParams(fe_ptr, gg);
71 }
73 }
74
75 for (auto &m : metaElasticAtPts) {
76 if (A::tagVsRangePtr->at(m.first).find(ent) !=
77 A::tagVsRangePtr->at(m.first).end()) {
78 CHKERR m.second->setParams(fe_ptr, gg);
80 }
81 }
82
83 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
84 "Meta elastic material parameters not found for entity %lu",
85 static_cast<unsigned long>(ent));
87 }
88
91 for (auto &m : metaElasticAtPts) {
92 CHKERR m.second->recordTape();
93 }
95 }
96
97 MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity, int gg) {
98 return metaElasticAtPts.at(tag)->evaluateVariable(tag, entity, gg);
99 }
100
101 MoFEMErrorCode evaluateDerivatives(int tag, EntityHandle entity, int gg) {
102 return metaElasticAtPts.at(tag)->evaluateDerivatives(tag, entity, gg);
103 }
104
105 MoFEMErrorCode updateState(int tag, EntityHandle entity, int gg) {
106 return metaElasticAtPts.at(tag)->updateState(tag, entity, gg);
107 }
108
109 std::map<int, boost::shared_ptr<PhysicalEquations>> &getMetaElasticMap() {
110 return metaElasticAtPts;
111 }
112
113protected:
114 static inline constexpr int modelType = MODEL_TYPE;
115
116 std::map<int, boost::shared_ptr<PhysicalEquations>> metaElasticAtPts = {
117
118 {
119
120 // First tag is always MetaElastic tag
122 createMatOpsPhysicalEquationsPtr<ELASTICITY::NEOHOOKEAN, modelType>(
123 this->matOpsDataPtr,
125
126 },
127
128 {
129
130 MatOps::MatOpsTagsRegistry::setTagName("MooneyRivlinWriggersEq63"),
132 modelType>(
133 this->matOpsDataPtr, MatOps::MatOpsTagsRegistry::setTagName(
134 "MooneyRivlinWriggersEq63"))
135
136 },
137
138 {
139
140 MatOps::MatOpsTagsRegistry::setTagName("StVenantKirchhoff"),
142 modelType>(
143 this->matOpsDataPtr,
144 MatOps::MatOpsTagsRegistry::setTagName("StVenantKirchhoff"))
145
146 },
147
148 };
149};
150
151std::map<int, boost::shared_ptr<PhysicalEquations>> &
152getMetaElasticMap(boost::shared_ptr<PhysicalEquations> meta_ptr) {
153 auto meta_elastic_3d_ptr =
154 boost::dynamic_pointer_cast<MatMetaElastic<3>>(meta_ptr);
155 if (meta_elastic_3d_ptr) {
156 return meta_elastic_3d_ptr->getMetaElasticMap();
157 }
158 auto meta_elastic_2d_ptr =
159 boost::dynamic_pointer_cast<MatMetaElastic<2>>(meta_ptr);
160 if (meta_elastic_2d_ptr) {
161 return meta_elastic_2d_ptr->getMetaElasticMap();
162 }
163 auto meta_elastic_axisymmetric_ptr = boost::dynamic_pointer_cast<
165 if (meta_elastic_axisymmetric_ptr) {
166 return meta_elastic_axisymmetric_ptr->getMetaElasticMap();
167 }
170 "Provided PhysicalEquations pointer is not of type MatMetaElastic");
171 static std::map<int, boost::shared_ptr<PhysicalEquations>> empty_map;
172 return empty_map;
173}
174
175template <>
176boost::shared_ptr<PhysicalEquations>
178 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
179 return boost::make_shared<MatMetaElastic<3>>(mat_ops_data_ptr, tag);
180}
181
182template <>
183boost::shared_ptr<PhysicalEquations>
185 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
186 return boost::make_shared<MatMetaElastic<2>>(mat_ops_data_ptr, tag);
187}
188
189template <>
190boost::shared_ptr<PhysicalEquations>
192 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
193 return boost::make_shared<MatMetaElastic<3, MODEL_AXISYMMETRIC>>(
194 mat_ops_data_ptr, tag);
195}
196} // namespace MatOps
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
MoFEMErrorCode getCubitMeshsetPtr(const int ms_id, const CubitBCType cubit_bc_type, const CubitMeshSets **cubit_meshset_ptr) const
get cubit meshset
std::map< int, boost::shared_ptr< PhysicalEquations > > & getMetaElasticMap(boost::shared_ptr< PhysicalEquations > meta_ptr)
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< ELASTICITY::META, MODEL_AXISYMMETRIC >(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
@ MODEL_3D
Definition MatOps.hpp:193
@ MODEL_2D_PLANE_STRAIN
Definition MatOps.hpp:194
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< ELASTICITY::META, MODEL_2D_PLANE_STRAIN >(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< ELASTICITY::META, MODEL_3D >(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
FTensor::Index< 'm', 3 > m
MoFEMErrorCode recordTape() override
MoFEMErrorCode evaluateDerivatives(int tag, EntityHandle entity, int gg)
MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override
MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr) override
MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity, int gg)
MoFEMErrorCode updateState(int tag, EntityHandle entity, int gg)
std::map< int, boost::shared_ptr< PhysicalEquations > > & getMetaElasticMap()
static int setTagName(std::string name, int tag=-1)
Definition MatOps.cpp:29
Deprecated interface functions.
Structure for user loop methods on finite elements.
EntityHandle getFEEntityHandle() const
Get the entity handle of the current finite element.
Interface for managing meshsets containing materials and boundary conditions.