preCICE v3.1.2
Loading...
Searching...
No Matches
AccelerationSerialTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <algorithm>
18#include "testing/Testing.hpp"
20
21using namespace precice;
22using namespace precice::acceleration;
23
25
26BOOST_AUTO_TEST_SUITE(AccelerationTests)
27
30
31 // AccelerationSerialTestsFixture() {}
32};
33
34BOOST_FIXTURE_TEST_SUITE(AccelerationSerialTests, AccelerationSerialTestsFixture)
35
36#ifndef PRECICE_NO_MPI
37
38void testIQNIMVJPP(bool exchangeSubsteps)
39{
41 // use two vectors and see if underrelaxation works
42 double initialRelaxation = 0.01;
43 int maxIterationsUsed = 50;
44 int timeWindowsReused = 6;
45 int reusedTimeWindowsAtRestart = 0;
46 int chunkSize = 0;
47 int filter = Acceleration::QR1FILTER;
48 int restartType = IQNIMVJAcceleration::NO_RESTART;
49 double singularityLimit = 1e-10;
50 double svdTruncationEps = 0.0;
51 bool enforceInitialRelaxation = false;
52 bool alwaysBuildJacobian = false;
53 std::vector<int> dataIDs;
54 dataIDs.push_back(0);
55 dataIDs.push_back(1);
56 std::vector<double> factors;
57 factors.resize(2, 1.0);
59 mesh::PtrMesh dummyMesh(new mesh::Mesh("DummyMesh", 3, testing::nextMeshID()));
60
61 IQNIMVJAcceleration pp(initialRelaxation, enforceInitialRelaxation, maxIterationsUsed,
62 timeWindowsReused, filter, singularityLimit, dataIDs, prec, alwaysBuildJacobian,
63 restartType, chunkSize, reusedTimeWindowsAtRestart, svdTruncationEps);
64
65 Eigen::VectorXd fcol1;
66
67 mesh::PtrData displacements(new mesh::Data("dvalues", -1, 1));
68 mesh::PtrData forces(new mesh::Data("fvalues", -1, 1));
69
70 // init displacements
71 displacements->values().resize(4);
72 displacements->values() << 1.0, 1.0, 1.0, 1.0;
73 displacements->setSampleAtTime(0, displacements->sample());
74
75 // init forces
76 forces->values().resize(4);
77 forces->values() << 0.2, 0.2, 0.2, 0.2;
78 forces->setSampleAtTime(0, forces->sample());
79
80 cplscheme::PtrCouplingData dpcd = makeCouplingData(displacements, dummyMesh, exchangeSubsteps);
81 cplscheme::PtrCouplingData fpcd = makeCouplingData(forces, dummyMesh, exchangeSubsteps);
82
83 DataMap data;
86 dpcd->storeIteration();
87 fpcd->storeIteration();
88
89 pp.initialize(data);
90
91 displacements->values() << 1.0, 2.0, 3.0, 4.0;
92 displacements->setSampleAtTime(1, displacements->sample());
93 forces->values() << 0.1, 0.1, 0.1, 0.1;
94 forces->setSampleAtTime(1, forces->sample());
95
96 pp.performAcceleration(data);
97
98 BOOST_TEST(testing::equals(data.at(0)->values()(0), 1.00000000000000000000));
99 BOOST_TEST(testing::equals(data.at(0)->values()(1), 1.01000000000000000888));
100 BOOST_TEST(testing::equals(data.at(0)->values()(2), 1.02000000000000001776));
101 BOOST_TEST(testing::equals(data.at(0)->values()(3), 1.03000000000000002665));
102 BOOST_TEST(testing::equals(data.at(1)->values()(0), 0.199000000000000010214));
103 BOOST_TEST(testing::equals(data.at(1)->values()(1), 0.199000000000000010214));
104 BOOST_TEST(testing::equals(data.at(1)->values()(2), 0.199000000000000010214));
105 BOOST_TEST(testing::equals(data.at(1)->values()(3), 0.199000000000000010214));
106
107 data.begin()->second->values() << 10, 10, 10, 10;
108
109 pp.performAcceleration(data);
110
111 BOOST_TEST(testing::equals(data.at(0)->values()(0), -5.63401340929695848558e-01));
112 BOOST_TEST(testing::equals(data.at(0)->values()(1), 6.10309919173602111186e-01));
113 BOOST_TEST(testing::equals(data.at(0)->values()(2), 1.78402117927690184729e+00));
114 BOOST_TEST(testing::equals(data.at(0)->values()(3), 2.95773243938020247157e+00));
115 BOOST_TEST(testing::equals(data.at(1)->values()(0), 8.28025852497733250157e-02));
116 BOOST_TEST(testing::equals(data.at(1)->values()(1), 8.28025852497733250157e-02));
117 BOOST_TEST(testing::equals(data.at(1)->values()(2), 8.28025852497733250157e-02));
118 BOOST_TEST(testing::equals(data.at(1)->values()(3), 8.28025852497733250157e-02));
119}
120
121#if 0
122// TODO not yet supported
123BOOST_AUTO_TEST_CASE(testIQNIMVJPPWithSubsteps)
124{
125 PRECICE_TEST(1_rank);
126 testIQNIMVJPP(true);
127}
128#endif
129
130BOOST_AUTO_TEST_CASE(testIQNIMVJPPWithoutSubsteps)
131{
132 PRECICE_TEST(1_rank);
133 testIQNIMVJPP(false);
134}
135
136void testVIQNPP(bool exchangeSubsteps)
137{
139 // use two vectors and see if underrelaxation works
140
141 double initialRelaxation = 0.01;
142 int maxIterationsUsed = 50;
143 int timeWindowsReused = 6;
144 int filter = acceleration::BaseQNAcceleration::QR1FILTER;
145 double singularityLimit = 1e-10;
146 bool enforceInitialRelaxation = false;
147 std::vector<int> dataIDs;
148 dataIDs.push_back(0);
149 dataIDs.push_back(1);
150 std::vector<double> factors;
151 factors.resize(2, 1.0);
153
154 std::map<int, double> scalings;
155 scalings.insert(std::make_pair(0, 1.0));
156 scalings.insert(std::make_pair(1, 1.0));
157 mesh::PtrMesh dummyMesh(new mesh::Mesh("DummyMesh", 3, testing::nextMeshID()));
158
159 IQNILSAcceleration pp(initialRelaxation, enforceInitialRelaxation, maxIterationsUsed,
160 timeWindowsReused, filter, singularityLimit, dataIDs, prec);
161
162 mesh::PtrData displacements(new mesh::Data("dvalues", -1, 1));
163 mesh::PtrData forces(new mesh::Data("fvalues", -1, 1));
164
165 // init displacements
166 displacements->values().resize(4);
167 displacements->values() << 1.0, 1.0, 1.0, 1.0;
168 displacements->setSampleAtTime(0, displacements->sample());
169
170 // init forces
171 forces->values().resize(4);
172 forces->values() << 0.2, 0.2, 0.2, 0.2;
173 forces->setSampleAtTime(0, forces->sample());
174
175 cplscheme::PtrCouplingData dpcd = makeCouplingData(displacements, dummyMesh, exchangeSubsteps);
176 cplscheme::PtrCouplingData fpcd = makeCouplingData(forces, dummyMesh, exchangeSubsteps);
177
178 dpcd->storeIteration();
179 fpcd->storeIteration();
180
181 DataMap data;
182 data.insert(std::pair<int, cplscheme::PtrCouplingData>(0, dpcd));
183 data.insert(std::pair<int, cplscheme::PtrCouplingData>(1, fpcd));
184
185 pp.initialize(data);
186
187 displacements->values() << 1.0, 2.0, 3.0, 4.0;
188 displacements->setSampleAtTime(1, displacements->sample());
189 forces->values() << 0.1, 0.1, 0.1, 0.1;
190 forces->setSampleAtTime(1, forces->sample());
191
192 pp.performAcceleration(data);
193
194 BOOST_TEST(testing::equals(data.at(0)->values()(0), 1.00));
195 BOOST_TEST(testing::equals(data.at(0)->values()(1), 1.01));
196 BOOST_TEST(testing::equals(data.at(0)->values()(2), 1.02));
197 BOOST_TEST(testing::equals(data.at(0)->values()(3), 1.03));
198 BOOST_TEST(testing::equals(data.at(1)->values()(0), 0.199));
199 BOOST_TEST(testing::equals(data.at(1)->values()(1), 0.199));
200 BOOST_TEST(testing::equals(data.at(1)->values()(2), 0.199));
201 BOOST_TEST(testing::equals(data.at(1)->values()(3), 0.199));
202
203 Eigen::VectorXd newdvalues;
204 utils::append(newdvalues, 10.0);
205 utils::append(newdvalues, 10.0);
206 utils::append(newdvalues, 10.0);
207 utils::append(newdvalues, 10.0);
208 data.begin()->second->values() = newdvalues;
209
210 pp.performAcceleration(data);
211
212 BOOST_TEST(testing::equals(data.at(0)->values()(0), -5.63401340929692295845e-01));
213 BOOST_TEST(testing::equals(data.at(0)->values()(1), 6.10309919173607440257e-01));
214 BOOST_TEST(testing::equals(data.at(0)->values()(2), 1.78402117927690717636e+00));
215 BOOST_TEST(testing::equals(data.at(0)->values()(3), 2.95773243938020513610e+00));
216 BOOST_TEST(testing::equals(data.at(1)->values()(0), 8.28025852497733944046e-02));
217 BOOST_TEST(testing::equals(data.at(1)->values()(1), 8.28025852497733944046e-02));
218 BOOST_TEST(testing::equals(data.at(1)->values()(2), 8.28025852497733944046e-02));
219 BOOST_TEST(testing::equals(data.at(1)->values()(3), 8.28025852497733944046e-02));
220}
221
222#if 0
223// TODO not yet supported
224BOOST_AUTO_TEST_CASE(testVIQNPPWithSubsteps)
225{
226 PRECICE_TEST(1_rank);
227 testVIQNPP(true);
228 }
229#endif
230
231BOOST_AUTO_TEST_CASE(testVIQNPPWithoutSubsteps)
232{
233 PRECICE_TEST(1_rank);
234 testVIQNPP(false);
235}
236
237BOOST_AUTO_TEST_CASE(testConstantUnderrelaxationWithSubsteps)
238{
239 PRECICE_TEST(1_rank);
240 // use two vectors and see if underrelaxation works
241 double relaxation = 0.4;
242 std::vector<int> dataIDs{0, 1};
243 mesh::PtrMesh dummyMesh = std::make_shared<mesh::Mesh>("DummyMesh", 3, testing::nextMeshID());
244
245 ConstantRelaxationAcceleration acc(relaxation, dataIDs);
246
247 mesh::PtrData displacements = std::make_shared<mesh::Data>("dvalues", -1, 1);
248 mesh::PtrData forces = std::make_shared<mesh::Data>("fvalues", -1, 1);
249
250 // //init displacements
251 displacements->values().resize(4);
252 displacements->values() << 1.0, 2.0, 3.0, 4.0;
253 displacements->setSampleAtTime(0, displacements->sample());
254
255 // //init forces
256 forces->values().resize(4);
257 forces->values() << 0.2, 0.2, 0.2, 0.2;
258 forces->setSampleAtTime(0, forces->sample());
259
260 bool exchangeSubsteps = false;
261
262 cplscheme::PtrCouplingData dpcd = makeCouplingData(displacements, dummyMesh, exchangeSubsteps);
263 cplscheme::PtrCouplingData fpcd = makeCouplingData(forces, dummyMesh, exchangeSubsteps);
264
265 DataMap data;
266 data.insert(std::pair<int, cplscheme::PtrCouplingData>(0, dpcd));
267 data.insert(std::pair<int, cplscheme::PtrCouplingData>(1, fpcd));
268 dpcd->storeIteration();
269 fpcd->storeIteration();
270
271 acc.initialize(data);
272
273 displacements->values() << 3.5, 2.0, 2.0, 1.0;
274 displacements->setSampleAtTime(1, displacements->sample());
275 forces->values() << 0.1, 0.1, 0.1, 0.1;
276 forces->setSampleAtTime(1, forces->sample());
277
278 acc.performAcceleration(data);
279
280 BOOST_TEST(data.at(0)->values()(0) == 2);
281 BOOST_TEST(data.at(0)->values()(1) == 2);
282 BOOST_TEST(data.at(0)->values()(2) == 2.6);
283 BOOST_TEST(data.at(0)->values()(3) == 2.8);
284 BOOST_TEST(data.at(1)->values()(0) == 0.16);
285 BOOST_TEST(data.at(1)->values()(1) == 0.16);
286 BOOST_TEST(data.at(1)->values()(2) == 0.16);
287 BOOST_TEST(data.at(1)->values()(3) == 0.16);
288
289 displacements->values() << 10, 10, 10, 10;
290 displacements->setSampleAtTime(1.0, displacements->sample());
291 forces->setSampleAtTime(1.0, forces->sample());
292
293 acc.performAcceleration(data);
294
295 BOOST_TEST(data.at(0)->values()(0) == 4.6);
296 BOOST_TEST(data.at(0)->values()(1) == 5.2);
297 BOOST_TEST(data.at(0)->values()(2) == 5.8);
298 BOOST_TEST(data.at(0)->values()(3) == 6.4);
299 BOOST_TEST(data.at(1)->values()(0) == 0.184);
300 BOOST_TEST(data.at(1)->values()(1) == 0.184);
301 BOOST_TEST(data.at(1)->values()(2) == 0.184);
302 BOOST_TEST(data.at(1)->values()(3) == 0.184);
303}
304
305BOOST_AUTO_TEST_CASE(testAitkenUnderrelaxationWithoutSubsteps)
306{
307 PRECICE_TEST(1_rank);
308
309 double relaxation = 0.4;
310 std::vector<int> dataIDs{0, 1};
311 std::vector<double> factors{1, 1};
312 mesh::PtrMesh dummyMesh = std::make_shared<mesh::Mesh>("DummyMesh", 3, testing::nextMeshID());
313
315 AitkenAcceleration acc(relaxation, dataIDs, prec);
316
317 mesh::PtrData displacements = std::make_shared<mesh::Data>("dvalues", -1, 1);
318 mesh::PtrData forces = std::make_shared<mesh::Data>("fvalues", -1, 1);
319
320 // //init displacements
321 displacements->values().resize(4);
322 displacements->values() << 1.0, 2.0, 3.0, 4.0;
323 displacements->setSampleAtTime(0.0, displacements->sample());
324
325 // //init forces
326 forces->values().resize(4);
327 forces->values() << 0.2, 0.2, 0.2, 0.2;
328 forces->setSampleAtTime(0.0, forces->sample());
329
330 cplscheme::PtrCouplingData dpcd = makeCouplingData(displacements, dummyMesh, false);
331 cplscheme::PtrCouplingData fpcd = makeCouplingData(forces, dummyMesh, false);
332
333 DataMap data;
334 data.insert(std::pair<int, cplscheme::PtrCouplingData>(0, dpcd));
335 data.insert(std::pair<int, cplscheme::PtrCouplingData>(1, fpcd));
336 dpcd->storeIteration();
337 fpcd->storeIteration();
338
339 acc.initialize(data);
340
341 displacements->values() << 3.5, 2.0, 2.0, 1.0;
342 displacements->setSampleAtTime(1.0, displacements->sample());
343 forces->values() << 0.1, 0.1, 0.1, 0.1;
344 forces->setSampleAtTime(1.0, forces->sample());
345
346 acc.performAcceleration(data);
347
348 BOOST_TEST(data.at(0)->values()(0) == 2);
349 BOOST_TEST(data.at(0)->values()(1) == 2);
350 BOOST_TEST(data.at(0)->values()(2) == 2.6);
351 BOOST_TEST(data.at(0)->values()(3) == 2.8);
352 BOOST_TEST(data.at(1)->values()(0) == 0.16);
353 BOOST_TEST(data.at(1)->values()(1) == 0.16);
354 BOOST_TEST(data.at(1)->values()(2) == 0.16);
355 BOOST_TEST(data.at(1)->values()(3) == 0.16);
356
357 data.begin()->second->values() << 10, 10, 10, 10;
358 displacements->setSampleAtTime(1.0, displacements->sample());
359 forces->setSampleAtTime(1.0, forces->sample());
360
361 acc.performAcceleration(data);
362
363 BOOST_TEST(data.at(0)->values()(0) == 1.2689851805508461);
364 BOOST_TEST(data.at(0)->values()(1) == 2.2390979382674185);
365 BOOST_TEST(data.at(0)->values()(2) == 3.2092106959839914);
366 BOOST_TEST(data.at(0)->values()(3) == 4.1793234537005644);
367 BOOST_TEST(data.at(1)->values()(0) == 0.19880451030866292);
368 BOOST_TEST(data.at(1)->values()(1) == 0.19880451030866292);
369 BOOST_TEST(data.at(1)->values()(2) == 0.19880451030866292);
370 BOOST_TEST(data.at(1)->values()(3) == 0.19880451030866292);
371}
372
373BOOST_AUTO_TEST_CASE(testAitkenUnderrelaxationWithPreconditioner)
374{
375 PRECICE_TEST(1_rank);
376
377 double relaxation = 0.8;
378 std::vector<int> dataIDs{0, 1, 2, 3};
379 mesh::PtrMesh dummyMesh = std::make_shared<mesh::Mesh>("DummyMesh", 3, testing::nextMeshID());
380
382 AitkenAcceleration acc(relaxation, dataIDs, prec);
383
384 mesh::PtrData data1 = std::make_shared<mesh::Data>("dvalues", -1, 1);
385 mesh::PtrData data2 = std::make_shared<mesh::Data>("fvalues", -1, 1);
386 mesh::PtrData data3 = std::make_shared<mesh::Data>("gvalues", -1, 3);
387 mesh::PtrData data4 = std::make_shared<mesh::Data>("hvalues", -1, 1);
388
389 // init data1
390 data1->values().resize(2);
391 data1->values() << 40, 80;
392 data1->setSampleAtTime(0.0, data1->sample());
393
394 // init data2
395 data2->values().resize(2);
396 data2->values() << 5, 5;
397 data2->setSampleAtTime(0.0, data2->sample());
398
399 // init data3
400 data3->values().resize(3);
401 data3->values() << 1, 2, 3;
402 data3->setSampleAtTime(0.0, data3->sample());
403
404 // init data4
405 data4->values().resize(4);
406 data4->values() << 20, 40, 60, 80;
407 data4->setSampleAtTime(0.0, data4->sample());
408
409 cplscheme::PtrCouplingData dpcd = makeCouplingData(data1, dummyMesh, false);
410 cplscheme::PtrCouplingData fpcd = makeCouplingData(data2, dummyMesh, false);
411 cplscheme::PtrCouplingData gpcd = makeCouplingData(data3, dummyMesh, false);
412 cplscheme::PtrCouplingData hpcd = makeCouplingData(data4, dummyMesh, false);
413
414 DataMap data;
415 data.insert(std::pair<int, cplscheme::PtrCouplingData>(0, dpcd));
416 data.insert(std::pair<int, cplscheme::PtrCouplingData>(1, fpcd));
417 data.insert(std::pair<int, cplscheme::PtrCouplingData>(2, gpcd));
418 data.insert(std::pair<int, cplscheme::PtrCouplingData>(3, hpcd));
419 dpcd->storeIteration();
420 fpcd->storeIteration();
421 gpcd->storeIteration();
422 hpcd->storeIteration();
423
424 acc.initialize(data);
425
426 data1->values() << 1, 7;
427 data1->setSampleAtTime(1.0, data1->sample());
428 data2->values() << 10, 10;
429 data2->setSampleAtTime(1.0, data2->sample());
430 data3->values() << 10, 11, 12;
431 data3->setSampleAtTime(1.0, data3->sample());
432 data4->values() << 40, 60, 80, 100;
433 data4->setSampleAtTime(1.0, data4->sample());
434
435 acc.performAcceleration(data);
436
437 BOOST_TEST(data.at(0)->values()(0) == 8.8);
438 BOOST_TEST(data.at(0)->values()(1) == 21.6);
439 BOOST_TEST(data.at(1)->values()(0) == 9);
440 BOOST_TEST(data.at(1)->values()(1) == 9);
441 BOOST_TEST(data.at(2)->values()(0) == 8.2);
442 BOOST_TEST(data.at(2)->values()(1) == 9.2);
443 BOOST_TEST(data.at(2)->values()(2) == 10.2);
444 BOOST_TEST(data.at(3)->values()(0) == 36);
445 BOOST_TEST(data.at(3)->values()(1) == 56);
446 BOOST_TEST(data.at(3)->values()(2) == 76);
447 BOOST_TEST(data.at(3)->values()(3) == 96);
448
449 data1->values() << 2, 14;
450 data1->setSampleAtTime(1.0, data1->sample());
451 data2->values() << 8, 8;
452 data2->setSampleAtTime(1.0, data2->sample());
453 data3->values() << 13, 14, 15;
454 data3->setSampleAtTime(1.0, data3->sample());
455 data4->values() << 41, 61, 81, 90;
456 data4->setSampleAtTime(1.0, data4->sample());
457
458 acc.performAcceleration(data);
459
460 BOOST_TEST(data.at(0)->values()(0) == -17.745640722103754);
461 BOOST_TEST(data.at(0)->values()(1) == -20.295060201548626);
462 BOOST_TEST(data.at(1)->values()(0) == 9.5588663727976648);
463 BOOST_TEST(data.at(1)->values()(1) == 9.5588663727976648);
464 BOOST_TEST(data.at(2)->values()(0) == 19.235465491190659);
465 BOOST_TEST(data.at(2)->values()(1) == 20.235465491190659);
466 BOOST_TEST(data.at(2)->values()(2) == 21.235465491190659);
467 BOOST_TEST(data.at(3)->values()(0) == 51.912064609583652);
468 BOOST_TEST(data.at(3)->values()(1) == 71.912064609583652);
469 BOOST_TEST(data.at(3)->values()(2) == 91.912064609583652);
470 BOOST_TEST(data.at(3)->values()(3) == 95.196221242658879);
471
472 data1->values() << 2.1, 14.1;
473 data1->setSampleAtTime(1.0, data1->sample());
474 data2->values() << 8, 8;
475 data2->setSampleAtTime(1.0, data2->sample());
476 data3->values() << 13.05, 14.07, 15.1;
477 data3->setSampleAtTime(1.0, data3->sample());
478 data4->values() << 42, 60, 81.3, 91;
479 data4->setSampleAtTime(1.0, data4->sample());
480
481 acc.iterationsConverged(data);
482
483 data1->values() << 3, 16;
484 data1->setSampleAtTime(2.0, data1->sample());
485 data2->values() << 7, 7;
486 data2->setSampleAtTime(2.0, data2->sample());
487 data3->values() << 18, 19, 20;
488 data3->setSampleAtTime(2.0, data3->sample());
489 data4->values() << 50, 70, 90, 110;
490 data4->setSampleAtTime(2.0, data4->sample());
491
492 acc.performAcceleration(data);
493
494 BOOST_TEST(data.at(0)->values()(0) == 10.4);
495 BOOST_TEST(data.at(0)->values()(1) == 28.8);
496 BOOST_TEST(data.at(1)->values()(0) == 6.6);
497 BOOST_TEST(data.at(1)->values()(1) == 6.6);
498 BOOST_TEST(data.at(2)->values()(0) == 14.6);
499 BOOST_TEST(data.at(2)->values()(1) == 15.6);
500 BOOST_TEST(data.at(2)->values()(2) == 16.6);
501 BOOST_TEST(data.at(3)->values()(0) == 44);
502 BOOST_TEST(data.at(3)->values()(1) == 64);
503 BOOST_TEST(data.at(3)->values()(2) == 84);
504 BOOST_TEST(data.at(3)->values()(3) == 104);
505}
506
507BOOST_AUTO_TEST_CASE(testConstantUnderrelaxationWithGradientWithSubsteps)
508{
509 PRECICE_TEST(1_rank);
510 //use two vectors and see if underrelaxation works
511 double relaxation = 0.4;
512 std::vector<int> dataIDs{0, 1};
513 const int dim = 3;
514 mesh::PtrMesh dummyMesh = std::make_shared<mesh::Mesh>("DummyMesh", dim, testing::nextMeshID());
515
516 ConstantRelaxationAcceleration acc(relaxation, dataIDs);
517
518 mesh::PtrData displacements = std::make_shared<mesh::Data>("dvalues", -1, 1);
519 mesh::PtrData forces = std::make_shared<mesh::Data>("fvalues", -1, 1);
520
521 // //init displacements
522 displacements->values().resize(4);
523 displacements->values() << 1.0, 2.0, 3.0, 4.0;
524 displacements->requireDataGradient();
525 displacements->gradients().resize(dim, 4);
526 for (unsigned int r = 0; r < dim; ++r) {
527 for (unsigned int c = 0; c < 4; ++c)
528 displacements->gradients()(r, c) = r + r * c;
529 }
530 displacements->setSampleAtTime(0.0, displacements->sample());
531 // //init forces
532 forces->values().resize(4);
533 forces->values() << 0.2, 0.2, 0.2, 0.2;
534 forces->requireDataGradient();
535 forces->gradients().resize(dim, 4);
536 forces->gradients().setConstant(-2);
537 forces->setSampleAtTime(0.0, forces->sample());
538
539 bool exchangeSubsteps = true;
540
541 cplscheme::PtrCouplingData dpcd = makeCouplingData(displacements, dummyMesh, exchangeSubsteps);
542 cplscheme::PtrCouplingData fpcd = makeCouplingData(forces, dummyMesh, exchangeSubsteps);
543
544 DataMap data;
545 data.insert(std::pair<int, cplscheme::PtrCouplingData>(0, dpcd));
546 data.insert(std::pair<int, cplscheme::PtrCouplingData>(1, fpcd));
547 dpcd->storeIteration();
548 fpcd->storeIteration();
549
550 acc.initialize(data);
551
552 displacements->values() << 3.5, 2.0, 2.0, 1.0;
553 displacements->gradients().setConstant(2.5);
554 displacements->setSampleAtTime(1.0, displacements->sample());
555 forces->values() << 0.1, 0.1, 0.1, 0.1;
556 forces->gradients().setConstant(3);
557 forces->setSampleAtTime(1.0, forces->sample());
558
559 acc.performAcceleration(data);
560
561 // Test value data
562 BOOST_TEST(data.at(0)->values()(0) == 2);
563 BOOST_TEST(data.at(0)->values()(1) == 2);
564 BOOST_TEST(data.at(0)->values()(2) == 2.6);
565 BOOST_TEST(data.at(0)->values()(3) == 2.8);
566 BOOST_TEST(data.at(1)->values()(0) == 0.16);
567 BOOST_TEST(data.at(1)->values()(1) == 0.16);
568 BOOST_TEST(data.at(1)->values()(2) == 0.16);
569 BOOST_TEST(data.at(1)->values()(3) == 0.16);
570
571 // Test gradient data
572 BOOST_TEST(data.at(0)->gradients()(0, 0) == 1);
573 BOOST_TEST(data.at(0)->gradients()(0, 1) == 1);
574 BOOST_TEST(data.at(0)->gradients()(0, 2) == 1);
575 BOOST_TEST(data.at(0)->gradients()(1, 0) == 1.6);
576 BOOST_TEST(data.at(0)->gradients()(1, 1) == 2.2);
577 BOOST_TEST(data.at(0)->gradients()(1, 2) == 2.8);
578 BOOST_TEST(data.at(1)->gradients()(0, 0) == 0);
579 BOOST_TEST(data.at(1)->gradients()(0, 1) == 0);
580 BOOST_TEST(data.at(1)->gradients()(0, 2) == 0);
581 BOOST_TEST(data.at(1)->gradients()(1, 0) == 0);
582 BOOST_TEST(data.at(1)->gradients()(1, 1) == 0);
583 BOOST_TEST(data.at(1)->gradients()(1, 2) == 0);
584
585 displacements->values() << 10, 10, 10, 10;
586 displacements->gradients().setConstant(4);
587 displacements->setSampleAtTime(1, displacements->sample());
588 forces->setSampleAtTime(1, forces->sample());
589
590 acc.performAcceleration(data);
591
592 // Check that store iteration works properly
593 BOOST_TEST(data.at(0)->values()(0) == 4.6);
594 BOOST_TEST(data.at(0)->values()(1) == 5.2);
595 BOOST_TEST(data.at(0)->values()(2) == 5.8);
596 BOOST_TEST(data.at(0)->values()(3) == 6.4);
597 BOOST_TEST(data.at(1)->values()(0) == 0.184);
598 BOOST_TEST(data.at(1)->values()(1) == 0.184);
599 BOOST_TEST(data.at(1)->values()(2) == 0.184);
600 BOOST_TEST(data.at(1)->values()(3) == 0.184);
601
602 BOOST_TEST(data.at(0)->gradients()(0, 0) == 1.6);
603 BOOST_TEST(data.at(0)->gradients()(0, 1) == 1.6);
604 BOOST_TEST(data.at(0)->gradients()(0, 2) == 1.6);
605 BOOST_TEST(data.at(0)->gradients()(1, 0) == 2.2);
606 BOOST_TEST(data.at(0)->gradients()(1, 1) == 2.8);
607 BOOST_TEST(data.at(0)->gradients()(1, 2) == 3.4);
608}
609
610BOOST_AUTO_TEST_CASE(testConstantUnderrelaxationWithoutSubsteps)
611{
612 PRECICE_TEST(1_rank);
613 //use two vectors and see if underrelaxation works
614 double relaxation = 0.4;
615 std::vector<int> dataIDs{0, 1};
616 mesh::PtrMesh dummyMesh = std::make_shared<mesh::Mesh>("DummyMesh", 3, testing::nextMeshID());
617
618 ConstantRelaxationAcceleration acc(relaxation, dataIDs);
619
620 mesh::PtrData displacements = std::make_shared<mesh::Data>("dvalues", -1, 1);
621 mesh::PtrData forces = std::make_shared<mesh::Data>("fvalues", -1, 1);
622
623 // //init displacements
624 displacements->values().resize(4);
625 displacements->values() << 1.0, 2.0, 3.0, 4.0;
626 displacements->setSampleAtTime(0.0, displacements->sample());
627
628 // //init forces
629 forces->values().resize(4);
630 forces->values() << 0.2, 0.2, 0.2, 0.2;
631 forces->setSampleAtTime(0.0, forces->sample());
632
633 bool exchangeSubsteps = false;
634
635 cplscheme::PtrCouplingData dpcd = makeCouplingData(displacements, dummyMesh, exchangeSubsteps);
636 cplscheme::PtrCouplingData fpcd = makeCouplingData(forces, dummyMesh, exchangeSubsteps);
637
638 DataMap data;
639 data.insert(std::pair<int, cplscheme::PtrCouplingData>(0, dpcd));
640 data.insert(std::pair<int, cplscheme::PtrCouplingData>(1, fpcd));
641 dpcd->storeIteration();
642 fpcd->storeIteration();
643
644 acc.initialize(data);
645
646 displacements->values() << 3.5, 2.0, 2.0, 1.0;
647 displacements->setSampleAtTime(1.0, displacements->sample());
648 forces->values() << 0.1, 0.1, 0.1, 0.1;
649 forces->setSampleAtTime(1.0, forces->sample());
650
651 acc.performAcceleration(data);
652
653 BOOST_TEST(data.at(0)->values()(0) == 2);
654 BOOST_TEST(data.at(0)->values()(1) == 2);
655 BOOST_TEST(data.at(0)->values()(2) == 2.6);
656 BOOST_TEST(data.at(0)->values()(3) == 2.8);
657 BOOST_TEST(data.at(1)->values()(0) == 0.16);
658 BOOST_TEST(data.at(1)->values()(1) == 0.16);
659 BOOST_TEST(data.at(1)->values()(2) == 0.16);
660 BOOST_TEST(data.at(1)->values()(3) == 0.16);
661
662 displacements->values() << 10, 10, 10, 10;
663 displacements->setSampleAtTime(1.0, displacements->sample());
664 forces->setSampleAtTime(1.0, forces->sample());
665
666 acc.performAcceleration(data);
667
668 BOOST_TEST(data.at(0)->values()(0) == 4.6);
669 BOOST_TEST(data.at(0)->values()(1) == 5.2);
670 BOOST_TEST(data.at(0)->values()(2) == 5.8);
671 BOOST_TEST(data.at(0)->values()(3) == 6.4);
672 BOOST_TEST(data.at(1)->values()(0) == 0.184);
673 BOOST_TEST(data.at(1)->values()(1) == 0.184);
674 BOOST_TEST(data.at(1)->values()(2) == 0.184);
675 BOOST_TEST(data.at(1)->values()(3) == 0.184);
676}
677
678BOOST_AUTO_TEST_CASE(testConstantUnderrelaxationWithGradientWithoutSubsteps)
679{
680 PRECICE_TEST(1_rank);
681 // use two vectors and see if underrelaxation works
682 double relaxation = 0.4;
683 std::vector<int> dataIDs{0, 1};
684 const int dim = 3;
685 mesh::PtrMesh dummyMesh = std::make_shared<mesh::Mesh>("DummyMesh", dim, testing::nextMeshID());
686
687 ConstantRelaxationAcceleration acc(relaxation, dataIDs);
688
689 mesh::PtrData displacements = std::make_shared<mesh::Data>("dvalues", -1, 1);
690 mesh::PtrData forces = std::make_shared<mesh::Data>("fvalues", -1, 1);
691
692 // //init displacements
693 displacements->values().resize(4);
694 displacements->values() << 1.0, 2.0, 3.0, 4.0;
695 displacements->requireDataGradient();
696 displacements->gradients().resize(dim, 4);
697 for (unsigned int r = 0; r < dim; ++r) {
698 for (unsigned int c = 0; c < 4; ++c)
699 displacements->gradients()(r, c) = r + r * c;
700 }
701 displacements->setSampleAtTime(0, displacements->sample());
702 // //init forces
703 forces->values().resize(4);
704 forces->values() << 0.2, 0.2, 0.2, 0.2;
705 forces->requireDataGradient();
706 forces->gradients().resize(dim, 4);
707 forces->gradients().setConstant(-2);
708 forces->setSampleAtTime(0, forces->sample());
709
710 bool exchangeSubsteps = false;
711
712 cplscheme::PtrCouplingData dpcd = makeCouplingData(displacements, dummyMesh, exchangeSubsteps);
713 cplscheme::PtrCouplingData fpcd = makeCouplingData(forces, dummyMesh, exchangeSubsteps);
714
715 DataMap data;
716 data.insert(std::pair<int, cplscheme::PtrCouplingData>(0, dpcd));
717 data.insert(std::pair<int, cplscheme::PtrCouplingData>(1, fpcd));
718 dpcd->storeIteration();
719 fpcd->storeIteration();
720
721 acc.initialize(data);
722
723 displacements->values() << 3.5, 2.0, 2.0, 1.0;
724 displacements->gradients().setConstant(2.5);
725 displacements->setSampleAtTime(1, displacements->sample());
726 forces->values() << 0.1, 0.1, 0.1, 0.1;
727 forces->gradients().setConstant(3);
728 forces->setSampleAtTime(1, forces->sample());
729
730 acc.performAcceleration(data);
731
732 // Test value data
733 BOOST_TEST(data.at(0)->values()(0) == 2);
734 BOOST_TEST(data.at(0)->values()(1) == 2);
735 BOOST_TEST(data.at(0)->values()(2) == 2.6);
736 BOOST_TEST(data.at(0)->values()(3) == 2.8);
737 BOOST_TEST(data.at(1)->values()(0) == 0.16);
738 BOOST_TEST(data.at(1)->values()(1) == 0.16);
739 BOOST_TEST(data.at(1)->values()(2) == 0.16);
740 BOOST_TEST(data.at(1)->values()(3) == 0.16);
741
742 // Test gradient data
743 BOOST_TEST(data.at(0)->gradients()(0, 0) == 1);
744 BOOST_TEST(data.at(0)->gradients()(0, 1) == 1);
745 BOOST_TEST(data.at(0)->gradients()(0, 2) == 1);
746 BOOST_TEST(data.at(0)->gradients()(1, 0) == 1.6);
747 BOOST_TEST(data.at(0)->gradients()(1, 1) == 2.2);
748 BOOST_TEST(data.at(0)->gradients()(1, 2) == 2.8);
749 BOOST_TEST(data.at(1)->gradients()(0, 0) == 0);
750 BOOST_TEST(data.at(1)->gradients()(0, 1) == 0);
751 BOOST_TEST(data.at(1)->gradients()(0, 2) == 0);
752 BOOST_TEST(data.at(1)->gradients()(1, 0) == 0);
753 BOOST_TEST(data.at(1)->gradients()(1, 1) == 0);
754 BOOST_TEST(data.at(1)->gradients()(1, 2) == 0);
755
756 data.begin()->second->values() << 10, 10, 10, 10;
757 displacements->gradients().setConstant(4);
758 displacements->setSampleAtTime(1, displacements->sample());
759 forces->setSampleAtTime(1, forces->sample());
760
761 acc.performAcceleration(data);
762
763 // Check that store iteration works properly
764 BOOST_TEST(data.at(0)->values()(0) == 4.6);
765 BOOST_TEST(data.at(0)->values()(1) == 5.2);
766 BOOST_TEST(data.at(0)->values()(2) == 5.8);
767 BOOST_TEST(data.at(0)->values()(3) == 6.4);
768 BOOST_TEST(data.at(1)->values()(0) == 0.184);
769 BOOST_TEST(data.at(1)->values()(1) == 0.184);
770 BOOST_TEST(data.at(1)->values()(2) == 0.184);
771 BOOST_TEST(data.at(1)->values()(3) == 0.184);
772
773 BOOST_TEST(data.at(0)->gradients()(0, 0) == 1.6);
774 BOOST_TEST(data.at(0)->gradients()(0, 1) == 1.6);
775 BOOST_TEST(data.at(0)->gradients()(0, 2) == 1.6);
776 BOOST_TEST(data.at(0)->gradients()(1, 0) == 2.2);
777 BOOST_TEST(data.at(0)->gradients()(1, 1) == 2.8);
778 BOOST_TEST(data.at(0)->gradients()(1, 2) == 3.4);
779}
780
781#endif // not PRECICE_NO_MPI
782
void testIQNIMVJPP(bool exchangeSubsteps)
BOOST_AUTO_TEST_CASE(testIQNIMVJPPWithoutSubsteps)
void testVIQNPP(bool exchangeSubsteps)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
virtual void iterationsConverged(const DataMap &cpldata)
virtual void performAcceleration(DataMap &cpldata)
virtual void initialize(const DataMap &cpldata)
virtual void performAcceleration(DataMap &cplData)
Performs one acceleration step.
Interface quasi-Newton with interface least-squares approximation.
virtual void initialize(const DataMap &cplData)
Initializes the acceleration.
Multi vector quasi-Newton update scheme.
virtual void initialize(const DataMap &cplData)
Initializes the acceleration.
Preconditioner that uses the constant user-defined factors to scale the quasi-Newton system.
Preconditioner that uses the recent residual to scale the quasi-Newton system.
Describes a set of data values belonging to the vertices of a mesh.
Definition Data.hpp:29
Container and creator for meshes.
Definition Mesh.hpp:39
T insert(T... args)
T make_pair(T... args)
contains implementations of acceleration schemes.
boost::test_tools::predicate_result equals(const std::vector< float > &VectorA, const std::vector< float > &VectorB, float tolerance)
equals to be used in tests. Compares two std::vectors using a given tolerance. Prints both operands o...
Definition Testing.cpp:65
cplscheme::PtrCouplingData makeCouplingData(mesh::PtrData data, mesh::PtrMesh mesh, bool exchangeSubsteps)
Definition helper.hpp:10
void append(Eigen::VectorXd &v, double value)
Main namespace of the precice library.
T push_back(T... args)
T resize(T... args)
std::map< int, cplscheme::PtrCouplingData > DataMap