v0.16.3
Loading...
Searching...
No Matches
MatMetaPiolaResponse.cpp
Go to the documentation of this file.
1/**
2 * @file MatMetaPiolaResponse.cpp
3 * @brief Dispatch first-Piola responses without implying stored energy
4 * @version 0.1
5 * @date 2026-03-28
6 *
7 * @copyright Copyright (c) 2026
8 *
9 */
10
11namespace MatOps {
12
13template <int DIM, int MODEL_TYPE = (DIM == 3) ? MatOps::MODEL_3D
17 using ResponsePtr = boost::shared_ptr<MatPiolaResponse>;
18
19 MatMetaPiolaResponse(boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag)
20 : A(mat_ops_data_ptr, tag) {
21
22 // Neohookean material is default
23 const int default_tag = MatOpsTagsRegistry::setTagName("MetaPiolaResponse");
24 metaPiolaResponses.emplace(
25 default_tag,
26 boost::static_pointer_cast<MatPiolaResponse>(
27 createMatOpsPhysicalEquationsPtr<ELASTICITY::NEOHOOKEAN, modelType>(
28 this->matOpsDataPtr, default_tag)));
29
30 // Mooney Rivlinw has policonvex coffactor term which only make sense in 3d
31 if constexpr (DIM == 3) {
32 const int mooney_tag =
33 MatOpsTagsRegistry::setTagName("MooneyRivlinWriggersEq63");
34 metaPiolaResponses.emplace(
35 mooney_tag, boost::static_pointer_cast<MatPiolaResponse>(
38 this->matOpsDataPtr, mooney_tag)));
39 }
40
41 // Kirchoff Stvent model
42 const int stvenant_tag =
43 MatOpsTagsRegistry::setTagName("StVenantKirchhoff");
44 metaPiolaResponses.emplace(
45 stvenant_tag,
46 boost::static_pointer_cast<MatPiolaResponse>(
48 modelType>(this->matOpsDataPtr,
49 stvenant_tag)));
50
51 }
52
53 MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr = nullptr) override {
55
56 // An unused UMAT still binds state tags and blocks elastic reference transfer.
57 char umat_library[PETSC_MAX_PATH_LEN] = "";
58 CHKERR PetscOptionsGetString(PETSC_NULLPTR, PETSC_NULLPTR, "-umat_library",
59 umat_library, sizeof(umat_library),
60 PETSC_NULLPTR);
61 if (umat_library[0] ||
62 (m_field_ptr &&
63 !m_field_ptr->getInterface<MeshsetsManager>()
64 ->getCubitMeshsetPtr(std::regex("MAT_UMAT(.*)"))
65 .empty())) {
66 const int umat_tag = MatOpsTagsRegistry::setTagName("Umat");
67 metaPiolaResponses.insert(
68 {umat_tag, boost::static_pointer_cast<MatPiolaResponse>(
69 createMatOpsPhysicalEquationsPtr<UMAT, modelType>(
70 this->matOpsDataPtr, umat_tag))});
71 }
72
73 for (auto &m : metaPiolaResponses) {
74 CHKERR m.second->getOptions(m_field_ptr);
75 }
76
77 // tagVsRangePtr is used to store the ranges of entities for each tag. It is
78 // initialized here based on the ranges provided by each response in
79 // metaPiolaResponses. This allows the MatMetaPiolaResponse to manage
80 // multiple responses and their associated entity ranges effectively.
81 A::tagVsRangePtr = boost::make_shared<std::map<int, Range>>();
82 for (const auto &m : metaPiolaResponses) {
83 A::tagVsRangePtr->insert(
84 {m.first, Range()}); // Initialize with empty range
85 for (auto &rp : m.second->paramVecByRange) {
86 A::tagVsRangePtr->at(m.first).merge(
87 rp.first); // Merge ranges for the same tag
88 }
89 }
91 }
92
93 MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override {
95 const auto ent = fe_ptr->getFEEntityHandle();
96
97 bool has_ranges = false;
98 if (A::tagVsRangePtr) {
99 for (const auto &tag_range : *A::tagVsRangePtr) {
100 has_ranges = has_ranges || !tag_range.second.empty();
101 }
102 }
103
104 if (!has_ranges) {
105 for (auto &m : metaPiolaResponses) {
106 CHKERR m.second->setParams(fe_ptr, gg);
107 }
109 }
110
111 for (auto &m : metaPiolaResponses) {
112 if (A::tagVsRangePtr->at(m.first).find(ent) !=
113 A::tagVsRangePtr->at(m.first).end()) {
114 CHKERR m.second->setParams(fe_ptr, gg);
116 }
117 }
118
119 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
120 "Meta Piola-response parameters not found for entity %lu",
121 static_cast<unsigned long>(ent));
123 }
124
127 for (auto &m : metaPiolaResponses) {
128 CHKERR m.second->recordTape();
129 }
131 }
132
133 MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity,
134 int gg) override {
135 return metaPiolaResponses.at(tag)->evaluateVariable(tag, entity, gg);
136 }
137
138 MoFEMErrorCode evaluateDerivatives(int tag, EntityHandle entity,
139 int gg) override {
140 return metaPiolaResponses.at(tag)->evaluateDerivatives(tag, entity, gg);
141 }
142
143 MoFEMErrorCode updateState(int tag, EntityHandle entity, int gg) override {
144 return metaPiolaResponses.at(tag)->updateState(tag, entity, gg);
145 }
146
147 std::map<int, ResponsePtr> &getMetaPiolaResponseMap() {
148 return metaPiolaResponses;
149 }
150
151protected:
152 static inline constexpr int modelType = MODEL_TYPE;
153
154 std::map<int, ResponsePtr> metaPiolaResponses;
155};
156
157std::map<int, boost::shared_ptr<MatPiolaResponse>> &
158getMetaPiolaResponseMap(boost::shared_ptr<MatPiolaResponse> meta_ptr) {
159 auto meta_response_3d_ptr =
160 boost::dynamic_pointer_cast<MatMetaPiolaResponse<3>>(meta_ptr);
161 if (meta_response_3d_ptr) {
162 return meta_response_3d_ptr->getMetaPiolaResponseMap();
163 }
164 auto meta_response_2d_ptr =
165 boost::dynamic_pointer_cast<MatMetaPiolaResponse<2>>(meta_ptr);
166 if (meta_response_2d_ptr) {
167 return meta_response_2d_ptr->getMetaPiolaResponseMap();
168 }
169 auto meta_response_axisymmetric_ptr =
170 boost::dynamic_pointer_cast<MatMetaPiolaResponse<3, MODEL_AXISYMMETRIC>>(
171 meta_ptr);
172 if (meta_response_axisymmetric_ptr) {
173 return meta_response_axisymmetric_ptr->getMetaPiolaResponseMap();
174 }
176 "Provided response pointer is not a MatMetaPiolaResponse");
177 static std::map<int, boost::shared_ptr<MatPiolaResponse>> empty_map;
178 return empty_map;
179}
180
181template <>
182boost::shared_ptr<PhysicalEquations>
184 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
185 return boost::make_shared<MatMetaPiolaResponse<3>>(mat_ops_data_ptr, tag);
186}
187
188template <>
189boost::shared_ptr<PhysicalEquations>
191 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
192 return boost::make_shared<MatMetaPiolaResponse<2>>(mat_ops_data_ptr, tag);
193}
194
195template <>
196boost::shared_ptr<PhysicalEquations>
198 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
199 return boost::make_shared<MatMetaPiolaResponse<3, MODEL_AXISYMMETRIC>>(
200 mat_ops_data_ptr, tag);
201}
202} // namespace MatOps
Tag tag
#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
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< PIOLA_RESPONSE::META, MODEL_AXISYMMETRIC >(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< PIOLA_RESPONSE::META, MODEL_3D >(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
@ MODEL_3D
Definition MatOps.hpp:234
@ MODEL_2D_PLANE_STRAIN
Definition MatOps.hpp:235
std::map< int, boost::shared_ptr< MatPiolaResponse > > & getMetaPiolaResponseMap(boost::shared_ptr< MatPiolaResponse > meta_ptr)
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< PIOLA_RESPONSE::META, MODEL_2D_PLANE_STRAIN >(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 evaluateDerivatives(int tag, EntityHandle entity, int gg) override
MatMetaPiolaResponse(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
std::map< int, ResponsePtr > metaPiolaResponses
boost::shared_ptr< MatPiolaResponse > ResponsePtr
MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override
MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr) override
std::map< int, ResponsePtr > & getMetaPiolaResponseMap()
MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity, int gg) override
MoFEMErrorCode recordTape() override
MoFEMErrorCode updateState(int tag, EntityHandle entity, int gg) override
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.