ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
eb_ Class Reference

#include <ERF_EB.H>

Collaboration diagram for eb_:

Classes

class  EBToPVD
 

Public Member Functions

 ~eb_ ()
 
 eb_ (amrex::Geometry const &a_geom, amrex::FArrayBox const &terrain_fab, amrex::Gpu::DeviceVector< amrex::Real > &a_dz_stretched, bool is_anelastic)
 
 eb_ ()
 
void define (int level, amrex::Geometry const &a_geom, amrex::EB2::Level const *a_eb_level, bool is_anelastic)
 
void make_all_factories (int level, amrex::Geometry const &a_geom, amrex::BoxArray const &ba, amrex::DistributionMapping const &dm, amrex::EB2::Level const &a_eb_level)
 
void make_cc_factory (int level, amrex::Geometry const &a_geom, amrex::BoxArray const &ba, amrex::DistributionMapping const &dm, amrex::EB2::Level const &a_eb_level)
 
int nghost_basic () const
 
int nghost_volume () const
 
int nghost_full () const
 
const std::unique_ptr< amrex::EBFArrayBoxFactory > & get_const_factory () const noexcept
 
void set_connection_flags ()
 
void WriteEBSurface (const amrex::BoxArray &ba, const amrex::DistributionMapping &dmap, const amrex::Geometry &geom, const amrex::EBFArrayBoxFactory *ebf, const int level)
 
eb_aux_ const * get_u_const_factory () const noexcept
 
eb_aux_ const * get_v_const_factory () const noexcept
 
eb_aux_ const * get_w_const_factory () const noexcept
 

Private Member Functions

void make_box (amrex::Geometry const &a_geom)
 
void make_terrain (amrex::Geometry const &a_geom)
 
template<class F >
void build_level (amrex::Geometry const &a_geom, amrex::EB2::GeometryShop< F > a_gshop)
 Construct EB levels from Geometry shop. More...
 
amrex::FabArray< amrex::EBCellFlagFab > & getNonConstEBCellFlags (const amrex::EBFArrayBoxFactory &ebfact)
 

Private Attributes

int m_has_eb
 
std::string m_type
 
amrex::EBSupport m_support_level
 
int m_write_eb_surface
 
amrex::FabArray< amrex::EBCellFlagFab > * m_cellflags = nullptr
 
amrex::EB2::Level const * m_eb_level
 EB level constructed from building GeometryShop. More...
 
std::unique_ptr< amrex::EBFArrayBoxFactory > m_factory = nullptr
 
eb_aux_ m_u_factory
 
eb_aux_ m_v_factory
 
eb_aux_ m_w_factory
 

Constructor & Destructor Documentation

◆ ~eb_()

eb_::~eb_ ( )
22 {
23  // if (m_factory) { m_factory.reset(nullptr); }
24 }

◆ eb_() [1/2]

eb_::eb_ ( amrex::Geometry const &  a_geom,
amrex::FArrayBox const &  terrain_fab,
amrex::Gpu::DeviceVector< amrex::Real > &  a_dz_stretched,
bool  is_anelastic 
)

◆ eb_() [2/2]

eb_::eb_ ( )
27  : m_has_eb(0),
28  m_support_level(EBSupport::full),
30 { }
amrex::EBSupport m_support_level
Definition: ERF_EB.H:67
int m_has_eb
Definition: ERF_EB.H:60
int m_write_eb_surface
Definition: ERF_EB.H:69

Member Function Documentation

◆ build_level()

template<class F >
void eb_::build_level ( amrex::Geometry const &  a_geom,
amrex::EB2::GeometryShop< F >  a_gshop 
)
inlineprivate

Construct EB levels from Geometry shop.

89  {
90  int const req_lev(0);
91  int const max_lev(2);
92 
93  amrex::EB2::Build(a_gshop, a_geom, req_lev, max_lev);
94  const amrex::EB2::IndexSpace& ebis = amrex::EB2::IndexSpace::top();
95  m_eb_level = &(ebis.getLevel(a_geom));
96  }
amrex::EB2::Level const * m_eb_level
EB level constructed from building GeometryShop.
Definition: ERF_EB.H:74

◆ define()

void eb_::define ( int  level,
amrex::Geometry const &  a_geom,
amrex::EB2::Level const *  a_eb_level,
bool  is_anelastic 
)

◆ get_const_factory()

const std::unique_ptr<amrex::EBFArrayBoxFactory>& eb_::get_const_factory ( ) const
inlinenoexcept
46 { return m_factory; }
std::unique_ptr< amrex::EBFArrayBoxFactory > m_factory
Definition: ERF_EB.H:76

Referenced by compute_gradp(), erf_slow_rhs_pre(), ERF::estTimeStep(), and make_buoyancy().

Here is the caller graph for this function:

◆ get_u_const_factory()

eb_aux_ const* eb_::get_u_const_factory ( ) const
inlinenoexcept
56 { return &m_u_factory; }
eb_aux_ m_u_factory
Definition: ERF_EB.H:78

Referenced by AdvectionSrcForMom_EB(), compute_gradp(), DiffusionSrcForMom_EB(), and erf_slow_rhs_pre().

Here is the caller graph for this function:

◆ get_v_const_factory()

eb_aux_ const* eb_::get_v_const_factory ( ) const
inlinenoexcept
57 { return &m_v_factory; }
eb_aux_ m_v_factory
Definition: ERF_EB.H:79

Referenced by AdvectionSrcForMom_EB(), compute_gradp(), DiffusionSrcForMom_EB(), and erf_slow_rhs_pre().

Here is the caller graph for this function:

◆ get_w_const_factory()

eb_aux_ const* eb_::get_w_const_factory ( ) const
inlinenoexcept
58 { return &m_w_factory; }
eb_aux_ m_w_factory
Definition: ERF_EB.H:80

Referenced by AdvectionSrcForMom_EB(), compute_gradp(), DiffusionSrcForMom_EB(), and erf_slow_rhs_pre().

Here is the caller graph for this function:

◆ getNonConstEBCellFlags()

amrex::FabArray<amrex::EBCellFlagFab>& eb_::getNonConstEBCellFlags ( const amrex::EBFArrayBoxFactory &  ebfact)
inlineprivate
101  {
102  const amrex::FabArray<amrex::EBCellFlagFab>& flags_const = ebfact.getMultiEBCellFlagFab();
103  return const_cast<amrex::FabArray<amrex::EBCellFlagFab>&>(flags_const);
104  }

Referenced by set_connection_flags().

Here is the caller graph for this function:

◆ make_all_factories()

void eb_::make_all_factories ( int  level,
amrex::Geometry const &  a_geom,
amrex::BoxArray const &  ba,
amrex::DistributionMapping const &  dm,
amrex::EB2::Level const &  a_eb_level 
)
38 {
39  Print() << "making EB factory\n";
40  m_factory = std::make_unique<EBFArrayBoxFactory>(a_eb_level, a_geom, ba, dm,
42 
43  // Correct cell connectivity
45 
46 #if 1
47  eb_::WriteEBSurface(ba, dm, a_geom, m_factory.get(), level);
48 #endif
49 
50  { int const idim(0);
51  Print() << "making EB staggered u-factory\n";
52  //m_u_factory.set_verbose();
53  m_u_factory.define(level, idim, a_geom, ba, dm,
54  Vector<int>{nghost_basic(), nghost_volume(), nghost_full()},
55  m_factory.get());
56  }
57 
58  { int const idim(1);
59  Print() << "making EB staggered v-factory\n";
60  //m_v_factory.set_verbose();
61  m_v_factory.define(level, idim, a_geom, ba, dm,
62  Vector<int>{nghost_basic(), nghost_volume(), nghost_full()},
63  m_factory.get());
64  }
65 
66  { int const idim(2);
67  Print() << "making EB staggered w-factory\n";
68  //m_w_factory.set_verbose();
69  m_w_factory.define(level, idim, a_geom, ba, dm,
70  Vector<int>{nghost_basic(), nghost_volume(), nghost_full()},
71  m_factory.get());
72  }
73  Print() << "\nDone making EB factory at level = " << level << ".\n\n";
74 }
void WriteEBSurface(const amrex::BoxArray &ba, const amrex::DistributionMapping &dmap, const amrex::Geometry &geom, const amrex::EBFArrayBoxFactory *ebf, const int level)
Definition: ERF_EB.cpp:136
int nghost_volume() const
Definition: ERF_EB.H:43
int nghost_full() const
Definition: ERF_EB.H:44
int nghost_basic() const
Definition: ERF_EB.H:42
void set_connection_flags()
Definition: ERF_EB.cpp:99
void define(int const &a_level, int const &a_idim, amrex::Geometry const &a_geom, amrex::BoxArray const &a_grids, amrex::DistributionMapping const &a_dmap, amrex::Vector< int > const &a_ngrow, amrex::EBFArrayBoxFactory const *a_factory)
Definition: ERF_EBAux.cpp:22
Here is the call graph for this function:

◆ make_box()

void eb_::make_box ( amrex::Geometry const &  a_geom)
private
23 {
24  ParmParse pp_box("eb.box");
25 
26  bool inside = true;
27 
28  Vector<Real> boxLo(AMREX_SPACEDIM), boxHi(AMREX_SPACEDIM);
29 
30  Real const* dx = a_geom.CellSize();
31 
32  if ( !almostEqual(dx[0],dx[1]) || !almostEqual(dx[1],dx[2])) {
33  amrex::Error(" EB Error: Mesh spacing must be uniform!.\n");
34  }
35 
36  Real offset = 0.01*dx[0];
37 
38  for (int i = 0; i < AMREX_SPACEDIM; i++) {
39  boxLo[i] = a_geom.ProbLo(i);
40  boxHi[i] = a_geom.ProbHi(i);
41  }
42 
43  pp_box.queryarr("lo", boxLo, 0, AMREX_SPACEDIM);
44  pp_box.queryarr("hi", boxHi, 0, AMREX_SPACEDIM);
45 
46  pp_box.query("internal_flow", inside);
47  pp_box.query("offset", offset);
48 
49  Real xlo = boxLo[0] + offset;
50  Real xhi = boxHi[0] - offset;
51 
52  // This ensures that the walls won't even touch the ghost cells. By
53  // putting them one domain width away
54  if (a_geom.isPeriodic(0))
55  {
56  xlo = 2.0*a_geom.ProbLo(0) - a_geom.ProbHi(0);
57  xhi = 2.0*a_geom.ProbHi(0) - a_geom.ProbLo(0);
58  }
59 
60 
61  Real ylo = boxLo[1] + offset;
62  Real yhi = boxHi[1] - offset;
63 
64  // This ensures that the walls won't even touch the ghost cells. By
65  // putting them one domain width away
66  if (a_geom.isPeriodic(1))
67  {
68  ylo = 2.0*a_geom.ProbLo(1) - a_geom.ProbHi(1);
69  yhi = 2.0*a_geom.ProbHi(1) - a_geom.ProbLo(1);
70  }
71 
72  Real zlo = boxLo[2] + offset;
73  Real zhi = boxHi[2] - offset;
74 
75  // This ensures that the walls won't even touch the ghost cells. By
76  // putting them one domain width away
77  if (a_geom.isPeriodic(2))
78  {
79  zlo = 2.0*a_geom.ProbLo(2) - a_geom.ProbHi(2);
80  zhi = 2.0*a_geom.ProbHi(2) - a_geom.ProbLo(2);
81  }
82 
83  Array<Real,3> point_lox{ xlo, 0.0, 0.0};
84  Array<Real,3> normal_lox{-1.0, 0.0, 0.0};
85  Array<Real,3> point_hix{ xhi, 0.0, 0.0};
86  Array<Real,3> normal_hix{ 1.0, 0.0, 0.0};
87 
88  Array<Real,3> point_loy{0.0, ylo, 0.0};
89  Array<Real,3> normal_loy{0.0,-1.0, 0.0};
90  Array<Real,3> point_hiy{0.0, yhi, 0.0};
91  Array<Real,3> normal_hiy{0.0, 1.0, 0.0};
92 
93  Array<Real,3> point_loz{0.0, 0.0, zlo};
94  Array<Real,3> normal_loz{0.0, 0.0,-1.0};
95  Array<Real,3> point_hiz{0.0, 0.0, zhi};
96  Array<Real,3> normal_hiz{0.0, 0.0, 1.0};
97 
98  EB2::PlaneIF plane_lox(point_lox,normal_lox);
99  EB2::PlaneIF plane_hix(point_hix,normal_hix);
100 
101  EB2::PlaneIF plane_loy(point_loy,normal_loy);
102  EB2::PlaneIF plane_hiy(point_hiy,normal_hiy);
103 
104  EB2::PlaneIF plane_loz(point_loz,normal_loz);
105  EB2::PlaneIF plane_hiz(point_hiz,normal_hiz);
106 
107  auto box = EB2::makeUnion(plane_lox, plane_hix, plane_loy,
108  plane_hiy, plane_loz, plane_hiz );
109 
110 
111  if( inside ) {
112 
113  auto gshop = EB2::makeShop(box);
114  build_level(a_geom, gshop);
115 
116  } else {
117 
118  auto xob = EB2::makeComplement(box);
119  auto gshop = EB2::makeShop(xob);
120 
121  build_level(a_geom, gshop);
122  }
123 
124 }
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:28
amrex::Real Real
Definition: ERF_ShocInterface.H:19
void build_level(amrex::Geometry const &a_geom, amrex::EB2::GeometryShop< F > a_gshop)
Construct EB levels from Geometry shop.
Definition: ERF_EB.H:87
Here is the call graph for this function:

◆ make_cc_factory()

void eb_::make_cc_factory ( int  level,
amrex::Geometry const &  a_geom,
amrex::BoxArray const &  ba,
amrex::DistributionMapping const &  dm,
amrex::EB2::Level const &  a_eb_level 
)
82 {
83  Print() << "making EB factory\n";
84  m_factory = std::make_unique<EBFArrayBoxFactory>(a_eb_level, a_geom, ba, dm,
86 
87 #if 0
88  eb_::WriteEBSurface(ba, dm, a_geom, m_factory.get(), level);
89 #endif
90 
91  Print() << "\nDone making EB factory at level " << level << ".\n\n";
92 }
Here is the call graph for this function:

◆ make_terrain()

void eb_::make_terrain ( amrex::Geometry const &  a_geom)
private

◆ nghost_basic()

int eb_::nghost_basic ( ) const
inline
42 { return 5; } // nghost_eb_basic ()

Referenced by make_all_factories(), and make_cc_factory().

Here is the caller graph for this function:

◆ nghost_full()

int eb_::nghost_full ( ) const
inline
44 { return 4; } // nghost_eb_full ()

Referenced by make_all_factories(), and make_cc_factory().

Here is the caller graph for this function:

◆ nghost_volume()

int eb_::nghost_volume ( ) const
inline
43 { return 5; } // nghost_eb_volume ()

Referenced by make_all_factories(), and make_cc_factory().

Here is the caller graph for this function:

◆ set_connection_flags()

void eb_::set_connection_flags ( )
100 {
101  // Get non-const reference to EBCellFlagFab FabArray
102  FabArray<EBCellFlagFab>& cellflag = getNonConstEBCellFlags(*m_factory);
103 
104  const MultiFab& volfrac = m_factory->getVolFrac();
105 
106  for (MFIter mfi(cellflag, false); mfi.isValid(); ++mfi) {
107  const Box& bx = mfi.validbox();
108  const Box gbx = amrex::grow(bx, cellflag.nGrow()-1); // Leave one cell layer
109 
110  Array4<EBCellFlag> const& flag = cellflag.array(mfi);
111  Array4<Real const> const& vfrac = volfrac.const_array(mfi);
112 
113  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
114  {
115  for(int kk(-1); kk<=1; kk++) {
116  for(int jj(-1); jj<=1; jj++) {
117  for(int ii(-1); ii<=1; ii++)
118  {
119  if (vfrac(i+ii,j+jj,k+kk) == 0.0) {
120  flag(i,j,k).setDisconnected(ii,jj,kk);
121  }
122  }}}
123  });
124 
125  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
126  {
127  if (vfrac(i,j,k)==0.0) {
128  flag(i,j,k).setCovered();
129  }
130  });
131 
132  }
133 }
amrex::FabArray< amrex::EBCellFlagFab > & getNonConstEBCellFlags(const amrex::EBFArrayBoxFactory &ebfact)
Definition: ERF_EB.H:100

Referenced by make_all_factories().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteEBSurface()

void eb_::WriteEBSurface ( const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dmap,
const amrex::Geometry &  geom,
const amrex::EBFArrayBoxFactory *  ebf,
const int  level 
)
141 {
142  eb_::EBToPVD eb_to_pvd;
143 
144  const Real* dx = geom.CellSize();
145  const Real* problo = geom.ProbLo();
146 
147  MultiFab mf_ba(ba, dmap, 1, 0, MFInfo(), *ebf);
148 
149  for (MFIter mfi(mf_ba); mfi.isValid(); ++mfi) {
150 
151  const auto & sfab = static_cast<EBFArrayBox const &>(mf_ba[mfi]);
152  const auto & my_flag = sfab.getEBCellFlagFab();
153  const auto * my_flag_ptr = &my_flag;
154 
155  const Box & bx = mfi.validbox();
156 
157  if (my_flag.getType(bx) == FabType::covered ||
158  my_flag.getType(bx) == FabType::regular) { continue; }
159 
160  std::array<const CutFab *, AMREX_SPACEDIM> areafrac;
161  const CutFab * bndrycent;
162 
163  for (int d = 0; d < AMREX_SPACEDIM; ++d) {
164  areafrac[d] = &(*ebf->getAreaFrac()[d])[mfi];
165  }
166  bndrycent = &(ebf->getBndryCent()[mfi]);
167 
168 #ifdef AMREX_USE_GPU
169  std::unique_ptr<EBCellFlagFab> host_flag;
170  if (my_flag.arena()->isManaged() || my_flag.arena()->isDevice()) {
171  host_flag = std::make_unique<EBCellFlagFab>(my_flag.box(), my_flag.nComp(),
172  The_Pinned_Arena());
173  Gpu::dtoh_memcpy_async(host_flag->dataPtr(), my_flag.dataPtr(),
174  host_flag->nBytes());
175  Gpu::streamSynchronize();
176  my_flag_ptr = host_flag.get();
177  }
178 
179  std::array<std::unique_ptr<CutFab>, AMREX_SPACEDIM> areafrac_h;
180  for (int d = 0; d < AMREX_SPACEDIM; ++d) {
181  if (areafrac[d]->arena()->isManaged() || areafrac[d]->arena()->isDevice()) {
182  areafrac_h[d] = std::make_unique<CutFab>(areafrac[d]->box(), areafrac[d]->nComp(),
183  The_Pinned_Arena());
184  Gpu::dtoh_memcpy_async(areafrac_h[d]->dataPtr(), areafrac[d]->dataPtr(),
185  areafrac[d]->size()*sizeof(Real));
186  Gpu::streamSynchronize();
187  areafrac[d] = areafrac_h[d].get();
188  }
189  }
190 
191  std::unique_ptr<CutFab> bndrycent_h;
192  if (bndrycent->arena()->isManaged() || bndrycent->arena()->isDevice()) {
193  bndrycent_h = std::make_unique<CutFab>(bndrycent->box(), bndrycent->nComp(),
194  The_Pinned_Arena());
195  Gpu::dtoh_memcpy_async(bndrycent_h->dataPtr(), bndrycent->dataPtr(),
196  bndrycent->size()*sizeof(Real));
197  Gpu::streamSynchronize();
198  bndrycent = bndrycent_h.get();
199  }
200 #endif
201 
202  eb_to_pvd.EBToPolygon(
203  problo, dx,
204  bx, my_flag_ptr->const_array(),
205  bndrycent->const_array(),
206  areafrac[0]->const_array(),
207  areafrac[1]->const_array(),
208  areafrac[2]->const_array());
209  }
210 
211  int cpu = ParallelDescriptor::MyProc();
212  int nProcs = ParallelDescriptor::NProcs();
213 
214  eb_to_pvd.WriteEBVTP(cpu, level);
215 
216  if(ParallelDescriptor::IOProcessor()) {
217  eb_::EBToPVD::WritePVTP(nProcs, level);
218  }
219 
220  for (MFIter mfi(mf_ba); mfi.isValid(); ++mfi) {
221 
222  const auto & sfab = static_cast<EBFArrayBox const &>(mf_ba[mfi]);
223  const auto & my_flag = sfab.getEBCellFlagFab();
224  const auto * my_flag_ptr = &my_flag;
225 
226  const Box & bx = mfi.validbox();
227 
228  if (my_flag.getType(bx) == FabType::covered ||
229  my_flag.getType(bx) == FabType::regular) { continue; }
230 
231 #ifdef AMREX_USE_GPU
232  std::unique_ptr<EBCellFlagFab> host_flag;
233  if (my_flag.arena()->isManaged() || my_flag.arena()->isDevice()) {
234  host_flag = std::make_unique<EBCellFlagFab>(my_flag.box(), my_flag.nComp(),
235  The_Pinned_Arena());
236  Gpu::dtoh_memcpy_async(host_flag->dataPtr(), my_flag.dataPtr(),
237  host_flag->nBytes());
238  Gpu::streamSynchronize();
239  my_flag_ptr = host_flag.get();
240  }
241 #endif
242 
243  eb_to_pvd.EBGridCoverage(cpu, problo, dx, bx, my_flag_ptr->const_array());
244  }
245 }
Definition: ERF_EBToPVD.H:16
void EBGridCoverage(int myID, const Real *problo, const Real *dx, const Box &bx, Array4< EBCellFlag const > const &flag)
Definition: ERF_EBToPVD.cpp:445
static void WritePVTP(const int nProcs, const int level)
Definition: ERF_EBToPVD.cpp:228
void EBToPolygon(const Real *problo, const Real *dx, const Box &bx, Array4< EBCellFlag const > const &flag, Array4< Real const > const &bcent, Array4< Real const > const &apx, Array4< Real const > const &apy, Array4< Real const > const &apz)
Definition: ERF_EBToPVD.cpp:33
void WriteEBVTP(const int myID, const int level) const
Definition: ERF_EBToPVD.cpp:201

Referenced by make_all_factories(), and make_cc_factory().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_cellflags

amrex::FabArray<amrex::EBCellFlagFab>* eb_::m_cellflags = nullptr
private

◆ m_eb_level

amrex::EB2::Level const* eb_::m_eb_level
private

EB level constructed from building GeometryShop.

Referenced by build_level().

◆ m_factory

std::unique_ptr<amrex::EBFArrayBoxFactory> eb_::m_factory = nullptr
private

◆ m_has_eb

int eb_::m_has_eb
private

◆ m_support_level

amrex::EBSupport eb_::m_support_level
private

◆ m_type

std::string eb_::m_type
private

◆ m_u_factory

eb_aux_ eb_::m_u_factory
private

◆ m_v_factory

eb_aux_ eb_::m_v_factory
private

◆ m_w_factory

eb_aux_ eb_::m_w_factory
private

◆ m_write_eb_surface

int eb_::m_write_eb_surface
private

The documentation for this class was generated from the following files: