Directory: | ./ |
---|---|
File: | Hyperelasticity/linearProblemHyperElasticityHelper.cpp |
Date: | 2024-04-14 07:32:34 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 44 | 104 | 42.3% |
Branches: | 45 | 264 | 17.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 | #include <cmath> | ||
17 | |||
18 | // External includes | ||
19 | |||
20 | // Project includes | ||
21 | #include "Geometry/geometricMeshRegion.hpp" | ||
22 | #include "Core/felisceTools.hpp" | ||
23 | #include "Hyperelasticity/linearProblemHyperElasticityHelper.hpp" | ||
24 | |||
25 | namespace felisce::Private::HyperElasticity | ||
26 | { | ||
27 | |||
28 | // Assign the type of force applied from the integer read in the data file | ||
29 | 24 | ForceType AssignForceType(int data_parameter) { | |
30 | // Check whether a surfacic or volumic force has been chosen | ||
31 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | switch (data_parameter) { |
32 | ✗ | case static_cast<int>(surfacic): | |
33 | ✗ | return surfacic; | |
34 | 24 | case static_cast<int>(volumic): | |
35 | 24 | return volumic; | |
36 | ✗ | default: | |
37 | ✗ | FEL_ERROR("Force applied should be either volumic or surfacic; make sure [solid] volumicOrSurfacicForce " | |
38 | "is correctly filled in your data file and encompass an acceptable value"); | ||
39 | } | ||
40 | |||
41 | ✗ | FEL_ERROR("Should never be reached; if so bug to correct in the function!!!"); | |
42 | ✗ | return volumic; // to avoid warning about missing warning | |
43 | |||
44 | } | ||
45 | |||
46 | /***********************************************************************************/ | ||
47 | /***********************************************************************************/ | ||
48 | |||
49 | 1578000 | void calculateLinearAndNonLinearMatrixAndRhs( | |
50 | HyperElasticLaw::Pointer pLaw, | ||
51 | const CurrentFiniteElement& feDisplacement, | ||
52 | const std::vector<UBlasVector>& displacementPreviousIterationPerComponent, | ||
53 | const UBlasVector& pressure_vector, | ||
54 | unsigned int quadraturePointIndex, | ||
55 | UBlasMatrix& linearPart, | ||
56 | UBlasMatrix& nonLinearPart, | ||
57 | UBlasVector& rhsPart, | ||
58 | const bool IsIncompressible | ||
59 | ) | ||
60 | { | ||
61 |
1/2✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
|
1578000 | FEL_ASSERT_LT(quadraturePointIndex, feDisplacement.numQuadraturePoint()); |
62 | 1578000 | const UBlasMatrix& dPhi = feDisplacement.dPhi[quadraturePointIndex]; // alias | |
63 | |||
64 | 1578000 | const std::size_t dimension = displacementPreviousIterationPerComponent.size(); | |
65 | |||
66 | 1578000 | double pressure = -99.; | |
67 | |||
68 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1578000 times.
|
1578000 | if (IsIncompressible) |
69 | ✗ | pressure = inner_prod(feDisplacement.phi[quadraturePointIndex], pressure_vector); | |
70 | |||
71 |
1/2✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
|
1578000 | UBlasMatrix De; |
72 | |||
73 |
1/3✓ Branch 0 taken 1578000 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
1578000 | switch(dimension) { |
74 | 1578000 | case 2: { | |
75 |
1/2✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
|
1578000 | FEL_ASSERT_EQUAL(nonLinearPart.size1(), 4); |
76 |
1/2✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
|
1578000 | FEL_ASSERT_EQUAL(nonLinearPart.size2(), 4); |
77 |
1/2✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
|
1578000 | nonLinearPart.clear(); |
78 | |||
79 |
1/2✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
|
1578000 | De.resize(3, 4); |
80 | |||
81 | 1578000 | Invariants::CauchyGreenTensor2D::Ptr cauchy_green_tensor_ptr; | |
82 | |||
83 | { | ||
84 |
1/2✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
|
1578000 | De.clear(); |
85 | |||
86 |
2/4✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1578000 times.
✗ Branch 6 not taken.
|
1578000 | const UBlasVector gradient_component_dispx = prod(dPhi, displacementPreviousIterationPerComponent[0]); |
87 |
2/4✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1578000 times.
✗ Branch 6 not taken.
|
1578000 | const UBlasVector gradient_component_dispy = prod(dPhi, displacementPreviousIterationPerComponent[1]); |
88 | |||
89 |
2/4✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
|
1578000 | De(0, 0) = 1. + gradient_component_dispx(0); |
90 |
2/4✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
|
1578000 | De(0, 2) = gradient_component_dispy(0); |
91 | |||
92 |
2/4✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
|
1578000 | De(1, 1) = gradient_component_dispx(1); |
93 |
2/4✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
|
1578000 | De(1, 3) = 1. + gradient_component_dispy(1); |
94 | |||
95 |
2/4✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
|
1578000 | De(2, 0) = gradient_component_dispx(1); |
96 |
2/4✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
|
1578000 | De(2, 1) = 1. + gradient_component_dispx(0); |
97 |
2/4✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
|
1578000 | De(2, 2) = 1. + gradient_component_dispy(1); |
98 |
2/4✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
|
1578000 | De(2, 3) = gradient_component_dispy(0); |
99 | |||
100 | cauchy_green_tensor_ptr = | ||
101 |
1/2✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
|
3156000 | Invariants::CauchyGreenTensor2D::Ptr(new Invariants::CauchyGreenTensor2D(gradient_component_dispx, |
102 |
2/4✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1578000 times.
✗ Branch 5 not taken.
|
3156000 | gradient_component_dispy)); |
103 | 1578000 | } | |
104 | |||
105 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 1578000 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1578000 | FEL_ASSERT(cauchy_green_tensor_ptr); |
106 | 1578000 | const Invariants::CauchyGreenTensor2D& cauchy_green_tensor = *cauchy_green_tensor_ptr; | |
107 | |||
108 |
1/2✓ Branch 1 taken 1578000 times.
✗ Branch 2 not taken.
|
1578000 | UBlasVector dW; |
109 |
1/2✓ Branch 2 taken 1578000 times.
✗ Branch 3 not taken.
|
1578000 | calculateLinearAndNonLinearMatrixAndRhsHelper(pLaw, cauchy_green_tensor, |
110 | pressure, | ||
111 | De, linearPart, dW, rhsPart, IsIncompressible); | ||
112 | |||
113 |
2/2✓ Branch 0 taken 3156000 times.
✓ Branch 1 taken 1578000 times.
|
4734000 | for (std::size_t i = 0; i < 2; ++i) { |
114 | 3156000 | std::size_t twice = 2 * i; | |
115 | |||
116 |
2/2✓ Branch 0 taken 6312000 times.
✓ Branch 1 taken 3156000 times.
|
9468000 | for (std::size_t iComp = 0; iComp < 2; ++iComp) |
117 |
2/4✓ Branch 1 taken 6312000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6312000 times.
✗ Branch 5 not taken.
|
6312000 | nonLinearPart(twice + iComp, twice + iComp) = dW(iComp); // Term SIGMA_xx, SIGMA_yy |
118 | |||
119 |
3/6✓ Branch 1 taken 3156000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3156000 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3156000 times.
✗ Branch 8 not taken.
|
3156000 | nonLinearPart(twice, twice + 1) = nonLinearPart(twice + 1, twice) = dW(2); // Term SIGMA_xy |
120 | } | ||
121 | |||
122 | 1578000 | break; | |
123 | 1578000 | } | |
124 | ✗ | case 3: { | |
125 | ✗ | FEL_ASSERT_EQUAL(nonLinearPart.size1(), 9); | |
126 | ✗ | FEL_ASSERT_EQUAL(nonLinearPart.size2(), 9); | |
127 | ✗ | nonLinearPart.clear(); | |
128 | |||
129 | ✗ | De.resize(6, 9); | |
130 | ✗ | Invariants::CauchyGreenTensor3D::Ptr cauchy_green_tensor_ptr; | |
131 | |||
132 | { | ||
133 | ✗ | De.clear(); | |
134 | |||
135 | ✗ | const UBlasVector gradient_component_dispx = prod(dPhi, displacementPreviousIterationPerComponent[0]); | |
136 | ✗ | const UBlasVector gradient_component_dispy = prod(dPhi, displacementPreviousIterationPerComponent[1]); | |
137 | ✗ | const UBlasVector gradient_component_dispz = prod(dPhi, displacementPreviousIterationPerComponent[2]); | |
138 | |||
139 | ✗ | De(0, 0) = 1. + gradient_component_dispx(0); | |
140 | ✗ | De(0, 3) = gradient_component_dispy(0); | |
141 | ✗ | De(0, 6) = gradient_component_dispz(0); | |
142 | |||
143 | ✗ | De(1, 1) = gradient_component_dispx(1); | |
144 | ✗ | De(1, 4) = 1. + gradient_component_dispy(1); | |
145 | ✗ | De(1, 7) = gradient_component_dispz(1); | |
146 | |||
147 | ✗ | De(2, 2) = gradient_component_dispx(2); | |
148 | ✗ | De(2, 5) = gradient_component_dispy(2); | |
149 | ✗ | De(2, 8) = 1. + gradient_component_dispz(2); | |
150 | |||
151 | ✗ | De(3, 0) = gradient_component_dispx(1); | |
152 | ✗ | De(3, 1) = 1. + gradient_component_dispx(0); | |
153 | ✗ | De(3, 3) = 1. + gradient_component_dispy(1); | |
154 | ✗ | De(3, 4) = gradient_component_dispy(0); | |
155 | ✗ | De(3, 6) = gradient_component_dispz(1); | |
156 | ✗ | De(3, 7) = gradient_component_dispz(0); | |
157 | |||
158 | ✗ | De(4, 1) = gradient_component_dispx(2); | |
159 | ✗ | De(4, 2) = gradient_component_dispx(1); | |
160 | ✗ | De(4, 4) = gradient_component_dispy(2); | |
161 | ✗ | De(4, 5) = 1. + gradient_component_dispy(1); | |
162 | ✗ | De(4, 7) = 1. + gradient_component_dispz(2); | |
163 | ✗ | De(4, 8) = gradient_component_dispz(1); | |
164 | |||
165 | ✗ | De(5, 0) = gradient_component_dispx(2); | |
166 | ✗ | De(5, 2) = 1. + gradient_component_dispx(0); | |
167 | ✗ | De(5, 3) = gradient_component_dispy(2); | |
168 | ✗ | De(5, 5) = gradient_component_dispy(0); | |
169 | ✗ | De(5, 6) = 1. + gradient_component_dispz(2); | |
170 | ✗ | De(5, 8) = gradient_component_dispz(0); | |
171 | |||
172 | cauchy_green_tensor_ptr = | ||
173 | ✗ | Invariants::CauchyGreenTensor3D::Ptr(new Invariants::CauchyGreenTensor3D(gradient_component_dispx, | |
174 | gradient_component_dispy, | ||
175 | ✗ | gradient_component_dispz)); | |
176 | } | ||
177 | |||
178 | ✗ | FEL_ASSERT(cauchy_green_tensor_ptr); | |
179 | ✗ | const Invariants::CauchyGreenTensor3D& r_cauchy_green_tensor = *cauchy_green_tensor_ptr; | |
180 | |||
181 | ✗ | UBlasVector dW; | |
182 | ✗ | calculateLinearAndNonLinearMatrixAndRhsHelper(pLaw, r_cauchy_green_tensor, | |
183 | pressure, De, | ||
184 | linearPart, dW, rhsPart, IsIncompressible); | ||
185 | |||
186 | ✗ | for (std::size_t i = 0; i < 3; ++i) { | |
187 | ✗ | const std::size_t thrice = 3 * i; | |
188 | |||
189 | ✗ | for (std::size_t iComp = 0; iComp < 3; ++iComp) | |
190 | ✗ | nonLinearPart(thrice + iComp, thrice + iComp) = dW(iComp); // Term SIGMA_xx, SIGMA_yy, SIGMA_zz | |
191 | |||
192 | ✗ | nonLinearPart(thrice, thrice + 1) = nonLinearPart(thrice + 1, thrice) = dW(3); // Term SIGMA_xy | |
193 | ✗ | nonLinearPart(thrice + 1, thrice + 2) = nonLinearPart(thrice + 2, thrice + 1) = dW(4); // Term SIGMA_yz | |
194 | ✗ | nonLinearPart(thrice, thrice + 2) = nonLinearPart(thrice + 2, thrice) = dW(5); // Term SIGMA_xz | |
195 | } | ||
196 | |||
197 | ✗ | break; | |
198 | } | ||
199 | ✗ | default: | |
200 | ✗ | FEL_ERROR("Invalid dimension; should never happen!"); | |
201 | } | ||
202 | 1578000 | } | |
203 | |||
204 | } // namespace felisce | ||
205 |