33#if BITPIT_ENABLE_MPI==1
37#include "bitpit_POD.hpp"
38#include "bitpit_patchkernel.hpp"
39#include "bitpit_voloctree.hpp"
41using namespace bitpit;
50 log::cout() <<
" >> 2D octree patch" <<
"\n";
60 std::unique_ptr<PabloUniform> treePointer = std::unique_ptr<PabloUniform>(
new PabloUniform(x_0, y_0, z_0, l, 2));
63 std::cout <<
" Origin : ( " << octree.
getX0() <<
", " << octree.
getY0() <<
", " << octree.
getZ0() <<
" )" << std::endl;
64 std::cout <<
" Length : " << octree.
getL() << std::endl;
81 patch_2D_original->
update();
83#if BITPIT_ENABLE_MPI==1
88 std::vector<uint64_t> refineList;
89 refineList.push_back( 7);
90 refineList.push_back( 13);
91 refineList.push_back( 15);
92 refineList.push_back( 26);
93 refineList.push_back( 27);
94 refineList.push_back( 31);
95 refineList.push_back( 37);
96 refineList.push_back( 39);
97 refineList.push_back( 49);
98 refineList.push_back( 50);
99 refineList.push_back( 51);
100 refineList.push_back( 53);
101 refineList.push_back( 55);
102 refineList.push_back( 63);
103 refineList.push_back( 78);
104 refineList.push_back(100);
105 refineList.push_back(102);
106 refineList.push_back(105);
107 refineList.push_back(108);
108 refineList.push_back(109);
109 refineList.push_back(110);
110 refineList.push_back(135);
111 refineList.push_back(141);
112 refineList.push_back(143);
113 refineList.push_back(146);
114 refineList.push_back(147);
115 refineList.push_back(151);
116 refineList.push_back(153);
117 refineList.push_back(154);
118 refineList.push_back(155);
119 refineList.push_back(157);
120 refineList.push_back(159);
121 refineList.push_back(165);
122 refineList.push_back(167);
123 refineList.push_back(183);
124 refineList.push_back(198);
125 refineList.push_back(204);
126 refineList.push_back(206);
127 refineList.push_back(225);
128 refineList.push_back(228);
129 refineList.push_back(229);
130 refineList.push_back(230);
133 for (uint64_t ind : refineList) {
134#if BITPIT_ENABLE_MPI==1
136 if (patch_2D_original->
getRank() == owner){
144#if BITPIT_ENABLE_MPI==1
149 patch_2D_original->
update(
false);
152#if BITPIT_ENABLE_MPI==1
153 patch_2D_original->
setVTKWriteTarget(PatchKernel::WriteTarget::WRITE_TARGET_CELLS_INTERNAL);
155 patch_2D_original->
write();
160 std::unique_ptr<PabloUniform> treePointer2 = std::unique_ptr<PabloUniform>(
new PabloUniform(x_0, y_0, z_0, l, 2));
172#if BITPIT_ENABLE_MPI==1
173 patch_2D->
setVTKWriteTarget(PatchKernel::WriteTarget::WRITE_TARGET_CELLS_INTERNAL);
177 for (
int k = 0; k < 10; ++k) {
180 log::cout() <<
">> Marking the cells to adapt... " << std::endl;
182 for (
int i = 0; i < 100; ++i) {
184#if BITPIT_ENABLE_MPI==1
187 cellId = rand() % nCells * 2;
188#if BITPIT_ENABLE_MPI==1
189 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
192 if (!patch_2D->
getCells().exists(cellId)) {
199 for (
int i = 0; i < 55; ++i) {
201#if BITPIT_ENABLE_MPI==1
204 cellId = rand() % nCells * 2;
205#if BITPIT_ENABLE_MPI==1
206 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
209 if (!patch_2D->
getCells().exists(cellId)) {
214 for (
auto neighId : patch_2D->findCellNeighs(cellId)) {
220 log::cout() <<
">> Initial number of cells... " << nCells << std::endl;
228 log::cout() <<
">> Final number of cells... " << nCells << std::endl;
231#if BITPIT_ENABLE_MPI==1
244#if BITPIT_ENABLE_MPI==1
251 mapobject.initialize(
true);
257 for (
Cell & cell : patch_2D_original->getCells()){
258 if (cell.isInterior()){
259 long id = cell.getId();
261 vdata[count] = data[id];
267 patch_2D_original->
getVTK().
addData(
"data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata);
268#if BITPIT_ENABLE_MPI==1
269 patch_2D_original->
setVTKWriteTarget(PatchKernel::WriteTarget::WRITE_TARGET_CELLS_INTERNAL);
271 patch_2D_original->
write();
280#if BITPIT_ENABLE_MPI==1
282 std::map<int, std::map<long, double> > datarec;
284 std::unordered_map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
285 std::unordered_map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();
288 MPI_Comm comm = MPI_COMM_WORLD;
291 std::size_t bytes = uint8_t(
sizeof(
double));
292 for (
const auto &val : rankIDsend){
293 int rank = val.first;
295 std::size_t buffSize = val.second.size() * bytes;
296 dataCommunicator.setSend(rank,buffSize);
298 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
299 for (
long ID : val.second){
300 sendBuffer << data[ID];
304 dataCommunicator.discoverRecvs();
305 dataCommunicator.startAllRecvs();
306 dataCommunicator.startAllSends();
308 for (
const auto &val : rankIDrec){
309 int rank = val.first;
310 dataCommunicator.waitRecv(rank);
311 RecvBuffer & recvBuffer = dataCommunicator.getRecvBuffer(rank);
312 for (
long ID : val.second){
313 recvBuffer >> datarec[rank][ID];
316 dataCommunicator.waitAllSends();
323 for (
Cell & cell : patch_2D->getCells()){
324 if (cell.isInterior()){
325 long id = cell.getId();
326 if (mapper[
id].type == mapping::Type::TYPE_RENUMBERING){
327#if BITPIT_ENABLE_MPI==1
328 if (mapper[
id].ranks[0] == patch_2D->
getRank()){
330 data2[id] = data[mapper[id].ids[0]];
331 vdata2[count] = data2[id];
332#if BITPIT_ENABLE_MPI==1
335 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
336 vdata2[count] = data2[id];
340 else if (mapper[
id].type == mapping::Type::TYPE_COARSENING){
342 int n = mapper[id].ids.size();
344 for (
long idd : mapper[id].ids){
345#if BITPIT_ENABLE_MPI==1
346 if (mapper[
id].ranks[i] == patch_2D->
getRank()){
348 data2[id] += data[idd] / n;
349#if BITPIT_ENABLE_MPI==1
352 data2[id] += datarec[mapper[id].ranks[i]][idd] / n;
357 vdata2[count] = data2[id];
359 else if (mapper[
id].type == mapping::Type::TYPE_REFINEMENT){
360#if BITPIT_ENABLE_MPI==1
361 if (mapper[
id].ranks[0] == patch_2D->
getRank()){
363 data2[id] = data[mapper[id].ids[0]];
364 vdata2[count] = data2[id];
365#if BITPIT_ENABLE_MPI==1
368 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
369 vdata2[count] = data2[id];
377 patch_2D->
getVTK().
addData(
"data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2);
390#if BITPIT_ENABLE_MPI==1
392 std::map<int, std::map<long, double> > datarec;
395 std::map<int, std::set<long> > rankIDsend;
399 for (
Cell & cell : patch_2D->getCells()){
400 long ID = cell.getId();
401 auto info = _mapper[ID];
403 for (
int rank :
info.ranks){
404 if (rank != patch_2D->
getRank()){
405 rankIDsend[rank].insert(ID);
412 MPI_Comm comm = MPI_COMM_WORLD;
415 std::size_t bytes = uint8_t(
sizeof(
double) +
sizeof(
long));
416 for (
const auto &val : rankIDsend){
417 int rank = val.first;
419 std::size_t buffSize = val.second.size() * bytes;
420 dataCommunicator.setSend(rank,buffSize);
422 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
423 for (
long ID : val.second){
425 sendBuffer << data2[ID];
429 dataCommunicator.discoverRecvs();
430 dataCommunicator.startAllRecvs();
431 dataCommunicator.startAllSends();
433 std::vector<int> recvRanks = dataCommunicator.getRecvRanks();
434 std::sort(recvRanks.begin(),recvRanks.end());
436 for (
int rank : recvRanks){
437 dataCommunicator.waitRecv(rank);
438 RecvBuffer & recvBuffer = dataCommunicator.getRecvBuffer(rank);
439 long nof = recvBuffer.
getSize() / bytes;
440 for (
long ii = 0; ii < nof; ii++){
443 recvBuffer >> datarec[rank][ID];
446 dataCommunicator.waitAllSends();
453 for (
Cell & cell : patch_2D_original->getCells()){
454 if (cell.isInterior()){
455 long id = cell.getId();
456 if (mapper[
id].type == mapping::Type::TYPE_RENUMBERING){
457#if BITPIT_ENABLE_MPI==1
458 if (mapper[
id].ranks[0] == patch_2D_original->
getRank()){
460 data2inv[id] = data2[mapper[id].ids[0]];
461 vdata2inv[count] = data2inv[id];
462#if BITPIT_ENABLE_MPI==1
465 data2inv[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
466 vdata2inv[count] = data2inv[id];
470 else if (mapper[
id].type == mapping::Type::TYPE_COARSENING){
472 int n = mapper[id].ids.size();
474 for (
long idd : mapper[id].ids){
475#if BITPIT_ENABLE_MPI==1
476 if (mapper[
id].ranks[i] == patch_2D_original->
getRank()){
478 data2inv[id] += data2[idd] / n;
479#if BITPIT_ENABLE_MPI==1
482 data2inv[id] += datarec[mapper[id].ranks[i]][idd] / n;
487 vdata2inv[count] = data2inv[id];
489 else if (mapper[
id].type == mapping::Type::TYPE_REFINEMENT){
490#if BITPIT_ENABLE_MPI==1
491 if (mapper[
id].ranks[0] == patch_2D_original->
getRank()){
493 data2inv[id] = data2[mapper[id].ids[0]];
494 vdata2inv[count] = data2inv[id];
495#if BITPIT_ENABLE_MPI==1
498 data2inv[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
499 vdata2inv[count] = data2inv[id];
507 patch_2D_original->
getVTK().
addData(
"data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2inv);
509 patch_2D_original->
write();
518int main(
int argc,
char *argv[])
520#if BITPIT_ENABLE_MPI==1
521 MPI_Init(&argc,&argv);
527 }
catch (
const std::exception &exception) {
532#if BITPIT_ENABLE_MPI==1
The Cell class defines the cells.
The DataCommunicator class provides the infrastructure needed to exchange data among processes.
uint32_t getLocalIdx(uint64_t gidx) const
bool adaptGlobalRefine(bool mapper_flag=false)
int getOwnerRank(uint64_t globalIdx) const
void initializeAdjacencies(AdjacenciesBuildStrategy strategy=ADJACENCIES_AUTOMATIC)
void markCellForRefinement(long id)
std::vector< adaption::Info > update(bool trackAdaption=true, bool squeezeStorage=false)
PiercedVector< Cell > & getCells()
virtual long getVertexCount() const
VTKUnstructuredGrid & getVTK()
std::vector< adaption::Info > partition(MPI_Comm communicator, const std::unordered_map< long, int > &cellRanks, bool trackPartitioning, bool squeezeStorage=false, std::size_t haloSize=1)
void markCellForCoarsening(long id)
const MPI_Comm & getCommunicator() const
void initializeInterfaces(InterfacesBuildStrategy strategy=INTERFACES_AUTOMATIC)
void setVTKWriteTarget(WriteTarget targetCells)
virtual long getCellCount() const
void write(VTKWriteMode mode=VTKWriteMode::DEFAULT)
long getInternalCellCount() const
Metafunction for generating a pierced storage.
Buffer to be used for receive communications.
Buffer to be used for send communications.
VTKField & addData(VTKField &&field)
void setName(const std::string &)
The VolOctreeMapper is the class to map two meshes of class VolOctree.
The VolOctree defines a Octree patch.
int getCellLevel(long id) const
PabloUniform & getTree()
Gets a reference to the octree associated with the patch.
long getOctantId(const OctantInfo &octantInfo) const
Logger & cout(log::Level defaultSeverity, log::Visibility defaultVisibility)
Logger & info(log::Visibility defaultVisibility)