Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move redist into amrex #3378

Merged
merged 32 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e12022e
move redist into amrex
asalmgren Jun 20, 2023
97553d7
Merge branch 'development' into move_redist_into_amrex
WeiqunZhang Jun 20, 2023
779be96
Fix warnings
WeiqunZhang Jun 20, 2023
1c26672
Fix more warnings
WeiqunZhang Jun 20, 2023
866af7b
we need to pass use_wts_in_divnc through the other interfaces
asalmgren Jun 20, 2023
e122966
fix more warnings
WeiqunZhang Jun 20, 2023
5bb0955
Merge branch 'move_redist_into_amrex' of github.com:asalmgren/amrex i…
WeiqunZhang Jun 20, 2023
bbadefd
add amrex::
WeiqunZhang Jun 20, 2023
f412f3b
fix warnings
WeiqunZhang Jun 20, 2023
b20f41c
fix warning
WeiqunZhang Jun 20, 2023
01f95d4
add new file
WeiqunZhang Jun 20, 2023
9337315
updated files
asalmgren Jun 23, 2023
9f1ac70
Merge branch 'move_redist_into_amrex' of github.com:asalmgren/amrex i…
asalmgren Jun 23, 2023
c6a43b2
fix indexing in EBFluxRegisters
asalmgren Jun 23, 2023
cfc8aa5
fix oops
asalmgren Jun 23, 2023
007c71e
Fix up YAFluxRegisters
asalmgren Jun 23, 2023
7ec5c6d
Fix typo
asalmgren Jun 23, 2023
53fab13
Add redistribution to docs
asalmgren Jun 23, 2023
ccfad1c
remove trailing white space
asalmgren Jun 23, 2023
0b34457
Fix component bug in EBFluxRegister::CrseAdd
asalmgren Jun 23, 2023
19b62d1
Fix clang-tidy warning
WeiqunZhang Jun 24, 2023
256c3f0
Fix so we don't need to pass srccomp into FluxRegisters
asalmgren Jun 24, 2023
15a3fe6
Merge branch 'move_redist_into_amrex' of github.com:asalmgren/amrex i…
asalmgren Jun 24, 2023
2bb6d42
fix bug plus BL_ASSERT --> AMREX_ASSERT
asalmgren Jun 25, 2023
82fd18f
make figures smaller
WeiqunZhang Jun 26, 2023
8cbeb49
Add srccomp to CrseAdd, FineAdd etc.
WeiqunZhang Jun 27, 2023
23bfc40
Remove some versions of CrseAdd, FineAdd and Reflux
WeiqunZhang Jun 29, 2023
950cd05
Merge branch 'development' into move_redist_into_amrex
WeiqunZhang Jun 29, 2023
e24d2b0
minor
WeiqunZhang Jun 29, 2023
7a9d862
Add back the non-re-redist version
WeiqunZhang Jul 1, 2023
41e8549
Add RZ support in YAFluxReglister
WeiqunZhang Jul 2, 2023
e60d441
fix a bug in last commit
WeiqunZhang Jul 3, 2023
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
433 changes: 433 additions & 0 deletions Src/Base/AMReX_Slopes_K.H

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Src/Base/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ C$(AMREX_BASE)_headers += AMReX_RKIntegrator.H
C$(AMREX_BASE)_headers += AMReX_TimeIntegrator.H
C$(AMREX_BASE)_headers += AMReX_RungeKutta.H

#
# Slopes
#
C$(AMREX_BASE)_headers += AMReX_Slopes_K.H

#
# Fortran interface routines.
#
Expand Down
20 changes: 20 additions & 0 deletions Src/EB/AMReX_EBFluxRegister.H
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public:
RunOn runon);

using YAFluxRegister::FineAdd;

// If we are not doing re-redistribution we don't need dm
void FineAdd (const MFIter& mfi,
const std::array<FArrayBox const*, AMREX_SPACEDIM>& flux,
const Real* dx, Real dt,
const FArrayBox& volfrac,
const std::array<FArrayBox const*, AMREX_SPACEDIM>& areafrac,
RunOn runon);

// If we are doing re-redistribution we add dm to the solution
void FineAdd (const MFIter& mfi,
const std::array<FArrayBox const*, AMREX_SPACEDIM>& flux,
const Real* dx, Real dt,
Expand All @@ -88,8 +98,18 @@ public:
const FArrayBox& dm,
RunOn runon);

// If we are not doing re-redistribution we don't touch the fine state
void Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac);
void Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac,
int src_comp, int dest_comp, int num_comp);

// If we are doing re-redistribution we update the fine state as well as crse
void Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac,
MultiFab& fine_state, const amrex::MultiFab& fine_vfrac);
void Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac,
MultiFab& fine_state, const amrex::MultiFab& fine_vfrac,
int src_comp, int dest_comp, int num_comp);


FArrayBox* getCrseData (const MFIter& mfi) {
return &(m_crse_data[mfi]);
Expand Down
142 changes: 97 additions & 45 deletions Src/EB/AMReX_EBFluxRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ EBFluxRegister::FineAdd (const MFIter& mfi,
const Real* dx, Real dt,
const FArrayBox& volfrac,
const std::array<FArrayBox const*, AMREX_SPACEDIM>& areafrac,
const FArrayBox& dm,
RunOn runon)
{
BL_ASSERT(m_cfpatch.nComp() == a_flux[0]->nComp());
Expand Down Expand Up @@ -207,11 +206,34 @@ EBFluxRegister::FineAdd (const MFIter& mfi,
}
}
}
}

void
EBFluxRegister::FineAdd (const MFIter& mfi,
const std::array<FArrayBox const*, AMREX_SPACEDIM>& a_flux,
const Real* dx, Real dt,
const FArrayBox& vfrac,
const std::array<FArrayBox const*, AMREX_SPACEDIM>& areafrac,
const FArrayBox& dm,
RunOn runon)
{
FineAdd(mfi, a_flux, dx, dt, vfrac, areafrac, runon);

const Box& tbx = mfi.tilebox();
const int nc = m_cfpatch.nComp();

const int li = mfi.LocalIndex();
Vector<FArrayBox*>& cfp_fabs = m_cfp_fab[li];
if (cfp_fabs.empty()) return;
const Box& cbx = amrex::coarsen(tbx, m_ratio);

Dim3 ratio = m_ratio.dim3();

Real threshold = amrex_eb_get_reredistribution_threshold()*static_cast<Real>(AMREX_D_TERM(ratio.x,*ratio.y,*ratio.z));
const Box& tbxg1 = amrex::grow(tbx,1);
const Box& cbxg1 = amrex::grow(cbx,1);
Array4<Real const> const& dma = dm.const_array();
Array4<Real const> const& vfrac_arr = vfrac.const_array();
for (FArrayBox* cfp : cfp_fabs)
{
const Box& wbx = cbxg1 & cfp->box();
Expand All @@ -220,17 +242,82 @@ EBFluxRegister::FineAdd (const MFIter& mfi,
Array4<Real> const& cfa = cfp->array();
AMREX_HOST_DEVICE_FOR_4D_FLAG(runon, wbx, nc, i, j, k, n,
{
eb_flux_reg_fineadd_dm(i,j,k,n,tbxg1, cfa, dma, vfrac, ratio, threshold);
eb_flux_reg_fineadd_dm(i,j,k,n,tbxg1, cfa, dma, vfrac_arr, ratio, threshold);
});
}
}
}


void
EBFluxRegister::Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac,
MultiFab& fine_state, const amrex::MultiFab& fine_vfrac)
{
int src_comp = 0;
int dest_comp = 0;
int num_comp = m_ncomp;
Reflux(crse_state, crse_vfrac, fine_state, fine_vfrac, src_comp, dest_comp, num_comp);
}

void
EBFluxRegister::Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac,
MultiFab& fine_state, const amrex::MultiFab& /*fine_vfrac*/,
int src_comp, int dest_comp, int num_comp)
{
Reflux(crse_state, crse_vfrac, src_comp, dest_comp, num_comp);

// The fine-covered cells of m_crse_data contain the data that should go to the fine level
BoxArray ba = fine_state.boxArray();
ba.coarsen(m_ratio);
MultiFab cf(ba, fine_state.DistributionMap(), m_ncomp, 0, MFInfo(), FArrayBoxFactory());
cf.ParallelCopy(m_crse_data);

auto const& factory = dynamic_cast<EBFArrayBoxFactory const&>(fine_state.Factory());
auto const& flags = factory.getMultiEBCellFlagFab();

Dim3 ratio = m_ratio.dim3();

#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for (MFIter mfi(cf,TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
const Box& cbx = mfi.tilebox();
const Box& fbx = amrex::refine(cbx, m_ratio);

const auto& ebflag = flags[mfi];

if (ebflag.getType(fbx) != FabType::covered)
{
Array4<Real> const& d = fine_state.array(mfi);
Array4<Real const> const& s = cf.const_array(mfi);
Array4< int const> const& m = m_cfp_inside_mask.const_array(mfi);
AMREX_HOST_DEVICE_FOR_4D(fbx,num_comp,i,j,k,n,
{
int nd = dest_comp + n;
int ns = src_comp + n;
eb_rereflux_to_fine(i,j,k,nd,ns,d,s,m,ratio);
});
}
}
}

void
EBFluxRegister::Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac)
{
int src_comp = 0;
int dest_comp = 0;
int num_comp = m_ncomp;
Reflux(crse_state, crse_vfrac, src_comp, dest_comp, num_comp);
}

void
EBFluxRegister::Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac,
MultiFab& fine_state, const amrex::MultiFab& /*fine_vfrac*/)
int src_comp, int dest_comp, int num_comp)
{
AMREX_ASSERT( src_comp+num_comp <= m_ncomp);
AMREX_ASSERT(dest_comp+num_comp <= m_ncomp);

if (!m_cfp_mask.empty())
{
#ifdef AMREX_USE_OMP
Expand All @@ -241,19 +328,19 @@ EBFluxRegister::Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac,
Array4<Real> const& cfa = m_cfpatch.array(mfi);
Array4<Real const> const& m = m_cfp_mask.const_array(mfi);
const Box& bx = mfi.fabbox();
AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx,m_ncomp,i,j,k,n,
AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx,num_comp,i,j,k,n,
{
cfa(i,j,k,n) *= m(i,j,k);
cfa(i,j,k,src_comp+n) *= m(i,j,k);
});
}
}

m_crse_data.ParallelCopy(m_cfpatch, m_crse_geom.periodicity(), FabArrayBase::ADD);
m_crse_data.ParallelCopy(m_cfpatch, src_comp, 0, num_comp, m_crse_geom.periodicity(), FabArrayBase::ADD);

{
MultiFab grown_crse_data(m_crse_data.boxArray(), m_crse_data.DistributionMap(),
m_ncomp, 1, MFInfo(), FArrayBoxFactory());
MultiFab::Copy(grown_crse_data, m_crse_data, 0, 0, m_ncomp, 0);
num_comp, 1, MFInfo(), FArrayBoxFactory());
MultiFab::Copy(grown_crse_data, m_crse_data, 0, 0, num_comp, 0);
grown_crse_data.FillBoundary(m_crse_geom.periodicity());

m_crse_data.setVal(0.0);
Expand Down Expand Up @@ -281,7 +368,7 @@ EBFluxRegister::Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac,
if (ebflag.getType(bxg1) == FabType::regular)
{
// no re-reflux or re-re-redistribution
AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx, m_ncomp, i, j, k, n,
AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx, num_comp, i, j, k, n,
{
dfab(i,j,k,n) += sfab(i,j,k,n);
});
Expand All @@ -301,41 +388,6 @@ EBFluxRegister::Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac,
}
}

MultiFab::Add(crse_state, m_crse_data, 0, 0, m_ncomp, 0);

// The fine-covered cells of m_crse_data contain the data that should go to the fine level
BoxArray ba = fine_state.boxArray();
ba.coarsen(m_ratio);
MultiFab cf(ba, fine_state.DistributionMap(), m_ncomp, 0, MFInfo(), FArrayBoxFactory());
cf.ParallelCopy(m_crse_data);

auto const& factory = dynamic_cast<EBFArrayBoxFactory const&>(fine_state.Factory());
auto const& flags = factory.getMultiEBCellFlagFab();

Dim3 ratio = m_ratio.dim3();

#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for (MFIter mfi(cf,TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
const Box& cbx = mfi.tilebox();
const Box& fbx = amrex::refine(cbx, m_ratio);

const auto& ebflag = flags[mfi];

if (ebflag.getType(fbx) != FabType::covered)
{
Array4<Real> const& d = fine_state.array(mfi);
Array4<Real const> const& s = cf.const_array(mfi);
Array4<int const> const& m = m_cfp_inside_mask.const_array(mfi);
AMREX_HOST_DEVICE_FOR_4D(fbx,m_ncomp,i,j,k,n,
{
eb_rereflux_to_fine(i,j,k,n,d,s,m,ratio);
});
}
}
MultiFab::Add(crse_state, m_crse_data, 0, dest_comp, num_comp, 0);
}


}
4 changes: 2 additions & 2 deletions Src/EB/AMReX_EBFluxRegister_2D_C.H
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ void eb_rereflux_from_crse (int i, int j, int k, int n, Box const& bx, Array4<Re
}

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void eb_rereflux_to_fine (int i, int j, int /*k*/, int n, Array4<Real> const& d,
void eb_rereflux_to_fine (int i, int j, int /*k*/, int nd, int ns, Array4<Real> const& d,
Array4<Real const> const& s, Array4<int const> const& msk, Dim3 ratio)
{
int ic = amrex::coarsen(i,ratio.x);
int jc = amrex::coarsen(j,ratio.y);
if (msk(ic,jc,0) == 1) {
d(i,j,0,n) += s(ic,jc,0,n);
d(i,j,0,nd) += s(ic,jc,0,ns);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Src/EB/AMReX_EBFluxRegister_3D_C.H
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,14 @@ void eb_rereflux_from_crse (int i, int j, int k, int n, Box const& bx, Array4<Re
}

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void eb_rereflux_to_fine (int i, int j, int k, int n, Array4<Real> const& d,
void eb_rereflux_to_fine (int i, int j, int k, int nd, int ns, Array4<Real> const& d,
Array4<Real const> const& s, Array4<int const> const& msk, Dim3 ratio)
{
int ic = amrex::coarsen(i,ratio.x);
int jc = amrex::coarsen(j,ratio.y);
int kc = amrex::coarsen(k,ratio.z);
if (msk(ic,jc,kc) == 1) {
d(i,j,k,n) += s(ic,jc,kc,n);
d(i,j,k,nd) += s(ic,jc,kc,ns);
}
}

Expand Down
Loading
Loading