Skip to content

Commit

Permalink
Some clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgrote committed Aug 13, 2024
1 parent 28353c1 commit a1dd51c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
14 changes: 7 additions & 7 deletions Source/Filter/Filter.H
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ public:

// Apply stencil on MultiFab.
// Guard cells are handled inside this function
void ApplyStencil(amrex::MultiFab& dstmf,
const amrex::MultiFab& srcmf, int lev, int scomp=0,
int dcomp=0, int ncomp=10000);
void ApplyStencil (amrex::MultiFab& dstmf,
const amrex::MultiFab& srcmf, int lev, int scomp=0,
int dcomp=0, int ncomp=10000);

// Apply stencil on a FabArray.
void ApplyStencil (amrex::FArrayBox& dstfab,
const amrex::FArrayBox& srcfab, const amrex::Box& tbx,
int scomp=0, int dcomp=0, int ncomp=10000);

// public for cuda
void DoFilter(const amrex::Box& tbx,
amrex::Array4<amrex::Real const> const& tmp,
amrex::Array4<amrex::Real > const& dst,
int scomp, int dcomp, int ncomp);
void DoFilter (const amrex::Box& tbx,
amrex::Array4<amrex::Real const> const& tmp,
amrex::Array4<amrex::Real > const& dst,
int scomp, int dcomp, int ncomp);

// Length of stencil in each included direction
amrex::IntVect stencil_length_each_dir;
Expand Down
36 changes: 10 additions & 26 deletions Source/Filter/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ void Filter::DoFilter (const Box& tbx,
Array4<Real > const& dst,
int scomp, int dcomp, int ncomp)
{
amrex::Real const* AMREX_RESTRICT sx = stencil_x.data();
#if AMREX_SPACEDIM >= 2
amrex::Real const* AMREX_RESTRICT sy = stencil_y.data();
#endif
#if AMREX_SPACEDIM == 3
AMREX_D_DECL(
amrex::Real const* AMREX_RESTRICT sx = stencil_x.data();,
amrex::Real const* AMREX_RESTRICT sy = stencil_y.data();,
amrex::Real const* AMREX_RESTRICT sz = stencil_z.data();
#endif
)
Dim3 slen_local = slen;

#if AMREX_SPACEDIM == 3
Expand Down Expand Up @@ -183,9 +181,6 @@ void Filter::DoFilter (const Box& tbx,

dst(i,j,k,dcomp+n) = d;
});
#else
WARPX_ABORT_WITH_MESSAGE(
"Filter not implemented for the current geometry!");
#endif
}

Expand Down Expand Up @@ -278,13 +273,11 @@ void Filter::DoFilter (const Box& tbx,
const auto lo = amrex::lbound(tbx);
const auto hi = amrex::ubound(tbx);
// tmp and dst are of type Array4 (Fortran ordering)
amrex::Real const* AMREX_RESTRICT sx = stencil_x.data();
#if AMREX_SPACEDIM >= 2
amrex::Real const* AMREX_RESTRICT sy = stencil_y.data();
#endif
#if AMREX_SPACEDIM == 3
AMREX_D_DECL(
amrex::Real const* AMREX_RESTRICT sx = stencil_x.data();,
amrex::Real const* AMREX_RESTRICT sy = stencil_y.data();,
amrex::Real const* AMREX_RESTRICT sz = stencil_z.data();
#endif
)
for (int n = 0; n < ncomp; ++n) {
// Set dst value to 0.
for (int k = lo.z; k <= hi.z; ++k) {
Expand All @@ -298,13 +291,7 @@ void Filter::DoFilter (const Box& tbx,
for (int iz=0; iz < slen.z; ++iz){
for (int iy=0; iy < slen.y; ++iy){
for (int ix=0; ix < slen.x; ++ix){
#if AMREX_SPACEDIM == 3
const Real sss = sx[ix]*sy[iy]*sz[iz];
#elif AMREX_SPACEDIM >= 2
const Real sss = sx[ix]*sy[iy];
#elif AMREX_SPACEDIM == 1
const Real sss = sx[ix];
#endif
const Real sss = AMREX_D_TERM(sx[ix], *sy[iy], *sz[iz]);
// 3 nested loop on 3D array
for (int k = lo.z; k <= hi.z; ++k) {
for (int j = lo.y; j <= hi.y; ++j) {
Expand All @@ -319,17 +306,14 @@ void Filter::DoFilter (const Box& tbx,
+tmp(i+ix,j-iy,k+iz,scomp+n)
+tmp(i-ix,j+iy,k+iz,scomp+n)
+tmp(i+ix,j+iy,k+iz,scomp+n));
#elif AMREX_SPACEDIM >= 2
#elif AMREX_SPACEDIM == 2
dst(i,j,k,dcomp+n) += sss*(tmp(i-ix,j-iy,k,scomp+n)
+tmp(i+ix,j-iy,k,scomp+n)
+tmp(i-ix,j+iy,k,scomp+n)
+tmp(i+ix,j+iy,k,scomp+n));
#elif AMREX_SPACEDIM == 1
dst(i,j,k,dcomp+n) += sss*(tmp(i-ix,j,k,scomp+n)
+tmp(i+ix,j,k,scomp+n));
#else
WARPX_ABORT_WITH_MESSAGE(
"Filter not implemented for the current geometry!");
#endif
}
}
Expand Down

0 comments on commit a1dd51c

Please sign in to comment.