46 bool hasMeshBeenGathered =
false;
48 bool twoLevelInitAlreadyUsed =
false;
50 for (
auto &m2n :
_m2ns) {
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().",
111 com::sendMesh(*m2n->getPrimaryRankCommunication(), 0, globalMesh);
123 int numberOfVertices =
_mesh->nVertices();
129 for (
int i = 0; i < numberOfVertices; i++) {
130 _mesh->vertex(i).setGlobalIndex(i);
134 vertexOffsets[0] = numberOfVertices;
135 int globalNumberOfVertices = numberOfVertices;
139 int numberOfSecondaryRankVertices = -1;
141 vertexOffsets[secondaryRank] = numberOfSecondaryRankVertices + vertexOffsets[secondaryRank - 1];
143 globalNumberOfVertices += numberOfSecondaryRankVertices;
147 _mesh->setVertexOffsets(vertexOffsets);
150 _mesh->setGlobalNumberOfVertices(globalNumberOfVertices);
151 PRECICE_DEBUG(
"Broadcast global number of vertices: {}", globalNumberOfVertices);
164 auto & localIds = vertexDistribution[0];
165 localIds.resize(vertexOffsets[0]);
166 std::iota(localIds.begin(), localIds.end(), 0);
170 auto &secondaryIds = vertexDistribution[secondaryRank];
171 for (
int i = vertexOffsets[secondaryRank - 1]; i < vertexOffsets[secondaryRank]; i++) {
172 secondaryIds.push_back(i);
176 _mesh->setVertexDistribution(std::move(vertexDistribution));
181 PRECICE_DEBUG(
"Send number of vertices: {}", numberOfVertices);
185 int globalVertexCounter = -1;
188 for (
int i = 0; i < numberOfVertices; i++) {
189 _mesh->vertex(i).setGlobalIndex(globalVertexCounter + i);
193 int globalNumberOfVertices = -1;
196 _mesh->setGlobalNumberOfVertices(globalNumberOfVertices);
203 _mesh->setVertexOffsets(std::move(vertexOffsets));
209 _mesh->setVertexDistribution([&] {
211 for (
int i = 0; i < numberOfVertices; i++) {
212 vertexDistribution[0].push_back(i);
213 _mesh->vertex(i).setGlobalIndex(i);
215 return vertexDistribution;
218 _mesh->setVertexOffsets({numberOfVertices});
219 _mesh->setGlobalNumberOfVertices(numberOfVertices);
247 _mesh->clearPartitioning();
252 if (not
_m2ns[0]->usesTwoLevelInitialization())
257 PRECICE_ASSERT(
_mesh->getBoundingBox().getDimension() ==
_mesh->getDimensions(),
"The boundingbox of the local mesh is invalid!");
273 bbm.
emplace(secondaryRank, bb);
283 int remoteConnectionMapSize = 0;
290 remoteConnectionMapSize = connectedRanksList.
size();
293 for (
auto &rank : connectedRanksList) {
294 remoteConnectionMap[rank] = {-1};
296 if (remoteConnectionMapSize != 0) {
302 if (remoteConnectionMapSize != 0) {
308 _mesh->setConnectedRanks([&] {
310 for (
const auto &remoteRank : remoteConnectionMap) {
311 for (
const auto &includedRank : remoteRank.second) {
325 if (!connectedRanksList.
empty()) {
326 for (
Rank rank : connectedRanksList) {
327 remoteConnectionMap[rank] = {-1};
333 _mesh->setConnectedRanks([&] {
335 for (
const auto &remoteRank : remoteConnectionMap) {
336 for (
int includedRanks : remoteRank.second) {