38 const
std::
string & participantName,
39 const mesh::MeshConfiguration &meshConfig)
41 BOOST_TEST(meshConfig.meshes().size() == 1);
43 BOOST_TEST(mesh->data().size() == 2);
44 auto &dataValues0 = mesh->data(0)->values();
45 auto &dataValues1 = mesh->data(1)->values();
46 BOOST_TEST(mesh->nVertices() > 0);
48 double valueData0 = 1.0;
49 Eigen::VectorXd valueData1 = Eigen::VectorXd::Constant(3, 1.0);
51 double computedTime = 0.0;
52 int computedTimesteps = 0;
54 if (participantName ==
std::string(
"Participant0")) {
55 mesh->data(0)->setSampleAtTime(0,
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
56 cplScheme.initialize(0.0, 1);
57 BOOST_TEST(not cplScheme.hasDataBeenReceived());
58 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
59 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
60 BOOST_TEST(not cplScheme.isTimeWindowComplete());
61 BOOST_TEST(cplScheme.isCouplingOngoing());
62 while (cplScheme.isCouplingOngoing()) {
63 dataValues0(vertex.
getID()) = valueData0;
64 BOOST_TEST(cplScheme.getNextTimeStepMaxSize() > 0.0);
65 computedTime += cplScheme.getNextTimeStepMaxSize();
67 cplScheme.addComputedTime(cplScheme.getNextTimeStepMaxSize());
68 mesh->data(0)->setSampleAtTime(cplScheme.getTime(),
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
69 cplScheme.firstSynchronization({});
70 cplScheme.firstExchange();
71 cplScheme.secondSynchronization();
72 cplScheme.secondExchange();
73 BOOST_TEST(cplScheme.isTimeWindowComplete());
75 BOOST_TEST(computedTimesteps == cplScheme.getTimeWindows() - 1);
76 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
77 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
78 BOOST_TEST(cplScheme.isTimeWindowComplete());
79 if (cplScheme.isCouplingOngoing()) {
82 Eigen::VectorXd value = dataValues1.segment(vertex.
getID() * 3, 3);
85 BOOST_TEST(cplScheme.hasDataBeenReceived());
89 valueData1 += Eigen::VectorXd::Constant(3, 1.0);
94 BOOST_TEST(computedTimesteps == 10);
95 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
96 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
97 BOOST_TEST(cplScheme.isTimeWindowComplete());
98 BOOST_TEST(not cplScheme.isCouplingOngoing());
99 BOOST_TEST(cplScheme.getNextTimeStepMaxSize() == 0.0);
100 }
else if (participantName ==
std::string(
"Participant1")) {
101 mesh->data(1)->setSampleAtTime(0,
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
102 cplScheme.initialize(0.0, 1);
103 BOOST_TEST(cplScheme.hasDataBeenReceived());
104 double value = dataValues0(vertex.
getID());
107 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
108 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
109 BOOST_TEST(not cplScheme.isTimeWindowComplete());
110 BOOST_TEST(cplScheme.isCouplingOngoing());
111 while (cplScheme.isCouplingOngoing()) {
112 dataValues1.segment(vertex.
getID() * 3, 3) = valueData1;
113 BOOST_TEST(cplScheme.getNextTimeStepMaxSize() > 0.0);
114 computedTime += cplScheme.getNextTimeStepMaxSize();
116 cplScheme.addComputedTime(cplScheme.getNextTimeStepMaxSize());
117 mesh->data(1)->setSampleAtTime(cplScheme.getTime(),
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
118 cplScheme.firstSynchronization({});
119 cplScheme.firstExchange();
120 cplScheme.secondSynchronization();
121 cplScheme.secondExchange();
123 BOOST_TEST(computedTimesteps == cplScheme.getTimeWindows() - 1);
124 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
125 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
126 BOOST_TEST(cplScheme.isTimeWindowComplete());
127 if (cplScheme.isCouplingOngoing()) {
130 BOOST_TEST(cplScheme.hasDataBeenReceived());
131 double value = dataValues0(vertex.
getID());
135 valueData1 += Eigen::VectorXd::Constant(3, 1.0);
137 cplScheme.finalize();
140 BOOST_TEST(computedTimesteps == 10);
141 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::WriteCheckpoint));
142 BOOST_TEST(not cplScheme.isActionRequired(CouplingScheme::Action::ReadCheckpoint));
143 BOOST_TEST(cplScheme.isTimeWindowComplete());
144 BOOST_TEST(not cplScheme.isCouplingOngoing());
145 BOOST_TEST(cplScheme.getNextTimeStepMaxSize() == 0.0);
154 BOOST_TEST(meshConfig.
meshes().size() == 1);
156 BOOST_TEST(mesh->data().size() == 2);
157 BOOST_TEST(mesh->nVertices() > 0);
159 double valueData0 = 1.0;
160 Eigen::VectorXd valueData1 = Eigen::VectorXd::Constant(3, 1.0);
161 auto & dataValues0 = mesh->data(0)->values();
162 auto & dataValues1 = mesh->data(1)->values();
164 double computedTime = 0.0;
165 int computedTimesteps = 0;
168 BOOST_TEST(((participantName == nameParticipant0) || (participantName == nameParticipant1)));
169 if (participantName == nameParticipant0) {
170 mesh->data(0)->setSampleAtTime(0,
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
172 mesh->data(0)->timeStepsStorage().trim();
174 double dtUsed = dtDesired;
176 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
177 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
188 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
189 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
190 dataValues0(vertex.
getID()) = valueData0;
191 computedTime += dtUsed;
194 mesh->data(0)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
199 if (computedTimesteps % 2 == 0) {
206 Eigen::VectorXd value = dataValues1.segment(vertex.
getID() * 3, 3);
213 valueData1 += Eigen::VectorXd::Constant(3, 1.0);
214 mesh->data(0)->timeStepsStorage().trim();
221 BOOST_TEST(computedTimesteps == 20);
222 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
223 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
227 }
else if (participantName == nameParticipant1) {
229 mesh->data(1)->setSampleAtTime(0,
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
235 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
236 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
240 dataValues1.segment(vertex.
getID() * 3, 3) = valueData1;
245 mesh->data(1)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
252 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
253 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
263 valueData1 += Eigen::VectorXd::Constant(3, 1.0);
267 BOOST_TEST(computedTimesteps == 10);
268 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::WriteCheckpoint));
269 BOOST_TEST(not cplScheme.
isActionRequired(CouplingScheme::Action::ReadCheckpoint));
308 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
311 auto m2n = context.connectPrimaryRanks(
"Participant0",
"Participant1", options);
315 dataConfig->addData(
"Data0", mesh::Data::typeName::SCALAR);
316 dataConfig->addData(
"Data1", mesh::Data::typeName::VECTOR);
319 mesh->createData(
"Data0", 1, 0_dataID);
320 mesh->createData(
"Data1", 3, 1_dataID);
321 mesh->createVertex(Eigen::Vector3d::Zero());
322 mesh->allocateDataValues();
326 const double maxTime = 1.0;
327 const int maxTimeWindows = 10;
328 const double timeWindowSize = 0.1;
329 const double timeStepSize = timeWindowSize;
332 int sendDataIndex = -1;
333 int receiveDataIndex = -1;
335 if (context.isNamed(nameParticipant0)) {
337 receiveDataIndex = 1;
340 receiveDataIndex = 0;
343 cplScheme.
addDataToSend(mesh->data(sendDataIndex), mesh,
false,
true);
344 cplScheme.
addDataToReceive(mesh->data(receiveDataIndex), mesh,
false,
true);
352 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
354 using namespace mesh;
356 std::string configurationPath(_pathToTests +
"explicit-coupling-scheme-1.xml");
361 PtrDataConfiguration dataConfig(
new DataConfiguration(root));
362 PtrMeshConfiguration meshConfig(
new MeshConfiguration(root, dataConfig));
369 m2n::PtrM2N m2n = m2nConfig->getM2N(nameParticipant0, nameParticipant1);
372 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(1.0, 1.0, 1.0));
373 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(2.0, 1.0, -1.0));
374 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(3.0, 1.0, 1.0));
375 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(4.0, 1.0, -1.0));
376 meshConfig->meshes().at(0)->allocateDataValues();
378 connect(nameParticipant0, nameParticipant1, context.name, m2n);
380 context.name, *meshConfig);
386 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
388 using namespace mesh;
389 std::string configurationPath(_pathToTests +
"explicit-coupling-scheme-2.xml");
394 PtrDataConfiguration dataConfig(
new DataConfiguration(root));
395 PtrMeshConfiguration meshConfig(
new MeshConfiguration(root, dataConfig));
402 m2n::PtrM2N m2n = m2nConfig->getM2N(nameParticipant0, nameParticipant1);
405 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(1.0, 1.0, 1.0));
406 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(2.0, 1.0, -1.0));
407 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(3.0, 1.0, 1.0));
408 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(4.0, 1.0, -1.0));
409 meshConfig->meshes().at(0)->allocateDataValues();
411 connect(nameParticipant0, nameParticipant1, context.name, m2n);
414 double computedTime = 0.0;
415 double maxTime = 1.0;
416 int computedTimesteps = 0;
420 if (context.isNamed(nameParticipant0)) {
421 double solverDt = 0.3;
422 double preciceDt, dt;
423 mesh->data(0)->setSampleAtTime(0,
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
432 dt =
std::min({solverDt, preciceDt});
433 mesh->data(0)->setSampleAtTime(computedTime + dt,
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
450 BOOST_TEST(computedTimesteps == 4);
454 BOOST_TEST(context.isNamed(nameParticipant1));
455 mesh->data(1)->setSampleAtTime(0,
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
461 mesh->data(1)->setSampleAtTime(computedTime + cplScheme.
getTimeWindowSize(),
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
478 BOOST_TEST(computedTimesteps == 4);
492 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
494 using namespace mesh;
496 std::string configurationPath(_pathToTests +
"serial-explicit-coupling-datainit.xml");
501 PtrDataConfiguration dataConfig(
new DataConfiguration(root));
502 PtrMeshConfiguration meshConfig(
new MeshConfiguration(root, dataConfig));
509 m2n::PtrM2N m2n = m2nConfig->getM2N(nameParticipant0, nameParticipant1);
512 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(1.0, 1.0));
513 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(2.0, -1.0));
514 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(3.0, 1.0));
515 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(4.0, -1.0));
516 meshConfig->meshes().at(0)->allocateDataValues();
518 connect(nameParticipant0, nameParticipant1, context.name, m2n);
520 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::InitializeData));
522 BOOST_TEST(meshConfig->meshes().size() == 1);
524 BOOST_TEST(mesh->data().size() == 3);
525 auto &dataValues0 = mesh->data(0)->values();
526 auto &dataValues1 = mesh->data(1)->values();
527 auto &dataValues2 = mesh->data(2)->values();
529 BOOST_TEST(mesh->data(0)->getName() ==
"Data0");
530 BOOST_TEST(mesh->data(1)->getName() ==
"Data1");
531 BOOST_TEST(mesh->data(2)->getName() ==
"Data2");
533 if (context.isNamed(nameParticipant0)) {
534 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::InitializeData));
535 dataValues2(0) = 3.0;
538 mesh->data(2)->setSampleAtTime(0,
time::Sample{mesh->data(2)->getDimensions(), mesh->data(2)->values()});
544 dataValues2(0) = 2.0;
546 mesh->data(2)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(2)->getDimensions(), mesh->data(2)->values()});
556 BOOST_TEST(context.isNamed(nameParticipant1));
557 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::InitializeData));
558 dataValues0(0) = 5.0;
559 dataValues1(0) = 1.0;
561 mesh->data(0)->setSampleAtTime(0,
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
562 mesh->data(1)->setSampleAtTime(0,
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
566 dataValues0(0) = 4.0;
568 mesh->data(0)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
569 mesh->data(1)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
588 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
590 using namespace mesh;
592 std::string configurationPath(_pathToTests +
"parallel-explicit-coupling-datainit.xml");
597 PtrDataConfiguration dataConfig(
new DataConfiguration(root));
598 PtrMeshConfiguration meshConfig(
new MeshConfiguration(root, dataConfig));
605 m2n::PtrM2N m2n = m2nConfig->getM2N(nameParticipant0, nameParticipant1);
608 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(1.0, 1.0));
609 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(2.0, -1.0));
610 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(3.0, 1.0));
611 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(4.0, -1.0));
612 meshConfig->meshes().at(0)->allocateDataValues();
614 connect(nameParticipant0, nameParticipant1, context.name, m2n);
616 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::InitializeData));
618 BOOST_TEST(meshConfig->meshes().size() == 1);
620 BOOST_TEST(mesh->data().size() == 3);
621 auto &dataValues0 = mesh->data(0)->values();
622 auto &dataValues1 = mesh->data(1)->values();
623 auto &dataValues2 = mesh->data(2)->values();
625 BOOST_TEST(mesh->data(0)->getName() ==
"Data0");
626 BOOST_TEST(mesh->data(1)->getName() ==
"Data1");
627 BOOST_TEST(mesh->data(2)->getName() ==
"Data2");
629 if (context.isNamed(nameParticipant0)) {
630 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::InitializeData));
631 dataValues2(0) = 3.0;
634 mesh->data(2)->setSampleAtTime(0,
time::Sample{mesh->data(2)->getDimensions(), mesh->data(2)->values()});
640 dataValues2(0) = 2.0;
642 mesh->data(2)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(2)->getDimensions(), mesh->data(2)->values()});
652 BOOST_TEST(context.isNamed(nameParticipant1));
653 BOOST_TEST(cplScheme.
isActionRequired(CouplingScheme::Action::InitializeData));
654 dataValues0(0) = 5.0;
655 dataValues1(0) = 1.0;
657 mesh->data(0)->setSampleAtTime(0,
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
658 mesh->data(1)->setSampleAtTime(0,
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
662 dataValues0(0) = 4.0;
664 mesh->data(0)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
665 mesh->data(1)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
680 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
683 auto m2n = context.connectPrimaryRanks(
"Participant0",
"Participant1", options);
687 dataConfig->addData(
"Data0", mesh::Data::typeName::SCALAR);
688 dataConfig->addData(
"Data1", mesh::Data::typeName::VECTOR);
691 mesh->createData(
"Data0", 1, 0_dataID);
692 mesh->createData(
"Data1", 3, 1_dataID);
693 mesh->createVertex(Eigen::Vector3d::Zero());
694 mesh->allocateDataValues();
698 const double maxTime = 1.0;
699 const int maxTimeWindows = 10;
700 const double timeWindowSize = 0.1;
701 const double timeStepSize = timeWindowSize;
704 int sendDataIndex = -1;
705 int receiveDataIndex = -1;
706 if (context.isNamed(nameParticipant0)) {
708 receiveDataIndex = 1;
711 receiveDataIndex = 0;
714 cplScheme.
addDataToSend(mesh->data(sendDataIndex), mesh,
false,
true);
715 cplScheme.
addDataToReceive(mesh->data(receiveDataIndex), mesh,
false,
true);
723 PRECICE_TEST(
"Participant0"_on(1_rank),
"Participant1"_on(1_rank), Require::Events);
725 using namespace mesh;
727 std::string configurationPath(_pathToTests +
"explicit-coupling-scheme-1.xml");
732 PtrDataConfiguration dataConfig(
new DataConfiguration(root));
733 PtrMeshConfiguration meshConfig(
new MeshConfiguration(root, dataConfig));
740 m2n::PtrM2N m2n = m2nConfig->getM2N(nameParticipant0, nameParticipant1);
742 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(1.0, 1.0, 1.0));
743 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(2.0, -1.0, 1.0));
744 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(3.0, 1.0, 1.0));
745 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(4.0, -1.0, 1.0));
746 meshConfig->meshes().at(0)->allocateDataValues();
748 connect(nameParticipant0, nameParticipant1, context.name, m2n);