Directory: | ./ |
---|---|
File: | HyperelasticityLaws/HyperElasticLaw.cpp |
Date: | 2024-04-14 07:32:34 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 79 | 96 | 82.3% |
Branches: | 26 | 64 | 40.6% |
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 <string> | ||
17 | |||
18 | // External includes | ||
19 | |||
20 | // Project includes | ||
21 | #include "Core/felisceTools.hpp" | ||
22 | #include "Core/felisceParam.hpp" | ||
23 | #include "HyperelasticityLaws/HyperElasticLaw.hpp" | ||
24 | #include "HyperelasticityLaws/stVenantKirchhoff.hpp" | ||
25 | #include "HyperelasticityLaws/ciarletGeymonat.hpp" | ||
26 | #include "HyperelasticityLaws/Ogden.hpp" | ||
27 | |||
28 | namespace felisce | ||
29 | { | ||
30 | |||
31 | HyperElasticityLawDatabase::HyperElasticityLawDatabaseType HyperElasticityLawDatabase::DatabaseOfHyperelasticLaws = { | ||
32 | std::make_pair("StVenantKirchhoff" , felisce::make_shared<StVenantKirchhoff>()), | ||
33 | std::make_pair("CiarletGeymonat" , felisce::make_shared<CiarletGeymonat>()), | ||
34 | std::make_pair("Ogden" , felisce::make_shared<Ogden>()) | ||
35 | }; | ||
36 | |||
37 | /***********************************************************************************/ | ||
38 | /***********************************************************************************/ | ||
39 | |||
40 | ✗ | ErrorInvalidParameter::ErrorInvalidParameter(std::bitset<3> parametersStatus) | |
41 | { | ||
42 | ✗ | std::ostringstream oconv; | |
43 | ✗ | oconv << "The following parameters were not properly set in the input parameters file (in [solid]): "; | |
44 | |||
45 | // Aesthetic note: I don't like to put a condition on a single line, but XCode seems lost with indent otherwise. | ||
46 | ✗ | if (parametersStatus[0]) { | |
47 | ✗ | oconv << "poisson "; | |
48 | } | ||
49 | ✗ | if (parametersStatus[1]) { | |
50 | ✗ | oconv << "young "; | |
51 | } | ||
52 | ✗ | if (parametersStatus[2]) { | |
53 | ✗ | oconv << "bulk"; | |
54 | } | ||
55 | |||
56 | ✗ | m_message = oconv.str(); | |
57 | } | ||
58 | |||
59 | /***********************************************************************************/ | ||
60 | /***********************************************************************************/ | ||
61 | |||
62 | ✗ | const char* ErrorInvalidParameter::what() const noexcept | |
63 | { | ||
64 | ✗ | return m_message.c_str(); | |
65 | } | ||
66 | |||
67 | /***********************************************************************************/ | ||
68 | /***********************************************************************************/ | ||
69 | |||
70 | ✗ | const char* ErrorUninitializedHyperElasticLaw::what() const noexcept | |
71 | { | ||
72 | return "HyperelasticLaw was not correctly initialised; make sure Young modulus, Poisson coefficient, " | ||
73 | " dimension, hyperelasticity bulk and so forth were properly initialized (through InitParameters() and " | ||
74 | ✗ | " SetInvariants())."; | |
75 | } | ||
76 | |||
77 | /***********************************************************************************/ | ||
78 | /***********************************************************************************/ | ||
79 | |||
80 | ✗ | ErrorUninitializedHyperElasticLaw::~ErrorUninitializedHyperElasticLaw() noexcept | |
81 | = default; | ||
82 | |||
83 | /***********************************************************************************/ | ||
84 | /***********************************************************************************/ | ||
85 | |||
86 | 1738 | HyperElasticLaw::HyperElasticLaw() | |
87 | 1738 | : m_bulk(1.e20) | |
88 | { | ||
89 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1738 times.
|
1738 | FEL_ASSERT(m_isInitialised.none()); // standard should initialise bitset with all bits unset |
90 | 1738 | } | |
91 | |||
92 | /***********************************************************************************/ | ||
93 | /***********************************************************************************/ | ||
94 | |||
95 | 86 | void HyperElasticLaw::InitParameters() | |
96 | { | ||
97 | 86 | m_bulk = FelisceParam::instance().hyperelastic_bulk; | |
98 | 86 | m_isInitialised.set(1); // index_kappaAndBulk_ | |
99 | 86 | } | |
100 | |||
101 | /***********************************************************************************/ | ||
102 | /***********************************************************************************/ | ||
103 | |||
104 | 11821702 | void HyperElasticLaw::checkInitDone() const | |
105 | { | ||
106 | 11821702 | FEL_ASSERT_EQUAL(m_invariants.size(), 3); | |
107 | |||
108 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 11821702 times.
|
11821702 | if (!m_isInitialised.all()) { |
109 | ✗ | throw ErrorUninitializedHyperElasticLaw(); | |
110 | } | ||
111 | 11821702 | } | |
112 | |||
113 | /***********************************************************************************/ | ||
114 | /***********************************************************************************/ | ||
115 | |||
116 | 11 | double HyperElasticLaw::W() const | |
117 | { | ||
118 | 11 | checkInitDone(); | |
119 | 11 | return 0.0; | |
120 | } | ||
121 | |||
122 | /***********************************************************************************/ | ||
123 | /***********************************************************************************/ | ||
124 | |||
125 | 1580275 | double HyperElasticLaw::FirstDerivativeWFirstInvariant() const { | |
126 | 1580275 | checkInitDone(); | |
127 | 1580275 | return 0.0; | |
128 | } | ||
129 | |||
130 | /***********************************************************************************/ | ||
131 | /***********************************************************************************/ | ||
132 | |||
133 | 1580278 | double HyperElasticLaw::FirstDerivativeWSecondInvariant() const | |
134 | { | ||
135 | 1580278 | checkInitDone(); | |
136 | 1580278 | return 0.0; | |
137 | } | ||
138 | |||
139 | /***********************************************************************************/ | ||
140 | /***********************************************************************************/ | ||
141 | |||
142 | 1580277 | double HyperElasticLaw::FirstDerivativeWThirdInvariant() const | |
143 | { | ||
144 | 1580277 | checkInitDone(); | |
145 | 1580277 | return 0.0; | |
146 | } | ||
147 | |||
148 | /***********************************************************************************/ | ||
149 | /***********************************************************************************/ | ||
150 | |||
151 | 782273 | double HyperElasticLaw::SecondDerivativeWFirstInvariant() const | |
152 | { | ||
153 | 782273 | checkInitDone(); | |
154 | 782273 | return 0.0; | |
155 | } | ||
156 | |||
157 | /***********************************************************************************/ | ||
158 | /***********************************************************************************/ | ||
159 | |||
160 | 782272 | double HyperElasticLaw::SecondDerivativeWSecondInvariant() const | |
161 | { | ||
162 | 782272 | checkInitDone(); | |
163 | 782272 | return 0.0; | |
164 | } | ||
165 | |||
166 | /***********************************************************************************/ | ||
167 | /***********************************************************************************/ | ||
168 | |||
169 | 1580277 | double HyperElasticLaw::SecondDerivativeWThirdInvariant() const | |
170 | { | ||
171 | 1580277 | checkInitDone(); | |
172 | 1580277 | return 0.0; | |
173 | } | ||
174 | |||
175 | /***********************************************************************************/ | ||
176 | /***********************************************************************************/ | ||
177 | |||
178 | 1578009 | double HyperElasticLaw::SecondDerivativeWFirstAndThirdInvariant() const | |
179 | { | ||
180 | 1578009 | checkInitDone(); | |
181 | 1578009 | return 0.0; | |
182 | } | ||
183 | |||
184 | /***********************************************************************************/ | ||
185 | /***********************************************************************************/ | ||
186 | |||
187 | 1578009 | double HyperElasticLaw::SecondDerivativeWSecondAndThirdInvariant() const | |
188 | { | ||
189 | 1578009 | checkInitDone(); | |
190 | 1578009 | return 0.0; | |
191 | } | ||
192 | |||
193 | /***********************************************************************************/ | ||
194 | /***********************************************************************************/ | ||
195 | |||
196 | 780006 | double HyperElasticLaw::SecondDerivativeWFirstAndSecondInvariant() const | |
197 | { | ||
198 | 780006 | checkInitDone(); | |
199 | 780006 | return 0.0; | |
200 | } | ||
201 | |||
202 | /***********************************************************************************/ | ||
203 | /***********************************************************************************/ | ||
204 | |||
205 | 5 | double HyperElasticLaw::Wc(const double pressure) const | |
206 | { | ||
207 | IGNORE_UNUSED_ARGUMENT(pressure); | ||
208 | 5 | checkInitDone(); | |
209 | 5 | return 0.0; | |
210 | } | ||
211 | |||
212 | /***********************************************************************************/ | ||
213 | /***********************************************************************************/ | ||
214 | |||
215 | 5 | double HyperElasticLaw::FirstDerivativeWcThirdInvariant(const double pressure) const | |
216 | { | ||
217 | IGNORE_UNUSED_ARGUMENT(pressure); | ||
218 | 5 | checkInitDone(); | |
219 | 5 | return 0.0; | |
220 | } | ||
221 | |||
222 | /***********************************************************************************/ | ||
223 | /***********************************************************************************/ | ||
224 | |||
225 | 5 | double HyperElasticLaw::SecondDerivativeWcThirdInvariant(const double pressure) const | |
226 | { | ||
227 | IGNORE_UNUSED_ARGUMENT(pressure); | ||
228 | 5 | checkInitDone(); | |
229 | 5 | return 0.0; | |
230 | } | ||
231 | |||
232 | /***********************************************************************************/ | ||
233 | /***********************************************************************************/ | ||
234 | |||
235 | 32 | HyperElasticityLawManager::HyperElasticityLawManager() | |
236 | { | ||
237 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | const auto& r_instance = FelisceParam::instance(); |
238 | 32 | std::string hyperelastic_law; | |
239 | 32 | int counter_label = 0; | |
240 |
1/2✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
|
32 | mDatabaseOfHyperelasticLaws.insert({0, nullptr}); |
241 |
2/2✓ Branch 1 taken 40 times.
✓ Branch 2 taken 32 times.
|
72 | for (std::size_t i = 0; i < r_instance.hyperElasticLaw.type.size(); ++i) { |
242 |
1/2✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
|
40 | hyperelastic_law = r_instance.hyperElasticLaw.type[i]; |
243 |
3/6✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 40 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 40 times.
✗ Branch 9 not taken.
|
40 | HyperElasticLaw::Pointer hyperElasticLaw = HyperElasticityLawDatabase::DatabaseOfHyperelasticLaws.find(hyperelastic_law) != HyperElasticityLawDatabase::DatabaseOfHyperelasticLaws.end() ? HyperElasticityLawDatabase::DatabaseOfHyperelasticLaws[hyperelastic_law] : nullptr; |
244 |
2/2✓ Branch 1 taken 24 times.
✓ Branch 2 taken 16 times.
|
40 | if (r_instance.hyperElasticLaw.label.size() == 0) { |
245 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
24 | FEL_ASSERT(i == 0); |
246 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | mDatabaseOfHyperelasticLaws[0] = hyperElasticLaw; |
247 | } else { | ||
248 | 16 | const int num_label = r_instance.hyperElasticLaw.numLabel[i]; | |
249 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
|
32 | for (int j = 0; j < num_label; ++j) { |
250 | 16 | const int label = r_instance.hyperElasticLaw.label[counter_label]; | |
251 |
3/4✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 8 times.
|
16 | if (mDatabaseOfHyperelasticLaws.find(label) != mDatabaseOfHyperelasticLaws.end()) { |
252 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | mDatabaseOfHyperelasticLaws[label] = hyperElasticLaw; |
253 | } else { | ||
254 |
1/2✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
8 | mDatabaseOfHyperelasticLaws.insert({label, hyperElasticLaw}); |
255 | } | ||
256 | 16 | ++counter_label; | |
257 | } | ||
258 | } | ||
259 | 40 | } | |
260 | 32 | } | |
261 | |||
262 | /***********************************************************************************/ | ||
263 | /***********************************************************************************/ | ||
264 | |||
265 | 32 | void HyperElasticityLawManager::InitParameters() | |
266 | { | ||
267 | // Init all laws | ||
268 |
2/2✓ Branch 5 taken 40 times.
✓ Branch 6 taken 32 times.
|
72 | for (auto& r_law : mDatabaseOfHyperelasticLaws) { |
269 |
1/2✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
|
40 | r_law.second->InitParameters(); |
270 | } | ||
271 | 32 | } | |
272 | |||
273 | /***********************************************************************************/ | ||
274 | /***********************************************************************************/ | ||
275 | |||
276 | 1580268 | HyperElasticLaw::Pointer HyperElasticityLawManager::GetHyperElasticLaw(const int LabelElement) | |
277 | { | ||
278 |
1/2✓ Branch 1 taken 1580268 times.
✗ Branch 2 not taken.
|
1580268 | auto it_law = mDatabaseOfHyperelasticLaws.find(LabelElement); |
279 |
1/2✓ Branch 2 taken 1580268 times.
✗ Branch 3 not taken.
|
1580268 | if (it_law != mDatabaseOfHyperelasticLaws.end()) { |
280 | 1580268 | return it_law->second; | |
281 | } else { // Default is label 0 | ||
282 | ✗ | return mDatabaseOfHyperelasticLaws[0]; | |
283 | } | ||
284 | } | ||
285 | |||
286 | } // namespace felisce | ||
287 |