version 0.4.1
physicshelper.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
10#pragma once
11#include <dune/common/float_cmp.hh>
12
13#include <Eigen/Core>
14namespace Ikarus {
15
23inline Eigen::Matrix3d planeStressLinearElasticMaterialTangent(double E, double nu) {
24 Eigen::Matrix3d C;
25 C.setZero();
26 C(0, 0) = C(1, 1) = 1;
27 C(0, 1) = C(1, 0) = nu;
28 C(2, 2) = (1 - nu) / 2;
29 C *= E / (1 - nu * nu);
30 return C;
31}
32
40inline Eigen::Matrix<double, 6, 6> linearElasticMaterialTangent3D(double E, double nu) {
41 Eigen::Matrix<double, 6, 6> C;
42 C.setZero();
43 C(0, 0) = C(1, 1) = C(2, 2) = 1 - nu;
44 C(0, 1) = C(1, 0) = C(2, 0) = C(0, 2) = C(1, 2) = C(2, 1) = nu;
45 C(3, 3) = C(4, 4) = C(5, 5) = (1 - 2 * nu) / 2;
46 C *= E / ((1 + nu) * (1 - 2 * nu));
47 return C;
48}
49
53{
54 double emodul;
55 double nu;
56};
57
60{
61 double emodul;
62 double mu;
63};
64
67{
68 double emodul;
69 double K;
70};
71
74{
75 double emodul;
76 double lambda;
77};
78
81{
82 double K;
83 double lambda;
84};
85
88{
89 double lambda;
90 double mu;
91};
92
98template <typename MP>
99concept MPTuple =
100 std::is_same_v<MP, YoungsModulusAndPoissonsRatio> or std::is_same_v<MP, YoungsModulusAndBulkModulus> or
101 std::is_same_v<MP, YoungsModulusAndLamesFirstParameter> or std::is_same_v<MP, BulkModulusAndLamesFirstParameter> or
102 std::is_same_v<MP, LamesFirstParameterAndShearModulus> or std::is_same_v<MP, YoungsModulusAndShearModulus>;
103
109template <typename ValuePair>
111{
112 constexpr double toLamesFirstParameter()
113 requires(!std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter> and
114 !std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter> and
115 !std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>)
116 {
117 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
118 const auto& E = vp_.emodul;
119 const auto& nu = vp_.nu;
120 return Dune::FloatCmp::eq(nu, 0.5) ? std::numeric_limits<double>::infinity()
121 : E * nu / ((1.0 + nu) * (1.0 - 2.0 * nu));
122 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
123 const auto& E = vp_.emodul;
124 const auto& mu = vp_.mu;
125 return mu * (E - 2.0 * mu) / (3.0 * mu - E);
126 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
127 const auto& E = vp_.emodul;
128 const auto& K = vp_.K;
129 return 3.0 * K * (3.0 * K - E) / (9.0 * K - E);
130 } else
131 assert(false && "Your LameParameter request is not implemented");
132 }
133
134 constexpr double toBulkModulus()
135 requires(!std::is_same_v<ValuePair, YoungsModulusAndBulkModulus> and
136 !std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>)
137 {
138 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
139 const auto& E = vp_.emodul;
140 const auto& nu = vp_.nu;
141 return E / (3.0 * (1.0 - 2.0 * nu));
142 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
143 const auto& E = vp_.emodul;
144 const auto& mu = vp_.mu;
145 return E * mu / (3.0 * (3.0 * mu - E));
146 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
147 const auto& E = vp_.emodul;
148 const auto& lambda = vp_.lambda;
149 return (E + 3.0 * lambda + calcR(vp_)) / 6.0;
150 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
151 const auto& lambda = vp_.lambda;
152 const auto& mu = vp_.mu;
153 return lambda + 2.0 * mu / 3.0;
154 } else
155 assert(false && "Your LameParameter request is not implemented");
156 }
157
158 constexpr double toShearModulus()
159 requires(!std::is_same_v<ValuePair, YoungsModulusAndShearModulus> and
160 !std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>)
161 {
162 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
163 const auto& E = vp_.emodul;
164 const auto& nu = vp_.nu;
165 return E / (2.0 * (1.0 + nu));
166 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
167 const auto& E = vp_.emodul;
168 const auto& K = vp_.K;
169 return 3.0 * K * E / (9.0 * K - E);
170 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
171 const auto& E = vp_.emodul;
172 const auto& lambda = vp_.lambda;
173 return (E - 3.0 * lambda + calcR(vp_)) / 4.0;
174 } else if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
175 const auto& K = vp_.K;
176 const auto& lambda = vp_.lambda;
177 return 3.0 * (K - lambda) / 2.0;
178 } else
179 assert(false && "Your LameParameter request is not implemented");
180 }
181
182 constexpr double toPWaveModulus() {
183 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
184 const auto& E = vp_.emodul;
185 const auto& nu = vp_.nu;
186 return E * (1.0 - nu) / ((1.0 + nu) * (1.0 - 2.0 * nu));
187 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
188 const auto& E = vp_.emodul;
189 const auto& mu = vp_.mu;
190 return mu * (4.0 * mu - E) / (3.0 * mu - E);
191 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
192 const auto& E = vp_.emodul;
193 const auto& K = vp_.K;
194 return 3.0 * K * (3.0 * K + E) / (9.0 * K - E);
195 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
196 const auto& E = vp_.emodul;
197 const auto& lambda = vp_.lambda;
198 return (E - lambda + calcR(vp_)) / 2.0;
199 } else if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
200 const auto& K = vp_.K;
201 const auto& lambda = vp_.lambda;
202 return 3.0 * K - 2.0 * lambda;
203 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
204 const auto& lambda = vp_.lambda;
205 const auto& mu = vp_.mu;
206 return lambda + 2.0 * mu;
207 } else
208 assert(false && "Your LameParameter request is not implemented");
209 }
210
211 constexpr double toPoissonsRatio()
212 requires(!std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>)
213 {
214 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
215 const auto& E = vp_.emodul;
216 const auto& mu = vp_.mu;
217 return E / (2.0 * mu) - 1.0;
218 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
219 const auto& E = vp_.emodul;
220 const auto& K = vp_.K;
221 return (3.0 * K - E) / (6.0 * K);
222 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
223 const auto& E = vp_.emodul;
224 const auto& lambda = vp_.lambda;
225 return 2.0 * lambda / (E + lambda + calcR(vp_));
226 } else if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
227 const auto& K = vp_.K;
228 const auto& lambda = vp_.lambda;
229 return lambda / (3 * K - lambda);
230 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
231 const auto& lambda = vp_.lambda;
232 const auto& mu = vp_.mu;
233 return lambda / (2.0 * (lambda + mu));
234 } else
235 assert(false && "Your LameParameter request is not implemented");
236 }
237
238 constexpr double toYoungsModulus()
239 requires(!std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio> and
240 !std::is_same_v<ValuePair, YoungsModulusAndShearModulus> and
241 !std::is_same_v<ValuePair, YoungsModulusAndBulkModulus> and
242 !std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>)
243 {
244 if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
245 return 9.0 * vp_.K * (vp_.K - vp_.lambda) / (3.0 * vp_.K - vp_.lambda);
246 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
247 const auto& lambda = vp_.lambda;
248 const auto& mu = vp_.mu;
249 return mu * (3.0 * lambda + 2.0 * mu) / (lambda + mu);
250 } else
251 assert(false && "Your LameParameter request is not implemented");
252 }
253
254private:
256 const YoungsModulusAndPoissonsRatio& valuePair);
258 const YoungsModulusAndShearModulus& valuePair);
259
261 const YoungsModulusAndBulkModulus& valuePair);
262
264 const LamesFirstParameterAndShearModulus& valuePair);
265
267 const BulkModulusAndLamesFirstParameter& valuePair);
268 ConvertLameConstants(ValuePair&& valuePair)
269 : vp_(valuePair) {}
270 ConvertLameConstants(const ValuePair& valuePair)
271 : vp_(valuePair) {}
272
273 double calcR(const YoungsModulusAndLamesFirstParameter& valuePair) {
274 const auto& E = valuePair.emodul;
275 const auto& lambda = valuePair.lambda;
276 return std::sqrt(E * E + 9 * lambda * lambda + 2 * E * lambda);
277 }
278 ValuePair vp_;
279};
281 const YoungsModulusAndPoissonsRatio& valuePair) {
282 return {valuePair};
283}
285 const YoungsModulusAndShearModulus& valuePair) {
286 return {valuePair};
287}
289 const YoungsModulusAndBulkModulus& valuePair) {
290 return {valuePair};
291}
293 const LamesFirstParameterAndShearModulus& valuePair) {
294 return {valuePair};
295}
297 const BulkModulusAndLamesFirstParameter& valuePair) {
298 return {valuePair};
299}
300
308 auto lambda = convertLameConstants(matParameter).toLamesFirstParameter();
309 auto mu = convertLameConstants(matParameter).toShearModulus();
310
311 return LamesFirstParameterAndShearModulus{.lambda = lambda, .mu = mu};
312}
313
321 auto emod = convertLameConstants(matParameter).toYoungsModulus();
322 auto nu = convertLameConstants(matParameter).toPoissonsRatio();
323
324 return YoungsModulusAndPoissonsRatio{.emodul = emod, .nu = nu};
325}
326
327} // namespace Ikarus
Definition: simpleassemblers.hh:22
auto toLamesFirstParameterAndShearModulus(const YoungsModulusAndPoissonsRatio &matParameter)
Converts Young's modulus and Poisson's ratio to Lame's first parameter and shear modulus.
Definition: physicshelper.hh:307
auto toYoungsModulusAndPoissonsRatio(const LamesFirstParameterAndShearModulus &matParameter)
Converts Lame's first parameter and shear modulus to Young's modulus and Poisson's ratio.
Definition: physicshelper.hh:320
ConvertLameConstants< YoungsModulusAndPoissonsRatio > convertLameConstants(const YoungsModulusAndPoissonsRatio &valuePair)
Definition: physicshelper.hh:280
Eigen::Matrix3d planeStressLinearElasticMaterialTangent(double E, double nu)
Computes the plane stress linear elastic material tangent matrix.
Definition: physicshelper.hh:23
Eigen::Matrix< double, 6, 6 > linearElasticMaterialTangent3D(double E, double nu)
Computes the 3D linear elastic material tangent matrix.
Definition: physicshelper.hh:40
Structure representing Young's modulus and shear modulus.
Definition: physicshelper.hh:53
double emodul
Definition: physicshelper.hh:54
double nu
Definition: physicshelper.hh:55
Structure representing Young's modulus and bulk modulus.
Definition: physicshelper.hh:60
double mu
Definition: physicshelper.hh:62
double emodul
Definition: physicshelper.hh:61
Structure representing Young's modulus and Lame's first parameter.
Definition: physicshelper.hh:67
double emodul
Definition: physicshelper.hh:68
double K
Definition: physicshelper.hh:69
Structure representing bulk modulus and Lame's first parameter.
Definition: physicshelper.hh:74
double lambda
Definition: physicshelper.hh:76
double emodul
Definition: physicshelper.hh:75
Structure representing Lame's first parameter and shear modulus.
Definition: physicshelper.hh:81
double K
Definition: physicshelper.hh:82
double lambda
Definition: physicshelper.hh:83
Definition: physicshelper.hh:88
double lambda
Definition: physicshelper.hh:89
double mu
Definition: physicshelper.hh:90
Conversion utility for Lame's constants.
Definition: physicshelper.hh:111
constexpr double toYoungsModulus()
Definition: physicshelper.hh:238
constexpr double toBulkModulus()
Definition: physicshelper.hh:134
constexpr double toPoissonsRatio()
Definition: physicshelper.hh:211
friend ConvertLameConstants< YoungsModulusAndPoissonsRatio > convertLameConstants(const YoungsModulusAndPoissonsRatio &valuePair)
Definition: physicshelper.hh:280
constexpr double toLamesFirstParameter()
Definition: physicshelper.hh:112
constexpr double toPWaveModulus()
Definition: physicshelper.hh:182
constexpr double toShearModulus()
Definition: physicshelper.hh:158
Concept for checking if a type is a valid material parameter tuple.
Definition: physicshelper.hh:99