Skip to content

Commit 6370000

Browse files
authored
EB: Move EB without regenerating geometry (#4511)
1 parent df1e7d0 commit 6370000

File tree

6 files changed

+112
-36
lines changed

6 files changed

+112
-36
lines changed

Src/EB/AMReX_EB2.H

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public:
4444

4545
static void pop () noexcept { m_instance.pop_back(); }
4646
static void clear () noexcept { m_instance.clear(); }
47-
static const IndexSpace& top () {
47+
static IndexSpace& top () {
4848
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!m_instance.empty(),
4949
"Have you forgot to call EB2::build? It's required even if the geometry is all regular.");
5050
return *(m_instance.back());
@@ -58,6 +58,10 @@ public:
5858
virtual void addFineLevels (int num_new_fine_levels) = 0;
5959
virtual void addRegularCoarseLevels (int num_new_coarse_levels) = 0;
6060

61+
virtual void setShift (int, int) {
62+
amrex::Abort("IndexSpace::setShift: not supported");
63+
}
64+
6165
protected:
6266
static AMREX_EXPORT Vector<std::unique_ptr<IndexSpace> > m_instance;
6367
};
@@ -91,6 +95,8 @@ public:
9195
void addFineLevels (int num_new_fine_levels) final;
9296
void addRegularCoarseLevels (int num_new_coarse_levels) final;
9397

98+
void setShift (int direction, int ncells) override;
99+
94100
using F = typename G::FunctionType;
95101

96102
private:

Src/EB/AMReX_EB2_IndexSpaceI.H

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,14 @@ IndexSpaceImp<G>::addRegularCoarseLevels (int num_new_coarse_levels)
152152
m_gslevel[ilev].buildCutCellMask(m_gslevel[ilev+1]);
153153
}
154154
}
155+
156+
template <typename G>
157+
void
158+
IndexSpaceImp<G>::setShift (int direction, int ncells)
159+
{
160+
auto nlevs = int(m_gslevel.size());
161+
for (int ilev = nlevs-1; ilev >= 0; --ilev) {
162+
m_gslevel[ilev].setShift(direction, ncells);
163+
ncells *= 2;
164+
}
165+
}

Src/EB/AMReX_EB2_IndexSpace_STL.H

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public:
3636
void addFineLevels (int num_new_fine_levels) final;
3737
void addRegularCoarseLevels (int num_new_coarse_levels) final;
3838

39+
void setShift (int direction, int ncells) override;
40+
3941
private:
4042

4143
Vector<STLLevel> m_stllevel;

Src/EB/AMReX_EB2_IndexSpace_STL.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,14 @@ IndexSpaceSTL::addRegularCoarseLevels (int /*num_new_coarse_levels*/)
9999
amrex::Abort("IndexSpaceSTL::addRegularCoarseLevels: todo");
100100
}
101101

102+
void
103+
IndexSpaceSTL::setShift (int direction, int ncells)
104+
{
105+
auto nlevs = int(m_stllevel.size());
106+
for (int ilev = nlevs-1; ilev >= 0; --ilev) {
107+
m_stllevel[ilev].setShift(direction, ncells);
108+
ncells *= 2;
109+
}
110+
}
111+
102112
}

Src/EB/AMReX_EB2_Level.H

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public:
6969
bool hasEBInfo () const noexcept { return m_has_eb_info; }
7070
void fillCutCellMask (iMultiFab& cutcellmask, const Geometry& geom) const;
7171

72+
void setShift (int direction, int ncells);
73+
7274
// public: // for cuda
7375
int coarsenFromFine (Level& fineLevel, bool fill_boundary);
7476
void buildCellFlag ();
@@ -96,6 +98,7 @@ protected:
9698
bool m_allregular = false;
9799
bool m_ok = false;
98100
bool m_has_eb_info = true;
101+
IntVect m_shift{0};
99102
IndexSpace const* m_parent;
100103

101104
private:

Src/EB/AMReX_EB2_Level.cpp

Lines changed: 79 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ Level::buildCellFlag ()
423423
}
424424

425425
void
426-
Level::fillEBCellFlag (FabArray<EBCellFlagFab>& cellflag, const Geometry& geom) const
426+
Level::fillEBCellFlag (FabArray<EBCellFlagFab>& cellflag, const Geometry& /*geom*/) const
427427
{
428428
if (isAllRegular()) {
429429
cellflag.setVal(EBCellFlag::TheDefaultCell());
@@ -436,10 +436,13 @@ Level::fillEBCellFlag (FabArray<EBCellFlagFab>& cellflag, const Geometry& geom)
436436
}
437437

438438
const int ng = cellflag.nGrow();
439+
cellflag.ParallelCopy(m_cellflag,0,0,1,IntVect(0),IntVect(ng),-m_shift,
440+
m_geom.periodicity());
439441

440-
cellflag.ParallelCopy(m_cellflag,0,0,1,0,ng,geom.periodicity());
441-
442-
const std::vector<IntVect>& pshifts = geom.periodicity().shiftIntVect();
442+
std::vector<IntVect> pshifts = m_geom.periodicity().shiftIntVect();
443+
if (m_shift != 0) {
444+
for (auto& pit : pshifts) { pit += m_shift; }
445+
}
443446

444447
auto cov_val = EBCellFlag::TheCoveredCell();
445448
#ifdef AMREX_USE_OMP
@@ -474,14 +477,18 @@ Level::fillEBCellFlag (FabArray<EBCellFlagFab>& cellflag, const Geometry& geom)
474477
}
475478

476479
void
477-
Level::fillVolFrac (MultiFab& vfrac, const Geometry& geom) const
480+
Level::fillVolFrac (MultiFab& vfrac, const Geometry& /*geom*/) const
478481
{
479482
vfrac.setVal(1.0);
480483
if (isAllRegular()) { return; }
481484

482-
vfrac.ParallelCopy(m_volfrac,0,0,1,0,vfrac.nGrow(),geom.periodicity());
485+
vfrac.ParallelCopy(m_volfrac,0,0,1,IntVect(0),vfrac.nGrowVect(),-m_shift,
486+
m_geom.periodicity());
483487

484-
const std::vector<IntVect>& pshifts = geom.periodicity().shiftIntVect();
488+
std::vector<IntVect> pshifts = m_geom.periodicity().shiftIntVect();
489+
if (m_shift != 0) {
490+
for (auto& pit : pshifts) { pit += m_shift; }
491+
}
485492

486493
#ifdef AMREX_USE_OMP
487494
#pragma omp parallel if (Gpu::notInLaunchRegion())
@@ -545,12 +552,12 @@ Level::fillCentroid (MultiCutFab& centroid, const Geometry& geom) const
545552
}
546553

547554
void
548-
Level::fillCentroid (MultiFab& centroid, const Geometry& geom) const
555+
Level::fillCentroid (MultiFab& centroid, const Geometry& /*geom*/) const
549556
{
550557
centroid.setVal(0.0);
551558
if (!isAllRegular()) {
552-
centroid.ParallelCopy(m_centroid,0,0,AMREX_SPACEDIM,0,centroid.nGrow(),
553-
geom.periodicity());
559+
centroid.ParallelCopy(m_centroid,0,0,AMREX_SPACEDIM,IntVect(0),centroid.nGrowVect(),
560+
-m_shift, m_geom.periodicity());
554561
}
555562
}
556563

@@ -569,11 +576,12 @@ Level::fillBndryArea (MultiCutFab& bndryarea, const Geometry& geom) const
569576
}
570577

571578
void
572-
Level::fillBndryArea ( MultiFab& bndryarea, const Geometry& geom) const
579+
Level::fillBndryArea ( MultiFab& bndryarea, const Geometry& /*geom*/) const
573580
{
574581
bndryarea.setVal(0.0);
575582
if (!isAllRegular()) {
576-
bndryarea.ParallelCopy(m_bndryarea,0,0,1,0,bndryarea.nGrow(),geom.periodicity());
583+
bndryarea.ParallelCopy(m_bndryarea,0,0,1,IntVect(0),bndryarea.nGrowVect(),
584+
-m_shift, m_geom.periodicity());
577585
}
578586
}
579587

@@ -592,12 +600,12 @@ Level::fillBndryCent (MultiCutFab& bndrycent, const Geometry& geom) const
592600
}
593601

594602
void
595-
Level::fillBndryCent (MultiFab& bndrycent, const Geometry& geom) const
603+
Level::fillBndryCent (MultiFab& bndrycent, const Geometry& /*geom*/) const
596604
{
597605
bndrycent.setVal(-1.0);
598606
if (!isAllRegular()) {
599-
bndrycent.ParallelCopy(m_bndrycent,0,0,bndrycent.nComp(),0,bndrycent.nGrow(),
600-
geom.periodicity());
607+
bndrycent.ParallelCopy(m_bndrycent,0,0,bndrycent.nComp(),IntVect(0),
608+
bndrycent.nGrowVect(), -m_shift, m_geom.periodicity());
601609
}
602610
}
603611

@@ -616,17 +624,18 @@ Level::fillBndryNorm (MultiCutFab& bndrynorm, const Geometry& geom) const
616624
}
617625

618626
void
619-
Level::fillBndryNorm ( MultiFab& bndrynorm, const Geometry& geom) const
627+
Level::fillBndryNorm ( MultiFab& bndrynorm, const Geometry& /*geom*/) const
620628
{
621629
bndrynorm.setVal(0.0);
622630
if (!isAllRegular()) {
623-
bndrynorm.ParallelCopy(m_bndrynorm,0,0,bndrynorm.nComp(),0,bndrynorm.nGrow(),
624-
geom.periodicity());
631+
bndrynorm.ParallelCopy(m_bndrynorm,0,0,bndrynorm.nComp(),IntVect(0),
632+
bndrynorm.nGrowVect(), -m_shift, m_geom.periodicity());
625633
}
626634
}
627635

628636
void
629-
Level::fillAreaFrac (Array<MultiCutFab*,AMREX_SPACEDIM> const& a_areafrac, const Geometry& geom) const
637+
Level::fillAreaFrac (Array<MultiCutFab*,AMREX_SPACEDIM> const& a_areafrac,
638+
const Geometry& /*geom*/) const
630639
{
631640
if (isAllRegular()) {
632641
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
@@ -642,11 +651,14 @@ Level::fillAreaFrac (Array<MultiCutFab*,AMREX_SPACEDIM> const& a_areafrac, const
642651
areafrac.nComp(), areafrac.nGrow());
643652
tmp.setVal(1.0);
644653
tmp.ParallelCopy(m_areafrac[idim],0,0,areafrac.nComp(),
645-
0,areafrac.nGrow(),geom.periodicity());
654+
IntVect(0),tmp.nGrowVect(), -m_shift, m_geom.periodicity());
646655
copyMultiFabToMultiCutFab(areafrac, tmp);
647656
}
648657

649-
const std::vector<IntVect>& pshifts = geom.periodicity().shiftIntVect();
658+
std::vector<IntVect> pshifts = m_geom.periodicity().shiftIntVect();
659+
if (m_shift != 0) {
660+
for (auto& pit : pshifts) { pit += m_shift; }
661+
}
650662

651663
#ifdef AMREX_USE_OMP
652664
#pragma omp parallel if (Gpu::notInLaunchRegion())
@@ -703,7 +715,8 @@ Level::fillAreaFrac (Array<MultiCutFab*,AMREX_SPACEDIM> const& a_areafrac, const
703715
}
704716

705717
void
706-
Level::fillAreaFrac (Array<MultiFab*,AMREX_SPACEDIM> const& a_areafrac, const Geometry& geom) const
718+
Level::fillAreaFrac (Array<MultiFab*,AMREX_SPACEDIM> const& a_areafrac,
719+
const Geometry& /*geom*/) const
707720
{
708721
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
709722
a_areafrac[idim]->setVal(1.0);
@@ -715,10 +728,13 @@ Level::fillAreaFrac (Array<MultiFab*,AMREX_SPACEDIM> const& a_areafrac, const Ge
715728
{
716729
auto& areafrac = *a_areafrac[idim];
717730
areafrac.ParallelCopy(m_areafrac[idim],0,0,areafrac.nComp(),
718-
0,areafrac.nGrow(),geom.periodicity());
731+
IntVect(0),areafrac.nGrowVect(),-m_shift,m_geom.periodicity());
719732
}
720733

721-
const std::vector<IntVect>& pshifts = geom.periodicity().shiftIntVect();
734+
std::vector<IntVect> pshifts = m_geom.periodicity().shiftIntVect();
735+
if (m_shift != 0) {
736+
for (auto& pit : pshifts) { pit += m_shift; }
737+
}
722738

723739
#ifdef AMREX_USE_OMP
724740
#pragma omp parallel if (Gpu::notInLaunchRegion())
@@ -772,7 +788,8 @@ Level::fillAreaFrac (Array<MultiFab*,AMREX_SPACEDIM> const& a_areafrac, const Ge
772788
}
773789

774790
void
775-
Level::fillFaceCent (Array<MultiCutFab*,AMREX_SPACEDIM> const& a_facecent, const Geometry& geom) const
791+
Level::fillFaceCent (Array<MultiCutFab*,AMREX_SPACEDIM> const& a_facecent,
792+
const Geometry& /*geom*/) const
776793
{
777794
if (isAllRegular()) {
778795
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
@@ -788,13 +805,14 @@ Level::fillFaceCent (Array<MultiCutFab*,AMREX_SPACEDIM> const& a_facecent, const
788805
facecent.nComp(), facecent.nGrow());
789806
tmp.setVal(0.0);
790807
tmp.ParallelCopy(m_facecent[idim],0,0,facecent.nComp(),
791-
0,facecent.nGrow(),geom.periodicity());
808+
IntVect(0),tmp.nGrowVect(),-m_shift,m_geom.periodicity());
792809
copyMultiFabToMultiCutFab(facecent,tmp);
793810
}
794811
}
795812

796813
void
797-
Level::fillFaceCent (Array<MultiFab*,AMREX_SPACEDIM> const& a_facecent, const Geometry& geom) const
814+
Level::fillFaceCent (Array<MultiFab*,AMREX_SPACEDIM> const& a_facecent,
815+
const Geometry& /*geom*/) const
798816
{
799817
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
800818
a_facecent[idim]->setVal(0.0);
@@ -804,7 +822,8 @@ Level::fillFaceCent (Array<MultiFab*,AMREX_SPACEDIM> const& a_facecent, const Ge
804822
{
805823
auto& facecent = *a_facecent[idim];
806824
a_facecent[idim]->ParallelCopy(m_facecent[idim],0,0,facecent.nComp(),
807-
0,facecent.nGrow(),geom.periodicity());
825+
IntVect(0),facecent.nGrowVect(),
826+
-m_shift, m_geom.periodicity());
808827
}
809828
}
810829
}
@@ -834,7 +853,8 @@ Level::fillEdgeCent (Array<MultiCutFab*,AMREX_SPACEDIM> const& a_edgecent, const
834853
}
835854

836855
void
837-
Level::fillEdgeCent (Array<MultiFab*,AMREX_SPACEDIM> const& a_edgecent, const Geometry& geom) const
856+
Level::fillEdgeCent (Array<MultiFab*,AMREX_SPACEDIM> const& a_edgecent,
857+
const Geometry& /*geom*/) const
838858
{
839859
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
840860
a_edgecent[idim]->setVal(1.0);
@@ -844,14 +864,18 @@ Level::fillEdgeCent (Array<MultiFab*,AMREX_SPACEDIM> const& a_edgecent, const Ge
844864
{
845865
auto& edgecent = *a_edgecent[idim];
846866
a_edgecent[idim]->ParallelCopy(m_edgecent[idim],0,0,edgecent.nComp(),
847-
0,edgecent.nGrow(),geom.periodicity());
867+
IntVect(0),edgecent.nGrowVect(),
868+
-m_shift,m_geom.periodicity());
848869

849870
#ifdef AMREX_USE_OMP
850871
#pragma omp parallel if (Gpu::notInLaunchRegion())
851872
#endif
852873
if (!m_covered_grids.empty())
853874
{
854-
const std::vector<IntVect>& pshifts = geom.periodicity().shiftIntVect();
875+
std::vector<IntVect> pshifts = m_geom.periodicity().shiftIntVect();
876+
if (m_shift != 0) {
877+
for (auto& pit : pshifts) { pit += m_shift; }
878+
}
855879
BoxArray const& covered_edge_grids = amrex::convert(m_covered_grids,
856880
edgecent.ixType());
857881
std::vector<std::pair<int,Box> > isects;
@@ -877,12 +901,16 @@ Level::fillEdgeCent (Array<MultiFab*,AMREX_SPACEDIM> const& a_edgecent, const Ge
877901
}
878902

879903
void
880-
Level::fillLevelSet (MultiFab& levelset, const Geometry& geom) const
904+
Level::fillLevelSet (MultiFab& levelset, const Geometry& /*geom*/) const
881905
{
882906
levelset.setVal(-1.0);
883-
levelset.ParallelCopy(m_levelset,0,0,1,IntVect(0),levelset.nGrowVect(),geom.periodicity());
907+
levelset.ParallelCopy(m_levelset,0,0,1,IntVect(0),levelset.nGrowVect(),
908+
-m_shift, m_geom.periodicity());
884909

885-
const std::vector<IntVect>& pshifts = geom.periodicity().shiftIntVect();
910+
std::vector<IntVect> pshifts = m_geom.periodicity().shiftIntVect();
911+
if (m_shift != 0) {
912+
for (auto& pit : pshifts) { pit += m_shift; }
913+
}
886914

887915
Real cov_val = 1.0; // for covered cells
888916

@@ -916,7 +944,8 @@ Level::fillCutCellMask (iMultiFab& cutcellmask, const Geometry&) const
916944
{
917945
if (!m_has_eb_info) {
918946
cutcellmask.setVal(0);
919-
cutcellmask.ParallelCopy(m_cutcellmask);
947+
cutcellmask.ParallelCopy(m_cutcellmask,0,0,1,IntVect(0),IntVect(0),-m_shift,
948+
m_geom.periodicity());
920949
}
921950
}
922951

@@ -1011,4 +1040,19 @@ Level::buildCutCellMask (Level const& fine_level)
10111040
}
10121041
}
10131042

1043+
void
1044+
Level::setShift (int direction, int ncells)
1045+
{
1046+
if (direction < 0 || direction >= AMREX_SPACEDIM) { return; }
1047+
1048+
if (m_geom.isPeriodic(direction)) {
1049+
auto len = m_geom.Domain().length(direction);
1050+
ncells = ncells % len;
1051+
if (ncells < 0) { ncells += len; }
1052+
if (2*ncells > len) { ncells -= len; }
1053+
}
1054+
1055+
m_shift[direction] = ncells;
1056+
}
1057+
10141058
}

0 commit comments

Comments
 (0)