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 Abaqus-compatible compressible Neo-Hookean material
5 * @version 0.1
6 * @date 2026-03-26
7 *
8 * @copyright Copyright (c) 2026
9 *
10 */
11
12namespace MatOps {
13template <typename M> struct MatNeohookeanGeneric : public M {
14 using A = M;
15 using A::A;
16
17 static inline double getShearModulus(const double c10) { return 2. * c10; }
18
19 static inline double getAbaqusD1(const double K) { return 2. / K; }
20
22 const double K,
23 const char *source) {
25 if (!std::isfinite(c10) || c10 <= 0.) {
26 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
27 "Neohookean C10 must be finite and positive in %s", source);
28 }
29 if (!std::isfinite(K) || K <= 0.) {
30 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
31 "Neohookean bulk modulus K must be finite and positive in %s "
32 "(received C10=%.16g, K=%.16g)",
33 source, c10, K);
34 }
36 }
37
38 MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr = nullptr) override {
40
41 MOFEM_LOG_CHANNEL("WORLD");
42
43 if (!A::paramVecByRange.empty()) {
44 for (const auto &[range, parameters] : A::paramVecByRange) {
45 (void)range;
46 if (parameters.size() != 2) {
47 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
48 "Neohookean material range needs exactly C10 and K");
49 }
50 CHKERR validateMaterialParameters(parameters[0], parameters[1],
51 "preconfigured material range");
52 }
54 }
55
56 PetscOptionsBegin(PETSC_COMM_WORLD, "neo_hookean_", "", "none");
57 CHKERR PetscOptionsScalar("-c10", "C10", "", C10, &C10, PETSC_NULLPTR);
58 CHKERR PetscOptionsScalar("-K", "Bulk modulus K", "", K, &K, PETSC_NULLPTR);
59 PetscOptionsEnd();
60 CHKERR validateMaterialParameters(C10, K, "command-line parameters");
62
63 std::string block_name = "MAT_NEOHOOKEAN";
64
65 for (auto &m :
66
67 m_field_ptr->getInterface<MeshsetsManager>()->
68
69 getCubitMeshsetPtr(
70 std::regex((boost::format("%s(.*)") % block_name).str()))
71
72 ) {
73
74 std::vector<double> block_data;
75 CHKERR m->getAttributes(block_data);
76 auto get_block_ents = [&]() {
77 Range ents;
78 CHK_MOAB_THROW(m_field_ptr->get_moab().get_entities_by_handle(
79 m->meshset, ents, true),
80 "can not get block entities");
81 return ents;
82 };
83
84 CHKERR addBlockParameters(*m_field_ptr, m->getName(), m->getMeshsetId(),
85 get_block_ents(), block_data);
86 }
87
88 if (A::paramVecByRange.empty()) {
90 MOFEM_TAG_AND_LOG("WORLD", Sev::inform,
91 "Command line Neohookean parameters")
92 << "C10 = " << C10 << " K = " << K << " mu = " << getShearModulus(C10)
93 << " Abaqus D1 = " << getAbaqusD1(K);
94 }
95
97 }
98
100 addBlockParameters(MoFEM::Interface &m_field, const std::string &block_name,
101 int block_id, const Range &block_entities,
102 const std::vector<double> &block_data) override {
104
105 const auto json_params =
106 m_field.getInterface<JsonConfigManager>()->getParamsFromBlockset(
107 "MAT_NEOHOOKEAN", block_id);
108 std::vector<double> params;
109 if (!json_params.empty()) {
110 if (json_params.size() != 2 ||
111 json_params.find("c10") == json_params.end() ||
112 json_params.find("k") == json_params.end()) {
113 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
114 "Neohookean JSON block %s needs exactly C10 and K attributes",
115 block_name.c_str());
116 }
117 params = {json_params.at("c10"), json_params.at("k")};
118 } else {
119 if (block_data.size() < 2) {
120 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
121 "Neohookean block %s has %d attributes; expected C10 and K",
122 block_name.c_str(), static_cast<int>(block_data.size()));
123 }
124 params = {block_data[0], block_data[1]};
125 }
126
127 CHKERR validateMaterialParameters(params[0], params[1], block_name.c_str());
128
129 A::paramVecByRange.push_back({block_entities, params});
130
131 MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "MatBlock for Neohookean")
132 << block_name << " C10 = " << params[0] << " K = " << params[1]
133 << " mu = " << getShearModulus(params[0])
134 << " Abaqus D1 = " << getAbaqusD1(params[1]);
135
137 }
138
139protected:
140 double C10 = 1;
141 double K = 2;
142 std::vector<double> defaultMaterialParameters = {C10, K};
143 std::vector<double> commandLineParameters;
144};
145
146template <int DIM>
147struct MatNeohookean : public MatNeohookeanGeneric<MatElasticImpl<DIM>> {
149 using A::A;
150
151 MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override {
152 (void)gg;
153 const auto ent = fe_ptr->getFEEntityHandle();
154 for (auto &[range, param_vec] : A::paramVecByRange) {
155 if (std::find(range.begin(), range.end(), ent) != range.end()) {
156 set_param_vec(A::tAg, param_vec.size(), param_vec.data());
157 return 0;
158 }
159 }
160 // command line overrides block parameters
161 if (!this->commandLineParameters.empty()) {
162 set_param_vec(A::tAg, this->commandLineParameters.size(),
163 this->commandLineParameters.data());
164 return 0;
165 }
166 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
167 "Neohookean material parameters not found for entity %lu",
168 static_cast<unsigned long>(ent));
169 }
170
173
174 A::matOpsDataPtr->insertCommonData("grad", MatrixDouble());
175 A::matOpsDataPtr->insertCommonData("P", MatrixDouble());
176 A::matOpsDataPtr->insertCommonData("P_dF", MatrixDouble());
177
178 A::matOpsDataPtr->insertActiveData("F", MatrixDouble());
179 A::matOpsDataPtr->insertDependentData("P", MatrixDouble());
180 A::matOpsDataPtr->insertDependentData("energy", MatrixDouble());
181 A::matOpsDataPtr->insertDependentDerivativesData("P_dF", MatrixDouble());
182 A::matOpsDataPtr->insertDependentDerivativesData("energy_dF",
183 MatrixDouble());
184
185 A::matOpsDataPtr->getActiveDataPtr("F")->resize(DIM, DIM, false);
186 A::matOpsDataPtr->getDependentDataPtr("P")->resize(DIM, DIM, false);
187 A::matOpsDataPtr->getDependentDataPtr("energy")->resize(1, 1, false);
188 A::matOpsDataPtr->getDependentDerivativesDataPtr("energy_dF")
189 ->resize(1, DIM * DIM, false);
190
191 auto t_F = getFTensor2FromPtr<DIM, DIM>(
192 A::matOpsDataPtr->getActiveDataPtr("F")->data().data());
193 auto t_P = getFTensor2FromPtr<DIM, DIM>(
194 A::matOpsDataPtr->getDependentDataPtr("P")->data().data());
195 auto energy_ptr = A::matOpsDataPtr->getDependentDataPtr("energy");
196
198
199 FTENSOR_INDEX(DIM, i);
200 FTENSOR_INDEX(DIM, j);
201 FTENSOR_INDEX(DIM, I);
202 FTENSOR_INDEX(DIM, J);
203
204 t_F(i, J) = 0;
205
208
209 adouble det_aF, I1, ta_energy;
211
212 trace_on(A::tAg);
213 auto p_c10 = mkparam(this->C10);
214 auto p_K = mkparam(this->K);
215
216 ta_F(i, J) <<= t_F(i, J);
217 // assume that gradient from approximated displacement, that why we add diagonal
219 ta_F(i, J) += t_kd(i, J);
220 }
221
222 det_aF = determinantTensor(ta_F);
223 I1 = ta_F(i, I) * ta_F(i, I);
224 if constexpr (DIM == 2) {
225 // Abaqus plane strain uses the three-dimensional potential with F33=1.
226 I1 += 1.;
227 }
228 CHKERR invertTensor(ta_F, det_aF, ta_invF);
229
230 // Abaqus compressible Neo-Hookean potential (reduced polynomial N=1):
231 //
232 // W = C10 * (I1_bar - 3) + (1 / D1) * (J - 1)^2,
233 // I1_bar = J^(-2/3) * I1, mu0 = 2*C10, D1 = 2/K0.
234 //
235 // Its first Piola stress is
236 //
237 // P = 2*C10*J^(-2/3)*(F - I1/3*F^(-T))
238 // + K0*J*(J - 1)*F^(-T).
239 const auto jacobian_to_minus_two_thirds = pow(det_aF, -2. / 3.);
240 ta_P(i, I) = 2. * p_c10 * jacobian_to_minus_two_thirds *
241 (ta_F(i, I) - (I1 / 3.) * ta_invF(I, i)) +
242 p_K * det_aF * (det_aF - 1.) * ta_invF(I, i);
243
244 ta_energy = p_c10 * (jacobian_to_minus_two_thirds * I1 - 3.) +
245 0.5 * p_K * (det_aF - 1.) * (det_aF - 1.);
246
247 ta_P(i, I) >>= t_P(i, I);
248 ta_energy >>= (*energy_ptr)(0, 0);
249
250 trace_off();
251
253 }
254};
255
256template <>
257boost::shared_ptr<PhysicalEquations>
259 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
260 return boost::make_shared<MatNeohookean<3>>(mat_ops_data_ptr, tag);
261}
262
263template <>
264boost::shared_ptr<PhysicalEquations>
266 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
267 return boost::make_shared<MatNeohookean<2>>(mat_ops_data_ptr, tag);
268}
269
270template <>
271boost::shared_ptr<PhysicalEquations>
273 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
274 return boost::make_shared<MatNeohookean<3>>(mat_ops_data_ptr, tag);
275}
276
277} // namespace MatOps
std::vector< int > source
Tag tag
std::vector< double > empty
One value per component.
#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
@ MOFEM_INVALID_DATA
Definition definitions.h:36
#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 double getShearModulus(const double c10)
std::vector< double > commandLineParameters
std::vector< double > defaultMaterialParameters
static MoFEMErrorCode validateMaterialParameters(const double c10, const double K, const char *source)
MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr) override
static double getAbaqusD1(const double K)
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
MoFEMErrorCode recordTape() override
MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override
static bool useDeformationGradient
Otherwise the displacement gradient is supplied and I is added.
Definition MatOps.hpp:214
std::vector< std::pair< Range, std::vector< double > > > paramVecByRange
Definition MatOps.hpp:199
boost::shared_ptr< MatOpsData > matOpsDataPtr
Definition MatOps.hpp:201
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.