49 const
std::
string & nameParticipant,
50 const mesh::MeshConfiguration &meshConfig,
51 const
std::vector<
int> & validIterations)
53 BOOST_REQUIRE(meshConfig.meshes().size() == 1);
55 BOOST_REQUIRE(mesh->data().size() == 2);
56 BOOST_REQUIRE(!mesh->empty());
57 BOOST_REQUIRE(!validIterations.empty());
61 auto & dataValues0 = mesh->data(0)->values();
62 auto & dataValues1 = mesh->data(1)->values();
63 double initialStepsizeData0 = 5.0;
64 double stepsizeData0 = 5.0;
65 Eigen::VectorXd initialStepsizeData1 = Eigen::VectorXd::Constant(3, 5.0);
66 Eigen::VectorXd stepsizeData1 = Eigen::VectorXd::Constant(3, 5.0);
67 double computedTime = 0.0;
68 int computedTimesteps = 0;
71 BOOST_TEST(((nameParticipant == nameParticipant0) || (nameParticipant == nameParticipant1)));
72 int iterationCount = 0;
73 std::vector<int>::const_iterator iterValidIterations = validIterations.begin();
75 if (nameParticipant == nameParticipant0) {
76 mesh->data(0)->setSampleAtTime(0,
time::Sample{1, mesh->data(0)->values()});
77 cplScheme.initialize(0.0, 1);
78 BOOST_TEST(not cplScheme.isTimeWindowComplete());
79 BOOST_TEST(cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
80 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
81 BOOST_TEST(not cplScheme.hasDataBeenReceived());
85 cplScheme.markActionFulfilled(CouplingScheme::Action::WriteCheckpoint);
86 BOOST_TEST(cplScheme.isActionFulfilled(CouplingScheme::Action::WriteCheckpoint));
88 while (cplScheme.isCouplingOngoing()) {
89 dataValues0(
index) += stepsizeData0;
91 double maxTimeStepSize = cplScheme.getNextTimeStepMaxSize();
92 cplScheme.addComputedTime(maxTimeStepSize);
93 mesh->data(0)->setSampleAtTime(cplScheme.getTime(),
time::Sample{1, mesh->data(0)->values()});
94 cplScheme.firstSynchronization({});
95 cplScheme.firstExchange();
96 cplScheme.secondSynchronization();
97 cplScheme.secondExchange();
102 if (cplScheme.isTimeWindowComplete()) {
104 computedTime += maxTimeStepSize;
107 BOOST_TEST(computedTimesteps == cplScheme.getTimeWindows() - 1);
110 BOOST_TEST(iterationCount == *iterValidIterations);
111 if (cplScheme.isCouplingOngoing()) {
112 BOOST_TEST(cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
113 cplScheme.markActionFulfilled(CouplingScheme::Action::WriteCheckpoint);
114 BOOST_TEST(cplScheme.isActionFulfilled(CouplingScheme::Action::WriteCheckpoint));
116 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
117 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
120 iterValidIterations++;
121 if (iterValidIterations == validIterations.end()) {
122 BOOST_REQUIRE(not cplScheme.isCouplingOngoing());
126 stepsizeData0 = initialStepsizeData0;
128 BOOST_TEST(cplScheme.isCouplingOngoing());
129 BOOST_TEST(iterationCount < *iterValidIterations);
130 BOOST_TEST(cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
131 cplScheme.markActionFulfilled(CouplingScheme::Action::ReadCheckpoint);
132 BOOST_TEST(cplScheme.isActionFulfilled(CouplingScheme::Action::ReadCheckpoint));
135 stepsizeData0 -= 1.0;
139 BOOST_TEST(cplScheme.hasDataBeenReceived());
141 cplScheme.finalize();
143 BOOST_TEST(computedTimesteps == 3);
144 }
else if (nameParticipant == nameParticipant1) {
145 mesh->data(1)->setSampleAtTime(0,
time::Sample{1, mesh->data(1)->values()});
146 cplScheme.initialize(0.0, 1);
147 BOOST_TEST(not cplScheme.isTimeWindowComplete());
148 BOOST_TEST(cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
149 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
150 BOOST_TEST(cplScheme.hasDataBeenReceived());
154 cplScheme.markActionFulfilled(CouplingScheme::Action::WriteCheckpoint);
155 BOOST_TEST(cplScheme.isActionFulfilled(CouplingScheme::Action::WriteCheckpoint));
157 while (cplScheme.isCouplingOngoing()) {
158 Eigen::VectorXd currentData(3);
159 currentData = dataValues1.segment(
index * 3, 3);
160 currentData += stepsizeData1;
161 dataValues1.segment(
index * 3, 3) = currentData;
163 double maxTimeStepSize = cplScheme.getNextTimeStepMaxSize();
164 cplScheme.addComputedTime(maxTimeStepSize);
165 mesh->data(1)->setSampleAtTime(cplScheme.getTime(),
time::Sample{1, mesh->data(1)->values()});
166 cplScheme.firstSynchronization({});
167 cplScheme.firstExchange();
168 cplScheme.secondSynchronization();
169 cplScheme.secondExchange();
174 if (cplScheme.isTimeWindowComplete()) {
176 computedTime += maxTimeStepSize;
179 BOOST_TEST(computedTimesteps == cplScheme.getTimeWindows() - 1);
182 BOOST_TEST(iterationCount == *iterValidIterations);
183 if (cplScheme.isCouplingOngoing()) {
184 BOOST_TEST(cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
185 cplScheme.markActionFulfilled(CouplingScheme::Action::WriteCheckpoint);
186 BOOST_TEST(cplScheme.isActionFulfilled(CouplingScheme::Action::WriteCheckpoint));
188 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
189 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
192 iterValidIterations++;
193 if (iterValidIterations == validIterations.end()) {
194 BOOST_REQUIRE(not cplScheme.isCouplingOngoing());
198 stepsizeData1 = initialStepsizeData1;
200 BOOST_TEST(cplScheme.isCouplingOngoing());
201 BOOST_TEST(iterationCount < *iterValidIterations);
202 BOOST_TEST(cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
205 cplScheme.markActionFulfilled(CouplingScheme::Action::ReadCheckpoint);
206 BOOST_TEST(cplScheme.isActionFulfilled(CouplingScheme::Action::ReadCheckpoint));
210 stepsizeData1 -= Eigen::Vector3d::Constant(1.0);
213 if (cplScheme.isCouplingOngoing())
214 BOOST_TEST(cplScheme.hasDataBeenReceived());
216 cplScheme.finalize();
218 BOOST_TEST(computedTimesteps == 3);
228 BOOST_REQUIRE(meshConfig.
meshes().size() == 1);
230 BOOST_REQUIRE(mesh->data().size() == 2);
231 BOOST_REQUIRE(!mesh->empty());
232 BOOST_REQUIRE(!validIterations.
empty());
234 double initialStepsizeData0 = 5.0;
235 double stepsizeData0 = 5.0;
236 Eigen::Vector3d initialStepsizeData1 = Eigen::Vector3d::Constant(5.0);
237 Eigen::Vector3d stepsizeData1 = Eigen::Vector3d::Constant(5.0);
238 double computedTime = 0.0;
239 int computedTimesteps = 0;
242 BOOST_TEST(((nameParticipant == nameParticipant0) || (nameParticipant == nameParticipant1)));
243 int iterationCount = 0;
244 std::vector<int>::const_iterator iterValidIterations =
245 validIterations.
begin();
247 if (nameParticipant == nameParticipant0) {
249 mesh->data(0)->setSampleAtTime(0,
time::Sample{1, mesh->data(0)->values()});
252 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
253 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
259 BOOST_TEST(cplScheme.
isActionFulfilled(CouplingScheme::Action::WriteCheckpoint));
262 double computedTimeStepSize = maxTimeStepSize / 2.0;
263 int subcyclingStep = 0;
266 mesh->data(0)->timeStepsStorage().trim();
271 mesh->data(0)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{1, mesh->data(0)->values()});
281 mesh->data(0)->timeStepsStorage().trim();
282 computedTime += maxTimeStepSize;
288 BOOST_TEST(iterationCount == *iterValidIterations);
290 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
292 BOOST_TEST(cplScheme.
isActionFulfilled(CouplingScheme::Action::WriteCheckpoint));
294 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
295 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
298 iterValidIterations++;
299 if (iterValidIterations == validIterations.
end()) {
304 stepsizeData0 = initialStepsizeData0;
305 BOOST_TEST(subcyclingStep == 1);
311 BOOST_TEST(iterationCount <= *iterValidIterations);
312 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
313 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
318 stepsizeData0 -= 1.0;
322 BOOST_TEST(iterationCount <= *iterValidIterations);
323 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
324 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
325 BOOST_TEST(subcyclingStep < 2);
332 BOOST_TEST(computedTimesteps == 3);
333 BOOST_TEST(stepsizeData0 == 5.0);
336 else if (nameParticipant == nameParticipant1) {
338 mesh->data(1)->setSampleAtTime(0,
time::Sample{1, mesh->data(1)->values()});
341 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
342 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
348 BOOST_TEST(cplScheme.
isActionFulfilled(CouplingScheme::Action::WriteCheckpoint));
351 double preferredTimeStepSize = maxTimeStepSize / 2.5;
352 double computedTimeStepSize = preferredTimeStepSize;
353 int subcyclingStep = 0;
356 mesh->data(1)->timeStepsStorage().trim();
361 mesh->data(1)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{1, mesh->data(1)->values()});
366 computedTimeStepSize =
369 : preferredTimeStepSize;
374 mesh->data(1)->timeStepsStorage().trim();
376 computedTime += maxTimeStepSize;
382 BOOST_TEST(iterationCount == *iterValidIterations);
384 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
386 BOOST_TEST(cplScheme.
isActionFulfilled(CouplingScheme::Action::WriteCheckpoint));
388 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
389 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
392 iterValidIterations++;
393 if (iterValidIterations == validIterations.
end()) {
398 stepsizeData1 = initialStepsizeData1;
399 BOOST_TEST(subcyclingStep == 2);
405 BOOST_TEST(iterationCount <= *iterValidIterations);
406 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
407 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
412 stepsizeData1.array() -= 1.0;
416 BOOST_TEST(iterationCount <= *iterValidIterations);
417 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
418 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
419 BOOST_TEST(subcyclingStep < 3);
426 BOOST_TEST(computedTimesteps == 3);
470 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
473 auto m2n = context.connectPrimaryRanks(
"Participant0",
"Participant1", options);
475 using namespace mesh;
481 PtrDataConfiguration dataConfig(
new DataConfiguration(root));
482 dataConfig->addData(
"data0", mesh::Data::typeName::SCALAR);
483 dataConfig->addData(
"data1", mesh::Data::typeName::VECTOR);
485 MeshConfiguration meshConfig(root, dataConfig);
487 mesh->createData(
"data0", 1, 0_dataID);
488 mesh->createData(
"data1", 3, 1_dataID);
489 mesh->createVertex(Eigen::Vector3d::Zero());
490 mesh->allocateDataValues();
491 meshConfig.insertMeshToMeshDimensionsMap(mesh->getName(), mesh->getDimensions());
492 meshConfig.addMesh(mesh);
495 const double maxTime = 1.0;
496 const int maxTimeWindows = 3;
497 const double timeWindowSize = 0.1;
500 int sendDataIndex = -1;
501 int receiveDataIndex = -1;
502 int convergenceDataIndex = -1;
503 if (context.isNamed(nameParticipant0)) {
505 receiveDataIndex = 1;
506 convergenceDataIndex = receiveDataIndex;
509 receiveDataIndex = 0;
510 convergenceDataIndex = sendDataIndex;
514 const int minIterations = 1;
515 const int maxIterations = 100;
516 cplscheme::SerialCouplingScheme cplScheme(maxTime, maxTimeWindows, timeWindowSize, nameParticipant0, nameParticipant1, context.name, m2n,
constants::FIXED_TIME_WINDOW_SIZE,
BaseCouplingScheme::Implicit, minIterations, maxIterations);
517 cplScheme.
addDataToSend(mesh->data(sendDataIndex), mesh,
false,
true);
518 cplScheme.
addDataToReceive(mesh->data(receiveDataIndex), mesh,
false,
true);
521 double convergenceLimit1 = sqrt(3.0);
528 runCoupling(cplScheme, context.name, meshConfig, validIterations);
533 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
535 using namespace mesh;
540 _pathToTests +
"serial-implicit-cplscheme-absolute-config.xml");
543 PtrDataConfiguration dataConfig(
new DataConfiguration(root));
544 PtrMeshConfiguration meshConfig(
new MeshConfiguration(root, dataConfig));
550 m2n::PtrM2N m2n = m2nConfig->getM2N(
"Participant0",
"Participant1");
551 useOnlyPrimaryCom(m2n) =
true;
554 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(1.0, 1.0, 1.0));
555 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(2.0, 1.0, -1.0));
556 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(3.0, 1.0, 1.0));
557 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(4.0, 1.0, -1.0));
558 meshConfig->meshes().at(0)->allocateDataValues();
562 if (context.isNamed(
"Participant0")) {
563 m2n->requestPrimaryRankConnection(
"Participant1",
"Participant0");
565 m2n->acceptPrimaryRankConnection(
"Participant1",
"Participant0");
569 context.name, *meshConfig, validIterations);
574 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
577 auto m2n = context.connectPrimaryRanks(
"Participant0",
"Participant1", options);
582 dataConfig->addData(
"data0", mesh::Data::typeName::SCALAR);
583 dataConfig->addData(
"data1", mesh::Data::typeName::VECTOR);
587 mesh->createData(
"data0", 1, 0_dataID);
588 mesh->createData(
"data1", 3, 1_dataID);
589 mesh->createVertex(Eigen::Vector3d::Zero());
590 mesh->allocateDataValues();
595 const double maxTime = 1.0;
596 const int maxTimeWindows = 3;
597 const double timeWindowSize = 0.1;
600 int sendDataIndex = -1;
601 int receiveDataIndex = -1;
602 if (context.isNamed(nameParticipant0)) {
604 receiveDataIndex = 1;
607 receiveDataIndex = 0;
611 const int minIterations = 1;
612 const int maxIterations = 3;
613 cplscheme::SerialCouplingScheme cplScheme(maxTime, maxTimeWindows, timeWindowSize, nameParticipant0, nameParticipant1, context.name, m2n,
constants::FIXED_TIME_WINDOW_SIZE,
BaseCouplingScheme::Implicit, minIterations, maxIterations);
614 cplScheme.
addDataToSend(mesh->data(sendDataIndex), mesh,
false,
true);
615 cplScheme.
addDataToReceive(mesh->data(receiveDataIndex), mesh,
false,
true);
620 runCoupling(cplScheme, context.name, meshConfig, validIterations);
625 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
628 auto m2n = context.connectPrimaryRanks(
"Participant0",
"Participant1", options);
633 dataConfig->addData(
"data0", mesh::Data::typeName::SCALAR);
634 dataConfig->addData(
"data1", mesh::Data::typeName::VECTOR);
638 mesh->createData(
"data0", 1, 0_dataID);
639 mesh->createData(
"data1", 3, 1_dataID);
640 mesh->createVertex(Eigen::Vector3d::Zero());
641 mesh->allocateDataValues();
646 double maxTime = 1.0;
647 int maxTimeWindows = 3;
648 double timeWindowSize = 0.1;
651 int sendDataIndex = -1;
652 int receiveDataIndex = -1;
654 if (context.isNamed(nameParticipant0)) {
656 receiveDataIndex = 1;
657 validIterations = {3, 3, 3};
660 receiveDataIndex = 0;
661 validIterations = {3, 3, 3};
665 const int minIterations = 1;
666 const int maxIterations = 3;
667 cplscheme::SerialCouplingScheme cplScheme(maxTime, maxTimeWindows, timeWindowSize, nameParticipant0, nameParticipant1, context.name, m2n,
constants::FIXED_TIME_WINDOW_SIZE,
BaseCouplingScheme::Implicit, minIterations, maxIterations);
668 cplScheme.
addDataToSend(mesh->data(sendDataIndex), mesh,
false,
true);
669 cplScheme.
addDataToReceive(mesh->data(receiveDataIndex), mesh,
false,
true);
673 cplScheme, context.name, meshConfig, validIterations);
678 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
681 auto m2n = context.connectPrimaryRanks(
"Participant0",
"Participant1", options);
688 dataConfig->addData(
"Data0", mesh::Data::typeName::SCALAR);
689 dataConfig->addData(
"Data1", mesh::Data::typeName::VECTOR);
693 const auto dataID0 = mesh->createData(
"Data0", 1, 0_dataID)->getID();
694 const auto dataID1 = mesh->createData(
"Data1", 3, 1_dataID)->getID();
695 mesh->createVertex(Eigen::Vector3d::Zero());
696 mesh->allocateDataValues();
701 const double maxTime = 1.0;
702 const int maxTimeWindows = 3;
703 const double timeWindowSize = 0.1;
704 const double timeStepSize = timeWindowSize;
707 int sendDataIndex = -1;
708 int receiveDataIndex = -1;
709 bool dataRequiresInitialization =
false;
710 if (context.isNamed(nameParticipant0)) {
711 sendDataIndex = dataID0;
712 receiveDataIndex = dataID1;
714 sendDataIndex = dataID1;
715 receiveDataIndex = dataID0;
716 dataRequiresInitialization =
true;
720 const int minIterations = 1;
721 const int maxIterations = 3;
722 cplscheme::SerialCouplingScheme cplScheme(maxTime, maxTimeWindows, timeWindowSize, nameParticipant0, nameParticipant1, context.name, m2n,
constants::FIXED_TIME_WINDOW_SIZE,
BaseCouplingScheme::Implicit, minIterations, maxIterations);
725 cplScheme.
addDataToSend(mesh->data(sendDataIndex), mesh, dataRequiresInitialization,
true);
726 CouplingData *sendCouplingData = Fixture::getSendData(cplScheme, sendDataIndex);
727 cplScheme.
addDataToReceive(mesh->data(receiveDataIndex), mesh, not dataRequiresInitialization,
true);
728 CouplingData *receiveCouplingData = Fixture::getReceiveData(cplScheme, receiveDataIndex);
731 if (context.isNamed(nameParticipant0)) {
733 BOOST_TEST(receiveCouplingData->
getSize() == 3);
736 BOOST_TEST(sendCouplingData->
getSize() == 1);
739 BOOST_TEST(Fixture::isImplicitCouplingScheme(cplScheme));
744 BOOST_TEST(receiveCouplingData->
getSize() == 3);
749 BOOST_TEST(sendCouplingData->
getSize() == 1);
773 BOOST_TEST(context.isNamed(nameParticipant1));
774 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::InitializeData));
775 Eigen::VectorXd v(3);
779 BOOST_TEST(receiveCouplingData->
getSize() == 1);
781 BOOST_TEST(sendCouplingData->
getSize() == 3);
785 BOOST_TEST(receiveCouplingData->
getSize() == 1);
789 BOOST_TEST(sendCouplingData->
getSize() == 3);