v0.16.0
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>
16 using MatElasticImpl<DIM>::MatElasticImpl;
17
19
20 MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr = nullptr) override {
22
23 MOFEM_LOG_CHANNEL("WORLD");
24
25 PetscOptionsBegin(PETSC_COMM_WORLD, "stvenant_", "", "none");
26 CHKERR PetscOptionsScalar("-young_modulus", "Young modulus", "", E, &E,
27 PETSC_NULLPTR);
28 CHKERR PetscOptionsScalar("-poisson_ratio", "poisson ratio", "", nu, &nu,
29 PETSC_NULLPTR);
30 PetscOptionsEnd();
31
32 MOFEM_TAG_AND_LOG("WORLD", Sev::inform,
33 "Default StVenantKirchhoff parameters:")
34 << " E = " << E << " nu = " << nu;
36
37 std::string block_name = "MAT_STVENANTKIRCHHOFF";
38
39 for (auto &m :
40
41 m_field_ptr->getInterface<MeshsetsManager>()->
42
43 getCubitMeshsetPtr(
44 std::regex((boost::format("%s(.*)") % block_name).str()))
45
46 ) {
47
48 std::vector<double> block_data;
49 CHKERR m->getAttributes(block_data);
50 if (block_data.size() < 2) {
52 "Expected that block has two attribute");
53 }
54 auto get_block_ents = [&]() {
55 Range ents;
56 CHK_MOAB_THROW(m_field_ptr->get_moab().get_entities_by_handle(
57 m->meshset, ents, true),
58 "can not get block entities");
59 return ents;
60 };
61
62 A::paramVecByRange.push_back(
63 {get_block_ents(), {block_data[0], block_data[1]}});
64
65 MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "MatBlock for StVenantKirchhoff")
66 << *m << " E = " << block_data[0] << " nu = " << block_data[1];
67 }
68
70 };
71
72 MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override {
73 (void)gg;
74 const auto ent = fe_ptr->getFEEntityHandle();
75 for (auto &[range, param_vec] : A::paramVecByRange) {
76 if (std::find(range.begin(), range.end(), ent) != range.end()) {
77 set_param_vec(A::tAg, param_vec.size(), param_vec.data());
78 return 0;
79 }
80 }
81 set_param_vec(A::tAg, defaultMaterialParameters.size(),
83 return 0;
84 }
85
86 MoFEMErrorCode recordTape() override {
88
89 A::matOpsDataPtr->insertCommonData("grad", MatrixDouble());
90 A::matOpsDataPtr->insertCommonData("P", MatrixDouble());
91 A::matOpsDataPtr->insertCommonData("P_dF", MatrixDouble());
92
93 A::matOpsDataPtr->insertActiveData("F", MatrixDouble());
94 A::matOpsDataPtr->insertDependentData("P", MatrixDouble());
95 A::matOpsDataPtr->insertDependentDerivativesData("P_dF", MatrixDouble());
96
97 A::matOpsDataPtr->getActiveDataPtr("F")->resize(DIM, DIM, false);
98 A::matOpsDataPtr->getDependentDataPtr("P")->resize(DIM, DIM, false);
99
100
101 auto t_F = getFTensor2FromPtr<DIM, DIM>(
102 A::matOpsDataPtr->getActiveDataPtr("F")->data().data());
103 auto t_P = getFTensor2FromPtr<DIM, DIM>(
104 A::matOpsDataPtr->getDependentDataPtr("P")->data().data());
105
107
108 FTENSOR_INDEX(DIM, i);
109 FTENSOR_INDEX(DIM, j);
110 FTENSOR_INDEX(DIM, I);
111 FTENSOR_INDEX(DIM, J);
112
113 t_F(i, J) = 0;
114
120
121 adouble trE;
122
123 trace_on(A::tAg);
124 auto p_E = mkparam(E);
125 auto p_nu = mkparam(nu);
126
127 const auto calc_lambda = [](const auto &young_modulus,
128 const auto &poisson_ratio) {
129 const auto nu_value = 1 * poisson_ratio;
130 return (young_modulus * nu_value) /
131 ((1. + nu_value) * (1. - 2. * nu_value));
132 };
133
134 const auto calc_mu = [](const auto &young_modulus,
135 const auto &poisson_ratio) {
136 const auto nu_value = 1 * poisson_ratio;
137 return 0.5 * (young_modulus / (1. + nu_value));
138 };
139
140 auto lambda = calc_lambda(p_E, p_nu);
141 auto mu = calc_mu(p_E, p_nu);
142
143 ta_F(i, J) <<= t_F(i, J);
144 // assume that gradient from approximated displacement, that why we add diagonal
146 ta_F(i, J) += t_kd(i, J);
147 }
148
149 ta_C(I, J) = ta_F(i, I) * ta_F(i, J);
150 ta_E(I, J) = (ta_C(I, J) - t_kd(I, J))/2.;
151
152 // Stress Piola II
153 trE = ta_E(I, I);
154 ta_S(I, J) = (2 * mu) * ta_E(I, J) + lambda * trE * t_kd(I, J);
155 // Stress Piola I
156 ta_P(i, J) = ta_F(i, I) * ta_S(I, J);
157
158 ta_P(i, I) >>= t_P(i, I);
159
160 trace_off();
161
163 }
164
165protected:
166 double E = 1;
167 double nu = 0.25;
168 std::vector<double> defaultMaterialParameters = {E, nu};
169};
170
171template <>
172boost::shared_ptr<PhysicalEquations>
174 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
175 return boost::make_shared<MatStVenantKirchhoff<3>>(mat_ops_data_ptr, tag);
176}
177
178template <>
179boost::shared_ptr<PhysicalEquations>
180createMatOpsPhysicalEquationsPtr<ELASTICITY::STVENANTKIRCHHOFF,
182 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
183 return boost::make_shared<MatStVenantKirchhoff<2>>(mat_ops_data_ptr, tag);
184}
185} // namespace MatOps
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
#define FTENSOR_INDEX(DIM, I)
Kronecker Delta class.
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#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_2D_PLANE_STRAIN
Definition MatOps.hpp:172
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)
constexpr IntegrationType I
FTensor::Index< 'm', 3 > m
static bool useDeformationGradient
std::vector< double > defaultMaterialParameters
MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override
MoFEMErrorCode recordTape() override
MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr) override
std::vector< std::pair< Range, std::vector< double > > > paramVecByRange
Definition MatOps.hpp:152
boost::shared_ptr< MatOpsData > matOpsDataPtr
Definition MatOps.hpp:154
Deprecated interface functions.
double young_modulus
Young modulus.
Definition plastic.cpp:126
double poisson_ratio
Poisson ratio.
Definition plastic.cpp:127