preCICE v3.1.2
Loading...
Searching...
No Matches
M2N.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <memory>
5#include <string>
6#include <type_traits>
7#include <vector>
9#include "SharedPointer.hpp"
10#include "com/SharedPointer.hpp"
11#include "logging/Logger.hpp"
14
15namespace precice {
16namespace mesh {
17class Mesh;
18} // namespace mesh
19
20namespace m2n {
21
22// Forward declaration to friend unit tests which only use the primary com
23struct WhiteboxAccessor;
24
31class M2N {
32public:
33 M2N(com::PtrCommunication intraComm, DistributedComFactory::SharedPointer distrFactory, bool useOnlyPrimaryCom = false, bool useTwoLevelInit = false);
34
36 ~M2N();
37
39 bool isConnected();
40
47 void acceptPrimaryRankConnection(const std::string &acceptorName,
48 const std::string &requesterName);
49
56 void requestPrimaryRankConnection(const std::string &acceptorName,
57 const std::string &requesterName);
58
65 void acceptSecondaryRanksConnection(const std::string &acceptorName,
66 const std::string &requesterName);
67
74 void requestSecondaryRanksConnection(const std::string &acceptorName,
75 const std::string &requesterName);
76
81 void acceptSecondaryRanksPreConnection(const std::string &acceptorName,
82 const std::string &requesterName);
83
88 void requestSecondaryRanksPreConnection(const std::string &acceptorName,
89 const std::string &requesterName);
90
91 /*
92 * @brief After preliminary communication channels were set up and after
93 * the mesh partitions were communicated locally for every mesh,
94 * call this function to update and complete the communication
95 * channels for every communicated mesh
96 */
98
111 void prepareEstablishment(const std::string &acceptorName,
112 const std::string &requesterName);
113
126 void cleanupEstablishment(const std::string &acceptorName,
127 const std::string &requesterName);
128
135 void closeConnection();
136
139
142
145
148
150 void send(precice::span<double const> itemsToSend,
151 int meshID,
152 int valueDimension);
153
158 void send(bool itemToSend);
159
164 void send(double itemToSend);
165
170 void send(precice::span<double const> itemsToSend);
171
176 void send(int itemToSend);
177
179 void broadcastSendMesh(mesh::Mesh &mesh);
180
182 void scatterAllCommunicationMap(std::map<int, std::vector<int>> &localCommunicationMap, mesh::Mesh &mesh);
183
185 void broadcastSend(int itemToSend, mesh::Mesh &mesh);
186
190 void receive(precice::span<double> itemsToReceive,
191 int meshID,
192 int valueDimension);
193
195 void receive(bool &itemToReceive);
196
198 void receive(double &itemToReceive);
199
201 void receive(precice::span<double> itemsToReceive);
202
204 void receive(int &itemToReceive);
205
208
210 void gatherAllCommunicationMap(std::map<int, std::vector<int>> &localCommunicationMap, mesh::Mesh &mesh);
211
216 void broadcastReceiveAll(std::vector<int> &itemToReceive, mesh::Mesh &mesh);
217
219 {
220 return _useTwoLevelInit;
221 }
222
223private:
225
228
230
232
234
236
237 // The following flag is (solely) needed for unit tests between two serial participants.
238 // To also use the secondary communication would require a lengthy setup of meshes
239 // and their re-partitioning, which could also not be moved to some fixture as the M2Ns
240 // are created through the configuration.
241 // See e.g. "CplSchemeTests/ExplicitCouplingSchemeTests/testConfiguredSimpleExplicitCoupling"
242 // This flag gives a loophole. It is set to false for normal use and modified in the
243 // respective tests through a friend declaration.
244
246 bool _useOnlyPrimaryCom = false;
247
249 bool _useTwoLevelInit = false;
250
251 // @brief To allow access to _useOnlyPrimaryCom
252 friend struct WhiteboxAccessor;
253};
254
257 static auto useOnlyPrimaryCom(PtrM2N m2n) -> typename std::add_lvalue_reference<decltype(m2n->_useOnlyPrimaryCom)>::type
258 {
259 return m2n->_useOnlyPrimaryCom;
260 }
261};
262
263} // namespace m2n
264} // namespace precice
This class provides a lightweight logger.
Definition Logger.hpp:16
M2N communication class. This layer is necessary since communication between two participants can be ...
Definition M2N.hpp:31
void scatterAllCommunicationMap(std::map< int, std::vector< int > > &localCommunicationMap, mesh::Mesh &mesh)
Scatters a communication map over connected ranks on remote participant (concerning the given mesh)
Definition M2N.cpp:277
com::PtrCommunication _intraComm
Definition M2N.hpp:229
void broadcastReceiveAll(std::vector< int > &itemToReceive, mesh::Mesh &mesh)
Receives an int per connected rank on remote participant (concerning the given mesh) @para[out] itemT...
Definition M2N.cpp:370
bool _isPrimaryRankConnected
Definition M2N.hpp:233
void closeDistributedConnections()
Disconnects all connections of the DistributedCommunication.
Definition M2N.cpp:180
void createDistributedCommunication(const mesh::PtrMesh &mesh)
Creates a new distributes communication for that mesh, stores the pointer in _distComs.
Definition M2N.cpp:201
void closePrimaryRankConnection()
Disconnects the primary connection.
Definition M2N.cpp:168
std::map< int, DistributedCommunication::SharedPointer > _distComs
mesh::getID() -> Pointer to distributed communication
Definition M2N.hpp:227
logging::Logger _log
Definition M2N.hpp:224
void cleanupEstablishment(const std::string &acceptorName, const std::string &requesterName)
cleans-up to establish the connections
Definition M2N.cpp:118
void gatherAllCommunicationMap(std::map< int, std::vector< int > > &localCommunicationMap, mesh::Mesh &mesh)
Gathers a communication maps from connected ranks on remote participant (concerning the given mesh)
Definition M2N.cpp:390
void broadcastSendMesh(mesh::Mesh &mesh)
Broadcasts a mesh to connected ranks on remote participant (concerning the given mesh)
Definition M2N.cpp:266
void closeConnection()
Disconnects from communication space, i.e. participant.
Definition M2N.cpp:161
void requestPrimaryRankConnection(const std::string &acceptorName, const std::string &requesterName)
Connects to another participant, which has to call acceptConnection().
Definition M2N.cpp:59
com::PtrCommunication getPrimaryRankCommunication()
Get the basic communication between the 2 primary ranks.
Definition M2N.cpp:195
void acceptSecondaryRanksPreConnection(const std::string &acceptorName, const std::string &requesterName)
Definition M2N.cpp:125
bool _useOnlyPrimaryCom
between two serial participants, only use the primary com and no secondary com
Definition M2N.hpp:246
void acceptSecondaryRanksConnection(const std::string &acceptorName, const std::string &requesterName)
Connects to another participant, which has to call requestConnection().
Definition M2N.cpp:77
void requestSecondaryRanksConnection(const std::string &acceptorName, const std::string &requesterName)
Connects to another participant, which has to call acceptConnection().
Definition M2N.cpp:94
bool _areSecondaryRanksConnected
Definition M2N.hpp:235
void broadcastReceiveAllMesh(mesh::Mesh &mesh)
Receive mesh partitions per connected rank on remote participant (concerning the given mesh)
Definition M2N.cpp:379
void requestSecondaryRanksPreConnection(const std::string &acceptorName, const std::string &requesterName)
Definition M2N.cpp:139
DistributedComFactory::SharedPointer _distrFactory
Definition M2N.hpp:231
M2N(com::PtrCommunication intraComm, DistributedComFactory::SharedPointer distrFactory, bool useOnlyPrimaryCom=false, bool useTwoLevelInit=false)
Definition M2N.cpp:21
bool usesTwoLevelInitialization()
Definition M2N.hpp:218
bool isConnected()
Returns true, if a connection to a remote participant has been setup.
Definition M2N.cpp:36
void broadcastSend(int itemToSend, mesh::Mesh &mesh)
Broadcasts an int to connected ranks on remote participant (concerning the given mesh)
Definition M2N.cpp:287
void completeSecondaryRanksConnection()
Definition M2N.cpp:153
bool _useTwoLevelInit
use the two-level initialization concept
Definition M2N.hpp:249
void prepareEstablishment(const std::string &acceptorName, const std::string &requesterName)
prepares to establish the connections
Definition M2N.cpp:111
~M2N()
Destructor, empty.
Definition M2N.cpp:29
void send(precice::span< double const > itemsToSend, int meshID, int valueDimension)
Sends an array of double values from all ranks (different for each rank).
Definition M2N.cpp:208
void receive(precice::span< double > itemsToReceive, int meshID, int valueDimension)
Definition M2N.cpp:296
void acceptPrimaryRankConnection(const std::string &acceptorName, const std::string &requesterName)
Connects to another participant, which has to call requestConnection().
Definition M2N.cpp:41
Container and creator for meshes.
Definition Mesh.hpp:39
A C++ 11 implementation of the non-owning C++20 std::span type.
Definition span.hpp:284
Main namespace of the precice library.
struct giving access _useOnlyPrimaryCom
Definition M2N.hpp:256
static auto useOnlyPrimaryCom(PtrM2N m2n) -> typename std::add_lvalue_reference< decltype(m2n->_useOnlyPrimaryCom)>::type
Definition M2N.hpp:257