34#if BITPIT_ENABLE_MPI==1
38#include "bitpit_POD.hpp"
39#include "bitpit_patchkernel.hpp"
40#include "bitpit_voloctree.hpp"
42using namespace bitpit;
48void runReferenceAdaptation()
51 log::cout() <<
" >> 2D octree patch" <<
"\n";
61 std::unique_ptr<PabloUniform> treePointer = std::unique_ptr<PabloUniform>(
new PabloUniform(x_0, y_0, z_0, l, 2));
64 std::cout <<
" Origin : ( " << octree.
getX0() <<
", " << octree.
getY0() <<
", " << octree.
getZ0() <<
" )" << std::endl;
65 std::cout <<
" Length : " << octree.
getL() << std::endl;
82 patch_2D_original->
update();
84#if BITPIT_ENABLE_MPI==1
89 std::vector<uint64_t> refineList;
90 refineList.push_back( 7);
91 refineList.push_back( 13);
92 refineList.push_back( 15);
93 refineList.push_back( 26);
94 refineList.push_back( 27);
95 refineList.push_back( 31);
96 refineList.push_back( 37);
97 refineList.push_back( 39);
98 refineList.push_back( 49);
99 refineList.push_back( 50);
100 refineList.push_back( 51);
101 refineList.push_back( 53);
102 refineList.push_back( 55);
103 refineList.push_back( 63);
104 refineList.push_back( 78);
105 refineList.push_back(100);
106 refineList.push_back(102);
107 refineList.push_back(105);
108 refineList.push_back(108);
109 refineList.push_back(109);
110 refineList.push_back(110);
111 refineList.push_back(135);
112 refineList.push_back(141);
113 refineList.push_back(143);
114 refineList.push_back(146);
115 refineList.push_back(147);
116 refineList.push_back(151);
117 refineList.push_back(153);
118 refineList.push_back(154);
119 refineList.push_back(155);
120 refineList.push_back(157);
121 refineList.push_back(159);
122 refineList.push_back(165);
123 refineList.push_back(167);
124 refineList.push_back(183);
125 refineList.push_back(198);
126 refineList.push_back(204);
127 refineList.push_back(206);
128 refineList.push_back(225);
129 refineList.push_back(228);
130 refineList.push_back(229);
131 refineList.push_back(230);
134 for (uint64_t ind : refineList) {
135#if BITPIT_ENABLE_MPI==1
137 if (patch_2D_original->
getRank() == owner){
145#if BITPIT_ENABLE_MPI==1
150 patch_2D_original->
update(
false);
155 std::unique_ptr<PabloUniform> treePointer2 = std::unique_ptr<PabloUniform>(
new PabloUniform(x_0, y_0, z_0, l, 2));
167#if BITPIT_ENABLE_MPI==1
168 patch_2D->
setVTKWriteTarget(PatchKernel::WriteTarget::WRITE_TARGET_CELLS_INTERNAL);
172 for (
int k = 0; k < 10; ++k) {
175 log::cout() <<
">> Marking the cells to adapt... " << std::endl;
177 for (
int i = 0; i < 100; ++i) {
179#if BITPIT_ENABLE_MPI==1
182 cellId = rand() % nCells * 2;
183#if BITPIT_ENABLE_MPI==1
184 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
187 if (!patch_2D->
getCells().exists(cellId)) {
194 for (
int i = 0; i < 55; ++i) {
196#if BITPIT_ENABLE_MPI==1
199 cellId = rand() % nCells * 2;
200#if BITPIT_ENABLE_MPI==1
201 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
204 if (!patch_2D->
getCells().exists(cellId)) {
209 for (
auto neighId : patch_2D->findCellNeighs(cellId)) {
215 log::cout() <<
">> Initial number of cells... " << nCells << std::endl;
223 log::cout() <<
">> Final number of cells... " << nCells << std::endl;
226#if BITPIT_ENABLE_MPI==1
240#if BITPIT_ENABLE_MPI==1
247 mapobject.initialize(
true);
253 for (
Cell & cell : patch_2D_original->getCells()){
254 if (cell.isInterior()){
255 long id = cell.getId();
257 vdata[count] = data[id];
262 patch_2D_original->
getVTK().
setName(
"mesh_original_testR.0");
263 patch_2D_original->
getVTK().
addData(
"data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata);
264#if BITPIT_ENABLE_MPI==1
265 patch_2D_original->
setVTKWriteTarget(PatchKernel::WriteTarget::WRITE_TARGET_CELLS_INTERNAL);
267 patch_2D_original->
write();
277#if BITPIT_ENABLE_MPI==1
279 std::map<int, std::map<long, double> > datarec;
280 std::map<int, std::map<long, double> > volrec;
282 std::unordered_map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
283 std::unordered_map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();
286 MPI_Comm comm = MPI_COMM_WORLD;
289 std::size_t bytes = uint8_t(2*
sizeof(
double));
290 for (
const auto &val : rankIDsend){
291 int rank = val.first;
293 std::size_t buffSize = val.second.size() * bytes;
294 dataCommunicator.setSend(rank,buffSize);
296 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
297 for (
long ID : val.second){
298 sendBuffer << data[ID];
303 dataCommunicator.discoverRecvs();
304 dataCommunicator.startAllRecvs();
305 dataCommunicator.startAllSends();
307 for (
const auto &val : rankIDrec){
308 int rank = val.first;
309 dataCommunicator.waitRecv(rank);
310 RecvBuffer & recvBuffer = dataCommunicator.getRecvBuffer(rank);
311 for (
long ID : val.second){
312 recvBuffer >> datarec[rank][ID];
313 recvBuffer >> volrec[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){
344 for (
long idd : mapper[id].ids){
345#if BITPIT_ENABLE_MPI==1
346 if (mapper[
id].ranks[i] == patch_2D->
getRank()){
350#if BITPIT_ENABLE_MPI==1
353 data2[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
354 Volume += volrec[mapper[id].ranks[i]][idd];
360 vdata2[count] = data2[id];
362 else if (mapper[
id].type == mapping::Type::TYPE_REFINEMENT){
363#if BITPIT_ENABLE_MPI==1
364 if (mapper[
id].ranks[0] == patch_2D->
getRank()){
366 data2[id] = data[mapper[id].ids[0]];
367 vdata2[count] = data2[id];
368#if BITPIT_ENABLE_MPI==1
371 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
372 vdata2[count] = data2[id];
380 patch_2D->
getVTK().
addData(
"data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2);
389 log::cout() <<
">> Marking the cells to adapt... " << std::endl;
393 for (
int i = 0; i < 30; ++i) {
395#if BITPIT_ENABLE_MPI==1
398 cellId = rand() % nCells * 2;
399#if BITPIT_ENABLE_MPI==1
400 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
403 if (!patch_2D->
getCells().exists(cellId)) {
411 for (
int i = 0; i < 60; ++i) {
413#if BITPIT_ENABLE_MPI==1
416 cellId = rand() % nCells * 2;
417#if BITPIT_ENABLE_MPI==1
418 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
421 if (!patch_2D->
getCells().exists(cellId)) {
426 for (
auto neighId : patch_2D->findCellNeighs(cellId)) {
433 log::cout() <<
">> Initial number of cells... " << nCells << std::endl;
435 std::vector<adaption::Info> infoAdapt = patch_2D->
adaptionPrepare(
true);
437 mapobject.adaptionPrepare(infoAdapt,
true);
441 mapobject.adaptionAlter(infoAdapt,
true,
true);
445 mapobject.adaptionCleanup();
448 log::cout() <<
">> Final number of cells... " << nCells << std::endl;
456#if BITPIT_ENABLE_MPI==1
458 std::map<int, std::map<long, double> > datarec;
459 std::map<int, std::map<long, double> > volrec;
461 std::unordered_map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
462 std::unordered_map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();
465 MPI_Comm comm = MPI_COMM_WORLD;
468 std::size_t bytes = uint8_t(2*
sizeof(
double));
469 for (
const auto &val : rankIDsend){
470 int rank = val.first;
472 std::size_t buffSize = val.second.size() * bytes;
473 dataCommunicator.setSend(rank,buffSize);
475 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
476 for (
long ID : val.second){
477 sendBuffer << data[ID];
482 dataCommunicator.discoverRecvs();
483 dataCommunicator.startAllRecvs();
484 dataCommunicator.startAllSends();
486 for (
const auto &val : rankIDrec){
487 int rank = val.first;
488 dataCommunicator.waitRecv(rank);
489 RecvBuffer & recvBuffer = dataCommunicator.getRecvBuffer(rank);
490 for (
long ID : val.second){
491 recvBuffer >> datarec[rank][ID];
492 recvBuffer >> volrec[rank][ID];
495 dataCommunicator.waitAllSends();
501 for (
Cell & cell : patch_2D->getCells()){
502 if (cell.isInterior()){
503 long id = cell.getId();
504 if (mapper[
id].type == mapping::Type::TYPE_RENUMBERING){
505#if BITPIT_ENABLE_MPI==1
506 if (mapper[
id].ranks[0] == patch_2D->
getRank()){
508 data2[id] = data[mapper[id].ids[0]];
509 vdata2[count] = data2[id];
510#if BITPIT_ENABLE_MPI==1
513 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
514 vdata2[count] = data2[id];
518 else if (mapper[
id].type == mapping::Type::TYPE_COARSENING){
522 for (
long idd : mapper[id].ids){
523#if BITPIT_ENABLE_MPI==1
524 if (mapper[
id].ranks[i] == patch_2D->
getRank()){
528#if BITPIT_ENABLE_MPI==1
531 data2[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
532 Volume += volrec[mapper[id].ranks[i]][idd];
538 vdata2[count] = data2[id];
540 else if (mapper[
id].type == mapping::Type::TYPE_REFINEMENT){
541#if BITPIT_ENABLE_MPI==1
542 if (mapper[
id].ranks[0] == patch_2D->
getRank()){
544 data2[id] = data[mapper[id].ids[0]];
545 vdata2[count] = data2[id];
546#if BITPIT_ENABLE_MPI==1
549 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
550 vdata2[count] = data2[id];
558 patch_2D->
getVTK().
addData(
"data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2);
570#if BITPIT_ENABLE_MPI==1
572 std::map<int, std::map<long, double> > datarec;
573 std::map<int, std::map<long, double> > volrec;
577 std::map<int, std::set<long> > rankIDsend;
581 for (
Cell & cell : patch_2D->getCells()){
582 long ID = cell.getId();
583 auto info = _mapper[ID];
585 for (
int rank :
info.ranks){
586 if (rank != patch_2D->
getRank()){
587 rankIDsend[rank].insert(ID);
594 MPI_Comm comm = MPI_COMM_WORLD;
597 std::size_t bytes = uint8_t(2*
sizeof(
double) +
sizeof(
long));
598 for (
const auto &val : rankIDsend){
599 int rank = val.first;
601 std::size_t buffSize = val.second.size() * bytes;
602 dataCommunicator.setSend(rank,buffSize);
604 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
605 for (
long ID : val.second){
607 sendBuffer << data2[ID];
612 dataCommunicator.discoverRecvs();
613 dataCommunicator.startAllRecvs();
614 dataCommunicator.startAllSends();
616 std::vector<int> recvRanks = dataCommunicator.getRecvRanks();
617 std::sort(recvRanks.begin(),recvRanks.end());
619 for (
int rank : recvRanks){
620 dataCommunicator.waitRecv(rank);
621 RecvBuffer & recvBuffer = dataCommunicator.getRecvBuffer(rank);
622 long nof = recvBuffer.
getSize() / bytes;
623 for (
long ii = 0; ii < nof; ii++){
626 recvBuffer >> datarec[rank][ID];
627 recvBuffer >> volrec[rank][ID];
630 dataCommunicator.waitAllSends();
637 for (
Cell & cell : patch_2D_original->getCells()){
638 if (cell.isInterior()){
639 long id = cell.getId();
640 if (mapper[
id].type == mapping::Type::TYPE_RENUMBERING){
641#if BITPIT_ENABLE_MPI==1
642 if (mapper[
id].ranks[0] == patch_2D_original->
getRank()){
644 data2inv[id] = data2[mapper[id].ids[0]];
645 vdata2inv[count] = data2inv[id];
646#if BITPIT_ENABLE_MPI==1
649 data2inv[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
650 vdata2inv[count] = data2inv[id];
654 else if (mapper[
id].type == mapping::Type::TYPE_COARSENING){
658 for (
long idd : mapper[id].ids){
659#if BITPIT_ENABLE_MPI==1
660 if (mapper[
id].ranks[i] == patch_2D_original->
getRank()){
664#if BITPIT_ENABLE_MPI==1
667 data2inv[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
668 Volume += volrec[mapper[id].ranks[i]][idd];
673 data2inv[id] /= Volume;
674 vdata2inv[count] = data2inv[id];
676 else if (mapper[
id].type == mapping::Type::TYPE_REFINEMENT){
677#if BITPIT_ENABLE_MPI==1
678 if (mapper[
id].ranks[0] == patch_2D_original->
getRank()){
680 data2inv[id] = data2[mapper[id].ids[0]];
681 vdata2inv[count] = data2inv[id];
682#if BITPIT_ENABLE_MPI==1
685 data2inv[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
686 vdata2inv[count] = data2inv[id];
694 patch_2D_original->
getVTK().
addData(
"data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2inv);
695 patch_2D_original->
getVTK().
setName(
"mesh_original_testR.1");
696 patch_2D_original->
write();
702void runMappedAdaptation()
705 log::cout() <<
" >> 2D octree patch" <<
"\n";
715 std::unique_ptr<PabloUniform> treePointer = std::unique_ptr<PabloUniform>(
new PabloUniform(x_0, y_0, z_0, l, 2));
718 std::cout <<
" Origin : ( " << octree.
getX0() <<
", " << octree.
getY0() <<
", " << octree.
getZ0() <<
" )" << std::endl;
719 std::cout <<
" Length : " << octree.
getL() << std::endl;
736 patch_2D_original->
update();
738#if BITPIT_ENABLE_MPI==1
743 std::vector<uint64_t> refineList;
744 refineList.push_back( 7);
745 refineList.push_back( 13);
746 refineList.push_back( 15);
747 refineList.push_back( 26);
748 refineList.push_back( 27);
749 refineList.push_back( 31);
750 refineList.push_back( 37);
751 refineList.push_back( 39);
752 refineList.push_back( 49);
753 refineList.push_back( 50);
754 refineList.push_back( 51);
755 refineList.push_back( 53);
756 refineList.push_back( 55);
757 refineList.push_back( 63);
758 refineList.push_back( 78);
759 refineList.push_back(100);
760 refineList.push_back(102);
761 refineList.push_back(105);
762 refineList.push_back(108);
763 refineList.push_back(109);
764 refineList.push_back(110);
765 refineList.push_back(135);
766 refineList.push_back(141);
767 refineList.push_back(143);
768 refineList.push_back(146);
769 refineList.push_back(147);
770 refineList.push_back(151);
771 refineList.push_back(153);
772 refineList.push_back(154);
773 refineList.push_back(155);
774 refineList.push_back(157);
775 refineList.push_back(159);
776 refineList.push_back(165);
777 refineList.push_back(167);
778 refineList.push_back(183);
779 refineList.push_back(198);
780 refineList.push_back(204);
781 refineList.push_back(206);
782 refineList.push_back(225);
783 refineList.push_back(228);
784 refineList.push_back(229);
785 refineList.push_back(230);
788 for (uint64_t ind : refineList) {
789#if BITPIT_ENABLE_MPI==1
791 if (patch_2D_original->
getRank() == owner){
799#if BITPIT_ENABLE_MPI==1
804 patch_2D_original->
update(
false);
809 std::unique_ptr<PabloUniform> treePointer2 = std::unique_ptr<PabloUniform>(
new PabloUniform(x_0, y_0, z_0, l, 2));
821#if BITPIT_ENABLE_MPI==1
822 patch_2D->
setVTKWriteTarget(PatchKernel::WriteTarget::WRITE_TARGET_CELLS_INTERNAL);
826 for (
int k = 0; k < 10; ++k) {
829 log::cout() <<
">> Marking the cells to adapt... " << std::endl;
831 for (
int i = 0; i < 100; ++i) {
833#if BITPIT_ENABLE_MPI==1
836 cellId = rand() % nCells * 2;
837#if BITPIT_ENABLE_MPI==1
838 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
841 if (!patch_2D->
getCells().exists(cellId)) {
848 for (
int i = 0; i < 55; ++i) {
850#if BITPIT_ENABLE_MPI==1
853 cellId = rand() % nCells * 2;
854#if BITPIT_ENABLE_MPI==1
855 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
858 if (!patch_2D->
getCells().exists(cellId)) {
863 for (
auto neighId : patch_2D->findCellNeighs(cellId)) {
869 log::cout() <<
">> Initial number of cells... " << nCells << std::endl;
877 log::cout() <<
">> Final number of cells... " << nCells << std::endl;
881#if BITPIT_ENABLE_MPI==1
898 for (
Cell & cell : patch_2D_original->getCells()){
899 if (cell.isInterior()){
900 long id = cell.getId();
902 vdata[count] = data[id];
907 patch_2D_original->
getVTK().
setName(
"mesh_original_testM.0");
908 patch_2D_original->
getVTK().
addData(
"data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata);
909#if BITPIT_ENABLE_MPI==1
910 patch_2D_original->
setVTKWriteTarget(PatchKernel::WriteTarget::WRITE_TARGET_CELLS_INTERNAL);
912 patch_2D_original->
write();
915#if BITPIT_ENABLE_MPI==1
922 mapobject.initialize(
true);
931#if BITPIT_ENABLE_MPI==1
933 std::map<int, std::map<long, double> > datarec;
934 std::map<int, std::map<long, double> > volrec;
938 std::map<int, std::set<long> > rankIDsend;
942 for (
Cell & cell : patch_2D_original->getCells()){
943 long ID = cell.getId();
944 auto info = _mapper[ID];
946 for (
int rank :
info.ranks){
947 if (rank != patch_2D_original->
getRank()){
948 rankIDsend[rank].insert(ID);
955 MPI_Comm comm = MPI_COMM_WORLD;
958 std::size_t bytes = uint8_t(2*
sizeof(
double) +
sizeof(
long));
959 for (
const auto &val : rankIDsend){
960 int rank = val.first;
962 std::size_t buffSize = val.second.size() * bytes;
963 dataCommunicator.setSend(rank,buffSize);
965 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
966 for (
long ID : val.second){
968 sendBuffer << data[ID];
973 dataCommunicator.discoverRecvs();
974 dataCommunicator.startAllRecvs();
975 dataCommunicator.startAllSends();
977 std::vector<int> recvRanks = dataCommunicator.getRecvRanks();
978 std::sort(recvRanks.begin(),recvRanks.end());
980 for (
int rank : recvRanks){
981 dataCommunicator.waitRecv(rank);
982 RecvBuffer & recvBuffer = dataCommunicator.getRecvBuffer(rank);
983 long nof = recvBuffer.
getSize() / bytes;
984 for (
long ii = 0; ii < nof; ii++){
987 recvBuffer >> datarec[rank][ID];
988 recvBuffer >> volrec[rank][ID];
991 dataCommunicator.waitAllSends();
998 for (
Cell & cell : patch_2D->getCells()){
999 if (cell.isInterior()){
1000 long id = cell.getId();
1001 if (mapper[
id].type == mapping::Type::TYPE_RENUMBERING){
1002#if BITPIT_ENABLE_MPI==1
1003 if (mapper[
id].ranks[0] == patch_2D->
getRank()){
1005 data2[id] = data[mapper[id].ids[0]];
1006 vdata2[count] = data2[id];
1007#if BITPIT_ENABLE_MPI==1
1010 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1011 vdata2[count] = data2[id];
1015 else if (mapper[
id].type == mapping::Type::TYPE_COARSENING){
1017 double Volume = 0.0;
1019 for (
long idd : mapper[id].ids){
1020#if BITPIT_ENABLE_MPI==1
1021 if (mapper[
id].ranks[i] == patch_2D->
getRank()){
1025#if BITPIT_ENABLE_MPI==1
1028 data2[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
1029 Volume += volrec[mapper[id].ranks[i]][idd];
1034 data2[id] /= Volume;
1035 vdata2[count] = data2[id];
1037 else if (mapper[
id].type == mapping::Type::TYPE_REFINEMENT){
1038#if BITPIT_ENABLE_MPI==1
1039 if (mapper[
id].ranks[0] == patch_2D->
getRank()){
1041 data2[id] = data[mapper[id].ids[0]];
1042 vdata2[count] = data2[id];
1043#if BITPIT_ENABLE_MPI==1
1046 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1047 vdata2[count] = data2[id];
1055 patch_2D->
getVTK().
addData(
"data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2);
1065 log::cout() <<
">> Marking the cells to adapt... " << std::endl;
1069 for (
int i = 0; i < 300; ++i) {
1071#if BITPIT_ENABLE_MPI==1
1074 cellId = rand() % nCells * 2;
1075#if BITPIT_ENABLE_MPI==1
1076 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
1079 if (!patch_2D->
getCells().exists(cellId)) {
1087 for (
int i = 0; i < 200; ++i) {
1089#if BITPIT_ENABLE_MPI==1
1092 cellId = rand() % nCells * 2;
1093#if BITPIT_ENABLE_MPI==1
1094 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
1097 if (!patch_2D->
getCells().exists(cellId)) {
1102 for (
auto neighId : patch_2D->findCellNeighs(cellId)) {
1109 log::cout() <<
">> Initial number of cells... " << nCells << std::endl;
1111 std::vector<adaption::Info> infoAdapt = patch_2D->
adaptionPrepare(
true);
1113 mapobject.adaptionPrepare(infoAdapt,
false);
1117 mapobject.adaptionAlter(infoAdapt,
false,
true);
1121 mapobject.adaptionCleanup();
1124 log::cout() <<
">> Final number of cells... " << nCells << std::endl;
1134#if BITPIT_ENABLE_MPI==1
1136 std::map<int, std::map<long, double> > datarec;
1137 std::map<int, std::map<long, double> > volrec;
1141 std::map<int, std::set<long> > rankIDsend;
1145 for (
Cell & cell : patch_2D_original->getCells()){
1146 long ID = cell.getId();
1147 auto info = _mapper[ID];
1149 for (
int rank :
info.ranks){
1150 if (rank != patch_2D_original->
getRank()){
1151 rankIDsend[rank].insert(ID);
1159 MPI_Comm_dup(MPI_COMM_WORLD, &comm);
1162 std::size_t bytes = uint8_t(2*
sizeof(
double) +
sizeof(
long));
1163 for (
const auto &val : rankIDsend){
1164 int rank = val.first;
1166 std::size_t buffSize = val.second.size() * bytes;
1167 dataCommunicator.setSend(rank,buffSize);
1169 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
1170 for (
long ID : val.second){
1172 sendBuffer << data[ID];
1177 dataCommunicator.discoverRecvs();
1178 dataCommunicator.startAllRecvs();
1179 dataCommunicator.startAllSends();
1181 std::vector<int> recvRanks = dataCommunicator.getRecvRanks();
1182 std::sort(recvRanks.begin(),recvRanks.end());
1184 for (
int rank : recvRanks){
1185 dataCommunicator.waitRecv(rank);
1186 RecvBuffer & recvBuffer = dataCommunicator.getRecvBuffer(rank);
1187 long nof = recvBuffer.
getSize() / bytes;
1188 for (
long ii = 0; ii < nof; ii++){
1191 recvBuffer >> datarec[rank][ID];
1192 recvBuffer >> volrec[rank][ID];
1195 dataCommunicator.waitAllSends();
1202 for (
Cell & cell : patch_2D->getCells()){
1203 if (cell.isInterior()){
1204 long id = cell.getId();
1205 if (mapper[
id].type == mapping::Type::TYPE_RENUMBERING){
1206#if BITPIT_ENABLE_MPI==1
1207 if (mapper[
id].ranks[0] == patch_2D->
getRank()){
1209 data2[id] = data[mapper[id].ids[0]];
1210 vdata2[count] = data2[id];
1211#if BITPIT_ENABLE_MPI==1
1214 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1215 vdata2[count] = data2[id];
1219 else if (mapper[
id].type == mapping::Type::TYPE_COARSENING){
1221 double Volume = 0.0;
1223 for (
long idd : mapper[id].ids){
1226 std::cout <<
"mapped id : " << idd << std::endl;
1230#if BITPIT_ENABLE_MPI==1
1231 if (mapper[
id].ranks[i] == patch_2D->
getRank()){
1235#if BITPIT_ENABLE_MPI==1
1238 data2[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
1239 Volume += volrec[mapper[id].ranks[i]][idd];
1244 data2[id] /= Volume;
1245 vdata2[count] = data2[id];
1247 else if (mapper[
id].type == mapping::Type::TYPE_REFINEMENT){
1248#if BITPIT_ENABLE_MPI==1
1249 if (mapper[
id].ranks[0] == patch_2D->
getRank()){
1251 data2[id] = data[mapper[id].ids[0]];
1252 vdata2[count] = data2[id];
1253#if BITPIT_ENABLE_MPI==1
1256 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1257 vdata2[count] = data2[id];
1265 patch_2D->
getVTK().
addData(
"data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2);
1279#if BITPIT_ENABLE_MPI==1
1281 std::map<int, std::map<long, double> > datarec;
1282 std::map<int, std::map<long, double> > volrec;
1284 std::unordered_map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
1285 std::unordered_map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();
1289 MPI_Comm_dup(MPI_COMM_WORLD, &comm);
1292 std::size_t bytes = uint8_t(2*
sizeof(
double));
1293 for (
const auto &val : rankIDsend){
1294 int rank = val.first;
1296 std::size_t buffSize = val.second.size() * bytes;
1297 dataCommunicator.setSend(rank,buffSize);
1299 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
1300 for (
long ID : val.second){
1301 sendBuffer << data2[ID];
1306 dataCommunicator.discoverRecvs();
1307 dataCommunicator.startAllRecvs();
1308 dataCommunicator.startAllSends();
1310 for (
const auto &val : rankIDrec){
1311 int rank = val.first;
1312 dataCommunicator.waitRecv(rank);
1313 RecvBuffer & recvBuffer = dataCommunicator.getRecvBuffer(rank);
1314 for (
long ID : val.second){
1315 recvBuffer >> datarec[rank][ID];
1316 recvBuffer >> volrec[rank][ID];
1319 dataCommunicator.waitAllSends();
1326 for (
Cell & cell : patch_2D_original->getCells()){
1327 if (cell.isInterior()){
1328 long id = cell.getId();
1329 if (mapper[
id].type == mapping::Type::TYPE_RENUMBERING){
1330#if BITPIT_ENABLE_MPI==1
1331 if (mapper[
id].ranks[0] == patch_2D_original->
getRank()){
1333 data2inv[id] = data2[mapper[id].ids[0]];
1334 vdata2inv[count] = data2inv[id];
1335#if BITPIT_ENABLE_MPI==1
1338 data2inv[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1339 vdata2inv[count] = data2inv[id];
1343 else if (mapper[
id].type == mapping::Type::TYPE_COARSENING){
1345 double Volume = 0.0;
1347 for (
long idd : mapper[id].ids){
1348#if BITPIT_ENABLE_MPI==1
1349 if (mapper[
id].ranks[i] == patch_2D_original->
getRank()){
1353#if BITPIT_ENABLE_MPI==1
1356 data2inv[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
1357 Volume += volrec[mapper[id].ranks[i]][idd];
1362 data2inv[id] /= Volume;
1363 vdata2inv[count] = data2inv[id];
1365 else if (mapper[
id].type == mapping::Type::TYPE_REFINEMENT){
1366#if BITPIT_ENABLE_MPI==1
1367 if (mapper[
id].ranks[0] == patch_2D_original->
getRank()){
1369 data2inv[id] = data2[mapper[id].ids[0]];
1370 vdata2inv[count] = data2inv[id];
1371#if BITPIT_ENABLE_MPI==1
1374 data2inv[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1375 vdata2inv[count] = data2inv[id];
1383#if BITPIT_ENABLE_MPI==1
1384 MPI_Comm comm = MPI_COMM_WORLD;
1387 patch_2D_original->
getVTK().
addData(
"data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2inv);
1388 patch_2D_original->
getVTK().
setName(
"mesh_original_testM.1");
1389 patch_2D_original->
write();
1399int main(
int argc,
char *argv[])
1402#if BITPIT_ENABLE_MPI==1
1403 MPI_Init(&argc,&argv);
1409 runReferenceAdaptation();
1410 }
catch (
const std::exception &exception) {
1416 runMappedAdaptation();
1417 }
catch (
const std::exception &exception) {
1422#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
std::vector< adaption::Info > adaptionPrepare(bool trackAdaption=true)
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
std::vector< adaption::Info > adaptionAlter(bool trackAdaption=true, bool squeezeStorage=false)
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
double evalCellVolume(long id) const override
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)