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")) {
56 cplScheme.initialize();
57 BOOST_TEST(not cplScheme.hasDataBeenReceived());
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);
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);
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")) {
102 cplScheme.initialize();
103 BOOST_TEST(cplScheme.hasDataBeenReceived());
104 double value = dataValues0(vertex.
getID());
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);
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);
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) {
172 mesh->data(0)->timeStepsStorage().trim();
174 double dtUsed = dtDesired;
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);
227 }
else if (participantName == nameParticipant1) {
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()});
263 valueData1 += Eigen::VectorXd::Constant(3, 1.0);
267 BOOST_TEST(computedTimesteps == 10);
290 BOOST_TEST(communication);
291 BOOST_TEST(not communication->isConnected());
293 if (participant0 == localParticipant) {
294 communication->requestPrimaryRankConnection(participant1, participant0,
"");
296 BOOST_TEST(participant1 == localParticipant);
297 communication->acceptPrimaryRankConnection(participant1, participant0,
"");
312 auto m2n = context.connectPrimaryRanks(
"Participant0",
"Participant1", options);
320 mesh->createData(
"Data0", 1, 0_dataID);
321 mesh->createData(
"Data1", 3, 1_dataID);
322 mesh->createVertex(Eigen::Vector3d::Zero());
323 mesh->allocateDataValues();
327 const double maxTime = 1.0;
328 const int maxTimeWindows = 10;
329 const double timeWindowSize = 0.1;
332 int sendDataIndex = -1;
333 int receiveDataIndex = -1;
335 if (context.isNamed(nameParticipant0)) {
337 receiveDataIndex = 1;
340 receiveDataIndex = 0;
355 using namespace mesh;
357 std::string configurationPath(_pathToTests +
"explicit-coupling-scheme-1.xml");
370 m2n::PtrM2N m2n = m2nConfig->getM2N(nameParticipant0, nameParticipant1);
373 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(1.0, 1.0, 1.0));
374 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(2.0, 1.0, -1.0));
375 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(3.0, 1.0, 1.0));
376 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(4.0, 1.0, -1.0));
377 meshConfig->meshes().at(0)->allocateDataValues();
379 connect(nameParticipant0, nameParticipant1, context.name,
m2n);
381 context.name, *meshConfig);
390 using namespace mesh;
391 std::string configurationPath(_pathToTests +
"explicit-coupling-scheme-2.xml");
404 m2n::PtrM2N m2n = m2nConfig->getM2N(nameParticipant0, nameParticipant1);
407 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(1.0, 1.0, 1.0));
408 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(2.0, 1.0, -1.0));
409 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(3.0, 1.0, 1.0));
410 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(4.0, 1.0, -1.0));
411 meshConfig->meshes().at(0)->allocateDataValues();
413 connect(nameParticipant0, nameParticipant1, context.name,
m2n);
414 CouplingScheme &cplScheme = *cplSchemeConfig.getCouplingScheme(context.name);
416 double computedTime = 0.0;
417 double maxTime = 1.0;
418 int computedTimesteps = 0;
422 if (context.isNamed(nameParticipant0)) {
423 double solverDt = 0.3;
424 double preciceDt, dt;
434 dt =
std::min({solverDt, preciceDt});
435 mesh->data(0)->setSampleAtTime(computedTime + dt,
time::Sample{
mesh->data(0)->getDimensions(),
mesh->data(0)->values()});
452 BOOST_TEST(computedTimesteps == 4);
456 BOOST_TEST(context.isNamed(nameParticipant1));
480 BOOST_TEST(computedTimesteps == 4);
497 using namespace mesh;
499 std::string configurationPath(_pathToTests +
"serial-explicit-coupling-datainit.xml");
512 m2n::PtrM2N m2n = m2nConfig->getM2N(nameParticipant0, nameParticipant1);
515 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(1.0, 1.0));
516 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(2.0, -1.0));
517 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(3.0, 1.0));
518 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(4.0, -1.0));
519 meshConfig->meshes().at(0)->allocateDataValues();
521 connect(nameParticipant0, nameParticipant1, context.name,
m2n);
522 CouplingScheme &cplScheme = *cplSchemeConfig.getCouplingScheme(context.name);
525 BOOST_TEST(meshConfig->meshes().size() == 1);
527 BOOST_TEST(
mesh->data().size() == 3);
528 auto &dataValues0 =
mesh->data(0)->values();
529 auto &dataValues1 =
mesh->data(1)->values();
530 auto &dataValues2 =
mesh->data(2)->values();
532 BOOST_TEST(
mesh->data(0)->getName() ==
"Data0");
533 BOOST_TEST(
mesh->data(1)->getName() ==
"Data1");
534 BOOST_TEST(
mesh->data(2)->getName() ==
"Data2");
536 if (context.isNamed(nameParticipant0)) {
538 dataValues2(0) = 3.0;
547 dataValues2(0) = 2.0;
549 mesh->data(2)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(2)->getDimensions(), mesh->data(2)->values()});
559 BOOST_TEST(context.isNamed(nameParticipant1));
561 dataValues0(0) = 5.0;
562 dataValues1(0) = 1.0;
569 dataValues0(0) = 4.0;
571 mesh->data(0)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
572 mesh->data(1)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
594 using namespace mesh;
596 std::string configurationPath(_pathToTests +
"parallel-explicit-coupling-datainit.xml");
609 m2n::PtrM2N m2n = m2nConfig->getM2N(nameParticipant0, nameParticipant1);
612 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(1.0, 1.0));
613 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(2.0, -1.0));
614 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(3.0, 1.0));
615 meshConfig->meshes().at(0)->createVertex(Eigen::Vector2d(4.0, -1.0));
616 meshConfig->meshes().at(0)->allocateDataValues();
618 connect(nameParticipant0, nameParticipant1, context.name,
m2n);
619 CouplingScheme &cplScheme = *cplSchemeConfig.getCouplingScheme(context.name);
622 BOOST_TEST(meshConfig->meshes().size() == 1);
624 BOOST_TEST(
mesh->data().size() == 3);
625 auto &dataValues0 =
mesh->data(0)->values();
626 auto &dataValues1 =
mesh->data(1)->values();
627 auto &dataValues2 =
mesh->data(2)->values();
629 BOOST_TEST(
mesh->data(0)->getName() ==
"Data0");
630 BOOST_TEST(
mesh->data(1)->getName() ==
"Data1");
631 BOOST_TEST(
mesh->data(2)->getName() ==
"Data2");
633 if (context.isNamed(nameParticipant0)) {
635 dataValues2(0) = 3.0;
644 dataValues2(0) = 2.0;
646 mesh->data(2)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(2)->getDimensions(), mesh->data(2)->values()});
656 BOOST_TEST(context.isNamed(nameParticipant1));
658 dataValues0(0) = 5.0;
659 dataValues1(0) = 1.0;
666 dataValues0(0) = 4.0;
668 mesh->data(0)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(0)->getDimensions(), mesh->data(0)->values()});
669 mesh->data(1)->setSampleAtTime(cplScheme.
getTime(),
time::Sample{mesh->data(1)->getDimensions(), mesh->data(1)->values()});
688 auto m2n = context.connectPrimaryRanks(
"Participant0",
"Participant1", options);
696 mesh->createData(
"Data0", 1, 0_dataID);
697 mesh->createData(
"Data1", 3, 1_dataID);
698 mesh->createVertex(Eigen::Vector3d::Zero());
699 mesh->allocateDataValues();
700 meshConfig.insertMeshToMeshDimensionsMap(
mesh->getName(),
mesh->getDimensions());
701 meshConfig.addMesh(
mesh);
703 const double maxTime = 1.0;
704 const int maxTimeWindows = 10;
705 const double timeWindowSize = 0.1;
708 int sendDataIndex = -1;
709 int receiveDataIndex = -1;
710 if (context.isNamed(nameParticipant0)) {
712 receiveDataIndex = 1;
715 receiveDataIndex = 0;
718 cplScheme.addDataToSend(
mesh->data(sendDataIndex),
mesh,
false,
true);
719 cplScheme.addDataToReceive(
mesh->data(receiveDataIndex),
mesh,
false,
true);
720 cplScheme.determineInitialDataExchange();
730 using namespace mesh;
732 std::string configurationPath(_pathToTests +
"explicit-coupling-scheme-1.xml");
745 m2n::PtrM2N m2n = m2nConfig->getM2N(nameParticipant0, nameParticipant1);
747 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(1.0, 1.0, 1.0));
748 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(2.0, -1.0, 1.0));
749 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(3.0, 1.0, 1.0));
750 meshConfig->meshes().at(0)->createVertex(Eigen::Vector3d(4.0, -1.0, 1.0));
751 meshConfig->meshes().at(0)->allocateDataValues();
753 connect(nameParticipant0, nameParticipant1, context.name,
m2n);
755 *cplSchemeConfig.getCouplingScheme(context.name), context.name,
BOOST_AUTO_TEST_CASE(testIQNIMVJPPWithSubsteps)
void runSimpleExplicitCoupling(CouplingScheme &cplScheme, const std::string &participantName, const mesh::MeshConfiguration &meshConfig)
void runExplicitCouplingWithSubcycling(CouplingScheme &cplScheme, const std::string &participantName, const mesh::MeshConfiguration &meshConfig)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST_SETUP(...)
Creates and attaches a TestSetup to a Boost test case.
Performs XML configuration of a participant.
void addDataToReceive(const mesh::PtrData &data, mesh::PtrMesh mesh, bool requiresInitialization, bool exchangeSubsteps)
Adds data to be received on data exchange.
void addDataToSend(const mesh::PtrData &data, mesh::PtrMesh mesh, bool requiresInitialization, bool exchangeSubsteps)
Adds data to be sent on data exchange and possibly be modified during coupling iterations.
void determineInitialDataExchange() override
Determines which data is initialized and therefore has to be exchanged during initialize.
Configuration for coupling schemes.
Interface for all coupling schemes.
virtual void initialize()=0
Initializes the coupling scheme and establishes a communication connection to the coupling partner....
@ WriteCheckpoint
Is the participant required to write a checkpoint?
@ ReadCheckpoint
Is the participant required to read a previously written checkpoint?
@ InitializeData
Is the initialization of coupling data required?
virtual ChangedMeshes firstSynchronization(const ChangedMeshes &changes)=0
virtual bool addComputedTime(double timeToAdd)=0
Adds newly computed time. Has to be called before every advance.
virtual double getTime() const =0
Returns the currently computed time of the coupling scheme.
virtual ChangedMeshes secondSynchronization()=0
virtual void markActionFulfilled(Action action)=0
Tells the coupling scheme that the accessor has performed the given action.
virtual void secondExchange()=0
virtual double getNextTimeStepMaxSize() const =0
Returns the maximal size of the next time step to be computed.
virtual bool isTimeWindowComplete() const =0
Returns true, when the accessor can advance to the next time window.
virtual double getTimeWindowSize() const =0
Returns the time window size, if one is given by the coupling scheme.
virtual void finalize()=0
Finalizes the coupling and disconnects communication.
virtual bool isCouplingOngoing() const =0
Returns true, when the coupled simulation is still ongoing.
virtual int getTimeWindows() const =0
Returns the currently computed time windows of the coupling scheme.
virtual bool isActionRequired(Action action) const =0
Returns true, if the given action has to be performed by the accessor.
virtual bool hasDataBeenReceived() const =0
Returns true, if data has been exchanged in last call of advance().
virtual void firstExchange()=0
Coupling scheme for serial coupling, i.e. staggered execution of two coupled participants.
Configuration for communication channels between solvers.
std::shared_ptr< M2NConfiguration > SharedPointer
Performs and provides configuration for Data objects from XML files.
void addMesh(const mesh::PtrMesh &mesh)
void insertMeshToMeshDimensionsMap(const std::string &mesh, int dimensions)
Initialize the map between meshes and dimensions, for unit tests that directly create mesh objects wi...
const std::vector< PtrMesh > & meshes() const
Returns all configured meshes.
Container and creator for meshes.
VertexID getID() const
Returns the unique (among vertices of one mesh on one processor) ID of the vertex.
Represents an XML tag to be configured automatically.
std::shared_ptr< ParticipantConfiguration > PtrParticipantConfiguration
contains implementations of coupling schemes for coupled simulations.
contains the logic of the parallel communication between participants.
std::shared_ptr< M2N > PtrM2N
provides Mesh, Data and primitives.
std::shared_ptr< DataConfiguration > PtrDataConfiguration
std::shared_ptr< Mesh > PtrMesh
std::shared_ptr< MeshConfiguration > PtrMeshConfiguration
@ Events
Require to initialize Event.
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...
std::string getPathToSources()
Returns the base path to the sources.
XMLTag getRootTag()
Returns an empty root tag with name "configuration".
std::string configure(XMLTag &tag, const precice::xml::ConfigurationContext &context, std::string_view configurationFilename)
Configures the given configuration from file configurationFilename.
Main namespace of the precice library.
ExplicitCouplingSchemeFixture()
void connect(const std::string &participant0, const std::string &participant1, const std::string &localParticipant, m2n::PtrM2N &communication)
struct giving access _useOnlyPrimaryCom
static auto useOnlyPrimaryCom(PtrM2N m2n) -> typename std::add_lvalue_reference< decltype(m2n->_useOnlyPrimaryCom)>::type
Tightly coupled to the parameters of Participant()