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