Loading...
Searching...
No Matches
voloctree_mapper_example_00004.cpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
32#include <ctime>
33#include <array>
34#if BITPIT_ENABLE_MPI==1
35#include <mpi.h>
36#endif
37
38#include "bitpit_POD.hpp"
39#include "bitpit_patchkernel.hpp"
40#include "bitpit_voloctree.hpp"
41
42using namespace bitpit;
43using namespace pod;
44
48void runReferenceAdaptation()
49{
50
51 log::cout() << " >> 2D octree patch" << "\n";
52
56 double x_0 = 10.;
57 double y_0 = 20.;
58 double z_0 = 30.;
59 double l = 1.5;
60
61 std::unique_ptr<PabloUniform> treePointer = std::unique_ptr<PabloUniform>(new PabloUniform(x_0, y_0, z_0, l, 2));
62 PabloUniform &octree = *treePointer;
63
64 std::cout << " Origin : ( " << octree.getX0() << ", " << octree.getY0() << ", " << octree.getZ0() << " )" << std::endl;
65 std::cout << " Length : " << octree.getL() << std::endl;
66
68 octree.adaptGlobalRefine();
69 octree.adaptGlobalRefine();
70 octree.adaptGlobalRefine();
71 octree.adaptGlobalRefine();
72
77 VolOctree *patch_2D_original = new VolOctree(std::move(treePointer), &treePointer);
78
79 patch_2D_original->initializeAdjacencies();
80 patch_2D_original->initializeInterfaces();
81
82 patch_2D_original->update();
83
84#if BITPIT_ENABLE_MPI==1
86 patch_2D_original->partition(true);
87#endif
88
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);
132
133
134 for (uint64_t ind : refineList) {
135#if BITPIT_ENABLE_MPI==1
136 int owner = patch_2D_original->getTree().getOwnerRank(ind);
137 if (patch_2D_original->getRank() == owner){
138 uint32_t lind = patch_2D_original->getTree().getLocalIdx(ind, owner);
139#else
140 uint32_t lind = patch_2D_original->getTree().getLocalIdx(ind);
141#endif
142 VolOctree::OctantInfo octinfo(lind, true);
143 long id = patch_2D_original->getOctantId(octinfo);
144 patch_2D_original->markCellForRefinement(id);
145#if BITPIT_ENABLE_MPI==1
146 }
147#endif
148 }
149
150 patch_2D_original->update(false);
151
155 std::unique_ptr<PabloUniform> treePointer2 = std::unique_ptr<PabloUniform>(new PabloUniform(x_0, y_0, z_0, l, 2));
156 PabloUniform &octree2 = *treePointer2;
157
159 octree2.adaptGlobalRefine();
160 octree2.adaptGlobalRefine();
161 octree2.adaptGlobalRefine();
162 octree2.adaptGlobalRefine();
163
165 VolOctree *patch_2D = new VolOctree(std::move(treePointer2), &treePointer2);
166 patch_2D->update(false);
167#if BITPIT_ENABLE_MPI==1
168 patch_2D->setVTKWriteTarget(PatchKernel::WriteTarget::WRITE_TARGET_CELLS_INTERNAL);
169#endif
170
172 for (int k = 0; k < 10; ++k) {
173 long nCells = patch_2D->getCellCount();
174 log::cout() << std::endl;
175 log::cout() << ">> Marking the cells to adapt... " << std::endl;
176
177 for (int i = 0; i < 100; ++i) {
178 long cellId;
179#if BITPIT_ENABLE_MPI==1
180 if (patch_2D->getRank() == 0)
181#endif
182 cellId = rand() % nCells * 2;
183#if BITPIT_ENABLE_MPI==1
184 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
185#endif
186
187 if (!patch_2D->getCells().exists(cellId)) {
188 continue;
189 }
190
191 patch_2D->markCellForRefinement(cellId);
192 }
193
194 for (int i = 0; i < 55; ++i) {
195 long cellId;
196#if BITPIT_ENABLE_MPI==1
197 if (patch_2D->getRank() == 0)
198#endif
199 cellId = rand() % nCells * 2;
200#if BITPIT_ENABLE_MPI==1
201 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
202#endif
203
204 if (!patch_2D->getCells().exists(cellId)) {
205 continue;
206 }
207
208 patch_2D->markCellForCoarsening(cellId);
209 for (auto neighId : patch_2D->findCellNeighs(cellId)) {
210 patch_2D->markCellForCoarsening(neighId);
211 }
212 }
213
214 log::cout() << std::endl;
215 log::cout() << ">> Initial number of cells... " << nCells << std::endl;
216
217 patch_2D->initializeAdjacencies();
218 patch_2D->initializeInterfaces();
219
220 patch_2D->update(false);
221
222 nCells = patch_2D->getCellCount();
223 log::cout() << ">> Final number of cells... " << nCells << std::endl;
224 }
225
226#if BITPIT_ENABLE_MPI==1
228 patch_2D->partition(true);
229#endif
230
232 log::cout() << "Cell count: " << patch_2D->getCellCount() << std::endl;
233 log::cout() << "Vertex count: " << patch_2D->getVertexCount() << std::endl;
234
235 patch_2D->getVTK().setName("mesh_random_testR.0");
236 patch_2D->write();
237
238
240#if BITPIT_ENABLE_MPI==1
241 VolOctreeMapper mapobject(patch_2D, patch_2D_original, patch_2D->getCommunicator());
242#else
243 VolOctreeMapper mapobject(patch_2D, patch_2D_original);
244#endif
245
247 mapobject.initialize(true);
248
250 PiercedStorage<double> data(1, &patch_2D_original->getCells());
251 std::vector<double> vdata(patch_2D_original->getInternalCellCount());
252 int count = 0;
253 for (Cell & cell : patch_2D_original->getCells()){
254 if (cell.isInterior()){
255 long id = cell.getId();
256 data[id] = double(patch_2D_original->getCellLevel(id));
257 vdata[count] = data[id];
258 count++;
259 }
260 }
261
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);
266#endif
267 patch_2D_original->write();
268
269
271 {
272 PiercedStorage<double> data2(1, &patch_2D->getCells());
273 data2.fill(0.0);
274
275 const PiercedStorage<mapping::Info> & mapper = mapobject.getMapping();
276
277#if BITPIT_ENABLE_MPI==1
278 //Communicate needed data for mapping
279 std::map<int, std::map<long, double> > datarec;
280 std::map<int, std::map<long, double> > volrec;
281 {
282 std::unordered_map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
283 std::unordered_map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();
284
285 //build send buffers
286 MPI_Comm comm = MPI_COMM_WORLD;
287 DataCommunicator dataCommunicator(comm);
288 MPI_Barrier(comm);
289 std::size_t bytes = uint8_t(2*sizeof(double));
290 for (const auto &val : rankIDsend){
291 int rank = val.first;
292 //set size
293 std::size_t buffSize = val.second.size() * bytes;
294 dataCommunicator.setSend(rank,buffSize);
295 //fill buffer with octants
296 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
297 for (long ID : val.second){
298 sendBuffer << data[ID];
299 sendBuffer << patch_2D_original->evalCellVolume(ID);
300 }
301 }
302
303 dataCommunicator.discoverRecvs();
304 dataCommunicator.startAllRecvs();
305 dataCommunicator.startAllSends();
306
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];
314 }
315 }
316 dataCommunicator.waitAllSends();
317
318 }
319#endif
320
321 std::vector<double> vdata2(patch_2D->getInternalCellCount());
322 count = 0;
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()){
329#endif
330 data2[id] = data[mapper[id].ids[0]];
331 vdata2[count] = data2[id];
332#if BITPIT_ENABLE_MPI==1
333 }
334 else{
335 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
336 vdata2[count] = data2[id];
337 }
338#endif
339 }
340 else if (mapper[id].type == mapping::Type::TYPE_COARSENING){
341 data2[id] = 0.0;
342 double Volume = 0.0;
343 int i = 0;
344 for (long idd : mapper[id].ids){
345#if BITPIT_ENABLE_MPI==1
346 if (mapper[id].ranks[i] == patch_2D->getRank()){
347#endif
348 data2[id] += data[idd] * patch_2D_original->evalCellVolume(idd);
349 Volume += patch_2D_original->evalCellVolume(idd);
350#if BITPIT_ENABLE_MPI==1
351 }
352 else{
353 data2[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
354 Volume += volrec[mapper[id].ranks[i]][idd];
355 }
356#endif
357 i++;
358 }
359 data2[id] /= Volume;
360 vdata2[count] = data2[id];
361 }
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()){
365#endif
366 data2[id] = data[mapper[id].ids[0]];
367 vdata2[count] = data2[id];
368#if BITPIT_ENABLE_MPI==1
369 }
370 else{
371 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
372 vdata2[count] = data2[id];
373 }
374#endif
375 }
376 count++;
377 }
378 }
379
380 patch_2D->getVTK().addData("data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2);
381 patch_2D->getVTK().setName("mesh_random_testR.0");
382 patch_2D->write();
383
384 }
385
387 long nCells = patch_2D->getCellCount();
388 log::cout() << std::endl;
389 log::cout() << ">> Marking the cells to adapt... " << std::endl;
390
391 std::srand(0);
392
393 for (int i = 0; i < 30; ++i) {
394 long cellId;
395#if BITPIT_ENABLE_MPI==1
396 if (patch_2D->getRank() == 0)
397#endif
398 cellId = rand() % nCells * 2;
399#if BITPIT_ENABLE_MPI==1
400 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
401#endif
402
403 if (!patch_2D->getCells().exists(cellId)) {
404 continue;
405 }
406
407 patch_2D->markCellForRefinement(cellId);
408
409 }
410
411 for (int i = 0; i < 60; ++i) {
412 long cellId;
413#if BITPIT_ENABLE_MPI==1
414 if (patch_2D->getRank() == 0)
415#endif
416 cellId = rand() % nCells * 2;
417#if BITPIT_ENABLE_MPI==1
418 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
419#endif
420
421 if (!patch_2D->getCells().exists(cellId)) {
422 continue;
423 }
424
425 patch_2D->markCellForCoarsening(cellId);
426 for (auto neighId : patch_2D->findCellNeighs(cellId)) {
427 patch_2D->markCellForCoarsening(neighId);
428 }
429
430 }
431
432 log::cout() << std::endl;
433 log::cout() << ">> Initial number of cells... " << nCells << std::endl;
434
435 std::vector<adaption::Info> infoAdapt = patch_2D->adaptionPrepare(true);
436
437 mapobject.adaptionPrepare(infoAdapt, true);
438
439 infoAdapt = patch_2D->adaptionAlter(true);
440
441 mapobject.adaptionAlter(infoAdapt, true, true);
442
443 patch_2D->adaptionCleanup();
444
445 mapobject.adaptionCleanup();
446
447 nCells = patch_2D->getCellCount();
448 log::cout() << ">> Final number of cells... " << nCells << std::endl;
449
451 PiercedStorage<double> data2(1, &patch_2D->getCells());
452 data2.fill(0.0);
453 {
454 const PiercedStorage<mapping::Info> & mapper = mapobject.getMapping();
455
456#if BITPIT_ENABLE_MPI==1
457 //Communicate needed data for mapping
458 std::map<int, std::map<long, double> > datarec;
459 std::map<int, std::map<long, double> > volrec;
460 {
461 std::unordered_map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
462 std::unordered_map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();
463
464 //build send buffers
465 MPI_Comm comm = MPI_COMM_WORLD;
466 DataCommunicator dataCommunicator(comm);
467 MPI_Barrier(comm);
468 std::size_t bytes = uint8_t(2*sizeof(double));
469 for (const auto &val : rankIDsend){
470 int rank = val.first;
471 //set size
472 std::size_t buffSize = val.second.size() * bytes;
473 dataCommunicator.setSend(rank,buffSize);
474 //fill buffer with octants
475 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
476 for (long ID : val.second){
477 sendBuffer << data[ID];
478 sendBuffer << patch_2D_original->evalCellVolume(ID);
479 }
480 }
481
482 dataCommunicator.discoverRecvs();
483 dataCommunicator.startAllRecvs();
484 dataCommunicator.startAllSends();
485
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];
493 }
494 }
495 dataCommunicator.waitAllSends();
496 }
497#endif
498
499 std::vector<double> vdata2(patch_2D->getInternalCellCount());
500 count = 0;
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()){
507#endif
508 data2[id] = data[mapper[id].ids[0]];
509 vdata2[count] = data2[id];
510#if BITPIT_ENABLE_MPI==1
511 }
512 else{
513 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
514 vdata2[count] = data2[id];
515 }
516#endif
517 }
518 else if (mapper[id].type == mapping::Type::TYPE_COARSENING){
519 data2[id] = 0.0;
520 double Volume = 0.0;
521 int i = 0;
522 for (long idd : mapper[id].ids){
523#if BITPIT_ENABLE_MPI==1
524 if (mapper[id].ranks[i] == patch_2D->getRank()){
525#endif
526 data2[id] += data[idd] * patch_2D_original->evalCellVolume(idd);
527 Volume += patch_2D_original->evalCellVolume(idd);
528#if BITPIT_ENABLE_MPI==1
529 }
530 else{
531 data2[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
532 Volume += volrec[mapper[id].ranks[i]][idd];
533 }
534#endif
535 i++;
536 }
537 data2[id] /= Volume;
538 vdata2[count] = data2[id];
539 }
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()){
543#endif
544 data2[id] = data[mapper[id].ids[0]];
545 vdata2[count] = data2[id];
546#if BITPIT_ENABLE_MPI==1
547 }
548 else{
549 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
550 vdata2[count] = data2[id];
551 }
552#endif
553 }
554 count++;
555 }
556 }
557
558 patch_2D->getVTK().addData("data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2);
559 patch_2D->getVTK().setName("mesh_random_testR.1");
560 patch_2D->write();
561
562 }
563
565 PiercedStorage<double> data2inv(1, &patch_2D_original->getCells());
566 data2inv.fill(0.0);
567 {
568 const PiercedStorage<mapping::Info> & mapper = mapobject.getInverseMapping();
569
570#if BITPIT_ENABLE_MPI==1
571 //Communicate needed data for mapping
572 std::map<int, std::map<long, double> > datarec;
573 std::map<int, std::map<long, double> > volrec;
574 {
575
576 // recover id to be rec/sent
577 std::map<int, std::set<long> > rankIDsend;
578
579 const PiercedStorage<mapping::Info> & _mapper = mapobject.getMapping();
580
581 for (Cell & cell : patch_2D->getCells()){
582 long ID = cell.getId();
583 auto info = _mapper[ID];
584 int i = 0;
585 for (int rank : info.ranks){
586 if (rank != patch_2D->getRank()){
587 rankIDsend[rank].insert(ID);
588 }
589 i++;
590 }
591 }
592
593 //build send buffers
594 MPI_Comm comm = MPI_COMM_WORLD;
595 DataCommunicator dataCommunicator(comm);
596 MPI_Barrier(comm);
597 std::size_t bytes = uint8_t(2*sizeof(double) + sizeof(long));
598 for (const auto &val : rankIDsend){
599 int rank = val.first;
600 //set size
601 std::size_t buffSize = val.second.size() * bytes;
602 dataCommunicator.setSend(rank,buffSize);
603 //fill buffer with octants
604 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
605 for (long ID : val.second){
606 sendBuffer << ID;
607 sendBuffer << data2[ID];
608 sendBuffer << patch_2D->evalCellVolume(ID);
609 }
610 }
611
612 dataCommunicator.discoverRecvs();
613 dataCommunicator.startAllRecvs();
614 dataCommunicator.startAllSends();
615
616 std::vector<int> recvRanks = dataCommunicator.getRecvRanks();
617 std::sort(recvRanks.begin(),recvRanks.end());
618
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++){
624 long ID;
625 recvBuffer >> ID;
626 recvBuffer >> datarec[rank][ID];
627 recvBuffer >> volrec[rank][ID];
628 }
629 }
630 dataCommunicator.waitAllSends();
631
632 }
633#endif
634
635 std::vector<double> vdata2inv(patch_2D_original->getInternalCellCount());
636 count = 0;
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()){
643#endif
644 data2inv[id] = data2[mapper[id].ids[0]];
645 vdata2inv[count] = data2inv[id];
646#if BITPIT_ENABLE_MPI==1
647 }
648 else{
649 data2inv[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
650 vdata2inv[count] = data2inv[id];
651 }
652#endif
653 }
654 else if (mapper[id].type == mapping::Type::TYPE_COARSENING){
655 data2inv[id] = 0.0;
656 double Volume = 0.0;
657 int i = 0;
658 for (long idd : mapper[id].ids){
659#if BITPIT_ENABLE_MPI==1
660 if (mapper[id].ranks[i] == patch_2D_original->getRank()){
661#endif
662 data2inv[id] += data2[idd] * patch_2D->evalCellVolume(idd);
663 Volume += patch_2D->evalCellVolume(idd);
664#if BITPIT_ENABLE_MPI==1
665 }
666 else{
667 data2inv[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
668 Volume += volrec[mapper[id].ranks[i]][idd];
669 }
670#endif
671 i++;
672 }
673 data2inv[id] /= Volume;
674 vdata2inv[count] = data2inv[id];
675 }
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()){
679#endif
680 data2inv[id] = data2[mapper[id].ids[0]];
681 vdata2inv[count] = data2inv[id];
682#if BITPIT_ENABLE_MPI==1
683 }
684 else{
685 data2inv[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
686 vdata2inv[count] = data2inv[id];
687 }
688#endif
689 }
690 count++;
691 }
692 }
693
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();
697
698 }
699
700}
701
702void runMappedAdaptation()
703{
704
705 log::cout() << " >> 2D octree patch" << "\n";
706
710 double x_0 = 10.;
711 double y_0 = 20.;
712 double z_0 = 30.;
713 double l = 1.5;
714
715 std::unique_ptr<PabloUniform> treePointer = std::unique_ptr<PabloUniform>(new PabloUniform(x_0, y_0, z_0, l, 2));
716 PabloUniform &octree = *treePointer;
717
718 std::cout << " Origin : ( " << octree.getX0() << ", " << octree.getY0() << ", " << octree.getZ0() << " )" << std::endl;
719 std::cout << " Length : " << octree.getL() << std::endl;
720
722 octree.adaptGlobalRefine();
723 octree.adaptGlobalRefine();
724 octree.adaptGlobalRefine();
725 octree.adaptGlobalRefine();
726
731 VolOctree *patch_2D_original = new VolOctree(std::move(treePointer), &treePointer);
732
733 patch_2D_original->initializeAdjacencies();
734 patch_2D_original->initializeInterfaces();
735
736 patch_2D_original->update();
737
738#if BITPIT_ENABLE_MPI==1
740 patch_2D_original->partition(true);
741#endif
742
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);
786
787
788 for (uint64_t ind : refineList) {
789#if BITPIT_ENABLE_MPI==1
790 int owner = patch_2D_original->getTree().getOwnerRank(ind);
791 if (patch_2D_original->getRank() == owner){
792 uint32_t lind = patch_2D_original->getTree().getLocalIdx(ind, owner);
793#else
794 uint32_t lind = patch_2D_original->getTree().getLocalIdx(ind);
795#endif
796 VolOctree::OctantInfo octinfo(lind, true);
797 long id = patch_2D_original->getOctantId(octinfo);
798 patch_2D_original->markCellForRefinement(id);
799#if BITPIT_ENABLE_MPI==1
800 }
801#endif
802 }
803
804 patch_2D_original->update(false);
805
809 std::unique_ptr<PabloUniform> treePointer2 = std::unique_ptr<PabloUniform>(new PabloUniform(x_0, y_0, z_0, l, 2));
810 PabloUniform &octree2 = *treePointer2;
811
813 octree2.adaptGlobalRefine();
814 octree2.adaptGlobalRefine();
815 octree2.adaptGlobalRefine();
816 octree2.adaptGlobalRefine();
817
819 VolOctree *patch_2D = new VolOctree(std::move(treePointer2), &treePointer2);
820 patch_2D->update(false);
821#if BITPIT_ENABLE_MPI==1
822 patch_2D->setVTKWriteTarget(PatchKernel::WriteTarget::WRITE_TARGET_CELLS_INTERNAL);
823#endif
824
826 for (int k = 0; k < 10; ++k) {
827 long nCells = patch_2D->getCellCount();
828 log::cout() << std::endl;
829 log::cout() << ">> Marking the cells to adapt... " << std::endl;
830
831 for (int i = 0; i < 100; ++i) {
832 long cellId;
833#if BITPIT_ENABLE_MPI==1
834 if (patch_2D->getRank() == 0)
835#endif
836 cellId = rand() % nCells * 2;
837#if BITPIT_ENABLE_MPI==1
838 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
839#endif
840
841 if (!patch_2D->getCells().exists(cellId)) {
842 continue;
843 }
844
845 patch_2D->markCellForRefinement(cellId);
846 }
847
848 for (int i = 0; i < 55; ++i) {
849 long cellId;
850#if BITPIT_ENABLE_MPI==1
851 if (patch_2D->getRank() == 0)
852#endif
853 cellId = rand() % nCells * 2;
854#if BITPIT_ENABLE_MPI==1
855 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
856#endif
857
858 if (!patch_2D->getCells().exists(cellId)) {
859 continue;
860 }
861
862 patch_2D->markCellForCoarsening(cellId);
863 for (auto neighId : patch_2D->findCellNeighs(cellId)) {
864 patch_2D->markCellForCoarsening(neighId);
865 }
866 }
867
868 log::cout() << std::endl;
869 log::cout() << ">> Initial number of cells... " << nCells << std::endl;
870
871 patch_2D->initializeAdjacencies();
872 patch_2D->initializeInterfaces();
873
874 patch_2D->update(false);
875
876 nCells = patch_2D->getCellCount();
877 log::cout() << ">> Final number of cells... " << nCells << std::endl;
878 }
879
880
881#if BITPIT_ENABLE_MPI==1
883 patch_2D->partition(true);
884#endif
885
887 log::cout() << "Cell count: " << patch_2D->getCellCount() << std::endl;
888 log::cout() << "Vertex count: " << patch_2D->getVertexCount() << std::endl;
889
890
891 patch_2D->getVTK().setName("mesh_random_testM.0");
892 patch_2D->write();
893
895 PiercedStorage<double> data(1, &patch_2D_original->getCells());
896 std::vector<double> vdata(patch_2D_original->getInternalCellCount());
897 int count = 0;
898 for (Cell & cell : patch_2D_original->getCells()){
899 if (cell.isInterior()){
900 long id = cell.getId();
901 data[id] = double(patch_2D_original->getCellLevel(id));
902 vdata[count] = data[id];
903 count++;
904 }
905 }
906
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);
911#endif
912 patch_2D_original->write();
913
915#if BITPIT_ENABLE_MPI==1
916 VolOctreeMapper mapobject(patch_2D_original, patch_2D, patch_2D_original->getCommunicator());
917#else
918 VolOctreeMapper mapobject(patch_2D_original, patch_2D);
919#endif
920
922 mapobject.initialize(true);
923
925 {
926 PiercedStorage<double> data2(1, &patch_2D->getCells());
927 data2.fill(0.0);
928
929 const PiercedStorage<mapping::Info> & mapper = mapobject.getInverseMapping();
930
931#if BITPIT_ENABLE_MPI==1
932 //Communicate needed data for mapping
933 std::map<int, std::map<long, double> > datarec;
934 std::map<int, std::map<long, double> > volrec;
935 {
936
937 // recover id to be rec/sent
938 std::map<int, std::set<long> > rankIDsend;
939
940 const PiercedStorage<mapping::Info> & _mapper = mapobject.getMapping();
941
942 for (Cell & cell : patch_2D_original->getCells()){
943 long ID = cell.getId();
944 auto info = _mapper[ID];
945 int i = 0;
946 for (int rank : info.ranks){
947 if (rank != patch_2D_original->getRank()){
948 rankIDsend[rank].insert(ID);
949 }
950 i++;
951 }
952 }
953
954 //build send buffers
955 MPI_Comm comm = MPI_COMM_WORLD;
956 DataCommunicator dataCommunicator(comm);
957 MPI_Barrier(comm);
958 std::size_t bytes = uint8_t(2*sizeof(double) + sizeof(long));
959 for (const auto &val : rankIDsend){
960 int rank = val.first;
961 //set size
962 std::size_t buffSize = val.second.size() * bytes;
963 dataCommunicator.setSend(rank,buffSize);
964 //fill buffer with octants
965 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
966 for (long ID : val.second){
967 sendBuffer << ID;
968 sendBuffer << data[ID];
969 sendBuffer << patch_2D_original->evalCellVolume(ID);
970 }
971 }
972
973 dataCommunicator.discoverRecvs();
974 dataCommunicator.startAllRecvs();
975 dataCommunicator.startAllSends();
976
977 std::vector<int> recvRanks = dataCommunicator.getRecvRanks();
978 std::sort(recvRanks.begin(),recvRanks.end());
979
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++){
985 long ID;
986 recvBuffer >> ID;
987 recvBuffer >> datarec[rank][ID];
988 recvBuffer >> volrec[rank][ID];
989 }
990 }
991 dataCommunicator.waitAllSends();
992
993 }
994#endif
995
996 std::vector<double> vdata2(patch_2D->getInternalCellCount());
997 count = 0;
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()){
1004#endif
1005 data2[id] = data[mapper[id].ids[0]];
1006 vdata2[count] = data2[id];
1007#if BITPIT_ENABLE_MPI==1
1008 }
1009 else{
1010 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1011 vdata2[count] = data2[id];
1012 }
1013#endif
1014 }
1015 else if (mapper[id].type == mapping::Type::TYPE_COARSENING){
1016 data2[id] = 0.0;
1017 double Volume = 0.0;
1018 int i = 0;
1019 for (long idd : mapper[id].ids){
1020#if BITPIT_ENABLE_MPI==1
1021 if (mapper[id].ranks[i] == patch_2D->getRank()){
1022#endif
1023 data2[id] += data[idd] * patch_2D_original->evalCellVolume(idd);
1024 Volume += patch_2D_original->evalCellVolume(idd);
1025#if BITPIT_ENABLE_MPI==1
1026 }
1027 else{
1028 data2[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
1029 Volume += volrec[mapper[id].ranks[i]][idd];
1030 }
1031#endif
1032 i++;
1033 }
1034 data2[id] /= Volume;
1035 vdata2[count] = data2[id];
1036 }
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()){
1040#endif
1041 data2[id] = data[mapper[id].ids[0]];
1042 vdata2[count] = data2[id];
1043#if BITPIT_ENABLE_MPI==1
1044 }
1045 else{
1046 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1047 vdata2[count] = data2[id];
1048 }
1049#endif
1050 }
1051 count++;
1052 }
1053 }
1054
1055 patch_2D->getVTK().addData("data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2);
1056 patch_2D->getVTK().setName("mesh_random_testM.0");
1057 patch_2D->write();
1058
1059 }
1060
1061
1063 long nCells = patch_2D->getCellCount();
1064 log::cout() << std::endl;
1065 log::cout() << ">> Marking the cells to adapt... " << std::endl;
1066
1067 std::srand(0);
1068
1069 for (int i = 0; i < 300; ++i) {
1070 long cellId;
1071#if BITPIT_ENABLE_MPI==1
1072 if (patch_2D->getRank() == 0)
1073#endif
1074 cellId = rand() % nCells * 2;
1075#if BITPIT_ENABLE_MPI==1
1076 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
1077#endif
1078
1079 if (!patch_2D->getCells().exists(cellId)) {
1080 continue;
1081 }
1082
1083 patch_2D->markCellForRefinement(cellId);
1084
1085 }
1086
1087 for (int i = 0; i < 200; ++i) {
1088 long cellId;
1089#if BITPIT_ENABLE_MPI==1
1090 if (patch_2D->getRank() == 0)
1091#endif
1092 cellId = rand() % nCells * 2;
1093#if BITPIT_ENABLE_MPI==1
1094 MPI_Bcast(&cellId, 1, MPI_LONG, 0, MPI_COMM_WORLD);
1095#endif
1096
1097 if (!patch_2D->getCells().exists(cellId)) {
1098 continue;
1099 }
1100
1101 patch_2D->markCellForCoarsening(cellId);
1102 for (auto neighId : patch_2D->findCellNeighs(cellId)) {
1103 patch_2D->markCellForCoarsening(neighId);
1104 }
1105
1106 }
1107
1108 log::cout() << std::endl;
1109 log::cout() << ">> Initial number of cells... " << nCells << std::endl;
1110
1111 std::vector<adaption::Info> infoAdapt = patch_2D->adaptionPrepare(true);
1112
1113 mapobject.adaptionPrepare(infoAdapt, false);
1114
1115 infoAdapt = patch_2D->adaptionAlter(true);
1116
1117 mapobject.adaptionAlter(infoAdapt, false, true);
1118
1119 patch_2D->adaptionCleanup();
1120
1121 mapobject.adaptionCleanup();
1122
1123 nCells = patch_2D->getCellCount();
1124 log::cout() << ">> Final number of cells... " << nCells << std::endl;
1125
1126
1128 PiercedStorage<double> data2(1, &patch_2D->getCells());
1129 data2.fill(0.0);
1130 {
1131
1132 const PiercedStorage<mapping::Info> & mapper = mapobject.getInverseMapping();
1133
1134#if BITPIT_ENABLE_MPI==1
1135 //Communicate needed data for mapping
1136 std::map<int, std::map<long, double> > datarec;
1137 std::map<int, std::map<long, double> > volrec;
1138 {
1139
1140 // recover id to be rec/sent
1141 std::map<int, std::set<long> > rankIDsend;
1142
1143 const PiercedStorage<mapping::Info> & _mapper = mapobject.getMapping();
1144
1145 for (Cell & cell : patch_2D_original->getCells()){
1146 long ID = cell.getId();
1147 auto info = _mapper[ID];
1148 int i = 0;
1149 for (int rank : info.ranks){
1150 if (rank != patch_2D_original->getRank()){
1151 rankIDsend[rank].insert(ID);
1152 }
1153 i++;
1154 }
1155 }
1156
1157 //build send buffers
1158 MPI_Comm comm;
1159 MPI_Comm_dup(MPI_COMM_WORLD, &comm);
1160 DataCommunicator dataCommunicator(comm);
1161 MPI_Barrier(comm);
1162 std::size_t bytes = uint8_t(2*sizeof(double) + sizeof(long));
1163 for (const auto &val : rankIDsend){
1164 int rank = val.first;
1165 //set size
1166 std::size_t buffSize = val.second.size() * bytes;
1167 dataCommunicator.setSend(rank,buffSize);
1168 //fill buffer with octants
1169 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
1170 for (long ID : val.second){
1171 sendBuffer << ID;
1172 sendBuffer << data[ID];
1173 sendBuffer << patch_2D_original->evalCellVolume(ID);
1174 }
1175 }
1176
1177 dataCommunicator.discoverRecvs();
1178 dataCommunicator.startAllRecvs();
1179 dataCommunicator.startAllSends();
1180
1181 std::vector<int> recvRanks = dataCommunicator.getRecvRanks();
1182 std::sort(recvRanks.begin(),recvRanks.end());
1183
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++){
1189 long ID;
1190 recvBuffer >> ID;
1191 recvBuffer >> datarec[rank][ID];
1192 recvBuffer >> volrec[rank][ID];
1193 }
1194 }
1195 dataCommunicator.waitAllSends();
1196
1197 }
1198#endif
1199
1200 std::vector<double> vdata2(patch_2D->getInternalCellCount());
1201 count = 0;
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()){
1208#endif
1209 data2[id] = data[mapper[id].ids[0]];
1210 vdata2[count] = data2[id];
1211#if BITPIT_ENABLE_MPI==1
1212 }
1213 else{
1214 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1215 vdata2[count] = data2[id];
1216 }
1217#endif
1218 }
1219 else if (mapper[id].type == mapping::Type::TYPE_COARSENING){
1220 data2[id] = 0.0;
1221 double Volume = 0.0;
1222 int i = 0;
1223 for (long idd : mapper[id].ids){
1224
1225 if (id == 348){
1226 std::cout << "mapped id : " << idd << std::endl;
1227 }
1228
1229
1230#if BITPIT_ENABLE_MPI==1
1231 if (mapper[id].ranks[i] == patch_2D->getRank()){
1232#endif
1233 data2[id] += data[idd] * patch_2D_original->evalCellVolume(idd);
1234 Volume += patch_2D_original->evalCellVolume(idd);
1235#if BITPIT_ENABLE_MPI==1
1236 }
1237 else{
1238 data2[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
1239 Volume += volrec[mapper[id].ranks[i]][idd];
1240 }
1241#endif
1242 i++;
1243 }
1244 data2[id] /= Volume;
1245 vdata2[count] = data2[id];
1246 }
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()){
1250#endif
1251 data2[id] = data[mapper[id].ids[0]];
1252 vdata2[count] = data2[id];
1253#if BITPIT_ENABLE_MPI==1
1254 }
1255 else{
1256 data2[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1257 vdata2[count] = data2[id];
1258 }
1259#endif
1260 }
1261 count++;
1262 }
1263 }
1264
1265 patch_2D->getVTK().addData("data", VTKFieldType::SCALAR, VTKLocation::CELL, vdata2);
1266 patch_2D->getVTK().setName("mesh_random_testM.1");
1267 patch_2D->write();
1268
1269 }
1270
1271
1273 {
1274 PiercedStorage<double> data2inv(1, &patch_2D_original->getCells());
1275 data2inv.fill(0.0);
1276
1277 const PiercedStorage<mapping::Info> & mapper = mapobject.getMapping();
1278
1279#if BITPIT_ENABLE_MPI==1
1280 //Communicate needed data for mapping
1281 std::map<int, std::map<long, double> > datarec;
1282 std::map<int, std::map<long, double> > volrec;
1283 {
1284 std::unordered_map<int, std::vector<long> > rankIDrec = mapobject.getReceivedMappedIds();
1285 std::unordered_map<int, std::vector<long> > rankIDsend = mapobject.getSentMappedIds();
1286
1287 //build send buffers
1288 MPI_Comm comm;
1289 MPI_Comm_dup(MPI_COMM_WORLD, &comm);
1290 DataCommunicator dataCommunicator(comm);
1291 MPI_Barrier(comm);
1292 std::size_t bytes = uint8_t(2*sizeof(double));
1293 for (const auto &val : rankIDsend){
1294 int rank = val.first;
1295 //set size
1296 std::size_t buffSize = val.second.size() * bytes;
1297 dataCommunicator.setSend(rank,buffSize);
1298 //fill buffer with octants
1299 SendBuffer &sendBuffer = dataCommunicator.getSendBuffer(rank);
1300 for (long ID : val.second){
1301 sendBuffer << data2[ID];
1302 sendBuffer << patch_2D->evalCellVolume(ID);
1303 }
1304 }
1305
1306 dataCommunicator.discoverRecvs();
1307 dataCommunicator.startAllRecvs();
1308 dataCommunicator.startAllSends();
1309
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];
1317 }
1318 }
1319 dataCommunicator.waitAllSends();
1320
1321 }
1322#endif
1323
1324 std::vector<double> vdata2inv(patch_2D_original->getInternalCellCount());
1325 count = 0;
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()){
1332#endif
1333 data2inv[id] = data2[mapper[id].ids[0]];
1334 vdata2inv[count] = data2inv[id];
1335#if BITPIT_ENABLE_MPI==1
1336 }
1337 else{
1338 data2inv[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1339 vdata2inv[count] = data2inv[id];
1340 }
1341#endif
1342 }
1343 else if (mapper[id].type == mapping::Type::TYPE_COARSENING){
1344 data2inv[id] = 0.0;
1345 double Volume = 0.0;
1346 int i = 0;
1347 for (long idd : mapper[id].ids){
1348#if BITPIT_ENABLE_MPI==1
1349 if (mapper[id].ranks[i] == patch_2D_original->getRank()){
1350#endif
1351 data2inv[id] += data2[idd] * patch_2D->evalCellVolume(idd);
1352 Volume += patch_2D->evalCellVolume(idd);
1353#if BITPIT_ENABLE_MPI==1
1354 }
1355 else{
1356 data2inv[id] += datarec[mapper[id].ranks[i]][idd] * volrec[mapper[id].ranks[i]][idd];
1357 Volume += volrec[mapper[id].ranks[i]][idd];
1358 }
1359#endif
1360 i++;
1361 }
1362 data2inv[id] /= Volume;
1363 vdata2inv[count] = data2inv[id];
1364 }
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()){
1368#endif
1369 data2inv[id] = data2[mapper[id].ids[0]];
1370 vdata2inv[count] = data2inv[id];
1371#if BITPIT_ENABLE_MPI==1
1372 }
1373 else{
1374 data2inv[id] = datarec[mapper[id].ranks[0]][mapper[id].ids[0]];
1375 vdata2inv[count] = data2inv[id];
1376 }
1377#endif
1378 }
1379 count++;
1380 }
1381 }
1382
1383#if BITPIT_ENABLE_MPI==1
1384 MPI_Comm comm = MPI_COMM_WORLD;
1385 MPI_Barrier(comm);
1386#endif
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();
1390
1391 }
1392
1393}
1394
1399int main(int argc, char *argv[])
1400{
1401
1402#if BITPIT_ENABLE_MPI==1
1403 MPI_Init(&argc,&argv);
1404#endif
1405
1406
1408 try {
1409 runReferenceAdaptation();
1410 } catch (const std::exception &exception) {
1411 log::cout() << exception.what();
1412 exit(1);
1413 }
1414
1415 try {
1416 runMappedAdaptation();
1417 } catch (const std::exception &exception) {
1418 log::cout() << exception.what();
1419 exit(1);
1420 }
1421
1422#if BITPIT_ENABLE_MPI==1
1423 MPI_Finalize();
1424#endif
1425
1426}
The Cell class defines the cells.
Definition cell.hpp:42
The DataCommunicator class provides the infrastructure needed to exchange data among processes.
PABLO Uniform is an example of user class derived from ParaTree to map ParaTree in a uniform (square/...
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)
Definition VTK.cpp:281
void setName(const std::string &)
Definition VTK.cpp:119
The VolOctreeMapper is the class to map two meshes of class VolOctree.
The VolOctree defines a Octree patch.
Definition voloctree.hpp:37
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)
Definition logger.cpp:1705
Logger & info(log::Visibility defaultVisibility)
Definition logger.cpp:1847
--- layout: doxygen_footer ---