version 0.4
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>
14
16namespace Ikarus {
17
26 [[deprecated(
27 "These are hard-coded function you should use the material library Ikarus::LinearElasticity")]] inline Eigen::
28 Matrix3d
30 Eigen::Matrix3d C;
31 C.setZero();
32 C(0, 0) = C(1, 1) = 1;
33 C(0, 1) = C(1, 0) = nu;
34 C(2, 2) = (1 - nu) / 2;
35 C *= E / (1 - nu * nu);
36 return C;
37 }
38
47 [[deprecated(
48 "These are hard-coded function you should use the material library: Ikarus::LinearElasticity")]] inline Eigen::
49 Matrix<double, 6, 6>
50 linearElasticMaterialTangent3D(double E, double nu) {
51 Eigen::Matrix<double, 6, 6> C;
52 C.setZero();
53 C(0, 0) = C(1, 1) = C(2, 2) = 1 - nu;
54 C(0, 1) = C(1, 0) = C(2, 0) = C(0, 2) = C(1, 2) = C(2, 1) = nu;
55 C(3, 3) = C(4, 4) = C(5, 5) = (1 - 2 * nu) / 2;
56 C *= E / ((1 + nu) * (1 - 2 * nu));
57 return C;
58 }
59
67 template <typename Basis_, typename FERequirements_, bool useRef = false>
68 struct TraitsFromFE {
70 using Basis = Basis_;
71
73 using FERequirementType = FERequirements_;
74
77
79 using FlatBasis = typename Basis::FlatBasis;
80
82 using LocalView = typename FlatBasis::LocalView;
83
85 using GridView = typename FlatBasis::GridView;
86
88 using Element = typename LocalView::Element;
89
91 using Geometry = typename Element::Geometry;
92
94 static constexpr int worlddim = Element::Geometry::coorddimension;
95
97 static constexpr int mydim = Element::mydimension;
98
100 static constexpr int dimension = Element::dimension;
101
103 template <typename ScalarType = double>
104 using VectorType = std::conditional_t<useRef, Eigen::Ref<Eigen::VectorX<ScalarType>>, Eigen::VectorX<ScalarType>&>;
105
107 template <typename ScalarType = double>
108 using MatrixType = std::conditional_t<useRef, Eigen::Ref<Eigen::MatrixX<ScalarType>>, Eigen::MatrixX<ScalarType>&>;
109 };
110
114 double emodul;
115 double nu;
116 };
117
120 double emodul;
121 double mu;
122 };
123
126 double emodul;
127 double K;
128 };
129
132 double emodul;
133 double lambda;
134 };
135
138 double K;
139 double lambda;
140 };
141
144 double lambda;
145 double mu;
146 };
147
153 template <typename MaterialParameter>
154 concept MaterialParameterTuple = std::is_same_v<MaterialParameter, YoungsModulusAndPoissonsRatio> or std::is_same_v<
155 MaterialParameter, YoungsModulusAndBulkModulus> or std::is_same_v<MaterialParameter,
156 YoungsModulusAndLamesFirstParameter> or std::
157 is_same_v<MaterialParameter, BulkModulusAndLamesFirstParameter> or std::is_same_v<
158 MaterialParameter, LamesFirstParameterAndShearModulus> or std::is_same_v<MaterialParameter,
159 YoungsModulusAndShearModulus>;
160
166 template <typename ValuePair>
168 constexpr double toLamesFirstParameter() requires(
169 !std::is_same_v<
170 ValuePair,
171 YoungsModulusAndLamesFirstParameter> and !std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter> and !std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
172 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
173 const auto& E = vp.emodul;
174 const auto& nu = vp.nu;
175 return Dune::FloatCmp::eq(nu, 0.5) ? std::numeric_limits<double>::infinity()
176 : E * nu / ((1.0 + nu) * (1.0 - 2.0 * nu));
177 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
178 const auto& E = vp.emodul;
179 const auto& mu = vp.mu;
180 return mu * (E - 2.0 * mu) / (3.0 * mu - E);
181 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
182 const auto& E = vp.emodul;
183 const auto& K = vp.K;
184 return 3.0 * K * (3.0 * K - E) / (9.0 * K - E);
185 } else
186 assert(false && "Your LameParameter request is not implemented");
187 }
188
189 constexpr double toBulkModulus() requires(
190 !std::is_same_v<
191 ValuePair, YoungsModulusAndBulkModulus> and !std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
192 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
193 const auto& E = vp.emodul;
194 const auto& nu = vp.nu;
195 return E / (3.0 * (1.0 - 2.0 * nu));
196 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
197 const auto& E = vp.emodul;
198 const auto& mu = vp.mu;
199 return E * mu / (3.0 * (3.0 * mu - E));
200 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
201 const auto& E = vp.emodul;
202 const auto& lambda = vp.lambda;
203 return (E + 3.0 * lambda + calcR(vp)) / 6.0;
204 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
205 const auto& lambda = vp.lambda;
206 const auto& mu = vp.mu;
207 return lambda + 2.0 * mu / 3.0;
208 } else
209 assert(false && "Your LameParameter request is not implemented");
210 }
211
212 constexpr double toShearModulus() requires(
213 !std::is_same_v<
214 ValuePair,
215 YoungsModulusAndShearModulus> and !std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
216 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
217 const auto& E = vp.emodul;
218 const auto& nu = vp.nu;
219 return E / (2.0 * (1.0 + nu));
220 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
221 const auto& E = vp.emodul;
222 const auto& K = vp.K;
223 return 3.0 * K * E / (9.0 * K - E);
224 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
225 const auto& E = vp.emodul;
226 const auto& lambda = vp.lambda;
227 return (E - 3.0 * lambda + calcR(vp)) / 4.0;
228 } else if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
229 const auto& K = vp.K;
230 const auto& lambda = vp.lambda;
231 return 3.0 * (K - lambda) / 2.0;
232 } else
233 assert(false && "Your LameParameter request is not implemented");
234 }
235
236 constexpr double toPWaveModulus() {
237 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
238 const auto& E = vp.emodul;
239 const auto& nu = vp.nu;
240 return E * (1.0 - nu) / ((1.0 + nu) * (1.0 - 2.0 * nu));
241 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
242 const auto& E = vp.emodul;
243 const auto& mu = vp.mu;
244 return mu * (4.0 * mu - E) / (3.0 * mu - E);
245 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
246 const auto& E = vp.emodul;
247 const auto& K = vp.K;
248 return 3.0 * K * (3.0 * K + E) / (9.0 * K - E);
249 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
250 const auto& E = vp.emodul;
251 const auto& lambda = vp.lambda;
252 return (E - lambda + calcR(vp)) / 2.0;
253 } else if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
254 const auto& K = vp.K;
255 const auto& lambda = vp.lambda;
256 return 3.0 * K - 2.0 * lambda;
257 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
258 const auto& lambda = vp.lambda;
259 const auto& mu = vp.mu;
260 return lambda + 2.0 * mu;
261 } else
262 assert(false && "Your LameParameter request is not implemented");
263 }
264
265 constexpr double toPoissonsRatio() requires(!std::is_same_v<ValuePair, YoungsModulusAndPoissonsRatio>) {
266 if constexpr (std::is_same_v<ValuePair, YoungsModulusAndShearModulus>) {
267 const auto& E = vp.emodul;
268 const auto& mu = vp.mu;
269 return E / (2.0 * mu) - 1.0;
270 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndBulkModulus>) {
271 const auto& E = vp.emodul;
272 const auto& K = vp.K;
273 return (3.0 * K - E) / (6.0 * K);
274 } else if constexpr (std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
275 const auto& E = vp.emodul;
276 const auto& lambda = vp.lambda;
277 return 2.0 * lambda / (E + lambda + calcR(vp));
278 } else if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
279 const auto& K = vp.K;
280 const auto& lambda = vp.lambda;
281 return lambda / (3 * K - lambda);
282 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
283 const auto& lambda = vp.lambda;
284 const auto& mu = vp.mu;
285 return lambda / (2.0 * (lambda + mu));
286 } else
287 assert(false && "Your LameParameter request is not implemented");
288 }
289
290 constexpr double toYoungsModulus() requires(
291 !std::is_same_v<
292 ValuePair,
293 YoungsModulusAndPoissonsRatio> and !std::is_same_v<ValuePair, YoungsModulusAndShearModulus> and !std::is_same_v<ValuePair, YoungsModulusAndBulkModulus> and !std::is_same_v<ValuePair, YoungsModulusAndLamesFirstParameter>) {
294 if constexpr (std::is_same_v<ValuePair, BulkModulusAndLamesFirstParameter>) {
295 return 9.0 * vp.K * (vp.K - vp.lambda) / (3.0 * vp.K - vp.lambda);
296 } else if constexpr (std::is_same_v<ValuePair, LamesFirstParameterAndShearModulus>) {
297 const auto& lambda = vp.lambda;
298 const auto& mu = vp.mu;
299 return mu * (3.0 * lambda + 2.0 * mu) / (lambda + mu);
300 } else
301 assert(false && "Your LameParameter request is not implemented");
302 }
303
307 const YoungsModulusAndShearModulus& p_vp);
308
310 const YoungsModulusAndBulkModulus& p_vp);
311
314
317 ConvertLameConstants(ValuePair&& p_vp) : vp(p_vp) {}
318 ConvertLameConstants(const ValuePair& p_vp) : vp(p_vp) {}
319
320 double calcR(const YoungsModulusAndLamesFirstParameter& vp_) {
321 const auto& E = vp_.emodul;
322 const auto& lambda = vp_.lambda;
323 return std::sqrt(E * E + 9 * lambda * lambda + 2 * E * lambda);
324 }
325 ValuePair vp;
326 };
328 const YoungsModulusAndPoissonsRatio& p_vp) {
329 return {p_vp};
330 }
332 const YoungsModulusAndShearModulus& p_vp) {
333 return {p_vp};
334 }
336 const YoungsModulusAndBulkModulus& p_vp) {
337 return {p_vp};
338 }
341 return {p_vp};
342 }
345 return {p_vp};
346 }
347
355 auto lambda = convertLameConstants(matParameter).toLamesFirstParameter();
356 auto mu = convertLameConstants(matParameter).toShearModulus();
357
358 return LamesFirstParameterAndShearModulus{.lambda = lambda, .mu = mu};
359 }
360
368 auto emod = convertLameConstants(matParameter).toYoungsModulus();
369 auto nu = convertLameConstants(matParameter).toPoissonsRatio();
370
371 return YoungsModulusAndPoissonsRatio{.emodul = emod, .nu = nu};
372 }
373
374} // namespace Ikarus
Definition of the LinearElastic class for finite element mechanics computations.
Definition: simpleassemblers.hh:21
auto toLamesFirstParameterAndShearModulus(const YoungsModulusAndPoissonsRatio &matParameter)
Converts Young's modulus and Poisson's ratio to Lame's first parameter and shear modulus.
Definition: physicshelper.hh:354
auto toYoungsModulusAndPoissonsRatio(const LamesFirstParameterAndShearModulus &matParameter)
Converts Lame's first parameter and shear modulus to Young's modulus and Poisson's ratio.
Definition: physicshelper.hh:367
Eigen::Matrix3d planeStressLinearElasticMaterialTangent(double E, double nu)
Computes the plane stress linear elastic material tangent matrix.
Definition: physicshelper.hh:29
ConvertLameConstants< YoungsModulusAndPoissonsRatio > convertLameConstants(const YoungsModulusAndPoissonsRatio &p_vp)
Definition: physicshelper.hh:327
Eigen::Matrix< double, 6, 6 > linearElasticMaterialTangent3D(double E, double nu)
Computes the 3D linear elastic material tangent matrix.
Definition: physicshelper.hh:50
Class representing the requirements for obtaining specific results.
Definition: ferequirements.hh:405
Traits for handling finite elements.see https://en.wikipedia.org/wiki/Lam%C3%A9_parameters.
Definition: physicshelper.hh:68
std::conditional_t< useRef, Eigen::Ref< Eigen::VectorX< ScalarType > >, Eigen::VectorX< ScalarType > & > VectorType
Type of the internal forces.
Definition: physicshelper.hh:104
typename LocalView::Element Element
Type of the grid element.
Definition: physicshelper.hh:88
static constexpr int worlddim
Dimension of the world space.
Definition: physicshelper.hh:94
typename FlatBasis::LocalView LocalView
Type of the local view.
Definition: physicshelper.hh:82
typename Basis::FlatBasis FlatBasis
Type of the flat basis.
Definition: physicshelper.hh:79
Basis_ Basis
Type of the basis of the finite element.
Definition: physicshelper.hh:70
std::conditional_t< useRef, Eigen::Ref< Eigen::MatrixX< ScalarType > >, Eigen::MatrixX< ScalarType > & > MatrixType
Type of the stiffness matrix.
Definition: physicshelper.hh:108
static constexpr int mydim
Dimension of the geometry.
Definition: physicshelper.hh:97
static constexpr int dimension
Dimension of the grid.
Definition: physicshelper.hh:100
typename FlatBasis::GridView GridView
Type of the grid view.
Definition: physicshelper.hh:85
FERequirements_ FERequirementType
Type of the requirements for the finite element.
Definition: physicshelper.hh:73
typename Element::Geometry Geometry
Type of the element geometry.
Definition: physicshelper.hh:91
Structure representing Young's modulus and shear modulus.
Definition: physicshelper.hh:113
double emodul
Definition: physicshelper.hh:114
double nu
Definition: physicshelper.hh:115
Structure representing Young's modulus and bulk modulus.
Definition: physicshelper.hh:119
double mu
Definition: physicshelper.hh:121
double emodul
Definition: physicshelper.hh:120
Structure representing Young's modulus and Lame's first parameter.
Definition: physicshelper.hh:125
double emodul
Definition: physicshelper.hh:126
double K
Definition: physicshelper.hh:127
Structure representing bulk modulus and Lame's first parameter.
Definition: physicshelper.hh:131
double lambda
Definition: physicshelper.hh:133
double emodul
Definition: physicshelper.hh:132
Structure representing Lame's first parameter and shear modulus.
Definition: physicshelper.hh:137
double K
Definition: physicshelper.hh:138
double lambda
Definition: physicshelper.hh:139
Definition: physicshelper.hh:143
double lambda
Definition: physicshelper.hh:144
double mu
Definition: physicshelper.hh:145
Conversion utility for Lame's constants.
Definition: physicshelper.hh:167
constexpr double toBulkModulus()
Definition: physicshelper.hh:189
constexpr double toYoungsModulus()
Definition: physicshelper.hh:290
constexpr double toPoissonsRatio()
Definition: physicshelper.hh:265
friend ConvertLameConstants< YoungsModulusAndPoissonsRatio > convertLameConstants(const YoungsModulusAndPoissonsRatio &p_vp)
Definition: physicshelper.hh:327
constexpr double toLamesFirstParameter()
Definition: physicshelper.hh:168
constexpr double toPWaveModulus()
Definition: physicshelper.hh:236
constexpr double toShearModulus()
Definition: physicshelper.hh:212
decltype(Dune::Functions::DefaultGlobalBasis(Ikarus::flatPreBasis(std::declval< PreBasis >()))) FlatBasis
The type of the flattened basis.
Definition: utils/basis.hh:36
Concept for checking if a type is a valid material parameter tuple.
Definition: physicshelper.hh:154