Skip to content

Commit

Permalink
Add ns to gpu cns (#2177)
Browse files Browse the repository at this point in the history
Add the ability to compute and use diffusive fluxes to Tests/GPU/CNS.  Default is now to include diffusive terms so the existing inputs files now have cns.do_visc=false.
  • Loading branch information
asalmgren authored Jul 19, 2021
1 parent 388ce7e commit ee8facf
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Tests/GPU/CNS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ endif ()
#
set(_sources main.cpp CNS_advance.cpp CNS_bcfill.cpp CNSBld.cpp CNS.cpp CNS_derive.cpp CNS_derive.H CNS.H
CNS_index_macros.H CNS_io.cpp CNS_K.H CNS_parm.cpp CNS_parm.H CNS_setup.cpp CNS_tagging.H
hydro/CNS_hydro_K.H)
hydro/CNS_hydro_K.H diffusion/CNS_diffusion_K.H)
list(TRANSFORM _sources PREPEND Source/)

##########################################################################################
Expand Down
2 changes: 2 additions & 0 deletions Tests/GPU/CNS/Exec/RT/inputs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ cns.hi_bc = 0 0 4
cns.gravity = -1.0
cns.eos_gamma = 1.6666666666

cns.do_visc = false

cns.cfl = 0.3 # cfl number for hyperbolic system

cns.refine_max_dengrad_lev = 10
Expand Down
2 changes: 2 additions & 0 deletions Tests/GPU/CNS/Exec/RT/inputs-rt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ cns.hi_bc = 0 0 4
cns.gravity = -1.0
cns.eos_gamma = 1.6666666666

cns.do_visc = false

cns.cfl = 0.3 # cfl number for hyperbolic system

cns.refine_max_dengrad_lev = 10
Expand Down
2 changes: 2 additions & 0 deletions Tests/GPU/CNS/Exec/Sod/inputs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ cns.hi_bc = 2 0 0

cns.cfl = 0.3 # cfl number for hyperbolic system

cns.do_visc = false

cns.v = 2
amr.v = 1

Expand Down
2 changes: 2 additions & 0 deletions Tests/GPU/CNS/Exec/Sod/inputs-rt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ cns.hi_bc = 2 0 0

cns.cfl = 0.3 # cfl number for hyperbolic system

cns.do_visc = false

cns.v = 2
amr.v = 1

Expand Down
3 changes: 3 additions & 0 deletions Tests/GPU/CNS/Source/CNS.H
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ protected:

static int do_reflux;

static bool do_visc;
static bool use_const_visc;

static int refine_max_dengrad_lev;
static amrex::Real refine_dengrad;

Expand Down
31 changes: 31 additions & 0 deletions Tests/GPU/CNS/Source/CNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ int CNS::do_reflux = 1;
int CNS::refine_max_dengrad_lev = -1;
Real CNS::refine_dengrad = 1.0e10;

bool CNS::do_visc = true; // diffusion is on by default
bool CNS::use_const_visc = false; // diffusion does not use constant viscosity by default

Real CNS::gravity = 0.0;

CNS::CNS ()
Expand Down Expand Up @@ -98,6 +101,9 @@ CNS::initData ()
cns_initdata(i, j, k, sfab, geomdata, *lparm, *lprobparm);
});
}

// Compute the initial temperature (will override what was set in initdata)
computeTemp(S_new,0);
}

void
Expand Down Expand Up @@ -349,12 +355,37 @@ CNS::read_params ()

pp.query("do_reflux", do_reflux);

pp.query("do_visc", do_visc);

if (do_visc)
{
pp.query("use_const_visc",use_const_visc);
if (use_const_visc)
{
pp.get("const_visc_mu",h_parm->const_visc_mu);
pp.get("const_visc_ki",h_parm->const_visc_ki);
pp.get("const_lambda" ,h_parm->const_lambda);
}
} else {
use_const_visc = true;
h_parm->const_visc_mu = 0.0;
h_parm->const_visc_ki = 0.0;
h_parm->const_lambda = 0.0;
}

pp.query("refine_max_dengrad_lev", refine_max_dengrad_lev);
pp.query("refine_dengrad", refine_dengrad);

pp.query("gravity", gravity);

pp.query("eos_gamma", h_parm->eos_gamma);
pp.query("eos_mu" , h_parm->eos_mu);

pp.query("eos_gamma", h_parm->eos_gamma);
pp.query("eos_mu" , h_parm->eos_mu);
pp.query("Pr" , h_parm->Pr);
pp.query("C_S" , h_parm->C_S);
pp.query("T_S" , h_parm->T_S);

h_parm->Initialize();
amrex::Gpu::copy(amrex::Gpu::hostToDevice, h_parm, h_parm+1, d_parm);
Expand Down
64 changes: 63 additions & 1 deletion Tests/GPU/CNS/Source/CNS_advance.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include "CNS.H"
#include "CNS_hydro_K.H"
#include "CNS_diffusion_K.H"
#include "CNS_K.H"

using namespace amrex;
Expand Down Expand Up @@ -68,6 +69,7 @@ CNS::compute_dSdt (const MultiFab& S, MultiFab& dSdt, Real dt,
const int neqns = 5;
const int ncons = 7;
const int nprim = 8;
const int ncoef = 3;

Array<MultiFab,AMREX_SPACEDIM> fluxes;
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
Expand All @@ -77,7 +79,7 @@ CNS::compute_dSdt (const MultiFab& S, MultiFab& dSdt, Real dt,

Parm const* lparm = d_parm;

FArrayBox qtmp, slopetmp;
FArrayBox qtmp, slopetmp, diff_coeff;
for (MFIter mfi(S); mfi.isValid(); ++mfi)
{
const Box& bx = mfi.tilebox();
Expand All @@ -91,14 +93,40 @@ CNS::compute_dSdt (const MultiFab& S, MultiFab& dSdt, Real dt,
const Box& bxg2 = amrex::grow(bx,2);
qtmp.resize(bxg2, nprim);
Elixir qeli = qtmp.elixir();
Elixir dcoeff_eli;
auto const& q = qtmp.array();

if (do_visc)
{
diff_coeff.resize(bxg2, ncoef);
dcoeff_eli = diff_coeff.elixir();
}

amrex::ParallelFor(bxg2,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
cns_ctoprim(i, j, k, sfab, q, *lparm);
});

if (do_visc)
{
auto const& coefs = diff_coeff.array();
if(use_const_visc == 1 ) {
amrex::ParallelFor(bxg2,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
cns_constcoef(i, j, k, q, coefs, *lparm);
});
} else {
amrex::ParallelFor(bxg2,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
cns_diffcoef(i, j, k, q, coefs, *lparm);
});
}
}


const Box& bxg1 = amrex::grow(bx,1);
slopetmp.resize(bxg1,neqns);
Elixir slopeeli = slopetmp.elixir();
Expand All @@ -120,6 +148,16 @@ CNS::compute_dSdt (const MultiFab& S, MultiFab& dSdt, Real dt,
for (int n = neqns; n < ncons; ++n) fxfab(i,j,k,n) = Real(0.0);
});

if (do_visc)
{
auto const& coefs = diff_coeff.array();
amrex::ParallelFor(xflxbx,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
cns_diff_x(i, j, k, q, coefs, dxinv, fxfab, *lparm);
});
}

// y-direction
cdir = 1;
const Box& yslpbx = amrex::grow(bx, cdir, 1);
Expand All @@ -136,6 +174,16 @@ CNS::compute_dSdt (const MultiFab& S, MultiFab& dSdt, Real dt,
for (int n = neqns; n < ncons; ++n) fyfab(i,j,k,n) = Real(0.0);
});

if (do_visc)
{
auto const& coefs = diff_coeff.array();
amrex::ParallelFor(yflxbx,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
cns_diff_y(i, j, k, q, coefs, dxinv, fyfab, *lparm);
});
}

// z-direction
cdir = 2;
const Box& zslpbx = amrex::grow(bx, cdir, 1);
Expand All @@ -152,10 +200,24 @@ CNS::compute_dSdt (const MultiFab& S, MultiFab& dSdt, Real dt,
for (int n = neqns; n < ncons; ++n) fzfab(i,j,k,n) = Real(0.0);
});

if (do_visc)
{
auto const& coefs = diff_coeff.array();
amrex::ParallelFor(zflxbx,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
cns_diff_z(i, j, k, q, coefs, dxinv, fzfab, *lparm);
});
}

// don't have to do this, but we could
qeli.clear(); // don't need them anymore
slopeeli.clear();

if (do_visc) {
dcoeff_eli.clear();
}

amrex::ParallelFor(bx, ncons,
[=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
{
Expand Down
4 changes: 4 additions & 0 deletions Tests/GPU/CNS/Source/CNS_index_macros.H
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
#define QTEMP 7
#define NPRIM 8

#define CETA 0
#define CXI 1
#define CLAM 2

#endif
4 changes: 4 additions & 0 deletions Tests/GPU/CNS/Source/CNS_parm.H
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ struct Parm
amrex::Real smallr = 1.e-19;
amrex::Real smallp = 1.e-10;

amrex::Real const_visc_mu = -1.0;
amrex::Real const_visc_ki = -1.0;
amrex::Real const_lambda = -1.0;

void Initialize ();
};

Expand Down
Loading

0 comments on commit ee8facf

Please sign in to comment.