Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_EB2_Level.H
Go to the documentation of this file.
1#ifndef AMREX_EB2_LEVEL_H_
2#define AMREX_EB2_LEVEL_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_ParmParse.H>
6#include <AMReX_Geometry.H>
7#include <AMReX_MultiFab.H>
8#include <AMReX_iMultiFab.H>
9#include <AMReX_LayoutData.H>
10#include <AMReX_VisMF.H>
11#include <AMReX_Array.H>
12#include <AMReX_EBCellFlag.H>
13#include <AMReX_MultiCutFab.H>
14#if (AMREX_SPACEDIM == 3)
15# include <AMReX_MarchingCubes.H>
16#endif
17#include <AMReX_EB2_MultiGFab.H>
18#include <AMReX_EB2_C.H>
20
21#ifdef AMREX_USE_OMP
22#include <omp.h>
23#endif
24
25#include <cmath>
26#include <limits>
27#include <map>
28#include <type_traits>
29#include <unordered_map>
30
31namespace amrex
32{
33 class STLtools;
34}
35
36namespace amrex::EB2 {
37
38class IndexSpace;
39template <typename G> class GShopLevel;
40
41class Level
42{
43public:
44
46 bool isAllRegular () const noexcept { return m_allregular; }
48 bool isOK () const noexcept { return m_ok; }
59 void fillVolFrac (MultiFab& vfrac, const Geometry& geom) const;
63 void fillCentroid (MultiCutFab& centroid, const Geometry& geom) const;
65 void fillCentroid ( MultiFab& centroid, const Geometry& geom) const;
69 void fillBndryArea (MultiCutFab& bndryarea, const Geometry& geom) const;
71 void fillBndryArea ( MultiFab& bndryarea, const Geometry& geom) const;
75 void fillBndryCent (MultiCutFab& bndrycent, const Geometry& geom) const;
77 void fillBndryCent ( MultiFab& bndrycent, const Geometry& geom) const;
81 void fillBndryNorm (MultiCutFab& bndrynorm, const Geometry& geom) const;
83 void fillBndryNorm ( MultiFab& bndrynorm, const Geometry& geom) const;
87 void fillAreaFrac (Array<MultiCutFab*,AMREX_SPACEDIM> const& areafrac, const Geometry& geom) const;
89 void fillAreaFrac (Array< MultiFab*,AMREX_SPACEDIM> const& areafrac, const Geometry& geom) const;
93 void fillFaceCent (Array<MultiCutFab*,AMREX_SPACEDIM> const& facecent, const Geometry& geom) const;
95 void fillFaceCent (Array< MultiFab*,AMREX_SPACEDIM> const& facecent, const Geometry& geom) const;
99 void fillEdgeCent (Array<MultiCutFab*,AMREX_SPACEDIM> const& edgecent, const Geometry& geom) const;
101 void fillEdgeCent (Array< MultiFab*,AMREX_SPACEDIM> const& edgecent, const Geometry& geom) const;
105 void fillLevelSet (MultiFab& levelset, const Geometry& geom) const;
106
108 const BoxArray& boxArray () const noexcept { return m_grids; }
110 const DistributionMapping& DistributionMap () const noexcept { return m_dmap; }
111
113 Level (IndexSpace const* is, const Geometry& geom) : m_geom(geom), m_parent(is) {}
117 void prepareForCoarsening (const Level& rhs, int max_grid_size, IntVect const& ngrow);
118
120 const Geometry& Geom () const noexcept { return m_geom; }
122 IndexSpace const* getEBIndexSpace () const noexcept { return m_parent; }
123
125 IntVect const& nGrowVect () const noexcept { return m_ngrow; }
126
134 void write_to_chkpt_file (const std::string& fname, bool extend_domain_face, int max_grid_size) const;
135
137 bool hasEBInfo () const noexcept { return m_has_eb_info; }
139 void fillCutCellMask (iMultiFab& cutcellmask, const Geometry& geom) const;
140
144 void setShift (int direction, int ncells);
145
149 struct FCData {
159 // Covered region of the refined level, coarsened onto this level. The refined level
160 // is transient, so this has to be captured while it exists. It is not the same as
161 // Level::m_covered_grids: the refined level resolves the body more finely, so once
162 // coarsened its covered region is the larger of the two, and it is the one that
163 // matches where the face-centered data was computed.
164 //
165 // The fill*FC functions apply it before their ParallelCopy, and deliberately do not
166 // shrink it first. A face-centered cell straddles two cell-centered cells, so the
167 // ones on the covered/cut interface may themselves be cut; clearing them here and
168 // letting the copy write over them is correct, because the copy writes exactly where
169 // the face-centered data is valid - the nodal span of the cut boxes, which reaches
170 // the interface and no further. Ordering does the shrinking, so no box has to be
171 // trimmed and two adjacent covered boxes need no special treatment.
173 bool m_built = false;
174 };
175
184 [[nodiscard]] static IntVect fcEdgeType (int idim, int face_dir) noexcept {
185 IntVect edge_type{1};
186 if (idim != face_dir) { edge_type[idim] = 0; }
187 return edge_type;
188 }
189
191 [[nodiscard]] bool hasFCData (int face_dir) const noexcept {
192 return face_dir >= 0 && face_dir < AMREX_SPACEDIM &&
193 m_fc_data[face_dir] && m_fc_data[face_dir]->m_built;
194 }
195
197 [[nodiscard]] const FCData& getFCData (int face_dir) const {
198 AMREX_ASSERT(hasFCData(face_dir));
199 return *m_fc_data[face_dir];
200 }
201
203 void fillVolFracFC (MultiFab& vfrac, int face_dir, const Geometry& geom) const;
205 void fillAreaFracFC (Array< MultiFab*,AMREX_SPACEDIM> const& areafrac, int face_dir, const Geometry& geom) const;
206 void fillAreaFracFC (Array<MultiCutFab*,AMREX_SPACEDIM> const& areafrac, int face_dir, const Geometry& geom) const;
208 void fillCentroidFC (MultiFab& centroid, int face_dir, const Geometry& geom) const;
209 void fillCentroidFC (MultiCutFab& centroid, int face_dir, const Geometry& geom) const;
211 void fillBndryAreaFC (MultiFab& bndryarea, int face_dir, const Geometry& geom) const;
212 void fillBndryAreaFC (MultiCutFab& bndryarea, int face_dir, const Geometry& geom) const;
214 void fillBndryCentFC (MultiFab& bndrycent, int face_dir, const Geometry& geom) const;
215 void fillBndryCentFC (MultiCutFab& bndrycent, int face_dir, const Geometry& geom) const;
217 void fillBndryNormFC (MultiFab& bndrynorm, int face_dir, const Geometry& geom) const;
218 void fillBndryNormFC (MultiCutFab& bndrynorm, int face_dir, const Geometry& geom) const;
220 void fillEBCellFlagFC (FabArray<EBCellFlagFab>& cellflag, int face_dir, const Geometry& geom) const;
222 void fillFaceCentFC (Array< MultiFab*,AMREX_SPACEDIM> const& facecent, int face_dir, const Geometry& geom) const;
223 void fillFaceCentFC (Array<MultiCutFab*,AMREX_SPACEDIM> const& facecent, int face_dir, const Geometry& geom) const;
225 void fillEdgeCentFC (Array< MultiFab*,AMREX_SPACEDIM> const& edgecent, int face_dir, const Geometry& geom) const;
226 void fillEdgeCentFC (Array<MultiCutFab*,AMREX_SPACEDIM> const& edgecent, int face_dir, const Geometry& geom) const;
227
228// public: // for cuda
236 int coarsenFromFine (Level& fineLevel, bool fill_boundary);
238 void buildCellFlag ();
240 void buildCutCellMask (Level const& fine_level);
241
242protected:
243
250#if (AMREX_SPACEDIM == 3)
251 std::map<int,std::unique_ptr<MC::MCFab>> m_marching_cubes;
252#endif
265 bool m_allregular = false;
266 bool m_ok = false;
267 bool m_has_eb_info = true;
270
273
274private:
275 template <typename G> friend class GShopLevel;
276
277 // Need this function to work around a gcc bug.
278 void setRegularLevel () {
279 m_allregular = true;
280 m_ok = true;
281 m_has_eb_info = false;
282 }
283};
284
285template <typename G>
287 : public Level
288{
289public:
293 GShopLevel (IndexSpace const* is, G const& gshop, const Geometry& geom, int max_grid_size,
294 int ngrow, bool extend_domain_face, int num_crse_opt);
298 GShopLevel (IndexSpace const* is, int ilev, int max_grid_size, int ngrow,
299 const Geometry& geom, GShopLevel<G>& fineLevel);
301 GShopLevel (IndexSpace const* is, const Geometry& geom);
303 void define_fine (G const& gshop, const Geometry& geom,
304 int max_grid_size, int ngrow, bool extend_domain_face, int num_crse_opt);
305
306#if (AMREX_SPACEDIM == 3)
310 template <typename GS = G>
311 requires (std::same_as<GS,STLtools>)
312 void define_fine_mvmc (GS const& gshop, const Geometry& geom,
313 int max_grid_size, int ngrow, bool extend_domain_face, int num_crse_opt);
314#endif
315
319 static GShopLevel<G>
320 makeAllRegular(IndexSpace const* is, const Geometry& geom)
321 {
322 GShopLevel<G> r(is, geom);
323 r.setRegularLevel();
324 return r;
325 }
326
328 void buildFCData (G const& gshop, int face_dir, int max_grid_size);
329
330private:
331
332 Box m_bounding_box;
333
334 void prepare_grids (G const& gshop, Geometry const& geom, int max_grid_size, int ngrow,
335 bool extend_domain_face, int num_crse_opt);
336
337};
338
339template <typename G>
341 : Level(is, geom)
342{}
343
344template <typename G>
345GShopLevel<G>::GShopLevel (IndexSpace const* is, G const& gshop, const Geometry& geom,
346 int max_grid_size, int ngrow, bool extend_domain_face, int num_crse_opt)
347 : Level(is, geom)
348{
349 if (std::is_same_v<typename G::FunctionType, AllRegularIF>) {
350 m_allregular = true;
351 m_ok = true;
352 return;
353 }
354
355 define_fine(gshop, geom, max_grid_size, ngrow, extend_domain_face, num_crse_opt);
356}
357
358template <typename G>
359void
360GShopLevel<G>::prepare_grids (G const& gshop, const Geometry& geom,
361 int max_grid_size, int ngrow, bool extend_domain_face, int num_crse_opt)
362{
363 if (amrex::Verbose() > 0 && extend_domain_face == false) {
364 amrex::Print() << "AMReX WARNING: extend_domain_face=false is not recommended!\n";
365 }
366
367 BL_PROFILE("EB2::GShopLevel()-prepare_grids");
368
369 // make sure ngrow is multiple of 16
370 m_ngrow = IntVect{static_cast<int>(std::ceil(ngrow/16.)) * 16};
371
372 Box const& domain = geom.Domain();
373 Box domain_grown = domain;
374 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
375 if (geom.isPeriodic(idim)) {
376 m_ngrow[idim] = 0;
377 } else {
378 m_ngrow[idim] = std::min(m_ngrow[idim], domain_grown.length(idim));
379 }
380 }
381 domain_grown.grow(m_ngrow);
382 m_bounding_box = (extend_domain_face) ? domain : domain_grown;
383 m_bounding_box.surroundingNodes();
384
385 BoxList cut_boxes;
386 BoxList covered_boxes;
387
388 const int nprocs = ParallelDescriptor::NProcs();
389 const int iproc = ParallelDescriptor::MyProc();
390
391 num_crse_opt = std::max(0,std::min(8,num_crse_opt));
392 for (int clev = num_crse_opt; clev >= 0; --clev) {
393 IntVect crse_ratio(1 << clev);
394 if (domain.coarsenable(crse_ratio)) {
395 Box const& crse_bounding_box = amrex::coarsen(m_bounding_box, crse_ratio);
396 Geometry const& crse_geom = amrex::coarsen(geom, crse_ratio);
397 BoxList test_boxes;
398 if (cut_boxes.isEmpty()) {
399 covered_boxes.clear();
400 test_boxes = BoxList(crse_geom.Domain());
401 test_boxes.maxSize(max_grid_size);
402 } else {
403 test_boxes.swap(cut_boxes);
404 test_boxes.coarsen(crse_ratio);
405 test_boxes.maxSize(max_grid_size);
406 }
407
408 const Long nboxes = test_boxes.size();
409 const auto& boxes = test_boxes.data();
410 for (Long i = iproc; i < nboxes; i += nprocs) {
411 const Box& vbx = boxes[i];
412 const Box& gbx = amrex::surroundingNodes(amrex::grow(vbx,1));
413 auto box_type = gshop.getBoxType(gbx&crse_bounding_box,crse_geom,RunOn::Gpu);
414 if (box_type == gshop.allcovered) {
415 covered_boxes.push_back(amrex::refine(vbx, crse_ratio));
416 } else if (box_type == gshop.mixedcells) {
417 cut_boxes.push_back(amrex::refine(vbx, crse_ratio));
418 }
419 }
420
421 amrex::AllGatherBoxes(cut_boxes.data());
422 }
423 }
424
425 amrex::AllGatherBoxes(covered_boxes.data());
426
427 if (m_ngrow != 0) {
428 auto grow_at_domain_boundary = [&] (BoxList& bl)
429 {
430 const IntVect& domlo = domain.smallEnd();
431 const IntVect& domhi = domain.bigEnd();
432 for (auto& b : bl) {
433 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
434 if (m_ngrow[idim] != 0) {
435 if (b.smallEnd(idim) == domlo[idim]) {
436 b.growLo(idim,m_ngrow[idim]);
437 }
438 if (b.bigEnd(idim) == domhi[idim]) {
439 b.growHi(idim,m_ngrow[idim]);
440 }
441 }
442 }
443 }
444 };
445 grow_at_domain_boundary(covered_boxes);
446 grow_at_domain_boundary(cut_boxes);
447 }
448
449 if ( cut_boxes.isEmpty() &&
450 !covered_boxes.isEmpty())
451 {
452 amrex::Abort("AMReX_EB2_Level.H: Domain is completely covered");
453 }
454
455 if (!covered_boxes.isEmpty()) {
456 if (num_crse_opt > 2) { // don't want the box too big
457 covered_boxes.maxSize(max_grid_size*4);
458 }
459 m_covered_grids = BoxArray(std::move(covered_boxes));
460 }
461
462 if (cut_boxes.isEmpty()) {
463 m_grids = BoxArray();
464 m_dmap = DistributionMapping();
465 m_allregular = true;
466 m_ok = true;
467 } else {
468 m_grids = BoxArray(std::move(cut_boxes));
469 m_dmap = DistributionMapping(m_grids);
470 }
471}
472
473template <typename G>
474void
475GShopLevel<G>::define_fine (G const& gshop, const Geometry& geom,
476 int max_grid_size, int ngrow, bool extend_domain_face, int num_crse_opt)
477{
478 BL_PROFILE("EB2::GShopLevel()-fine");
479
480#ifdef AMREX_USE_FLOAT
481 Real small_volfrac = 1.e-5_rt;
482#else
483 Real small_volfrac = 1.e-14;
484#endif
485 bool cover_multiple_cuts = false;
486 int maxiter = 32;
487 {
488 ParmParse pp("eb2");
489 pp.queryAdd("small_volfrac", small_volfrac);
490 pp.queryAdd("cover_multiple_cuts", cover_multiple_cuts);
491 pp.queryAdd("maxiter", maxiter);
492 }
493 maxiter = std::min(100000, maxiter);
494
495 prepare_grids(gshop, geom, max_grid_size, ngrow, extend_domain_face, num_crse_opt);
496
497 if (m_allregular) { return; }
498
499 m_mgf.define(m_grids, m_dmap);
500 const int ng = GFab::ng;
501 MFInfo mf_info;
502 mf_info.SetTag("EB2::Level");
503 m_cellflag.define(m_grids, m_dmap, 1, ng, mf_info);
504 m_volfrac.define(m_grids, m_dmap, 1, ng, mf_info);
505 m_centroid.define(m_grids, m_dmap, AMREX_SPACEDIM, ng, mf_info);
506 m_bndryarea.define(m_grids, m_dmap, 1, ng, mf_info);
507 m_bndrycent.define(m_grids, m_dmap, AMREX_SPACEDIM, ng, mf_info);
508 m_bndrynorm.define(m_grids, m_dmap, AMREX_SPACEDIM, ng, mf_info);
509 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
510 m_areafrac[idim].define(amrex::convert(m_grids, IntVect::TheDimensionVector(idim)),
511 m_dmap, 1, ng, mf_info);
512 m_facecent[idim].define(amrex::convert(m_grids, IntVect::TheDimensionVector(idim)),
513 m_dmap, AMREX_SPACEDIM-1, ng, mf_info);
514 IntVect edge_type{1}; edge_type[idim] = 0;
515 m_edgecent[idim].define(amrex::convert(m_grids, edge_type), m_dmap, 1, ng, mf_info);
516 }
517
518 const auto dx = geom.CellSizeArray();
519 const auto problo = geom.ProbLoArray();
520
521 auto bounding_box = m_bounding_box;
522 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
523 if (!extend_domain_face || geom.isPeriodic(idim)) {
524 bounding_box.grow(idim,GFab::ng);
525 }
526 }
527
528 RunOn gshop_run_on = (Gpu::inLaunchRegion() && gshop.isGPUable())
530
531 bool hybrid = Gpu::inLaunchRegion() && (gshop_run_on == RunOn::Cpu);
532 amrex::ignore_unused(hybrid);
533
534 int iter = 0;
535 for (; iter < maxiter; ++iter)
536 {
537 int nsmallcells = 0;
538 int nmulticuts = 0;
539#ifdef AMREX_USE_OMP
540#pragma omp parallel if (Gpu::notInLaunchRegion()) reduction(+:nsmallcells,nmulticuts)
541#endif
542 {
543#if (AMREX_SPACEDIM == 3)
544 Array<BaseFab<Real>, AMREX_SPACEDIM> M2;
545 EBCellFlagFab cellflagtmp;
546#endif
547 for (MFIter mfi(m_mgf); mfi.isValid(); ++mfi)
548 {
549 auto& gfab = m_mgf[mfi];
550 const Box& vbx = gfab.validbox();
551
552 auto& levelset = gfab.getLevelSet();
553 if (iter == 0) {
554 gshop.fillFab(levelset, geom, gshop_run_on, bounding_box);
555#ifdef AMREX_USE_GPU
556 if (hybrid) {
557 levelset.prefetchToDevice();
558 }
559#endif
560 }
561
562 auto& cellflag = m_cellflag[mfi];
563
564 gfab.buildTypes(cellflag);
565
566 Array4<Real const> const& clst = levelset.const_array();
567 Array4<Real > const& lst = levelset.array();
568 Array4<EBCellFlag> const& cfg = m_cellflag.array(mfi);
569 Array4<Real> const& vfr = m_volfrac.array(mfi);
570 Array4<Real> const& ctr = m_centroid.array(mfi);
571 Array4<Real> const& bar = m_bndryarea.array(mfi);
572 Array4<Real> const& bct = m_bndrycent.array(mfi);
573 Array4<Real> const& bnm = m_bndrynorm.array(mfi);
574 AMREX_D_TERM(Array4<Real> const& apx = m_areafrac[0].array(mfi);,
575 Array4<Real> const& apy = m_areafrac[1].array(mfi);,
576 Array4<Real> const& apz = m_areafrac[2].array(mfi););
577 AMREX_D_TERM(Array4<Real> const& fcx = m_facecent[0].array(mfi);,
578 Array4<Real> const& fcy = m_facecent[1].array(mfi);,
579 Array4<Real> const& fcz = m_facecent[2].array(mfi););
580
581 auto& facetype = gfab.getFaceType();
582 AMREX_D_TERM(Array4<Type_t> const& ftx = facetype[0].array();,
583 Array4<Type_t> const& fty = facetype[1].array();,
584 Array4<Type_t> const& ftz = facetype[2].array(););
585
586 int nmc = 0;
587 int nsm = 0;
588
589#if (AMREX_SPACEDIM == 3)
590 auto& edgetype = gfab.getEdgeType();
591 Array4<Type_t const> const& xdg = edgetype[0].const_array();
592 Array4<Type_t const> const& ydg = edgetype[1].const_array();
593 Array4<Type_t const> const& zdg = edgetype[2].const_array();
594
595 Array4<Real> const& xip = m_edgecent[0].array(mfi);
596 Array4<Real> const& yip = m_edgecent[1].array(mfi);
597 Array4<Real> const& zip = m_edgecent[2].array(mfi);
598
599 if (iter == 0) {
600#ifdef AMREX_USE_GPU
601 if (hybrid) {
603 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
604 edgetype[idim].prefetchToHost();
605 m_edgecent[idim][mfi].prefetchToHost();
606 }
607 }
608#endif
609
610 gshop.getIntercept({xip,yip,zip}, {xdg,ydg,zdg}, clst,
611 geom, gshop_run_on, bounding_box);
612
613#ifdef AMREX_USE_GPU
614 if (hybrid) {
615 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
616 edgetype[idim].prefetchToDevice();
617 m_edgecent[idim][mfi].prefetchToDevice();
618 }
619 }
620#endif
621 } else {
622 gshop.updateIntercept({xip,yip,zip}, {xdg,ydg,zdg}, clst, geom);
623 }
624
625 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
626 const Box& b = facetype[idim].box();
627 M2[idim].resize(b,3);
628 }
629 Array4<Real> const& xm2 = M2[0].array();
630 Array4<Real> const& ym2 = M2[1].array();
631 Array4<Real> const& zm2 = M2[2].array();
632
633 nmc = build_faces(vbx, cfg, ftx, fty, ftz, xdg, ydg, zdg, lst,
634 xip, yip, zip, apx, apy, apz, fcx, fcy, fcz,
635 xm2, ym2, zm2, dx, problo, cover_multiple_cuts);
636
637 cellflagtmp.resize(m_cellflag[mfi].box());
638 Elixir cellflagtmp_eli = cellflagtmp.elixir();
639 Array4<EBCellFlag> const& cfgtmp = cellflagtmp.array();
640
641 build_cells(vbx, cfg, ftx, fty, ftz, apx, apy, apz,
642 fcx, fcy, fcz, xm2, ym2, zm2, dx, vfr, ctr,
643 bar, bct, bnm, cfgtmp, lst,
644 small_volfrac, geom, extend_domain_face, cover_multiple_cuts,
645 nsm, nmc);
646
647 // Because it is used in a synchronous reduction kernel in
648 // build_cells, we do not need to worry about M2's lifetime.
649 // But we still need to use Elixir to extend the life of
650 // cellflagtmp.
651
652#elif (AMREX_SPACEDIM == 2)
653 Array4<Real> const& xip = m_edgecent[0].array(mfi);
654 Array4<Real> const& yip = m_edgecent[1].array(mfi);
655
656 if (iter == 0) {
657#ifdef AMREX_USE_GPU
658 if (hybrid) {
660 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
661 facetype[idim].prefetchToHost();
662 m_edgecent[idim][mfi].prefetchToHost();
663 }
664 }
665#endif
666
667 // yes, factype[1] and then [0]
668 gshop.getIntercept({xip,yip},
669 {facetype[1].const_array(), facetype[0].const_array()},
670 clst, geom, gshop_run_on, bounding_box);
671
672#ifdef AMREX_USE_GPU
673 if (hybrid) {
674 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
675 facetype[idim].prefetchToDevice();
676 m_edgecent[idim][mfi].prefetchToDevice();
677 }
678 }
679#endif
680 } else {
681 gshop.updateIntercept({xip,yip},
682 {facetype[1].const_array(), facetype[0].const_array()},
683 clst, geom);
684 }
685
686 nmc = build_faces(vbx, cfg, ftx, fty, lst, xip, yip, apx, apy, fcx, fcy,
687 dx, problo, cover_multiple_cuts, nsm);
688
689 build_cells(vbx, cfg, ftx, fty, apx, apy, dx, vfr, ctr,
690 bar, bct, bnm, lst, small_volfrac, geom, extend_domain_face,
691 nsm, nmc);
692#endif
693 nsmallcells += nsm;
694 nmulticuts += nmc;
695 }
696 }
697
698 ParallelAllReduce::Sum<int>({nsmallcells,nmulticuts}, ParallelContext::CommunicatorSub());
699 if (nsmallcells == 0 && nmulticuts == 0) {
700 break;
701 } else {
702 auto ls = m_mgf.getLevelSet();
703 // This is an alias MultiFab, therefore FillBoundary on it is fine.
704 ls.FillBoundary(geom.periodicity());
705 if (amrex::Verbose() > 0) {
706 if (nsmallcells) {
707 amrex::Print() << "AMReX EB: Iter. " << iter+1 << " fixed " << nsmallcells
708 << " small cells" << '\n';
709 }
710 if (nmulticuts) {
711 amrex::Print() << "AMReX EB: Iter. " << iter+1 << " fixed " << nmulticuts
712 << " multicuts" << '\n';
713 }
714 }
715 }
716 }
717
718 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(iter < maxiter, "EB: failed to fix small cells");
719
720#ifdef AMREX_USE_OMP
721#pragma omp parallel if (Gpu::notInLaunchRegion())
722#endif
723 for (MFIter mfi(m_mgf); mfi.isValid(); ++mfi)
724 {
725 auto& gfab = m_mgf[mfi];
726 auto const& levelset = gfab.getLevelSet();
727 Array4<Real const> const& clst = levelset.const_array();
728
729 AMREX_D_TERM(Array4<Real> const& xip = m_edgecent[0].array(mfi);,
730 Array4<Real> const& yip = m_edgecent[1].array(mfi);,
731 Array4<Real> const& zip = m_edgecent[2].array(mfi);)
732#if (AMREX_SPACEDIM == 3)
733 auto const& edgetype = gfab.getEdgeType();
734 Array4<Type_t const> const& xdg = edgetype[0].const_array();
735 Array4<Type_t const> const& ydg = edgetype[1].const_array();
736 Array4<Type_t const> const& zdg = edgetype[2].const_array();
737
738 intercept_to_edge_centroid(xip, yip, zip, xdg, ydg, zdg, clst, dx, problo);
739
740#elif (AMREX_SPACEDIM == 2)
741 auto& facetype = gfab.getFaceType();
742 Array4<Type_t const> const& ftx = facetype[0].const_array();
743 Array4<Type_t const> const& fty = facetype[1].const_array();
744 // fty then ftx
745 intercept_to_edge_centroid(xip, yip, fty, ftx, clst, dx, problo);
746#endif
747 }
748
749 m_levelset = m_mgf.getLevelSet();
750
751 m_ok = true;
752}
753
754#if (AMREX_SPACEDIM == 3)
755template <typename G>
756template <typename GS>
757requires (std::same_as<GS,STLtools>)
758void
759GShopLevel<G>::define_fine_mvmc (GS const& gshop, const Geometry& geom,
760 int max_grid_size, int ngrow, bool extend_domain_face, int num_crse_opt)
761{
762 BL_PROFILE("EB2::GShopLevel()-fine-mvmc");
763
764 prepare_grids(gshop, geom, max_grid_size, ngrow, extend_domain_face, num_crse_opt);
765
766 if (m_allregular) { return; }
767
769
770 m_sdf.define(amrex::convert(m_grids,IntVect(1)), m_dmap, 1, IntVect(1));
771 gshop.fillSignedDistance(m_sdf, m_sdf.nGrowVect(), geom);
772
773 for (MFIter mfi(m_sdf,MFItInfo().DisableDeviceSync()); mfi.isValid(); ++mfi) {
774 m_marching_cubes[mfi.index()] = std::make_unique<MC::MCFab>();
775 }
776
777 MFItInfo info{};
778
779#if defined(AMREX_USE_OMP) && !defined(AMREX_USE_GPU)
780 info.SetDynamic(true);
781#pragma omp parallel
782#endif
783 for (MFIter mfi(m_sdf,info); mfi.isValid(); ++mfi) {
784 amrex::MC::marching_cubes(geom, m_sdf[mfi], *m_marching_cubes[mfi.index()]);
785 }
786
787 MC::write_stl("test.stl", m_marching_cubes);
788
789 m_ok = false; // xxxxx TODO
790}
791#endif
792
793template <typename G>
794GShopLevel<G>::GShopLevel (IndexSpace const* is, int /*ilev*/, int max_grid_size, int /*ngrow*/,
795 const Geometry& geom, GShopLevel<G>& fineLevel)
796 : Level(is, geom)
797{
798 if (fineLevel.isAllRegular()) {
799 m_allregular = true;
800 m_ok = true;
801 return;
802 }
803
804 BL_PROFILE("EB2::GShopLevel()-coarse");
805
806 const BoxArray& fine_grids = fineLevel.m_grids;
807 const BoxArray& fine_covered_grids = fineLevel.m_covered_grids;
808
809 const int coarse_ratio = 2;
810 const int min_width = 8;
811 bool coarsenable = fine_grids.coarsenable(coarse_ratio, min_width)
812 && (fine_covered_grids.empty() || fine_covered_grids.coarsenable(coarse_ratio));
813
814 m_ngrow = amrex::coarsen(fineLevel.m_ngrow,2);
815 if (amrex::scale(m_ngrow,2) != fineLevel.m_ngrow) {
817 }
818
819 if (coarsenable)
820 {
821 int ierr = coarsenFromFine(fineLevel, true);
822 m_ok = (ierr == 0);
823 }
824 else
825 {
826 Level fine_level_2(is, fineLevel.m_geom);
827 fine_level_2.prepareForCoarsening(fineLevel, max_grid_size, amrex::scale(m_ngrow,2));
828 int ierr = coarsenFromFine(fine_level_2, false);
829 m_ok = (ierr == 0);
830 }
831}
832
833template <typename G>
834void
835GShopLevel<G>::buildFCData (G const& gshop, int face_dir, int max_grid_size)
836{
837 BL_PROFILE("EB2::GShopLevel::buildFCData");
838
839 AMREX_ASSERT(face_dir >= 0 && face_dir < AMREX_SPACEDIM);
840
841 // Allocate FC data structure if needed
842 if (!m_fc_data[face_dir]) {
843 m_fc_data[face_dir] = std::make_unique<FCData>();
844 }
845
846 if (m_fc_data[face_dir]->m_built) { return; }
847
848 if (m_allregular) {
849 // An all-regular level carries no MultiFabs, and there is nothing to coarsen. Mark the
850 // face-centered data built anyway so that hasFCData() is true and a face-centered factory
851 // can be constructed: the fill*FC functions fill the regular values for such a level
852 // without reading anything, exactly as their cell-centered counterparts do.
853 m_fc_data[face_dir]->m_built = true;
854 return;
855 }
856
857 // **********************************************************************
858 // STEP1: Get or build the one-level-finer CC data
859 // **********************************************************************
860
861 Level const* refined_cc_level = nullptr;
862 std::unique_ptr<GShopLevel<G>> transient_level;
863
864 // Always create transient refined CC level to avoid grid mismatch
865 // with application-defined BoxArrays (ERF EB-FC development)
866 Geometry refined_geom = amrex::refine(m_geom, 2);
867 transient_level = std::make_unique<GShopLevel<G>>(
868 m_parent, gshop, refined_geom,
869 max_grid_size, m_ngrow[0] > 0 ? m_ngrow[0] : 4, true, 0); // xxxxx TODO: should we use IndexSpace's member variables extend_domain_face and num_crse_opt?
870
871 if (!transient_level->isOK()) {
872 amrex::Abort("GShopLevel::buildFCData: failed to build refined level");
873 }
874 refined_cc_level = transient_level.get();
875
876 // **********************************************************************
877 // STEP2: Check multi-cut error
878 // **********************************************************************
879
880 // Everything below is local. m_grids, m_dmap and m_levelset describe the cell-centered
881 // level that the IndexSpace hands to every EBFArrayBoxFactory built from it, so building
882 // face-centered data must not touch them: overwriting m_grids would leave Level::boxArray()
883 // describing a different region than the cell-centered data it belongs to, and redefining
884 // m_levelset on those grids would silently change the level set that cell-centered
885 // factories created afterwards report.
886 //
887 // The grids are coarsened from the refined level rather than taken from m_grids so that the
888 // DistributionMapping stays compatible with the refined data we read below.
889 const BoxArray fc_base_grids = amrex::coarsen(refined_cc_level->m_grids, 2);
890 if (!refined_cc_level->m_covered_grids.empty()) {
891 m_fc_data[face_dir]->m_covered_grids_fc =
892 amrex::coarsen(refined_cc_level->m_covered_grids, 2);
893 }
894 const DistributionMapping fc_dmap = refined_cc_level->m_dmap;
895
896 // Face-centered data provides no level set, so nothing here coarsens one. The multi-cut check
897 // below only needs an MFIter over the coarse boxes, walking alongside the refined level set
898 // that shares this DistributionMapping, so this MultiFab is declared without data.
899 auto const& f_levelset = refined_cc_level->m_levelset;
900 MultiFab crse_boxes(amrex::convert(fc_base_grids,IntVect::TheNodeVector()), fc_dmap, 1, 0,
901 MFInfo{}.SetAlloc(false));
902
903 int mvmc_error = 0;
904
906 {
907#ifdef AMREX_USE_OMP
908#pragma omp parallel reduction(max:mvmc_error)
909#endif
910 for (MFIter mfi(crse_boxes,true); mfi.isValid(); ++mfi)
911 {
912 const Box& ccbx = mfi.tilebox(IntVect::TheCellVector());
913 auto const& fine = f_levelset.const_array(mfi);
914
915 int tile_error = 0;
916 amrex::LoopOnCpu(ccbx,
917 [=,&tile_error] (int i, int j, int k) noexcept
918 {
919 int ierror = check_mvmc(i,j,k,fine);
920 tile_error = std::max(tile_error,ierror);
921 });
922
923 mvmc_error = std::max(mvmc_error, tile_error);
924 }
925 }
926 else
927 {
928 ReduceOps<ReduceOpMax> reduce_op;
929 ReduceData<int> reduce_data(reduce_op);
930 using ReduceTuple = typename decltype(reduce_data)::Type;
931
932 for (MFIter mfi(crse_boxes); mfi.isValid(); ++mfi)
933 {
934 const Box& ndbx = mfi.validbox();
935 const Box& ccbx = amrex::enclosedCells(ndbx);
936 auto const& fine = f_levelset.const_array(mfi);
937 reduce_op.eval(ndbx, reduce_data,
938 [=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple
939 {
940 int ierror;
941 if (ccbx.contains(IntVect{AMREX_D_DECL(i,j,k)})) {
942 ierror = check_mvmc(i,j,k,fine);
943 } else {
944 ierror = 0;
945 }
946 return {ierror};
947 });
948 }
949 ReduceTuple rv = reduce_data.value(reduce_op);
950 mvmc_error = amrex::max(0, amrex::get<0>(rv));
951 }
952
953 {
954 bool b = mvmc_error;
956 mvmc_error = b;
957 }
958 if (mvmc_error) {
959 amrex::Abort("GShopLevel::buildFCData: MVMC error");
960 }
961
962 // **********************************************************************
963 // STEP3: Define FC data structures
964 // **********************************************************************
965
966 // FC MultiFabs
967 auto& fc_cellflag = m_fc_data[face_dir]->m_cellflag_fc;
968 MultiFab& fc_volfrac = m_fc_data[face_dir]->m_volfrac_fc;
969 MultiFab& fc_centroid = m_fc_data[face_dir]->m_centroid_fc;
970 MultiFab& fc_bndryarea = m_fc_data[face_dir]->m_bndryarea_fc;
971 MultiFab& fc_bndrycent = m_fc_data[face_dir]->m_bndrycent_fc;
972 MultiFab& fc_bndrynorm = m_fc_data[face_dir]->m_bndrynorm_fc;
973 auto& fc_areafrac = m_fc_data[face_dir]->m_areafrac_fc;
974 auto& fc_facecent = m_fc_data[face_dir]->m_facecent_fc;
975 auto& fc_edgecent = m_fc_data[face_dir]->m_edgecent_fc;
976
977 // Index types of the face-centered data. One rule covers all of it: face_dir is nodal,
978 // because that is how a box spans staggered cells - there is one more of them than there
979 // are cell-centered cells, and nodal is how AMReX says so. The remaining directions carry
980 // whatever type the cell-centered path would give.
981 //
982 // cellflag / volfrac / centroid / bndry* nodal in face_dir alone, i.e. (N,C,C) for
983 // face_dir=0, (C,N,C) for 1, (C,C,N) for 2.
984 // These are the staggered cells themselves.
985 // areafrac[idim] / facecent[idim] the same, for every idim.
986 // edgecent[idim] cell in idim and nodal elsewhere, as in the
987 // cell-centered path, with face_dir forced nodal.
988 //
989 // areafrac and facecent are kept uniform across idim on purpose. The cell-centered path
990 // gives each direction its own nodal index type (areafrac[0] is (N,C,C), areafrac[1] is
991 // (C,N,C), ...); carrying that over to a grid already staggered in face_dir would put three
992 // different index types in play at once for no real gain. Here all three are simply indexed
993 // by the staggered cell they belong to, and areafrac[idim](i,j,k) is that cell's low face in
994 // direction idim, with areafrac[idim](i+1,j,k) its high one.
995 //
996 // Indexing by the staggered cell is why face_dir has to be nodal even here. The valid box
997 // then holds every staggered cell the box owns, which is what coarsen_from_fine below fills
998 // and what the fill*FC ParallelCopy can hand out. A cell-typed face_dir would stop one short
999 // and leave the last staggered cell of every box in the ghost region, where the copy cannot
1000 // reach it: the covered-region mask in fill*FC would clear that plane with nothing able to
1001 // write it back.
1002
1003 // Define FC MultiFabs
1004 BoxArray fc_grids = amrex::convert(fc_base_grids, IntVect::TheDimensionVector(face_dir));
1005 const int ng = 3;
1006 fc_cellflag.define(fc_grids, fc_dmap, 1, ng);
1007 fc_volfrac.define(fc_grids, fc_dmap, 1, ng);
1008 fc_centroid.define(fc_grids, fc_dmap, AMREX_SPACEDIM, ng);
1009 fc_bndryarea.define(fc_grids, fc_dmap, 1, ng);
1010 fc_bndrycent.define(fc_grids, fc_dmap, AMREX_SPACEDIM, ng);
1011 fc_bndrynorm.define(fc_grids, fc_dmap, AMREX_SPACEDIM, ng);
1012
1013 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1014 fc_areafrac[idim].define(fc_grids, fc_dmap, 1, ng);
1015 fc_facecent[idim].define(fc_grids, fc_dmap, AMREX_SPACEDIM-1, ng);
1016 fc_edgecent[idim].define(amrex::convert(fc_base_grids, Level::fcEdgeType(idim,face_dir)),
1017 fc_dmap, 1, ng);
1018 }
1019
1020 // **********************************************************************
1021 // STEP4: Coarsen from refined CC to FC with staggered averaging
1022 // **********************************************************************
1023
1024 // Fine CC MultiFabs
1025 auto const& cc_cellflag = refined_cc_level->m_cellflag;
1026 MultiFab const& cc_volfrac = refined_cc_level->m_volfrac;
1027 MultiFab const& cc_centroid = refined_cc_level->m_centroid;
1028 MultiFab const& cc_bndryarea = refined_cc_level->m_bndryarea;
1029 MultiFab const& cc_bndrycent = refined_cc_level->m_bndrycent;
1030 MultiFab const& cc_bndrynorm = refined_cc_level->m_bndrynorm;
1031 auto const& cc_areafrac = refined_cc_level->m_areafrac;
1032 auto const& cc_facecent = refined_cc_level->m_facecent;
1033 auto const& cc_edgecent = refined_cc_level->m_edgecent;
1034
1035 int error = 0;
1036
1038 {
1039#ifdef AMREX_USE_OMP
1040#pragma omp parallel reduction(max:error)
1041#endif
1042 for (MFIter mfi(fc_volfrac,true); mfi.isValid(); ++mfi)
1043 {
1044 // Coarse FC arrays
1045 auto const& cvol = fc_volfrac.array(mfi);
1046 auto const& ccent = fc_centroid.array(mfi);
1047 auto const& cba = fc_bndryarea.array(mfi);
1048 auto const& cbc = fc_bndrycent.array(mfi);
1049 auto const& cbn = fc_bndrynorm.array(mfi);
1050 AMREX_D_TERM(auto const& capx = fc_areafrac[0].array(mfi);,
1051 auto const& capy = fc_areafrac[1].array(mfi);,
1052 auto const& capz = fc_areafrac[2].array(mfi););
1053 AMREX_D_TERM(auto const& cfcx = fc_facecent[0].array(mfi);,
1054 auto const& cfcy = fc_facecent[1].array(mfi);,
1055 auto const& cfcz = fc_facecent[2].array(mfi););
1056 AMREX_D_TERM(auto const& cecx = fc_edgecent[0].array(mfi);,
1057 auto const& cecy = fc_edgecent[1].array(mfi);,
1058 auto const& cecz = fc_edgecent[2].array(mfi););
1059 auto const& cflag = fc_cellflag.array(mfi);
1060
1061 // Fine CC arrays
1062 auto const& fvol = cc_volfrac.const_array(mfi);
1063 auto const& fcent = cc_centroid.const_array(mfi);
1064 auto const& fba = cc_bndryarea.const_array(mfi);
1065 auto const& fbc = cc_bndrycent.const_array(mfi);
1066 auto const& fbn = cc_bndrynorm.const_array(mfi);
1067 AMREX_D_TERM(auto const& fapx = cc_areafrac[0].const_array(mfi);,
1068 auto const& fapy = cc_areafrac[1].const_array(mfi);,
1069 auto const& fapz = cc_areafrac[2].const_array(mfi););
1070 AMREX_D_TERM(auto const& ffcx = cc_facecent[0].const_array(mfi);,
1071 auto const& ffcy = cc_facecent[1].const_array(mfi);,
1072 auto const& ffcz = cc_facecent[2].const_array(mfi););
1073 AMREX_D_TERM(auto const& fecx = cc_edgecent[0].const_array(mfi);,
1074 auto const& fecy = cc_edgecent[1].const_array(mfi);,
1075 auto const& fecz = cc_edgecent[2].const_array(mfi););
1076 auto const& fflag = cc_cellflag.const_array(mfi);
1077
1078 Box const& bx = mfi.validbox();
1079 Box const& ndgbx = mfi.grownnodaltilebox(-1,2);
1080
1081 int tile_error = 0;
1082 amrex::LoopOnCpu(ndgbx,
1083 [=,&tile_error] (int i, int j, int k) noexcept
1084 {
1086 int ierr = coarsen_from_fine(AMREX_D_DECL(i,j,k), bx, 2,
1087 cvol,ccent,cba,cbc,cbn,
1088 AMREX_D_DECL(capx,capy,capz),
1089 AMREX_D_DECL(cfcx,cfcy,cfcz),
1090 AMREX_D_DECL(cecx,cecy,cecz),
1091 cflag,fvol,fcent,fba,fbc,fbn,
1092 AMREX_D_DECL(fapx,fapy,fapz),
1093 AMREX_D_DECL(ffcx,ffcy,ffcz),
1094 AMREX_D_DECL(fecx,fecy,fecz),
1095 fflag, face_dir);
1096 tile_error = std::max(tile_error,ierr);
1097 });
1098
1099 error = std::max(error,tile_error);
1100 }
1101 }
1102 else
1103 {
1104 ReduceOps<ReduceOpMax> reduce_op;
1105 ReduceData<int> reduce_data(reduce_op);
1106 using ReduceTuple = typename decltype(reduce_data)::Type;
1107
1108 for (MFIter mfi(fc_volfrac); mfi.isValid(); ++mfi)
1109 {
1110 auto const& cvol = fc_volfrac.array(mfi);
1111 auto const& ccent = fc_centroid.array(mfi);
1112 auto const& cba = fc_bndryarea.array(mfi);
1113 auto const& cbc = fc_bndrycent.array(mfi);
1114 auto const& cbn = fc_bndrynorm.array(mfi);
1115 AMREX_D_TERM(auto const& capx = fc_areafrac[0].array(mfi);,
1116 auto const& capy = fc_areafrac[1].array(mfi);,
1117 auto const& capz = fc_areafrac[2].array(mfi););
1118 AMREX_D_TERM(auto const& cfcx = fc_facecent[0].array(mfi);,
1119 auto const& cfcy = fc_facecent[1].array(mfi);,
1120 auto const& cfcz = fc_facecent[2].array(mfi););
1121 // We use MultiArray4 instead of Array4 here
1122 // to be below the 2 kB kernel parameter limit for SYCL
1123 AMREX_D_TERM(auto const& cecx = fc_edgecent[0].arrays();,
1124 auto const& cecy = fc_edgecent[1].arrays();,
1125 auto const& cecz = fc_edgecent[2].arrays(););
1126 auto const& cflag = fc_cellflag.array(mfi);
1127
1128 auto const& fvol = cc_volfrac.const_array(mfi);
1129 auto const& fcent = cc_centroid.const_array(mfi);
1130 auto const& fba = cc_bndryarea.const_array(mfi);
1131 auto const& fbc = cc_bndrycent.const_array(mfi);
1132 auto const& fbn = cc_bndrynorm.const_array(mfi);
1133 AMREX_D_TERM(auto const& fapx = cc_areafrac[0].const_array(mfi);,
1134 auto const& fapy = cc_areafrac[1].const_array(mfi);,
1135 auto const& fapz = cc_areafrac[2].const_array(mfi););
1136 AMREX_D_TERM(auto const& ffcx = cc_facecent[0].const_array(mfi);,
1137 auto const& ffcy = cc_facecent[1].const_array(mfi);,
1138 auto const& ffcz = cc_facecent[2].const_array(mfi););
1139 AMREX_D_TERM(auto const& fecx = cc_edgecent[0].const_arrays();,
1140 auto const& fecy = cc_edgecent[1].const_arrays();,
1141 auto const& fecz = cc_edgecent[2].const_arrays(););
1142 auto const& fflag = cc_cellflag.const_array(mfi);
1143
1144 const int lidx = mfi.LocalIndex();
1145 Box const& bx = mfi.validbox();
1146 Box const& gbx = amrex::grow(bx,2);
1147 Box const& ndgbx = amrex::surroundingNodes(gbx);
1148
1149 reduce_op.eval(ndgbx, reduce_data,
1150 [=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple
1151 {
1153 int ierr = coarsen_from_fine(AMREX_D_DECL(i,j,k), bx, 2,
1154 cvol,ccent,cba,cbc,cbn,
1155 AMREX_D_DECL(capx,capy,capz),
1156 AMREX_D_DECL(cfcx,cfcy,cfcz),
1157 AMREX_D_DECL(cecx[lidx],cecy[lidx],cecz[lidx]),
1158 cflag,fvol,fcent,fba,fbc,fbn,
1159 AMREX_D_DECL(fapx,fapy,fapz),
1160 AMREX_D_DECL(ffcx,ffcy,ffcz),
1161 AMREX_D_DECL(fecx[lidx],fecy[lidx],fecz[lidx]),
1162 fflag, face_dir);
1163 return {ierr};
1164 });
1165 }
1166
1167 ReduceTuple rv = reduce_data.value(reduce_op);
1168 error = amrex::max(0, amrex::get<0>(rv));
1169 }
1170
1171 {
1172 bool b = error;
1174 error = b;
1175 }
1176
1177 if (!error) {
1178 buildCellFlag();
1179 }
1180
1181 // return error;
1182
1183 m_fc_data[face_dir]->m_built = true;
1184 // If transient_level exists, it's automatically destroyed here
1185}
1186
1187}
1188
1189#endif
Fixed-size array types for use on GPU and CPU.
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:551
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
Problem-domain geometry: maps between index space and physical space.
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
amrex::ParmParse pp
Input file parser instance for the given namespace.
Definition AMReX_HypreIJIface.cpp:15
Array4< Real > fine
Definition AMReX_InterpFaceRegister.cpp:90
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
void resize(const Box &b, int N=1, Arena *ar=nullptr)
This function resizes a BaseFab so it covers the Box b with N components.
Definition AMReX_BaseFab.H:1767
Array4< T const > array() const noexcept
Create an Array4 view over all components.
Definition AMReX_BaseFab.H:475
Elixir elixir() noexcept
Transfer owned storage to an Elixir when running in a GPU launch region.
Definition AMReX_BaseFab.H:1810
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:676
bool coarsenable(int refinement_ratio, int min_width=1) const
Check whether every Box is coarsenable by refinement_ratio.
Definition AMReX_BoxArray.cpp:615
bool empty() const noexcept
Return whether the BoxArray is empty.
Definition AMReX_BoxArray.H:759
__host__ __device__ BoxND< new_dim > resize() const noexcept
Return a new BoxND of size new_dim by either shrinking or expanding this BoxND.
Definition AMReX_Box.H:927
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:233
GpuArray< Real, 3 > CellSizeArray() const noexcept
Returns the cell sizes as a GpuArray for use on host or device.
Definition AMReX_CoordSys.H:85
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:51
static constexpr int ng
Definition AMReX_EB2_MultiGFab.H:26
Definition AMReX_EB2_Level.H:288
GShopLevel(IndexSpace const *is, const Geometry &geom)
Construct an empty level (usually regular) bound to geom.
Definition AMReX_EB2_Level.H:340
void define_fine(G const &gshop, const Geometry &geom, int max_grid_size, int ngrow, bool extend_domain_face, int num_crse_opt)
Define data for the finest level using the supplied GeometryShop.
Definition AMReX_EB2_Level.H:475
void buildFCData(G const &gshop, int face_dir, int max_grid_size)
Build face-centered EB data for face_dir. Builds refined CC transiently.
Definition AMReX_EB2_Level.H:835
GShopLevel(IndexSpace const *is, int ilev, int max_grid_size, int ngrow, const Geometry &geom, GShopLevel< G > &fineLevel)
Construct a coarse level by coarsening fineLevel.
Definition AMReX_EB2_Level.H:794
GShopLevel(IndexSpace const *is, G const &gshop, const Geometry &geom, int max_grid_size, int ngrow, bool extend_domain_face, int num_crse_opt)
Build a level directly from a GeometryShop object.
Definition AMReX_EB2_Level.H:345
static GShopLevel< G > makeAllRegular(IndexSpace const *is, const Geometry &geom)
Build a regular (no EB) level.
Definition AMReX_EB2_Level.H:320
void define_fine_mvmc(GS const &gshop, const Geometry &geom, int max_grid_size, int ngrow, bool extend_domain_face, int num_crse_opt)
Define a fine level for multi-valued multi-cut STL geometries (3-D only)
Definition AMReX_EB2_Level.H:759
Definition AMReX_EB2.H:28
Definition AMReX_EB2_Level.H:42
MultiFab m_bndryarea
Definition AMReX_EB2_Level.H:258
bool isOK() const noexcept
Definition AMReX_EB2_Level.H:48
void fillFaceCent(Array< MultiCutFab *, 3 > const &facecent, const Geometry &geom) const
Populate face centroids for each direction.
Definition AMReX_EB2_Level.cpp:794
MultiFab m_volfrac
Definition AMReX_EB2_Level.H:256
MultiGFab m_mgf
Definition AMReX_EB2_Level.H:253
bool m_allregular
Definition AMReX_EB2_Level.H:265
IntVect m_shift
Definition AMReX_EB2_Level.H:268
iMultiFab m_cutcellmask
Definition AMReX_EB2_Level.H:264
Array< MultiFab, 3 > m_facecent
Definition AMReX_EB2_Level.H:262
void fillBndryAreaFC(MultiFab &bndryarea, int face_dir, const Geometry &geom) const
Fill face-centered boundary areas for face_dir.
Definition AMReX_EB2_Level.cpp:1184
Array< MultiFab, 3 > m_edgecent
Definition AMReX_EB2_Level.H:263
void fillBndryNormFC(MultiFab &bndrynorm, int face_dir, const Geometry &geom) const
Fill face-centered boundary normals for face_dir.
Definition AMReX_EB2_Level.cpp:1220
void prepareForCoarsening(const Level &rhs, int max_grid_size, IntVect const &ngrow)
Prepare for coarsening by copying from rhs, respecting max grid size and grow vector.
Definition AMReX_EB2_Level.cpp:10
void fillCutCellMask(iMultiFab &cutcellmask, const Geometry &geom) const
Populate the cut-cell mask into cutcellmask.
Definition AMReX_EB2_Level.cpp:946
MultiFab m_centroid
Definition AMReX_EB2_Level.H:257
FabArray< EBCellFlagFab > m_cellflag
Definition AMReX_EB2_Level.H:255
const DistributionMapping & DistributionMap() const noexcept
Definition AMReX_EB2_Level.H:110
BoxArray m_covered_grids
Definition AMReX_EB2_Level.H:247
void fillLevelSet(MultiFab &levelset, const Geometry &geom) const
Write the implicit function values into levelset.
Definition AMReX_EB2_Level.cpp:907
Geometry m_geom
Definition AMReX_EB2_Level.H:244
Array< MultiFab, 3 > m_areafrac
Definition AMReX_EB2_Level.H:261
IntVect m_ngrow
Definition AMReX_EB2_Level.H:245
void fillEBCellFlagFC(FabArray< EBCellFlagFab > &cellflag, int face_dir, const Geometry &geom) const
Fill face-centered EBCellFlags for face_dir.
Definition AMReX_EB2_Level.cpp:1238
IndexSpace const * m_parent
Definition AMReX_EB2_Level.H:269
const FCData & getFCData(int face_dir) const
Get reference to face-centered data for face_dir (0=x, 1=y, 2=z).
Definition AMReX_EB2_Level.H:197
BoxArray m_grids
Definition AMReX_EB2_Level.H:246
void fillEdgeCentFC(Array< MultiFab *, 3 > const &edgecent, int face_dir, const Geometry &geom) const
Fill face-centered edge centroids for face_dir.
Definition AMReX_EB2_Level.cpp:1322
const Geometry & Geom() const noexcept
Definition AMReX_EB2_Level.H:120
std::map< int, std::unique_ptr< MC::MCFab > > m_marching_cubes
Definition AMReX_EB2_Level.H:251
bool hasEBInfo() const noexcept
Definition AMReX_EB2_Level.H:137
void write_to_chkpt_file(const std::string &fname, bool extend_domain_face, int max_grid_size) const
Write this level’s EB data to a checkpoint file fname.
Definition AMReX_EB2_Level.cpp:956
void fillEBCellFlag(FabArray< EBCellFlagFab > &cellflag, const Geometry &geom) const
Fill cellflag with EBCellFlag data using geometry geom.
Definition AMReX_EB2_Level.cpp:429
void fillEdgeCent(Array< MultiCutFab *, 3 > const &edgecent, const Geometry &geom) const
Populate edge centroids for each direction.
Definition AMReX_EB2_Level.cpp:835
int coarsenFromFine(Level &fineLevel, bool fill_boundary)
Coarsen EB data from fineLevel into this level.
Definition AMReX_EB2_Level.cpp:84
MultiFab m_bndrynorm
Definition AMReX_EB2_Level.H:260
bool m_has_eb_info
Definition AMReX_EB2_Level.H:267
void fillAreaFrac(Array< MultiCutFab *, 3 > const &areafrac, const Geometry &geom) const
Populate face area fractions for each direction.
Definition AMReX_EB2_Level.cpp:640
MultiFab m_bndrycent
Definition AMReX_EB2_Level.H:259
MultiFab m_levelset
Definition AMReX_EB2_Level.H:254
void setShift(int direction, int ncells)
Shift this level by ncells cells along direction direction (for periodic tiling).
Definition AMReX_EB2_Level.cpp:1047
bool isAllRegular() const noexcept
Definition AMReX_EB2_Level.H:46
static IntVect fcEdgeType(int idim, int face_dir) noexcept
Index type of the face-centered edge centroids for edge direction idim.
Definition AMReX_EB2_Level.H:184
void fillBndryCent(MultiCutFab &bndrycent, const Geometry &geom) const
Populate boundary centroids into bndrycent.
Definition AMReX_EB2_Level.cpp:592
void fillCentroidFC(MultiFab &centroid, int face_dir, const Geometry &geom) const
Fill face-centered centroids for face_dir.
Definition AMReX_EB2_Level.cpp:1166
void fillBndryNorm(MultiCutFab &bndrynorm, const Geometry &geom) const
Populate boundary normals into bndrynorm.
Definition AMReX_EB2_Level.cpp:616
void fillBndryCentFC(MultiFab &bndrycent, int face_dir, const Geometry &geom) const
Fill face-centered boundary centroids for face_dir.
Definition AMReX_EB2_Level.cpp:1202
MultiFab m_sdf
Definition AMReX_EB2_Level.H:249
IntVect const & nGrowVect() const noexcept
Definition AMReX_EB2_Level.H:125
void fillAreaFracFC(Array< MultiFab *, 3 > const &areafrac, int face_dir, const Geometry &geom) const
Fill face-centered area fractions for face_dir.
Definition AMReX_EB2_Level.cpp:1101
void fillVolFrac(MultiFab &vfrac, const Geometry &geom) const
Populate volume fractions into vfrac using geom.
Definition AMReX_EB2_Level.cpp:483
const BoxArray & boxArray() const noexcept
Definition AMReX_EB2_Level.H:108
Level(IndexSpace const *is, const Geometry &geom)
Construct a Level bound to EB index space is and Geometry geom.
Definition AMReX_EB2_Level.H:113
friend class GShopLevel
Definition AMReX_EB2_Level.H:275
bool m_ok
Definition AMReX_EB2_Level.H:266
void fillCentroid(MultiCutFab &centroid, const Geometry &geom) const
Populate cut-cell centroids into a MultiCutFab.
Definition AMReX_EB2_Level.cpp:544
Array< std::unique_ptr< FCData >, 3 > m_fc_data
Face-centered data storage: [0]=x-face, [1]=y-face, [2]=z-face.
Definition AMReX_EB2_Level.H:272
DistributionMapping m_dmap
Definition AMReX_EB2_Level.H:248
void fillBndryArea(MultiCutFab &bndryarea, const Geometry &geom) const
Populate boundary-face areas into bndryarea.
Definition AMReX_EB2_Level.cpp:568
void buildCellFlag()
Build EBCellFlag data from the current implicit function field.
Definition AMReX_EB2_Level.cpp:403
void buildCutCellMask(Level const &fine_level)
Build the cut-cell mask by coarsening from fine_level.
Definition AMReX_EB2_Level.cpp:966
bool hasFCData(int face_dir) const noexcept
Check if face-centered data is available for face_dir (0=x, 1=y, 2=z).
Definition AMReX_EB2_Level.H:191
IndexSpace const * getEBIndexSpace() const noexcept
Definition AMReX_EB2_Level.H:122
void fillVolFracFC(MultiFab &vfrac, int face_dir, const Geometry &geom) const
Fill face-centered volume fractions for face_dir.
Definition AMReX_EB2_Level.cpp:1062
void fillFaceCentFC(Array< MultiFab *, 3 > const &facecent, int face_dir, const Geometry &geom) const
Fill face-centered face centroids for face_dir.
Definition AMReX_EB2_Level.cpp:1290
LayoutData wrapper that allocates a GFab per FAB/Box.
Definition AMReX_EB2_MultiGFab.H:86
FAB storing EBCellFlag data per cell.
Definition AMReX_EBCellFlag.H:324
An Array of FortranArrayBox(FAB)-like Objects.
Definition AMReX_FabArray.H:356
Array4< typename FabArray< FAB >::value_type const > array(const MFIter &mfi) const noexcept
Read-only Array4 view for the FAB referenced by iterator mfi.
Definition AMReX_FabArray.H:621
Array4< typename FabArray< FAB >::value_type const > const_array(const MFIter &mfi) const noexcept
Synonym for array(const MFIter&) that highlights read-only semantics.
Definition AMReX_FabArray.H:649
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:85
const Box & Domain() const noexcept
Returns our rectangular domain.
Definition AMReX_Geometry.H:244
Periodicity periodicity() const noexcept
Return the Periodicity based on the length of the domain.
Definition AMReX_Geometry.H:415
GpuArray< Real, 3 > ProbLoArray() const noexcept
Return the lo end of the problem domain in a GpuArray for device code.
Definition AMReX_Geometry.H:217
bool isPeriodic(int dir) const noexcept
Is the domain periodic in the specified direction?
Definition AMReX_Geometry.H:388
Definition AMReX_GpuElixir.H:13
__host__ static __device__ constexpr IntVectND< dim > TheCellVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:810
__host__ static __device__ constexpr IntVectND< dim > TheZeroVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:771
__host__ static __device__ constexpr IntVectND< dim > TheNodeVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:801
__host__ static __device__ constexpr IntVectND< dim > TheDimensionVector(int d) noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:790
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:88
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:172
FabArray façade that only allocates cut-cell Fabs (skipping regular cells).
Definition AMReX_MultiCutFab.H:87
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:40
void define(const BoxArray &bxs, const DistributionMapping &dm, int nvar, int ngrow, const MFInfo &info=MFInfo(), const FabFactory< FArrayBox > &factory=FArrayBoxFactory())
Definition AMReX_MultiFab.cpp:519
Parse Parameters From Command Line and Input Files.
Definition AMReX_ParmParse.H:351
int queryAdd(std::string_view name, T &ref)
If name is found, the value in the ParmParse database will be stored in the ref argument....
Definition AMReX_ParmParse.H:1047
This class provides the user with a few print options.
Definition AMReX_Print.H:35
Definition AMReX_Reduce.H:438
Type value()
Definition AMReX_Reduce.H:473
Definition AMReX_Reduce.H:597
void eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:731
A Collection of IArrayBoxes.
Definition AMReX_iMultiFab.H:34
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a copy of b converted to the nodal flags typ.
Definition AMReX_Box.H:1630
__host__ __device__ BoxND< dim > surroundingNodes(const BoxND< dim > &b, int dir) noexcept
Return a BoxND with NODE based coordinates in direction dir that encloses BoxND b.
Definition AMReX_Box.H:1582
__host__ __device__ BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Return a copy of b coarsened by the isotropic ratio ref_ratio.
Definition AMReX_Box.H:1469
__host__ __device__ BoxND< dim > enclosedCells(const BoxND< dim > &b, int dir) noexcept
Return a BoxND with CELL based coordinates in direction dir that is enclosed by b.
Definition AMReX_Box.H:1664
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Return a copy of b grown uniformly by i cells in every direction.
Definition AMReX_Box.H:1326
__host__ __device__ BoxND< dim > refine(const BoxND< dim > &b, int ref_ratio) noexcept
Return a copy of b refined by the isotropic ratio ref_ratio.
Definition AMReX_Box.H:1510
std::array< T, N > Array
Definition AMReX_Array.H:31
int MyProc() noexcept
Definition AMReX_ParallelDescriptor.H:128
void ReduceBoolOr(bool &)
Definition AMReX_ParallelDescriptor.cpp:1292
int NProcs() noexcept
Definition AMReX_ParallelDescriptor.H:255
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:53
Definition AMReX_FabArrayBase.H:38
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:310
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:88
bool notInLaunchRegion() noexcept
Definition AMReX_GpuControl.H:89
void write_stl(std::string const &filename, std::map< int, std::unique_ptr< MCFab > > const &mc_fabs)
Write the collected marching-cubes output to an STL file.
Definition AMReX_MarchingCubes.cpp:924
void marching_cubes(Geometry const &geom, FArrayBox &sdf_fab, MCFab &mc_fab)
Run marching cubes on signed-distance field sdf_fab.
Definition AMReX_MarchingCubes.cpp:693
void Initialize()
Initialize internal lookup tables and device buffers for marching cubes.
Definition AMReX_MarchingCubes.cpp:651
MPI_Comm CommunicatorSub() noexcept
sub-communicator for current frame
Definition AMReX_ParallelContext.H:70
Definition AMReX_Amr.cpp:50
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:259
RunOn
Definition AMReX_GpuControl.H:65
void AllGatherBoxes(Vector< Box > &bxs, int n_extra_reserve)
Gather boxes from all MPI ranks into bxs.
Definition AMReX_Box.cpp:124
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
__host__ __device__ constexpr IntVectND< dim > scale(const IntVectND< dim > &p, int s) noexcept
Returns a IntVectND obtained by multiplying each of the components of this IntVectND by s.
Definition AMReX_IntVect.H:1102
int Verbose() noexcept
Return the verbosity level configured via ParmParse or SetVerbose().
Definition AMReX.cpp:182
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:242
void LoopOnCpu(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition AMReX_Loop.H:365
A multidimensional array accessor.
Definition AMReX_Array4.H:288
Face-centered EB data storage structure.
Definition AMReX_EB2_Level.H:149
bool m_built
Definition AMReX_EB2_Level.H:173
Array< MultiFab, 3 > m_areafrac_fc
Definition AMReX_EB2_Level.H:156
MultiFab m_bndryarea_fc
Definition AMReX_EB2_Level.H:153
Array< MultiFab, 3 > m_edgecent_fc
Definition AMReX_EB2_Level.H:158
BoxArray m_covered_grids_fc
Definition AMReX_EB2_Level.H:172
MultiFab m_bndrycent_fc
Definition AMReX_EB2_Level.H:154
MultiFab m_centroid_fc
Definition AMReX_EB2_Level.H:152
MultiFab m_bndrynorm_fc
Definition AMReX_EB2_Level.H:155
MultiFab m_volfrac_fc
Definition AMReX_EB2_Level.H:151
Array< MultiFab, 3 > m_facecent_fc
Definition AMReX_EB2_Level.H:157
FabArray< EBCellFlagFab > m_cellflag_fc
Definition AMReX_EB2_Level.H:150
FabArray memory allocation information.
Definition AMReX_FabArray.H:73
MFInfo & SetTag() noexcept
Terminate a variadic SetTag() call.
Definition AMReX_FabArray.H:90
MFInfo & SetAlloc(bool a) noexcept
Control whether FAB storage is allocated when the FabArray is defined.
Definition AMReX_FabArray.H:81
Definition AMReX_MFIter.H:20
MFItInfo & SetDynamic(bool f) noexcept
Definition AMReX_MFIter.H:43