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
19{
20 double emodul;
21 double nu;
22};
23
26{
27 double emodul;
28 double mu;
29};
30
33{
34 double emodul;
35 double K;
36};
37
40{
41 double emodul;
42 double lambda;
43};
44
47{
48 double K;
49 double lambda;
50};
51
54{
55 double lambda;
56 double mu;
57};
58
64template <typename MP>
65concept MPTuple =
66 std::is_same_v<MP, YoungsModulusAndPoissonsRatio> or std::is_same_v<MP, YoungsModulusAndBulkModulus> or
67 std::is_same_v<MP, YoungsModulusAndLamesFirstParameter> or std::is_same_v<MP, BulkModulusAndLamesFirstParameter> or
68 std::is_same_v<MP, LamesFirstParameterAndShearModulus> or std::is_same_v<MP, YoungsModulusAndShearModulus>;
69
75template <typename ValuePair>
77{
78 constexpr double toLamesFirstParameter()
79 requires(!std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter> and
80 !std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter> and
81 !std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>)
82 {
83 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
84 const auto& E = vp_.emodul;
85 const auto& nu = vp_.nu;
86 return Dune::FloatCmp::eq(nu, 0.5) ? std::numeric_limits<double>::infinity()
87 : E * nu / ((1.0 + nu) * (1.0 - 2.0 * nu));
88 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
89 const auto& E = vp_.emodul;
90 const auto& mu = vp_.mu;
91 return mu * (E - 2.0 * mu) / (3.0 * mu - E);
92 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
93 const auto& E = vp_.emodul;
94 const auto& K = vp_.K;
95 return 3.0 * K * (3.0 * K - E) / (9.0 * K - E);
96 } else
97 assert(false && "Your LameParameter request is not implemented");
98 }
99
100 constexpr double toBulkModulus()
101 requires(!std::is_same_v<ValuePair, YoungsModulusAndBulkModulus> and
102 !std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>)
103 {
104 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
105 const auto& E = vp_.emodul;
106 const auto& nu = vp_.nu;
107 return E / (3.0 * (1.0 - 2.0 * nu));
108 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
109 const auto& E = vp_.emodul;
110 const auto& mu = vp_.mu;
111 return E * mu / (3.0 * (3.0 * mu - E));
112 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
113 const auto& E = vp_.emodul;
114 const auto& lambda = vp_.lambda;
115 return (E + 3.0 * lambda + calcR(vp_)) / 6.0;
116 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
117 const auto& lambda = vp_.lambda;
118 const auto& mu = vp_.mu;
119 return lambda + 2.0 * mu / 3.0;
120 } else
121 assert(false && "Your LameParameter request is not implemented");
122 }
123
124 constexpr double toShearModulus()
125 requires(!std::is_same_v<ValuePair, YoungsModulusAndShearModulus> and
126 !std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>)
127 {
128 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
129 const auto& E = vp_.emodul;
130 const auto& nu = vp_.nu;
131 return E / (2.0 * (1.0 + nu));
132 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
133 const auto& E = vp_.emodul;
134 const auto& K = vp_.K;
135 return 3.0 * K * E / (9.0 * K - E);
136 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
137 const auto& E = vp_.emodul;
138 const auto& lambda = vp_.lambda;
139 return (E - 3.0 * lambda + calcR(vp_)) / 4.0;
140 } else if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
141 const auto& K = vp_.K;
142 const auto& lambda = vp_.lambda;
143 return 3.0 * (K - lambda) / 2.0;
144 } else
145 assert(false && "Your LameParameter request is not implemented");
146 }
147
148 constexpr double toPWaveModulus() {
149 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
150 const auto& E = vp_.emodul;
151 const auto& nu = vp_.nu;
152 return E * (1.0 - nu) / ((1.0 + nu) * (1.0 - 2.0 * nu));
153 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
154 const auto& E = vp_.emodul;
155 const auto& mu = vp_.mu;
156 return mu * (4.0 * mu - E) / (3.0 * mu - E);
157 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
158 const auto& E = vp_.emodul;
159 const auto& K = vp_.K;
160 return 3.0 * K * (3.0 * K + E) / (9.0 * K - E);
161 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
162 const auto& E = vp_.emodul;
163 const auto& lambda = vp_.lambda;
164 return (E - lambda + calcR(vp_)) / 2.0;
165 } else if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
166 const auto& K = vp_.K;
167 const auto& lambda = vp_.lambda;
168 return 3.0 * K - 2.0 * lambda;
169 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
170 const auto& lambda = vp_.lambda;
171 const auto& mu = vp_.mu;
172 return lambda + 2.0 * mu;
173 } else
174 assert(false && "Your LameParameter request is not implemented");
175 }
176
177 constexpr double toPoissonsRatio()
178 requires(!std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>)
179 {
180 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
181 const auto& E = vp_.emodul;
182 const auto& mu = vp_.mu;
183 return E / (2.0 * mu) - 1.0;
184 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
185 const auto& E = vp_.emodul;
186 const auto& K = vp_.K;
187 return (3.0 * K - E) / (6.0 * K);
188 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
189 const auto& E = vp_.emodul;
190 const auto& lambda = vp_.lambda;
191 return 2.0 * lambda / (E + lambda + calcR(vp_));
192 } else if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
193 const auto& K = vp_.K;
194 const auto& lambda = vp_.lambda;
195 return lambda / (3 * K - lambda);
196 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
197 const auto& lambda = vp_.lambda;
198 const auto& mu = vp_.mu;
199 return lambda / (2.0 * (lambda + mu));
200 } else
201 assert(false && "Your LameParameter request is not implemented");
202 }
203
204 constexpr double toYoungsModulus()
205 requires(!std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio> and
206 !std::is_same_v<ValuePair, YoungsModulusAndShearModulus> and
207 !std::is_same_v<ValuePair, YoungsModulusAndBulkModulus> and
208 !std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>)
209 {
210 if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
211 return 9.0 * vp_.K * (vp_.K - vp_.lambda) / (3.0 * vp_.K - vp_.lambda);
212 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
213 const auto& lambda = vp_.lambda;
214 const auto& mu = vp_.mu;
215 return mu * (3.0 * lambda + 2.0 * mu) / (lambda + mu);
216 } else
217 assert(false && "Your LameParameter request is not implemented");
218 }
219
220private:
222 const YoungsModulusAndPoissonsRatio& valuePair);
224 const YoungsModulusAndShearModulus& valuePair);
225
227 const YoungsModulusAndBulkModulus& valuePair);
228
230 const LamesFirstParameterAndShearModulus& valuePair);
231
233 const BulkModulusAndLamesFirstParameter& valuePair);
234
236 const YoungsModulusAndLamesFirstParameter& valuePair);
237
238 ConvertLameConstants(ValuePair&& valuePair)
239 : vp_(valuePair) {}
240 ConvertLameConstants(const ValuePair& valuePair)
241 : vp_(valuePair) {}
242
243 double calcR(const YoungsModulusAndLamesFirstParameter& valuePair) {
244 const auto& E = valuePair.emodul;
245 const auto& lambda = valuePair.lambda;
246 return std::sqrt(E * E + 9 * lambda * lambda + 2 * E * lambda);
247 }
248 ValuePair vp_;
249};
251 const YoungsModulusAndPoissonsRatio& valuePair) {
252 return {valuePair};
253}
255 const YoungsModulusAndShearModulus& valuePair) {
256 return {valuePair};
257}
259 const YoungsModulusAndBulkModulus& valuePair) {
260 return {valuePair};
261}
263 const LamesFirstParameterAndShearModulus& valuePair) {
264 return {valuePair};
265}
267 const BulkModulusAndLamesFirstParameter& valuePair) {
268 return {valuePair};
269}
271 const YoungsModulusAndLamesFirstParameter& valuePair) {
272 return {valuePair};
273}
274
282 auto lambda = convertLameConstants(matParameter).toLamesFirstParameter();
283 auto mu = convertLameConstants(matParameter).toShearModulus();
284
285 return LamesFirstParameterAndShearModulus{.lambda = lambda, .mu = mu};
286}
287
295 auto emod = convertLameConstants(matParameter).toYoungsModulus();
296 auto nu = convertLameConstants(matParameter).toPoissonsRatio();
297
298 return YoungsModulusAndPoissonsRatio{.emodul = emod, .nu = nu};
299}
300
301} // namespace Ikarus
Definition: assemblermanipulatorbuildingblocks.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:281
auto toYoungsModulusAndPoissonsRatio(const LamesFirstParameterAndShearModulus &matParameter)
Converts Lame's first parameter and shear modulus to Young's modulus and Poisson's ratio.
Definition: physicshelper.hh:294
ConvertLameConstants< YoungsModulusAndPoissonsRatio > convertLameConstants(const YoungsModulusAndPoissonsRatio &valuePair)
Definition: physicshelper.hh:250
see https://en.wikipedia.org/wiki/Lam%C3%A9_parameters Structure representing Young's modulus and she...
Definition: physicshelper.hh:19
double emodul
Definition: physicshelper.hh:20
double nu
Definition: physicshelper.hh:21
Structure representing Young's modulus and bulk modulus.
Definition: physicshelper.hh:26
double mu
Definition: physicshelper.hh:28
double emodul
Definition: physicshelper.hh:27
Structure representing Young's modulus and Lame's first parameter.
Definition: physicshelper.hh:33
double emodul
Definition: physicshelper.hh:34
double K
Definition: physicshelper.hh:35
Structure representing bulk modulus and Lame's first parameter.
Definition: physicshelper.hh:40
double lambda
Definition: physicshelper.hh:42
double emodul
Definition: physicshelper.hh:41
Structure representing Lame's first parameter and shear modulus.
Definition: physicshelper.hh:47
double K
Definition: physicshelper.hh:48
double lambda
Definition: physicshelper.hh:49
Definition: physicshelper.hh:54
double lambda
Definition: physicshelper.hh:55
double mu
Definition: physicshelper.hh:56
Conversion utility for Lame's constants.
Definition: physicshelper.hh:77
constexpr double toYoungsModulus()
Definition: physicshelper.hh:204
constexpr double toBulkModulus()
Definition: physicshelper.hh:100
constexpr double toPoissonsRatio()
Definition: physicshelper.hh:177
friend ConvertLameConstants< YoungsModulusAndPoissonsRatio > convertLameConstants(const YoungsModulusAndPoissonsRatio &valuePair)
Definition: physicshelper.hh:250
constexpr double toLamesFirstParameter()
Definition: physicshelper.hh:78
constexpr double toPWaveModulus()
Definition: physicshelper.hh:148
constexpr double toShearModulus()
Definition: physicshelper.hh:124
Concept for checking if a type is a valid material parameter tuple.
Definition: physicshelper.hh:65