Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/EB/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ CEXE_sources += eb_sphere.cpp
CEXE_sources += writeEBsurface.cpp

CEXE_headers += eb_if.H
CEXE_headers += eb_utils.H
23 changes: 23 additions & 0 deletions Source/EB/eb_utils.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef EB_UTILS_H
#define EB_UTILS_H

AMREX_GPU_DEVICE
AMREX_FORCE_INLINE
bool
is_cut_neighborhood(
const amrex::IntVect& iv,
amrex::Array4<amrex::EBCellFlag const> const& flags,
const amrex::IntVect& ng = amrex::IntVect(1))
{
// Check if there's a cut cell in an ng neighborhood around iv
bool has_cut_cell = flags(iv).isSingleValued();
for (int idir = 0; idir < AMREX_SPACEDIM; idir++) {
const auto dimvec = amrex::IntVect::TheDimensionVector(idir);
for (int n = 1; n <= ng[idir]; n++) {
has_cut_cell |= flags(iv - n * dimvec).isSingleValued() ||
flags(iv + n * dimvec).isSingleValued();
}
}
return has_cut_cell;
}
#endif
12 changes: 6 additions & 6 deletions Source/Hydro/Godunov/Godunov_2D_eb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Godunov_umeth_eb (
amrex::Array4<const amrex::Real> const& /*a1*/,
amrex::Array4<const amrex::Real> const& /*a2*/,
amrex::Array4<const amrex::Real> const& /*vfrac*/,
amrex::Array4<amrex::EBCellFlag const> const& /*flag_arr*/,
amrex::Array4<amrex::EBCellFlag const> const& flag_arr,
const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> del,
const amrex::Real dt,
const amrex::Real small,
Expand Down Expand Up @@ -84,7 +84,7 @@ Godunov_umeth_eb (
// Calculate flattening in-place
if (use_flattening == 1) {
for (int dir_flat = 0; dir_flat < AMREX_SPACEDIM; dir_flat++) {
flat = std::min(flat, flatten(i, j, k, dir_flat, q));
flat = std::min(flat, flatten_eb(i, j, k, dir_flat, flag_arr, q));
}
}

Expand All @@ -93,9 +93,9 @@ Godunov_umeth_eb (
for (int n = 0; n < QVAR; ++n)
{
if (n == QPRES && use_pslope)
slope[n] = plm_pslope(i, j, k, n, 0, q, dx, srcQ, flat, iorder);
slope[n] = plm_pslope_eb(i, j, k, n, 0, flag_arr, q, dx, srcQ, flat, iorder);
else
slope[n] = plm_slope(i, j, k, n, 0, q, flat, iorder);
slope[n] = plm_slope_eb(i, j, k, n, 0, flag_arr, q, flat, iorder);
}
CAMR_plm_d(
i, j, k, 0, qxmarr, qxparr, slope, q, qaux(i, j, k, QC), dx, dt,
Expand All @@ -105,9 +105,9 @@ Godunov_umeth_eb (
for (int n = 0; n < QVAR; n++)
{
if (n == QPRES && use_pslope)
slope[n] = plm_pslope(i, j, k, n, 1, q, dy, srcQ, flat, iorder);
slope[n] = plm_pslope_eb(i, j, k, n, 1, flag_arr, q, dy, srcQ, flat, iorder);
else
slope[n] = plm_slope(i, j, k, n, 1, q, flat, iorder);
slope[n] = plm_slope_eb(i, j, k, n, 1, flag_arr, q, flat, iorder);
}
CAMR_plm_d(
i, j, k, 1, qymarr, qyparr, slope, q, qaux(i, j, k, QC), dy, dt,
Expand Down
16 changes: 8 additions & 8 deletions Source/Hydro/Godunov/Godunov_3D_eb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Godunov_umeth_eb (
amrex::Array4<const amrex::Real> const& /*a2*/,
amrex::Array4<const amrex::Real> const& /*a3*/,
amrex::Array4<const amrex::Real> const& /*vfrac*/,
amrex::Array4<amrex::EBCellFlag const> const& /*flag_arr*/,
amrex::Array4<amrex::EBCellFlag const> const& flag_arr,
const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> del,
const amrex::Real dt,
const amrex::Real small,
Expand Down Expand Up @@ -109,17 +109,17 @@ Godunov_umeth_eb (
// Calculate flattening in-place
if (use_flattening == 1) {
for (int dir_flat = 0; dir_flat < AMREX_SPACEDIM; dir_flat++) {
flat = std::min(flat, flatten(i, j, k, dir_flat, q));
flat = std::min(flat, flatten_eb(i, j, k, dir_flat, flag_arr, q));
}
}

// X slopes and interp
int idir = 0;
for (int n = 0; n < QVAR; ++n) {
if (n == QPRES && use_pslope)
slope[n] = plm_pslope(i, j, k, n, 0, q, dx, srcQ, flat, iorder);
slope[n] = plm_pslope_eb(i, j, k, n, 0, flag_arr, q, dx, srcQ, flat, iorder);
else
slope[n] = plm_slope(i, j, k, n, 0, q, flat, iorder);
slope[n] = plm_slope_eb(i, j, k, n, 0, flag_arr, q, flat, iorder);
}
CAMR_plm_d(
i, j, k, idir, qxmarr, qxparr, slope, q, qaux(i, j, k, QC), dx, dt,
Expand All @@ -129,9 +129,9 @@ Godunov_umeth_eb (
idir = 1;
for (int n = 0; n < QVAR; n++) {
if (n == QPRES && use_pslope)
slope[n] = plm_pslope(i, j, k, n, 1, q, dy, srcQ, flat, iorder);
slope[n] = plm_pslope_eb(i, j, k, n, 1, flag_arr, q, dy, srcQ, flat, iorder);
else
slope[n] = plm_slope(i, j, k, n, 1, q, flat, iorder);
slope[n] = plm_slope_eb(i, j, k, n, 1, flag_arr, q, flat, iorder);
}
CAMR_plm_d(
i, j, k, idir, qymarr, qyparr, slope, q, qaux(i, j, k, QC), dy, dt,
Expand All @@ -141,9 +141,9 @@ Godunov_umeth_eb (
idir = 2;
for (int n = 0; n < QVAR; ++n) {
if (n == QPRES && use_pslope)
slope[n] = plm_pslope(i, j, k, n, 2, q, dz, srcQ, flat, iorder);
slope[n] = plm_pslope_eb(i, j, k, n, 2, flag_arr, q, dz, srcQ, flat, iorder);
else
slope[n] = plm_slope(i, j, k, n, 2, q, flat, iorder);
slope[n] = plm_slope_eb(i, j, k, n, 2, flag_arr, q, flat, iorder);
}
CAMR_plm_d(
i, j, k, idir, qzmarr, qzparr, slope, q, qaux(i, j, k, QC), dz, dt,
Expand Down
21 changes: 21 additions & 0 deletions Source/Hydro/Godunov/Godunov_utils.H
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "AMReX_MultiFabUtil.H"
#include <AMReX_EBFArrayBox.H>
#include <AMReX_MultiCutFab.H>
#include "eb_utils.H"
#endif

AMREX_GPU_DEVICE
Expand Down Expand Up @@ -98,6 +99,26 @@ flatten (
return 1.0 - std::max(chi2 * z2, chi * z);
}

#ifdef AMREX_USE_EB
AMREX_GPU_DEVICE
AMREX_FORCE_INLINE
amrex::Real flatten_eb(const int i,
const int j,
const int k,
const int dir,
amrex::Array4<amrex::EBCellFlag const> const& flags,
amrex::Array4<const amrex::Real> const &q) {

const amrex::IntVect iv{AMREX_D_DECL(i, j, k)};
const amrex::IntVect dvec(amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect ng(3 * dvec);
if(is_cut_neighborhood(iv, flags, ng)){
return 1.0;
}
return flatten(i, j, k, dir, q);
}
#endif

#if (AMREX_SPACEDIM == 3)
// Transverse Correction for Predicted dir-states, using other_dir-Flux
AMREX_GPU_DEVICE
Expand Down
191 changes: 150 additions & 41 deletions Source/Hydro/Godunov/PLM.H
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "CAMR_Constants.H"
#include "IndexDefines.H"


// This header file contains functions and declarations for the 3D hydro portion
// of CAMR on the GPU. As per the convention of AMReX, inlined functions are
// defined here, whereas non-inline functions are declared here.
Expand All @@ -32,34 +33,38 @@ plm_slope (
} else {
amrex::ignore_unused(k);
const amrex::IntVect iv{AMREX_D_DECL(i, j, k)};
const amrex::IntVect ivm2(iv - 2 * amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect ivm(iv - amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect ivp(iv + amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect ivp2(iv + 2 * amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect dvec(amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect ivm2(iv - 2 * dvec);
const amrex::IntVect ivm(iv - dvec);
const amrex::IntVect ivp(iv + dvec);
const amrex::IntVect ivp2(iv + 2 * dvec);

amrex::Real dlft, drgt, dcen, dfm, dfp, dlim, dsgn, dtemp;
amrex::Real dlft, drgt, dcen, dfm = 0.0, dfp = 0.0, dlim, dsgn, dtemp;
const amrex::Real qc = q(iv, n);
const amrex::Real qm2 = q(ivm2, n);
const amrex::Real qm = q(ivm, n);
const amrex::Real qp = q(ivp, n);
const amrex::Real qp2 = q(ivp2, n);

dlft = qm - qm2;
drgt = qc - qm;
dcen = 0.5 * (dlft + drgt);
dsgn = amrex::Math::copysign(1.0, dcen);
dlim = (dlft * drgt >= 0.0)
? 2.0 * std::min(std::abs(dlft), std::abs(drgt))
: 0.0;
dfm = dsgn * std::min(dlim, std::abs(dcen));

dlft = qp - qc;
drgt = qp2 - qp;
dcen = 0.5 * (dlft + drgt);
dsgn = amrex::Math::copysign(1.0, dcen);
dlim = (dlft * drgt >= 0.0)
? 2.0 * std::min(std::abs(dlft), std::abs(drgt)) : 0.0;
dfp = dsgn * std::min(dlim, std::abs(dcen));
if (order == 4) {
dlft = qm - qm2;
drgt = qc - qm;
dcen = 0.5 * (dlft + drgt);
dsgn = amrex::Math::copysign(1.0, dcen);
dlim = (dlft * drgt >= 0.0)
? 2.0 * std::min(std::abs(dlft), std::abs(drgt))
: 0.0;
dfm = dsgn * std::min(dlim, std::abs(dcen));

dlft = qp - qc;
drgt = (order == 4) ? qp2 - qp : 0.0;
dcen = 0.5 * (dlft + drgt);
dsgn = amrex::Math::copysign(1.0, dcen);
dlim = (dlft * drgt >= 0.0)
? 2.0 * std::min(std::abs(dlft), std::abs(drgt))
: 0.0;
dfp = dsgn * std::min(dlim, std::abs(dcen));
}

dlft = qc - qm;
drgt = qp - qc;
Expand Down Expand Up @@ -96,12 +101,13 @@ plm_pslope (

amrex::ignore_unused(k);
const amrex::IntVect iv{AMREX_D_DECL(i, j, k)};
const amrex::IntVect ivm2(iv - 2 * amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect ivm(iv - amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect ivp(iv + amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect ivp2(iv + 2 * amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect dvec(amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect ivm2(iv - 2 * dvec);
const amrex::IntVect ivm(iv - dvec);
const amrex::IntVect ivp(iv + dvec);
const amrex::IntVect ivp2(iv + 2 * dvec);

amrex::Real dlft, drgt, dcen, dfm, dfp, dlim, dsgn, dtemp;
amrex::Real dlft, drgt, dcen, dfm = 0.0, dfp = 0.0, dlim, dsgn, dtemp;
const amrex::Real qc = q(iv , n);
const amrex::Real qm2 = q(ivm2, n);
const amrex::Real qm = q(ivm , n);
Expand All @@ -115,21 +121,33 @@ plm_pslope (
if (dir == 2) QIU = QW;
#endif

dlft = qm - qm2 - 0.25 * dx * (q(ivm,QRHO)+q(ivm2,QRHO)) * (srcQ(ivm,QIU)+srcQ(ivm2,QIU));
drgt = qc - qm - 0.25 * dx * (q(ivm,QRHO)+q(iv ,QRHO)) * (srcQ(ivm,QIU)+srcQ(iv ,QIU));
dcen = 0.5 * (dlft + drgt);
dsgn = amrex::Math::copysign(1.0, dcen);
dlim = (dlft * drgt >= 0.0)
? 2.0 * std::min( std::abs(dlft), std::abs(drgt)) : 0.0;
dfm = dsgn * std::min<amrex::Real>(dlim, std::abs(dcen));

dlft = qp - qc - 0.25 * dx * (q(ivp,QRHO)+q(iv ,QRHO)) * (srcQ(ivp,QIU)+srcQ(iv ,QIU));
drgt = qp2 - qp - 0.25 * dx * (q(ivp,QRHO)+q(ivp2,QRHO)) * (srcQ(ivp,QIU)+srcQ(ivp2,QIU));
dcen = 0.5 * (dlft + drgt);
dsgn = amrex::Math::copysign(1.0, dcen);
dlim = (dlft * drgt >= 0.0)
? 2.0 * std::min(std::abs(dlft), std::abs(drgt)) : 0.0;
dfp = dsgn * std::min(dlim, std::abs(dcen));
if (order == 4) {
dlft = qm - qm2 -
0.25 * dx * (q(ivm, QRHO) + q(ivm2, QRHO)) *
(srcQ(ivm, QIU) + srcQ(ivm2, QIU));
drgt = qc - qm -
0.25 * dx * (q(ivm, QRHO) + q(iv, QRHO)) *
(srcQ(ivm, QIU) + srcQ(iv, QIU));
dcen = 0.5 * (dlft + drgt);
dsgn = amrex::Math::copysign(1.0, dcen);
dlim = (dlft * drgt >= 0.0)
? 2.0 * std::min(std::abs(dlft), std::abs(drgt))
: 0.0;
dfm = dsgn * std::min<amrex::Real>(dlim, std::abs(dcen));

dlft = qp - qc -
0.25 * dx * (q(ivp, QRHO) + q(iv, QRHO)) *
(srcQ(ivp, QIU) + srcQ(iv, QIU));
drgt = qp2 - qp -
0.25 * dx * (q(ivp, QRHO) + q(ivp2, QRHO)) *
(srcQ(ivp, QIU) + srcQ(ivp2, QIU));
dcen = 0.5 * (dlft + drgt);
dsgn = amrex::Math::copysign(1.0, dcen);
dlim = (dlft * drgt >= 0.0)
? 2.0 * std::min(std::abs(dlft), std::abs(drgt))
: 0.0;
dfp = dsgn * std::min(dlim, std::abs(dcen));
}

dlft = qc - qm - 0.25 * dx * (q(iv,QRHO)+q(ivm,QRHO)) * (srcQ(iv,QIU)+srcQ(ivm,QIU));
drgt = qp - qc - 0.25 * dx * (q(iv,QRHO)+q(ivp,QRHO)) * (srcQ(iv,QIU)+srcQ(ivp,QIU));
Expand All @@ -147,6 +165,97 @@ plm_pslope (
}
}


#ifdef AMREX_USE_EB
AMREX_GPU_DEVICE
AMREX_FORCE_INLINE
amrex::Real
plm_slope_eb (
const int i,
const int j,
const int k,
const int n,
const int dir,
amrex::Array4<amrex::EBCellFlag const> const& flags,
amrex::Array4<const amrex::Real> const& q,
amrex::Real flat,
const int order)
{
const amrex::IntVect iv{AMREX_D_DECL(i, j, k)};
const amrex::IntVect dvec(amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect ivm2(iv - 2 * dvec);
const amrex::IntVect ivm(iv - dvec);
const amrex::IntVect ivp(iv + dvec);
const amrex::IntVect ivp2(iv + 2 * dvec);

// We have enough cells in the x-direction to do 4th order slopes
// centered on (i,j,k) with all values at cell centers
if ((order == 4) &&
flags(iv).isSingleValued() &&
flags(ivm).isSingleValued() &&
flags(ivm2).isSingleValued() &&
flags(ivp).isSingleValued() &&
flags(ivp2).isSingleValued()){
return plm_slope(i, j, k, n, dir, q, flat, order);
}
// We have enough cells in the x-direction to do 2nd order slopes
// centered on (i,j,k) with all values at cell centers
else if ((order > 1) &&
flags(iv).isSingleValued() &&
flags(ivm).isSingleValued() &&
flags(ivp).isSingleValued()){
return plm_slope(i, j, k, n, dir, q, flat, 2);
} else {
return 0.0;
}
}

AMREX_GPU_DEVICE
AMREX_FORCE_INLINE
amrex::Real
plm_pslope_eb (
const int i,
const int j,
const int k,
const int n,
const int dir,
amrex::Array4<amrex::EBCellFlag const> const& flags,
amrex::Array4<const amrex::Real> const& q,
const amrex::Real dx,
amrex::Array4<const amrex::Real> const& srcQ,
amrex::Real flat,
const int order)
{
const amrex::IntVect iv{AMREX_D_DECL(i, j, k)};
const amrex::IntVect dvec(amrex::IntVect::TheDimensionVector(dir));
const amrex::IntVect ivm2(iv - 2 * dvec);
const amrex::IntVect ivm(iv - dvec);
const amrex::IntVect ivp(iv + dvec);
const amrex::IntVect ivp2(iv + 2 * dvec);

// We have enough cells in the x-direction to do 4th order slopes
// centered on (i,j,k) with all values at cell centers
if ((order == 4) &&
flags(iv).isSingleValued() &&
flags(ivm).isSingleValued() &&
flags(ivm2).isSingleValued() &&
flags(ivp).isSingleValued() &&
flags(ivp2).isSingleValued()){
return plm_pslope(i, j, k, n, dir, q, dx, srcQ, flat, order);
}
// We have enough cells in the x-direction to do 2nd order slopes
// centered on (i,j,k) with all values at cell centers
else if ((order > 1) &&
flags(iv).isSingleValued() &&
flags(ivm).isSingleValued() &&
flags(ivp).isSingleValued()){
return plm_pslope(i, j, k, n, dir, q, dx, srcQ, flat, 2);
} else {
return 0.0;
}
}
#endif

AMREX_GPU_DEVICE
AMREX_FORCE_INLINE
void
Expand Down
Loading