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

Stores face-centered EB geometry reconstructed from a cell-centered factory. More...

#include <ERF_EBAux.H>

Collaboration diagram for eb_aux_:

Public Member Functions

 eb_aux_ ()
 Construct an undefined auxiliary EB factory. More...
 
 ~eb_aux_ ()=default
 Destroy the auxiliary EB factory; the owned geometry is released by its unique_ptrs. More...
 
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)
 Define face-centered EB geometry for one staggered direction. More...
 
void set_verbose ()
 Enable verbose diagnostic output during factory construction. More...
 
const amrex::FabArray< amrex::EBCellFlagFab > & getMultiEBCellFlagFab () const
 Return the reconstructed EB cell flags. More...
 
const amrex::MultiFab & getVolFrac () const
 Return the reconstructed volume fractions. More...
 
const amrex::MultiFab & getCentroid () const
 Return the reconstructed volume centroids. More...
 
const amrex::MultiFab & getBndryArea () const
 Return the reconstructed EB boundary areas. More...
 
const amrex::MultiFab & getBndryCent () const
 Return the reconstructed EB boundary centroids. More...
 
const amrex::MultiFab & getBndryNormal () const
 Return the reconstructed EB boundary normals. More...
 
amrex::Array< const amrex::MultiFab *, AMREX_SPACEDIM > getAreaFrac () const
 Return reconstructed area fractions for all coordinate directions. More...
 
amrex::Array< const amrex::MultiFab *, AMREX_SPACEDIM > getFaceCent () const
 Return reconstructed face centroids for all coordinate directions. More...
 

Private Attributes

int m_verbose
 
std::unique_ptr< amrex::FabArray< amrex::EBCellFlagFab > > m_cellflags
 
std::unique_ptr< amrex::MultiFab > m_volfrac
 
std::unique_ptr< amrex::MultiFab > m_volcent
 
std::unique_ptr< amrex::MultiFab > m_bndryarea
 
std::unique_ptr< amrex::MultiFab > m_bndrycent
 
std::unique_ptr< amrex::MultiFab > m_bndrynorm
 
amrex::Array< std::unique_ptr< amrex::MultiFab >, AMREX_SPACEDIM > m_areafrac
 
amrex::Array< std::unique_ptr< amrex::MultiFab >, AMREX_SPACEDIM > m_facecent
 

Detailed Description

Stores face-centered EB geometry reconstructed from a cell-centered factory.

This class mirrors the subset of the AMReX EB factory interface needed by ERF staggered momentum fields when native face-centered EB factories are disabled.

Constructor & Destructor Documentation

◆ eb_aux_()

eb_aux_::eb_aux_ ( )

Construct an undefined auxiliary EB factory.

18  : m_verbose(0)
19 // ,m_defined(0)
20 {}
int m_verbose
Definition: ERF_EBAux.H:78

◆ ~eb_aux_()

eb_aux_::~eb_aux_ ( )
default

Destroy the auxiliary EB factory; the owned geometry is released by its unique_ptrs.

Member Function Documentation

◆ define()

void eb_aux_::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 
)

Define face-centered EB geometry for one staggered direction.

May be called more than once on the same object – ERF::RemakeLevel and MakeNewLevelFromCoarse both redefine the factories of an existing level. Each call replaces the previously owned geometry, which is freed on reassignment of the owning unique_ptr.

Parameters
a_levelAMR level index.
a_idimStaggered direction for the target velocity grid.
a_geomCell-centered level geometry.
a_gridsCell-centered grid boxes.
a_dmapDistribution mapping for the grids.
a_ngrowGhost-cell counts for flags, volumes, and centroids.
a_factorySource cell-centered EB factory.
31 {
32  // Box dbox(a_geom.Domain());
33 
34  // small_volfrac
35  Real small_volfrac = Real(1.e-14);
36  ParmParse pp("eb2");
37  pp.queryAdd("small_volfrac", small_volfrac);
38  const Real small_value = Real(1.e-15);
39 
40  const IntVect vdim(IntVect::TheDimensionVector(a_idim));
41 
42  const BoxArray& my_grids = amrex::convert(a_grids, vdim);
43 
44  // NOTE: assigning here frees whatever a previous call to define() allocated
45  m_cellflags = std::make_unique<FabArray<EBCellFlagFab>>(my_grids, a_dmap, 1, a_ngrow[0], MFInfo(),
46  DefaultFabFactory<EBCellFlagFab>());
47 
48  // Set m_cellflags type to singlevalued
49  m_cellflags->setVal(EBCellFlag::TheDefaultCell());
50  for (MFIter mfi(*m_cellflags, false); mfi.isValid(); ++mfi) {
51  auto& fab = (*m_cellflags)[mfi];
52  fab.setType(FabType::singlevalued);
53  }
54 
55  m_volfrac = std::make_unique<MultiFab>(my_grids, a_dmap, 1, a_ngrow[1], MFInfo(), FArrayBoxFactory());
56  m_volcent = std::make_unique<MultiFab>(my_grids, a_dmap, AMREX_SPACEDIM, a_ngrow[2], MFInfo(), FArrayBoxFactory());
57 
58  for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
59  m_areafrac[idim] = std::make_unique<MultiFab>(a_grids, a_dmap, 1, a_ngrow[1]+1, MFInfo(), FArrayBoxFactory());
60  m_facecent[idim] = std::make_unique<MultiFab>(a_grids, a_dmap, AMREX_SPACEDIM-1, a_ngrow[2], MFInfo(), FArrayBoxFactory());
61  }
62 
63  m_bndryarea = std::make_unique<MultiFab>(my_grids, a_dmap, 1, a_ngrow[2], MFInfo(), FArrayBoxFactory());
64  m_bndrycent = std::make_unique<MultiFab>(my_grids, a_dmap, AMREX_SPACEDIM, a_ngrow[2], MFInfo(), FArrayBoxFactory());
65  m_bndrynorm = std::make_unique<MultiFab>(my_grids, a_dmap, AMREX_SPACEDIM, a_ngrow[2], MFInfo(), FArrayBoxFactory());
66 
67  // Initialize with zeros
68  m_volfrac->setVal(0.0);
69  m_volcent->setVal(0.0);
70 
71  for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
72  m_areafrac[idim]->setVal(0.0);
73  m_facecent[idim]->setVal(0.0);
74  }
75 
76  m_bndryarea->setVal(0.0);
77  m_bndrycent->setVal(0.0);
78  m_bndrynorm->setVal(0.0);
79 
80  const auto& FlagFab = a_factory->getMultiEBCellFlagFab(); // EBFArrayBoxFactory, EBDataCollection
81 
82  for (MFIter mfi(*m_cellflags, false); mfi.isValid(); ++mfi) {
83 
84  const Box& bx = mfi.validbox();
85  const Box& bx_grown = mfi.growntilebox();
86  const Box tbx = mfi.nodaltilebox(a_idim);
87  const Box domain = surroundingNodes(a_geom.Domain(), a_idim);
88 
89  GpuArray<Real, AMREX_SPACEDIM> dx = a_geom.CellSizeArray();
90  bool l_periodic = a_geom.isPeriodic(a_idim);
91 
92  Array4<EBCellFlag> const& aux_flag = m_cellflags->array(mfi);
93  Array4<Real> const& aux_vfrac = m_volfrac->array(mfi);
94  Array4<Real> const& aux_afrac_x = m_areafrac[0]->array(mfi);
95  Array4<Real> const& aux_afrac_y = m_areafrac[1]->array(mfi);
96  Array4<Real> const& aux_afrac_z = m_areafrac[2]->array(mfi);
97 
98  if (FlagFab[mfi].getType(bx) == FabType::covered ) {
99 
100  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
101  {
102  aux_flag(i,j,k).setCovered();
103  aux_flag(i,j,k).setDisconnected();
104  if (i==bx.bigEnd(0)) {
105  aux_flag(i+1,j,k).setCovered();
106  }
107  if (j==bx.bigEnd(1)) {
108  aux_flag(i,j+1,k).setCovered();
109  }
110  if (k==bx.bigEnd(2)) {
111  aux_flag(i,j,k+1).setCovered();
112  }
113  });
114 
115  } else if (FlagFab[mfi].getType(bx) == FabType::regular ) {
116 
117  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
118  {
119  aux_flag(i,j,k).setRegular();
120  aux_flag(i,j,k).setDisconnected();
121  aux_vfrac(i,j,k) = one;
122  aux_afrac_x(i,j,k) = one;
123  aux_afrac_y(i,j,k) = one;
124  aux_afrac_z(i,j,k) = one;
125  if (i==bx.bigEnd(0)) {
126  aux_flag(i+1,j,k).setRegular();
127  aux_vfrac(i+1,j,k) = one;
128  aux_afrac_x(i+1,j,k) = one;
129  }
130  if (j==bx.bigEnd(1)) {
131  aux_flag(i,j+1,k).setRegular();
132  aux_vfrac(i,j+1,k) = one;
133  aux_afrac_y(i,j+1,k) = one;
134  }
135  if (k==bx.bigEnd(2)) {
136  aux_flag(i,j,k+1).setRegular();
137  aux_vfrac(i,j,k+1) = one;
138  aux_afrac_z(i,j,k+1) = one;
139  }
140  });
141 
142  } else if (FlagFab[mfi].getType(bx) == FabType::singlevalued ) {
143 
144  // Initialization
145 
146  // CC cell quantities
147  Array4<EBCellFlag const> const& flag = FlagFab.const_array(mfi);
148  Array4<Real const> const& afrac = (a_factory->getAreaFrac()[a_idim])->const_array(mfi);
149  Array4<Real const> const& bnorm = a_factory->getBndryNormal()[mfi].const_array();
150  Array4<Real const> const& bcent = a_factory->getBndryCent()[mfi].const_array();
151 
152  // aux quantities
153  Array4<Real> const& aux_vcent = m_volcent->array(mfi);
154  Array4<Real> const& aux_fcent_x = m_facecent[0]->array(mfi);
155  Array4<Real> const& aux_fcent_y = m_facecent[1]->array(mfi);
156  Array4<Real> const& aux_fcent_z = m_facecent[2]->array(mfi);
157  Array4<Real> const& aux_barea = m_bndryarea->array(mfi);
158  Array4<Real> const& aux_bcent = m_bndrycent->array(mfi);
159  Array4<Real> const& aux_bnorm = m_bndrynorm->array(mfi);
160 
161  // Extended domain in the direction of periodicity
162  Box dom_grown = domain;
163  for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
164  if (a_geom.isPeriodic(idim)) {
165  dom_grown.grow(idim, a_ngrow[0]);
166  }
167  }
168 
169  const IntVect dom_grown_lo = dom_grown.smallEnd();
170  const IntVect dom_grown_hi = dom_grown.bigEnd();
171 
172  BoxList diffList = boxDiff(bx_grown, bx);
173  for (const Box& b : diffList) {
174  ParallelFor(b, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
175  {
176  if ( i < dom_grown_lo[0] || i > dom_grown_hi[0] ||
177  j < dom_grown_lo[1] || j > dom_grown_hi[1] ||
178  k < dom_grown_lo[2] || k > dom_grown_hi[2] ) {
179  aux_flag(i,j,k).setCovered();
180  aux_flag(i,j,k).setDisconnected();
181  }
182  });
183  }
184 
185 #ifndef AMREX_USE_GPU
186  int const verbose=m_verbose;
187 #endif
188 
189  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
190  {
191  // defaults to covered and disconnected.
192  aux_flag(i,j,k).setCovered();
193  aux_flag(i,j,k).setDisconnected();
194 
195  if (i==bx.bigEnd(0)) {
196  aux_flag(i+1,j,k).setCovered();
197  }
198  if (j==bx.bigEnd(1)) {
199  aux_flag(i,j+1,k).setCovered();
200  }
201  if (k==bx.bigEnd(2)) {
202  aux_flag(i,j,k+1).setCovered();
203  }
204 
205  // Index for low and hi cells
206  IntVect iv_hi(i,j,k);
207  IntVect iv_lo(iv_hi - vdim);
208 
209  bool lo_isCovered = flag(iv_lo).isCovered();
210  bool hi_isCovered = flag(iv_hi).isCovered();
211  bool lo_isRegular = flag(iv_lo).isRegular();
212  bool hi_isRegular = flag(iv_hi).isRegular();
213  bool lo_isSingleValued = flag(iv_lo).isSingleValued();
214  bool hi_isSingleValued = flag(iv_hi).isSingleValued();
215 
216  const bool at_lo_boundary = (!l_periodic && iv_hi[a_idim]==domain.smallEnd(a_idim));
217  const bool at_hi_boundary = (!l_periodic && iv_hi[a_idim]==domain.bigEnd(a_idim));
218 
219  // Treatment of lower boundary
220 
221  if (at_lo_boundary) {
222  if (hi_isCovered) {
223  lo_isCovered = true;
224  lo_isRegular = false;
225  lo_isSingleValued = false;
226  } else if (hi_isRegular) {
227  lo_isCovered = false;
228  lo_isRegular = true;
229  lo_isSingleValued = false;
230  } else if (hi_isSingleValued) {
231  if (almostEqual(afrac(i,j,k),zero)) {
232  lo_isCovered = true;
233  lo_isRegular = false;
234  lo_isSingleValued = false;
235  } else if (almostEqual(afrac(i,j,k),one)) {
236  lo_isCovered = false;
237  lo_isRegular = true;
238  lo_isSingleValued = false;
239  } else {
240  lo_isCovered = false;
241  lo_isRegular = false;
242  lo_isSingleValued = true;
243  iv_lo = iv_hi; // At the lower boundary, low cell takes the values of the high cell.
244  }
245  }
246  }
247 
248  // Treatment of upper boundary
249 
250  if (at_hi_boundary) {
251  if (lo_isCovered) { // Covered
252  hi_isCovered = true;
253  hi_isRegular = false;
254  hi_isSingleValued = false;
255  } else if (lo_isRegular) { // Regular
256  hi_isCovered = false;
257  hi_isRegular = true;
258  hi_isSingleValued = false;
259  } else if (lo_isSingleValued) { // SingleValued
260  if (almostEqual(afrac(i,j,k),zero)) { //Covered
261  hi_isCovered = true;
262  hi_isRegular = false;
263  hi_isSingleValued = false;
264  } else if (almostEqual(afrac(i,j,k),one)) { //Regular
265  hi_isCovered = false;
266  hi_isRegular = true;
267  hi_isSingleValued = false;
268  } else { // SingleValued
269  hi_isCovered = false;
270  hi_isRegular = false;
271  hi_isSingleValued = true;
272  iv_hi = iv_lo; // At the upper boundary, hi cell takes the values of the low cell.
273  }
274  }
275  }
276 
277  if ( lo_isCovered && hi_isCovered) {
278 
279  // defaults to covered and disconnected.
280 
281  } else if ( lo_isRegular && hi_isRegular) {
282 
283  aux_flag(i,j,k).setRegular();
284  aux_flag(i,j,k).setConnected();
285 
286  aux_vfrac(i,j,k) = one;
287 
288  aux_afrac_x(i,j,k) = one;
289  aux_afrac_y(i,j,k) = one;
290  aux_afrac_z(i,j,k) = one;
291 
292  if (i==bx.bigEnd(0)) {
293  aux_afrac_x(i+1,j,k) = one;
294  }
295  if (j==bx.bigEnd(1)) {
296  aux_afrac_y(i,j+1,k) = one;
297  }
298  if (k==bx.bigEnd(2)) {
299  aux_afrac_z(i,j,k+1) = one;
300  }
301 
302  } else {
303 
304 #ifndef AMREX_USE_GPU
305  if (verbose) { Print() << "\ncell: " << amrex::IntVect(i,j,k) << "\n"; }
306 #endif
307  Array<Real,AMREX_SPACEDIM> lo_arr = {-myhalf,-myhalf,-myhalf};
308  Array<Real,AMREX_SPACEDIM> hi_arr = { myhalf, myhalf, myhalf};
309 
310  //-----------------------
311  // Low EB cut cell
312  //-----------------------
313 
314  // Map bcent and bnorm to the isoparametric space for anisotropic grids.
315  // (This step is needed because bcent in AMReX is isotropically normalized.)
316 
317  RealVect lo_point (bcent(iv_lo,0), bcent(iv_lo,1), bcent(iv_lo,2));
318  RealVect lo_normal(bnorm(iv_lo,0), bnorm(iv_lo,1), bnorm(iv_lo,2));
319 
320  if (at_lo_boundary) { // At lower boundary
321  lo_point[a_idim] += one; // Move the boundary centroid upward in the a_idim direction.
322  }
323 
324  if (lo_isSingleValued ) {
325  Real bnorm_x = bnorm(iv_lo,0) * dx[0];
326  Real bnorm_y = bnorm(iv_lo,1) * dx[1];
327  Real bnorm_z = bnorm(iv_lo,2) * dx[2];
328 
329  Real norm = std::sqrt( bnorm_x*bnorm_x + bnorm_y*bnorm_y + bnorm_z*bnorm_z);
330 
331  RealVect bnorm_isoparam ( bnorm_x / norm, bnorm_y / norm, bnorm_z / norm);
332 
333  lo_normal = bnorm_isoparam;
334  }
335 
336  // High side of low cell
337  lo_arr[a_idim] = zero;
338  hi_arr[a_idim] = myhalf;
339  RealBox lo_rbx(lo_arr.data(), hi_arr.data());
340 
341  eb_cut_cell_ lo_eb_cc(flag(iv_lo), lo_rbx, lo_point, lo_normal);
342 
343  // cell iv_lo covered (regular) implies lo_eb_cc is covered (regular)
344  // The inverse is not always true.
345  AMREX_ASSERT( !lo_isCovered || lo_eb_cc.isCovered() );
346  AMREX_ASSERT( !lo_isRegular || lo_eb_cc.isRegular() );
347 
348  //-----------------------
349  // High EB cut cell
350  //-----------------------
351 
352  RealVect hi_point (bcent(iv_hi,0), bcent(iv_hi,1), bcent(iv_hi,2));
353  RealVect hi_normal(bnorm(iv_hi,0), bnorm(iv_hi,1), bnorm(iv_hi,2));
354 
355  if (at_hi_boundary) {
356  hi_point[a_idim] += -one; // Move the boundary centroid downward in the a_idim direction.
357  }
358 
359  if (hi_isSingleValued ) {
360  Real bnorm_x = bnorm(iv_hi,0) * dx[0];
361  Real bnorm_y = bnorm(iv_hi,1) * dx[1];
362  Real bnorm_z = bnorm(iv_hi,2) * dx[2];
363 
364  Real norm = std::sqrt( bnorm_x*bnorm_x + bnorm_y*bnorm_y + bnorm_z*bnorm_z);
365 
366  RealVect bnorm_isoparam ( bnorm_x / norm, bnorm_y / norm, bnorm_z / norm);
367 
368  hi_normal = bnorm_isoparam;
369  }
370 
371  // Low side of high cell
372  lo_arr[a_idim] = -myhalf;
373  hi_arr[a_idim] = zero;
374  RealBox hi_rbx(lo_arr.data(), hi_arr.data());
375 
376  eb_cut_cell_ hi_eb_cc(flag(iv_hi), hi_rbx, hi_point, hi_normal);
377 
378  // cell iv_hi covered (regular) implies hi_eb_cc is covered (regular)
379  // The inverse is not always true.
380  AMREX_ASSERT( !hi_isCovered || hi_eb_cc.isCovered() );
381  AMREX_ASSERT( !hi_isRegular || hi_eb_cc.isRegular() );
382 
383 #if 0
384 #if defined(AMREX_DEBUG) || defined(AMREX_TESTING) || 1
385 
386  { /***************************** SANITY CHECK ***********************\
387  * Perform some basic sanity checks to verify that what we computed *
388  * for cell (i,j,k) compares to what we know to be true. *
389  \******************************************************************/
390 
391  // Compute the cut-cell for the high side of the high cell. This is
392  // only needed for sanity checks.
393 
394  eb_cut_cell_ hi_hi_eb_cc(flag(iv_hi), lo_rbx, hi_point, hi_normal);
395 
396  // cell iv_hi covered (regular) implies hi_hi_eb_cc is covered (regular)
397  // The inverse is not always true.
398 #ifndef AMREX_USE_GPU
399  if ( !(!hi_isRegular || hi_hi_eb_cc.isRegular()) ||
400  !(!hi_isCovered || hi_hi_eb_cc.isCovered()) ) {
401  Print() << "flag(iv_hi) and hi_hi_eb_cc flags do not agree\n"
402  << "\n isRegular() " << hi_isRegular << " " << hi_hi_eb_cc.isRegular()
403  << "\n isCovered() " << hi_isCovered << " " << hi_hi_eb_cc.isCovered()
404  << "\n";
405  }
406 #endif
407  // If cell iv_hi is regular or covered, then hi_hi_eb_cc must also
408  // be regular or covered. The inverse is not true.
409  AMREX_ALWAYS_ASSERT( !hi_isRegular || hi_hi_eb_cc.isRegular() );
410  AMREX_ALWAYS_ASSERT( !hi_isCovered || hi_hi_eb_cc.isCovered() );
411 
412  // The area and volume fractions that are computed for the scalar grid
413  // are slightly different than those we compute from the geometric
414  // reconstruction using the EB point and normal. However, we expect
415  // that the area fractions computed here will give back the same
416  // normal we used to compute them.
417  if ( hi_isSingleValued ) {
418 
419  Real const adx = (a_idim == 0)
420  ? (hi_eb_cc.areaLo(0) - hi_hi_eb_cc.areaHi(0)) * dx[1] * dx[2]
421  : (hi_eb_cc.areaLo(0) + hi_hi_eb_cc.areaLo(0)) * dx[1] * dx[2]
422  - (hi_eb_cc.areaHi(0) + hi_hi_eb_cc.areaHi(0)) * dx[1] * dx[2];
423 
424  Real const ady = (a_idim == 1)
425  ? (hi_eb_cc.areaLo(1) - hi_hi_eb_cc.areaHi(1)) * dx[0] * dx[2]
426  : (hi_eb_cc.areaLo(1) + hi_hi_eb_cc.areaLo(1)) * dx[0] * dx[2]
427  - (hi_eb_cc.areaHi(1) + hi_hi_eb_cc.areaHi(1)) * dx[0] * dx[2];
428 
429  Real const adz = (a_idim == 2)
430  ? (hi_eb_cc.areaLo(2) - hi_hi_eb_cc.areaHi(2)) * dx[0] * dx[1]
431  : (hi_eb_cc.areaLo(2) + hi_hi_eb_cc.areaLo(2)) * dx[0] * dx[1]
432  - (hi_eb_cc.areaHi(2) + hi_hi_eb_cc.areaHi(2)) * dx[0] * dx[1];
433 
434  Real const apnorm = std::sqrt(adx*adx + ady*ady + adz*adz);
435 
436  // EB normal
437  Real const apnorminv = one / apnorm;
438  RealVect const normal(adx*apnorminv, ady*apnorminv, adz*apnorminv);
439  Real const dot_normals = normal.dotProduct(hi_normal);
440 
441 #ifndef AMREX_USE_GPU
442  if ( !amrex::almostEqual(dot_normals, one) ) {
443  Print() << "\nFail: check-1 dot_normals " << dot_normals
444  << '\n';
445 
446  hi_eb_cc.debug();
447  hi_hi_eb_cc.debug();
448 
449  } else if (verbose) {
450  Print() << "Pass: dot_normals = one\n";
451 
452  }
453 #endif
454  AMREX_ALWAYS_ASSERT( amrex::almostEqual(dot_normals, one) );
455  }
456 
457  // The a_idim area of hi_eb_cc.areaHi() should equal hi_hi_eb_cc.areaLo()
458  {
459 #ifndef AMREX_USE_GPU
460  Real const abs_err = std::abs( hi_eb_cc.areaHi(a_idim) - hi_hi_eb_cc.areaLo(a_idim) );
462  if ( abs_err >= machine_tol ) {
463  Print() << "\nFail: check-2 area abs_err: " << abs_err
464  << "\n hi_eb_cc.areaHi " << hi_eb_cc.areaHi(a_idim)
465  << "\n hi_hi_eb_cc.areaLo " << hi_hi_eb_cc.areaLo(a_idim)
466  << '\n';
467  } else if (verbose) {
468  Print() << "Pass: hi_eb_cc.areaHi = hi_hi_eb_cc.areaLo"
469  << " abs_err: " << abs_err << "\n";
470  }
471  AMREX_ALWAYS_ASSERT( abs_err < machine_tol );
472 #endif
473  }
474 
475  // The low-side area of hi_eb_cc should equal a_idim afrac.
476  { Real const abs_err = amrex::max(std::abs(lo_eb_cc.areaHi(a_idim) - afrac(iv_hi)),
477  std::abs(hi_eb_cc.areaLo(a_idim) - afrac(iv_hi)));
478  Real compare_tol = Real(5.0e-6);
479 #ifndef AMREX_USE_GPU
480  if ( abs_err >= compare_tol ) {
481  //hi_eb_cc.debug();
482  Print() << "\nFail: check-3 area abs_err " << abs_err
483  << "\n hi_eb_cc.areaLo(" << a_idim << ") = " << hi_eb_cc.areaLo(a_idim)
484  << "\n lo_eb_cc.areaHi(" << a_idim << ") = " << lo_eb_cc.areaHi(a_idim)
485  << "\n afrac" << iv_hi << " = " << afrac(iv_hi)
486  << '\n';
487  } else if (verbose) {
488  Print() << "Pass: hi_eb_cc.areaLo = afrac = " << afrac(iv_hi)
489  << " abs_err: " << abs_err << "\n";
490  }
491 #endif
492  AMREX_ALWAYS_ASSERT( abs_err < compare_tol );
493  }
494 
495  // The combined volumes of hi_eb_cc.areaHi() and hi_hi_eb_cc should
496  // equal vfrac(iv_hi).
497  { Real const vol = hi_eb_cc.volume() + hi_hi_eb_cc.volume();
498  Real const abs_err = amrex::Math::abs(vfrac(iv_hi) - vol);
499  Real compare_tol = Real(5.0e-6);
500 #ifndef AMREX_USE_GPU
501  if ( abs_err >= compare_tol ) {
502  hi_eb_cc.debug();
503  hi_hi_eb_cc.debug();
504  amrex::Print() << "\nFail: check-4 volume abs_err: " << abs_err
505  << "\n point: " << hi_point
506  << "\n normal: " << hi_normal
507  << "\n hi_eb_cc.volume() " << hi_eb_cc.volume()
508  << "\n hi_hi_eb_cc.volume() " << hi_hi_eb_cc.volume()
509  << "\n vfrac: " << vfrac(iv_hi)
510  << '\n';
511  } else if (verbose) {
512  Print() << "Pass: hi_eb_cc + hi_hi_eb_cc = vfrac = " << vfrac(iv_hi)
513  << " abs_err: " << abs_err << "\n";
514  }
515 #endif
516  AMREX_ALWAYS_ASSERT( abs_err < compare_tol );
517  }
518  } //
519 #endif
520 #endif // 0
521 
522  //-----------------------
523  // Fill out aux_ arrays
524  //-----------------------
525 
526  if (lo_eb_cc.isCovered() && hi_eb_cc.isCovered()) {
527 
528  // defaults to covered and disconnected.
529 
530  } else if (lo_eb_cc.isRegular() && hi_eb_cc.isRegular()) {
531 
532  aux_flag(i,j,k).setRegular();
533  aux_flag(i,j,k).setConnected();
534 
535  aux_vfrac(i,j,k) = one;
536 
537  aux_afrac_x(i,j,k) = one;
538  aux_afrac_y(i,j,k) = one;
539  aux_afrac_z(i,j,k) = one;
540 
541  aux_fcent_x(i,j,k,0) = zero; aux_fcent_x(i,j,k,1) = zero;
542  aux_fcent_y(i,j,k,0) = zero; aux_fcent_y(i,j,k,1) = zero;
543  aux_fcent_z(i,j,k,0) = zero; aux_fcent_z(i,j,k,1) = zero;
544 
545  if (i==bx.bigEnd(0)) {
546  aux_afrac_x(i+1,j,k) = one;
547  aux_fcent_x(i+1,j,k,0) = zero; aux_fcent_x(i+1,j,k,1) = zero;
548  }
549  if (j==bx.bigEnd(1)) {
550  aux_afrac_y(i,j+1,k) = one;
551  aux_fcent_y(i,j+1,k,0) = zero; aux_fcent_y(i,j+1,k,1) = zero;
552  }
553  if (k==bx.bigEnd(2)) {
554  aux_afrac_z(i,j,k+1) = one;
555  aux_fcent_z(i,j,k+1,0) = zero; aux_fcent_z(i,j,k+1,1) = zero;
556  }
557 
558  } else if ( (lo_eb_cc.isRegular() && hi_eb_cc.isCovered())
559  || (lo_eb_cc.isCovered() && hi_eb_cc.isRegular()) ) {
560 
561  // This is a problematic situation.
562 #ifndef AMREX_USE_GPU
563  Print()<< "eb_aux_ / Check: Regular and Covered cut cells are facing each other." << std::endl;
564 #endif
565 
566  } else {
567 
568  // zero Cell Flag
569 
570  aux_flag(i,j,k).setSingleValued();
571 
572  // 1. Volume Fraction
573 
574  Real lo_vol {lo_eb_cc.volume()}; AMREX_ASSERT(lo_vol >= zero && lo_vol <= myhalf);
575  Real hi_vol {hi_eb_cc.volume()}; AMREX_ASSERT(hi_vol >= zero && hi_vol <= myhalf);
576 
577  aux_vfrac(i,j,k) = lo_vol + hi_vol;
578 
579  // 2. Volume Centroid
580 
581  /* centVol() returns the coordinates based on m_rbx.
582  The coordinates in the a_idim direction are in [zero,myhalf] for the low cell and in [-myhalf,zero] for the hi cell.
583  Therefore, they need to be mapped to the eb_aux space, by shifting:
584  x' = x - myhalf (low cell), x + myhalf (hi cell) if a_idim = 0
585  y' = y - myhalf (low cell), y + myhalf (hi cell) if a_idim = 1
586  z' = z - myhalf (low cell), z + myhalf (hi cell) if a_idim = 2
587  */
588 
589  RealVect lo_vcent {lo_eb_cc.centVol()};
590  RealVect hi_vcent {hi_eb_cc.centVol()};
591 
592  lo_vcent[a_idim] = lo_vcent[a_idim] - myhalf;
593  hi_vcent[a_idim] = hi_vcent[a_idim] + myhalf;
594 
595  aux_vcent(i,j,k,0) = ( lo_vol * lo_vcent[0] + hi_vol * hi_vcent[0] ) / aux_vfrac(i,j,k);
596  aux_vcent(i,j,k,1) = ( lo_vol * lo_vcent[1] + hi_vol * hi_vcent[1] ) / aux_vfrac(i,j,k);
597  aux_vcent(i,j,k,2) = ( lo_vol * lo_vcent[2] + hi_vol * hi_vcent[2] ) / aux_vfrac(i,j,k);
598 
599  // 3. Area Fraction
600 
601  Real lo_areaLo_x {lo_eb_cc.areaLo(0)};
602  Real lo_areaLo_y {lo_eb_cc.areaLo(1)};
603  Real lo_areaLo_z {lo_eb_cc.areaLo(2)};
604 
605  Real hi_areaLo_x {hi_eb_cc.areaLo(0)};
606  Real hi_areaLo_y {hi_eb_cc.areaLo(1)};
607  Real hi_areaLo_z {hi_eb_cc.areaLo(2)};
608 
609  aux_afrac_x(i,j,k) = (a_idim == 0) ? lo_areaLo_x : lo_areaLo_x + hi_areaLo_x;
610  aux_afrac_y(i,j,k) = (a_idim == 1) ? lo_areaLo_y : lo_areaLo_y + hi_areaLo_y;
611  aux_afrac_z(i,j,k) = (a_idim == 2) ? lo_areaLo_z : lo_areaLo_z + hi_areaLo_z;
612 
613  if (i==bx.bigEnd(0)) {
614  Real lo_areaHi_x {lo_eb_cc.areaHi(0)};
615  Real hi_areaHi_x {hi_eb_cc.areaHi(0)};
616  aux_afrac_x(i+1,j,k) = (a_idim == 0) ? hi_areaHi_x : lo_areaHi_x + hi_areaHi_x;
617  }
618  if (j==bx.bigEnd(1)) {
619  Real lo_areaHi_y {lo_eb_cc.areaHi(1)};
620  Real hi_areaHi_y {hi_eb_cc.areaHi(1)};
621  aux_afrac_y(i,j+1,k) = (a_idim == 1) ? hi_areaHi_y : lo_areaHi_y + hi_areaHi_y;
622  }
623  if (k==bx.bigEnd(2)) {
624  Real lo_areaHi_z {lo_eb_cc.areaHi(2)};
625  Real hi_areaHi_z {hi_eb_cc.areaHi(2)};
626  aux_afrac_z(i,j,k+1) = (a_idim == 2) ? hi_areaHi_z : lo_areaHi_z + hi_areaHi_z;
627  }
628 
629  // 4. Face Centroid
630 
631  /* fcentLo returns the coordinates based on m_rbx.
632  The coordinates in the a_idim direction are in [zero,myhalf] for the low cell and in [-myhalf,zero] for the hi cell.
633  Therefore, they need to be mapped to the eb_aux space, by shifting:
634  x' = x - myhalf (low cell), x + myhalf (hi cell) if a_idim = 0
635  y' = y - myhalf (low cell), y + myhalf (hi cell) if a_idim = 1
636  z' = z - myhalf (low cell), z + myhalf (hi cell) if a_idim = 2
637  */
638 
639  RealVect lo_centLo_x {lo_eb_cc.centLo(0)};
640  RealVect lo_centLo_y {lo_eb_cc.centLo(1)};
641  RealVect lo_centLo_z {lo_eb_cc.centLo(2)};
642 
643  RealVect hi_centLo_x {hi_eb_cc.centLo(0)};
644  RealVect hi_centLo_y {hi_eb_cc.centLo(1)};
645  RealVect hi_centLo_z {hi_eb_cc.centLo(2)};
646 
647  if (a_idim == 0) {
648  aux_fcent_x(i,j,k,0) = lo_centLo_x[1]; // y
649  aux_fcent_x(i,j,k,1) = lo_centLo_x[2]; // z
650  aux_fcent_y(i,j,k,0) = (aux_afrac_y(i,j,k) > zero) // x (mapped)
651  ? ( lo_areaLo_y * (lo_centLo_y[0] - myhalf)
652  + hi_areaLo_y * (hi_centLo_y[0] + myhalf) ) / aux_afrac_y(i,j,k)
653  : zero;
654  aux_fcent_y(i,j,k,1) = (aux_afrac_y(i,j,k) > zero) // z
655  ? ( lo_areaLo_y * lo_centLo_y[2]
656  + hi_areaLo_y * hi_centLo_y[2] ) / aux_afrac_y(i,j,k)
657  : zero;
658  aux_fcent_z(i,j,k,0) = (aux_afrac_z(i,j,k) > zero) // x (mapped)
659  ? ( lo_areaLo_z * (lo_centLo_z[0] - myhalf)
660  + hi_areaLo_z * (hi_centLo_z[0] + myhalf) ) / aux_afrac_z(i,j,k)
661  : zero;
662  aux_fcent_z(i,j,k,1) = (aux_afrac_z(i,j,k) > zero) // y
663  ? ( lo_areaLo_z * lo_centLo_z[1]
664  + hi_areaLo_z * hi_centLo_z[1] ) / aux_afrac_z(i,j,k)
665  : zero;
666  } else if (a_idim == 1) {
667  aux_fcent_x(i,j,k,0) = (aux_afrac_x(i,j,k) > zero) // y (mapped)
668  ? ( lo_areaLo_x * (lo_centLo_x[1] - myhalf)
669  + hi_areaLo_x * (hi_centLo_x[1] + myhalf) ) / aux_afrac_x(i,j,k)
670  : zero;
671  aux_fcent_x(i,j,k,1) = (aux_afrac_x(i,j,k) > zero) // z
672  ? ( lo_areaLo_x * lo_centLo_x[2]
673  + hi_areaLo_x * hi_centLo_x[2] ) / aux_afrac_x(i,j,k)
674  : zero;
675  aux_fcent_y(i,j,k,0) = lo_centLo_y[0]; // x
676  aux_fcent_y(i,j,k,1) = lo_centLo_y[2]; // z
677  aux_fcent_z(i,j,k,0) = (aux_afrac_z(i,j,k) > zero) // x
678  ? ( lo_areaLo_z * lo_centLo_z[0]
679  + hi_areaLo_z * hi_centLo_z[0] ) / aux_afrac_z(i,j,k)
680  : zero;
681  aux_fcent_z(i,j,k,1) = (aux_afrac_z(i,j,k) > zero) // y (mapped)
682  ? ( lo_areaLo_z * (lo_centLo_z[1] - myhalf)
683  + hi_areaLo_z * (hi_centLo_z[1] + myhalf) ) / aux_afrac_z(i,j,k)
684  : zero;
685  } else if (a_idim == 2) {
686  aux_fcent_x(i,j,k,0) = (aux_afrac_x(i,j,k) > zero) // y
687  ? ( lo_areaLo_x * lo_centLo_x[1]
688  + hi_areaLo_x * hi_centLo_x[1] ) / aux_afrac_x(i,j,k)
689  : zero;
690  aux_fcent_x(i,j,k,1) = (aux_afrac_x(i,j,k) > zero) // z (mapped)
691  ? ( lo_areaLo_x * (lo_centLo_x[2] - myhalf)
692  + hi_areaLo_x * (hi_centLo_x[2] + myhalf) ) / aux_afrac_x(i,j,k)
693  : zero;
694  aux_fcent_y(i,j,k,0) = (aux_afrac_y(i,j,k) > zero) // x
695  ? ( lo_areaLo_y * lo_centLo_y[0]
696  + hi_areaLo_y * hi_centLo_y[0] ) / aux_afrac_y(i,j,k)
697  : zero;
698  aux_fcent_y(i,j,k,1) = (aux_afrac_y(i,j,k) > zero) // z (mapped)
699  ? ( lo_areaLo_y * (lo_centLo_y[2] - myhalf)
700  + hi_areaLo_y * (hi_centLo_y[2] + myhalf) ) / aux_afrac_y(i,j,k)
701  : zero;
702  aux_fcent_z(i,j,k,0) = lo_centLo_z[0]; // x
703  aux_fcent_z(i,j,k,1) = lo_centLo_z[1]; // y
704  }
705 
706  if (i==bx.bigEnd(0)) {
707  Real lo_areaHi_x {lo_eb_cc.areaHi(0)};
708  Real hi_areaHi_x {hi_eb_cc.areaHi(0)};
709  RealVect lo_centHi_x {lo_eb_cc.centHi(0)};
710  RealVect hi_centHi_x {hi_eb_cc.centHi(0)};
711  if (a_idim == 0) {
712  aux_fcent_x(i+1,j,k,0) = hi_centHi_x[1]; // y
713  aux_fcent_x(i+1,j,k,1) = hi_centHi_x[2]; // z
714  } else if (a_idim == 1) {
715  aux_fcent_x(i+1,j,k,0) = (aux_afrac_x(i+1,j,k) > zero) // y (mapped)
716  ? ( lo_areaHi_x * (lo_centHi_x[1] - myhalf)
717  + hi_areaHi_x * (hi_centHi_x[1] + myhalf) ) / aux_afrac_x(i+1,j,k)
718  : zero;
719  aux_fcent_x(i+1,j,k,1) = (aux_afrac_x(i+1,j,k) > zero) // z
720  ? ( lo_areaHi_x * lo_centHi_x[2]
721  + hi_areaHi_x * hi_centHi_x[2] ) / aux_afrac_x(i+1,j,k)
722  : zero;
723  } else if (a_idim == 2) {
724  aux_fcent_x(i+1,j,k,0) = (aux_afrac_x(i+1,j,k) > zero) // y
725  ? ( lo_areaHi_x * lo_centHi_x[1]
726  + hi_areaHi_x * hi_centHi_x[1] ) / aux_afrac_x(i+1,j,k)
727  : zero;
728  aux_fcent_x(i+1,j,k,1) = (aux_afrac_x(i+1,j,k) > zero) // z (mapped)
729  ? ( lo_areaHi_x * (lo_centHi_x[2] - myhalf)
730  + hi_areaHi_x * (hi_centHi_x[2] + myhalf) ) / aux_afrac_x(i+1,j,k)
731  : zero;
732  }
733  }
734  if (j==bx.bigEnd(1)) {
735  Real lo_areaHi_y {lo_eb_cc.areaHi(1)};
736  Real hi_areaHi_y {hi_eb_cc.areaHi(1)};
737  RealVect lo_centHi_y {lo_eb_cc.centHi(1)};
738  RealVect hi_centHi_y {hi_eb_cc.centHi(1)};
739  if (a_idim == 0) {
740  aux_fcent_y(i,j+1,k,0) = (aux_afrac_y(i,j+1,k) > zero) // x (mapped)
741  ? ( lo_areaHi_y * (lo_centHi_y[0] - myhalf)
742  + hi_areaHi_y * (hi_centHi_y[0] + myhalf) ) / aux_afrac_y(i,j+1,k)
743  : zero;
744  aux_fcent_y(i,j+1,k,1) = (aux_afrac_y(i,j+1,k) > zero) // z
745  ? ( lo_areaHi_y * lo_centHi_y[2]
746  + hi_areaHi_y * hi_centHi_y[2] ) / aux_afrac_y(i,j+1,k)
747  : zero;
748  } else if (a_idim == 1) {
749  aux_fcent_y(i,j+1,k,0) = lo_centHi_y[0]; // x
750  aux_fcent_y(i,j+1,k,1) = lo_centHi_y[2]; // z
751  } else if (a_idim == 2) {
752  aux_fcent_y(i,j+1,k,0) = (aux_afrac_y(i,j+1,k) > zero) // x
753  ? ( lo_areaHi_y * lo_centHi_y[0]
754  + hi_areaHi_y * hi_centHi_y[0] ) / aux_afrac_y(i,j+1,k)
755  : zero;
756  aux_fcent_y(i,j+1,k,1) = (aux_afrac_y(i,j+1,k) > zero) // z (mapped)
757  ? ( lo_areaHi_y * (lo_centHi_y[2] - myhalf)
758  + hi_areaHi_y * (hi_centHi_y[2] + myhalf) ) / aux_afrac_y(i,j+1,k)
759  : zero;
760  }
761  }
762  if (k==bx.bigEnd(2)) {
763  Real lo_areaHi_z {lo_eb_cc.areaHi(2)};
764  Real hi_areaHi_z {hi_eb_cc.areaHi(2)};
765  RealVect lo_centHi_z {lo_eb_cc.centHi(2)};
766  RealVect hi_centHi_z {hi_eb_cc.centHi(2)};
767  if (a_idim == 0) {
768  aux_fcent_z(i,j,k+1,0) = (aux_afrac_z(i,j,k+1) > zero) // x (mapped)
769  ? ( lo_areaHi_z * (lo_centHi_z[0] - myhalf)
770  + hi_areaHi_z * (hi_centHi_z[0] + myhalf) ) / aux_afrac_z(i,j,k+1)
771  : zero;
772  aux_fcent_z(i,j,k+1,1) = (aux_afrac_z(i,j,k+1) > zero) // y
773  ? ( lo_areaHi_z * lo_centHi_z[1]
774  + hi_areaHi_z * hi_centHi_z[1] ) / aux_afrac_z(i,j,k+1)
775  : zero;
776  } else if (a_idim == 1) {
777  aux_fcent_z(i,j,k+1,0) = (aux_afrac_z(i,j,k+1) > zero) // x
778  ? ( lo_areaHi_z * lo_centHi_z[0]
779  + hi_areaHi_z * hi_centHi_z[0] ) / aux_afrac_z(i,j,k+1)
780  : zero;
781  aux_fcent_z(i,j,k+1,1) = (aux_afrac_z(i,j,k+1) > zero) // y (mapped)
782  ? ( lo_areaHi_z * (lo_centHi_z[1] - myhalf)
783  + hi_areaHi_z * (hi_centHi_z[1] + myhalf) ) / aux_afrac_z(i,j,k+1)
784  : zero;
785  } else if (a_idim == 2) {
786  aux_fcent_z(i,j,k+1,0) = lo_centHi_z[0]; // x
787  aux_fcent_z(i,j,k+1,1) = lo_centHi_z[1]; // y
788  }
789  }
790 
791  // 5. Boundary Area
792 
793  Real lo_areaBoun {lo_eb_cc.areaBoun()};
794  Real hi_areaBoun {hi_eb_cc.areaBoun()};
795 
796  aux_barea(i,j,k) = lo_areaBoun + hi_areaBoun;
797 
798  // 6. Boundary Centroid
799 
800  RealVect lo_centBoun {lo_eb_cc.centBoun()};
801  RealVect hi_centBoun {hi_eb_cc.centBoun()};
802 
803  if (a_idim == 0) {
804  aux_bcent(i,j,k,0) = ( lo_areaBoun * (lo_centBoun[0]-myhalf) + hi_areaBoun * (hi_centBoun[0]+myhalf) ) / aux_barea(i,j,k); // x (mapped)
805  aux_bcent(i,j,k,1) = ( lo_areaBoun * lo_centBoun[1] + hi_areaBoun * hi_centBoun[1] ) / aux_barea(i,j,k); // y
806  aux_bcent(i,j,k,2) = ( lo_areaBoun * lo_centBoun[2] + hi_areaBoun * hi_centBoun[2] ) / aux_barea(i,j,k); // z
807  } else if (a_idim == 1) {
808  aux_bcent(i,j,k,0) = ( lo_areaBoun * lo_centBoun[0] + hi_areaBoun * hi_centBoun[0] ) / aux_barea(i,j,k); // x
809  aux_bcent(i,j,k,1) = ( lo_areaBoun * (lo_centBoun[1]-myhalf) + hi_areaBoun * (hi_centBoun[1]+myhalf) ) / aux_barea(i,j,k); // y (mapped)
810  aux_bcent(i,j,k,2) = ( lo_areaBoun * lo_centBoun[2] + hi_areaBoun * hi_centBoun[2] ) / aux_barea(i,j,k); // z
811  } else if (a_idim == 2) {
812  aux_bcent(i,j,k,0) = ( lo_areaBoun * lo_centBoun[0] + hi_areaBoun * hi_centBoun[0] ) / aux_barea(i,j,k); // x
813  aux_bcent(i,j,k,1) = ( lo_areaBoun * lo_centBoun[1] + hi_areaBoun * hi_centBoun[1] ) / aux_barea(i,j,k); // y
814  aux_bcent(i,j,k,2) = ( lo_areaBoun * (lo_centBoun[2]-myhalf) + hi_areaBoun * (hi_centBoun[2]+myhalf) ) / aux_barea(i,j,k); // z (mapped)
815  }
816 
817  // 7. Boundary Normal
818 
819  RealVect eb_normal = ( lo_areaBoun * lo_normal + hi_areaBoun * hi_normal )/ aux_barea(i,j,k);
820 
821  aux_bnorm(i,j,k,0) = eb_normal[0];
822  aux_bnorm(i,j,k,1) = eb_normal[1];
823  aux_bnorm(i,j,k,2) = eb_normal[2];
824 
825  }
826 
827  } // flag(iv_lo) and flag(iv_hi)
828 
829  });
830 
831  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
832  {
833  if (aux_vfrac(i,j,k) < small_volfrac)
834  {
835  aux_vfrac(i,j,k) = zero;
836  }
837  });
838 
839  } // if (FlagFab[mfi].getType(bx) == FabType::singlevalued )
840 
841  } // MFIter
842 
843  // We FillBoundary volfrac here so that we can use tests on volfrac in ghost cells below
844  m_volfrac->FillBoundary(a_geom.periodicity());
845 
846  for (MFIter mfi(*m_cellflags, false); mfi.isValid(); ++mfi) {
847 
848  const Box& bx = mfi.validbox();
849  const Box& bx_grown = mfi.growntilebox();
850 
851  Array4<EBCellFlag> const& aux_flag = m_cellflags->array(mfi);
852  Array4<Real> const& aux_vfrac = m_volfrac->array(mfi);
853  Array4<Real> const& aux_afrac_x = m_areafrac[0]->array(mfi);
854  Array4<Real> const& aux_afrac_y = m_areafrac[1]->array(mfi);
855  Array4<Real> const& aux_afrac_z = m_areafrac[2]->array(mfi);
856  Array4<Real> const& aux_afrac_idim = m_areafrac[a_idim]->array(mfi);
857 
858  Array4<Real> const& aux_vcent = m_volcent->array(mfi);
859  Array4<Real> const& aux_fcent_x = m_facecent[0]->array(mfi);
860  Array4<Real> const& aux_fcent_y = m_facecent[1]->array(mfi);
861  Array4<Real> const& aux_fcent_z = m_facecent[2]->array(mfi);
862  Array4<Real> const& aux_barea = m_bndryarea->array(mfi);
863  Array4<Real> const& aux_bcent = m_bndrycent->array(mfi);
864  Array4<Real> const& aux_bnorm = m_bndrynorm->array(mfi);
865 
866  if (FlagFab[mfi].getType(bx) == FabType::singlevalued ) {
867 
868  // Corrections for small cells
869  Box my_xbx(bx); my_xbx.growHi(0,1);
870  int xbx_lo = my_xbx.smallEnd(0);
871  int xbx_hi = my_xbx.bigEnd(0);
872  ParallelFor(my_xbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
873  {
874  if ((i == xbx_lo && aux_vfrac(i,j,k) < small_volfrac) ||
875  (i == xbx_hi && aux_vfrac(i-1,j,k) < small_volfrac) ||
876  (i > xbx_lo && i < xbx_hi &&
877  (aux_vfrac(i,j,k) < small_volfrac || aux_vfrac(i-1,j,k) < small_volfrac))) {
878  aux_afrac_x(i,j,k) = zero;
879  }
880  });
881 
882  Box my_ybx(bx); my_ybx.growHi(1,1);
883  int ybx_lo = my_ybx.smallEnd(1);
884  int ybx_hi = my_ybx.bigEnd(1);
885  ParallelFor(my_ybx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
886  {
887  if ((j == ybx_lo && aux_vfrac(i,j,k) < small_volfrac) ||
888  (j == ybx_hi && aux_vfrac(i,j-1,k) < small_volfrac) ||
889  (j > ybx_lo && j < ybx_hi &&
890  (aux_vfrac(i,j,k) < small_volfrac || aux_vfrac(i,j-1,k) < small_volfrac))) {
891  aux_afrac_y(i,j,k) = zero;
892  }
893  });
894 
895  Box my_zbx(bx); my_zbx.growHi(2,1);
896  int zbx_lo = my_zbx.smallEnd(2);
897  int zbx_hi = my_zbx.bigEnd(2);
898  ParallelFor(my_zbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
899  {
900  if ((k == zbx_lo && aux_vfrac(i,j,k) < small_volfrac) ||
901  (k == zbx_hi && aux_vfrac(i,j,k-1) < small_volfrac) ||
902  (k > zbx_lo && k < zbx_hi &&
903  (aux_vfrac(i,j,k) < small_volfrac || aux_vfrac(i,j,k-1) < small_volfrac))) {
904  aux_afrac_z(i,j,k) = zero;
905  }
906  });
907 
908  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
909  {
910  if (aux_vfrac(i,j,k) < small_volfrac)
911  {
912  aux_vcent(i,j,k,0) = zero;
913  aux_vcent(i,j,k,1) = zero;
914  aux_vcent(i,j,k,2) = zero;
915 
916  aux_fcent_x(i ,j ,k ,0) = zero;
917  aux_fcent_x(i ,j ,k ,1) = zero;
918  aux_fcent_x(i+1,j ,k ,0) = zero;
919  aux_fcent_x(i+1,j ,k ,1) = zero;
920 
921  aux_fcent_y(i ,j ,k ,0) = zero;
922  aux_fcent_y(i ,j ,k ,1) = zero;
923  aux_fcent_y(i ,j+1,k ,0) = zero;
924  aux_fcent_y(i ,j+1,k ,1) = zero;
925 
926  aux_fcent_z(i ,j ,k ,0) = zero;
927  aux_fcent_z(i ,j ,k ,1) = zero;
928  aux_fcent_z(i ,j ,k+1,0) = zero;
929  aux_fcent_z(i ,j ,k+1,1) = zero;
930 
931  aux_barea(i,j,k) = zero;
932 
933  aux_bcent(i,j,k,0) = zero;
934  aux_bcent(i,j,k,1) = zero;
935  aux_bcent(i,j,k,2) = zero;
936 
937  aux_bnorm(i,j,k,0) = zero;
938  aux_bnorm(i,j,k,1) = zero;
939  aux_bnorm(i,j,k,2) = zero;
940 
941  aux_flag(i,j,k).setCovered();
942  }
943 
944  if (std::abs(aux_vcent(i,j,k,0)) < small_value) aux_vcent(i,j,k,0) = zero;
945  if (std::abs(aux_vcent(i,j,k,1)) < small_value) aux_vcent(i,j,k,1) = zero;
946  if (std::abs(aux_vcent(i,j,k,2)) < small_value) aux_vcent(i,j,k,2) = zero;
947  if (std::abs(aux_bcent(i,j,k,0)) < small_value) aux_bcent(i,j,k,0) = zero;
948  if (std::abs(aux_bcent(i,j,k,1)) < small_value) aux_bcent(i,j,k,1) = zero;
949  if (std::abs(aux_bcent(i,j,k,2)) < small_value) aux_bcent(i,j,k,2) = zero;
950  });
951 
952  // Area fraction MultiFab has one more slice at bigEnd(idim),
953  // and this slice is not filled by fillBoundary(), for higher levels.
954  // (Lower level might be filled by fillBoundary().)
955  // Fill the ghost region for the last slice at bigEnd(idim)
956  // by the value of the nearest point. And let fillBoundary() overwrite it.
957 
958  Box upper_slab = makeSlab(bx_grown, a_idim, bx.bigEnd(a_idim)+1);
959  Box bx_grown_1 = bx; bx_grown_1.grow(a_idim,1);
960  BoxList slab_diffList = boxDiff(upper_slab, bx_grown_1);
961 
962  for (const Box& b : slab_diffList) {
963  ParallelFor(b, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
964  {
965  IntVect iv(AMREX_D_DECL(i,j,k));
966  IntVect iv_nearest = iv;
967  for (int d=0; d<AMREX_SPACEDIM; ++d) {
968  iv_nearest[d] = Clamp(iv[d], bx_grown_1.smallEnd(d), bx_grown_1.bigEnd(d));
969  }
970  aux_afrac_idim(iv) = aux_afrac_idim(iv_nearest);
971  });
972  }
973 
974  } // if (FlagFab[mfi].getType(bx) == FabType::singlevalued )
975 
976  } // MFIter
977 
978  // Fill Boundary
979 
980  // The FB call for volfrac is done above
981  // m_volfrac->FillBoundary(a_geom.periodicity());
982 
983  m_volcent->FillBoundary(a_geom.periodicity());
984  for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
985  m_areafrac[idim]->FillBoundary(a_geom.periodicity());
986  m_facecent[idim]->FillBoundary(a_geom.periodicity());
987  }
988  m_bndryarea->FillBoundary(a_geom.periodicity());
989  m_bndrycent->FillBoundary(a_geom.periodicity());
990  m_bndrynorm->FillBoundary(a_geom.periodicity());
991 
992  // Set Connectivities
993  for (MFIter mfi(*m_cellflags, false); mfi.isValid(); ++mfi) {
994 
995  const Box& bx = mfi.validbox();
996  const Box domain = surroundingNodes(a_geom.Domain(), a_idim);
997 
998  if (FlagFab[mfi].getType(bx) == FabType::singlevalued ) {
999 
1000  Array4<EBCellFlag> const& aux_flag = m_cellflags->array(mfi);
1001  Array4<Real> const& aux_afrac_x = m_areafrac[0]->array(mfi);
1002  Array4<Real> const& aux_afrac_y = m_areafrac[1]->array(mfi);
1003  Array4<Real> const& aux_afrac_z = m_areafrac[2]->array(mfi);
1004 
1005  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1006  {
1007  EB2::build_cellflag_from_ap (i, j, k, aux_flag, aux_afrac_x, aux_afrac_y, aux_afrac_z);
1008  });
1009 
1010  // Set disconnected non-periodicfaces
1011 
1012  bool l_periodic_x = a_geom.isPeriodic(0);
1013  bool l_periodic_y = a_geom.isPeriodic(1);
1014  bool l_periodic_z = a_geom.isPeriodic(2);
1015 
1016  if (!l_periodic_x) {
1017  const Box dom_grown = grow(grow(domain,1,1),2,1);
1018  const Box bx_grown = grow(grow( bx,1,1),2,1);
1019  const Box bx_face_x_lo = bx_grown & makeSlab(dom_grown,0,domain.smallEnd(0));
1020  const Box bx_face_x_hi = bx_grown & makeSlab(dom_grown,0,domain.bigEnd(0));
1021 
1022  ParallelFor(bx_face_x_lo, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1023  {
1024  for(int kk(-1); kk<=1; kk++) {
1025  for(int jj(-1); jj<=1; jj++) {
1026  aux_flag(i,j,k).setDisconnected(-1,jj,kk);
1027  }}
1028  });
1029  ParallelFor(bx_face_x_hi, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1030  {
1031  for(int kk(-1); kk<=1; kk++) {
1032  for(int jj(-1); jj<=1; jj++) {
1033  aux_flag(i,j,k).setDisconnected( 1,jj,kk);
1034  }}
1035  });
1036  }
1037 
1038  if (!l_periodic_y) {
1039  const Box dom_grown = grow(grow(domain,0,1),2,1);
1040  const Box bx_grown = grow(grow( bx,0,1),2,1);
1041  const Box bx_face_y_lo = bx_grown & makeSlab(dom_grown,1,domain.smallEnd(1));
1042  const Box bx_face_y_hi = bx_grown & makeSlab(dom_grown,1,domain.bigEnd(1));
1043 
1044  ParallelFor(bx_face_y_lo, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1045  {
1046  for(int kk(-1); kk<=1; kk++) {
1047  for(int ii(-1); ii<=1; ii++) {
1048  aux_flag(i,j,k).setDisconnected(ii,-1,kk);
1049  }}
1050  });
1051  ParallelFor(bx_face_y_hi, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1052  {
1053  for(int kk(-1); kk<=1; kk++) {
1054  for(int ii(-1); ii<=1; ii++) {
1055  aux_flag(i,j,k).setDisconnected(ii, 1,kk);
1056  }}
1057  });
1058  }
1059 
1060  if (!l_periodic_z) {
1061  const Box dom_grown = grow(grow(domain,0,1),1,1);
1062  const Box bx_grown = grow(grow( bx,0,1),1,1);
1063  const Box bx_face_z_lo = bx_grown & makeSlab(dom_grown,2,domain.smallEnd(2));
1064  const Box bx_face_z_hi = bx_grown & makeSlab(dom_grown,2,domain.bigEnd(2));
1065 
1066  ParallelFor(bx_face_z_lo, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1067  {
1068  for(int jj(-1); jj<=1; jj++) {
1069  for(int ii(-1); ii<=1; ii++) {
1070  aux_flag(i,j,k).setDisconnected(ii,jj,-1);
1071  }}
1072  });
1073  ParallelFor(bx_face_z_hi, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1074  {
1075  for(int jj(-1); jj<=1; jj++) {
1076  for(int ii(-1); ii<=1; ii++) {
1077  aux_flag(i,j,k).setDisconnected(ii,jj, 1);
1078  }}
1079  });
1080  }
1081 
1082  } // FabType::singlevalued
1083 
1084  } // MFIter
1085 
1086  // Set disconnected zero-volume-fraction cells
1087  // (equivalent to eb_::set_connection_flags for CC grids)
1088 
1089  for (MFIter mfi(*m_cellflags, false); mfi.isValid(); ++mfi) {
1090 
1091  const Box& bx = mfi.validbox();
1092  const Box gbx = amrex::grow(bx, m_cellflags->nGrow()-1); // Leave one cell layer
1093 
1094  Array4<EBCellFlag> const& aux_flag = m_cellflags->array(mfi);
1095  Array4<Real> const& aux_vfrac = m_volfrac->array(mfi);
1096 
1097  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1098  {
1099  for(int kk(-1); kk<=1; kk++) {
1100  for(int jj(-1); jj<=1; jj++) {
1101  for(int ii(-1); ii<=1; ii++)
1102  {
1103  if (aux_vfrac(i+ii,j+jj,k+kk) == zero) {
1104  aux_flag(i,j,k).setDisconnected(ii,jj,kk);
1105  }
1106  }}}
1107  });
1108 
1109  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
1110  {
1111  if (aux_vfrac(i,j,k)==zero) {
1112  aux_flag(i,j,k).setCovered();
1113  }
1114  });
1115 
1116  } // MFIter
1117 
1118  // Fill Boundary
1119 
1120  m_cellflags->FillBoundary(a_geom.periodicity());
1121 
1122 #if 0
1123  // We leave these here for debugging if necessary.
1124  // If you uncomment these, make sure to uncomment AMReX_VisMF include above
1125  if (a_idim == 0) {
1126  amrex::VisMF::Write(*m_volfrac,"UVOL");
1127  amrex::VisMF::Write(*m_areafrac[0],"UAREAX");
1128  amrex::VisMF::Write(*m_areafrac[1],"UAREAY");
1129  amrex::VisMF::Write(*m_areafrac[2],"UAREAZ");
1130  } else if (a_idim == 1) {
1131  amrex::VisMF::Write(*m_volfrac,"VVOL");
1132  amrex::VisMF::Write(*m_areafrac[0],"VAREAX");
1133  amrex::VisMF::Write(*m_areafrac[1],"VAREAY");
1134  amrex::VisMF::Write(*m_areafrac[2],"VAREAZ");
1135  } else {
1136  amrex::VisMF::Write(*m_volfrac,"WVOL");
1137  amrex::VisMF::Write(*m_areafrac[0],"WAREAX");
1138  amrex::VisMF::Write(*m_areafrac[1],"WAREAY");
1139  amrex::VisMF::Write(*m_areafrac[2],"WAREAZ");
1140  }
1141 #endif
1142 }
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
ParmParse pp("prob")
const Real dx
Definition: ERF_InitCustomPert_ABL.H:44
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
amrex::Array< std::unique_ptr< amrex::MultiFab >, AMREX_SPACEDIM > m_areafrac
Definition: ERF_EBAux.H:92
std::unique_ptr< amrex::MultiFab > m_bndrynorm
Definition: ERF_EBAux.H:90
std::unique_ptr< amrex::MultiFab > m_bndrycent
Definition: ERF_EBAux.H:89
std::unique_ptr< amrex::FabArray< amrex::EBCellFlagFab > > m_cellflags
Definition: ERF_EBAux.H:85
std::unique_ptr< amrex::MultiFab > m_bndryarea
Definition: ERF_EBAux.H:88
amrex::Array< std::unique_ptr< amrex::MultiFab >, AMREX_SPACEDIM > m_facecent
Definition: ERF_EBAux.H:93
std::unique_ptr< amrex::MultiFab > m_volcent
Definition: ERF_EBAux.H:87
std::unique_ptr< amrex::MultiFab > m_volfrac
Definition: ERF_EBAux.H:86
Reconstructs geometric moments for one EB cut cell.
Definition: ERF_EBCutCell.H:68
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12

Referenced by eb_::make_all_factories().

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

◆ getAreaFrac()

Array< const MultiFab *, AMREX_SPACEDIM > eb_aux_::getAreaFrac ( ) const

Return reconstructed area fractions for all coordinate directions.

1188 {
1189  AMREX_ASSERT(m_areafrac[0] != nullptr);
1190  return {AMREX_D_DECL(m_areafrac[0].get(), m_areafrac[1].get(), m_areafrac[2].get())};
1191 }
pp get("wavelength", wavelength)
Here is the call graph for this function:

◆ getBndryArea()

const MultiFab & eb_aux_::getBndryArea ( ) const

Return the reconstructed EB boundary areas.

1167 {
1168  AMREX_ASSERT(m_bndryarea != nullptr);
1169  return *m_bndryarea;
1170 }

◆ getBndryCent()

const MultiFab & eb_aux_::getBndryCent ( ) const

Return the reconstructed EB boundary centroids.

1174 {
1175  AMREX_ASSERT(m_bndrycent != nullptr);
1176  return *m_bndrycent;
1177 }

◆ getBndryNormal()

const MultiFab & eb_aux_::getBndryNormal ( ) const

Return the reconstructed EB boundary normals.

1181 {
1182  AMREX_ASSERT(m_bndrynorm != nullptr);
1183  return *m_bndrynorm;
1184 }

◆ getCentroid()

const MultiFab & eb_aux_::getCentroid ( ) const

Return the reconstructed volume centroids.

1160 {
1161  AMREX_ASSERT(m_volcent != nullptr);
1162  return *m_volcent;
1163 }

◆ getFaceCent()

Array< const MultiFab *, AMREX_SPACEDIM > eb_aux_::getFaceCent ( ) const

Return reconstructed face centroids for all coordinate directions.

1195 {
1196  AMREX_ASSERT(m_facecent[0] != nullptr);
1197  return {AMREX_D_DECL(m_facecent[0].get(), m_facecent[1].get(), m_facecent[2].get())};
1198 }
Here is the call graph for this function:

◆ getMultiEBCellFlagFab()

const FabArray< EBCellFlagFab > & eb_aux_::getMultiEBCellFlagFab ( ) const

Return the reconstructed EB cell flags.

1146 {
1147  AMREX_ASSERT(m_cellflags != nullptr);
1148  return *m_cellflags;
1149 }

Referenced by AdvectionSrcForMom_EB(), compute_gradp_xy(), compute_gradp_z(), and DiffusionSrcForMom_EB().

Here is the caller graph for this function:

◆ getVolFrac()

const MultiFab & eb_aux_::getVolFrac ( ) const

Return the reconstructed volume fractions.

1153 {
1154  AMREX_ASSERT(m_volfrac != nullptr);
1155  return *m_volfrac;
1156 }

◆ set_verbose()

void eb_aux_::set_verbose ( )
inline

Enable verbose diagnostic output during factory construction.

56 { m_verbose = 1; }

Member Data Documentation

◆ m_areafrac

amrex::Array<std::unique_ptr<amrex::MultiFab>,AMREX_SPACEDIM> eb_aux_::m_areafrac
private

Referenced by define(), and getAreaFrac().

◆ m_bndryarea

std::unique_ptr<amrex::MultiFab> eb_aux_::m_bndryarea
private

Referenced by define(), and getBndryArea().

◆ m_bndrycent

std::unique_ptr<amrex::MultiFab> eb_aux_::m_bndrycent
private

Referenced by define(), and getBndryCent().

◆ m_bndrynorm

std::unique_ptr<amrex::MultiFab> eb_aux_::m_bndrynorm
private

Referenced by define(), and getBndryNormal().

◆ m_cellflags

std::unique_ptr<amrex::FabArray<amrex::EBCellFlagFab> > eb_aux_::m_cellflags
private

Referenced by define(), and getMultiEBCellFlagFab().

◆ m_facecent

amrex::Array<std::unique_ptr<amrex::MultiFab>,AMREX_SPACEDIM> eb_aux_::m_facecent
private

Referenced by define(), and getFaceCent().

◆ m_verbose

int eb_aux_::m_verbose
private

Referenced by define(), and set_verbose().

◆ m_volcent

std::unique_ptr<amrex::MultiFab> eb_aux_::m_volcent
private

Referenced by define(), and getCentroid().

◆ m_volfrac

std::unique_ptr<amrex::MultiFab> eb_aux_::m_volfrac
private

Referenced by define(), and getVolFrac().


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