46 bool hasMeshBeenGathered =
false;
48 bool twoLevelInitAlreadyUsed =
false;
51 if (
m2n->usesTwoLevelInitialization()) {
53 PRECICE_CHECK(not twoLevelInitAlreadyUsed,
"Two-level initialization does not yet support multiple receivers of a provided mesh. "
54 "Please either switch two-level initialization off in your m2n definition, or "
55 "adapt your mesh setup such that each provided mesh is only received by maximum one "
57 twoLevelInitAlreadyUsed =
true;
63 _m2ns[0]->getPrimaryRankCommunication()->send(
_mesh->getGlobalNumberOfVertices(), 0);
69 const int minGlobalVertexID = vertexOffset -
_mesh->nVertices();
70 const int maxGlobalVertexID = vertexOffset - 1;
73 _m2ns[0]->broadcastSend(minGlobalVertexID, *
_mesh);
74 _m2ns[0]->broadcastSend(maxGlobalVertexID, *
_mesh);
81 if (not hasMeshBeenGathered) {
94 PRECICE_DEBUG(
"Received sub-mesh, from secondary rank: {}, global vertexCount: {}", secondaryRank, globalMesh.
nVertices());
100 hasMeshBeenGathered =
true;
109 "The provided mesh \"{}\" is empty. Please set the mesh using setMeshVertex()/setMeshVertices() prior to calling initialize().",
127 int numberOfVertices =
_mesh->nVertices();
133 for (
int i = 0; i < numberOfVertices; i++) {
134 _mesh->vertex(i).setGlobalIndex(i);
138 vertexOffsets[0] = numberOfVertices;
139 int globalNumberOfVertices = numberOfVertices;
143 int numberOfSecondaryRankVertices = -1;
145 vertexOffsets[secondaryRank] = numberOfSecondaryRankVertices + vertexOffsets[secondaryRank - 1];
147 globalNumberOfVertices += numberOfSecondaryRankVertices;
149 PRECICE_ASSERT(std::all_of(vertexOffsets.begin(), vertexOffsets.end(), [](
auto i) { return i >= 0; }));
150 _mesh->setVertexOffsets(vertexOffsets);
153 _mesh->setGlobalNumberOfVertices(globalNumberOfVertices);
154 PRECICE_DEBUG(
"Broadcast global number of vertices: {}", globalNumberOfVertices);
167 auto &localIds = vertexDistribution[0];
168 localIds.resize(vertexOffsets[0]);
169 std::iota(localIds.begin(), localIds.end(), 0);
173 auto &secondaryIds = vertexDistribution[secondaryRank];
174 for (
int i = vertexOffsets[secondaryRank - 1]; i < vertexOffsets[secondaryRank]; i++) {
175 secondaryIds.push_back(i);
179 _mesh->setVertexDistribution(std::move(vertexDistribution));
184 PRECICE_DEBUG(
"Send number of vertices: {}", numberOfVertices);
188 int globalVertexCounter = -1;
191 for (
int i = 0; i < numberOfVertices; i++) {
192 _mesh->vertex(i).setGlobalIndex(globalVertexCounter + i);
196 int globalNumberOfVertices = -1;
199 _mesh->setGlobalNumberOfVertices(globalNumberOfVertices);
206 _mesh->setVertexOffsets(std::move(vertexOffsets));
210 _mesh->setVertexDistribution([&] {
212 for (
int i = 0; i < numberOfVertices; i++) {
213 vertexDistribution[0].push_back(i);
214 _mesh->vertex(i).setGlobalIndex(i);
216 return vertexDistribution;
218 _mesh->setVertexOffsets({numberOfVertices});
219 _mesh->setGlobalNumberOfVertices(numberOfVertices);
249 _mesh->clearPartitioning();
257 if (not
_m2ns[0]->usesTwoLevelInitialization())
262 PRECICE_ASSERT(
_mesh->getBoundingBox().getDimension() ==
_mesh->getDimensions(),
"The boundingbox of the local mesh is invalid!");
272 bbm.emplace(0,
_mesh->getBoundingBox());
273 PRECICE_ASSERT(!bbm.empty(),
"The bounding box of the local mesh is invalid!");
278 bbm.emplace(secondaryRank, bb);
288 int remoteConnectionMapSize = 0;
294 std::vector<Rank> connectedRanksList =
_m2ns[0]->getPrimaryRankCommunication()->receiveRange(0,
com::asVector<Rank>);
295 remoteConnectionMapSize = connectedRanksList.size();
298 for (
auto &rank : connectedRanksList) {
299 remoteConnectionMap[rank] = {-1};
301 if (remoteConnectionMapSize != 0) {
307 if (remoteConnectionMapSize != 0) {
313 _mesh->setConnectedRanks([&] {
314 std::vector<Rank> ranks;
315 for (
const auto &remoteRank : remoteConnectionMap) {
316 for (
const auto &includedRank : remoteRank.second) {
318 ranks.push_back(remoteRank.first);
326 std::vector<Rank> connectedRanksList;
330 if (!connectedRanksList.empty()) {
331 for (
Rank rank : connectedRanksList) {
332 remoteConnectionMap[rank] = {-1};
338 _mesh->setConnectedRanks([&] {
339 std::vector<Rank> ranks;
340 for (
const auto &remoteRank : remoteConnectionMap) {
341 for (
int includedRanks : remoteRank.second) {
343 ranks.push_back(remoteRank.first);