Skip to content

Commit

Permalink
move set_2darrays to Init, and adjust prob for seamount
Browse files Browse the repository at this point in the history
  • Loading branch information
hklion committed Sep 22, 2023
1 parent 40876f7 commit c60667a
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 128 deletions.
2 changes: 0 additions & 2 deletions Exec/Seamount/prob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ init_custom_prob(
Array4<Real > const& x_vel,
Array4<Real > const& y_vel,
Array4<Real > const& z_vel,
Array4<Real > const& /*r_hse*/,
Array4<Real > const& /*p_hse*/,
Array4<Real const> const& /*z_w*/,
Array4<Real const> const& z_r,
Array4<Real const> const& Hz,
Expand Down
126 changes: 126 additions & 0 deletions Source/ROMSX_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,129 @@ ROMSX::init_custom(int lev)
set_2darrays(lev);

}

void
ROMSX::set_2darrays (int lev)
{
auto& lev_new = vars_new[lev];
auto& lev_old = vars_old[lev];
std::unique_ptr<MultiFab>& mf_x_r = vec_x_r[lev];
std::unique_ptr<MultiFab>& mf_y_r = vec_y_r[lev];
auto N = Geom(lev).Domain().size()[2]-1; // Number of vertical "levs" aka, NZ

for ( MFIter mfi(*(mf_x_r), TilingIfNotGPU()); mfi.isValid(); ++mfi )
{

Array4<Real> const& x_r = (mf_x_r)->array(mfi);
Array4<Real> const& y_r = (mf_y_r)->array(mfi);
const Box& bx = mfi.growntilebox();
const auto & geomdata = Geom(lev).data();
int ncomp = 1;
Gpu::synchronize();
amrex::ParallelFor(amrex::makeSlab(bx,2,0), ncomp,
[=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
{
const auto prob_lo = geomdata.ProbLo();
const auto dx = geomdata.CellSize();

x_r(i,j,0) = prob_lo[0] + (i + 0.5) * dx[0];
y_r(i,j,0) = prob_lo[1] + (j + 0.5) * dx[1];
// const Real z = prob_lo[2] + (k + 0.5) * dx[2];

});
}
// x_r[lev]->FillBoundary(geom[lev].periodicity());
// y_r[lev]->FillBoundary(geom[lev].periodicity());

MultiFab& U_old = vars_new[lev][Vars::xvel];
MultiFab& V_old = vars_new[lev][Vars::yvel];
MultiFab& W_old = vars_new[lev][Vars::zvel];
std::unique_ptr<MultiFab>& mf_ubar = vec_ubar[lev];
std::unique_ptr<MultiFab>& mf_vbar = vec_vbar[lev];
std::unique_ptr<MultiFab>& mf_Hz = vec_Hz[lev];
int nstp = 0;
int kstp = 0;
int knew = 0;
int ncomp = 1;
for ( MFIter mfi(U_old, TilingIfNotGPU()); mfi.isValid(); ++mfi )
{
Array4<Real> const& ubar = (mf_ubar)->array(mfi);
Array4<Real> const& vbar = (mf_vbar)->array(mfi);
Array4<Real> const& Hz = (mf_Hz)->array(mfi);
Array4<Real> const& u = (U_old).array(mfi);
Array4<Real> const& v = (V_old).array(mfi);

Box bx = mfi.tilebox();
//copy the tilebox
Box gbx1 = bx;
Box gbx11 = bx;
Box gbx2 = bx;
//make only gbx be grown to match multifabs
gbx2.grow(IntVect(NGROW,NGROW,0));
gbx1.grow(IntVect(NGROW-1,NGROW-1,0));
gbx11.grow(IntVect(NGROW-1,NGROW-1,NGROW-1));
Box gbx1D = gbx1;
gbx1D.makeSlab(2,0);

FArrayBox fab_DC(gbx11,1,amrex::The_Async_Arena());
FArrayBox fab_CF(gbx11,1,amrex::The_Async_Arena());
auto DC=fab_DC.array();
auto CF=fab_CF.array();

//fab_DC.setVal(0.0);
//fab_CF.setVal(0.0);
amrex::ParallelFor(gbx11, ncomp,
[=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
{
DC(i,j,k)=0.0;
CF(i,j,k)=0.0;
});
Gpu::streamSynchronize();
amrex::ParallelFor(gbx1D, ncomp,
[=] AMREX_GPU_DEVICE (int i, int j, int , int )
{
for(int k=0; k<=N; k++) {
DC(i,j,k)=0.5*(Hz(i,j,k)+Hz(i-1,j,k));
DC(i,j,-1)=DC(i,j,-1)+DC(i,j,k);
CF(i,j,-1)=CF(i,j,-1)+DC(i,j,k)*u(i,j,k,nstp);
}
});
amrex::ParallelFor(amrex::makeSlab(gbx1,2,0),
[=] AMREX_GPU_DEVICE (int i, int j, int k)
{
Real cff1=1.0/DC(i,j,-1);
Real cff2=CF(i,j,-1)*cff1;
ubar(i,j,0,kstp)=cff2;
ubar(i,j,0,knew)=cff2;
});

//fab_DC.setVal(0.0);
//fab_CF.setVal(0.0);
amrex::ParallelFor(gbx11, ncomp,
[=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
{
DC(i,j,k)=0.0;
CF(i,j,k)=0.0;
});
Gpu::streamSynchronize();
amrex::ParallelFor(gbx1D,
[=] AMREX_GPU_DEVICE (int i, int j, int )
{
for(int k=0; k<=N; k++) {
DC(i,j,k)=0.5*(Hz(i,j,k)+Hz(i,j-1,k));
DC(i,j,-1)=DC(i,j,-1)+DC(i,j,k);
CF(i,j,-1)=CF(i,j,-1)+DC(i,j,k)*v(i,j,k,nstp);
}
});
amrex::ParallelFor(amrex::makeSlab(gbx1,2,0),
[=] AMREX_GPU_DEVICE (int i, int j, int k)
{
Real cff1=1.0/DC(i,j,-1);
Real cff2=CF(i,j,-1)*cff1;
vbar(i,j,0,kstp)=cff2;
vbar(i,j,0,knew)=cff2;
});
}
vec_ubar[lev]->FillBoundary(geom[lev].periodicity());
vec_vbar[lev]->FillBoundary(geom[lev].periodicity());
}
126 changes: 0 additions & 126 deletions Source/Utils/DepthStretchTransform.H
Original file line number Diff line number Diff line change
Expand Up @@ -8,132 +8,6 @@

using namespace amrex;

void
ROMSX::set_2darrays (int lev)
{
auto& lev_new = vars_new[lev];
auto& lev_old = vars_old[lev];
std::unique_ptr<MultiFab>& mf_x_r = vec_x_r[lev];
std::unique_ptr<MultiFab>& mf_y_r = vec_y_r[lev];
auto N = Geom(lev).Domain().size()[2]-1; // Number of vertical "levs" aka, NZ

for ( MFIter mfi(*(mf_x_r), TilingIfNotGPU()); mfi.isValid(); ++mfi )
{

Array4<Real> const& x_r = (mf_x_r)->array(mfi);
Array4<Real> const& y_r = (mf_y_r)->array(mfi);
const Box& bx = mfi.growntilebox();
const auto & geomdata = Geom(lev).data();
int ncomp = 1;
Gpu::synchronize();
amrex::ParallelFor(amrex::makeSlab(bx,2,0), ncomp,
[=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
{
const auto prob_lo = geomdata.ProbLo();
const auto dx = geomdata.CellSize();

x_r(i,j,0) = prob_lo[0] + (i + 0.5) * dx[0];
y_r(i,j,0) = prob_lo[1] + (j + 0.5) * dx[1];
// const Real z = prob_lo[2] + (k + 0.5) * dx[2];

});
}
// x_r[lev]->FillBoundary(geom[lev].periodicity());
// y_r[lev]->FillBoundary(geom[lev].periodicity());

MultiFab& U_old = vars_new[lev][Vars::xvel];
MultiFab& V_old = vars_new[lev][Vars::yvel];
MultiFab& W_old = vars_new[lev][Vars::zvel];
std::unique_ptr<MultiFab>& mf_ubar = vec_ubar[lev];
std::unique_ptr<MultiFab>& mf_vbar = vec_vbar[lev];
std::unique_ptr<MultiFab>& mf_Hz = vec_Hz[lev];
int nstp = 0;
int kstp = 0;
int knew = 0;
int ncomp = 1;
for ( MFIter mfi(U_old, TilingIfNotGPU()); mfi.isValid(); ++mfi )
{
Array4<Real> const& ubar = (mf_ubar)->array(mfi);
Array4<Real> const& vbar = (mf_vbar)->array(mfi);
Array4<Real> const& Hz = (mf_Hz)->array(mfi);
Array4<Real> const& u = (U_old).array(mfi);
Array4<Real> const& v = (V_old).array(mfi);

Box bx = mfi.tilebox();
//copy the tilebox
Box gbx1 = bx;
Box gbx11 = bx;
Box gbx2 = bx;
//make only gbx be grown to match multifabs
gbx2.grow(IntVect(NGROW,NGROW,0));
gbx1.grow(IntVect(NGROW-1,NGROW-1,0));
gbx11.grow(IntVect(NGROW-1,NGROW-1,NGROW-1));
Box gbx1D = gbx1;
gbx1D.makeSlab(2,0);

FArrayBox fab_DC(gbx11,1,amrex::The_Async_Arena());
FArrayBox fab_CF(gbx11,1,amrex::The_Async_Arena());
auto DC=fab_DC.array();
auto CF=fab_CF.array();

//fab_DC.setVal(0.0);
//fab_CF.setVal(0.0);
amrex::ParallelFor(gbx11, ncomp,
[=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
{
DC(i,j,k)=0.0;
CF(i,j,k)=0.0;
});
Gpu::streamSynchronize();
amrex::ParallelFor(gbx1D, ncomp,
[=] AMREX_GPU_DEVICE (int i, int j, int , int )
{
for(int k=0; k<=N; k++) {
DC(i,j,k)=0.5*(Hz(i,j,k)+Hz(i-1,j,k));
DC(i,j,-1)=DC(i,j,-1)+DC(i,j,k);
CF(i,j,-1)=CF(i,j,-1)+DC(i,j,k)*u(i,j,k,nstp);
}
});
amrex::ParallelFor(amrex::makeSlab(gbx1,2,0),
[=] AMREX_GPU_DEVICE (int i, int j, int k)
{
Real cff1=1.0/DC(i,j,-1);
Real cff2=CF(i,j,-1)*cff1;
ubar(i,j,0,kstp)=cff2;
ubar(i,j,0,knew)=cff2;
});

//fab_DC.setVal(0.0);
//fab_CF.setVal(0.0);
amrex::ParallelFor(gbx11, ncomp,
[=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
{
DC(i,j,k)=0.0;
CF(i,j,k)=0.0;
});
Gpu::streamSynchronize();
amrex::ParallelFor(gbx1D,
[=] AMREX_GPU_DEVICE (int i, int j, int )
{
for(int k=0; k<=N; k++) {
DC(i,j,k)=0.5*(Hz(i,j,k)+Hz(i,j-1,k));
DC(i,j,-1)=DC(i,j,-1)+DC(i,j,k);
CF(i,j,-1)=CF(i,j,-1)+DC(i,j,k)*v(i,j,k,nstp);
}
});
amrex::ParallelFor(amrex::makeSlab(gbx1,2,0),
[=] AMREX_GPU_DEVICE (int i, int j, int k)
{
Real cff1=1.0/DC(i,j,-1);
Real cff2=CF(i,j,-1)*cff1;
vbar(i,j,0,kstp)=cff2;
vbar(i,j,0,knew)=cff2;
});
}
vec_ubar[lev]->FillBoundary(geom[lev].periodicity());
vec_vbar[lev]->FillBoundary(geom[lev].periodicity());
}

void
ROMSX::stretch_transform (int lev)
{
Expand Down

0 comments on commit c60667a

Please sign in to comment.