v0.16.0
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> struct MatMetaElastic : public MatElasticImpl<DIM> {
14 using MatElasticImpl<DIM>::MatElasticImpl;
15
17
18 MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr = nullptr) override {
20
21 char umat_library[PETSC_MAX_PATH_LEN] = "./umat.so";
22 CHKERR PetscOptionsGetString(PETSC_NULLPTR, PETSC_NULLPTR,
23 "-umat_library", umat_library,
24 sizeof(umat_library), PETSC_NULLPTR);
25
26 if (std::filesystem::exists(std::filesystem::path(umat_library))) {
27 metaElasticAtPts.insert(
29 createMatOpsPhysicalEquationsPtr<UMAT, modelType>(
30 this->matOpsDataPtr,
32 }
33
34 for (auto &m : metaElasticAtPts) {
35 CHKERR m.second->getOptions(m_field_ptr);
36 }
37 A::tagVsRangePtr = boost::make_shared<std::map<int, Range>>();
38 for (const auto &m : metaElasticAtPts) {
39 A::tagVsRangePtr->insert(
40 {m.first, Range()}); // Initialize with empty range
41 for (auto &rp : m.second->paramVecByRange) {
42 A::tagVsRangePtr->at(m.first).merge(
43 rp.first); // Merge ranges for the same tag
44 }
45 }
47 }
48
49 MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override {
51 const auto ent = fe_ptr->getFEEntityHandle();
52
53 bool has_ranges = false;
54 if (A::tagVsRangePtr) {
55 for (const auto &tag_range : *A::tagVsRangePtr) {
56 has_ranges = has_ranges || !tag_range.second.empty();
57 }
58 }
59
60 if (!has_ranges) {
61 for (auto &m : metaElasticAtPts) {
62 CHKERR m.second->setParams(fe_ptr, gg);
63 }
65 }
66
67 for (auto &m : metaElasticAtPts) {
68 if (A::tagVsRangePtr->at(m.first).find(ent) !=
69 A::tagVsRangePtr->at(m.first).end()) {
70 CHKERR m.second->setParams(fe_ptr, gg);
72 }
73 }
74
75 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
76 "Meta elastic material parameters not found for entity %lu",
77 static_cast<unsigned long>(ent));
79 }
80
83 for (auto &m : metaElasticAtPts) {
84 CHKERR m.second->recordTape();
85 }
87 }
88
89 MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity,
90 int gg) override {
91 return metaElasticAtPts.at(tag)->evaluateVariable(tag, entity, gg);
92 }
93
94 MoFEMErrorCode evaluateDerivatives(int tag, EntityHandle entity,
95 int gg) override {
96 return metaElasticAtPts.at(tag)->evaluateDerivatives(tag, entity, gg);
97 }
98
99 MoFEMErrorCode updateState(int tag, EntityHandle entity, int gg) override {
100 return metaElasticAtPts.at(tag)->updateState(tag, entity, gg);
101 }
102
103 std::map<int, boost::shared_ptr<PhysicalEquations>> &getMetaElasticMap() {
104 return metaElasticAtPts;
105 }
106
107protected:
108 static inline constexpr int modelType =
110
111 std::map<int, boost::shared_ptr<PhysicalEquations>> metaElasticAtPts = {
112
113 {
114
115 // First tag is always MetaElastic tag
117 createMatOpsPhysicalEquationsPtr<ELASTICITY::NEOHOOKEAN, modelType>(
118 this->matOpsDataPtr,
120
121 },
122
123 {
124
125 MatOps::MatOpsTagsRegistry::setTagName("MooneyRivlinWriggersEq63"),
127 modelType>(
129 "MooneyRivlinWriggersEq63"))
130
131 },
132
133 {
134
135 MatOps::MatOpsTagsRegistry::setTagName("StVenantKirchhoff"),
137 modelType>(
138 this->matOpsDataPtr,
139 MatOps::MatOpsTagsRegistry::setTagName("StVenantKirchhoff"))
140
141 },
142
143 };
144};
145
146std::map<int, boost::shared_ptr<PhysicalEquations>> &
147getMetaElasticMap(boost::shared_ptr<PhysicalEquations> meta_ptr) {
148 auto meta_elastic_3d_ptr =
149 boost::dynamic_pointer_cast<MatMetaElastic<3>>(meta_ptr);
150 if (meta_elastic_3d_ptr) {
151 return meta_elastic_3d_ptr->getMetaElasticMap();
152 }
153 auto meta_elastic_2d_ptr =
154 boost::dynamic_pointer_cast<MatMetaElastic<2>>(meta_ptr);
155 if (meta_elastic_2d_ptr) {
156 return meta_elastic_2d_ptr->getMetaElasticMap();
157 }
160 "Provided PhysicalEquations pointer is not of type MatMetaElastic");
161 static std::map<int, boost::shared_ptr<PhysicalEquations>> empty_map;
162 return empty_map;
163}
164
165template <>
166boost::shared_ptr<PhysicalEquations>
168 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
169 return boost::make_shared<MatMetaElastic<3>>(mat_ops_data_ptr, tag);
170}
171
172template <>
173boost::shared_ptr<PhysicalEquations>
175 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
176 return boost::make_shared<MatMetaElastic<2>>(mat_ops_data_ptr, tag);
177}
178} // 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.
std::map< int, boost::shared_ptr< PhysicalEquations > > & getMetaElasticMap(boost::shared_ptr< PhysicalEquations > meta_ptr)
@ MODEL_3D
Definition MatOps.hpp:181
@ MODEL_2D_PLANE_STRAIN
Definition MatOps.hpp:182
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 updateState(int tag, EntityHandle entity, int gg) override
MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr) override
MoFEMErrorCode recordTape() override
std::map< int, boost::shared_ptr< PhysicalEquations > > & getMetaElasticMap()
std::map< int, boost::shared_ptr< PhysicalEquations > > metaElasticAtPts
static constexpr int modelType
MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override
MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity, int gg) override
MoFEMErrorCode evaluateDerivatives(int tag, EntityHandle entity, int gg) override
static int setTagName(std::string name, int tag=-1)
Definition MatOps.cpp:30
boost::shared_ptr< std::map< int, Range > > tagVsRangePtr
Definition MatOps.hpp:161
boost::shared_ptr< MatOpsData > matOpsDataPtr
Definition MatOps.hpp:164
Deprecated interface functions.
Structure for user loop methods on finite elements.
EntityHandle getFEEntityHandle() const
Get the entity handle of the current finite element.