v0.16.3
Loading...
Searching...
No Matches
MatNeohookean.cpp
Go to the documentation of this file.
1/**
2 * @file MatNeohookean.cpp
3 * @author your name (you@domain.com)
4 * @brief
5 * @version 0.1
6 * @date 2026-03-26
7 *
8 * @copyright Copyright (c) 2026
9 *
10 */
11
12namespace MatOps {
13
14template <int DIM> struct MatNeohookean : public MatElasticImpl<DIM> {
15 using MatElasticImpl<DIM>::MatElasticImpl;
16
18
19 MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr = nullptr) override {
21
22 MOFEM_LOG_CHANNEL("WORLD");
23
24 if (!A::paramVecByRange.empty()) {
26 }
27
28 PetscOptionsBegin(PETSC_COMM_WORLD, "neo_hookean_", "", "none");
29 CHKERR PetscOptionsScalar("-c10", "C10", "", C10, &C10, PETSC_NULLPTR);
30 CHKERR PetscOptionsScalar("-K", "Bulk modulus K", "", K, &K,
31 PETSC_NULLPTR);
32 PetscOptionsEnd();
33
34 std::string block_name = "MAT_NEOHOOKEAN";
35
36 for (auto &m :
37
38 m_field_ptr->getInterface<MeshsetsManager>()->
39
40 getCubitMeshsetPtr(
41 std::regex((boost::format("%s(.*)") % block_name).str()))
42
43 ) {
44
45 std::vector<double> block_data;
46 CHKERR m->getAttributes(block_data);
47 auto get_block_ents = [&]() {
48 Range ents;
49 CHK_MOAB_THROW(m_field_ptr->get_moab().get_entities_by_handle(
50 m->meshset, ents, true),
51 "can not get block entities");
52 return ents;
53 };
54
55 CHKERR addBlockParameters(*m_field_ptr, m->getName(),
56 m->getMeshsetId(), get_block_ents(),
57 block_data);
58 }
59
60 if (A::paramVecByRange.empty()) {
62 MOFEM_TAG_AND_LOG("WORLD", Sev::inform,
63 "Command line Neohookean parameters")
64 << "C10 = " << C10 << " K = " << K;
65 }
66
68 }
69
71 addBlockParameters(MoFEM::Interface &m_field, const std::string &block_name,
72 int block_id, const Range &block_entities,
73 const std::vector<double> &block_data) override {
75
76 const auto json_params =
77 m_field.getInterface<JsonConfigManager>()->getParamsFromBlockset(
78 "MAT_NEOHOOKEAN", block_id);
79 if (!json_params.empty() && (json_params.size() != 2 ||
80 json_params.find("c10") == json_params.end() ||
81 json_params.find("k") == json_params.end())) {
82 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
83 "Neohookean JSON block %s needs exactly C10 and K attributes",
84 block_name.c_str());
85 }
86
87 if (block_data.size() < 2) {
88 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
89 "Neohookean block %s has %d attributes; expected C10 and K",
90 block_name.c_str(), static_cast<int>(block_data.size()));
91 }
92 std::vector<double> params = {block_data[0], block_data[1]};
93
94 A::paramVecByRange.push_back({block_entities, params});
95
96 MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "MatBlock for Neohookean")
97 << block_name << " C10 = " << params[0] << " K = " << params[1];
98
100 }
101
102 MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override {
103 (void)gg;
104 const auto ent = fe_ptr->getFEEntityHandle();
105 for (auto &[range, param_vec] : A::paramVecByRange) {
106 if (std::find(range.begin(), range.end(), ent) != range.end()) {
107 set_param_vec(A::tAg, param_vec.size(), param_vec.data());
108 return 0;
109 }
110 }
111 // command line overrides block parameters
112 if (!commandLineParameters.empty()) {
113 set_param_vec(A::tAg, commandLineParameters.size(),
114 commandLineParameters.data());
115 return 0;
116 }
117 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
118 "Neohookean material parameters not found for entity %lu",
119 static_cast<unsigned long>(ent));
120 }
121
124
125 A::matOpsDataPtr->insertCommonData("grad", MatrixDouble());
126 A::matOpsDataPtr->insertCommonData("P", MatrixDouble());
127 A::matOpsDataPtr->insertCommonData("P_dF", MatrixDouble());
128
129 A::matOpsDataPtr->insertActiveData("F", MatrixDouble());
130 A::matOpsDataPtr->insertDependentData("P", MatrixDouble());
131 A::matOpsDataPtr->insertDependentDerivativesData("P_dF", MatrixDouble());
132
133 A::matOpsDataPtr->getActiveDataPtr("F")->resize(DIM, DIM, false);
134 A::matOpsDataPtr->getDependentDataPtr("P")->resize(DIM, DIM, false);
135
136 auto t_F = getFTensor2FromPtr<DIM, DIM>(
137 A::matOpsDataPtr->getActiveDataPtr("F")->data().data());
138 auto t_P = getFTensor2FromPtr<DIM, DIM>(
139 A::matOpsDataPtr->getDependentDataPtr("P")->data().data());
140
142
143 FTENSOR_INDEX(DIM, i);
144 FTENSOR_INDEX(DIM, j);
145 FTENSOR_INDEX(DIM, I);
146 FTENSOR_INDEX(DIM, J);
147
148 t_F(i, J) = 0;
149
152
153 adouble det_aF;
155
156 trace_on(A::tAg);
157 auto p_c10 = mkparam(C10);
158 auto p_K = mkparam(K);
159
160 ta_F(i, J) <<= t_F(i, J);
161 // assume that gradient from approximated displacement, that why we add diagonal
163 ta_F(i, J) += t_kd(i, J);
164 }
165
166 det_aF = determinantTensor(ta_F);
167 CHKERR invertTensor(ta_F, det_aF, ta_invF);
168
169 ta_P(i, I) = 2. * p_c10 * (ta_F(i, I) - ta_invF(i, I)) +
170 p_K * log(det_aF) * ta_invF(i, I);
171
172 ta_P(i, I) >>= t_P(i, I);
173
174 trace_off();
175
177 }
178
179protected:
180 double C10 = 1;
181 double K = 1;
182 std::vector<double> commandLineParameters;
183};
184
185template <>
186boost::shared_ptr<PhysicalEquations>
188 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
189 return boost::make_shared<MatNeohookean<3>>(mat_ops_data_ptr, tag);
190}
191
192template <>
193boost::shared_ptr<PhysicalEquations>
195 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
196 return boost::make_shared<MatNeohookean<2>>(mat_ops_data_ptr, tag);
197}
198
199template <>
200boost::shared_ptr<PhysicalEquations>
202 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
203 return boost::make_shared<MatNeohookean<3>>(mat_ops_data_ptr, tag);
204}
205} // namespace MatOps
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
#define FTENSOR_INDEX(DIM, I)
Kronecker Delta class.
#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 ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ 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.
constexpr auto t_kd
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'J', DIM1 > J
Definition level_set.cpp:30
FTensor::Index< 'j', 3 > j
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< ELASTICITY::NEOHOOKEAN, MODEL_AXISYMMETRIC >(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< ELASTICITY::NEOHOOKEAN, MODEL_3D >(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< ELASTICITY::NEOHOOKEAN, MODEL_2D_PLANE_STRAIN >(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
UBlasMatrix< double > MatrixDouble
Definition Types.hpp:77
static MoFEMErrorCode invertTensor(FTensor::Tensor2< T1, DIM, DIM > &t, T2 &det, FTensor::Tensor2< T3, DIM, DIM > &inv_t)
static auto determinantTensor(FTensor::Tensor2< T, DIM, DIM > &t)
Calculate the determinant of a tensor of rank DIM.
constexpr IntegrationType I
FTensor::Index< 'm', 3 > m
static bool useDeformationGradient
MoFEMErrorCode recordTape() override
MoFEMErrorCode addBlockParameters(MoFEM::Interface &m_field, const std::string &block_name, int block_id, const Range &block_entities, const std::vector< double > &block_data) override
std::vector< double > commandLineParameters
MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override
MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr) override
std::vector< std::pair< Range, std::vector< double > > > paramVecByRange
Definition MatOps.hpp:174
boost::shared_ptr< MatOpsData > matOpsDataPtr
Definition MatOps.hpp:176
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.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.