GCC Code Coverage Report


Directory: ./
File: Hyperelasticity/invariants.cpp
Date: 2024-04-14 07:32:34
Exec Total Coverage
Lines: 78 164 47.6%
Branches: 41 228 18.0%

Line Branch Exec Source
1 // ______ ______ _ _ _____ ______
2 // | ____| ____| | (_)/ ____| | ____|
3 // | |__ | |__ | | _| (___ ___| |__
4 // | __| | __| | | | |\___ \ / __| __|
5 // | | | |____| |____| |____) | (__| |____
6 // |_| |______|______|_|_____/ \___|______|
7 // Finite Elements for Life Sciences and Engineering
8 //
9 // License: LGL2.1 License
10 // FELiScE default license: LICENSE in root folder
11 //
12 // Main authors: S. Gilles
13 //
14
15 // System includes
16
17 // External includes
18
19 // Project includes
20 #include "Core/felisce.hpp"
21 #include "Hyperelasticity/invariants.hpp"
22
23 namespace felisce::Invariants {
24
25 namespace { // anonymous
26
27 564 UBlasMatrix InitMatrixSecondDerivativeInvariant2_3D()
28 {
29 564 UBlasMatrix ret(6, 6);
30
1/2
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
564 ret.clear();
31
32 // [0, 1, 1, 0 , 0 , 0 ],
33 // [1, 0, 1, 0 , 0 , 0 ],
34 // [1, 1, 0, 0 , 0 , 0 ],
35 // [0, 0, 0, -0.5, 0 , 0 ],
36 // [0, 0, 0, 0 , -0.5, 0 ],
37 // [0, 0, 0, 0 , 0 , -0.5]
38
39
3/6
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 564 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 564 times.
✗ Branch 8 not taken.
564 ret(3, 3) = ret(4, 4) = ret(5, 5) = -.5;
40
41
2/2
✓ Branch 0 taken 1692 times.
✓ Branch 1 taken 564 times.
2256 for (std::size_t i = 0; i < 3; ++i)
42
2/2
✓ Branch 0 taken 1692 times.
✓ Branch 1 taken 1692 times.
3384 for (std::size_t j = i + 1; j < 3; ++j)
43
2/4
✓ Branch 1 taken 1692 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1692 times.
✗ Branch 5 not taken.
1692 ret(i, j) = ret(j, i) = 1.;
44
45 564 return ret;
46 }
47
48 // Constant matrix obtained for second derivative of invariant 2 in 3D case
49 static const UBlasMatrix MatrixSecondDerivativeInvariant2_3D = std::move(InitMatrixSecondDerivativeInvariant2_3D());
50
51 564 UBlasMatrix InitMatrixSecondDerivativeInvariant23_2D()
52 {
53 564 UBlasMatrix ret(3, 3);
54
1/2
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
564 ret.clear();
55
56 // [0, 1, 0]
57 // [1, 0, 0]
58 // [0, 0, -0.5]
59
60
1/2
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
564 ret(2, 2) = -0.5;
61
2/4
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 564 times.
✗ Branch 5 not taken.
564 ret(0, 1) = ret(1, 0) = 1.;
62
63 564 return ret;
64 }
65
66 // Constant matrix obtained for second derivative of invariant 2 and 3 in 2D case
67 static const UBlasMatrix MatrixSecondDerivativeInvariant23_2D = std::move(InitMatrixSecondDerivativeInvariant23_2D());
68
69 564 UBlasVector InitVectorFirstDerivativeInvariant1_2D()
70 {
71 564 UBlasVector ret(3);
72
1/2
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
564 ret(0) = 1.;
73
1/2
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
564 ret(1) = 1.;
74
1/2
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
564 ret(2) = 0.;
75 564 return ret;
76 }
77
78 static const UBlasVector VectorFirstDerivativeInvariant1_2D = std::move(InitVectorFirstDerivativeInvariant1_2D());
79
80 564 UBlasVector InitVectorFirstDerivativeInvariant1_3D()
81 {
82 564 UBlasVector ret(6);
83
1/2
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
564 ret.clear();
84
1/2
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
564 ret(0) = 1.;
85
1/2
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
564 ret(1) = 1.;
86
1/2
✓ Branch 1 taken 564 times.
✗ Branch 2 not taken.
564 ret(2) = 1.;
87 564 return ret;
88 }
89
90 static const UBlasVector VectorFirstDerivativeInvariant1_3D = std::move(InitVectorFirstDerivativeInvariant1_3D());
91
92 template<int SizeT>
93 2256 UBlasMatrix InitEmptyMatrix() {
94 2256 UBlasMatrix ret(SizeT, SizeT);
95
1/2
✓ Branch 1 taken 1128 times.
✗ Branch 2 not taken.
2256 ret.clear();
96 2256 return ret;
97 }
98
99 static const UBlasMatrix EmptyMatrix_2D = std::move(InitEmptyMatrix<3>());
100 static const UBlasMatrix EmptyMatrix_3D = std::move(InitEmptyMatrix<6>());
101
102 } // namespace anonymous
103
104 /***********************************************************************************/
105 /***********************************************************************************/
106
107 4734000 double CauchyGreenTensor2D::xx() const
108 {
109 4734000 return m_components[0];
110 }
111
112 /***********************************************************************************/
113 /***********************************************************************************/
114
115 double CauchyGreenTensor3D::xx() const
116 {
117 return m_components[0];
118 }
119
120 /***********************************************************************************/
121 /***********************************************************************************/
122
123 4734000 double CauchyGreenTensor2D::yy() const
124 {
125 4734000 return m_components[1];
126 }
127
128 /***********************************************************************************/
129 /***********************************************************************************/
130
131 double CauchyGreenTensor3D::yy() const
132 {
133 return m_components[1];
134 }
135
136 /***********************************************************************************/
137 /***********************************************************************************/
138
139 double CauchyGreenTensor3D::zz() const
140 {
141 return m_components[2];
142 }
143
144 /***********************************************************************************/
145 /***********************************************************************************/
146
147 3156000 double CauchyGreenTensor2D::xy() const
148 {
149 3156000 return m_components[2];
150 }
151
152 /***********************************************************************************/
153 /***********************************************************************************/
154
155 double CauchyGreenTensor3D::xy() const
156 {
157 return m_components[3];
158 }
159
160 /***********************************************************************************/
161 /***********************************************************************************/
162
163 double CauchyGreenTensor3D::yz() const {
164 return m_components[4];
165 }
166
167 /***********************************************************************************/
168 /***********************************************************************************/
169
170 double CauchyGreenTensor3D::xz() const {
171 return m_components[5];
172 }
173
174 /***********************************************************************************/
175 /***********************************************************************************/
176
177 1578000 double Invariant1(const CauchyGreenTensor2D& tensor)
178 {
179 1578000 return tensor.xx() + tensor.yy() + 1.;
180 }
181
182 /***********************************************************************************/
183 /***********************************************************************************/
184
185 double Invariant1(const CauchyGreenTensor3D& tensor)
186 {
187 return tensor.xx() + tensor.yy() + tensor.zz();
188 }
189
190 /***********************************************************************************/
191 /***********************************************************************************/
192
193 1578000 double Invariant2(const CauchyGreenTensor2D& tensor)
194 {
195 1578000 const auto& r_components = tensor.components();
196
197 1578000 return r_components[0] * r_components[1] + r_components[0] + r_components[1] - std::pow(r_components[2], 2);
198 }
199
200 /***********************************************************************************/
201 /***********************************************************************************/
202
203 double Invariant2(const CauchyGreenTensor3D& tensor)
204 {
205 const auto& r_components = tensor.components();
206
207 return r_components[0] * r_components[1] + r_components[1] * r_components[2] + r_components[0] * r_components[2] - std::pow(r_components[3], 2) - std::pow(r_components[5], 2) - std::pow(r_components[4], 2);
208 }
209
210 /***********************************************************************************/
211 /***********************************************************************************/
212
213 1578000 double Invariant3(const CauchyGreenTensor2D& tensor)
214 {
215 1578000 return tensor.xx() * tensor.yy() - std::pow(tensor.xy(), 2);
216 }
217
218 /***********************************************************************************/
219 /***********************************************************************************/
220
221 double Invariant3(const CauchyGreenTensor3D& tensor)
222 {
223 const auto& r_components = tensor.components();
224
225 return r_components[0] * r_components[1] * r_components[2] - r_components[0] * std::pow(r_components[4], 2) - r_components[1] * std::pow(r_components[5], 2) - r_components[2] * std::pow(r_components[3], 2) + 2. * r_components[3] * r_components[4] * r_components[5];
226 }
227
228 /***********************************************************************************/
229 /***********************************************************************************/
230
231 1578000 CauchyGreenTensor2D::CauchyGreenTensor2D(
232 const UBlasVector& gradient_component_dispx,
233 const UBlasVector& gradient_component_dispy
234 1578000 )
235 {
236 std::array<double, 3> components;
237
238 // Component Cxx
239
1/2
✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
1578000 components[0] = 1. + 2. * gradient_component_dispx[0]
240
1/2
✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
1578000 + std::pow(gradient_component_dispx[0], 2)
241
1/2
✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
1578000 + std::pow(gradient_component_dispy[0], 2);
242
243 // Component Cyy
244
1/2
✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
1578000 components[1] = 1. + 2. * gradient_component_dispy[1]
245
1/2
✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
1578000 + std::pow(gradient_component_dispx[1], 2)
246
1/2
✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
1578000 + std::pow(gradient_component_dispy[1], 2);
247
248 // Component Cxy
249
2/4
✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
1578000 components[2] = gradient_component_dispx[1] + gradient_component_dispy[0]
250
2/4
✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
1578000 + gradient_component_dispx[0] * gradient_component_dispx[1]
251
2/4
✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
1578000 + gradient_component_dispy[0] * gradient_component_dispy[1];
252
253 1578000 SetComponents(std::move(components));
254 1578000 }
255
256 /***********************************************************************************/
257 /***********************************************************************************/
258
259 CauchyGreenTensor3D::CauchyGreenTensor3D(const UBlasVector& gradient_component_dispx,
260 const UBlasVector& gradient_component_dispy,
261 const UBlasVector& gradient_component_dispz
262 )
263 {
264
265 std::array<double, 6> components;
266
267 // Component Cxx
268 components[0] = 1. + 2. * gradient_component_dispx[0]
269 + std::pow(gradient_component_dispx[0], 2)
270 + std::pow(gradient_component_dispy[0], 2)
271 + std::pow(gradient_component_dispz[0], 2);
272
273 // Component Cyy
274 components[1] = 1. + 2. * gradient_component_dispy[1]
275 + std::pow(gradient_component_dispx[1], 2)
276 + std::pow(gradient_component_dispy[1], 2)
277 + std::pow(gradient_component_dispz[1], 2);
278
279 // Component Czz
280 components[2] = 1. + 2. * gradient_component_dispz[2]
281 + std::pow(gradient_component_dispx[2], 2)
282 + std::pow(gradient_component_dispy[2], 2)
283 + std::pow(gradient_component_dispz[2], 2);
284
285 // Component Cxy
286 components[3] = gradient_component_dispx[1] + gradient_component_dispy[0]
287 + gradient_component_dispx[0] * gradient_component_dispx[1]
288 + gradient_component_dispy[0] * gradient_component_dispy[1]
289 + gradient_component_dispz[0] * gradient_component_dispz[1];
290
291 // Component Cyz
292 components[4] = gradient_component_dispy[2] + gradient_component_dispz[1]
293 + gradient_component_dispx[2] * gradient_component_dispx[1]
294 + gradient_component_dispy[2] * gradient_component_dispy[1]
295 + gradient_component_dispz[2] * gradient_component_dispz[1];
296
297 // Component Cxz
298 components[5] = gradient_component_dispz[0] + gradient_component_dispx[2]
299 + gradient_component_dispx[2] * gradient_component_dispx[0]
300 + gradient_component_dispy[2] * gradient_component_dispy[0]
301 + gradient_component_dispz[2] * gradient_component_dispz[0];
302
303 SetComponents(std::move(components));
304 }
305
306 /***********************************************************************************/
307 /***********************************************************************************/
308
309 1578000 UBlasVector FirstDerivativeInvariant1CauchyGreen(const CauchyGreenTensor2D& )
310 {
311 1578000 return VectorFirstDerivativeInvariant1_2D;
312 }
313
314 /***********************************************************************************/
315 /***********************************************************************************/
316
317 UBlasVector FirstDerivativeInvariant1CauchyGreen(const CauchyGreenTensor3D& )
318 {
319 return VectorFirstDerivativeInvariant1_3D;
320 }
321
322 /***********************************************************************************/
323 /***********************************************************************************/
324
325 1578000 UBlasVector FirstDerivativeInvariant2CauchyGreen(const CauchyGreenTensor2D& tensor)
326 {
327 1578000 UBlasVector ret(3);
328
1/2
✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
1578000 ret(0) = tensor.yy() + 1.;
329
1/2
✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
1578000 ret(1) = tensor.xx() + 1.;
330
1/2
✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
1578000 ret(2) = -tensor.xy();
331 1578000 return ret;
332 }
333
334 /***********************************************************************************/
335 /***********************************************************************************/
336
337 UBlasVector FirstDerivativeInvariant2CauchyGreen(const CauchyGreenTensor3D& tensor)
338 {
339 UBlasVector ret(6);
340 ret.clear();
341
342 const auto& r_components = tensor.components();
343
344 ret(0) = r_components[1] + r_components[2];
345 ret(1) = r_components[0] + r_components[2];
346 ret(2) = r_components[0] + r_components[1];
347 ret(3) = -r_components[3];
348 ret(4) = -r_components[4];
349 ret(5) = -r_components[5];
350
351 return ret;
352 }
353
354 /***********************************************************************************/
355 /***********************************************************************************/
356
357 1578000 UBlasVector FirstDerivativeInvariant3CauchyGreen(const CauchyGreenTensor2D& tensor) {
358
1/2
✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
1578000 UBlasVector ret(3);
359
360 1578000 const auto& r_components = tensor.components();
361
362
1/2
✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
1578000 ret(0) = r_components[1];
363
1/2
✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
1578000 ret(1) = r_components[0];
364
1/2
✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
1578000 ret(2) = -r_components[2];
365
366 3156000 return ret;
367 }
368
369 /***********************************************************************************/
370 /***********************************************************************************/
371
372 UBlasVector FirstDerivativeInvariant3CauchyGreen(const CauchyGreenTensor3D& tensor)
373 {
374 UBlasVector ret(6);
375 ret.clear();
376
377 const auto& r_components = tensor.components();
378
379 ret(0) = r_components[1] * r_components[2] - std::pow(r_components[4], 2);
380 ret(1) = r_components[0] * r_components[2] - std::pow(r_components[5], 2);
381 ret(2) = r_components[0] * r_components[1] - std::pow(r_components[3], 2);
382 ret(3) = r_components[4] * r_components[5] - r_components[2] * r_components[3];
383 ret(4) = r_components[3] * r_components[5] - r_components[0] * r_components[4];
384 ret(5) = r_components[3] * r_components[4] - r_components[1] * r_components[5];
385
386 return ret;
387 }
388
389 /***********************************************************************************/
390 /***********************************************************************************/
391
392 1578000 UBlasMatrix SecondDerivativeInvariant1CauchyGreen(const CauchyGreenTensor2D& )
393 {
394 1578000 return EmptyMatrix_2D;
395 }
396
397 /***********************************************************************************/
398 /***********************************************************************************/
399
400 UBlasMatrix SecondDerivativeInvariant1CauchyGreen(const CauchyGreenTensor3D& )
401 {
402 return EmptyMatrix_3D;
403 }
404
405 /***********************************************************************************/
406 /***********************************************************************************/
407
408 1578000 UBlasMatrix SecondDerivativeInvariant2CauchyGreen(const CauchyGreenTensor2D& )
409 {
410 1578000 return MatrixSecondDerivativeInvariant23_2D;
411 }
412
413 /***********************************************************************************/
414 /***********************************************************************************/
415
416 UBlasMatrix SecondDerivativeInvariant2CauchyGreen(const CauchyGreenTensor3D& )
417 {
418 return MatrixSecondDerivativeInvariant2_3D;
419 }
420
421 /***********************************************************************************/
422 /***********************************************************************************/
423
424 1578000 UBlasMatrix SecondDerivativeInvariant3CauchyGreen(const CauchyGreenTensor2D&)
425 {
426 1578000 return MatrixSecondDerivativeInvariant23_2D;
427 }
428
429
430 /***********************************************************************************/
431 /***********************************************************************************/
432
433 UBlasMatrix SecondDerivativeInvariant3CauchyGreen(const CauchyGreenTensor3D& tensor)
434 {
435 UBlasMatrix ret(6, 6);
436 ret.clear();
437
438 // [0 , Czz , Cyy , 0 , -Cyz , 0 ],
439 // [Czz , 0 , Cxx , 0 , 0 , -Cxz ],
440 // [Cyy , Cxx , 0 , -Cxy , 0 , 0 ],
441 // [0 , 0 , -Cxy , -0.5*Czz , 0.5*Cxz , 0.5*Cyz ],
442 // [-Cyz , 0 , 0 , 0.5*Cxz , -0.5*Cxx , 0.5*Cxy ],
443 // [0 , -Cxz , 0 , 0.5*Cyz , 0.5*Cxy , -0.5*Cyy ]
444
445 const auto& r_components = tensor.components();
446
447 ret(3, 3) = -0.5 * r_components[2];
448 ret(4, 4) = -0.5 * r_components[0];
449 ret(5, 5) = -0.5 * r_components[1];
450
451 ret(1, 0) = ret(0, 1) = r_components[2];
452 ret(2, 0) = ret(0, 2) = r_components[1];
453 ret(1, 2) = ret(2, 1) = r_components[0];
454
455 ret(0, 4) = ret(4, 0) = -r_components[4];
456 ret(1, 5) = ret(5, 1) = -r_components[5];
457 ret(2, 3) = ret(3, 2) = -r_components[3];
458
459 ret(3, 4) = ret(4, 3) = 0.5 * r_components[5];
460 ret(3, 5) = ret(5, 3) = 0.5 * r_components[4];
461 ret(5, 4) = ret(4, 5) = 0.5 * r_components[3];
462
463 return ret;
464 }
465
466 } // namespace felisce
467