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

Qmoist ptr #1337

Merged
merged 3 commits into from
Dec 11, 2023
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
2 changes: 1 addition & 1 deletion Source/ERF.H
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ private:
amrex::Vector<amrex::MultiFab> rW_new;

Microphysics micro;
amrex::Vector<amrex::MultiFab> qmoist; // This has 6 components: qv, qc, qi, qr, qs, qg
amrex::Vector<std::unique_ptr<amrex::MultiFab>> qmoist; // This has up to 6 components: qv, qc, qi, qr, qs, qg

#if defined(ERF_USE_RRTMGP)
Radiation rad;
Expand Down
12 changes: 6 additions & 6 deletions Source/ERF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ ERF::InitData ()
if (solverChoice.moisture_type != MoistureType::None)
{
for (int lev = 0; lev <= finest_level; lev++) {
FillPatchMoistVars(lev, qmoist[lev]);
FillPatchMoistVars(lev, *(qmoist[lev]));
}
}
}
Expand Down Expand Up @@ -587,9 +587,9 @@ ERF::InitData ()
{
// If not restarting we need to fill qmoist given qt and qp.
if (restart_chkfile.empty()) {
micro.Init(vars_new[lev][Vars::cons], qmoist[lev],
micro.Init(vars_new[lev][Vars::cons], *(qmoist[lev]),
grids[lev], Geom(lev), 0.0); // dummy value, not needed just to diagnose
micro.Update(vars_new[lev][Vars::cons], qmoist[lev]);
micro.Update(vars_new[lev][Vars::cons], *(qmoist[lev]));
}
}
}
Expand Down Expand Up @@ -856,6 +856,8 @@ ERF::init_only (int lev, Real time)
lev_new[Vars::yvel].setVal(0.0); lev_old[Vars::yvel].setVal(0.0);
lev_new[Vars::zvel].setVal(0.0); lev_old[Vars::zvel].setVal(0.0);

qmoist[lev]->setVal(0.);

// Initialize background flow (optional)
if (init_type == "input_sounding") {
// The base state is initialized by integrating vertically through the
Expand Down Expand Up @@ -889,8 +891,6 @@ ERF::init_only (int lev, Real time)
init_from_hse(lev);
}

qmoist[lev].setVal(0.);

// Add problem-specific flow features
//
// Notes:
Expand Down Expand Up @@ -1172,7 +1172,7 @@ ERF::MakeHorizontalAverages ()

if (use_moisture)
{
MultiFab qv(qmoist[lev], make_alias, 0, 1);
MultiFab qv(*(qmoist[lev]), make_alias, 0, 1);

for (MFIter mfi(mf); mfi.isValid(); ++mfi) {
const Box& bx = mfi.validbox();
Expand Down
12 changes: 9 additions & 3 deletions Source/ERF_make_new_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void ERF::MakeNewLevelFromScratch (int lev, Real time, const BoxArray& ba,
//********************************************************************************************
// Microphysics
// *******************************************************************************************
qmoist[lev].define(ba, dm, 6, ngrow_state); // qv, qc, qi, qr, qs, qg
int q_size = micro.Get_Qmoist_Size();
qmoist[lev] = std::make_unique<MultiFab>(ba, dm, q_size, ngrow_state); // qv, qc, qi, qr, qs, qg

// ********************************************************************************************
// Build the data structures for calculating diffusive/turbulent terms
Expand Down Expand Up @@ -194,7 +195,8 @@ ERF::MakeNewLevelFromCoarse (int lev, Real time, const BoxArray& ba,
// Microphysics
// *******************************************************************************************
int ngrow_state = ComputeGhostCells(solverChoice.advChoice, solverChoice.use_NumDiff) + 1;
qmoist[lev].define(ba, dm, 6, ngrow_state); // qv, qc, qi, qr, qs, qg
int q_size = micro.Get_Qmoist_Size();
qmoist[lev] = std::make_unique<MultiFab>(ba, dm, q_size, ngrow_state);

init_stuff(lev, ba, dm);

Expand Down Expand Up @@ -296,7 +298,8 @@ ERF::RemakeLevel (int lev, Real time, const BoxArray& ba, const DistributionMapp
//********************************************************************************************
// Microphysics
// *******************************************************************************************
qmoist[lev].define(ba, dm, 6, ngrow_state); // qv, qc, qi, qr, qs, qg
int q_size = micro.Get_Qmoist_Size();
qmoist[lev]->define(ba, dm, q_size, ngrow_state); // qv, qc, qi, qr, qs, qg

init_stuff(lev,ba,dm);

Expand Down Expand Up @@ -544,6 +547,9 @@ ERF::ClearLevel (int lev)
rW_new[lev].clear();
rW_old[lev].clear();

// Clears the qmoist memory
qmoist[lev].reset();

// Clears the integrator memory
mri_integrator_mem[lev].reset();
physbcs[lev].reset();
Expand Down
14 changes: 7 additions & 7 deletions Source/IO/Checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ ERF::WriteCheckpointFile () const
IntVect ng;
if (solverChoice.moisture_type != MoistureType::None) {
// We must read and write qmoist with ghost cells because we don't directly impose BCs on these vars
ng = qmoist[lev].nGrowVect();
MultiFab moist_vars(grids[lev],dmap[lev],qmoist[lev].nComp(),ng);
MultiFab::Copy(moist_vars,qmoist[lev],0,0,qmoist[lev].nComp(),ng);
ng = qmoist[lev]->nGrowVect();
MultiFab moist_vars(grids[lev],dmap[lev],qmoist[lev]->nComp(),ng);
MultiFab::Copy(moist_vars,*(qmoist[lev]),0,0,qmoist[lev]->nComp(),ng);
VisMF::Write(moist_vars, amrex::MultiFabFileFullPrefix(lev, checkpointname, "Level_", "MoistVars"));
}

Expand Down Expand Up @@ -346,12 +346,12 @@ ERF::ReadCheckpointFile ()

IntVect ng;
if (solverChoice.moisture_type == MoistureType::None) {
qmoist[lev].setVal(0.0);
qmoist[lev]->setVal(0.0);
} else {
ng = qmoist[lev].nGrowVect();
MultiFab moist_vars(grids[lev],dmap[lev],qmoist[lev].nComp(),ng);
ng = qmoist[lev]->nGrowVect();
MultiFab moist_vars(grids[lev],dmap[lev],qmoist[lev]->nComp(),ng);
VisMF::Read(moist_vars, amrex::MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "MoistVars"));
MultiFab::Copy(qmoist[lev],moist_vars,0,0,qmoist[lev].nComp(),ng);
MultiFab::Copy(*(qmoist[lev]),moist_vars,0,0,qmoist[lev]->nComp(),ng);
}

// Note that we read the ghost cells of the base state (unlike above)
Expand Down
2 changes: 1 addition & 1 deletion Source/IO/ERF_Write1DProfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ ERF::derive_diag_profiles(Gpu::HostVector<Real>& h_avg_u , Gpu::HostVector<Rea

if (use_moisture)
{
MultiFab qv(qmoist[lev], make_alias, 0, 1);
MultiFab qv(*(qmoist[lev]), make_alias, 0, 1);

for ( MFIter mfi(mf_cons,TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
Expand Down
18 changes: 10 additions & 8 deletions Source/IO/Plotfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ ERF::WritePlotFile (int which, Vector<std::string> plot_var_names)
const Box& bx = mfi.tilebox();
const Array4<Real >& derdat = mf[lev].array(mfi);
const Array4<Real const>& S_arr = vars_new[lev][Vars::cons].const_array(mfi);
const Array4<Real const>& qv_arr = qmoist[0].const_array(mfi);
const Array4<Real const>& qv_arr = qmoist[0]->const_array(mfi);

ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
{
Expand All @@ -227,7 +227,7 @@ ERF::WritePlotFile (int which, Vector<std::string> plot_var_names)
const Array4<Real>& derdat = mf[lev].array(mfi);
const Array4<Real const>& p0_arr = p_hse.const_array(mfi);
const Array4<Real const>& S_arr = vars_new[lev][Vars::cons].const_array(mfi);
const Array4<Real const> & qv_arr = qmoist[0].const_array(mfi);
const Array4<Real const> & qv_arr = qmoist[0]->const_array(mfi);

ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
{
Expand Down Expand Up @@ -593,12 +593,14 @@ ERF::WritePlotFile (int which, Vector<std::string> plot_var_names)
mf_comp ++;
}

MultiFab qv_mf(qmoist[lev], make_alias, 0, 1);
MultiFab qc_mf(qmoist[lev], make_alias, 1, 1);
MultiFab qi_mf(qmoist[lev], make_alias, 2, 1);
MultiFab qr_mf(qmoist[lev], make_alias, 3, 1);
MultiFab qs_mf(qmoist[lev], make_alias, 4, 1);
MultiFab qg_mf(qmoist[lev], make_alias, 5, 1);
// TODO: Protect against accessing non-existent data
int q_size = micro.Get_Qmoist_Size();
MultiFab qv_mf(*(qmoist[lev]), make_alias, 0, 1);
MultiFab qc_mf(*(qmoist[lev]), make_alias, 1, 1);
MultiFab qi_mf(*(qmoist[lev]), make_alias, 2, 1);
MultiFab qr_mf(*(qmoist[lev]), make_alias, 3, 1);
MultiFab qs_mf(*(qmoist[lev]), make_alias, 4, 1);
MultiFab qg_mf(*(qmoist[lev]), make_alias, 5, 1);

if (containerHasElement(plot_var_names, "qt"))
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Initialization/ERF_init_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void
ERF::init_custom (int lev)
{
auto& lev_new = vars_new[lev];
auto& qmoist_new = qmoist[lev];
auto& qmoist_new = *(qmoist[lev]);

MultiFab r_hse(base_state[lev], make_alias, 0, 1); // r_0 is first component
MultiFab p_hse(base_state[lev], make_alias, 1, 1); // p_0 is second component
Expand All @@ -42,7 +42,7 @@ ERF::init_custom (int lev)
yvel_pert.setVal(0.);
zvel_pert.setVal(0.);

MultiFab qmoist_pert(qmoist[lev].boxArray(), qmoist[lev].DistributionMap(), 3, qmoist[lev].nGrow());
MultiFab qmoist_pert(qmoist[lev]->boxArray(), qmoist[lev]->DistributionMap(), 3, qmoist[lev]->nGrow());
qmoist_pert.setVal(0.);

MultiFab qv_pert(qmoist_pert, amrex::make_alias, 0, 1);
Expand Down
2 changes: 1 addition & 1 deletion Source/Initialization/InputSoundingData.H
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public:
iss_z >> z >> theta >> qv >> U >> V;
if (z == 0) {
AMREX_ALWAYS_ASSERT(theta == theta_inp_sound_tmp[0]);
AMREX_ALWAYS_ASSERT(qv == qv_inp_sound_tmp[0]);
AMREX_ALWAYS_ASSERT(qv*0.001 == qv_inp_sound_tmp[0]);
U_inp_sound_tmp[0] = U;
V_inp_sound_tmp[0] = V;
} else {
Expand Down
Loading
Loading