v0.16.3
Loading...
Searching...
No Matches
MatStVenantKirchhoff.cpp
Go to the documentation of this file.
1/**
2 * @file MatStVenantKirchhoff.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 MatStVenantKirchhoff : 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, "stvenant_", "", "none");
29 CHKERR PetscOptionsScalar("-young_modulus", "Young modulus", "", E, &E,
30 PETSC_NULLPTR);
31 CHKERR PetscOptionsScalar("-poisson_ratio", "poisson ratio", "", nu, &nu,
32 PETSC_NULLPTR);
33 PetscOptionsEnd();
34
35 std::string block_name = "MAT_STVENANTKIRCHHOFF";
36
37 for (auto &m :
38
39 m_field_ptr->getInterface<MeshsetsManager>()->
40
41 getCubitMeshsetPtr(
42 std::regex((boost::format("%s(.*)") % block_name).str()))
43
44 ) {
45
46 std::vector<double> block_data;
47 CHKERR m->getAttributes(block_data);
48 auto get_block_ents = [&]() {
49 Range ents;
50 CHK_MOAB_THROW(m_field_ptr->get_moab().get_entities_by_handle(
51 m->meshset, ents, true),
52 "can not get block entities");
53 return ents;
54 };
55
56 CHKERR addBlockParameters(*m_field_ptr, m->getName(), m->getMeshsetId(),
57 get_block_ents(), block_data);
58 }
59
60 if (A::paramVecByRange.empty()) {
62 MOFEM_TAG_AND_LOG("WORLD", Sev::inform,
63 "Command line StVenantKirchhoff parameters")
64 << "E = " << E << " nu = " << nu;
65 }
66
68 };
69
71 addBlockParameters(MoFEM::Interface &, const std::string &block_name, int,
72 const Range &block_entities,
73 const std::vector<double> &block_data) override {
75
76 if (block_data.size() < 2) {
77 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
78 "StVenantKirchhoff block %s has %d attributes; expected E "
79 "and nu",
80 block_name.c_str(), static_cast<int>(block_data.size()));
81 }
82 std::vector<double> params = {block_data[0], block_data[1]};
83
84 A::paramVecByRange.push_back({block_entities, params});
85
86 MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "MatBlock for StVenantKirchhoff")
87 << block_name << " E = " << params[0] << " nu = " << params[1];
88
90 }
91
92 MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override {
93 (void)gg;
94 const auto ent = fe_ptr->getFEEntityHandle();
95 for (auto &[range, param_vec] : A::paramVecByRange) {
96 if (std::find(range.begin(), range.end(), ent) != range.end()) {
97 set_param_vec(A::tAg, param_vec.size(), param_vec.data());
98 return 0;
99 }
100 }
101 // command line overrides block parameters
102 if (!commandLineParameters.empty()) {
103 set_param_vec(A::tAg, commandLineParameters.size(),
104 commandLineParameters.data());
105 return 0;
106 }
107 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
108 "StVenantKirchhoff material parameters not found for entity %lu",
109 static_cast<unsigned long>(ent));
110 }
111
114
115 A::matOpsDataPtr->insertCommonData("grad", MatrixDouble());
116 A::matOpsDataPtr->insertCommonData("P", MatrixDouble());
117 A::matOpsDataPtr->insertCommonData("P_dF", MatrixDouble());
118
119 A::matOpsDataPtr->insertActiveData("F", MatrixDouble());
120 A::matOpsDataPtr->insertDependentData("P", MatrixDouble());
121 A::matOpsDataPtr->insertDependentData("energy", MatrixDouble());
122 A::matOpsDataPtr->insertDependentDerivativesData("P_dF", MatrixDouble());
123 A::matOpsDataPtr->insertDependentDerivativesData("energy_dF",
124 MatrixDouble());
125
126 A::matOpsDataPtr->getActiveDataPtr("F")->resize(DIM, DIM, false);
127 A::matOpsDataPtr->getDependentDataPtr("P")->resize(DIM, DIM, false);
128 A::matOpsDataPtr->getDependentDataPtr("energy")->resize(1, 1, false);
129 A::matOpsDataPtr->getDependentDerivativesDataPtr("energy_dF")
130 ->resize(1, DIM * DIM, false);
131
132 auto t_F = getFTensor2FromPtr<DIM, DIM>(
133 A::matOpsDataPtr->getActiveDataPtr("F")->data().data());
134 auto t_P = getFTensor2FromPtr<DIM, DIM>(
135 A::matOpsDataPtr->getDependentDataPtr("P")->data().data());
136 auto energy_ptr = A::matOpsDataPtr->getDependentDataPtr("energy");
137
139
140 FTENSOR_INDEX(DIM, i);
141 FTENSOR_INDEX(DIM, j);
142 FTENSOR_INDEX(DIM, I);
143 FTENSOR_INDEX(DIM, J);
144
145 t_F(i, J) = 0;
146
152
153 adouble trE, ta_energy;
154
155 trace_on(A::tAg);
156 auto p_E = mkparam(E);
157 auto p_nu = mkparam(nu);
158
159 const auto calc_lambda = [](const auto &young_modulus,
160 const auto &poisson_ratio) {
161 const auto nu_value = 1 * poisson_ratio;
162 return (young_modulus * nu_value) /
163 ((1. + nu_value) * (1. - 2. * nu_value));
164 };
165
166 const auto calc_mu = [](const auto &young_modulus,
167 const auto &poisson_ratio) {
168 const auto nu_value = 1 * poisson_ratio;
169 return 0.5 * (young_modulus / (1. + nu_value));
170 };
171
172 auto lambda = calc_lambda(p_E, p_nu);
173 auto mu = calc_mu(p_E, p_nu);
174
175 ta_F(i, J) <<= t_F(i, J);
176 // assume that gradient from approximated displacement, that why we add diagonal
178 ta_F(i, J) += t_kd(i, J);
179 }
180
181 ta_C(I, J) = ta_F(i, I) * ta_F(i, J);
182 ta_E(I, J) = (ta_C(I, J) - t_kd(I, J)) / 2.;
183
184 // Stress Piola II
185 trE = ta_E(I, I);
186 ta_S(I, J) = (2 * mu) * ta_E(I, J) + lambda * trE * t_kd(I, J);
187 // Stress Piola I
188 ta_P(i, J) = ta_F(i, I) * ta_S(I, J);
189 ta_energy = mu * (ta_E(I, J) * ta_E(I, J)) + 0.5 * lambda * trE * trE;
190
191 ta_P(i, I) >>= t_P(i, I);
192 ta_energy >>= (*energy_ptr)(0, 0);
193
194 trace_off();
195
197 }
198
199protected:
200 double E = 1;
201 double nu = 0.25;
202 std::vector<double> commandLineParameters;
203};
204
205template <>
206boost::shared_ptr<PhysicalEquations>
208 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
209 return boost::make_shared<MatStVenantKirchhoff<3>>(mat_ops_data_ptr, tag);
210}
211
212template <>
213boost::shared_ptr<PhysicalEquations>
214createMatOpsPhysicalEquationsPtr<ELASTICITY::STVENANTKIRCHHOFF,
216 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
217 return boost::make_shared<MatStVenantKirchhoff<2>>(mat_ops_data_ptr, tag);
218}
219
220template <>
221boost::shared_ptr<PhysicalEquations>
222createMatOpsPhysicalEquationsPtr<ELASTICITY::STVENANTKIRCHHOFF,
224 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
225 return boost::make_shared<MatStVenantKirchhoff<3>>(mat_ops_data_ptr, tag);
226}
227} // 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
static double lambda
FTensor::Index< 'J', DIM1 > J
Definition level_set.cpp:30
FTensor::Index< 'j', 3 > j
@ MODEL_AXISYMMETRIC
Definition MatOps.hpp:212
@ MODEL_2D_PLANE_STRAIN
Definition MatOps.hpp:210
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< ELASTICITY::STVENANTKIRCHHOFF, MODEL_3D >(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)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
UBlasMatrix< double > MatrixDouble
Definition Types.hpp:77
constexpr IntegrationType I
double young_modulus
Young modulus.
Definition plastic.cpp:126
double poisson_ratio
Poisson ratio.
Definition plastic.cpp:127
FTensor::Index< 'm', 3 > m
static bool useDeformationGradient
Otherwise the displacement gradient is supplied and I is added.
Definition MatOps.hpp:189
MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override
MoFEMErrorCode addBlockParameters(MoFEM::Interface &, const std::string &block_name, int, const Range &block_entities, const std::vector< double > &block_data) override
MoFEMErrorCode recordTape() override
MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr) override
std::vector< double > commandLineParameters
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.