Skip to content

Commit

Permalink
Small volfrac (#1228)
Browse files Browse the repository at this point in the history
## Summary

When extend_domain_face is set to true we do the following: If we set a cell that lies on one of the 6 faces of the domain as covered because its volfrac is less than the small_volfrac , we are forcing the corresponding ghost cells on that face to also be covered.

## Additional background

## Checklist

The proposed changes:
- [x] fix a bug or incorrect behavior in AMReX
- [ ] add new capabilities to AMReX
- [x] changes answers in the test suite to more than roundoff level
- [ ] are likely to significantly affect the results of downstream AMReX users
- [ ] are described in the proposed changes to the AMReX documentation, if appropriate
  • Loading branch information
drangara authored Aug 9, 2020
1 parent d8d2700 commit a2eecef
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 27 deletions.
85 changes: 75 additions & 10 deletions Src/EB/AMReX_EB2_2D_C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ void set_eb_data (const int i, const int j,
}
}
}

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void set_covered(const int i, const int j,
Array4<EBCellFlag> const& cell,
Array4<Real> const& vfrac, Array4<Real> const& vcent,
Array4<Real> const& barea, Array4<Real> const& bcent,
Array4<Real> const& bnorm)
{
vfrac(i,j,0) = 0.0;
vcent(i,j,0,0) = 0.0;
vcent(i,j,0,1) = 0.0;
barea(i,j,0) = 0.0;
bcent(i,j,0,0) = -1.0;
bcent(i,j,0,1) = -1.0;
bnorm(i,j,0,0) = 0.0;
bnorm(i,j,0,1) = 0.0;
cell(i,j,0).setCovered();
}

}

void build_faces (Box const& bx, Array4<EBCellFlag> const& cell,
Expand Down Expand Up @@ -223,7 +242,8 @@ void build_cells (Box const& bx, Array4<EBCellFlag> const& cell,
Array4<Real> const& apx, Array4<Real> const& apy,
Array4<Real> const& vfrac, Array4<Real> const& vcent,
Array4<Real> const& barea, Array4<Real> const& bcent,
Array4<Real> const& bnorm, Real small_volfrac)
Array4<Real> const& bnorm, Real small_volfrac,
Geometry const& geom, bool extend_domain_face)
{
const Box& bxg1 = amrex::grow(bx,1);
AMREX_HOST_DEVICE_FOR_3D ( bxg1, i, j, k,
Expand Down Expand Up @@ -252,19 +272,64 @@ void build_cells (Box const& bx, Array4<EBCellFlag> const& cell,

// remove small cells
if (vfrac(i,j,0) < small_volfrac) {
vfrac(i,j,0) = 0.0;
vcent(i,j,0,0) = 0.0;
vcent(i,j,0,1) = 0.0;
barea(i,j,0) = 0.0;
bcent(i,j,0,0) = -1.0;
bcent(i,j,0,1) = -1.0;
bnorm(i,j,0,0) = 0.0;
bnorm(i,j,0,1) = 0.0;
cell(i,j,0).setCovered();
set_covered(i,j,cell,vfrac,vcent,barea,bcent,bnorm);
}
}
});

// set cells in the extended region to covered if the
// corresponding cell on the domain face is covered
if(extend_domain_face) {

Box gdomain = geom.Domain();
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
if (geom.isPeriodic(idim)) {
gdomain.setSmall(idim, std::min(gdomain.smallEnd(idim), bxg1.smallEnd(idim)));
gdomain.setBig(idim, std::max(gdomain.bigEnd(idim), bxg1.bigEnd(idim)));
}
}

if (not gdomain.contains(bxg1)) {
AMREX_HOST_DEVICE_FOR_3D ( bxg1, i, j, k,
{
const auto & dlo = gdomain.loVect();
const auto & dhi = gdomain.hiVect();

// find the cell(ii,jj,kk) on the corr. domain face
// this would have already been set to correct value
bool in_extended_domain = false;
int ii = i;
int jj = j;
int kk = k;
if(i < dlo[0]) {
in_extended_domain = true;
ii = dlo[0];
}
else if(i > dhi[0]) {
in_extended_domain = true;
ii = dhi[0];
}

if(j < dlo[1]) {
in_extended_domain = true;
jj = dlo[1];
}
else if(j > dhi[1]) {
in_extended_domain = true;
jj = dhi[1];
}

// set cell in extendable region to covered if necessary
if( in_extended_domain and (not cell(i,j,k).isCovered())
and cell(ii,jj,kk).isCovered() )
{
set_covered(i,j,cell,vfrac,vcent,barea,bcent,bnorm);
}
});
}
}


// fix face for small cells
AMREX_LAUNCH_HOST_DEVICE_LAMBDA ( bxg1, tbx,
{
Expand Down
98 changes: 85 additions & 13 deletions Src/EB/AMReX_EB2_3D_C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,27 @@ void cut_face_2d (Real& areafrac, Real& centx, Real& centy,
}
}
}

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void set_covered (const int i, const int j, const int k,
Array4<EBCellFlag> const& cell,
Array4<Real> const& vfrac, Array4<Real> const& vcent,
Array4<Real> const& barea, Array4<Real> const& bcent,
Array4<Real> const& bnorm)
{
vfrac(i,j,k) = 0.0;
vcent(i,j,k,0) = 0.0;
vcent(i,j,k,1) = 0.0;
vcent(i,j,k,2) = 0.0;
bcent(i,j,k,0) = -1.0;
bcent(i,j,k,1) = -1.0;
bcent(i,j,k,2) = -1.0;
bnorm(i,j,k,0) = 0.0;
bnorm(i,j,k,1) = 0.0;
bnorm(i,j,k,2) = 0.0;
barea(i,j,k) = 0.0;
cell(i,j,k).setCovered();
}
}

void build_faces (Box const& bx, Array4<EBCellFlag> const& cell,
Expand Down Expand Up @@ -609,7 +630,8 @@ void build_cells (Box const& bx, Array4<EBCellFlag> const& cell,
Array4<Real> const& vfrac, Array4<Real> const& vcent,
Array4<Real> const& barea, Array4<Real> const& bcent,
Array4<Real> const& bnorm, Array4<EBCellFlag> const& ctmp,
Real small_volfrac)
Real small_volfrac,
Geometry const& geom, bool extend_domain_face)
{
const Box& bxg1 = amrex::grow(bx,1);
AMREX_HOST_DEVICE_FOR_3D ( bxg1, i, j, k,
Expand Down Expand Up @@ -646,22 +668,72 @@ void build_cells (Box const& bx, Array4<EBCellFlag> const& cell,

// remove small cells
if (vfrac(i,j,k) < small_volfrac) {
vfrac(i,j,k) = 0.0;
vcent(i,j,k,0) = 0.0;
vcent(i,j,k,1) = 0.0;
vcent(i,j,k,2) = 0.0;
bcent(i,j,k,0) = -1.0;
bcent(i,j,k,1) = -1.0;
bcent(i,j,k,2) = -1.0;
bnorm(i,j,k,0) = 0.0;
bnorm(i,j,k,1) = 0.0;
bnorm(i,j,k,2) = 0.0;
barea(i,j,k) = 0.0;
cell(i,j,k).setCovered();
set_covered(i,j,k,cell,vfrac,vcent,barea,bcent,bnorm);
}
}
});

// set cells in the extended region to covered if the
// corresponding cell on the domain face is covered
if(extend_domain_face) {

Box gdomain = geom.Domain();
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
if (geom.isPeriodic(idim)) {
gdomain.setSmall(idim, std::min(gdomain.smallEnd(idim), bxg1.smallEnd(idim)));
gdomain.setBig(idim, std::max(gdomain.bigEnd(idim), bxg1.bigEnd(idim)));
}
}

if (not gdomain.contains(bxg1)) {
AMREX_HOST_DEVICE_FOR_3D ( bxg1, i, j, k,
{
const auto & dlo = gdomain.loVect();
const auto & dhi = gdomain.hiVect();

// find the cell(ii,jj,kk) on the corr. domain face
// this would have already been set to correct value
bool in_extended_domain = false;
int ii = i;
int jj = j;
int kk = k;
if(i < dlo[0]) {
in_extended_domain = true;
ii = dlo[0];
}
else if(i > dhi[0]) {
in_extended_domain = true;
ii = dhi[0];
}

if(j < dlo[1]) {
in_extended_domain = true;
jj = dlo[1];
}
else if(j > dhi[1]) {
in_extended_domain = true;
jj = dhi[1];
}

if(k < dlo[2]) {
in_extended_domain = true;
kk = dlo[2];
}
else if(k > dhi[2]) {
in_extended_domain = true;
kk = dhi[2];
}

// set cell in extendable region to covered if necessary
if( in_extended_domain and (not cell(i,j,k).isCovered())
and cell(ii,jj,kk).isCovered() )
{
set_covered(i,j,k,cell,vfrac,vcent,barea,bcent,bnorm);
}
});
}
}

// fix faces for small cells
const auto bxlo = amrex::lbound(bx);
const auto bxhi = amrex::ubound(bx);
Expand Down
7 changes: 5 additions & 2 deletions Src/EB/AMReX_EB2_C.H
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <AMReX_FArrayBox.H>
#include <AMReX_EBCellFlag.H>
#include <AMReX_EB2_Graph.H>
#include <AMReX_Geometry.H>

#if (AMREX_SPACEDIM == 2)
#include <AMReX_EB2_2D_C.H>
Expand All @@ -29,7 +30,8 @@ void build_cells (Box const& bx, Array4<EBCellFlag> const& cell,
Array4<Real> const& apx, Array4<Real> const& apy,
Array4<Real> const& vfrac, Array4<Real> const& vcent,
Array4<Real> const& barea, Array4<Real> const& bcent,
Array4<Real> const& bnorm, Real small_volfrac);
Array4<Real> const& bnorm, Real small_volfrac,
Geometry const& geom, bool extend_domain_face);

#elif (AMREX_SPACEDIM == 3)

Expand Down Expand Up @@ -57,7 +59,8 @@ void build_cells (Box const& bx, Array4<EBCellFlag> const& cell,
Array4<Real> const& vfrac, Array4<Real> const& vcent,
Array4<Real> const& barea, Array4<Real> const& bcent,
Array4<Real> const& bnorm, Array4<EBCellFlag> const& ctmp,
Real small_volfrac);
Real small_volfrac,
Geometry const& geom, bool extend_domain_face);

#endif

Expand Down
6 changes: 4 additions & 2 deletions Src/EB/AMReX_EB2_Level.H
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ GShopLevel<G>::GShopLevel (IndexSpace const* is, G const& gshop, const Geometry&

build_cells(vbx, cfg, ftx, fty, ftz, apx, apy, apz,
fcx, fcy, fcz, xm2, ym2, zm2, vfr, ctr,
bar, bct, bnm, cfgtmp, small_volfrac);
bar, bct, bnm, cfgtmp, small_volfrac,
geom, extend_domain_face);

#elif (AMREX_SPACEDIM == 2)
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
Expand Down Expand Up @@ -332,7 +333,8 @@ GShopLevel<G>::GShopLevel (IndexSpace const* is, G const& gshop, const Geometry&

build_faces(vbx, cfg, ftx, fty, lst, xip, yip, apx, apy, fcx, fcy, dx, problo);

build_cells(vbx, cfg, ftx, fty, apx, apy, vfr, ctr, bar, bct, bnm, small_volfrac);
build_cells(vbx, cfg, ftx, fty, apx, apy, vfr, ctr, bar, bct, bnm, small_volfrac,
geom, extend_domain_face);
#endif
}
}
Expand Down

0 comments on commit a2eecef

Please sign in to comment.