From 0e6e179bd7babb0e0ea01f0dbcb3bf18ee68135d Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sat, 28 Jun 2025 22:58:28 +0200 Subject: [PATCH 01/87] first fusing --- Source/PeleLMeX_Advection.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 15dc26bc8..8e6f82063 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -238,6 +238,22 @@ PeleLM::updateVelocity(std::unique_ptr& advData) // Compute provisional new velocity // velForce holds: 1/\rho^{n+1/2} [(gravity+...)^{n+1/2} - \nabla pi^{n} + // 0.5 * divTau^{n}] + auto state_old_ma = ldataOld_p->state.const_arrays(); + auto adv_aofs_ma = advData->AofS[lev].const_arrays(); + auto force_ma = velForces[lev].const_arrays(); + auto state_new_ma = ldataNew_p->state.arrays(); + const Real dt_loc = m_dt; + + amrex::ParallelFor(ldataOld_p->state, [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + state_new_ma[box_no](i, j, k, VELX+n) = + state_old_ma[box_no](i, j, k, VELX+n) + + dt_loc * (adv_aofs_ma[box_no](i, j, k, VELX+n) + force_ma[box_no](i, j, k, n)); + } + }); + + + /* #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif @@ -258,6 +274,7 @@ PeleLM::updateVelocity(std::unique_ptr& advData) dt_loc * (vel_aofs(i, j, k, n) + force(i, j, k, n)); }); } + */ } } From 756fdd984e4b108711bf769c6e8387d2d737b866 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 29 Jun 2025 00:28:42 +0200 Subject: [PATCH 02/87] advection final --- Source/PeleLMeX_Advection.cpp | 161 +++++++++++++--------------------- 1 file changed, 61 insertions(+), 100 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 8e6f82063..8ba404ac2 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -22,7 +22,7 @@ PeleLM::computeVelocityAdvTerm(std::unique_ptr& advData) velForces[lev].define( grids[lev], dmap[lev], AMREX_SPACEDIM, nGrow_force, MFInfo(), Factory(lev)); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim].define( amrex::convert(grids[lev], IntVect::TheDimensionVector(idim)), dmap[lev], AMREX_SPACEDIM, 0, MFInfo(), Factory(lev)); @@ -156,7 +156,7 @@ PeleLM::computeVelocityAdvTerm(std::unique_ptr& advData) if (m_incompressible != 0) { divu.setVal(0.0); } else { - Real time = getTime(lev, AmrOldTime); + const Real time = getTime(lev, AmrOldTime); fillpatch_divu(lev, time, divu, m_nGrowdivu); } @@ -165,7 +165,7 @@ PeleLM::computeVelocityAdvTerm(std::unique_ptr& advData) auto* ldata_p = getLevelDataPtr(lev, AmrOldTime); //---------------------------------------------------------------- // Use a temporary MF to hold divergence before redistribution - int nGrow_divT = 3; + constexpr int nGrow_divT = 3; MultiFab divTmp( grids[lev], dmap[lev], AMREX_SPACEDIM, nGrow_divT, MFInfo(), EBFactory(lev)); @@ -212,7 +212,7 @@ PeleLM::updateVelocity(std::unique_ptr& advData) grids[lev], dmap[lev], AMREX_SPACEDIM, 0, MFInfo(), Factory(lev)); } constexpr int use_density = 0; - const Real CrankNicholsonFactor = 0.5; + constexpr Real CrankNicholsonFactor = 0.5; computeDivTau( AmrOldTime, GetVecOfPtrs(divtau), use_density, CrankNicholsonFactor); @@ -242,39 +242,13 @@ PeleLM::updateVelocity(std::unique_ptr& advData) auto adv_aofs_ma = advData->AofS[lev].const_arrays(); auto force_ma = velForces[lev].const_arrays(); auto state_new_ma = ldataNew_p->state.arrays(); - const Real dt_loc = m_dt; - - amrex::ParallelFor(ldataOld_p->state, [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::ParallelFor(ldataOld_p->state, [state_old_ma, adv_aofs_ma, force_ma, state_new_ma,dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { for (int n = 0; n < AMREX_SPACEDIM; ++n) { state_new_ma[box_no](i, j, k, VELX+n) = state_old_ma[box_no](i, j, k, VELX+n) + dt_loc * (adv_aofs_ma[box_no](i, j, k, VELX+n) + force_ma[box_no](i, j, k, n)); } - }); - - - /* -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldataOld_p->state, TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - - Box const& bx = mfi.tilebox(); - auto const& vel_old = ldataOld_p->state.const_array(mfi, VELX); - auto const& vel_aofs = advData->AofS[lev].const_array(mfi, VELX); - auto const& force = velForces[lev].const_array(mfi); - auto const& vel_new = ldataNew_p->state.array(mfi, VELX); - Real dt_loc = m_dt; - amrex::ParallelFor( - bx, AMREX_SPACEDIM, - [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - vel_new(i, j, k, n) = - vel_old(i, j, k, n) + - dt_loc * (vel_aofs(i, j, k, n) + force(i, j, k, n)); - }); - } - */ + }); } } @@ -292,41 +266,33 @@ PeleLM::getScalarAdvForce( auto* ldataR_p = getLevelDataReactPtr(lev); auto const* leosparm = eos_parms.device_parm(); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(advData->Forcing[lev], TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const Box& bx = mfi.tilebox(); - FArrayBox DummyFab(bx, 1); - auto const& rho = ldata_p->state.const_array(mfi, DENSITY); - auto const& rhoY = ldata_p->state.const_array(mfi, FIRSTSPEC); - auto const& T = ldata_p->state.const_array(mfi, TEMP); - auto const& dn = diffData->Dn[lev].const_array(mfi, 0); - auto const& ddn = diffData->Dn[lev].const_array(mfi, NUM_SPECIES + 1); - auto const& r = ldataR_p->I_R.const_array(mfi); - auto const& extRhoY = m_extSource[lev]->const_array(mfi, FIRSTSPEC); - auto const& extRhoH = m_extSource[lev]->const_array(mfi, RHOH); - auto const& fY = advData->Forcing[lev].array(mfi, 0); - auto const& fT = advData->Forcing[lev].array(mfi, NUM_SPECIES); - auto const& fAux = (m_nAux > 0) ? advData->Forcing_aux[lev].array(mfi, 0) - : DummyFab.array(); - auto const& dn_aux = (m_nAux > 0) - ? diffData->Dn_aux[lev].const_array(mfi, 0) - : DummyFab.const_array(); - amrex::ParallelFor( - bx, [rho, rhoY, T, dn, ddn, r, fY, fT, fAux, extRhoY, extRhoH, - aux_diffuse_d, dn_aux, nAux = m_nAux, dp0dt = m_dp0dt, - is_closed_ch = m_closed_chamber, do_react = m_do_react, - leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - buildAdvectionForcing( - i, j, k, rho, rhoY, T, dn, ddn, r, extRhoY, extRhoH, dp0dt, - is_closed_ch, do_react, fY, fT, fAux, dn_aux, aux_diffuse_d, nAux, - leosparm); - }); - } + auto state_ma = ldata_p->state.const_arrays(); + auto diffData_ma = diffData->Dn[lev].const_arrays(); + auto diffData_aux_ma = diffData->Dn_aux[lev].const_arrays(); + auto r_ma = ldataR_p->I_R.const_arrays(); + auto ext_ma = m_extSource[lev]->arrays(); + auto adv_ma = advData->Forcing[lev].arrays(); + auto adv_aux_ma = advData->Forcing_aux[lev].arrays(); + + amrex::ParallelFor(advData->Forcing[lev], [state_ma, diffData_ma, diffData_aux_ma,r_ma,ext_ma, adv_ma, adv_aux_ma,aux_diffuse_d,leosparm,nAux = m_nAux, dp0dt = m_dp0dt, + is_closed_ch = m_closed_chamber, do_react = m_do_react] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rho(state_ma[box_no],DENSITY); + Array4 rhoY(state_ma[box_no],FIRSTSPEC); + Array4 T(state_ma[box_no],TEMP); + Array4 dn(diffData_ma[box_no],0); + Array4 ddn(diffData_ma[box_no],NUM_SPECIES+1); + Array4 dn_aux(diffData_aux_ma[box_no],0); + Array4 r(r_ma[box_no],0); + Array4 extRhoY(ext_ma[box_no],FIRSTSPEC); + Array4 extRhoH(ext_ma[box_no],RHOH); + Array4 fY(adv_ma[box_no],0); + Array4 fT(adv_ma[box_no],NUM_SPECIES); + Array4 fAux(adv_aux_ma[box_no],0); + buildAdvectionForcing(i, j, k, rho, rhoY, T, dn, ddn, r, extRhoY, extRhoH, dp0dt, + is_closed_ch, do_react, fY, fT, fAux, dn_aux, aux_diffuse_d, nAux, + leosparm); + }); } - // Fill forcing ghost cells if (advData->Forcing[0].nGrow() > 0) { fillpatch_forces( @@ -369,7 +335,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) Vector> fluxes(finest_level + 1); Vector> fluxes_aux(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim].define( amrex::convert(grids[lev], IntVect::TheDimensionVector(idim)), dmap[lev], NUM_SPECIES + 1, 0, MFInfo(), @@ -391,10 +357,10 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) auto* ldata_p = getLevelDataPtr(lev, AmrOldTime); // Define edge state: Density + Species + RhoH + Temp - int nGrow = 0; + constexpr int nGrow = 0; Array edgeState; Array edgeState_aux; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { edgeState[idim].define( amrex::convert(grids[lev], IntVect::TheDimensionVector(idim)), dmap[lev], NUM_SPECIES + 3, nGrow, MFInfo(), Factory(lev)); @@ -472,7 +438,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) fluxes_are_area_weighted, m_advection_type, m_Godunov_ppm_limiter); // Ions one by one - for (int n = 0; n < NUM_IONS; n++) { + for (int n = 0; n < NUM_IONS; ++n) { const int ion_idx = NUM_SPECIES - NUM_IONS + n; auto bcRecIons = fetchBCRecArray(FIRSTSPEC + ion_idx, 1); auto bcRecIons_d = convertToDeviceVector(bcRecIons); @@ -570,9 +536,9 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) fluxes_are_area_weighted, m_advection_type, m_Godunov_ppm_limiter); } // Zero out fluxes for non-advected auxiliaries - for (int n = 0; n < m_nAux; n++) { + for (int n = 0; n < m_nAux; ++n) { if (m_aux_advect[n] == 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes_aux[lev][idim].setVal(0.0, n, 1); } } @@ -592,7 +558,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) #endif // Edge states - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const Box& ebx = amrex::surroundingNodes(bx, idim); auto const& rho_ed = edgeState[idim].array(mfi, 0); auto const& rhoY_ed = edgeState[idim].array(mfi, 1); @@ -683,7 +649,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; #endif - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const Box& ebx = amrex::surroundingNodes(bx, idim); auto const& rho = edgeState[idim].const_array(mfi, 0); auto const& rhoY = edgeState[idim].const_array(mfi, 1); @@ -814,9 +780,9 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) if (m_do_extraEFdiags) { for (int lev = 0; lev <= finest_level; ++lev) { for (int n = 0; n < NUM_IONS; ++n) { - int spec_idx = NUM_SPECIES - NUM_IONS + n; + const int spec_idx = NUM_SPECIES - NUM_IONS + n; Array, AMREX_SPACEDIM> ionFlux; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { ionFlux[idim].reset( new MultiFab(fluxes[lev][idim], amrex::make_alias, spec_idx, 1)); } @@ -839,7 +805,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) if (m_incompressible != 0) { divu.setVal(0.0); } else { - Real time = getTime(lev, AmrOldTime); + const Real time = getTime(lev, AmrOldTime); fillpatch_divu(lev, time, divu, m_nGrowdivu); } @@ -962,7 +928,7 @@ PeleLM::updateDensity(std::unique_ptr& advData) void PeleLM::computePassiveAdvTerms( - std::unique_ptr& advData, int state_comp, int ncomp) + std::unique_ptr& advData, const int state_comp, const int ncomp) { //---------------------------------------------------------------- // Get the BCRecs and AdvectionTypes @@ -976,7 +942,7 @@ PeleLM::computePassiveAdvTerms( Vector> fluxes(finest_level + 1); Vector> edgeState(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim].define( amrex::convert(grids[lev], IntVect::TheDimensionVector(idim)), dmap[lev], ncomp, 0, MFInfo(), Factory(lev)); @@ -1079,7 +1045,7 @@ PeleLM::computePassiveAdvTerms( if (m_incompressible != 0) { divu.setVal(0.0); } else { - Real time = getTime(lev, AmrOldTime); + const Real time = getTime(lev, AmrOldTime); fillpatch_divu(lev, time, divu, m_nGrowdivu); } @@ -1088,7 +1054,7 @@ PeleLM::computePassiveAdvTerms( auto* ldata_p = getLevelDataPtr(lev, AmrOldTime); //---------------------------------------------------------------- // Use a temporary MF to hold divergence before redistribution - int nGrow_divTmp = 3; + constexpr int nGrow_divTmp = 3; MultiFab divTmp( grids[lev], dmap[lev], ncomp, nGrow_divTmp, MFInfo(), EBFactory(lev)); divTmp.setVal(0.0); @@ -1117,31 +1083,26 @@ PeleLM::computePassiveAdvTerms( void PeleLM::updateScalarComp( - std::unique_ptr& advData, int state_comp, int ncomp) + std::unique_ptr& advData, const int state_comp, const int ncomp) { for (int lev = 0; lev <= finest_level; ++lev) { // Get level data ptr auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldataNew_p->state, TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - Box const& bx = mfi.tilebox(); - auto const& old_arr = ldataOld_p->state.const_array(mfi, state_comp); - auto const& new_arr = ldataNew_p->state.array(mfi, state_comp); - auto const& a_of_s = advData->AofS[lev].const_array(mfi, state_comp); - auto const& ext = m_extSource[lev]->const_array(mfi, state_comp); - amrex::ParallelFor( - bx, ncomp, - [old_arr, new_arr, a_of_s, ext, - dt = m_dt] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - new_arr(i, j, k, n) = - old_arr(i, j, k, n) + dt * (a_of_s(i, j, k, n) + ext(i, j, k, n)); - }); - } + + auto state_old_ma = ldataOld_p->state.const_arrays(); + auto adv_aofs_ma = advData->AofS[lev].const_arrays(); + auto ext_ma = m_extSource[lev]->const_arrays(); + auto state_new_ma = ldataNew_p->state.arrays(); + + amrex::ParallelFor(ldataOld_p->state, [state_old_ma, adv_aofs_ma,ext_ma,state_new_ma,state_comp,ncomp,dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = state_comp; n < state_comp+ncomp; ++n) { + state_new_ma[box_no](i, j, k, n) = + state_old_ma[box_no](i, j, k, n) + + dt_loc * (adv_aofs_ma[box_no](i, j, k, n) + ext_ma[box_no](i, j, k, n)); + } + }); } averageDown(AmrNewTime, state_comp, ncomp); } From 3aaba6ba96c1b422453681e2a103ba6e7f80918f Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 29 Jun 2025 00:42:16 +0200 Subject: [PATCH 03/87] advance and main --- Source/PeleLMeX.H | 4 ++-- Source/PeleLMeX_Advance.cpp | 24 ++++++++++++------------ Source/main.cpp | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index d3a0ce97c..8b14ebb8d 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -77,7 +77,7 @@ public: void Evaluate(); // Time advance function - void Advance(int is_init); + void Advance(const int is_init); //----------------------------------------------------------------------------- // Virtual AmrCore functions @@ -1493,7 +1493,7 @@ public: void advanceSetup(); void oneSDC( - int sdcIter, + const int sdcIter, std::unique_ptr& advData, std::unique_ptr& diffData); diff --git a/Source/PeleLMeX_Advance.cpp b/Source/PeleLMeX_Advance.cpp index 8d5085205..f958a928f 100644 --- a/Source/PeleLMeX_Advance.cpp +++ b/Source/PeleLMeX_Advance.cpp @@ -6,7 +6,7 @@ using namespace amrex; void -PeleLM::Advance(int is_initIter) +PeleLM::Advance(const int is_initIter) { BL_PROFILE("PeleLMeX::Advance()"); @@ -16,7 +16,7 @@ PeleLM::Advance(int is_initIter) #endif // Start timing current time step - Real strt_time = ParallelDescriptor::second(); + const Real strt_time = ParallelDescriptor::second(); //---------------------------------------------------------------- BL_PROFILE_VAR("PeleLMeX::advance::setup", PLM_SETUP); @@ -49,7 +49,7 @@ PeleLM::Advance(int is_initIter) #endif // Update time vectors - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { m_t_old[lev] = m_cur_time; m_t_new[lev] = m_cur_time + m_dt; } @@ -73,7 +73,7 @@ PeleLM::Advance(int is_initIter) finest_level, grids, dmap, m_factory, m_incompressible, m_nAux, m_nGrowAdv, m_nGrowMAC); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { m_extSource[lev]->setVal(0.); } //---------------------------------------------------------------- @@ -88,7 +88,7 @@ PeleLM::Advance(int is_initIter) // Reset velocity flux on boundary faces if doing closed chamber if (m_closed_chamber != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_domainUmacFlux[2 * idim] = 0.0; m_domainUmacFlux[2 * idim + 1] = 0.0; } @@ -203,10 +203,10 @@ PeleLM::Advance(int is_initIter) #endif if (m_has_divu != 0) { - int is_initialization = 0; // Not here - int computeDiffusionTerm = + constexpr int is_initialization = 0; // Not here + constexpr int computeDiffusionTerm = 1; // Yes, re-evaluate the diffusion term after the last chemistry solve - int do_avgDown = 1; // Always + constexpr int do_avgDown = 1; // Always calcDivU( is_initialization, computeDiffusionTerm, do_avgDown, AmrNewTime, diffData); @@ -269,7 +269,7 @@ PeleLM::Advance(int is_initIter) void PeleLM::oneSDC( - int sdcIter, + const int sdcIter, std::unique_ptr& advData, std::unique_ptr& diffData) { @@ -302,9 +302,9 @@ PeleLM::oneSDC( calcDiffusivity(AmrNewTime); computeDifferentialDiffusionTerms(AmrNewTime, diffData); if (m_has_divu != 0) { - int is_initialization = 0; // Not here - int computeDiffusionTerm = 0; // Nope, we just did that - int do_avgDown = 1; // Always + constexpr int is_initialization = 0; // Not here + constexpr int computeDiffusionTerm = 0; // Nope, we just did that + constexpr int do_avgDown = 1; // Always calcDivU( is_initialization, computeDiffusionTerm, do_avgDown, AmrNewTime, diffData); diff --git a/Source/main.cpp b/Source/main.cpp index 7f26308c1..df4148aa8 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -14,7 +14,7 @@ main(int argc, char* argv[]) // check to see if it contains --describe if (argc >= 2) { - for (auto i = 1; i < argc; i++) { + for (auto i = 1; i < argc; ++i) { if (std::string(argv[i]) == "--describe") { writeBuildInfo(); return 0; From 9f0b64c864eec79b3307d8f9175dc99e403d99fb Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 29 Jun 2025 01:11:22 +0200 Subject: [PATCH 04/87] BC --- Source/PeleLMeX.H | 90 ++++++------ Source/PeleLMeX_BC.cpp | 316 ++++++++++++++++++++--------------------- 2 files changed, 203 insertions(+), 203 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 8b14ebb8d..436d36668 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -1064,7 +1064,7 @@ public: // FillPatch the entire class state void fillPatchState(const PeleLM::TimeStamp& a_time); - void fillPatchState(int lev, const PeleLM::TimeStamp& a_time); + void fillPatchState(const int lev, const PeleLM::TimeStamp& a_time); // FillPatch the various state components void fillPatchDensity(const PeleLM::TimeStamp& a_time); @@ -1078,86 +1078,86 @@ public: // FillPatch and return a MF std::unique_ptr - fillPatchState(int lev, amrex::Real a_time, int nGrow); + fillPatchState(const int lev,const amrex::Real a_time, const int nGrow); std::unique_ptr - fillPatchReact(int lev, amrex::Real a_time, int nGrow); + fillPatchReact(const int lev, const amrex::Real a_time, const int nGrow); // FillPatch state components void fillpatch_state( - int lev, amrex::Real a_time, amrex::MultiFab& a_state, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_state, const int nGhost); void fillpatch_density( - int lev, - amrex::Real a_time, + const int lev, + const amrex::Real a_time, amrex::MultiFab& a_density, - int rho_comp, - int nGhost); + const int rho_comp, + const int nGhost); void fillpatch_species( - int lev, - amrex::Real a_time, + const int lev, + const amrex::Real a_time, amrex::MultiFab& a_species, - int rhoY_comp, - int nGhost); + const int rhoY_comp, + const int nGhost); void fillpatch_temp( - int lev, - amrex::Real a_time, + const int lev, + const amrex::Real a_time, amrex::MultiFab& a_temp, - int temp_comp, - int nGhost); + const int temp_comp, + const int nGhost); void fillpatch_aux( - int lev, amrex::Real a_time, amrex::MultiFab& a_aux, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_aux, const int nGhost); void fillpatch_divu( - int lev, amrex::Real a_time, amrex::MultiFab& a_divu, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_divu, const int nGhost); void fillpatch_gradp( - int lev, amrex::Real a_time, amrex::MultiFab& a_gp, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_gp, const int nGhost); void fillpatch_reaction( - int lev, amrex::Real a_time, amrex::MultiFab& a_I_R, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_I_R, const int nGhost); void fillpatch_forces( - amrex::Real a_time, + const amrex::Real a_time, amrex::Vector const& a_force, - int nGrowForce); + const int nGrowForce); void fillpatch_chemFunctCall( - int lev, amrex::Real a_time, amrex::MultiFab& a_fctC, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_fctC, const int nGhost); #ifdef PELE_USE_PLASMA void fillpatch_phiV( - int lev, - amrex::Real a_time, - amrex::MultiFab& a_phiV, - int phiV_comp, - int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_phiV, + const int phiV_comp, + const int nGhost); void fillPatchExtrap( - amrex::Real a_time, - amrex::Vector const& a_MF, - int a_nGrow); + const amrex::Real a_time, + amrex::Vector const& a_MF, + const int a_nGrow); void fillPatchNLnE( - amrex::Real a_time, - amrex::Vector const& a_nE, - int a_nGrow); + const amrex::Real a_time, + amrex::Vector const& a_nE, + const int a_nGrow); void fillPatchNLphiV( - amrex::Real a_time, - amrex::Vector const& a_phiV, - int a_nGrow); + const amrex::Real a_time, + amrex::Vector const& a_phiV, + const int a_nGrow); #endif // FillCoarsePatch state components void fillcoarsepatch_state( - int lev, amrex::Real a_time, amrex::MultiFab& a_state, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_state, const int nGhost); void fillcoarsepatch_aux( - int lev, amrex::Real a_time, amrex::MultiFab& a_aux, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_aux, const int nGhost); void fillcoarsepatch_divu( - int lev, amrex::Real a_time, amrex::MultiFab& a_divu, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_divu, const int nGhost); void fillcoarsepatch_gradp( - int lev, amrex::Real a_time, amrex::MultiFab& a_gp, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_gp, const int nGhost); void fillcoarsepatch_reaction( - int lev, amrex::Real a_time, amrex::MultiFab& a_I_R, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_I_R, const int nGhost); void fillcoarsepatch_chemFunctCall( - int lev, amrex::Real a_time, amrex::MultiFab& a_fctC, int nGhost); + const int lev, const amrex::Real a_time, amrex::MultiFab& a_fctC, const int nGhost); // Fill physical boundaries void setInflowBoundaryVel( - amrex::MultiFab& a_vel, int lev, PeleLM::TimeStamp a_time); + amrex::MultiFab& a_vel, const int lev, const PeleLM::TimeStamp a_time); void fillTurbInflow( - amrex::MultiFab& a_vel, int vel_comp, int lev, const amrex::Real a_time); + amrex::MultiFab& a_vel, const int vel_comp, const int lev, const amrex::Real a_time); // Average down operations void averageDownState(const PeleLM::TimeStamp& a_time); diff --git a/Source/PeleLMeX_BC.cpp b/Source/PeleLMeX_BC.cpp index 7c11dbed8..1d10c810e 100644 --- a/Source/PeleLMeX_BC.cpp +++ b/Source/PeleLMeX_BC.cpp @@ -10,72 +10,71 @@ // Components are Interior, Inflow, Outflow, Symmetry, & // SlipWallAdiab, NoSlipWallAdiab, SlipWallIsoTherm, NoSlipWallIsoTherm. -int norm_vel_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, - amrex::BCType::foextrap, amrex::BCType::reflect_odd, - amrex::BCType::ext_dir, amrex::BCType::ext_dir, - amrex::BCType::ext_dir, amrex::BCType::ext_dir}; - -int tang_vel_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, - amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::hoextrap, amrex::BCType::ext_dir, - amrex::BCType::hoextrap, amrex::BCType::ext_dir}; - -int density_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, - amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::foextrap, amrex::BCType::foextrap, - amrex::BCType::foextrap, amrex::BCType::foextrap}; - -int species_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, - amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::foextrap, amrex::BCType::foextrap, - amrex::BCType::ext_dir, amrex::BCType::ext_dir}; - -int rhoh_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, - amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::foextrap, amrex::BCType::foextrap, - amrex::BCType::ext_dir, amrex::BCType::ext_dir}; - -int temp_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, - amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::foextrap, amrex::BCType::foextrap, - amrex::BCType::ext_dir, amrex::BCType::ext_dir}; - -int aux_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, - amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::foextrap, amrex::BCType::foextrap, - amrex::BCType::ext_dir, amrex::BCType::ext_dir}; - -int divu_bc[] = {amrex::BCType::int_dir, amrex::BCType::reflect_even, - amrex::BCType::reflect_even, amrex::BCType::reflect_even, - amrex::BCType::reflect_even, amrex::BCType::reflect_even, - amrex::BCType::reflect_even, amrex::BCType::reflect_even}; +constexpr int norm_vel_bc[] = {BCType::int_dir, BCType::ext_dir, + BCType::foextrap, BCType::reflect_odd, + BCType::ext_dir, BCType::ext_dir, + BCType::ext_dir, BCType::ext_dir}; + +constexpr int tang_vel_bc[] = {BCType::int_dir, BCType::ext_dir, + BCType::foextrap, BCType::reflect_even, + BCType::hoextrap, BCType::ext_dir, + BCType::hoextrap, BCType::ext_dir}; + +constexpr int density_bc[] = {BCType::int_dir, BCType::ext_dir, + BCType::foextrap, BCType::reflect_even, + BCType::foextrap, BCType::foextrap, + BCType::foextrap, BCType::foextrap}; + +constexpr int species_bc[] = {BCType::int_dir, BCType::ext_dir, + BCType::foextrap, BCType::reflect_even, + BCType::foextrap, BCType::foextrap, + BCType::ext_dir, BCType::ext_dir}; + +constexpr int rhoh_bc[] = {BCType::int_dir, BCType::ext_dir, + BCType::foextrap, BCType::reflect_even, + BCType::foextrap, BCType::foextrap, + BCType::ext_dir, BCType::ext_dir}; + +constexpr int temp_bc[] = {BCType::int_dir, BCType::ext_dir, + BCType::foextrap, BCType::reflect_even, + BCType::foextrap, BCType::foextrap, + BCType::ext_dir, BCType::ext_dir}; + +constexpr int aux_bc[] = {BCType::int_dir, BCType::ext_dir, + BCType::foextrap, BCType::reflect_even, + BCType::foextrap, BCType::foextrap, + BCType::ext_dir, BCType::ext_dir}; + +constexpr int divu_bc[] = {BCType::int_dir, BCType::reflect_even, + BCType::reflect_even, BCType::reflect_even, + BCType::reflect_even, BCType::reflect_even, + BCType::reflect_even, BCType::reflect_even}; // Following incflo rather than IAMR here -int force_bc[] = {BCType::int_dir, BCType::foextrap, BCType::foextrap, +constexpr int force_bc[] = {BCType::int_dir, BCType::foextrap, BCType::foextrap, BCType::foextrap, BCType::foextrap, BCType::foextrap, BCType::foextrap, BCType::foextrap}; #ifdef PELE_USE_PLASMA -int nE_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, - amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::reflect_even, amrex::BCType::reflect_even, - amrex::BCType::ext_dir, amrex::BCType::ext_dir}; +constexpr int nE_bc[] = {BCType::int_dir, BCType::ext_dir, + BCType::foextrap, BCType::reflect_even, + BCType::reflect_even, BCType::reflect_even, + BCType::ext_dir, BCType::ext_dir}; -int phiV_bc[] = { - amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::reflect_even}; +constexpr int phiV_bc[] = {BCType::int_dir, BCType::ext_dir, BCType::reflect_even}; #endif #ifdef PELE_USE_SOOT -int soot_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, - amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::reflect_even, amrex::BCType::reflect_even, - amrex::BCType::ext_dir, amrex::BCType::ext_dir}; +constexpr int soot_bc[] = {BCType::int_dir, BCType::ext_dir, + BCType::foextrap, BCType::reflect_even, + BCType::reflect_even, BCType::reflect_even, + BCType::ext_dir, BCType::ext_dir}; #endif InterpBase* PeleLM:: getInterpolator( // NOLINT(readability-convert-member-functions-to-static) - int a_method) const + const int a_method) const { InterpBase* mapper = nullptr; @@ -109,7 +108,7 @@ PeleLM::setBoundaryConditions() // Initialize the BCRecs m_bcrec_state.resize(NVAR); - int sizeForceBC = std::max(AMREX_SPACEDIM, NUM_SPECIES + 2); + constexpr int sizeForceBC = std::max(AMREX_SPACEDIM, NUM_SPECIES + 2); m_bcrec_force.resize(sizeForceBC); m_bcrec_aux.resize(m_nAux); @@ -119,8 +118,8 @@ PeleLM::setBoundaryConditions() const int* hi_bc = m_phys_bc.hi(); // Velocity - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int idim2 = 0; idim2 < AMREX_SPACEDIM; idim2++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int idim2 = 0; idim2 < AMREX_SPACEDIM; ++idim2) { if (idim == idim2) { m_bcrec_state[VELX + idim].setLo(idim2, norm_vel_bc[lo_bc[idim2]]); m_bcrec_state[VELX + idim].setHi(idim2, norm_vel_bc[hi_bc[idim2]]); @@ -132,8 +131,8 @@ PeleLM::setBoundaryConditions() } // General forces: use int_dir in interior and foextrap otherwise - for (int i = 0; i < sizeForceBC; i++) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int i = 0; i < sizeForceBC; ++i) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_force[i].setLo(idim, force_bc[lo_bc[idim]]); m_bcrec_force[i].setHi(idim, force_bc[hi_bc[idim]]); } @@ -141,47 +140,47 @@ PeleLM::setBoundaryConditions() if (m_incompressible == 0) { // Density - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[DENSITY].setLo(idim, density_bc[lo_bc[idim]]); m_bcrec_state[DENSITY].setHi(idim, density_bc[hi_bc[idim]]); } // Species - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int n = 0; n < NUM_SPECIES; ++n) { m_bcrec_state[FIRSTSPEC + n].setLo(idim, density_bc[lo_bc[idim]]); m_bcrec_state[FIRSTSPEC + n].setHi(idim, density_bc[hi_bc[idim]]); } } // Enthalpy - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[RHOH].setLo(idim, rhoh_bc[lo_bc[idim]]); m_bcrec_state[RHOH].setHi(idim, rhoh_bc[hi_bc[idim]]); } // Temperature - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[TEMP].setLo(idim, temp_bc[lo_bc[idim]]); m_bcrec_state[TEMP].setHi(idim, temp_bc[hi_bc[idim]]); } // rhoRT: reflect even on all but interior bndy - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[RHORT].setLo(idim, divu_bc[lo_bc[idim]]); m_bcrec_state[RHORT].setHi(idim, divu_bc[hi_bc[idim]]); } // divU if (m_has_divu != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_divu.setLo(idim, divu_bc[lo_bc[idim]]); m_bcrec_divu.setHi(idim, divu_bc[hi_bc[idim]]); } } // auxiliaries - assumed to be the same as species - for (int n = 0; n < m_nAux; n++) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int n = 0; n < m_nAux; ++n) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_aux[n].setLo(idim, aux_bc[lo_bc[idim]]); m_bcrec_aux[n].setHi(idim, aux_bc[hi_bc[idim]]); } @@ -189,7 +188,7 @@ PeleLM::setBoundaryConditions() #ifdef PELE_USE_PLASMA // nE - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[NE].setLo(idim, nE_bc[lo_bc[idim]]); m_bcrec_state[NE].setHi(idim, nE_bc[hi_bc[idim]]); } @@ -197,7 +196,7 @@ PeleLM::setBoundaryConditions() // Get m_phiV_bc const int* lo_phibc = m_phiV_bc.lo(); const int* hi_phibc = m_phiV_bc.hi(); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[PHIV].setLo(idim, phiV_bc[lo_phibc[idim]]); m_bcrec_state[PHIV].setHi(idim, phiV_bc[hi_phibc[idim]]); } @@ -205,22 +204,22 @@ PeleLM::setBoundaryConditions() // Hack charged species BCs int FIRSTIONinVar = FIRSTSPEC + NUM_SPECIES - NUM_IONS; int FIRSTIONinSpec = NUM_SPECIES - NUM_IONS; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int n = 0; n < NUM_IONS; n++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int n = 0; n < NUM_IONS; ++n) { auto const bcIonSave = m_bcrec_state[FIRSTIONinVar + n]; m_bcrec_state[FIRSTIONinVar + n] = hackBCChargedParticle(zk[FIRSTIONinSpec + n], bcIonSave); } } // Need to hack nE too actually ... - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { auto const bcnESave = m_bcrec_state[NE]; m_bcrec_state[NE] = hackBCChargedParticle(-1.0, bcnESave); } #endif #ifdef PELE_USE_SOOT - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int mom = 0; mom < NUMSOOTVAR; mom++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int mom = 0; mom < NUMSOOTVAR; ++mom) { m_bcrec_state[FIRSTSOOT + mom].setLo(idim, soot_bc[lo_bc[idim]]); m_bcrec_state[FIRSTSOOT + mom].setHi(idim, soot_bc[hi_bc[idim]]); } @@ -230,20 +229,20 @@ PeleLM::setBoundaryConditions() } Vector -PeleLM::fetchBCRecArray(int scomp, int ncomp) +PeleLM::fetchBCRecArray(const int scomp, const int ncomp) { Vector bc(ncomp); - for (int comp = 0; comp < ncomp; comp++) { + for (int comp = 0; comp < ncomp; ++comp) { bc[comp] = m_bcrec_state[scomp + comp]; } return bc; } Vector -PeleLM::fetchBCRecAuxArray(int scomp, int ncomp) +PeleLM::fetchBCRecAuxArray(const int scomp, const int ncomp) { Vector bc(ncomp); - for (int comp = 0; comp < ncomp; comp++) { + for (int comp = 0; comp < ncomp; ++comp) { bc[comp] = m_bcrec_aux[scomp + comp]; } return bc; @@ -257,19 +256,19 @@ void PeleLM::fillPatchState(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchState()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { fillPatchState(lev, a_time); } } // Fill the a given level class state void -PeleLM::fillPatchState(int lev, const TimeStamp& a_time) +PeleLM::fillPatchState(const int lev, const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchStateLev()"); auto* ldata_p = getLevelDataPtr(lev, a_time); - Real time = getTime(lev, a_time); + const Real time = getTime(lev, a_time); fillpatch_state(lev, time, ldata_p->state, m_nGrowState); if (m_incompressible == 0) { @@ -284,9 +283,9 @@ void PeleLM::fillPatchDensity(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchDensity()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_time); - Real time = getTime(lev, a_time); + const Real time = getTime(lev, a_time); fillpatch_density(lev, time, ldata_p->state, DENSITY, m_nGrowState); } } @@ -295,9 +294,9 @@ void PeleLM::fillPatchSpecies(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchSpecies()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_time); - Real time = getTime(lev, a_time); + const Real time = getTime(lev, a_time); fillpatch_species(lev, time, ldata_p->state, FIRSTSPEC, m_nGrowState); } } @@ -306,9 +305,9 @@ void PeleLM::fillPatchTemp(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchTemp()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_time); - Real time = getTime(lev, a_time); + const Real time = getTime(lev, a_time); fillpatch_temp(lev, time, ldata_p->state, TEMP, m_nGrowState); } } @@ -317,9 +316,9 @@ void PeleLM::fillPatchAux(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchAux()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_time); - Real time = getTime(lev, a_time); + const Real time = getTime(lev, a_time); fillpatch_aux(lev, time, ldata_p->auxiliaries, m_nGrowState); } } @@ -329,9 +328,9 @@ void PeleLM::fillPatchPhiV(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchPhiV()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto ldata_p = getLevelDataPtr(lev, a_time); - Real time = getTime(lev, a_time); + const Real time = getTime(lev, a_time); fillpatch_phiV(lev, time, ldata_p->state, PHIV, m_nGrowState); } } @@ -342,7 +341,7 @@ PeleLM::fillPatchPhiV(const TimeStamp& a_time) // The following return a fillpatched MF ptr at a given level // Fill the entire state at once std::unique_ptr -PeleLM::fillPatchState(int lev, Real a_time, int nGrow) +PeleLM::fillPatchState(const int lev, const Real a_time, const int nGrow) { BL_PROFILE("PeleLMeX::fillPatchState()"); @@ -360,13 +359,14 @@ PeleLM::fillPatchState(int lev, Real a_time, int nGrow) } std::unique_ptr -PeleLM::fillPatchReact(int lev, Real a_time, int nGrow) +PeleLM::fillPatchReact(const int lev, const Real a_time, const int nGrow) { BL_PROFILE("PeleLMeX::fillPatchReact()"); - int IRsize = NUM_SPECIES; #ifdef PELE_USE_PLASMA - IRsize += 1; + constexpr int IRsize = NUM_SPECIES +1; +#else + constexpr int IRsize = NUM_SPECIES; #endif std::unique_ptr mf; mf = std::make_unique( @@ -380,12 +380,12 @@ PeleLM::fillPatchReact(int lev, Real a_time, int nGrow) // Fill the state void PeleLM::fillpatch_state( - int lev, const amrex::Real a_time, amrex::MultiFab& a_state, int nGhost) + const int lev, const Real a_time, MultiFab& a_state, const int nGhost) { ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); - int nCompState = (m_incompressible) != 0 ? AMREX_SPACEDIM : NVAR; + const int nCompState = (m_incompressible) != 0 ? AMREX_SPACEDIM : NVAR; fillTurbInflow(a_state, VELX, lev, a_time); @@ -436,11 +436,11 @@ PeleLM::fillpatch_state( // Fill the density void PeleLM::fillpatch_density( - int lev, - const amrex::Real a_time, - amrex::MultiFab& a_density, - int rho_comp, - int nGhost) + const int lev, + const Real a_time, + MultiFab& a_density, + const int rho_comp, + const int nGhost) { ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); @@ -491,16 +491,16 @@ PeleLM::fillpatch_density( // Fill the mass fractions void PeleLM::fillpatch_species( - int lev, - const amrex::Real a_time, - amrex::MultiFab& a_species, - int rhoY_comp, - int nGhost) + const int lev, + const Real a_time, + MultiFab& a_species, + const int rhoY_comp, + const int nGhost) { ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); if (lev == 0) { - + // Species PhysBCFunct< GpuBndryFuncFab>> @@ -545,11 +545,11 @@ PeleLM::fillpatch_species( // Fill temperature void PeleLM::fillpatch_temp( - int lev, - const amrex::Real a_time, - amrex::MultiFab& a_temp, - int temp_comp, - int nGhost) + const int lev, + const Real a_time, + MultiFab& a_temp, + const int temp_comp, + const int nGhost) { ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); @@ -596,7 +596,7 @@ PeleLM::fillpatch_temp( // Fill the auxiliaries void PeleLM::fillpatch_aux( - int lev, const amrex::Real a_time, amrex::MultiFab& a_aux, int nGhost) + const int lev, const Real a_time, MultiFab& a_aux, const int nGhost) { ProbParm const* lprobparm = prob_parm_d; @@ -650,11 +650,11 @@ PeleLM::fillpatch_aux( // Fill electro-static potential void PeleLM::fillpatch_phiV( - int lev, - const amrex::Real a_time, - amrex::MultiFab& a_temp, - int phiV_comp, - int nGhost) + const int lev, + const Real a_time, + MultiFab& a_temp, + const int phiV_comp, + const int nGhost) { ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); @@ -702,7 +702,7 @@ PeleLM::fillpatch_phiV( // Fill the divU void PeleLM::fillpatch_divu( - int lev, const amrex::Real a_time, amrex::MultiFab& a_divu, int nGhost) + const int lev, const Real a_time, MultiFab& a_divu, const int nGhost) { if (lev == 0) { PhysBCFunct> bndry_func( @@ -736,7 +736,7 @@ PeleLM::fillpatch_divu( // foextrap on domain BCs void PeleLM::fillpatch_forces( - Real a_time, Vector const& a_force, int nGrowForce) + const Real a_time, Vector const& a_force, const int nGrowForce) { AMREX_ASSERT(a_force[0]->nComp() <= m_bcrec_force.size()); const int nComp = a_force[0]->nComp(); @@ -766,7 +766,7 @@ PeleLM::fillpatch_forces( // Fill the gradp void PeleLM::fillpatch_gradp( - int lev, const amrex::Real a_time, amrex::MultiFab& a_gp, int nGhost) + const int lev, const Real a_time, MultiFab& a_gp, const int nGhost) { if (lev == 0) { PhysBCFunct> bndry_func( @@ -799,7 +799,7 @@ PeleLM::fillpatch_gradp( // Fill the reaction data void PeleLM::fillpatch_reaction( - int lev, const amrex::Real a_time, amrex::MultiFab& a_I_R, int nGhost) + const int lev, const Real a_time, MultiFab& a_I_R, const int nGhost) { if (lev == 0) { PhysBCFunct> bndry_func( @@ -827,7 +827,7 @@ PeleLM::fillpatch_reaction( // Fill functC void PeleLM::fillpatch_chemFunctCall( - int lev, const amrex::Real a_time, amrex::MultiFab& a_fctC, int nGhost) + const int lev, const Real a_time, MultiFab& a_fctC, const int nGhost) { if (lev == 0) { PhysBCFunct> bndry_func( @@ -855,13 +855,13 @@ PeleLM::fillpatch_chemFunctCall( // Fill the state void PeleLM::fillcoarsepatch_state( - int lev, const amrex::Real a_time, amrex::MultiFab& a_state, int nGhost) + const int lev, const Real a_time, MultiFab& a_state, const int nGhost) { AMREX_ASSERT(lev > 0); ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); - - int nCompState = (m_incompressible) != 0 ? AMREX_SPACEDIM : NVAR; + + const int nCompState = (m_incompressible) != 0 ? AMREX_SPACEDIM : NVAR; fillTurbInflow(a_state, VELX, lev, a_time); @@ -891,7 +891,7 @@ PeleLM::fillcoarsepatch_state( // Fill the auxiliaries void PeleLM::fillcoarsepatch_aux( - int lev, const amrex::Real a_time, amrex::MultiFab& a_aux, int nGhost) + const int lev, const Real a_time, MultiFab& a_aux, const int nGhost) { AMREX_ASSERT(lev > 0); ProbParm const* lprobparm = prob_parm_d; @@ -919,7 +919,7 @@ PeleLM::fillcoarsepatch_aux( // Fill the grad P void PeleLM::fillcoarsepatch_gradp( - int lev, const amrex::Real a_time, amrex::MultiFab& a_gp, int nGhost) + const int lev, const Real a_time, MultiFab& a_gp, const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -937,7 +937,7 @@ PeleLM::fillcoarsepatch_gradp( // Fill the divu void PeleLM::fillcoarsepatch_divu( - int lev, const amrex::Real a_time, amrex::MultiFab& a_divu, int nGhost) + const int lev, const Real a_time, MultiFab& a_divu, const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -955,7 +955,7 @@ PeleLM::fillcoarsepatch_divu( // Fill coarse patch of reaction void PeleLM::fillcoarsepatch_reaction( - int lev, const amrex::Real a_time, amrex::MultiFab& a_I_R, int nGhost) + const int lev, const Real a_time, MultiFab& a_I_R, const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -973,7 +973,7 @@ PeleLM::fillcoarsepatch_reaction( // Fill coarse patch of chem function call void PeleLM::fillcoarsepatch_chemFunctCall( - int lev, const amrex::Real a_time, amrex::MultiFab& a_fctC, int nGhost) + const int lev, const Real a_time, MultiFab& a_fctC, const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -991,18 +991,18 @@ PeleLM::fillcoarsepatch_chemFunctCall( // Fill the inflow boundary of a velocity MF // used for velocity projection void -PeleLM::setInflowBoundaryVel(MultiFab& a_vel, int lev, TimeStamp a_time) +PeleLM::setInflowBoundaryVel(MultiFab& a_vel, const int lev, const TimeStamp a_time) { BL_PROFILE("PeleLMeX::setInflowBoundaryVel()"); - Real time = getTime(lev, a_time); + const Real time = getTime(lev, a_time); // Create a dummy BCRec from Velocity BCRec keeping only Inflow and set the // other to bogus auto realVelBCRec = fetchBCRecArray(VELX, AMREX_SPACEDIM); - amrex::Vector dummyVelBCRec(AMREX_SPACEDIM); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int idim2 = 0; idim2 < AMREX_SPACEDIM; idim2++) { + Vector dummyVelBCRec(AMREX_SPACEDIM); + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int idim2 = 0; idim2 < AMREX_SPACEDIM; ++idim2) { if (realVelBCRec[idim].lo(idim2) == BCType::ext_dir) { dummyVelBCRec[idim].setLo(idim2, BCType::ext_dir); } else { @@ -1035,7 +1035,7 @@ PeleLM::setInflowBoundaryVel(MultiFab& a_vel, int lev, TimeStamp a_time) void PeleLM::fillTurbInflow( - MultiFab& a_vel, int vel_comp, int lev, const Real a_time) + MultiFab& a_vel, const int vel_comp, const int lev, const Real a_time) { if (turb_inflow.is_initialized()) { @@ -1046,8 +1046,8 @@ PeleLM::fillTurbInflow( auto velBCRec = fetchBCRecArray(VELX, AMREX_SPACEDIM); // Copy problem parameter structs to host - amrex::Gpu::copy( - amrex::Gpu::deviceToHost, probparmDD, probparmDD + 1, probparmDH); + Gpu::copy( + Gpu::deviceToHost, probparmDD, probparmDD + 1, probparmDH); #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) @@ -1059,55 +1059,55 @@ PeleLM::fillTurbInflow( for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { auto bndryBoxLO = - amrex::Box(amrex::adjCellLo(geom[lev].Domain(), dir, 4) & bx); + Box(adjCellLo(geom[lev].Domain(), dir, 4) & bx); if ( - velBCRec[0].lo()[dir] == amrex::BCType::ext_dir && bndryBoxLO.ok()) { + velBCRec[0].lo()[dir] == BCType::ext_dir && bndryBoxLO.ok()) { // Create box with ghost cells and set them to zero - amrex::IntVect growVect(amrex::IntVect::TheUnitVector()); - int Grow = 4; // Being conservative - for (int n = 0; n < AMREX_SPACEDIM; n++) { + IntVect growVect(IntVect::TheUnitVector()); + constexpr int Grow = 4; // Being conservative + for (int n = 0; n < AMREX_SPACEDIM; ++n) { growVect[n] = Grow; } growVect[dir] = 0; - amrex::Box modDom = geom[lev].Domain(); + Box modDom = geom[lev].Domain(); modDom.grow(growVect); auto bndryBoxLO_ghost = - amrex::Box(amrex::adjCellLo(modDom, dir, Grow) & bx); - data.setVal( + Box(adjCellLo(modDom, dir, Grow) & bx); + data.setVal( 0.0, bndryBoxLO_ghost, vel_comp, AMREX_SPACEDIM); turb_inflow.add_turb( bndryBoxLO, data, 0, geom[lev], a_time, dir, - amrex::Orientation::low); + Orientation::low); } auto bndryBoxHI = - amrex::Box(amrex::adjCellHi(geom[lev].Domain(), dir, 4) & bx); + Box(adjCellHi(geom[lev].Domain(), dir, 4) & bx); if ( - velBCRec[0].hi()[dir] == amrex::BCType::ext_dir && bndryBoxHI.ok()) { + velBCRec[0].hi()[dir] == BCType::ext_dir && bndryBoxHI.ok()) { // Create box with ghost cells and set them to zero - amrex::IntVect growVect(amrex::IntVect::TheUnitVector()); - int Grow = 4; - for (int n = 0; n < AMREX_SPACEDIM; n++) { + IntVect growVect(IntVect::TheUnitVector()); + constexpr int Grow = 4; + for (int n = 0; n < AMREX_SPACEDIM; ++n) { growVect[n] = Grow; } growVect[dir] = 0; - amrex::Box modDom = geom[lev].Domain(); + Box modDom = geom[lev].Domain(); modDom.grow(growVect); auto bndryBoxHI_ghost = - amrex::Box(amrex::adjCellHi(modDom, dir, Grow) & bx); - data.setVal( + Box(adjCellHi(modDom, dir, Grow) & bx); + data.setVal( 0.0, bndryBoxHI_ghost, vel_comp, AMREX_SPACEDIM); turb_inflow.add_turb( bndryBoxHI, data, 0, geom[lev], a_time, dir, - amrex::Orientation::high); + Orientation::high); } } } // Copy problem parameter structs back to device - amrex::Gpu::copy( - amrex::Gpu::hostToDevice, probparmDH, probparmDH + 1, probparmDD); + Gpu::copy( + Gpu::hostToDevice, probparmDH, probparmDH + 1, probparmDD); } } From 42b6b02a5a99ca782577a51c8cd05e503e4cdc4d Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 29 Jun 2025 01:24:01 +0200 Subject: [PATCH 05/87] BCfill, BPatch --- Source/PeleLMeX.H | 10 +++++----- Source/PeleLMeX.cpp | 8 ++++---- Source/PeleLMeX_BCfill.H | 26 +++++++++++++------------- Source/PeleLMeX_BCfillEB.H | 2 +- Source/PeleLMeX_BPatch.H | 12 ++++++------ Source/PeleLMeX_BPatch.cpp | 8 ++++---- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 436d36668..cdefaa75e 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -1640,7 +1640,7 @@ public: // Accessors std::string runMode() const { return m_run_mode; } - static int nCompIR() + static constexpr int nCompIR() { #ifdef PELE_USE_PLASMA return NUM_SPECIES + 1; @@ -1649,7 +1649,7 @@ public: #endif } - static int nCompForcing() + static constexpr int nCompForcing() { #ifdef PELE_USE_PLASMA return NUM_SPECIES + 2; @@ -1664,10 +1664,10 @@ public: } LevelData* - getLevelDataPtr(int lev, const PeleLM::TimeStamp& a_time, int useUmac = 0); - LevelDataReact* getLevelDataReactPtr(int lev); + getLevelDataPtr(const int lev, const PeleLM::TimeStamp& a_time, int useUmac = 0); + LevelDataReact* getLevelDataReactPtr(const int lev); - amrex::Real getTime(int lev, const PeleLM::TimeStamp& a_time) const + amrex::Real getTime(const int lev, const PeleLM::TimeStamp& a_time) const { AMREX_ASSERT( a_time == AmrOldTime || a_time == AmrNewTime || a_time == AmrHalfTime); diff --git a/Source/PeleLMeX.cpp b/Source/PeleLMeX.cpp index 82b2e0419..063b308f0 100644 --- a/Source/PeleLMeX.cpp +++ b/Source/PeleLMeX.cpp @@ -43,7 +43,7 @@ PeleLM::~PeleLM() PeleLM::LevelData* PeleLM::getLevelDataPtr( - int lev, const PeleLM::TimeStamp& a_time, int /*useUMac*/) + const int lev, const PeleLM::TimeStamp& a_time, int /*useUMac*/) { AMREX_ASSERT( a_time == AmrOldTime || a_time == AmrNewTime || a_time == AmrHalfTime); @@ -56,7 +56,7 @@ PeleLM::getLevelDataPtr( m_leveldata_floating = std::make_unique( grids[lev], dmap[lev], *m_factory[lev], m_incompressible, m_has_divu, m_nAux, m_nGrowState, m_use_soret, static_cast(m_do_les)); - Real time = getTime(lev, a_time); + const Real time = getTime(lev, a_time); fillpatch_state(lev, time, m_leveldata_floating->state, m_nGrowState); if (m_nAux > 0) { fillpatch_aux(lev, time, m_leveldata_floating->auxiliaries, m_nGrowState); @@ -65,7 +65,7 @@ PeleLM::getLevelDataPtr( } PeleLM::LevelDataReact* -PeleLM::getLevelDataReactPtr(int lev) +PeleLM::getLevelDataReactPtr(const int lev) { if (m_do_react != 0) { return m_leveldatareact[lev].get(); @@ -177,7 +177,7 @@ PeleLM::getDensityVect(const TimeStamp& a_time) } } else { for (int lev = 0; lev <= finest_level; ++lev) { - Real time = getTime(lev, a_time); + const Real time = getTime(lev, a_time); r.push_back( std::make_unique(grids[lev], dmap[lev], 1, m_nGrowState)); fillpatch_density(lev, time, *(r[lev]), 0, m_nGrowState); diff --git a/Source/PeleLMeX_BCfill.H b/Source/PeleLMeX_BCfill.H index 07e3e0f0b..390ce25f5 100644 --- a/Source/PeleLMeX_BCfill.H +++ b/Source/PeleLMeX_BCfill.H @@ -56,10 +56,10 @@ struct PeleLMCCFillExtDirState auto iv_3d = amrex::IntVectND<3>(0); AMREX_D_TERM(iv_3d[0] = iv[0];, iv_3d[1] = iv[1];, iv_3d[2] = iv[2];); - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low - for (int n = 0; n < std::min(numcomp, NVAR); n++) { + for (int n = 0; n < std::min(numcomp, NVAR); ++n) { // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; @@ -93,7 +93,7 @@ struct PeleLMCCFillExtDirState } // High - for (int n = 0; n < std::min(numcomp, NVAR); n++) { + for (int n = 0; n < std::min(numcomp, NVAR); ++n) { // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; @@ -176,10 +176,10 @@ struct PeleLMCCFillExtDirAux auto aux_ext = aux.cellData(iv[0], iv[1], iv[2]); #endif - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low - for (int n = 0; n < m_nAux; n++) { + for (int n = 0; n < m_nAux; ++n) { // Get current state component BC const int* bc = bcr[n].data(); @@ -192,7 +192,7 @@ struct PeleLMCCFillExtDirAux } } // High - for (int n = 0; n < m_nAux; n++) { + for (int n = 0; n < m_nAux; ++n) { // Get current state component BC const int* bc = bcr[n].data(); @@ -251,7 +251,7 @@ struct PeleLMCCFillExtDirSpec auto iv_3d = amrex::IntVectND<3>(0); AMREX_D_TERM(iv_3d[0] = iv[0];, iv_3d[1] = iv[1];, iv_3d[2] = iv[2];); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { // Get the species component BC const int* bc = bcr[n].data(); @@ -259,7 +259,7 @@ struct PeleLMCCFillExtDirSpec // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { @@ -346,7 +346,7 @@ struct PeleLMCCFillExtDirDens // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { @@ -430,7 +430,7 @@ struct PeleLMCCFillExtDirRhoH // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { @@ -513,7 +513,7 @@ struct PeleLMCCFillExtDirTemp // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { @@ -598,7 +598,7 @@ struct PeleLMCCFillExtDirnE // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { @@ -684,7 +684,7 @@ struct PeleLMCCFillExtDirPhiV // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { diff --git a/Source/PeleLMeX_BCfillEB.H b/Source/PeleLMeX_BCfillEB.H index 399952981..de5f4d668 100644 --- a/Source/PeleLMeX_BCfillEB.H +++ b/Source/PeleLMeX_BCfillEB.H @@ -142,7 +142,7 @@ struct PeleLMFillBCStateEB ebh.bcnormal_eb(xface, bcnorm, stateIn, stateExt, time, geom, *lprobparm); // Extract requested entries - for (int n = 0; n < numcomp; n++) { + for (int n = 0; n < numcomp; ++n) { ebState(i, j, k, n) = stateExt[firstcomp + n]; } } diff --git a/Source/PeleLMeX_BPatch.H b/Source/PeleLMeX_BPatch.H index 69a099df1..485caec5b 100644 --- a/Source/PeleLMeX_BPatch.H +++ b/Source/PeleLMeX_BPatch.H @@ -72,7 +72,7 @@ public: } #elif (AMREX_SPACEDIM == 3) amrex::Real zp; - const amrex::Real sqrt2 = sqrt(2.0); + constexpr amrex::Real sqrt2 = sqrt(2.0); xp = point_coordinate[0]; yp = point_coordinate[1]; @@ -82,9 +82,9 @@ public: inside = true; } else if (m_patchtype_num == 1) { - amrex::Real patch_circle_radius_touse = + const amrex::Real patch_circle_radius_touse = m_patch_circle_radius + dx * sqrt2 / 2.0; - amrex::Real rad = sqrt( + const amrex::Real rad = sqrt( (xp - m_patch_circle_center[0]) * (xp - m_patch_circle_center[0]) + (yp - m_patch_circle_center[1]) * (yp - m_patch_circle_center[1]) + (zp - m_patch_circle_center[2]) * (zp - m_patch_circle_center[2])); @@ -116,12 +116,12 @@ public: inside = true; } } else if (m_patchtype_num == 3) { - amrex::Real patch_circ_ann_outer_radius_touse = + const amrex::Real patch_circ_ann_outer_radius_touse = m_patch_circ_ann_outer_radius + dx * sqrt2 / 2.0; - amrex::Real patch_circ_ann_inner_radius_touse = + const amrex::Real patch_circ_ann_inner_radius_touse = m_patch_circ_ann_inner_radius - dx * sqrt2 / 2.0; - amrex::Real rad = sqrt( + const amrex::Real rad = sqrt( (xp - m_patch_circ_ann_center[0]) * (xp - m_patch_circ_ann_center[0]) + (yp - m_patch_circ_ann_center[1]) * diff --git a/Source/PeleLMeX_BPatch.cpp b/Source/PeleLMeX_BPatch.cpp index 527e611b0..346e92d1a 100644 --- a/Source/PeleLMeX_BPatch.cpp +++ b/Source/PeleLMeX_BPatch.cpp @@ -156,19 +156,19 @@ BPatch::BPatch(const std::string& patch_name, const amrex::Geometry& geom) pele::physics::eos::speciesNames(names); names.resize(names.size()); - for (int n = 0; n < names.size(); n++) { + for (int n = 0; n < names.size(); ++n) { m_bpdata_h.speciesIndex[n] = -1; } - for (int m = 0; m < m_bpdata_h.num_species; m++) { - for (int n = 0; n < names.size(); n++) { + for (int m = 0; m < m_bpdata_h.num_species; ++m) { + for (int n = 0; n < names.size(); ++n) { if (speciesList[m] == names[n]) { m_bpdata_h.speciesIndex[m] = n; } } } - for (int n = 0; n < m_bpdata_h.num_species; n++) { + for (int n = 0; n < m_bpdata_h.num_species; ++n) { if (m_bpdata_h.speciesIndex[n] == -1) { std::string msg = "\nError! Unable to find species index " + std::to_string(n); From 23f1cde3975b5be2c1e32a9627fb35a41360bbab Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 29 Jun 2025 12:58:58 +0200 Subject: [PATCH 06/87] some more changes --- Source/PeleLMeX.H | 34 +-- Source/PeleLMeX_Advection.cpp | 6 +- Source/PeleLMeX_Data.cpp | 59 ++--- Source/PeleLMeX_Derive.cpp | 8 +- Source/PeleLMeX_DeriveFunc.cpp | 8 +- Source/PeleLMeX_Diffusion.cpp | 385 +++++++++++++++------------------ 6 files changed, 237 insertions(+), 263 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index cdefaa75e..7082162e2 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -165,12 +165,12 @@ public: amrex::BoxArray const& ba, amrex::DistributionMapping const& dm, amrex::FabFactory const& factory, - int a_incompressible, - int a_has_divu, - int a_nAux, - int a_nGrowState, - int a_use_soret, - int a_do_les); + const int a_incompressible, + const int a_has_divu, + const int a_nAux, + const int a_nGrowState, + const int a_use_soret, + const int a_do_les); // cell-centered state multifabs amrex::MultiFab @@ -224,15 +224,15 @@ public: { AdvanceDiffData() = default; AdvanceDiffData( - int a_finestLevel, + const int a_finestLevel, const amrex::Vector& ba, const amrex::Vector& dm, const amrex::Vector>>& factory, - int a_nGrowAdv, - int a_use_wbar, - int a_use_soret, - int a_nAux, + const int a_nGrowAdv, + const int a_use_wbar, + const int a_use_soret, + const int a_nAux, int is_init = 0); amrex::Vector Dn; // Diffusion term t^n amrex::Vector Dnp1; // Diffusion term t^(n+1,k) @@ -258,15 +258,15 @@ public: { AdvanceAdvData() = default; AdvanceAdvData( - int a_finestLevel, + const int a_finestLevel, const amrex::Vector& ba, const amrex::Vector& dm, const amrex::Vector>>& factory, - int a_incompressible, - int a_nAux, - int a_nGrowAdv, - int a_nGrowMAC); + const int a_incompressible, + const int a_nAux, + const int a_nGrowAdv, + const int a_nGrowMAC); amrex::Vector> umac; // MAC face velocity amrex::Vector AofS; // Scalar advection term at t^(n+1/2) @@ -705,7 +705,7 @@ public: void computeDivTau( const PeleLM::TimeStamp& a_time, const amrex::Vector& a_divtau, - int use_density, + const int use_density, amrex::Real scale = 1.0); /** diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 8ba404ac2..c2cdaece9 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -248,9 +248,9 @@ PeleLM::updateVelocity(std::unique_ptr& advData) state_old_ma[box_no](i, j, k, VELX+n) + dt_loc * (adv_aofs_ma[box_no](i, j, k, VELX+n) + force_ma[box_no](i, j, k, n)); } - }); + }); } -} + Gpu::streamSynchronize();} void PeleLM::getScalarAdvForce( @@ -293,6 +293,7 @@ PeleLM::getScalarAdvForce( leosparm); }); } + Gpu::streamSynchronize(); // Fill forcing ghost cells if (advData->Forcing[0].nGrow() > 0) { fillpatch_forces( @@ -1104,5 +1105,6 @@ PeleLM::updateScalarComp( } }); } + Gpu::streamSynchronize(); averageDown(AmrNewTime, state_comp, ncomp); } diff --git a/Source/PeleLMeX_Data.cpp b/Source/PeleLMeX_Data.cpp index e5c4c7b94..9f90643fa 100644 --- a/Source/PeleLMeX_Data.cpp +++ b/Source/PeleLMeX_Data.cpp @@ -6,12 +6,12 @@ PeleLM::LevelData::LevelData( amrex::BoxArray const& ba, amrex::DistributionMapping const& dm, amrex::FabFactory const& factory, - int a_incompressible, - int a_has_divu, - int a_nAux, - int a_nGrowState, - int a_use_soret, - int a_do_les) + const int a_incompressible, + const int a_has_divu, + const int a_nAux, + const int a_nGrowState, + const int a_use_soret, + const int a_do_les) { if (a_incompressible != 0) { state.define(ba, dm, AMREX_SPACEDIM, a_nGrowState, MFInfo(), factory); @@ -61,9 +61,10 @@ PeleLM::LevelDataReact::LevelDataReact( const amrex::DistributionMapping& dm, const amrex::FabFactory& factory) { - int IRsize = NUM_SPECIES; #ifdef PELE_USE_PLASMA - IRsize += 1; + constexpr int IRsize = NUM_SPECIES +1; +#else + constexpr int IRsize = NUM_SPECIES; #endif I_R.define(ba, dm, IRsize, 0, MFInfo(), factory); functC.define(ba, dm, 1, 0, MFInfo(), factory); @@ -74,7 +75,7 @@ PeleLM::LevelDataNLSolve::LevelDataNLSolve( amrex::BoxArray const& ba, amrex::DistributionMapping const& dm, amrex::FabFactory const& factory, - int a_nGrow) + const int a_nGrow) { nlState.define(ba, dm, 2, a_nGrow, MFInfo(), factory); nlResid.define(ba, dm, 2, a_nGrow, MFInfo(), factory); @@ -90,29 +91,29 @@ PeleLM::LevelDataNLSolve::LevelDataNLSolve( #endif PeleLM::AdvanceDiffData::AdvanceDiffData( - int a_finestLevel, + const int a_finestLevel, const amrex::Vector& ba, const amrex::Vector& dm, const amrex::Vector>>& factory, - int nGrowAdv, - int a_use_wbar, - int a_use_soret, - int a_nAux, - int is_init) + const int nGrowAdv, + const int a_use_wbar, + const int a_use_soret, + const int a_nAux, + const int is_init) { if (is_init != 0) { // All I need is a container for a single diffusion term // Resize Vectors Dnp1.resize(a_finestLevel + 1); // Define MFs - for (int lev = 0; lev <= a_finestLevel; lev++) { + for (int lev = 0; lev <= a_finestLevel; ++lev) { Dnp1[lev].define( ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, MFInfo(), *factory[lev]); } if (a_nAux > 0) { Dnp1_aux.resize(a_finestLevel + 1); - for (int lev = 0; lev <= a_finestLevel; lev++) { + for (int lev = 0; lev <= a_finestLevel; ++lev) { Dnp1_aux[lev].define( ba[lev], dm[lev], a_nAux, nGrowAdv, MFInfo(), *factory[lev]); } @@ -137,7 +138,7 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( } // Define MFs - for (int lev = 0; lev <= a_finestLevel; lev++) { + for (int lev = 0; lev <= a_finestLevel; ++lev) { Dn[lev].define( ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, MFInfo(), *factory[lev]); Dnp1[lev].define( @@ -177,14 +178,14 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( } PeleLM::AdvanceAdvData::AdvanceAdvData( - int a_finestLevel, + const int a_finestLevel, const amrex::Vector& ba, const amrex::Vector& dm, const amrex::Vector>>& factory, - int a_incompressible, - int a_nAux, - int nGrowAdv, - int nGrowMAC) + const int a_incompressible, + const int a_nAux, + const int nGrowAdv, + const int nGrowMAC) { // Resize Vectors umac.resize(a_finestLevel + 1); @@ -203,7 +204,7 @@ PeleLM::AdvanceAdvData::AdvanceAdvData( #endif // Define MFs - for (int lev = 0; lev <= a_finestLevel; lev++) { + for (int lev = 0; lev <= a_finestLevel; ++lev) { for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const BoxArray& faceba = amrex::convert(ba[lev], IntVect::TheDimensionVector(idim)); @@ -245,7 +246,7 @@ void PeleLM::copyStateNewToOld(int nGhost) { AMREX_ASSERT(nGhost <= m_nGrowState); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { if (m_incompressible != 0) { MultiFab::Copy( m_leveldata_old[lev]->state, m_leveldata_new[lev]->state, 0, 0, @@ -271,7 +272,7 @@ PeleLM::copyStateNewToOld(int nGhost) void PeleLM::copyPressNewToOld() { - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy( m_leveldata_old[lev]->press, m_leveldata_new[lev]->press, 0, 0, 1, 1); MultiFab::Copy( @@ -284,7 +285,7 @@ void PeleLM::copyStateOldToNew(int nGhost) { AMREX_ASSERT(nGhost <= m_nGrowState); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { if (m_incompressible != 0) { MultiFab::Copy( m_leveldata_new[lev]->state, m_leveldata_old[lev]->state, 0, 0, @@ -310,7 +311,7 @@ PeleLM::copyStateOldToNew(int nGhost) void PeleLM::copyTransportOldToNew() { - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy( m_leveldata_new[lev]->visc_cc, m_leveldata_old[lev]->visc_cc, 0, 0, 1, 1); if (m_incompressible == 0) { @@ -340,7 +341,7 @@ PeleLM::copyTransportOldToNew() void PeleLM::copyDiffusionOldToNew(std::unique_ptr& diffData) { - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy( diffData->Dnp1[lev], diffData->Dn[lev], 0, 0, NUM_SPECIES + 2, m_nGrowAdv); diff --git a/Source/PeleLMeX_Derive.cpp b/Source/PeleLMeX_Derive.cpp index d1d7a56c6..f06e1a53c 100644 --- a/Source/PeleLMeX_Derive.cpp +++ b/Source/PeleLMeX_Derive.cpp @@ -115,7 +115,7 @@ PeleLMDeriveRec::numDerive() const noexcept } const std::string& -PeleLMDeriveRec::variableName(int comp) const noexcept +PeleLMDeriveRec::variableName(const int comp) const noexcept { if (comp < variable_names.size()) { return variable_names[comp]; @@ -130,7 +130,7 @@ PeleLMDeriveRec::variableComp(const std::string& a_name) const noexcept if (n_derive == 1) { return 0; } - for (int comp = 0; comp < n_derive; comp++) { + for (int comp = 0; comp < n_derive; ++comp) { if (variable_names[comp] == a_name) { return comp; } @@ -200,7 +200,7 @@ PeleLMDeriveList::canDerive(const std::string& name) const { for (const auto& li : lst) { // Can be either a component name ... - for (int i = 0; i < li.numDerive(); i++) { + for (int i = 0; i < li.numDerive(); ++i) { if (li.variableName(i) == name) { return true; } @@ -218,7 +218,7 @@ PeleLMDeriveList::get(const std::string& name) const { for (const auto& li : lst) { // Can be either a component name ... - for (int i = 0; i < li.numDerive(); i++) { + for (int i = 0; i < li.numDerive(); ++i) { if (li.variableName(i) == name) { return &li; } diff --git a/Source/PeleLMeX_DeriveFunc.cpp b/Source/PeleLMeX_DeriveFunc.cpp index 6228f7b11..cabd51f60 100644 --- a/Source/PeleLMeX_DeriveFunc.cpp +++ b/Source/PeleLMeX_DeriveFunc.cpp @@ -80,7 +80,7 @@ pelelmex_derheatrelease( amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { getHGivenT(i, j, k, temp, Hi, leosparm); HRR(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { HRR(i, j, k) -= Hi(i, j, k, n) * react(i, j, k, n); } }); @@ -153,12 +153,12 @@ pelelmex_dermolefrac( amrex::Real Yt[NUM_SPECIES] = {0.0}; amrex::Real Xt[NUM_SPECIES] = {0.0}; amrex::Real rhoinv = 1.0 / in_dat(i, j, k, DENSITY); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { Yt[n] = in_dat(i, j, k, FIRSTSPEC + n) * rhoinv; } auto eos = pele::physics::PhysicsType::eos(leosparm); eos.Y2X(Yt, Xt); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { der(i, j, k, n) = Xt[n]; } }); @@ -194,7 +194,7 @@ pelelmex_derrhomrhoy( auto der = derfab.array(dcomp); amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { der(i, j, k, 0) = in_dat(i, j, k, DENSITY); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { der(i, j, k, 0) -= in_dat(i, j, k, FIRSTSPEC + n); } }); diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index b4ffa2588..e824e2e20 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -22,7 +22,7 @@ PeleLM::getDiffusionOp() } DiffusionOp* -PeleLM::getMCDiffusionOp(int ncomp) +PeleLM::getMCDiffusionOp(const int ncomp) { if (!m_mcdiffusion_op || m_mcdiffusion_op->m_ncomp != ncomp) { m_mcdiffusion_op = std::make_unique(this, ncomp); @@ -43,7 +43,7 @@ void PeleLM::computeDifferentialDiffusionTerms( const TimeStamp& a_time, std::unique_ptr& diffData, - int is_init) + const int is_init) { BL_PROFILE("PeleLMeX::computeDifferentialDiffusionTerms()"); @@ -78,7 +78,7 @@ PeleLM::computeDifferentialDiffusionTerms( for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], NUM_SPECIES + 2, nGrow, MFInfo(), factory); @@ -305,11 +305,11 @@ PeleLM::adjustSpeciesFluxes( amrex::ParallelFor( ebx, [idim, rhoY, flux_dir, edomain, bc_lo, bc_hi] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - bool on_lo = + const int idx[3] = {i, j, k}; + const bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && (idx[idim] <= edomain.smallEnd(idim))); - bool on_hi = + const bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && (idx[idim] >= edomain.bigEnd(idim))); repair_flux(i, j, k, idim, on_lo, on_hi, rhoY, flux_dir); @@ -321,11 +321,11 @@ PeleLM::adjustSpeciesFluxes( ebx, [idim, rhoY, flux_dir, rhoYed_ar, areafrac_ar, edomain, bc_lo, bc_hi] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - bool on_lo = + const int idx[3] = {i, j, k}; + const bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && (idx[idim] <= edomain.smallEnd(idim))); - bool on_hi = + const bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && (idx[idim] >= edomain.bigEnd(idim))); repair_flux_eb( @@ -338,11 +338,11 @@ PeleLM::adjustSpeciesFluxes( amrex::ParallelFor( ebx, [idim, rhoY, flux_dir, edomain, bc_lo, bc_hi] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - bool on_lo = + const int idx[3] = {i, j, k}; + const bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && (idx[idim] <= edomain.smallEnd(idim))); - bool on_hi = + const bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && (idx[idim] >= edomain.bigEnd(idim))); repair_flux(i, j, k, idim, on_lo, on_hi, rhoY, flux_dir); @@ -377,8 +377,8 @@ PeleLM::correctIsothermalBoundary( Vector> soretfluxes(finest_level + 1); if (need_explicit_fluxes) { // need to fill the soret fluxes ourselves - for (int lev = 0; lev <= finest_level; lev++) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int lev = 0; lev <= finest_level; ++lev) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { soretfluxes[lev][idim] = new MultiFab( grids[lev], dmap[lev], NUM_SPECIES, 1, MFInfo(), Factory(lev)); soretfluxes[lev][idim]->setVal(0.0); @@ -388,8 +388,8 @@ PeleLM::correctIsothermalBoundary( soretfluxes, soretfluxes, GetVecOfConstPtrs(getTempVect(a_time)), GetVecOfConstPtrs(getDiffusivityVect(a_time))); } else { // have the lagged ones, alias to them - for (int lev = 0; lev <= finest_level; lev++) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int lev = 0; lev <= finest_level; ++lev) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { soretfluxes[lev][idim] = new MultiFab( *a_soretfluxes[lev][idim], amrex::make_alias, 0, NUM_SPECIES); } @@ -427,18 +427,18 @@ PeleLM::correctIsothermalBoundary( [flux_wbar, flux_soret, rhoD_ec, boundary_ar, idim, edomain, bc_lo, bc_hi, use_wbar = m_use_wbar, need_explicit_fluxes] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - bool on_lo = (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || + const int idx[3] = {i, j, k}; + const bool on_lo = (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || bc_lo == BoundaryCondition::BCSlipWallIsotherm) && (idx[idim] <= edomain.smallEnd(idim)); - bool on_hi = (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || + const bool on_hi = (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || bc_hi == BoundaryCondition::BCSlipWallIsotherm) && (idx[idim] >= edomain.bigEnd(idim)); if (on_lo || on_hi) { if (on_lo) { // need to move -1 for lo boundary idx[idim] -= 1; } - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { boundary_ar(idx[0], idx[1], idx[2], n) = flux_soret(i, j, k, n); // add lagged wbar flux if (use_wbar != 0 && !need_explicit_fluxes) { @@ -453,8 +453,8 @@ PeleLM::correctIsothermalBoundary( } } // TODO: wbar fluxes disabled for this case - boundary system becomes complex - for (int lev = 0; lev <= finest_level; lev++) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int lev = 0; lev <= finest_level; ++lev) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { delete soretfluxes[lev][idim]; } } @@ -494,7 +494,7 @@ PeleLM::computeDifferentialDiffusionFluxes( MultiFab::Copy( spec_boundary[lev], ldata_p->state, FIRSTSPEC, 0, NUM_SPECIES, 1); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { MultiFab::Divide(spec_boundary[lev], ldata_p->state, DENSITY, n, 1, 1); } } @@ -518,7 +518,7 @@ PeleLM::computeDifferentialDiffusionFluxes( GetVecOfConstPtrs(getDiffusivityVect(a_time)), 0, bcRecSpec, NUM_SPECIES - NUM_IONS, do_avgDown, {}); // Ions one by one - for (int n = 0; n < NUM_IONS; n++) { + for (int n = 0; n < NUM_IONS; ++n) { auto bcRecIons = fetchBCRecArray(FIRSTSPEC + NUM_SPECIES - NUM_IONS + n, 1); getDiffusionOp()->computeDiffFluxes( a_fluxes, NUM_SPECIES - NUM_IONS + n, @@ -671,6 +671,7 @@ PeleLM::addWbarTerm( grids[lev], dmap[lev], 1, nGrow, MFInfo(), Factory(lev)); } const Box& domain = geom[lev].Domain(); + #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif @@ -696,14 +697,14 @@ PeleLM::addWbarTerm( // NOTE: for now, this is skipped since wbar disabled for // isothermal/soret Wbar_boundary_arr(i, j, k) = Wbar_arr(i, j, k); - int idx[3] = {i, j, k}; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + const int idx[3] = {i, j, k}; + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const auto bc_lo = phys_bc.lo(idim); const auto bc_hi = phys_bc.hi(idim); - bool on_lo = (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || + const bool on_lo = (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || bc_lo == BoundaryCondition::BCSlipWallIsotherm) && (idx[idim] < domain.smallEnd(idim)); - bool on_hi = (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || + const bool on_hi = (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || bc_hi == BoundaryCondition::BCSlipWallIsotherm) && (idx[idim] > domain.bigEnd(idim)); @@ -728,7 +729,7 @@ PeleLM::addWbarTerm( for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { gradWbar[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], NUM_SPECIES, nGrow, MFInfo(), factory); @@ -758,7 +759,7 @@ PeleLM::addWbarTerm( #endif { for (MFIter mfi(*a_beta[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { // Get edge centered rhoYs const Box ebx = mfi.nodaltilebox(idim); @@ -772,11 +773,11 @@ PeleLM::addWbarTerm( amrex::ParallelFor( ebx, [idim, bc_lo, bc_hi, use_harmonic_avg, rhoY_arr, rhoYed_arr, edomain] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - bool on_lo = + const int idx[3] = {i, j, k}; + const bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && (idx[idim] <= edomain.smallEnd(idim))); - bool on_hi = + const bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && (idx[idim] >= edomain.bigEnd(idim))); cen2edg_cpp( @@ -804,23 +805,23 @@ PeleLM::addWbarTerm( auto eos = pele::physics::PhysicsType::eos(eosparm); // Get Wbar from rhoYs amrex::Real rho = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rho += rhoY(i, j, k, n); } amrex::Real rho_inv = 1.0 / rho; amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rho_inv; } amrex::Real WBAR = 0.0; eos.Y2WBAR(y, WBAR); WBAR *= 0.001; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { spFlux_ar(i, j, k, n) -= y[n] / WBAR * beta_ar(i, j, k, n) * gradWbar_ar(i, j, k); } if (need_wbar_fluxes != 0) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { spwbarFlux_ar(i, j, k, n) = -y[n] / WBAR * beta_ar(i, j, k, n) * gradWbar_ar(i, j, k); } @@ -855,7 +856,7 @@ PeleLM::addSoretTerm( for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { gradT[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], 1, nGrow, MFInfo(), factory); @@ -884,7 +885,7 @@ PeleLM::addSoretTerm( { FArrayBox T_ed; for (MFIter mfi(*a_beta[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { // Get edge centered rhoYs const Box ebx = mfi.nodaltilebox(idim); @@ -902,11 +903,11 @@ PeleLM::addSoretTerm( ebx, [idim, bc_lo_temp, bc_hi_temp, use_harmonic_avg, T_arr, Ted_arr, edomain] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - bool on_lo = + const int idx[3] = {i, j, k}; + const bool on_lo = ((bc_lo_temp == amrex::BCType::ext_dir) && (idx[idim] <= edomain.smallEnd(idim))); - bool on_hi = + const bool on_hi = ((bc_hi_temp == amrex::BCType::ext_dir) && (idx[idim] >= edomain.bigEnd(idim))); cen2edg_cpp( @@ -929,13 +930,13 @@ PeleLM::addSoretTerm( ebx, [need_soret_fluxes, gradT_ar, beta_ar, T, spFlux_ar, spsoretFlux_ar] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { spFlux_ar(i, j, k, n) -= beta_ar(i, j, k, n) * gradT_ar(i, j, k) / T(i, j, k); } if (need_soret_fluxes != 0) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { spsoretFlux_ar(i, j, k, n) = -beta_ar(i, j, k, n) * gradT_ar(i, j, k) / T(i, j, k); } @@ -1016,8 +1017,9 @@ PeleLM::computeSpeciesEnthalpyFlux( lev, 0, NUM_SPECIES, doZeroVisc, bcRecSpec, Enth, addTurbContrib); //------------------------------------------------------------------------ - // Compute \sum_k { \Flux_k * h_k } -#ifdef AMREX_USE_OMP + // Compute \sum_k { \Flux_k * h_k } + +#ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif for (MFIter mfi(Enth, TilingIfNotGPU()); mfi.isValid(); ++mfi) { @@ -1031,7 +1033,7 @@ PeleLM::computeSpeciesEnthalpyFlux( ebox, [spflux_ar, enthflux_ar, enth_ar] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { enthflux_ar(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { enthflux_ar(i, j, k) += spflux_ar(i, j, k, n) * enth_ar(i, j, k, n); } @@ -1059,7 +1061,7 @@ PeleLM::differentialDiffusionUpdate( for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], NUM_SPECIES + 2, nGrow, MFInfo(), factory); @@ -1088,34 +1090,25 @@ PeleLM::differentialDiffusionUpdate( // Get t^{n} data pointer auto* ldata_p = getLevelDataPtr(lev, AmrOldTime); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(advData->Forcing[lev], TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const Box& bx = mfi.tilebox(); - FArrayBox DummyFab(bx, 1); - auto const& rhoY_o = ldata_p->state.const_array(mfi, FIRSTSPEC); - auto const& fY = advData->Forcing[lev].array(mfi, 0); - auto const& aux_o = (m_nAux > 0) - ? ldata_p->auxiliaries.const_array(mfi, 0) - : DummyFab.const_array(); - auto const& fAux = (m_nAux > 0) ? advData->Forcing_aux[lev].array(mfi, 0) - : DummyFab.array(); - amrex::ParallelFor( - bx, [rhoY_o, fY, aux_o, fAux, dt = m_dt, - nAux = m_nAux] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; n++) { - fY(i, j, k, n) *= dt; - fY(i, j, k, n) += rhoY_o(i, j, k, n); - } - for (int n = 0; n < nAux; n++) { - fAux(i, j, k, n) *= dt; - fAux(i, j, k, n) += aux_o(i, j, k, n); - } - }); - } + + auto state_ma = ldata_p->state.const_arrays(); + auto fY_ma = advData->Forcing[lev].arrays(); + auto aux_ma = ldata_p->auxiliaries.const_arrays(); + auto fAux_ma = advData->Forcing_aux[lev].arrays(); + + amrex::ParallelFor(advData->Forcing[lev], [state_ma,fY_ma,aux_ma,fAux_ma,dt_loc = m_dt, nAux = m_nAux] AMREX_GPU_DEVICE(int box_no,int i, int j, int k) noexcept { + Array4 rhoY(state_ma[box_no],FIRSTSPEC); + for (int n = 0; n < NUM_SPECIES; ++n) { + fY_ma[box_no](i,j,k,n) *= dt_loc; + fY_ma[box_no](i,j,k,n) += rhoY(i,j,k,n); + } + for (int n = 0; n < nAux; ++n) { + fAux_ma[box_no](i,j,k,n) *= dt_loc; + fAux_ma[box_no](i,j,k,n) += aux_ma[box_no](i,j,k,n); + } + }); } + Gpu::streamSynchronize(); //------------------------------------------------------------------------ // Species diffusion solve @@ -1137,7 +1130,7 @@ PeleLM::differentialDiffusionUpdate( MultiFab::Copy( spec_boundary[lev], ldata_p->state, FIRSTSPEC, 0, NUM_SPECIES, 1); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { MultiFab::Divide(spec_boundary[lev], ldata_p->state, DENSITY, n, 1, 1); } } @@ -1164,7 +1157,7 @@ PeleLM::differentialDiffusionUpdate( GetVecOfConstPtrs(getDiffusivityVect(AmrNewTime)), 0, bcRecSpec, NUM_SPECIES - NUM_IONS, 0, m_dt, {}); // Ions one by one - for (int n = 0; n < NUM_IONS; n++) { + for (int n = 0; n < NUM_IONS; ++n) { auto bcRecIons = fetchBCRecArray(FIRSTSPEC + NUM_SPECIES - NUM_IONS + n, 1); getDiffusionOp()->diffuse_scalar( GetVecOfPtrs(getSpeciesVect(AmrNewTime)), NUM_SPECIES - NUM_IONS + n, @@ -1285,48 +1278,59 @@ PeleLM::differentialDiffusionUpdate( auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); - FArrayBox DummyFab(bx, 1); - auto const& rhoY = ldata_p->state.array(mfi, FIRSTSPEC); - auto const& dhat = diffData->Dhat[lev].const_array(mfi); - auto const& force = advData->Forcing[lev].const_array(mfi, 0); - auto const& dwbar = (m_use_wbar != 0) - ? diffData->Dwbar[lev].const_array(mfi) - : DummyFab.const_array(); - auto const& dT = (m_use_soret != 0) ? diffData->DT[lev].const_array(mfi) - : DummyFab.const_array(); - auto const& aux = - (m_nAux > 0) ? ldata_p->auxiliaries.array(mfi, 0) : DummyFab.array(); - auto const& dhat_aux = (m_nAux > 0) - ? diffData->Dhat_aux[lev].const_array(mfi) - : DummyFab.const_array(); - auto const& force_aux = (m_nAux > 0) - ? advData->Forcing_aux[lev].const_array(mfi, 0) - : DummyFab.const_array(); - amrex::ParallelFor( - bx, [rhoY, dhat, force, dwbar, dT, aux, dhat_aux, force_aux, - nAux = m_nAux, dt = m_dt, use_wbar = m_use_wbar, - use_soret = - m_use_soret] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; n++) { - rhoY(i, j, k, n) = force(i, j, k, n) + dt * dhat(i, j, k, n); - if (use_wbar != 0) { - rhoY(i, j, k, n) -= dt * dwbar(i, j, k, n); - } - if (use_soret != 0) { - rhoY(i, j, k, n) -= dt * dT(i, j, k, n); - } - } - for (int n = 0; n < nAux; n++) { - aux(i, j, k, n) = force_aux(i, j, k, n) + dt * dhat_aux(i, j, k, n); - } - }); - } + + auto state_ma = ldata_p->state.arrays(); + auto dhat_ma = diffData->Dhat[lev].const_arrays(); + auto force_ma = advData->Forcing[lev].const_arrays(); + auto dwbar_ma = diffData->Dwbar[lev].const_arrays(); + auto dT_ma = diffData->DT[lev].const_arrays(); + auto aux_ma = ldata_p->auxiliaries.arrays(); + auto dhat_aux_ma = diffData->Dhat_aux[lev].const_arrays(); + auto force_aux_ma = advData->Forcing_aux[lev].const_arrays(); + + if(m_use_wbar != 0 && m_use_soret != 0) { + amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dwbar_ma,dT_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rhoY(state_ma[box_no],FIRSTSPEC); + for (int n = 0; n < NUM_SPECIES; ++n) { + rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt_loc * (dhat_ma[box_no](i,j,k,n) - dwbar_ma[box_no](i,j,k,n) - dT_ma[box_no](i,j,k,n)); + } + for (int n = 0; n < nAux; ++n) { + aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt_loc * dhat_aux_ma[box_no](i,j,k,n); + } + }); + } else if (m_use_wbar != 0) { + amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dwbar_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rhoY(state_ma[box_no],FIRSTSPEC); + for (int n = 0; n < NUM_SPECIES; ++n) { + rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt_loc * (dhat_ma[box_no](i,j,k,n) - dwbar_ma[box_no](i,j,k,n)); + } + for (int n = 0; n < nAux; ++n) { + aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt_loc * dhat_aux_ma[box_no](i,j,k,n); + } + }); + } else if (m_use_soret != 0) { + amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dT_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rhoY(state_ma[box_no],FIRSTSPEC); + for (int n = 0; n < NUM_SPECIES; ++n) { + rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt_loc * (dhat_ma[box_no](i,j,k,n) - dT_ma[box_no](i,j,k,n)); + } + for (int n = 0; n < nAux; ++n) { + aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt_loc * dhat_aux_ma[box_no](i,j,k,n); + } + }); + } else { + amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no,int i, int j, int k) noexcept { + Array4 rhoY(state_ma[box_no],FIRSTSPEC); + for (int n = 0; n < NUM_SPECIES; ++n) { + rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt_loc * dhat_ma[box_no](i,j,k,n); + } + for (int n = 0; n < nAux; ++n) { + aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt_loc * dhat_aux_ma[box_no](i,j,k,n); + } + }); + } } + Gpu::streamSynchronize(); // FillPatch species again before going into the enthalpy solve fillPatchSpecies(AmrNewTime); @@ -1497,55 +1501,47 @@ PeleLM::deltaTIter_prepare( std::unique_ptr& diffData) { auto const* leosparm = eos_parms.device_parm(); + const Real dtinv = 1.0 / m_dt; for (int lev = 0; lev <= finest_level; ++lev) { auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldataNew_p->state, TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const Box& bx = mfi.tilebox(); - // RHS pieces - auto const& rhoH_o = ldataOld_p->state.const_array(mfi, RHOH); - auto const& rhoH_n = ldataNew_p->state.const_array(mfi, RHOH); - auto const& force = advData->Forcing[lev].const_array(mfi, NUM_SPECIES); - auto const& fourier = diffData->Dhat[lev].const_array(mfi, NUM_SPECIES); - auto const& diffDiff = - diffData->Dhat[lev].const_array(mfi, NUM_SPECIES + 1); - auto const& rhs = a_rhs[lev]->array(mfi); - const Real dtinv = 1.0 / m_dt; - - // Cpmix - auto const& rho = ldataNew_p->state.const_array(mfi, DENSITY); - auto const& rhoY = ldataNew_p->state.const_array(mfi, FIRSTSPEC); - auto const& T = ldataNew_p->state.const_array(mfi, TEMP); - auto const& rhocp = a_rhoCp[lev]->array(mfi); - - // T save - auto const& tsave = a_Tsave[lev]->array(mfi); - amrex::ParallelFor( - bx, [=, dt = m_dt] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - // Assemble deltaT RHS - rhs(i, j, k) = - dt * ((rhoH_o(i, j, k) - rhoH_n(i, j, k)) * dtinv + force(i, j, k) + - fourier(i, j, k) + diffDiff(i, j, k)); - - // Get \rho * Cp_{mix} - getCpmixGivenRYT(i, j, k, rho, rhoY, T, rhocp, leosparm); - rhocp(i, j, k) *= rho(i, j, k); - - // Save T - tsave(i, j, k) = T(i, j, k); - }); - } + + auto state_old_ma = ldataOld_p->state.const_arrays(); + auto state_new_ma = ldataNew_p->state.const_arrays(); + auto force_ma = advData->Forcing[lev].const_arrays(); + auto dhat_ma = diffData->Dhat[lev].const_arrays(); + auto rhs_ma = a_rhs[lev]->arrays(); + auto rhocp_ma = a_rhoCp[lev]->arrays(); + auto tsave_ma = a_Tsave[lev]->arrays(); + + amrex::ParallelFor(ldataNew_p->state, [state_old_ma,state_new_ma,force_ma,dhat_ma, rhs_ma,rhocp_ma,tsave_ma,dtinv, leosparm,dt=m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rhoH_o(state_old_ma[box_no],RHOH); + Array4 rhoH_n(state_new_ma[box_no],RHOH); + Array4 force(force_ma[box_no],NUM_SPECIES); + Array4 fourier(dhat_ma[box_no],NUM_SPECIES); + Array4 diffDiff(dhat_ma[box_no],NUM_SPECIES+1); + // Assemble deltaT RHS + rhs_ma[box_no](i,j,k) = dt * ((rhoH_o(i, j, k) - rhoH_n(i, j, k)) * dtinv + force(i, j, k) + + fourier(i, j, k) + diffDiff(i, j, k)); + + Array4 rho(state_new_ma[box_no],DENSITY); + Array4 rhoY(state_new_ma[box_no],FIRSTSPEC); + Array4 T(state_new_ma[box_no],TEMP); + // Get \rho * Cp_{mix} + getCpmixGivenRYT(i, j, k, rho, rhoY, T, rhocp_ma[box_no], leosparm); + rhocp_ma[box_no](i, j, k) *= rho(i, j, k); + + // Save T + tsave_ma[box_no](i, j, k) = T(i, j, k); + }); // Set T^{np1} to zero // Include one ghost cell to ensure levelBC at zero for linear solve ldataNew_p->state.setVal(0.0, TEMP, 1, 1); } + Gpu::streamSynchronize(); } void @@ -1667,54 +1663,29 @@ PeleLM::getScalarDiffForce( // Get t^{n} data pointer auto* ldataR_p = getLevelDataReactPtr(lev); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(advData->Forcing[lev], TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const Box& bx = mfi.tilebox(); - FArrayBox DummyFab(bx, 1); - auto const& dn = diffData->Dn[lev].const_array(mfi, 0); - auto const& ddn = diffData->Dn[lev].const_array(mfi, NUM_SPECIES + 1); - auto const& dnp1k = diffData->Dnp1[lev].const_array(mfi, 0); - auto const& ddnp1k = - diffData->Dnp1[lev].const_array(mfi, NUM_SPECIES + 1); - auto const& r = ldataR_p->I_R.const_array(mfi); - auto const& a = advData->AofS[lev].const_array(mfi, FIRSTSPEC); - auto const& extRhoY = m_extSource[lev]->const_array(mfi, FIRSTSPEC); - auto const& extRhoH = m_extSource[lev]->const_array(mfi, RHOH); - auto const& fY = advData->Forcing[lev].array(mfi, 0); - auto const& fT = advData->Forcing[lev].array(mfi, NUM_SPECIES); - auto const& dwbar = (m_use_wbar != 0) - ? diffData->Dwbar[lev].const_array(mfi, 0) - : DummyFab.const_array(); - auto const& dT = (m_use_soret != 0) - ? diffData->DT[lev].const_array(mfi, 0) - : DummyFab.const_array(); - auto const& fAux = (m_nAux > 0) ? advData->Forcing_aux[lev].array(mfi, 0) - : DummyFab.array(); - auto const& a_aux = (m_nAux > 0) - ? advData->AofS_aux[lev].const_array(mfi, 0) - : DummyFab.const_array(); - auto const& dn_aux = (m_nAux > 0) - ? diffData->Dn_aux[lev].const_array(mfi, 0) - : DummyFab.const_array(); - auto const& dnp1k_aux = (m_nAux > 0) - ? diffData->Dnp1_aux[lev].const_array(mfi, 0) - : DummyFab.const_array(); - amrex::ParallelFor( - bx, [dn, ddn, dnp1k, ddnp1k, do_react = m_do_react, r, a, extRhoY, - extRhoH, dwbar, dT, use_wbar = m_use_wbar, use_soret = m_use_soret, - fY, fT, fAux, a_aux, dn_aux, dnp1k_aux, aux_advect_d, - aux_diffuse_d, dp0dt = m_dp0dt, is_closed_ch = m_closed_chamber, - nAux = m_nAux] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - buildDiffusionForcing( - i, j, k, dn, ddn, dnp1k, ddnp1k, r, a, dp0dt, is_closed_ch, - do_react, fY, fT, dwbar, dT, extRhoY, extRhoH, use_wbar, use_soret, - fAux, a_aux, dn_aux, dnp1k_aux, aux_advect_d, aux_diffuse_d, nAux); - }); - } + auto dn_ma = diffData->Dn[lev].const_arrays(); + auto dnp1_ma = diffData->Dnp1[lev].const_arrays(); + auto r_ma = ldataR_p->I_R.const_arrays(); + auto a_ma = advData->AofS[lev].const_arrays(); + auto ext_ma = m_extSource[lev]->const_arrays(); + auto f_ma = advData->Forcing[lev].arrays(); + auto dwbar_ma = diffData->Dwbar[lev].const_arrays(); + auto dT_ma = diffData->DT[lev].const_arrays(); + auto f_aux_ma = advData->Forcing_aux[lev].arrays(); + auto a_aux_ma = advData->AofS_aux[lev].const_arrays(); + auto dn_aux_ma = diffData->Dn_aux[lev].const_arrays(); + auto dnp1_aux_ma = diffData->Dnp1_aux[lev].const_arrays(); + + amrex::ParallelFor(advData->Forcing[lev],[dn_ma,dnp1_ma,r_ma,a_ma,ext_ma,f_ma, dwbar_ma, dT_ma, f_aux_ma, a_aux_ma, dn_aux_ma, dnp1_aux_ma,do_react = m_do_react,use_wbar = m_use_wbar, use_soret = m_use_soret, dp0dt = m_dp0dt,is_closed_ch = m_closed_chamber, nAux = m_nAux,aux_advect_d, aux_diffuse_d] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 ddn(dn_ma[box_no],NUM_SPECIES+1); + Array4 ddnp1(dnp1_ma[box_no],NUM_SPECIES+1); + Array4 extRhoY(ext_ma[box_no],FIRSTSPEC); + Array4 extRhoH(ext_ma[box_no],RHOH); + Array4 fT(f_ma[box_no],NUM_SPECIES); + buildDiffusionForcing(i, j, k, dn_ma[box_no], ddn, dnp1_ma[box_no], ddnp1, r_ma[box_no], a_ma[box_no], dp0dt, is_closed_ch,do_react, f_ma[box_no], fT, dwbar_ma[box_no], dT_ma[box_no], extRhoY, extRhoH, use_wbar, use_soret, f_aux_ma[box_no], a_aux_ma[box_no], dn_aux_ma[box_no], dnp1_aux_ma[box_no] , aux_advect_d, aux_diffuse_d, nAux); + }); } + Gpu::streamSynchronize(); // Fill forcing ghost cells if (advData->Forcing[0].nGrow() > 0) { @@ -1732,8 +1703,8 @@ void PeleLM::computeDivTau( const TimeStamp& a_time, const Vector& a_divtau, - int use_density, - Real scale) + const int use_density, + const Real scale) { BL_PROFILE("PeleLMeX::computeDivTau()"); // Get the density component BCRec to get viscosity on faces @@ -1825,7 +1796,7 @@ PeleLM::getDiffusionTensorOpBC( r[0][idim] = LinOpBCType::Periodic;, r[1][idim] = LinOpBCType::Periodic; , r[2][idim] = LinOpBCType::Periodic;); } else { - for (int dir = 0; dir < AMREX_SPACEDIM; dir++) { + for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { auto amrexbc = (a_side == Orientation::low) ? a_bc[dir].lo(idim) : a_bc[dir].hi(idim); if (amrexbc == amrex::BCType::ext_dir) { From 9d20ed6cf104fc57ee16e0de1b7f4ab632be105d Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 29 Jun 2025 13:52:00 +0200 Subject: [PATCH 07/87] emplace and diffusion --- Source/PeleLMeX_Data.cpp | 80 ++++---- Source/PeleLMeX_Diffusion.cpp | 32 ++-- Source/PeleLMeX_DiffusionOp.H | 74 ++++---- Source/PeleLMeX_DiffusionOp.cpp | 315 +++++++++++++++----------------- 4 files changed, 236 insertions(+), 265 deletions(-) diff --git a/Source/PeleLMeX_Data.cpp b/Source/PeleLMeX_Data.cpp index 9f90643fa..745bf8781 100644 --- a/Source/PeleLMeX_Data.cpp +++ b/Source/PeleLMeX_Data.cpp @@ -102,75 +102,71 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( const int is_init) { if (is_init != 0) { // All I need is a container for a single diffusion term - // Resize Vectors - Dnp1.resize(a_finestLevel + 1); - + Dnp1.reserve(a_finestLevel+1); // Define MFs for (int lev = 0; lev <= a_finestLevel; ++lev) { - Dnp1[lev].define( + Dnp1.emplace_back( ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, MFInfo(), *factory[lev]); } - if (a_nAux > 0) { - Dnp1_aux.resize(a_finestLevel + 1); + Dnp1_aux.reserve(a_finestLevel+1); for (int lev = 0; lev <= a_finestLevel; ++lev) { - Dnp1_aux[lev].define( + Dnp1_aux.emplace_back( ba[lev], dm[lev], a_nAux, nGrowAdv, MFInfo(), *factory[lev]); } } } else { - // Resize Vectors - Dn.resize(a_finestLevel + 1); - Dnp1.resize(a_finestLevel + 1); - Dhat.resize(a_finestLevel + 1); + // Reserve/resize Vectors + Dn.reserve(a_finestLevel + 1); + Dnp1.reserve(a_finestLevel + 1); + Dhat.reserve(a_finestLevel + 1); if (a_nAux > 0) { - Dn_aux.resize(a_finestLevel + 1); - Dnp1_aux.resize(a_finestLevel + 1); - Dhat_aux.resize(a_finestLevel + 1); + Dn_aux.reserve(a_finestLevel + 1); + Dnp1_aux.reserve(a_finestLevel + 1); + Dhat_aux.reserve(a_finestLevel + 1); } if (a_use_wbar != 0) { - Dwbar.resize(a_finestLevel + 1); + Dwbar.reserve(a_finestLevel + 1); wbar_fluxes.resize(a_finestLevel + 1); } if (a_use_soret != 0) { - DT.resize(a_finestLevel + 1); + DT.reserve(a_finestLevel + 1); soret_fluxes.resize(a_finestLevel + 1); } - + // Define MFs for (int lev = 0; lev <= a_finestLevel; ++lev) { - Dn[lev].define( + Dn.emplace_back( ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, MFInfo(), *factory[lev]); - Dnp1[lev].define( + Dnp1.emplace_back( ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, MFInfo(), *factory[lev]); - Dhat[lev].define( + Dhat.emplace_back( ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, MFInfo(), *factory[lev]); if (a_use_wbar != 0) { - Dwbar[lev].define( + Dwbar.emplace_back( ba[lev], dm[lev], NUM_SPECIES, nGrowAdv, MFInfo(), *factory[lev]); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - const BoxArray& faceba = - amrex::convert(ba[lev], IntVect::TheDimensionVector(idim)); + const BoxArray& faceba = + amrex::convert(ba[lev], IntVect::TheDimensionVector(idim)); wbar_fluxes[lev][idim].define( faceba, dm[lev], NUM_SPECIES, 0, MFInfo(), *factory[lev]); } } if (a_use_soret != 0) { - DT[lev].define( - ba[lev], dm[lev], NUM_SPECIES, nGrowAdv, MFInfo(), *factory[lev]); + DT.emplace_back(ba[lev], dm[lev], NUM_SPECIES, nGrowAdv, MFInfo(), *factory[lev]); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const BoxArray& faceba = amrex::convert(ba[lev], IntVect::TheDimensionVector(idim)); soret_fluxes[lev][idim].define( - faceba, dm[lev], NUM_SPECIES, 0, MFInfo(), *factory[lev]); + faceba, dm[lev], NUM_SPECIES, 0, MFInfo(), *factory[lev]); } } if (a_nAux > 0) { - Dn_aux[lev].define( + Dn_aux.emplace_back( ba[lev], dm[lev], a_nAux, nGrowAdv, MFInfo(), *factory[lev]); - Dnp1_aux[lev].define( + Dnp1_aux.emplace_back( ba[lev], dm[lev], a_nAux, nGrowAdv, MFInfo(), *factory[lev]); - Dhat_aux[lev].define( + Dhat_aux.emplace_back( ba[lev], dm[lev], a_nAux, nGrowAdv, MFInfo(), *factory[lev]); } } @@ -189,15 +185,15 @@ PeleLM::AdvanceAdvData::AdvanceAdvData( { // Resize Vectors umac.resize(a_finestLevel + 1); - AofS.resize(a_finestLevel + 1); + AofS.reserve(a_finestLevel + 1); if (a_incompressible == 0) { - chi.resize(a_finestLevel + 1); - Forcing.resize(a_finestLevel + 1); - mac_divu.resize(a_finestLevel + 1); + chi.reserve(a_finestLevel + 1); + Forcing.reserve(a_finestLevel + 1); + mac_divu.reserve(a_finestLevel + 1); } if (a_nAux > 0) { - AofS_aux.resize(a_finestLevel + 1); - Forcing_aux.resize(a_finestLevel + 1); + AofS_aux.reserve(a_finestLevel + 1); + Forcing_aux.reserve(a_finestLevel + 1); } #ifdef PELE_USE_PLASMA uDrift.resize(a_finestLevel + 1); @@ -216,27 +212,27 @@ PeleLM::AdvanceAdvData::AdvanceAdvData( #endif } if (a_incompressible != 0) { - AofS[lev].define( + AofS.emplace_back( ba[lev], dm[lev], AMREX_SPACEDIM, 0, MFInfo(), *factory[lev]); } else { - AofS[lev].define(ba[lev], dm[lev], NVAR, 0, MFInfo(), *factory[lev]); + AofS.emplace_back(ba[lev], dm[lev], NVAR, 0, MFInfo(), *factory[lev]); chi[lev].define(ba[lev], dm[lev], 1, 1, MFInfo(), *factory[lev]); #ifdef PELE_USE_PLASMA - Forcing[lev].define( + Forcing.emplace_back( ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, MFInfo(), *factory[lev]); // Species + TEMP + nE #else - Forcing[lev].define( + Forcing.emplace_back( ba[lev], dm[lev], NUM_SPECIES + 1, nGrowAdv, MFInfo(), *factory[lev]); // Species + TEMP #endif - mac_divu[lev].define( + mac_divu.emplace_back( ba[lev], dm[lev], 1, nGrowAdv, MFInfo(), *factory[lev]); } if (a_nAux > 0) { - AofS_aux[lev].define( + AofS_aux.emplace_back( ba[lev], dm[lev], a_nAux, 0, MFInfo(), *factory[lev]); - Forcing_aux[lev].define( + Forcing_aux.emplace_back( ba[lev], dm[lev], a_nAux, nGrowAdv, MFInfo(), *factory[lev]); } } diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index e824e2e20..9a0f581c1 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -427,7 +427,7 @@ PeleLM::correctIsothermalBoundary( [flux_wbar, flux_soret, rhoD_ec, boundary_ar, idim, edomain, bc_lo, bc_hi, use_wbar = m_use_wbar, need_explicit_fluxes] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - const int idx[3] = {i, j, k}; + int idx[3] = {i, j, k}; const bool on_lo = (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || bc_lo == BoundaryCondition::BCSlipWallIsotherm) && (idx[idim] <= edomain.smallEnd(idim)); @@ -1096,14 +1096,14 @@ PeleLM::differentialDiffusionUpdate( auto aux_ma = ldata_p->auxiliaries.const_arrays(); auto fAux_ma = advData->Forcing_aux[lev].arrays(); - amrex::ParallelFor(advData->Forcing[lev], [state_ma,fY_ma,aux_ma,fAux_ma,dt_loc = m_dt, nAux = m_nAux] AMREX_GPU_DEVICE(int box_no,int i, int j, int k) noexcept { + amrex::ParallelFor(advData->Forcing[lev], [state_ma,fY_ma,aux_ma,fAux_ma,dt = m_dt, nAux = m_nAux] AMREX_GPU_DEVICE(int box_no,int i, int j, int k) noexcept { Array4 rhoY(state_ma[box_no],FIRSTSPEC); for (int n = 0; n < NUM_SPECIES; ++n) { - fY_ma[box_no](i,j,k,n) *= dt_loc; + fY_ma[box_no](i,j,k,n) *= dt; fY_ma[box_no](i,j,k,n) += rhoY(i,j,k,n); } for (int n = 0; n < nAux; ++n) { - fAux_ma[box_no](i,j,k,n) *= dt_loc; + fAux_ma[box_no](i,j,k,n) *= dt; fAux_ma[box_no](i,j,k,n) += aux_ma[box_no](i,j,k,n); } }); @@ -1289,43 +1289,43 @@ PeleLM::differentialDiffusionUpdate( auto force_aux_ma = advData->Forcing_aux[lev].const_arrays(); if(m_use_wbar != 0 && m_use_soret != 0) { - amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dwbar_ma,dT_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dwbar_ma,dT_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { Array4 rhoY(state_ma[box_no],FIRSTSPEC); for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt_loc * (dhat_ma[box_no](i,j,k,n) - dwbar_ma[box_no](i,j,k,n) - dT_ma[box_no](i,j,k,n)); + rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt * (dhat_ma[box_no](i,j,k,n) - dwbar_ma[box_no](i,j,k,n) - dT_ma[box_no](i,j,k,n)); } for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt_loc * dhat_aux_ma[box_no](i,j,k,n); + aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt * dhat_aux_ma[box_no](i,j,k,n); } }); } else if (m_use_wbar != 0) { - amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dwbar_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dwbar_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { Array4 rhoY(state_ma[box_no],FIRSTSPEC); for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt_loc * (dhat_ma[box_no](i,j,k,n) - dwbar_ma[box_no](i,j,k,n)); + rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt * (dhat_ma[box_no](i,j,k,n) - dwbar_ma[box_no](i,j,k,n)); } for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt_loc * dhat_aux_ma[box_no](i,j,k,n); + aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt * dhat_aux_ma[box_no](i,j,k,n); } }); } else if (m_use_soret != 0) { - amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dT_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dT_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { Array4 rhoY(state_ma[box_no],FIRSTSPEC); for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt_loc * (dhat_ma[box_no](i,j,k,n) - dT_ma[box_no](i,j,k,n)); + rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt * (dhat_ma[box_no](i,j,k,n) - dT_ma[box_no](i,j,k,n)); } for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt_loc * dhat_aux_ma[box_no](i,j,k,n); + aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt * dhat_aux_ma[box_no](i,j,k,n); } }); } else { - amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no,int i, int j, int k) noexcept { + amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no,int i, int j, int k) noexcept { Array4 rhoY(state_ma[box_no],FIRSTSPEC); for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt_loc * dhat_ma[box_no](i,j,k,n); + rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt * dhat_ma[box_no](i,j,k,n); } for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt_loc * dhat_aux_ma[box_no](i,j,k,n); + aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt * dhat_aux_ma[box_no](i,j,k,n); } }); } diff --git a/Source/PeleLMeX_DiffusionOp.H b/Source/PeleLMeX_DiffusionOp.H index ac4591c4a..fbb6b1cdb 100644 --- a/Source/PeleLMeX_DiffusionOp.H +++ b/Source/PeleLMeX_DiffusionOp.H @@ -23,87 +23,87 @@ public: void diffuse_scalar( amrex::Vector const& a_phi, - int phi_comp, + const int phi_comp, amrex::Vector const& a_rhs, - int rhs_comp, + const int rhs_comp, amrex::Vector> const& a_fluxes, - int flux_comp, + const int flux_comp, amrex::Vector const& a_acoeff, amrex::Vector const& a_density, amrex::Vector const& a_bcoeff, - int bcoeff_comp, + const int bcoeff_comp, amrex::Vector a_bcrec, - int ncomp, - int isPoissonSolve, - amrex::Real dt, + const int ncomp, + const int isPoissonSolve, + const amrex::Real dt, amrex::Vector const& a_boundary); #ifdef AMREX_USE_EB void diffuse_scalar( amrex::Vector const& a_phi, - int phi_comp, + const int phi_comp, amrex::Vector const& a_phiEB, - int phiEB_comp, + const int phiEB_comp, amrex::Vector const& a_rhs, - int rhs_comp, + const int rhs_comp, amrex::Vector> const& a_fluxes, - int flux_comp, + const int flux_comp, amrex::Vector const& a_acoeff, amrex::Vector const& a_density, amrex::Vector const& a_bcoeff, - int bcoeff_comp, + const int bcoeff_comp, amrex::Vector const& a_bcoeffEB, - int bcoeffEB_comp, + const int bcoeffEB_comp, amrex::Vector a_bcrec, - int ncomp, - int isPoissonSolve, - amrex::Real dt, + const int ncomp, + const int isPoissonSolve, + const amrex::Real dt, amrex::Vector const& a_boundary); #endif void computeDiffLap( amrex::Vector const& laps, - int lap_comp, + const int lap_comp, amrex::Vector const& phi, - int phi_comp, + const int phi_comp, amrex::Vector const& bcoeff, - int bcoeff_comp, + const int bcoeff_comp, amrex::Vector a_bcrec, - int ncomp); + const int ncomp); void computeDiffFluxes( amrex::Vector> const& - a_fluxes, - int flux_comp, + a_fluxes, + const int flux_comp, amrex::Vector const& a_phi, - int phi_comp, + const int phi_comp, amrex::Vector const& a_density, amrex::Vector const& a_bcoeff, - int bcoeff_comp, + const int bcoeff_comp, amrex::Vector a_bcrec, - int ncomp, - int do_avgDown, + const int ncomp, + const int do_avgDown, amrex::Vector const& a_boundary); #ifdef AMREX_USE_EB void computeDiffFluxes( amrex::Vector> const& a_fluxes, - int flux_comp, + const int flux_comp, amrex::Vector const& a_EBflux, - int ebflux_comp, + const int ebflux_comp, amrex::Vector const& a_phi, - int phi_comp, + const int phi_comp, amrex::Vector const& a_density, amrex::Vector const& a_bcoeff, - int bcoeff_comp, + const int bcoeff_comp, amrex::Vector const& a_EBvalue, amrex::Vector const& a_EBbcoeff, amrex::Vector a_bcrec, - int ncomp, - int do_avgDown, + const int ncomp, + const int do_avgDown, amrex::Vector const& a_boundary); #endif @@ -113,14 +113,14 @@ public: const amrex::Vector& a_phi, const amrex::Vector& a_boundary, const amrex::BCRec& a_bcrec, - int do_avgDown, + const int do_avgDown, int comp = 0) const; void avgDownFluxes( amrex::Vector> const& a_fluxes, - int flux_comp, - int ncomp) const; + const int flux_comp, + const int ncomp) const; void readParameters(); @@ -178,14 +178,14 @@ public: amrex::Vector const& a_density, amrex::Vector const& a_beta, const amrex::BCRec& a_bcrec, - amrex::Real scale); + const amrex::Real scale); void diffuse_velocity( amrex::Vector const& a_vel, amrex::Vector const& a_density, amrex::Vector const& a_beta, const amrex::BCRec& a_bcrec, - amrex::Real dt); + const amrex::Real dt); void computeGradientTensor( amrex::Vector> const& diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index d5ab45a0f..3c59c936a 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -13,7 +13,7 @@ using namespace amrex; //--------------------------------------------------------------------------------------- // Diffusion Operator -DiffusionOp::DiffusionOp(PeleLM* a_pelelm, int ncomp) +DiffusionOp::DiffusionOp(PeleLM* a_pelelm, const int ncomp) : m_pelelm(a_pelelm), m_ncomp(ncomp) { BL_PROFILE("DiffusionOp::DiffusionOp()"); @@ -94,30 +94,30 @@ DiffusionOp::DiffusionOp(PeleLM* a_pelelm, int ncomp) void DiffusionOp::diffuse_scalar( Vector const& a_phi, - int phi_comp, + const int phi_comp, Vector const& a_rhs, - int rhs_comp, + const int rhs_comp, Vector> const& a_flux, - int flux_comp, + const int flux_comp, Vector const& a_acoeff, Vector const& a_density, Vector const& a_bcoeff, - int bcoeff_comp, + const int bcoeff_comp, Vector a_bcrec, - int ncomp, - int isPoissonSolve, - Real a_dt, + const int ncomp, + const int isPoissonSolve, + const Real a_dt, Vector const& a_boundary) { BL_PROFILE("DiffusionOp::diffuse_scalar()"); //---------------------------------------------------------------- // What are we dealing with ? - int have_density = (a_density.empty()) ? 0 : 1; - int have_fluxes = (a_flux.empty()) ? 0 : 1; - int have_acoeff = (a_acoeff.empty()) ? 0 : 1; - int have_bcoeff = (a_bcoeff.empty()) ? 0 : 1; - int have_boundary = (a_boundary.empty()) ? 0 : 1; + const int have_density = (a_density.empty()) ? 0 : 1; + const int have_fluxes = (a_flux.empty()) ? 0 : 1; + const int have_acoeff = (a_acoeff.empty()) ? 0 : 1; + const int have_bcoeff = (a_bcoeff.empty()) ? 0 : 1; + const int have_boundary = (a_boundary.empty()) ? 0 : 1; //---------------------------------------------------------------- // Checks @@ -132,7 +132,7 @@ DiffusionOp::diffuse_scalar( AMREX_ASSERT(a_bcrec.size() >= ncomp); } - int finest_level = m_pelelm->finestLevel(); + const int finest_level = m_pelelm->finestLevel(); //---------------------------------------------------------------- // Duplicate phi_old to include rho scaling @@ -176,8 +176,8 @@ DiffusionOp::diffuse_scalar( // => \alpha = 1.0, A is a_acoeff if provided, 1.0 otherwise // => \beta = a_dt, B face centered diffusivity bcoeff^{np1,k} - Real alpha = (isPoissonSolve) != 0 ? 0.0 : 1.0; - Real beta = a_dt; + const Real alpha = (isPoissonSolve) != 0 ? 0.0 : 1.0; + const Real beta = a_dt; m_scal_solve_op->setScalars(alpha, beta); for (int lev = 0; lev <= finest_level; ++lev) { if (have_acoeff != 0) { @@ -212,8 +212,8 @@ DiffusionOp::diffuse_scalar( } if (have_bcoeff != 0) { - int doZeroVisc = 1; - int addTurbContrib = 1; + constexpr int doZeroVisc = 1; + constexpr int addTurbContrib = 1; Vector subBCRec = { a_bcrec.begin() + comp, a_bcrec.begin() + comp + m_ncomp}; Array bcoeff_ec = m_pelelm->getDiffusivity( @@ -280,29 +280,23 @@ DiffusionOp::diffuse_scalar( // Copy the results of the solve back into a_phi // Times rho{np1,kp1} if needed // Don't touch the ghost cells - for (int lev = 0; lev <= finest_level; ++lev) { -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(phi[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); - auto const& a_phi_arr = a_phi[lev]->array(mfi, phi_comp); - auto const& a_rho_arr = - (have_density) != 0 - ? a_density[lev]->const_array(mfi) - : a_phi[lev]->const_array(mfi); // Get dummy Array4 if no density - auto const& phi_arr = phi[lev].const_array(mfi); - amrex::ParallelFor( - bx, ncomp, - [a_phi_arr, a_rho_arr, phi_arr, - have_density] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - if (have_density != 0) { - a_phi_arr(i, j, k, n) = phi_arr(i, j, k, n) * a_rho_arr(i, j, k); - } else { - a_phi_arr(i, j, k, n) = phi_arr(i, j, k, n); - } - }); + + if (!have_density) { + for (int lev = 0; lev <= finest_level; ++lev) { + MultiFab::Copy(*a_phi[lev],phi[lev],0,0,ncomp,0); + } + } else { + for (int lev = 0; lev <= finest_level; ++lev) { + auto a_phi_ma = a_phi[lev]->arrays(); + auto phi_ma = phi[lev].const_arrays(); + auto a_rho_ma = a_density[lev]->const_arrays(); + amrex::ParallelFor(phi[lev], [a_phi_ma,a_rho_ma,phi_ma,ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < ncomp; ++n) { + a_phi_ma[box_no](i,j,k,n) = phi_ma[box_no](i,j,k,n) * a_rho_ma[box_no](i,j,k); + } + }); } + Gpu::streamSynchronize(); } } @@ -310,34 +304,34 @@ DiffusionOp::diffuse_scalar( void DiffusionOp::diffuse_scalar( Vector const& a_phi, - int phi_comp, + const int phi_comp, Vector const& a_phiEB, - int /*phiEB_comp*/, + const int /*phiEB_comp*/, Vector const& a_rhs, - int rhs_comp, + const int rhs_comp, Vector> const& a_flux, - int flux_comp, + const int flux_comp, Vector const& a_acoeff, Vector const& a_density, Vector const& a_bcoeff, - int bcoeff_comp, + const int bcoeff_comp, Vector const& a_bcoeffEB, - int /*bcoeffEB_comp*/, + const int /*bcoeffEB_comp*/, Vector a_bcrec, - int ncomp, - int isPoissonSolve, - Real a_dt, + const int ncomp, + const int isPoissonSolve, + const Real a_dt, Vector const& a_boundary) { BL_PROFILE("DiffusionOp::diffuse_scalar()"); //---------------------------------------------------------------- // What are we dealing with ? - int have_density = (a_density.empty()) ? 0 : 1; - int have_fluxes = (a_flux.empty()) ? 0 : 1; - int have_acoeff = (a_acoeff.empty()) ? 0 : 1; - int have_bcoeff = (a_bcoeff.empty()) ? 0 : 1; - int have_boundary = (a_boundary.empty()) ? 0 : 1; + const int have_density = (a_density.empty()) ? 0 : 1; + const int have_fluxes = (a_flux.empty()) ? 0 : 1; + const int have_acoeff = (a_acoeff.empty()) ? 0 : 1; + const int have_bcoeff = (a_bcoeff.empty()) ? 0 : 1; + const int have_boundary = (a_boundary.empty()) ? 0 : 1; //---------------------------------------------------------------- // Checks @@ -352,7 +346,7 @@ DiffusionOp::diffuse_scalar( AMREX_ASSERT(a_bcrec.size() >= ncomp); } - int finest_level = m_pelelm->finestLevel(); + const int finest_level = m_pelelm->finestLevel(); //---------------------------------------------------------------- // Duplicate phi_old to include rho scaling @@ -396,8 +390,8 @@ DiffusionOp::diffuse_scalar( // => \alpha = 1.0, A is a_acoeff if provided, 1.0 otherwise // => \beta = a_dt, B face centered diffusivity bcoeff^{np1,k} - Real alpha = (isPoissonSolve) != 0 ? 0.0 : 1.0; - Real beta = a_dt; + const Real alpha = (isPoissonSolve) != 0 ? 0.0 : 1.0; + const Real beta = a_dt; m_scal_solve_op->setScalars(alpha, beta); for (int lev = 0; lev <= finest_level; ++lev) { if (have_acoeff != 0) { @@ -432,7 +426,7 @@ DiffusionOp::diffuse_scalar( } if (have_bcoeff != 0) { - int doZeroVisc = 1; + constexpr int doZeroVisc = 1; Vector subBCRec = { a_bcrec.begin() + comp, a_bcrec.begin() + comp + m_ncomp}; Array bcoeff_ec = m_pelelm->getDiffusivity( @@ -492,43 +486,37 @@ DiffusionOp::diffuse_scalar( // Copy the results of the solve back into a_phi // Times rho{np1,kp1} if needed // Don't touch the ghost cells - for (int lev = 0; lev <= finest_level; ++lev) { -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(phi[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); - auto const& a_phi_arr = a_phi[lev]->array(mfi, phi_comp); - auto const& a_rho_arr = - (have_density) != 0 - ? a_density[lev]->const_array(mfi) - : a_phi[lev]->const_array(mfi); // Get dummy Array4 if no density - auto const& phi_arr = phi[lev].const_array(mfi); - amrex::ParallelFor( - bx, ncomp, - [a_phi_arr, a_rho_arr, phi_arr, - have_density] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - if (have_density != 0) { - a_phi_arr(i, j, k, n) = phi_arr(i, j, k, n) * a_rho_arr(i, j, k); - } else { - a_phi_arr(i, j, k, n) = phi_arr(i, j, k, n); - } - }); + + if (!have_density) { + for (int lev = 0; lev <= finest_level; ++lev) { + MultiFab::Copy(a_phi[lev],phi[lev],0,0,ncomp,0); } - } + } else { + for (int lev = 0; lev <= finest_level; ++lev) { + auto a_phi_ma = a_phi[lev]->arrays(); + auto phi_ma = phi[lev].const_arrays(); + auto a_rho_ma = a_density[lev]->const_arrays(); + amrex::ParallelFor(phi[lev], [a_phi_ma,a_rho_ma,phi_ma,ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < ncomp; ++n) { + a_phi_ma[box_no](i,j,k,n) = phi_ma[box_no](i,j,k,n) * a_rho_ma[box_no](i,j,k); + } + }); + } + Gpu::streamSynchronize(); + } } #endif void DiffusionOp::computeDiffLap( Vector const& a_laps, - int lap_comp, + const int lap_comp, Vector const& a_phi, - int phi_comp, + const int phi_comp, Vector const& a_bcoeff, - int bcoeff_comp, + const int bcoeff_comp, Vector a_bcrec, - int ncomp) + const int ncomp) { BL_PROFILE("DiffusionOp::computeDiffLap()"); @@ -540,7 +528,7 @@ DiffusionOp::computeDiffLap( AMREX_ASSERT(a_bcoeff[0]->nComp() >= bcoeff_comp + ncomp); AMREX_ASSERT(a_bcrec.size() >= ncomp); - int finest_level = m_pelelm->finestLevel(); + const int finest_level = m_pelelm->finestLevel(); // Copy phi with 1 ghost cell Vector phi(finest_level + 1); @@ -570,8 +558,8 @@ DiffusionOp::computeDiffLap( laps.emplace_back( *a_laps[lev], amrex::make_alias, lap_comp + comp, m_ncomp); component.emplace_back(phi[lev], amrex::make_alias, comp, m_ncomp); - int doZeroVisc = 0; - int addTurbContrib = 0; + constexpr int doZeroVisc = 0; + constexpr int addTurbContrib = 0; Vector subBCRec = { a_bcrec.begin() + comp, a_bcrec.begin() + comp + m_ncomp}; Array bcoeff_ec = m_pelelm->getDiffusivity( @@ -595,15 +583,15 @@ DiffusionOp::computeDiffLap( void DiffusionOp::computeDiffFluxes( Vector> const& a_flux, - int flux_comp, + const int flux_comp, Vector const& a_phi, - int phi_comp, + const int phi_comp, Vector const& a_density, Vector const& a_bcoeff, - int bcoeff_comp, + const int bcoeff_comp, Vector a_bcrec, - int ncomp, - int do_avgDown, + const int ncomp, + const int do_avgDown, Vector const& a_boundary) { BL_PROFILE("DiffusionOp::computeDiffFluxes()"); @@ -616,10 +604,10 @@ DiffusionOp::computeDiffFluxes( AMREX_ASSERT(a_bcoeff[0]->nComp() >= bcoeff_comp + ncomp); AMREX_ASSERT(a_bcrec.size() >= ncomp); - int finest_level = m_pelelm->finestLevel(); + const int finest_level = m_pelelm->finestLevel(); - int have_density = (a_density.empty()) ? 0 : 1; - int have_boundary = (a_boundary.empty()) ? 0 : 1; + const int have_density = (a_density.empty()) ? 0 : 1; + const int have_boundary = (a_boundary.empty()) ? 0 : 1; // Duplicate phi since it is modified by the LinOp // and if have_density -> divide by density @@ -657,8 +645,8 @@ DiffusionOp::computeDiffFluxes( // => \beta = -1.0, B face centered diffusivity a_bcoeff // Set scalars \alpha & \beta - Real alpha = 0.0; - Real beta = -1.0; + constexpr Real alpha = 0.0; + constexpr Real beta = -1.0; m_scal_apply_op->setScalars(alpha, beta); // Get fluxes on a m_ncomp component(s) basis @@ -688,8 +676,8 @@ DiffusionOp::computeDiffFluxes( boundary.emplace_back(phi[lev], amrex::make_alias, comp, m_ncomp); } - int doZeroVisc = 1; - int addTurbContrib = 1; + constexpr int doZeroVisc = 1; + constexpr int addTurbContrib = 1; Vector subBCRec = { a_bcrec.begin() + comp, a_bcrec.begin() + comp + m_ncomp}; Array bcoeff_ec = m_pelelm->getDiffusivity( @@ -732,19 +720,19 @@ DiffusionOp::computeDiffFluxes( void DiffusionOp::computeDiffFluxes( Vector> const& a_flux, - int flux_comp, + const int flux_comp, Vector const& a_EBflux, - int ebflux_comp, + const int ebflux_comp, Vector const& a_phi, - int phi_comp, + const int phi_comp, Vector const& a_density, Vector const& a_bcoeff, - int bcoeff_comp, + const int bcoeff_comp, Vector const& a_EBvalue, Vector const& a_EBbcoeff, Vector a_bcrec, - int ncomp, - int do_avgDown, + const int ncomp, + const int do_avgDown, Vector const& a_boundary) { BL_PROFILE("DiffusionOp::computeDiffFluxes()"); @@ -757,10 +745,10 @@ DiffusionOp::computeDiffFluxes( AMREX_ASSERT(a_bcoeff[0]->nComp() >= bcoeff_comp + ncomp); AMREX_ASSERT(a_bcrec.size() >= ncomp); - int finest_level = m_pelelm->finestLevel(); + const int finest_level = m_pelelm->finestLevel(); - int have_density = (a_density.empty()) ? 0 : 1; - int have_boundary = (a_boundary.empty()) ? 0 : 1; + const int have_density = (a_density.empty()) ? 0 : 1; + const int have_boundary = (a_boundary.empty()) ? 0 : 1; // Duplicate phi since it is modified by the LinOp // and if have_density -> divide by density @@ -798,8 +786,8 @@ DiffusionOp::computeDiffFluxes( // => \beta = -1.0, B face centered diffusivity a_bcoeff // Set scalars \alpha & \beta - Real alpha = 0.0; - Real beta = -1.0; + constexpr Real alpha = 0.0; + constexpr Real beta = -1.0; m_scal_apply_op->setScalars(alpha, beta); // Get fluxes on a m_ncomp component(s) basis @@ -833,7 +821,7 @@ DiffusionOp::computeDiffFluxes( } else { boundary.emplace_back(phi[lev], amrex::make_alias, comp, m_ncomp); } - int doZeroVisc = 1; + constexpr int doZeroVisc = 1; Vector subBCRec = { a_bcrec.begin() + comp, a_bcrec.begin() + comp + m_ncomp}; Array bcoeff_ec = m_pelelm->getDiffusivity( @@ -869,13 +857,13 @@ DiffusionOp::computeGradient( const Vector& a_phi, const Vector& a_boundary, const BCRec& a_bcrec, - int do_avgDown, - int comp) const + const int do_avgDown, + const int comp) const { BL_PROFILE("DiffusionOp::computeGradient()"); // Do I need the Laplacian out ? - int need_laplacian = (a_laps.empty()) ? 0 : 1; + const int need_laplacian = (a_laps.empty()) ? 0 : 1; // Force updating the operator for (int lev = 0; lev <= m_pelelm->finestLevel(); ++lev) { m_gradient_op->setBCoeffs(lev, -1.0); @@ -885,8 +873,8 @@ DiffusionOp::computeGradient( AMREX_ASSERT(a_phi[0]->nComp() > comp); AMREX_ASSERT(a_phi[0]->nGrow() >= 1); - int finest_level = m_pelelm->finestLevel(); - int have_boundary = (a_boundary.empty()) ? 0 : 1; + const int finest_level = m_pelelm->finestLevel(); + const int have_boundary = (a_boundary.empty()) ? 0 : 1; // Set domainBCs m_gradient_op->setDomainBC( @@ -939,11 +927,11 @@ DiffusionOp::computeGradient( void DiffusionOp::avgDownFluxes( const Vector>& a_fluxes, - int flux_comp, - int ncomp) const + const int flux_comp, + const int ncomp) const { - int finest_level = m_pelelm->finestLevel(); + const int finest_level = m_pelelm->finestLevel(); for (int lev = finest_level; lev > 0; --lev) { // Get the requested components only @@ -992,7 +980,7 @@ DiffusionTensorOp::DiffusionTensorOp(PeleLM* a_pelelm) : m_pelelm(a_pelelm) readParameters(); - int finest_level = m_pelelm->finestLevel(); + const int finest_level = m_pelelm->finestLevel(); auto bcRecVel = m_pelelm->fetchBCRecArray(VELX, AMREX_SPACEDIM); @@ -1054,7 +1042,7 @@ DiffusionTensorOp::computeGradientTensor( // in 3D: dU/dx, dV/dx, dW/dx, dU/dy, dV/dy, dW/dy, dU/dz, dV/dz, // dW/dz - int finest_level = m_pelelm->finestLevel(); + const int finest_level = m_pelelm->finestLevel(); // Duplicate vel since it may be modified by the TensorOp Vector vel(finest_level + 1); @@ -1102,11 +1090,11 @@ DiffusionTensorOp::compute_divtau( Vector const& a_density, Vector const& a_beta, const BCRec& a_bcrec, - Real scale) + const Real scale) { - int finest_level = m_pelelm->finestLevel(); + const int finest_level = m_pelelm->finestLevel(); - int have_density = (a_density.empty()) ? 0 : 1; + const int have_density = (a_density.empty()) ? 0 : 1; // Duplicate vel since it is modified by the TensorOp Vector vel(finest_level + 1); @@ -1133,8 +1121,8 @@ DiffusionTensorOp::compute_divtau( // anything. m_apply_op->setACoeffs(lev, *a_density[lev]); } - int doZeroVisc = 0; - int addTurbContrib = 1; + constexpr int doZeroVisc = 0; + constexpr int addTurbContrib = 1; Array beta_ec = m_pelelm->getDiffusivity( lev, 0, 1, doZeroVisc, {a_bcrec}, *a_beta[lev], addTurbContrib); m_apply_op->setShearViscosity( @@ -1166,8 +1154,8 @@ DiffusionTensorOp::compute_divtau( // anything. m_apply_op->setACoeffs(lev, *a_density[lev]); } - int doZeroVisc = 0; - int addTurbContrib = 1; + constexpr int doZeroVisc = 0; + constexpr int addTurbContrib = 1; Array beta_ec = m_pelelm->getDiffusivity( lev, 0, 1, doZeroVisc, {a_bcrec}, *a_beta[lev], addTurbContrib); m_apply_op->setShearViscosity(lev, GetArrOfConstPtrs(beta_ec)); @@ -1180,23 +1168,15 @@ DiffusionTensorOp::compute_divtau( if (have_density != 0) { for (int lev = 0; lev <= finest_level; ++lev) { -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(*a_divtau[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - Box const& bx = mfi.tilebox(); - auto const& divtau_arr = a_divtau[lev]->array(mfi); - auto const& rho_arr = a_density[lev]->const_array(mfi); - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - Real rhoinv = 1.0 / rho_arr(i, j, k); - AMREX_D_TERM(divtau_arr(i, j, k, 0) *= rhoinv; - , divtau_arr(i, j, k, 1) *= rhoinv; - , divtau_arr(i, j, k, 2) *= rhoinv;); - }); - } + auto divtau_ma = a_divtau[lev]->arrays(); + auto rho_ma = a_density[lev]->const_arrays(); + amrex::ParallelFor(*a_divtau[lev],[divtau_ma,rho_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + divtau_ma[box_no](i,j,k,n) /= rho_ma[box_no](i,j,k); + } + }); } - } + } } void @@ -1205,12 +1185,12 @@ DiffusionTensorOp::diffuse_velocity( Vector const& a_density, Vector const& a_beta, const BCRec& a_bcrec, - Real a_dt) + const Real a_dt) { const int finest_level = m_pelelm->finestLevel(); - int have_density = (a_density.empty()) ? 0 : 1; + const int have_density = (a_density.empty()) ? 0 : 1; AMREX_ASSERT( (!m_pelelm->m_incompressible && have_density) || @@ -1223,8 +1203,8 @@ DiffusionTensorOp::diffuse_velocity( } else { m_solve_op->setACoeffs(lev, m_pelelm->m_rho); } - int doZeroVisc = 0; - int addTurbContrib = 1; + constexpr int doZeroVisc = 0; + constexpr int addTurbContrib = 1; Array beta_ec = m_pelelm->getDiffusivity( lev, 0, 1, doZeroVisc, {a_bcrec}, *a_beta[lev], addTurbContrib); #ifdef AMREX_USE_EB @@ -1248,27 +1228,22 @@ DiffusionTensorOp::diffuse_velocity( for (int lev = 0; lev <= finest_level; ++lev) { rhs[lev].define( a_vel[lev]->boxArray(), a_vel[lev]->DistributionMap(), AMREX_SPACEDIM, 0); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(rhs[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - Box const& bx = mfi.tilebox(); - auto const& rhs_a = rhs[lev].array(mfi); - auto const& vel_a = a_vel[lev]->const_array(mfi); - auto const& rho_a = (have_density) != 0 ? a_density[lev]->const_array(mfi) - : Array4{}; - amrex::ParallelFor( - bx, AMREX_SPACEDIM, - [=, rho_incomp = m_pelelm->m_rho, - is_incomp = - m_pelelm - ->m_incompressible] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - if (is_incomp != 0) { - rhs_a(i, j, k, n) = rho_incomp * vel_a(i, j, k, n); - } else { - rhs_a(i, j, k, n) = rho_a(i, j, k) * vel_a(i, j, k, n); - } - }); + + auto rhs_ma = rhs[lev].arrays(); + auto vel_ma = a_vel[lev]->const_arrays(); + if (m_pelelm->m_incompressible == 0) { + auto rho_ma = a_density[lev]->const_arrays(); + amrex::ParallelFor(rhs[lev],[rhs_ma,vel_ma,rho_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + rhs_ma[box_no](i,j,k,n) = rho_ma[box_no](i,j,k) * vel_ma[box_no](i,j,k,n); + } + }); + } else { + amrex::ParallelFor(rhs[lev],[rhs_ma,vel_ma,rho = m_pelelm->m_rho] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + rhs_ma[box_no](i,j,k,n) = rho * vel_ma[box_no](i,j,k,n); + } + }); } } From 6815ae5aa11011d234485894b3fff44592e882e9 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 29 Jun 2025 14:30:22 +0200 Subject: [PATCH 08/87] kernel funcs --- Source/PeleLMeX_K.H | 506 ++++++++++++++++++++++---------------------- 1 file changed, 257 insertions(+), 249 deletions(-) diff --git a/Source/PeleLMeX_K.H b/Source/PeleLMeX_K.H index 8567ee637..6f00a7697 100644 --- a/Source/PeleLMeX_K.H +++ b/Source/PeleLMeX_K.H @@ -10,9 +10,9 @@ namespace c2m = pele::physics::utilities::cgs2mks; template AMREX_GPU_DEVICE AMREX_FORCE_INLINE void getTransportCoeff( - int i, - int j, - int k, + const int i, + const int j, + const int k, const bool do_fixed_Le, const bool do_fixed_Pr, const bool do_soret, @@ -38,19 +38,19 @@ getTransportCoeff( // Get rho & Y from rhoY amrex::Real rho = 0.0_rt; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rho += rhoY(i, j, k, n); } - amrex::Real rhoinv = 1.0_rt / rho; + const amrex::Real rhoinv = 1.0_rt / rho; amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } amrex::Real Wbar = 0.0_rt; eos.Y2WBAR(y, Wbar); - amrex::Real rho_cgs = m2c::Rho(rho); // MKS -> CGS conversion + const amrex::Real rho_cgs = m2c::Rho(rho); // MKS -> CGS conversion amrex::Real rhoDi_cgs[NUM_SPECIES] = {0.0}; amrex::Real lambda_cgs = 0.0_rt; amrex::Real mu_cgs = 0.0_rt; @@ -60,9 +60,9 @@ getTransportCoeff( constexpr bool get_xi = false; // always ignore bulk viscosity constexpr bool get_mu = true; // always get dynamic viscosity - bool get_lam = !do_fixed_Pr; - bool get_Ddiag = !do_fixed_Le; - bool get_chi = do_soret; + const bool get_lam = !do_fixed_Pr; + const bool get_Ddiag = !do_fixed_Le; + const bool get_chi = do_soret; auto trans = pele::physics::PhysicsType::transport(); trans.transport( get_xi, get_mu, get_lam, get_Ddiag, get_chi, Tloc, rho_cgs, y, rhoDi_cgs, @@ -75,41 +75,43 @@ getTransportCoeff( amrex::Real cpmix_cgs = 0.0_rt; eos.TY2Cp(T(i, j, k), y, cpmix_cgs); lambda(i, j, k) = PrInv * c2m::Cp(cpmix_cgs) * mu(i, j, k); - amrex::Real ScInv = PrInv * LeInv; - for (int n = 0; n < NUM_SPECIES; n++) { + const amrex::Real ScInv = PrInv * LeInv; + for (int n = 0; n < NUM_SPECIES; ++n) { rhoDi(i, j, k, n) = ScInv * mu(i, j, k); } } else if (do_fixed_Pr) { // fixed Pr, still use species diffs amrex::Real cpmix_cgs = 0.0_rt; eos.TY2Cp(T(i, j, k), y, cpmix_cgs); lambda(i, j, k) = PrInv * c2m::Cp(cpmix_cgs) * mu(i, j, k); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoDi(i, j, k, n) = rhoDi_cgs[n] * Wbar * mwtinv[n] * 1.0e-1_rt; } } else if (do_fixed_Le) { // fixed Le, still use thermal cond lambda(i, j, k) = c2m::Lambda(lambda_cgs); amrex::Real cpmix_cgs = 0.0_rt; eos.TY2Cp(T(i, j, k), y, cpmix_cgs); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoDi(i, j, k, n) = lambda_cgs * 1.0e-1_rt * LeInv / cpmix_cgs; } } else { // full MA model, with Soret if needed lambda(i, j, k) = c2m::Lambda(lambda_cgs); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoDi(i, j, k, n) = rhoDi_cgs[n] * Wbar * mwtinv[n] * 1.0e-1_rt; if (do_soret) { rhotheta(i, j, k, n) = -rhoDi_cgs[n] * chi_loc[n] * 1.0e-1_rt; } } if (do_soret) { -#if defined(H2_ID) && defined(H_ID) // Soret coefficient scaling, see Howarth, Day, Pitsch & Aspden +#if defined(H2_ID) rhotheta(i, j, k, H2_ID) *= 0.664; +#endif +#if defined(H_ID) rhotheta(i, j, k, H_ID) *= 0.58; -#else - amrex::Abort( - "Running with Soret without light species, waste of time " - "and memory..."); +#endif +#if !defined(H2_ID) && !defined(H_ID) + amrex::Abort("Running with Soret without light species, waste of time " + "and memory..."); #endif } } @@ -118,9 +120,9 @@ getTransportCoeff( template <> AMREX_GPU_DEVICE AMREX_FORCE_INLINE void getTransportCoeff( - int i, - int j, - int k, + const int i, + const int j, + const int k, const bool /*do_fixed_Le*/, const bool /*do_fixed_Pr*/, const bool do_soret, @@ -147,13 +149,13 @@ getTransportCoeff( amrex::Real rho, rhoinv; amrex::Real y[NUM_SPECIES] = {0.0}; amrex::Real massdens[NUM_SPECIES]; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { massdens[n] = rhoY(i, j, k, n); } auto eos = pele::physics::PhysicsType::eos(eosparm); eos.RY2RRinvY(massdens, rho, rhoinv, y); - amrex::Real rho_cgs = m2c::Rho(rho); // MKS -> CGS conversion + const amrex::Real rho_cgs = m2c::Rho(rho); // MKS -> CGS conversion amrex::Real rhoDi_cgs[NUM_SPECIES] = {0.0}; amrex::Real lambda_cgs = 0.0_rt; amrex::Real mu_cgs = 0.0_rt; @@ -165,14 +167,14 @@ getTransportCoeff( constexpr bool get_mu = true; constexpr bool get_lam = false; constexpr bool get_Ddiag = true; - bool get_chi = do_soret; + const bool get_chi = do_soret; auto trans = pele::physics::PhysicsType::transport(); trans.transport( get_xi, get_mu, get_lam, get_Ddiag, get_chi, Tloc, rho_cgs, y, rhoDi_cgs, dummy_chi, mu_cgs, dummy_xi, lambda_cgs, trans_parm); // Do CGS -> MKS conversions - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoDi(i, j, k, n) = rhoDi_cgs[n] * 1.0e-1_rt; } lambda(i, j, k) = 0.0; // No need to carry lambda for manifold @@ -183,9 +185,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void getVelViscosity( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& rhoY, amrex::Array4 const& T, amrex::Array4 const& mu, @@ -197,13 +199,13 @@ getVelViscosity( // Get rho & Y from rhoY amrex::Real massdens[NUM_SPECIES]; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { massdens[n] = rhoY(i, j, k, n); } amrex::Real rho = 0.0_rt, rhoinv = 0.0_rt, y[NUM_SPECIES] = {0.0}; pele::physics::PhysicsType::eos_type::RY2RRinvY(massdens, rho, rhoinv, y); - amrex::Real rho_cgs = m2c::Rho(rho); // MKS -> CGS conversion + const amrex::Real rho_cgs = m2c::Rho(rho); // MKS -> CGS conversion amrex::Real temp = T(i, j, k); amrex::Real dummy_rhoDi[NUM_SPECIES] = {0.0}; amrex::Real dummy_chi[NUM_SPECIES] = {0.0}; @@ -229,9 +231,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void getPGivenRTY( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& rho, amrex::Array4 const& rhoY, amrex::Array4 const& T, @@ -242,11 +244,11 @@ getPGivenRTY( using namespace amrex::literals; auto eos = pele::physics::PhysicsType::eos(eosparm); - amrex::Real rhoinv = 1.0_rt / rho(i, j, k); - amrex::Real rho_cgs = m2c::Rho(rho(i, j, k)); + const amrex::Real rhoinv = 1.0_rt / rho(i, j, k); + const amrex::Real rho_cgs = m2c::Rho(rho(i, j, k)); amrex::Real y[NUM_SPECIES] = {0.0_rt}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } amrex::Real P_cgs = 0.0; @@ -257,9 +259,9 @@ getPGivenRTY( template AMREX_GPU_DEVICE AMREX_FORCE_INLINE void compute_divu( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& rhoY, amrex::Array4 const& T, amrex::Array4 const& specDiff, @@ -269,7 +271,7 @@ compute_divu( amrex::Array4 const& extRhoY, amrex::Array4 const& extRhoH, amrex::Array4 const& divu, - int do_react, + const int do_react, pele::physics::eos::EosParm const* eosparm) noexcept { @@ -281,12 +283,12 @@ compute_divu( // Get rho & Y from rhoY amrex::Real rho = 0.0_rt; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rho += rhoY(i, j, k, n); } - amrex::Real rhoinv = 1.0_rt / rho; + const amrex::Real rhoinv = 1.0_rt / rho; amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } @@ -298,15 +300,15 @@ compute_divu( eos.T2Hi(T(i, j, k), hi_cgs); amrex::Real cpmix = c2m::Cp(cpmix_cgs); // CGS -> MKS conversion amrex::Real hi[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { hi[n] = c2m::H(hi_cgs[n]); // CGS -> MKS conversion } // Note: divu does not depend on extRho. See docs and PR #428 for details. - amrex::Real denominv = 1.0_rt / (rho * cpmix * T(i, j, k)); + const amrex::Real denominv = 1.0_rt / (rho * cpmix * T(i, j, k)); divu(i, j, k) = (specEnthDiff(i, j, k) + tempDiff(i, j, k) + extRhoH(i, j, k)) * denominv; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { amrex::Real specTerm = specDiff(i, j, k, n) + extRhoY(i, j, k, n); if (do_react != 0) { specTerm += rhoYdot(i, j, k, n); @@ -318,9 +320,9 @@ compute_divu( template <> AMREX_GPU_DEVICE AMREX_FORCE_INLINE void compute_divu( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& rhoY, amrex::Array4 const& /*T*/, amrex::Array4 const& specDiff, @@ -330,7 +332,7 @@ compute_divu( amrex::Array4 const& extRhoY, amrex::Array4 const& /*extRhoH*/, amrex::Array4 const& divu, - int do_react, + const int do_react, pele::physics::eos::EosParm const* eosparm) noexcept { @@ -340,7 +342,7 @@ compute_divu( amrex::Real rho, rhoinv; amrex::Real y[NUM_SPECIES] = {0.0_rt}; amrex::Real massdens[NUM_SPECIES] = {0.0_rt}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { massdens[n] = rhoY(i, j, k, n); } @@ -353,7 +355,7 @@ compute_divu( divu(i, j, k) = 0.0; - for (int n = 0; n < MANIFOLD_DIM; n++) { + for (int n = 0; n < MANIFOLD_DIM; ++n) { derivs[n] *= 1.0e3; // Unit conversion CGS -> MKS divu(i, j, k) += derivs[n] * specDiff(i, j, k, n); if (do_react != 0) { @@ -371,23 +373,23 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void extFluxDivergence_K( - int i, - int j, - int k, - int ncomp, + const int i, + const int j, + const int k, + const int ncomp, AMREX_D_DECL( amrex::Array4 const& fluxX, amrex::Array4 const& fluxY, amrex::Array4 const& fluxZ), amrex::Array4 const& vol, - const amrex::Real& scaling, + const amrex::Real scaling, amrex::Array4 const& div) noexcept { using namespace amrex::literals; - amrex::Real factor = scaling / vol(i, j, k); + const amrex::Real factor = scaling / vol(i, j, k); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { div(i, j, k, n) = AMREX_D_TERM( (fluxX(i + 1, j, k, n) - fluxX(i, j, k, n)), +(fluxY(i, j + 1, k, n) - fluxY(i, j, k, n)), @@ -400,10 +402,10 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void EB_intFluxDivergence_K( - int i, - int j, - int k, - int ncomp, + const int i, + const int j, + const int k, + const int ncomp, AMREX_D_DECL( amrex::Array4 const& fluxX, amrex::Array4 const& fluxY, @@ -414,14 +416,14 @@ EB_intFluxDivergence_K( amrex::Array4 const& afracZ), AMREX_D_DECL(amrex::Real areax, amrex::Real areay, amrex::Real areaz), amrex::Array4 const& vol, - const amrex::Real& scaling, + const amrex::Real scaling, amrex::Array4 const& div) noexcept { using namespace amrex::literals; - amrex::Real factor = scaling / vol(i, j, k); + const amrex::Real factor = scaling / vol(i, j, k); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { div(i, j, k, n) = AMREX_D_TERM( (areax * afracX(i + 1, j, k) * fluxX(i + 1, j, k, n) - areax * afracX(i, j, k) * fluxX(i, j, k, n)), @@ -437,10 +439,10 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void EB_intFluxDivergence_K( - int i, - int j, - int k, - int ncomp, + const int i, + const int j, + const int k, + const int ncomp, AMREX_D_DECL( amrex::Array4 const& fluxX, amrex::Array4 const& fluxY, @@ -453,16 +455,16 @@ EB_intFluxDivergence_K( amrex::Array4 const& ebFlux, amrex::Array4 const& ebAreaFrac, amrex::Array4 const& vol, - const amrex::Real& a_dx, - const amrex::Real& scaling, + const amrex::Real a_dx, + const amrex::Real scaling, amrex::Array4 const& div) noexcept { using namespace amrex::literals; - amrex::Real factor = scaling / vol(i, j, k); - amrex::Real eb_area = AMREX_D_TERM(1.0, *a_dx, *a_dx) * ebAreaFrac(i, j, k); + const amrex::Real factor = scaling / vol(i, j, k); + const amrex::Real eb_area = AMREX_D_TERM(1.0, *a_dx, *a_dx) * ebAreaFrac(i, j, k); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { div(i, j, k, n) = AMREX_D_TERM( (areax * afracX(i + 1, j, k) * fluxX(i + 1, j, k, n) - areax * afracX(i, j, k) * fluxX(i, j, k, n)), @@ -479,24 +481,24 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void intFluxDivergence_K( - int i, - int j, - int k, - int ncomp, + const int i, + const int j, + const int k, + const int ncomp, AMREX_D_DECL( amrex::Array4 const& fluxX, amrex::Array4 const& fluxY, amrex::Array4 const& fluxZ), AMREX_D_DECL(amrex::Real areax, amrex::Real areay, amrex::Real areaz), amrex::Array4 const& vol, - const amrex::Real& scaling, + const amrex::Real scaling, amrex::Array4 const& div) noexcept { using namespace amrex::literals; - amrex::Real factor = scaling / vol(i, j, k); + const amrex::Real factor = scaling / vol(i, j, k); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { div(i, j, k, n) = AMREX_D_TERM( (areax * fluxX(i + 1, j, k, n) - areax * fluxX(i, j, k, n)), +(areay * fluxY(i, j + 1, k, n) - areay * fluxY(i, j, k, n)), @@ -510,10 +512,10 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void intFluxDivergence_rz_K( - int i, - int j, - int k, - int ncomp, + const int i, + const int j, + const int k, + const int ncomp, AMREX_D_DECL( amrex::Array4 const& fluxX, amrex::Array4 const& fluxY, @@ -521,14 +523,14 @@ intFluxDivergence_rz_K( amrex::Array4 const& ax, amrex::Array4 const& ay, amrex::Array4 const& vol, - const amrex::Real& scaling, + const amrex::Real scaling, amrex::Array4 const& div) noexcept { using namespace amrex::literals; - amrex::Real factor = scaling / vol(i, j, k); + const amrex::Real factor = scaling / vol(i, j, k); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { div(i, j, k, n) = (ax(i + 1, j, k) * fluxX(i + 1, j, k, n) - ax(i, j, k) * fluxX(i, j, k, n)) + (ay(i, j + 1, k) * fluxY(i, j + 1, k, n) - @@ -542,9 +544,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void getMwmixGivenRY( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& rho, amrex::Array4 const& rhoY, amrex::Array4 const& Mwmix, @@ -554,9 +556,9 @@ getMwmixGivenRY( using namespace amrex::literals; auto eos = pele::physics::PhysicsType::eos(eosparm); - amrex::Real rhoinv = 1.0_rt / rho(i, j, k); + const amrex::Real rhoinv = 1.0_rt / rho(i, j, k); amrex::Real y[NUM_SPECIES] = {0.0_rt}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } @@ -568,9 +570,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void getGradMwmixGivengradYMwmix( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& gradY, amrex::Array4 const& Mwmix, amrex::Array4 const& gradMwmix, @@ -583,7 +585,7 @@ getGradMwmixGivengradYMwmix( amrex::Real imw[NUM_SPECIES] = {0.0_rt}; eos.inv_molecular_weight(imw); gradMwmix(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { imw[n] *= 1000.0; // CGS -> MKS gradMwmix(i, j, k) += gradY(i, j, k, n) * imw[n]; } @@ -595,11 +597,11 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void cen2edg_cpp( - int i, - int j, - int k, - int dir, - int ncomp, + const int i, + const int j, + const int k, + const int dir, + const int ncomp, const bool do_harmonic, const bool on_lo, const bool on_hi, @@ -623,7 +625,7 @@ cen2edg_cpp( id_h[dir] -= 1; } if (do_harmonic) { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { if ( (cfab(id_l[0], id_l[1], id_l[2], n) * cfab(id_h[0], id_h[1], id_h[2], n)) > 0.0_rt) { @@ -637,7 +639,7 @@ cen2edg_cpp( } } } else { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { efab(i, j, k, n) = 0.5_rt * (cfab(id_l[0], id_l[1], id_l[2], n) + cfab(id_h[0], id_h[1], id_h[2], n)); } @@ -648,10 +650,10 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void repair_flux( - int i, - int j, - int k, - int dir, + const int i, + const int j, + const int k, + const int dir, const bool on_lo, const bool on_hi, amrex::Array4 const& rhoY, @@ -676,14 +678,14 @@ repair_flux( amrex::Real sumFlux = 0.0_rt; amrex::Real sumRhoYe = 0.0_rt; amrex::Real RhoYe[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { sumFlux += flux(i, j, k, n); RhoYe[n] = 0.5_rt * (rhoY(id_l[0], id_l[1], id_l[2], n) + rhoY(id_h[0], id_h[1], id_h[2], n)); sumRhoYe += RhoYe[n]; } sumRhoYe = 1.0_rt / sumRhoYe; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { flux(i, j, k, n) -= sumFlux * RhoYe[n] * sumRhoYe; } } @@ -692,10 +694,10 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void repair_flux_eb( - int i, - int j, - int k, - int dir, + const int i, + const int j, + const int k, + const int dir, const bool on_lo, const bool on_hi, amrex::Array4 const& rhoY, @@ -712,7 +714,7 @@ repair_flux_eb( amrex::Real sumFlux = 0.0_rt; amrex::Real sumRhoYe = 0.0_rt; amrex::Real RhoYe[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { sumFlux += flux(i, j, k, n); RhoYe[n] = rhoYed(i, j, k, n); if (on_lo) { @@ -724,11 +726,11 @@ repair_flux_eb( sumRhoYe += RhoYe[n]; } sumRhoYe = 1.0_rt / sumRhoYe; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { flux(i, j, k, n) -= sumFlux * RhoYe[n] * sumRhoYe; } } else { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { flux(i, j, k, n) = 0.0_rt; } } @@ -738,9 +740,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void getHGivenT( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& T, amrex::Array4 const& Hi, pele::physics::eos::EosParm const* @@ -749,10 +751,10 @@ getHGivenT( using namespace amrex::literals; auto eos = pele::physics::PhysicsType::eos(eosparm); - amrex::Real hi_spec[NUM_SPECIES] = {0.0_rt}; - eos.T2Hi(T(i, j, k), hi_spec); - for (int n = 0; n < NUM_SPECIES; n++) { - Hi(i, j, k, n) = hi_spec[n] * 0.0001_rt; // CGS -> MKS conversion + amrex::Real hi_spec_cgs[NUM_SPECIES] = {0.0_rt}; + eos.T2Hi(T(i, j, k), hi_spec_cgs); + for (int n = 0; n < NUM_SPECIES; ++n) { + Hi(i, j, k, n) = c2m::H(hi_spec_cgs[n]); // CGS -> MKS conversion } } @@ -760,18 +762,18 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void makeVelForce( - int i, - int j, - int k, - int is_incomp, - const amrex::Real& rho_incomp, - int pseudo_gravity, - int pseudo_gravity_dir, - const amrex::Real& /*time*/, - amrex::GpuArray const gravity, - amrex::GpuArray const gp0, - const amrex::Real& dV_control, - amrex::GpuArray const /*dx*/, + const int i, + const int j, + const int k, + const int is_incomp, + const amrex::Real rho_incomp, + const int pseudo_gravity, + const int pseudo_gravity_dir, + const amrex::Real /*time*/, + amrex::GpuArray const& gravity, + amrex::GpuArray const& gp0, + const amrex::Real dV_control, + amrex::GpuArray const& /*dx*/, amrex::Array4 const& vel, amrex::Array4 const& rho, amrex::Array4 const& /*rhoY*/, @@ -792,7 +794,7 @@ makeVelForce( } // Gravity and background pressure gradient - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { force(i, j, k, idim) = -gp0[idim] + gravity[idim] * rho_lcl; } @@ -801,7 +803,7 @@ makeVelForce( force(i, j, k, pseudo_gravity_dir) += dV_control * rho_lcl; } - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { force(i, j, k, idim) += extmom(i, j, k, idim) - vel(i, j, k, idim) * extrho(i, j, k); } @@ -812,9 +814,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void getRHmixGivenTY( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& rho, amrex::Array4 const& rhoY, amrex::Array4 const& T, @@ -825,9 +827,9 @@ getRHmixGivenTY( using namespace amrex::literals; auto eos = pele::physics::PhysicsType::eos(eosparm); - amrex::Real rhoinv = 1.0_rt / rho(i, j, k); + const amrex::Real rhoinv = 1.0_rt / rho(i, j, k); amrex::Real y[NUM_SPECIES] = {0.0_rt}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } amrex::Real hmix_cgs = 0.0; @@ -839,9 +841,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void getTfromHY( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& rho, amrex::Array4 const& rhoY, amrex::Array4 const& rhoH, @@ -852,12 +854,12 @@ getTfromHY( using namespace amrex::literals; auto eos = pele::physics::PhysicsType::eos(eosparm); - amrex::Real rhoinv = 1.0_rt / rho(i, j, k); + const amrex::Real rhoinv = 1.0_rt / rho(i, j, k); amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } - amrex::Real h_cgs = m2c::H(rhoH(i, j, k) * rhoinv); + const amrex::Real h_cgs = m2c::H(rhoH(i, j, k) * rhoinv); amrex::Real T_loc = T(i, j, k); eos.HY2T(h_cgs, y, T_loc); T(i, j, k) = T_loc; @@ -867,9 +869,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void getCpmixGivenRYT( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& rho, amrex::Array4 const& rhoY, amrex::Array4 const& T, @@ -880,9 +882,9 @@ getCpmixGivenRYT( using namespace amrex::literals; auto eos = pele::physics::PhysicsType::eos(eosparm); - amrex::Real rhoinv = 1.0_rt / rho(i, j, k); + const amrex::Real rhoinv = 1.0_rt / rho(i, j, k); amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } amrex::Real cpmix_cgs = 0.0; @@ -894,9 +896,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void buildAdvectionForcing( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& rho, amrex::Array4 const& rhoY, amrex::Array4 const& T, @@ -905,15 +907,15 @@ buildAdvectionForcing( amrex::Array4 const& r, amrex::Array4 const& extRhoY, amrex::Array4 const& extRhoH, - amrex::Real const& dp0dt, - int const& closed_chamber, - int do_react, + const amrex::Real dp0dt, + const int closed_chamber, + const int do_react, amrex::Array4 const& forceY, amrex::Array4 const& forceT, amrex::Array4 const& forceAux, amrex::Array4 const& dn_aux, const int* aux_diffuse, - int nAux, + const int nAux, pele::physics::eos::EosParm const* eosparm) noexcept { @@ -925,11 +927,11 @@ buildAdvectionForcing( eos.T2Hi(T(i, j, k), hi_spec_cgs); // For species mass fractions - amrex::Real rhoinv = 1.0_rt / rho(i, j, k); + const amrex::Real rhoinv = 1.0_rt / rho(i, j, k); amrex::Real y[NUM_SPECIES] = {0.0}; forceT(i, j, k) = dn(i, j, k, NUM_SPECIES) + ddn(i, j, k); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; // get y forceY(i, j, k, n) = dn(i, j, k, n); // forceY = Dnk if (do_react != 0) { @@ -947,7 +949,7 @@ buildAdvectionForcing( forceT(i, j, k) += dp0dt; // Add dp0/dt } - for (int n = 0; n < nAux; n++) { + for (int n = 0; n < nAux; ++n) { if (aux_diffuse[n] != 0) { forceAux(i, j, k, n) = dn_aux(i, j, k, n); } else { @@ -958,7 +960,7 @@ buildAdvectionForcing( amrex::Real cpmix_cgs = 0.0_rt; eos.TY2Cp(T(i, j, k), y, cpmix_cgs); - amrex::Real cpmixinv = 1.0_rt / c2m::Cp(cpmix_cgs); // CGS -> MKS conversion + const amrex::Real cpmixinv = 1.0_rt / c2m::Cp(cpmix_cgs); // CGS -> MKS conversion forceT(i, j, k) *= rhoinv * cpmixinv; } @@ -966,37 +968,37 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void buildDiffusionForcing( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& dn, amrex::Array4 const& ddn, amrex::Array4 const& dnp1k, amrex::Array4 const& ddnp1k, amrex::Array4 const& r, amrex::Array4 const& a, - amrex::Real const& dp0dt, - int const& closed_chamber, - int do_react, + const amrex::Real dp0dt, + const int closed_chamber, + const int do_react, amrex::Array4 const& forceY, amrex::Array4 const& forceT, amrex::Array4 const& dwbar, amrex::Array4 const& dT, amrex::Array4 const& extRhoY, amrex::Array4 const& extRhoH, - int use_wbar, - int use_soret, + const int use_wbar, + const int use_soret, amrex::Array4 const& forceAux, amrex::Array4 const& a_aux, amrex::Array4 const& dn_aux, amrex::Array4 const& dnp1k_aux, const int* aux_advect, const int* aux_diffuse, - int nAux) noexcept + const int nAux) noexcept { using namespace amrex::literals; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { forceY(i, j, k, n) = a(i, j, k, n) + 0.5_rt * (dn(i, j, k, n) - dnp1k(i, j, k, n)) + extRhoY(i, j, k, n); @@ -1019,7 +1021,7 @@ buildDiffusionForcing( forceT(i, j, k) += dp0dt; } - for (int n = 0; n < nAux; n++) { + for (int n = 0; n < nAux; ++n) { forceAux(i, j, k, n) = 0.0; if (aux_diffuse[n] != 0) { forceAux(i, j, k, n) += @@ -1036,9 +1038,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void reactionRateRhoY( - int i, - int j, - int k, + const int i, + const int j, + const int k, amrex::Array4 const& rhoY, amrex::Array4 const& rhoH, amrex::Array4 const& T, @@ -1056,15 +1058,15 @@ reactionRateRhoY( // Get T from Y/H. amrex::Real Tloc = T(i, j, k); - amrex::Real h_cgs = + const amrex::Real h_cgs = m2c::H(rhoH(i, j, k) * rhoinv); // Include MKS -> CGS conversion eos.HY2T(h_cgs, y, Tloc); // Get wdot. - amrex::Real rho_cgs = m2c::Rho(rho); // rho MKS -> CGS + const amrex::Real rho_cgs = m2c::Rho(rho); // rho MKS -> CGS amrex::Real wdot[NUM_SPECIES] = {0.0_rt}; eos.RTY2WDOT(rho_cgs, Tloc, y, wdot); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoYdot(i, j, k, n) = wdot[n] * 1000.0_rt; // CGS -> MKS conversion } } @@ -1073,17 +1075,17 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void fabMinMax( - int i, - int j, - int k, - int ncomp, - amrex::Real fmin, - amrex::Real fmax, + const int i, + const int j, + const int k, + const int ncomp, + const amrex::Real fmin, + const amrex::Real fmax, amrex::Array4 const& fab) noexcept { using namespace amrex::literals; - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { fab(i, j, k, n) = amrex::max(fmin, amrex::min(fmax, fab(i, j, k, n))); } } @@ -1094,11 +1096,11 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real est_divu_dt_1( - int i, - int j, - int k, - amrex::Real const& dtfactor, - amrex::Real const& rhomin, + const int i, + const int j, + const int k, + const amrex::Real dtfactor, + const amrex::Real rhomin, amrex::Array4 const& rho, amrex::Array4 const& divu) noexcept { @@ -1121,12 +1123,12 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real est_divu_dt_2( - int i, - int j, - int k, - amrex::Real const& dtfactor, - amrex::Real const& rhomin, - amrex::GpuArray const dxinv, + const int i, + const int j, + const int k, + const amrex::Real dtfactor, + const amrex::Real rhomin, + amrex::GpuArray const& dxinv, amrex::Array4 const& rho, amrex::Array4 const& vel, amrex::Array4 const& divu) noexcept @@ -1135,7 +1137,7 @@ est_divu_dt_2( amrex::Real dtcell = 1.0e20_rt; amrex::Real denom = 0.0_rt; - bool rho_is_okay = (rho(i, j, k) > rhomin); + const bool rho_is_okay = (rho(i, j, k) > rhomin); denom = rho(i, j, k) * divu(i, j, k) + @@ -1155,13 +1157,13 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void check_divu_dt( - int i, - int j, - int k, - int check_type, - amrex::Real const& dtfactor, - amrex::Real const& rhomin, - amrex::GpuArray const dxinv, + const int i, + const int j, + const int k, + const int check_type, + const amrex::Real dtfactor, + const amrex::Real rhomin, + amrex::GpuArray const& dxinv, amrex::Array4 const& rho, amrex::Array4 const& vel, amrex::Array4 const& divu, @@ -1171,7 +1173,7 @@ check_divu_dt( amrex::Real dtcell = 1.0e12_rt; amrex::Real denom = 0.0_rt; - bool rho_is_okay = (rho(i, j, k) > rhomin); + const bool rho_is_okay = (rho(i, j, k) > rhomin); if (check_type == 1) { // Check based on divU if (divu(i, j, k) > 0.0_rt) { @@ -1201,25 +1203,25 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getGammaInv( - int i, - int j, - int k, - amrex::Array4 const& rhoY, - amrex::Array4 const& T, - pele::physics::eos::EosParm const* - eosparm) noexcept + const int i, + const int j, + const int k, + amrex::Array4 const& rhoY, + amrex::Array4 const& T, + pele::physics::eos::EosParm const* + eosparm) noexcept { using namespace amrex::literals; auto eos = pele::physics::PhysicsType::eos(eosparm); // Get rho & Y from rhoY amrex::Real rho = 0.0_rt; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rho += rhoY(i, j, k, n); } - amrex::Real rhoinv = 1.0_rt / rho; + const amrex::Real rhoinv = 1.0_rt / rho; amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } @@ -1228,7 +1230,7 @@ getGammaInv( amrex::Real cvmix = 0.0_rt; eos.TY2Cv(T(i, j, k), y, cvmix); - amrex::Real gammainv = cvmix / cpmix; + const amrex::Real gammainv = cvmix / cpmix; return gammainv; } @@ -1237,7 +1239,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getSijSij( - int i, int j, int k, amrex::Array4 const& velgrad) noexcept + const int i, + const int j, + const int k, + amrex::Array4 const& velgrad) noexcept { // This function returns SijSij, not strain rate magnitude |S| = sqrt(2 // SijSij) @@ -1257,7 +1262,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getVelGradTerm( - int i, int j, int k, amrex::Array4 const& velgrad) noexcept + const int i, + const int j, + const int k, + amrex::Array4 const& velgrad) noexcept { // Compute S^d_ij*S^d_ij // S^d_ij = 0.5(g2_ij + g2_ji) - (1/3)*delta_ij*g2_kk @@ -1274,7 +1282,7 @@ getVelGradTerm( } } } - amrex::Real g2_kk_third = + const amrex::Real g2_kk_third = (1.0 / AMREX_SPACEDIM) * (AMREX_D_TERM( g2_ij[0], +g2_ij[AMREX_SPACEDIM + 1], +g2_ij[2 * AMREX_SPACEDIM + 2])); @@ -1296,10 +1304,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void getTurbViscSmagorinsky( - int i, - int j, - int k, - amrex::Real prefactor, + const int i, + const int j, + const int k, + const amrex::Real prefactor, amrex::Array4 const& velgrad, amrex::Array4 const& rho, amrex::Array4 const& mu_t) noexcept @@ -1308,7 +1316,7 @@ getTurbViscSmagorinsky( // mu_t = rho * Cs * Delta^2 * |S| where |S| = sqrt(2 SijSij) - amrex::Real Smag = std::sqrt(2.0 * getSijSij(i, j, k, velgrad)); + const amrex::Real Smag = std::sqrt(2.0 * getSijSij(i, j, k, velgrad)); mu_t(i, j, k) = prefactor * rho(i, j, k) * Smag; } @@ -1316,10 +1324,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void getTurbViscWALE( - int i, - int j, - int k, - amrex::Real prefactor, + const int i, + const int j, + const int k, + const amrex::Real prefactor, amrex::Array4 const& velgrad, amrex::Array4 const& rho, amrex::Array4 const& mu_t) noexcept @@ -1331,12 +1339,12 @@ getTurbViscWALE( // / (SijSij^(5/2) + (S^d_ijS^d_ij)^(5/4) + smallnum) // smallnum included to make sure denom is nonzero - amrex::Real SijSij = getSijSij(i, j, k, velgrad); - amrex::Real Sterm52 = std::pow(SijSij, 2.5); - amrex::Real Sdterm = getVelGradTerm(i, j, k, velgrad); // (S^d_ijS^d_ij) - amrex::Real Sdterm14 = std::pow(Sdterm, 0.25); - amrex::Real Sdterm54 = Sdterm * Sdterm14; - amrex::Real Sdterm32 = Sdterm54 * Sdterm14; + const amrex::Real SijSij = getSijSij(i, j, k, velgrad); + const amrex::Real Sterm52 = std::pow(SijSij, 2.5); + const amrex::Real Sdterm = getVelGradTerm(i, j, k, velgrad); // (S^d_ijS^d_ij) + const amrex::Real Sdterm14 = std::pow(Sdterm, 0.25); + const amrex::Real Sdterm54 = Sdterm * Sdterm14; + const amrex::Real Sdterm32 = Sdterm54 * Sdterm14; mu_t(i, j, k) = prefactor * rho(i, j, k) * Sdterm32 / (Sterm52 + Sdterm54 + 1.0e-12); } @@ -1345,13 +1353,13 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void getTurbViscSigma( - int i, - int j, - int k, - amrex::Real prefactor, - amrex::Array4 const& velgrad, - amrex::Array4 const& rho, - amrex::Array4 const& mu_t) noexcept + const int i, + const int j, + const int k, + const amrex::Real prefactor, + amrex::Array4 const& velgrad, + amrex::Array4 const& rho, + amrex::Array4 const& mu_t) noexcept { #if (AMREX_SPACEDIM == 2) amrex::ignore_unused(i, j, k, prefactor, velgrad, rho, mu_t); @@ -1400,7 +1408,7 @@ getTurbViscSigma( if (alpha1 != 0.0) { alpha2 = (I[0] / 3.0) * (I[0] / 3.0) * (I[0] / 3.0) - I[0] * I[1] / 6.0 + I[2] / 2.0; - amrex::Real arcCosArg = + const amrex::Real arcCosArg = std::min(1.0, std::max(-1.0, alpha2 / std::pow(alpha1, 1.5))); alpha3 = std::acos(arcCosArg) / 3.0; From fe8d269c73ace1534309ee78b1528c9961bd9744 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 29 Jun 2025 14:52:54 +0200 Subject: [PATCH 09/87] formatting --- Source/PeleLMeX.H | 111 +++++--- Source/PeleLMeX.cpp | 106 +++---- Source/PeleLMeX_Advection.cpp | 210 +++++++------- Source/PeleLMeX_BC.cpp | 187 ++++++------- Source/PeleLMeX_Data.cpp | 19 +- Source/PeleLMeX_DeriveFunc.cpp | 35 +-- Source/PeleLMeX_DeriveUserDefined.cpp | 5 +- Source/PeleLMeX_Diffusion.cpp | 248 ++++++++++------- Source/PeleLMeX_DiffusionOp.H | 2 +- Source/PeleLMeX_DiffusionOp.cpp | 94 ++++--- Source/PeleLMeX_EB.cpp | 88 +++--- Source/PeleLMeX_FlowController.cpp | 19 +- Source/PeleLMeX_Forces.cpp | 55 +++- Source/PeleLMeX_K.H | 72 +++-- Source/PeleLMeX_Plot.cpp | 23 +- Source/PeleLMeX_ProblemSpecificFunctions.H | 10 +- Source/PeleLMeX_Projection.cpp | 10 +- Source/PeleLMeX_Setup.cpp | 46 ++-- Source/PeleLMeX_TransportProp.cpp | 5 +- Source/PeleLMeX_Utils.cpp | 62 ++--- .../LinOps/AMReX_MLABecCecLaplacian.cpp | 259 ++++++++---------- .../Plasma/LinOps/AMReX_MLCellABecCecLap.cpp | 5 +- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 82 +++--- 23 files changed, 881 insertions(+), 872 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 7082162e2..6135ef373 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -821,15 +821,15 @@ public: const TimeStamp& a_time, const amrex::Vector& a_divTau, const amrex::Vector& a_velForce, - int nGrowForce, - int add_gradP); + const int nGrowForce, + const int add_gradP); void getVelForces( const TimeStamp& a_time, - int lev, + const int lev, amrex::MultiFab* a_divTau, amrex::MultiFab* a_velForce, - int add_gradP); + const int add_gradP); void getVelForces( int lev, @@ -1078,16 +1078,19 @@ public: // FillPatch and return a MF std::unique_ptr - fillPatchState(const int lev,const amrex::Real a_time, const int nGrow); + fillPatchState(const int lev, const amrex::Real a_time, const int nGrow); std::unique_ptr fillPatchReact(const int lev, const amrex::Real a_time, const int nGrow); // FillPatch state components void fillpatch_state( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_state, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_state, + const int nGhost); void fillpatch_density( - const int lev, - const amrex::Real a_time, + const int lev, + const amrex::Real a_time, amrex::MultiFab& a_density, const int rho_comp, const int nGhost); @@ -1104,60 +1107,96 @@ public: const int temp_comp, const int nGhost); void fillpatch_aux( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_aux, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_aux, + const int nGhost); void fillpatch_divu( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_divu, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_divu, + const int nGhost); void fillpatch_gradp( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_gp, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_gp, + const int nGhost); void fillpatch_reaction( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_I_R, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_I_R, + const int nGhost); void fillpatch_forces( const amrex::Real a_time, amrex::Vector const& a_force, const int nGrowForce); void fillpatch_chemFunctCall( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_fctC, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_fctC, + const int nGhost); #ifdef PELE_USE_PLASMA void fillpatch_phiV( - const int lev, - const amrex::Real a_time, - amrex::MultiFab& a_phiV, - const int phiV_comp, - const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_phiV, + const int phiV_comp, + const int nGhost); void fillPatchExtrap( - const amrex::Real a_time, - amrex::Vector const& a_MF, - const int a_nGrow); + const amrex::Real a_time, + amrex::Vector const& a_MF, + const int a_nGrow); void fillPatchNLnE( - const amrex::Real a_time, - amrex::Vector const& a_nE, - const int a_nGrow); + const amrex::Real a_time, + amrex::Vector const& a_nE, + const int a_nGrow); void fillPatchNLphiV( - const amrex::Real a_time, - amrex::Vector const& a_phiV, - const int a_nGrow); + const amrex::Real a_time, + amrex::Vector const& a_phiV, + const int a_nGrow); #endif // FillCoarsePatch state components void fillcoarsepatch_state( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_state, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_state, + const int nGhost); void fillcoarsepatch_aux( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_aux, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_aux, + const int nGhost); void fillcoarsepatch_divu( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_divu, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_divu, + const int nGhost); void fillcoarsepatch_gradp( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_gp, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_gp, + const int nGhost); void fillcoarsepatch_reaction( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_I_R, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_I_R, + const int nGhost); void fillcoarsepatch_chemFunctCall( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_fctC, const int nGhost); + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_fctC, + const int nGhost); // Fill physical boundaries void setInflowBoundaryVel( amrex::MultiFab& a_vel, const int lev, const PeleLM::TimeStamp a_time); void fillTurbInflow( - amrex::MultiFab& a_vel, const int vel_comp, const int lev, const amrex::Real a_time); + amrex::MultiFab& a_vel, + const int vel_comp, + const int lev, + const amrex::Real a_time); // Average down operations void averageDownState(const PeleLM::TimeStamp& a_time); @@ -1663,8 +1702,8 @@ public: return *m_factory[lev]; } - LevelData* - getLevelDataPtr(const int lev, const PeleLM::TimeStamp& a_time, int useUmac = 0); + LevelData* getLevelDataPtr( + const int lev, const PeleLM::TimeStamp& a_time, int useUmac = 0); LevelDataReact* getLevelDataReactPtr(const int lev); amrex::Real getTime(const int lev, const PeleLM::TimeStamp& a_time) const diff --git a/Source/PeleLMeX.cpp b/Source/PeleLMeX.cpp index 063b308f0..3ebb2b9ef 100644 --- a/Source/PeleLMeX.cpp +++ b/Source/PeleLMeX.cpp @@ -81,29 +81,25 @@ PeleLM::getStateVect(const TimeStamp& a_time) if (a_time == AmrOldTime) { if (m_incompressible != 0) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, 0, AMREX_SPACEDIM)); + r.push_back(std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, 0, AMREX_SPACEDIM)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, 0, NVAR)); + r.push_back(std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, 0, NVAR)); } } } else { if (m_incompressible != 0) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, 0, AMREX_SPACEDIM)); + r.push_back(std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, 0, AMREX_SPACEDIM)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, 0, NVAR)); + r.push_back(std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, 0, NVAR)); } } } @@ -117,17 +113,13 @@ PeleLM::getVelocityVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, VELX, - AMREX_SPACEDIM)); + r.push_back(std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, VELX, - AMREX_SPACEDIM)); + r.push_back(std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); } } return r; @@ -141,17 +133,15 @@ PeleLM::getSpeciesVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, FIRSTSPEC, - NUM_SPECIES)); + r.push_back(std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, FIRSTSPEC, + NUM_SPECIES)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, FIRSTSPEC, - NUM_SPECIES)); + r.push_back(std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, FIRSTSPEC, + NUM_SPECIES)); } } return r; @@ -165,15 +155,13 @@ PeleLM::getDensityVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, DENSITY, 1)); + r.push_back(std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, DENSITY, 1)); } } else if (a_time == AmrNewTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, DENSITY, 1)); + r.push_back(std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, DENSITY, 1)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { @@ -194,15 +182,13 @@ PeleLM::getTempVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, TEMP, 1)); + r.push_back(std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, TEMP, 1)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, TEMP, 1)); + r.push_back(std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, TEMP, 1)); } } return r; @@ -216,15 +202,13 @@ PeleLM::getRhoHVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, RHOH, 1)); + r.push_back(std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, RHOH, 1)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, RHOH, 1)); + r.push_back(std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, RHOH, 1)); } } return r; @@ -302,15 +286,13 @@ PeleLM::getAuxVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_old[lev]->auxiliaries, amrex::make_alias, 0, m_nAux)); + r.push_back(std::make_unique( + m_leveldata_old[lev]->auxiliaries, amrex::make_alias, 0, m_nAux)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_new[lev]->auxiliaries, amrex::make_alias, 0, m_nAux)); + r.push_back(std::make_unique( + m_leveldata_new[lev]->auxiliaries, amrex::make_alias, 0, m_nAux)); } } return r; @@ -453,15 +435,13 @@ PeleLM::getPhiVVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, PHIV, 1)); + r.push_back(std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, PHIV, 1)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, PHIV, 1)); + r.push_back(std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, PHIV, 1)); } } return r; @@ -475,15 +455,13 @@ PeleLM::getnEVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, NE, 1)); + r.push_back(std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, NE, 1)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, NE, 1)); + r.push_back(std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, NE, 1)); } } return r; diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index c2cdaece9..8ce1a91d8 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -88,18 +88,15 @@ PeleLM::computeVelocityAdvTerm(std::unique_ptr& advData) for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM( - auto const& umac = advData->umac[lev][0].const_array(mfi); - , auto const& vmac = advData->umac[lev][1].const_array(mfi); - , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM( - auto const& fx = fluxes[lev][0].array(mfi); - , auto const& fy = fluxes[lev][1].array(mfi); - , auto const& fz = fluxes[lev][2].array(mfi);) - AMREX_D_TERM( - auto const& facex = faces[lev][0].array(mfi); - , auto const& facey = faces[lev][1].array(mfi); - , auto const& facez = faces[lev][2].array(mfi);) + AMREX_D_TERM(auto const& umac = advData->umac[lev][0].const_array(mfi); + , auto const& vmac = advData->umac[lev][1].const_array(mfi); + , auto const& wmac = advData->umac[lev][2].const_array(mfi);) + AMREX_D_TERM(auto const& fx = fluxes[lev][0].array(mfi); + , auto const& fy = fluxes[lev][1].array(mfi); + , auto const& fz = fluxes[lev][2].array(mfi);) + AMREX_D_TERM(auto const& facex = faces[lev][0].array(mfi); + , auto const& facey = faces[lev][1].array(mfi); + , auto const& facez = faces[lev][2].array(mfi);) auto const& divu_arr = divu.const_array(mfi); auto const& vel_arr = ldata_p->state.const_array(mfi, VELX); auto const& force_arr = velForces[lev].const_array(mfi); @@ -242,15 +239,21 @@ PeleLM::updateVelocity(std::unique_ptr& advData) auto adv_aofs_ma = advData->AofS[lev].const_arrays(); auto force_ma = velForces[lev].const_arrays(); auto state_new_ma = ldataNew_p->state.arrays(); - amrex::ParallelFor(ldataOld_p->state, [state_old_ma, adv_aofs_ma, force_ma, state_new_ma,dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - state_new_ma[box_no](i, j, k, VELX+n) = - state_old_ma[box_no](i, j, k, VELX+n) + - dt_loc * (adv_aofs_ma[box_no](i, j, k, VELX+n) + force_ma[box_no](i, j, k, n)); - } + amrex::ParallelFor( + ldataOld_p->state, + [state_old_ma, adv_aofs_ma, force_ma, state_new_ma, + dt_loc = + m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + state_new_ma[box_no](i, j, k, VELX + n) = + state_old_ma[box_no](i, j, k, VELX + n) + + dt_loc * (adv_aofs_ma[box_no](i, j, k, VELX + n) + + force_ma[box_no](i, j, k, n)); + } }); } - Gpu::streamSynchronize();} + Gpu::streamSynchronize(); +} void PeleLM::getScalarAdvForce( @@ -273,25 +276,31 @@ PeleLM::getScalarAdvForce( auto ext_ma = m_extSource[lev]->arrays(); auto adv_ma = advData->Forcing[lev].arrays(); auto adv_aux_ma = advData->Forcing_aux[lev].arrays(); - - amrex::ParallelFor(advData->Forcing[lev], [state_ma, diffData_ma, diffData_aux_ma,r_ma,ext_ma, adv_ma, adv_aux_ma,aux_diffuse_d,leosparm,nAux = m_nAux, dp0dt = m_dp0dt, - is_closed_ch = m_closed_chamber, do_react = m_do_react] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 rho(state_ma[box_no],DENSITY); - Array4 rhoY(state_ma[box_no],FIRSTSPEC); - Array4 T(state_ma[box_no],TEMP); - Array4 dn(diffData_ma[box_no],0); - Array4 ddn(diffData_ma[box_no],NUM_SPECIES+1); - Array4 dn_aux(diffData_aux_ma[box_no],0); - Array4 r(r_ma[box_no],0); - Array4 extRhoY(ext_ma[box_no],FIRSTSPEC); - Array4 extRhoH(ext_ma[box_no],RHOH); - Array4 fY(adv_ma[box_no],0); - Array4 fT(adv_ma[box_no],NUM_SPECIES); - Array4 fAux(adv_aux_ma[box_no],0); - buildAdvectionForcing(i, j, k, rho, rhoY, T, dn, ddn, r, extRhoY, extRhoH, dp0dt, - is_closed_ch, do_react, fY, fT, fAux, dn_aux, aux_diffuse_d, nAux, - leosparm); - }); + + amrex::ParallelFor( + advData->Forcing[lev], + [state_ma, diffData_ma, diffData_aux_ma, r_ma, ext_ma, adv_ma, adv_aux_ma, + aux_diffuse_d, leosparm, nAux = m_nAux, dp0dt = m_dp0dt, + is_closed_ch = m_closed_chamber, + do_react = + m_do_react] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rho(state_ma[box_no], DENSITY); + Array4 rhoY(state_ma[box_no], FIRSTSPEC); + Array4 T(state_ma[box_no], TEMP); + Array4 dn(diffData_ma[box_no], 0); + Array4 ddn(diffData_ma[box_no], NUM_SPECIES + 1); + Array4 dn_aux(diffData_aux_ma[box_no], 0); + Array4 r(r_ma[box_no], 0); + Array4 extRhoY(ext_ma[box_no], FIRSTSPEC); + Array4 extRhoH(ext_ma[box_no], RHOH); + Array4 fY(adv_ma[box_no], 0); + Array4 fT(adv_ma[box_no], NUM_SPECIES); + Array4 fAux(adv_aux_ma[box_no], 0); + buildAdvectionForcing( + i, j, k, rho, rhoY, T, dn, ddn, r, extRhoY, extRhoH, dp0dt, + is_closed_ch, do_react, fY, fT, fAux, dn_aux, aux_diffuse_d, nAux, + leosparm); + }); } Gpu::streamSynchronize(); // Fill forcing ghost cells @@ -402,18 +411,15 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM( - auto const& umac = advData->umac[lev][0].const_array(mfi); - , auto const& vmac = advData->umac[lev][1].const_array(mfi); - , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM( - auto const& fx = fluxes[lev][0].array(mfi, 0); - , auto const& fy = fluxes[lev][1].array(mfi, 0); - , auto const& fz = fluxes[lev][2].array(mfi, 0);) - AMREX_D_TERM( - auto const& edgex = edgeState[0].array(mfi, 1); - , auto const& edgey = edgeState[1].array(mfi, 1); - , auto const& edgez = edgeState[2].array(mfi, 1);) + AMREX_D_TERM(auto const& umac = advData->umac[lev][0].const_array(mfi); + , auto const& vmac = advData->umac[lev][1].const_array(mfi); + , auto const& wmac = advData->umac[lev][2].const_array(mfi);) + AMREX_D_TERM(auto const& fx = fluxes[lev][0].array(mfi, 0); + , auto const& fy = fluxes[lev][1].array(mfi, 0); + , auto const& fz = fluxes[lev][2].array(mfi, 0);) + AMREX_D_TERM(auto const& edgex = edgeState[0].array(mfi, 1); + , auto const& edgey = edgeState[1].array(mfi, 1); + , auto const& edgez = edgeState[2].array(mfi, 1);) auto const& divu_arr = divu.const_array(mfi); auto const& rhoY_arr = ldata_p->state.const_array(mfi, FIRSTSPEC); auto const& force_arr = advData->Forcing[lev].const_array(mfi, 0); @@ -449,10 +455,10 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) auto const& udrift = advData->uDrift[lev][0].const_array(mfi, n); , auto const& vdrift = advData->uDrift[lev][1].const_array(mfi, n); , auto const& wdrift = advData->uDrift[lev][2].const_array(mfi, n);) - AMREX_D_TERM( - auto const& fx_ions = fluxes[lev][0].array(mfi, ion_idx); - , auto const& fy_ions = fluxes[lev][1].array(mfi, ion_idx); - , auto const& fz_ions = fluxes[lev][2].array(mfi, ion_idx);) + AMREX_D_TERM(auto const& fx_ions = fluxes[lev][0].array(mfi, ion_idx); + , auto const& fy_ions = fluxes[lev][1].array(mfi, ion_idx); + , + auto const& fz_ions = fluxes[lev][2].array(mfi, ion_idx);) AMREX_D_TERM( auto const& edgex_ions = edgeState[0].array(mfi, 1 + ion_idx); , auto const& edgey_ions = edgeState[1].array(mfi, 1 + ion_idx); @@ -509,14 +515,12 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) auto const& umac = advData->umac[lev][0].const_array(mfi); , auto const& vmac = advData->umac[lev][1].const_array(mfi); , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM( - auto const& fx = fluxes_aux[lev][0].array(mfi, 0); - , auto const& fy = fluxes_aux[lev][1].array(mfi, 0); - , auto const& fz = fluxes_aux[lev][2].array(mfi, 0);) - AMREX_D_TERM( - auto const& edgex = edgeState_aux[0].array(mfi, 0); - , auto const& edgey = edgeState_aux[1].array(mfi, 0); - , auto const& edgez = edgeState_aux[2].array(mfi, 0);) + AMREX_D_TERM(auto const& fx = fluxes_aux[lev][0].array(mfi, 0); + , auto const& fy = fluxes_aux[lev][1].array(mfi, 0); + , auto const& fz = fluxes_aux[lev][2].array(mfi, 0);) + AMREX_D_TERM(auto const& edgex = edgeState_aux[0].array(mfi, 0); + , auto const& edgey = edgeState_aux[1].array(mfi, 0); + , auto const& edgez = edgeState_aux[2].array(mfi, 0);) auto const& divu_arr = divu.const_array(mfi); auto const& aux_arr = ldata_p->auxiliaries.const_array(mfi, 0); auto const& force_arr = advData->Forcing_aux[lev].const_array(mfi, 0); @@ -601,16 +605,14 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM( - auto const& umac = advData->umac[lev][0].const_array(mfi); - , auto const& vmac = advData->umac[lev][1].const_array(mfi); - , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM( - auto const& fx = fluxes[lev][0].array(mfi, NUM_SPECIES); - , // Put temp fluxes in place of rhoH - auto const& fy = fluxes[lev][1].array(mfi, NUM_SPECIES); - , // will be overwritten later - auto const& fz = fluxes[lev][2].array(mfi, NUM_SPECIES);) + AMREX_D_TERM(auto const& umac = advData->umac[lev][0].const_array(mfi); + , auto const& vmac = advData->umac[lev][1].const_array(mfi); + , auto const& wmac = advData->umac[lev][2].const_array(mfi);) + AMREX_D_TERM(auto const& fx = fluxes[lev][0].array(mfi, NUM_SPECIES); + , // Put temp fluxes in place of rhoH + auto const& fy = fluxes[lev][1].array(mfi, NUM_SPECIES); + , // will be overwritten later + auto const& fz = fluxes[lev][2].array(mfi, NUM_SPECIES);) AMREX_D_TERM( auto const& edgex = edgeState[0].array(mfi, NUM_SPECIES + 2); , auto const& edgey = edgeState[1].array(mfi, NUM_SPECIES + 2); @@ -694,14 +696,12 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM( - auto const& umac = advData->umac[lev][0].const_array(mfi); - , auto const& vmac = advData->umac[lev][1].const_array(mfi); - , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM( - auto const& fx = fluxes[lev][0].array(mfi, NUM_SPECIES); - , auto const& fy = fluxes[lev][1].array(mfi, NUM_SPECIES); - , auto const& fz = fluxes[lev][2].array(mfi, NUM_SPECIES);) + AMREX_D_TERM(auto const& umac = advData->umac[lev][0].const_array(mfi); + , auto const& vmac = advData->umac[lev][1].const_array(mfi); + , auto const& wmac = advData->umac[lev][2].const_array(mfi);) + AMREX_D_TERM(auto const& fx = fluxes[lev][0].array(mfi, NUM_SPECIES); + , auto const& fy = fluxes[lev][1].array(mfi, NUM_SPECIES); + , auto const& fz = fluxes[lev][2].array(mfi, NUM_SPECIES);) AMREX_D_TERM( auto const& edgex = edgeState[0].array(mfi, NUM_SPECIES + 1); , auto const& edgey = edgeState[1].array(mfi, NUM_SPECIES + 1); @@ -929,7 +929,9 @@ PeleLM::updateDensity(std::unique_ptr& advData) void PeleLM::computePassiveAdvTerms( - std::unique_ptr& advData, const int state_comp, const int ncomp) + std::unique_ptr& advData, + const int state_comp, + const int ncomp) { //---------------------------------------------------------------- // Get the BCRecs and AdvectionTypes @@ -981,18 +983,15 @@ PeleLM::computePassiveAdvTerms( #endif for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM( - auto const& umac = advData->umac[lev][0].const_array(mfi); - , auto const& vmac = advData->umac[lev][1].const_array(mfi); - , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM( - auto const& fx = fluxes[lev][0].array(mfi, 0); - , auto const& fy = fluxes[lev][1].array(mfi, 0); - , auto const& fz = fluxes[lev][2].array(mfi, 0);) - AMREX_D_TERM( - auto const& edgex = edgeState[lev][0].array(mfi, 0); - , auto const& edgey = edgeState[lev][1].array(mfi, 0); - , auto const& edgez = edgeState[lev][2].array(mfi, 0);) + AMREX_D_TERM(auto const& umac = advData->umac[lev][0].const_array(mfi); + , auto const& vmac = advData->umac[lev][1].const_array(mfi); + , auto const& wmac = advData->umac[lev][2].const_array(mfi);) + AMREX_D_TERM(auto const& fx = fluxes[lev][0].array(mfi, 0); + , auto const& fy = fluxes[lev][1].array(mfi, 0); + , auto const& fz = fluxes[lev][2].array(mfi, 0);) + AMREX_D_TERM(auto const& edgex = edgeState[lev][0].array(mfi, 0); + , auto const& edgey = edgeState[lev][1].array(mfi, 0); + , auto const& edgez = edgeState[lev][2].array(mfi, 0);) auto const& divu_arr = divu.const_array(mfi); auto const& pass_arr = ldata_p->state.const_array(mfi, state_comp); // TODO: Find way to include diffusive forces for passive scalars that @@ -1084,7 +1083,9 @@ PeleLM::computePassiveAdvTerms( void PeleLM::updateScalarComp( - std::unique_ptr& advData, const int state_comp, const int ncomp) + std::unique_ptr& advData, + const int state_comp, + const int ncomp) { for (int lev = 0; lev <= finest_level; ++lev) { @@ -1096,14 +1097,19 @@ PeleLM::updateScalarComp( auto adv_aofs_ma = advData->AofS[lev].const_arrays(); auto ext_ma = m_extSource[lev]->const_arrays(); auto state_new_ma = ldataNew_p->state.arrays(); - - amrex::ParallelFor(ldataOld_p->state, [state_old_ma, adv_aofs_ma,ext_ma,state_new_ma,state_comp,ncomp,dt_loc = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = state_comp; n < state_comp+ncomp; ++n) { - state_new_ma[box_no](i, j, k, n) = - state_old_ma[box_no](i, j, k, n) + - dt_loc * (adv_aofs_ma[box_no](i, j, k, n) + ext_ma[box_no](i, j, k, n)); - } - }); + + amrex::ParallelFor( + ldataOld_p->state, + [state_old_ma, adv_aofs_ma, ext_ma, state_new_ma, state_comp, ncomp, + dt_loc = + m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = state_comp; n < state_comp + ncomp; ++n) { + state_new_ma[box_no](i, j, k, n) = + state_old_ma[box_no](i, j, k, n) + + dt_loc * + (adv_aofs_ma[box_no](i, j, k, n) + ext_ma[box_no](i, j, k, n)); + } + }); } Gpu::streamSynchronize(); averageDown(AmrNewTime, state_comp, ncomp); diff --git a/Source/PeleLMeX_BC.cpp b/Source/PeleLMeX_BC.cpp index 1d10c810e..4e39e86c5 100644 --- a/Source/PeleLMeX_BC.cpp +++ b/Source/PeleLMeX_BC.cpp @@ -10,65 +10,59 @@ // Components are Interior, Inflow, Outflow, Symmetry, & // SlipWallAdiab, NoSlipWallAdiab, SlipWallIsoTherm, NoSlipWallIsoTherm. -constexpr int norm_vel_bc[] = {BCType::int_dir, BCType::ext_dir, - BCType::foextrap, BCType::reflect_odd, - BCType::ext_dir, BCType::ext_dir, - BCType::ext_dir, BCType::ext_dir}; - -constexpr int tang_vel_bc[] = {BCType::int_dir, BCType::ext_dir, - BCType::foextrap, BCType::reflect_even, - BCType::hoextrap, BCType::ext_dir, - BCType::hoextrap, BCType::ext_dir}; - -constexpr int density_bc[] = {BCType::int_dir, BCType::ext_dir, - BCType::foextrap, BCType::reflect_even, - BCType::foextrap, BCType::foextrap, - BCType::foextrap, BCType::foextrap}; - -constexpr int species_bc[] = {BCType::int_dir, BCType::ext_dir, - BCType::foextrap, BCType::reflect_even, - BCType::foextrap, BCType::foextrap, - BCType::ext_dir, BCType::ext_dir}; - -constexpr int rhoh_bc[] = {BCType::int_dir, BCType::ext_dir, - BCType::foextrap, BCType::reflect_even, - BCType::foextrap, BCType::foextrap, - BCType::ext_dir, BCType::ext_dir}; - -constexpr int temp_bc[] = {BCType::int_dir, BCType::ext_dir, - BCType::foextrap, BCType::reflect_even, - BCType::foextrap, BCType::foextrap, - BCType::ext_dir, BCType::ext_dir}; - -constexpr int aux_bc[] = {BCType::int_dir, BCType::ext_dir, - BCType::foextrap, BCType::reflect_even, - BCType::foextrap, BCType::foextrap, - BCType::ext_dir, BCType::ext_dir}; - -constexpr int divu_bc[] = {BCType::int_dir, BCType::reflect_even, - BCType::reflect_even, BCType::reflect_even, - BCType::reflect_even, BCType::reflect_even, - BCType::reflect_even, BCType::reflect_even}; +constexpr int norm_vel_bc[] = { + BCType::int_dir, BCType::ext_dir, BCType::foextrap, BCType::reflect_odd, + BCType::ext_dir, BCType::ext_dir, BCType::ext_dir, BCType::ext_dir}; + +constexpr int tang_vel_bc[] = { + BCType::int_dir, BCType::ext_dir, BCType::foextrap, BCType::reflect_even, + BCType::hoextrap, BCType::ext_dir, BCType::hoextrap, BCType::ext_dir}; + +constexpr int density_bc[] = { + BCType::int_dir, BCType::ext_dir, BCType::foextrap, BCType::reflect_even, + BCType::foextrap, BCType::foextrap, BCType::foextrap, BCType::foextrap}; + +constexpr int species_bc[] = { + BCType::int_dir, BCType::ext_dir, BCType::foextrap, BCType::reflect_even, + BCType::foextrap, BCType::foextrap, BCType::ext_dir, BCType::ext_dir}; + +constexpr int rhoh_bc[] = { + BCType::int_dir, BCType::ext_dir, BCType::foextrap, BCType::reflect_even, + BCType::foextrap, BCType::foextrap, BCType::ext_dir, BCType::ext_dir}; + +constexpr int temp_bc[] = { + BCType::int_dir, BCType::ext_dir, BCType::foextrap, BCType::reflect_even, + BCType::foextrap, BCType::foextrap, BCType::ext_dir, BCType::ext_dir}; + +constexpr int aux_bc[] = { + BCType::int_dir, BCType::ext_dir, BCType::foextrap, BCType::reflect_even, + BCType::foextrap, BCType::foextrap, BCType::ext_dir, BCType::ext_dir}; + +constexpr int divu_bc[] = {BCType::int_dir, BCType::reflect_even, + BCType::reflect_even, BCType::reflect_even, + BCType::reflect_even, BCType::reflect_even, + BCType::reflect_even, BCType::reflect_even}; // Following incflo rather than IAMR here -constexpr int force_bc[] = {BCType::int_dir, BCType::foextrap, BCType::foextrap, - BCType::foextrap, BCType::foextrap, BCType::foextrap, - BCType::foextrap, BCType::foextrap}; +constexpr int force_bc[] = { + BCType::int_dir, BCType::foextrap, BCType::foextrap, BCType::foextrap, + BCType::foextrap, BCType::foextrap, BCType::foextrap, BCType::foextrap}; #ifdef PELE_USE_PLASMA constexpr int nE_bc[] = {BCType::int_dir, BCType::ext_dir, - BCType::foextrap, BCType::reflect_even, - BCType::reflect_even, BCType::reflect_even, - BCType::ext_dir, BCType::ext_dir}; + BCType::foextrap, BCType::reflect_even, + BCType::reflect_even, BCType::reflect_even, + BCType::ext_dir, BCType::ext_dir}; -constexpr int phiV_bc[] = {BCType::int_dir, BCType::ext_dir, BCType::reflect_even}; +constexpr int phiV_bc[] = { + BCType::int_dir, BCType::ext_dir, BCType::reflect_even}; #endif #ifdef PELE_USE_SOOT constexpr int soot_bc[] = {BCType::int_dir, BCType::ext_dir, - BCType::foextrap, BCType::reflect_even, - BCType::reflect_even, BCType::reflect_even, - BCType::ext_dir, BCType::ext_dir}; + BCType::foextrap, BCType::reflect_even, + BCType::reflect_even, BCType::reflect_even, + BCType::ext_dir, BCType::ext_dir}; #endif InterpBase* @@ -364,7 +358,7 @@ PeleLM::fillPatchReact(const int lev, const Real a_time, const int nGrow) BL_PROFILE("PeleLMeX::fillPatchReact()"); #ifdef PELE_USE_PLASMA - constexpr int IRsize = NUM_SPECIES +1; + constexpr int IRsize = NUM_SPECIES + 1; #else constexpr int IRsize = NUM_SPECIES; #endif @@ -380,7 +374,7 @@ PeleLM::fillPatchReact(const int lev, const Real a_time, const int nGrow) // Fill the state void PeleLM::fillpatch_state( - const int lev, const Real a_time, MultiFab& a_state, const int nGhost) + const int lev, const Real a_time, MultiFab& a_state, const int nGhost) { ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); @@ -436,11 +430,11 @@ PeleLM::fillpatch_state( // Fill the density void PeleLM::fillpatch_density( - const int lev, - const Real a_time, - MultiFab& a_density, - const int rho_comp, - const int nGhost) + const int lev, + const Real a_time, + MultiFab& a_density, + const int rho_comp, + const int nGhost) { ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); @@ -491,16 +485,16 @@ PeleLM::fillpatch_density( // Fill the mass fractions void PeleLM::fillpatch_species( - const int lev, - const Real a_time, - MultiFab& a_species, - const int rhoY_comp, - const int nGhost) + const int lev, + const Real a_time, + MultiFab& a_species, + const int rhoY_comp, + const int nGhost) { ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); if (lev == 0) { - + // Species PhysBCFunct< GpuBndryFuncFab>> @@ -650,11 +644,11 @@ PeleLM::fillpatch_aux( // Fill electro-static potential void PeleLM::fillpatch_phiV( - const int lev, - const Real a_time, - MultiFab& a_temp, - const int phiV_comp, - const int nGhost) + const int lev, + const Real a_time, + MultiFab& a_temp, + const int phiV_comp, + const int nGhost) { ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); @@ -702,7 +696,7 @@ PeleLM::fillpatch_phiV( // Fill the divU void PeleLM::fillpatch_divu( - const int lev, const Real a_time, MultiFab& a_divu, const int nGhost) + const int lev, const Real a_time, MultiFab& a_divu, const int nGhost) { if (lev == 0) { PhysBCFunct> bndry_func( @@ -736,7 +730,7 @@ PeleLM::fillpatch_divu( // foextrap on domain BCs void PeleLM::fillpatch_forces( - const Real a_time, Vector const& a_force, const int nGrowForce) + const Real a_time, Vector const& a_force, const int nGrowForce) { AMREX_ASSERT(a_force[0]->nComp() <= m_bcrec_force.size()); const int nComp = a_force[0]->nComp(); @@ -766,7 +760,7 @@ PeleLM::fillpatch_forces( // Fill the gradp void PeleLM::fillpatch_gradp( - const int lev, const Real a_time, MultiFab& a_gp, const int nGhost) + const int lev, const Real a_time, MultiFab& a_gp, const int nGhost) { if (lev == 0) { PhysBCFunct> bndry_func( @@ -799,7 +793,7 @@ PeleLM::fillpatch_gradp( // Fill the reaction data void PeleLM::fillpatch_reaction( - const int lev, const Real a_time, MultiFab& a_I_R, const int nGhost) + const int lev, const Real a_time, MultiFab& a_I_R, const int nGhost) { if (lev == 0) { PhysBCFunct> bndry_func( @@ -827,7 +821,7 @@ PeleLM::fillpatch_reaction( // Fill functC void PeleLM::fillpatch_chemFunctCall( - const int lev, const Real a_time, MultiFab& a_fctC, const int nGhost) + const int lev, const Real a_time, MultiFab& a_fctC, const int nGhost) { if (lev == 0) { PhysBCFunct> bndry_func( @@ -855,12 +849,12 @@ PeleLM::fillpatch_chemFunctCall( // Fill the state void PeleLM::fillcoarsepatch_state( - const int lev, const Real a_time, MultiFab& a_state, const int nGhost) + const int lev, const Real a_time, MultiFab& a_state, const int nGhost) { AMREX_ASSERT(lev > 0); ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); - + const int nCompState = (m_incompressible) != 0 ? AMREX_SPACEDIM : NVAR; fillTurbInflow(a_state, VELX, lev, a_time); @@ -891,7 +885,7 @@ PeleLM::fillcoarsepatch_state( // Fill the auxiliaries void PeleLM::fillcoarsepatch_aux( - const int lev, const Real a_time, MultiFab& a_aux, const int nGhost) + const int lev, const Real a_time, MultiFab& a_aux, const int nGhost) { AMREX_ASSERT(lev > 0); ProbParm const* lprobparm = prob_parm_d; @@ -919,7 +913,7 @@ PeleLM::fillcoarsepatch_aux( // Fill the grad P void PeleLM::fillcoarsepatch_gradp( - const int lev, const Real a_time, MultiFab& a_gp, const int nGhost) + const int lev, const Real a_time, MultiFab& a_gp, const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -937,7 +931,7 @@ PeleLM::fillcoarsepatch_gradp( // Fill the divu void PeleLM::fillcoarsepatch_divu( - const int lev, const Real a_time, MultiFab& a_divu, const int nGhost) + const int lev, const Real a_time, MultiFab& a_divu, const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -955,7 +949,7 @@ PeleLM::fillcoarsepatch_divu( // Fill coarse patch of reaction void PeleLM::fillcoarsepatch_reaction( - const int lev, const Real a_time, MultiFab& a_I_R, const int nGhost) + const int lev, const Real a_time, MultiFab& a_I_R, const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -973,7 +967,7 @@ PeleLM::fillcoarsepatch_reaction( // Fill coarse patch of chem function call void PeleLM::fillcoarsepatch_chemFunctCall( - const int lev, const Real a_time, MultiFab& a_fctC, const int nGhost) + const int lev, const Real a_time, MultiFab& a_fctC, const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -991,7 +985,8 @@ PeleLM::fillcoarsepatch_chemFunctCall( // Fill the inflow boundary of a velocity MF // used for velocity projection void -PeleLM::setInflowBoundaryVel(MultiFab& a_vel, const int lev, const TimeStamp a_time) +PeleLM::setInflowBoundaryVel( + MultiFab& a_vel, const int lev, const TimeStamp a_time) { BL_PROFILE("PeleLMeX::setInflowBoundaryVel()"); @@ -1035,7 +1030,7 @@ PeleLM::setInflowBoundaryVel(MultiFab& a_vel, const int lev, const TimeStamp a_t void PeleLM::fillTurbInflow( - MultiFab& a_vel, const int vel_comp, const int lev, const Real a_time) + MultiFab& a_vel, const int vel_comp, const int lev, const Real a_time) { if (turb_inflow.is_initialized()) { @@ -1046,8 +1041,7 @@ PeleLM::fillTurbInflow( auto velBCRec = fetchBCRecArray(VELX, AMREX_SPACEDIM); // Copy problem parameter structs to host - Gpu::copy( - Gpu::deviceToHost, probparmDD, probparmDD + 1, probparmDH); + Gpu::copy(Gpu::deviceToHost, probparmDD, probparmDD + 1, probparmDH); #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) @@ -1058,10 +1052,8 @@ PeleLM::fillTurbInflow( for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { - auto bndryBoxLO = - Box(adjCellLo(geom[lev].Domain(), dir, 4) & bx); - if ( - velBCRec[0].lo()[dir] == BCType::ext_dir && bndryBoxLO.ok()) { + auto bndryBoxLO = Box(adjCellLo(geom[lev].Domain(), dir, 4) & bx); + if (velBCRec[0].lo()[dir] == BCType::ext_dir && bndryBoxLO.ok()) { // Create box with ghost cells and set them to zero IntVect growVect(IntVect::TheUnitVector()); constexpr int Grow = 4; // Being conservative @@ -1071,20 +1063,16 @@ PeleLM::fillTurbInflow( growVect[dir] = 0; Box modDom = geom[lev].Domain(); modDom.grow(growVect); - auto bndryBoxLO_ghost = - Box(adjCellLo(modDom, dir, Grow) & bx); + auto bndryBoxLO_ghost = Box(adjCellLo(modDom, dir, Grow) & bx); data.setVal( 0.0, bndryBoxLO_ghost, vel_comp, AMREX_SPACEDIM); turb_inflow.add_turb( - bndryBoxLO, data, 0, geom[lev], a_time, dir, - Orientation::low); + bndryBoxLO, data, 0, geom[lev], a_time, dir, Orientation::low); } - auto bndryBoxHI = - Box(adjCellHi(geom[lev].Domain(), dir, 4) & bx); - if ( - velBCRec[0].hi()[dir] == BCType::ext_dir && bndryBoxHI.ok()) { + auto bndryBoxHI = Box(adjCellHi(geom[lev].Domain(), dir, 4) & bx); + if (velBCRec[0].hi()[dir] == BCType::ext_dir && bndryBoxHI.ok()) { // Create box with ghost cells and set them to zero IntVect growVect(IntVect::TheUnitVector()); constexpr int Grow = 4; @@ -1094,20 +1082,17 @@ PeleLM::fillTurbInflow( growVect[dir] = 0; Box modDom = geom[lev].Domain(); modDom.grow(growVect); - auto bndryBoxHI_ghost = - Box(adjCellHi(modDom, dir, Grow) & bx); + auto bndryBoxHI_ghost = Box(adjCellHi(modDom, dir, Grow) & bx); data.setVal( 0.0, bndryBoxHI_ghost, vel_comp, AMREX_SPACEDIM); turb_inflow.add_turb( - bndryBoxHI, data, 0, geom[lev], a_time, dir, - Orientation::high); + bndryBoxHI, data, 0, geom[lev], a_time, dir, Orientation::high); } } } // Copy problem parameter structs back to device - Gpu::copy( - Gpu::hostToDevice, probparmDH, probparmDH + 1, probparmDD); + Gpu::copy(Gpu::hostToDevice, probparmDH, probparmDH + 1, probparmDD); } } diff --git a/Source/PeleLMeX_Data.cpp b/Source/PeleLMeX_Data.cpp index 745bf8781..78a3d7186 100644 --- a/Source/PeleLMeX_Data.cpp +++ b/Source/PeleLMeX_Data.cpp @@ -62,7 +62,7 @@ PeleLM::LevelDataReact::LevelDataReact( const amrex::FabFactory& factory) { #ifdef PELE_USE_PLASMA - constexpr int IRsize = NUM_SPECIES +1; + constexpr int IRsize = NUM_SPECIES + 1; #else constexpr int IRsize = NUM_SPECIES; #endif @@ -102,21 +102,21 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( const int is_init) { if (is_init != 0) { // All I need is a container for a single diffusion term - Dnp1.reserve(a_finestLevel+1); + Dnp1.reserve(a_finestLevel + 1); // Define MFs for (int lev = 0; lev <= a_finestLevel; ++lev) { Dnp1.emplace_back( ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, MFInfo(), *factory[lev]); } if (a_nAux > 0) { - Dnp1_aux.reserve(a_finestLevel+1); + Dnp1_aux.reserve(a_finestLevel + 1); for (int lev = 0; lev <= a_finestLevel; ++lev) { Dnp1_aux.emplace_back( ba[lev], dm[lev], a_nAux, nGrowAdv, MFInfo(), *factory[lev]); } } } else { - // Reserve/resize Vectors + // Reserve/resize Vectors Dn.reserve(a_finestLevel + 1); Dnp1.reserve(a_finestLevel + 1); Dhat.reserve(a_finestLevel + 1); @@ -133,7 +133,7 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( DT.reserve(a_finestLevel + 1); soret_fluxes.resize(a_finestLevel + 1); } - + // Define MFs for (int lev = 0; lev <= a_finestLevel; ++lev) { Dn.emplace_back( @@ -146,19 +146,20 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( Dwbar.emplace_back( ba[lev], dm[lev], NUM_SPECIES, nGrowAdv, MFInfo(), *factory[lev]); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - const BoxArray& faceba = - amrex::convert(ba[lev], IntVect::TheDimensionVector(idim)); + const BoxArray& faceba = + amrex::convert(ba[lev], IntVect::TheDimensionVector(idim)); wbar_fluxes[lev][idim].define( faceba, dm[lev], NUM_SPECIES, 0, MFInfo(), *factory[lev]); } } if (a_use_soret != 0) { - DT.emplace_back(ba[lev], dm[lev], NUM_SPECIES, nGrowAdv, MFInfo(), *factory[lev]); + DT.emplace_back( + ba[lev], dm[lev], NUM_SPECIES, nGrowAdv, MFInfo(), *factory[lev]); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const BoxArray& faceba = amrex::convert(ba[lev], IntVect::TheDimensionVector(idim)); soret_fluxes[lev][idim].define( - faceba, dm[lev], NUM_SPECIES, 0, MFInfo(), *factory[lev]); + faceba, dm[lev], NUM_SPECIES, 0, MFInfo(), *factory[lev]); } } if (a_nAux > 0) { diff --git a/Source/PeleLMeX_DeriveFunc.cpp b/Source/PeleLMeX_DeriveFunc.cpp index cabd51f60..bdee0c1ca 100644 --- a/Source/PeleLMeX_DeriveFunc.cpp +++ b/Source/PeleLMeX_DeriveFunc.cpp @@ -286,10 +286,9 @@ pelelmex_dermgvort( int /*level*/) { - AMREX_D_TERM( - const amrex::Real idx = geom.InvCellSize(0); - , const amrex::Real idy = geom.InvCellSize(1); - , const amrex::Real idz = geom.InvCellSize(2);); + AMREX_D_TERM(const amrex::Real idx = geom.InvCellSize(0); + , const amrex::Real idy = geom.InvCellSize(1); + , const amrex::Real idz = geom.InvCellSize(2);); auto const& dat_arr = statefab.const_array(); auto const& vort_arr = derfab.array(dcomp); @@ -449,10 +448,9 @@ pelelmex_dervort( AMREX_ASSERT(derfab.box().contains(bx)); AMREX_ASSERT(statefab.box().contains(bx)); AMREX_ASSERT(derfab.nComp() >= dcomp + ncomp); - AMREX_D_TERM( - const amrex::Real idx = geom.InvCellSize(0); - , const amrex::Real idy = geom.InvCellSize(1); - , const amrex::Real idz = geom.InvCellSize(2);); + AMREX_D_TERM(const amrex::Real idx = geom.InvCellSize(0); + , const amrex::Real idy = geom.InvCellSize(1); + , const amrex::Real idz = geom.InvCellSize(2);); auto const& dat_arr = statefab.const_array(); auto const& vort_arr = derfab.array(dcomp); @@ -624,10 +622,9 @@ pelelmex_dercoord( amrex::ignore_unused(ncomp); AMREX_ASSERT(derfab.box().contains(bx)); AMREX_ASSERT(derfab.nComp() >= dcomp + ncomp); - AMREX_D_TERM( - const amrex::Real dx = geom.CellSize(0); - , const amrex::Real dy = geom.CellSize(1); - , const amrex::Real dz = geom.CellSize(2);); + AMREX_D_TERM(const amrex::Real dx = geom.CellSize(0); + , const amrex::Real dy = geom.CellSize(1); + , const amrex::Real dz = geom.CellSize(2);); auto const& coord_arr = derfab.array(dcomp); const auto geomdata = geom.data(); @@ -711,10 +708,9 @@ pelelmex_derQcrit( { #if AMREX_SPACEDIM == 3 - AMREX_D_TERM( - const amrex::Real idx = geom.InvCellSize(0); - , const amrex::Real idy = geom.InvCellSize(1); - , const amrex::Real idz = geom.InvCellSize(2);); + AMREX_D_TERM(const amrex::Real idx = geom.InvCellSize(0); + , const amrex::Real idy = geom.InvCellSize(1); + , const amrex::Real idz = geom.InvCellSize(2);); auto const& dat_arr = statefab.const_array(); auto const& qcrit_arr = derfab.array(dcomp); @@ -981,10 +977,9 @@ pelelmex_derenstrophy( int /*level*/) { - AMREX_D_TERM( - const amrex::Real idx = geom.InvCellSize(0); - , const amrex::Real idy = geom.InvCellSize(1); - , const amrex::Real idz = geom.InvCellSize(2);); + AMREX_D_TERM(const amrex::Real idx = geom.InvCellSize(0); + , const amrex::Real idy = geom.InvCellSize(1); + , const amrex::Real idz = geom.InvCellSize(2);); auto const& dat_arr = statefab.const_array(VELX); auto const& rho_arr = (a_pelelm->m_incompressible) != 0 diff --git a/Source/PeleLMeX_DeriveUserDefined.cpp b/Source/PeleLMeX_DeriveUserDefined.cpp index b38319017..57bec4c89 100644 --- a/Source/PeleLMeX_DeriveUserDefined.cpp +++ b/Source/PeleLMeX_DeriveUserDefined.cpp @@ -34,7 +34,6 @@ pelelmex_deruserdef( const Vector& /*bcrec*/, int /*level*/) { - Abort( - "Using derUserDefine derived requires providing a definition in local " - "DeriveUserDefined.cpp"); + Abort("Using derUserDefine derived requires providing a definition in local " + "DeriveUserDefined.cpp"); } diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 9a0f581c1..9b0b325ed 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -428,12 +428,14 @@ PeleLM::correctIsothermalBoundary( bc_hi, use_wbar = m_use_wbar, need_explicit_fluxes] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { int idx[3] = {i, j, k}; - const bool on_lo = (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || - bc_lo == BoundaryCondition::BCSlipWallIsotherm) && - (idx[idim] <= edomain.smallEnd(idim)); - const bool on_hi = (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || - bc_hi == BoundaryCondition::BCSlipWallIsotherm) && - (idx[idim] >= edomain.bigEnd(idim)); + const bool on_lo = + (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || + bc_lo == BoundaryCondition::BCSlipWallIsotherm) && + (idx[idim] <= edomain.smallEnd(idim)); + const bool on_hi = + (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || + bc_hi == BoundaryCondition::BCSlipWallIsotherm) && + (idx[idim] >= edomain.bigEnd(idim)); if (on_lo || on_hi) { if (on_lo) { // need to move -1 for lo boundary idx[idim] -= 1; @@ -671,7 +673,7 @@ PeleLM::addWbarTerm( grids[lev], dmap[lev], 1, nGrow, MFInfo(), Factory(lev)); } const Box& domain = geom[lev].Domain(); - + #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif @@ -701,12 +703,14 @@ PeleLM::addWbarTerm( for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const auto bc_lo = phys_bc.lo(idim); const auto bc_hi = phys_bc.hi(idim); - const bool on_lo = (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || - bc_lo == BoundaryCondition::BCSlipWallIsotherm) && - (idx[idim] < domain.smallEnd(idim)); - const bool on_hi = (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || - bc_hi == BoundaryCondition::BCSlipWallIsotherm) && - (idx[idim] > domain.bigEnd(idim)); + const bool on_lo = + (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || + bc_lo == BoundaryCondition::BCSlipWallIsotherm) && + (idx[idim] < domain.smallEnd(idim)); + const bool on_hi = + (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || + bc_hi == BoundaryCondition::BCSlipWallIsotherm) && + (idx[idim] > domain.bigEnd(idim)); if (on_lo || on_hi) { getGradMwmixGivengradYMwmix( @@ -936,7 +940,7 @@ PeleLM::addSoretTerm( } if (need_soret_fluxes != 0) { - for (int n = 0; n < NUM_SPECIES; ++n) { + for (int n = 0; n < NUM_SPECIES; ++n) { spsoretFlux_ar(i, j, k, n) = -beta_ar(i, j, k, n) * gradT_ar(i, j, k) / T(i, j, k); } @@ -1017,9 +1021,9 @@ PeleLM::computeSpeciesEnthalpyFlux( lev, 0, NUM_SPECIES, doZeroVisc, bcRecSpec, Enth, addTurbContrib); //------------------------------------------------------------------------ - // Compute \sum_k { \Flux_k * h_k } - -#ifdef AMREX_USE_OMP + // Compute \sum_k { \Flux_k * h_k } + +#ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif for (MFIter mfi(Enth, TilingIfNotGPU()); mfi.isValid(); ++mfi) { @@ -1096,16 +1100,20 @@ PeleLM::differentialDiffusionUpdate( auto aux_ma = ldata_p->auxiliaries.const_arrays(); auto fAux_ma = advData->Forcing_aux[lev].arrays(); - amrex::ParallelFor(advData->Forcing[lev], [state_ma,fY_ma,aux_ma,fAux_ma,dt = m_dt, nAux = m_nAux] AMREX_GPU_DEVICE(int box_no,int i, int j, int k) noexcept { - Array4 rhoY(state_ma[box_no],FIRSTSPEC); - for (int n = 0; n < NUM_SPECIES; ++n) { - fY_ma[box_no](i,j,k,n) *= dt; - fY_ma[box_no](i,j,k,n) += rhoY(i,j,k,n); - } - for (int n = 0; n < nAux; ++n) { - fAux_ma[box_no](i,j,k,n) *= dt; - fAux_ma[box_no](i,j,k,n) += aux_ma[box_no](i,j,k,n); - } + amrex::ParallelFor( + advData->Forcing[lev], + [state_ma, fY_ma, aux_ma, fAux_ma, dt = m_dt, + nAux = + m_nAux] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rhoY(state_ma[box_no], FIRSTSPEC); + for (int n = 0; n < NUM_SPECIES; ++n) { + fY_ma[box_no](i, j, k, n) *= dt; + fY_ma[box_no](i, j, k, n) += rhoY(i, j, k, n); + } + for (int n = 0; n < nAux; ++n) { + fAux_ma[box_no](i, j, k, n) *= dt; + fAux_ma[box_no](i, j, k, n) += aux_ma[box_no](i, j, k, n); + } }); } Gpu::streamSynchronize(); @@ -1278,7 +1286,6 @@ PeleLM::differentialDiffusionUpdate( auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - auto state_ma = ldata_p->state.arrays(); auto dhat_ma = diffData->Dhat[lev].const_arrays(); auto force_ma = advData->Forcing[lev].const_arrays(); @@ -1288,47 +1295,75 @@ PeleLM::differentialDiffusionUpdate( auto dhat_aux_ma = diffData->Dhat_aux[lev].const_arrays(); auto force_aux_ma = advData->Forcing_aux[lev].const_arrays(); - if(m_use_wbar != 0 && m_use_soret != 0) { - amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dwbar_ma,dT_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 rhoY(state_ma[box_no],FIRSTSPEC); - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt * (dhat_ma[box_no](i,j,k,n) - dwbar_ma[box_no](i,j,k,n) - dT_ma[box_no](i,j,k,n)); - } - for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt * dhat_aux_ma[box_no](i,j,k,n); - } - }); + if (m_use_wbar != 0 && m_use_soret != 0) { + amrex::ParallelFor( + ldata_p->state, + [state_ma, dhat_ma, force_ma, dwbar_ma, dT_ma, aux_ma, dhat_aux_ma, + force_aux_ma, nAux = m_nAux, + dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rhoY(state_ma[box_no], FIRSTSPEC); + for (int n = 0; n < NUM_SPECIES; ++n) { + rhoY(i, j, k, n) = + force_ma[box_no](i, j, k, n) + + dt * (dhat_ma[box_no](i, j, k, n) - dwbar_ma[box_no](i, j, k, n) - + dT_ma[box_no](i, j, k, n)); + } + for (int n = 0; n < nAux; ++n) { + aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + + dt * dhat_aux_ma[box_no](i, j, k, n); + } + }); } else if (m_use_wbar != 0) { - amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dwbar_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 rhoY(state_ma[box_no],FIRSTSPEC); - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt * (dhat_ma[box_no](i,j,k,n) - dwbar_ma[box_no](i,j,k,n)); - } - for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt * dhat_aux_ma[box_no](i,j,k,n); - } - }); + amrex::ParallelFor( + ldata_p->state, + [state_ma, dhat_ma, force_ma, dwbar_ma, aux_ma, dhat_aux_ma, + force_aux_ma, nAux = m_nAux, + dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rhoY(state_ma[box_no], FIRSTSPEC); + for (int n = 0; n < NUM_SPECIES; ++n) { + rhoY(i, j, k, n) = + force_ma[box_no](i, j, k, n) + + dt * (dhat_ma[box_no](i, j, k, n) - dwbar_ma[box_no](i, j, k, n)); + } + for (int n = 0; n < nAux; ++n) { + aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + + dt * dhat_aux_ma[box_no](i, j, k, n); + } + }); } else if (m_use_soret != 0) { - amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,dT_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 rhoY(state_ma[box_no],FIRSTSPEC); - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt * (dhat_ma[box_no](i,j,k,n) - dT_ma[box_no](i,j,k,n)); - } - for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt * dhat_aux_ma[box_no](i,j,k,n); - } - }); + amrex::ParallelFor( + ldata_p->state, + [state_ma, dhat_ma, force_ma, dT_ma, aux_ma, dhat_aux_ma, force_aux_ma, + nAux = m_nAux, + dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rhoY(state_ma[box_no], FIRSTSPEC); + for (int n = 0; n < NUM_SPECIES; ++n) { + rhoY(i, j, k, n) = + force_ma[box_no](i, j, k, n) + + dt * (dhat_ma[box_no](i, j, k, n) - dT_ma[box_no](i, j, k, n)); + } + for (int n = 0; n < nAux; ++n) { + aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + + dt * dhat_aux_ma[box_no](i, j, k, n); + } + }); } else { - amrex::ParallelFor(ldata_p->state,[state_ma,dhat_ma,force_ma,aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no,int i, int j, int k) noexcept { - Array4 rhoY(state_ma[box_no],FIRSTSPEC); - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i,j,k,n) = force_ma[box_no](i,j,k,n) + dt * dhat_ma[box_no](i,j,k,n); - } - for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i,j,k,n) = force_aux_ma[box_no](i,j,k,n) + dt * dhat_aux_ma[box_no](i,j,k,n); - } - }); - } + amrex::ParallelFor( + ldata_p->state, + [state_ma, dhat_ma, force_ma, aux_ma, dhat_aux_ma, force_aux_ma, + nAux = m_nAux, + dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rhoY(state_ma[box_no], FIRSTSPEC); + for (int n = 0; n < NUM_SPECIES; ++n) { + rhoY(i, j, k, n) = + force_ma[box_no](i, j, k, n) + dt * dhat_ma[box_no](i, j, k, n); + } + for (int n = 0; n < nAux; ++n) { + aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + + dt * dhat_aux_ma[box_no](i, j, k, n); + } + }); + } } Gpu::streamSynchronize(); @@ -1507,7 +1542,6 @@ PeleLM::deltaTIter_prepare( auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - auto state_old_ma = ldataOld_p->state.const_arrays(); auto state_new_ma = ldataNew_p->state.const_arrays(); auto force_ma = advData->Forcing[lev].const_arrays(); @@ -1515,26 +1549,31 @@ PeleLM::deltaTIter_prepare( auto rhs_ma = a_rhs[lev]->arrays(); auto rhocp_ma = a_rhoCp[lev]->arrays(); auto tsave_ma = a_Tsave[lev]->arrays(); - - amrex::ParallelFor(ldataNew_p->state, [state_old_ma,state_new_ma,force_ma,dhat_ma, rhs_ma,rhocp_ma,tsave_ma,dtinv, leosparm,dt=m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 rhoH_o(state_old_ma[box_no],RHOH); - Array4 rhoH_n(state_new_ma[box_no],RHOH); - Array4 force(force_ma[box_no],NUM_SPECIES); - Array4 fourier(dhat_ma[box_no],NUM_SPECIES); - Array4 diffDiff(dhat_ma[box_no],NUM_SPECIES+1); - // Assemble deltaT RHS - rhs_ma[box_no](i,j,k) = dt * ((rhoH_o(i, j, k) - rhoH_n(i, j, k)) * dtinv + force(i, j, k) + - fourier(i, j, k) + diffDiff(i, j, k)); - - Array4 rho(state_new_ma[box_no],DENSITY); - Array4 rhoY(state_new_ma[box_no],FIRSTSPEC); - Array4 T(state_new_ma[box_no],TEMP); - // Get \rho * Cp_{mix} - getCpmixGivenRYT(i, j, k, rho, rhoY, T, rhocp_ma[box_no], leosparm); - rhocp_ma[box_no](i, j, k) *= rho(i, j, k); - - // Save T - tsave_ma[box_no](i, j, k) = T(i, j, k); + + amrex::ParallelFor( + ldataNew_p->state, + [state_old_ma, state_new_ma, force_ma, dhat_ma, rhs_ma, rhocp_ma, + tsave_ma, dtinv, leosparm, + dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rhoH_o(state_old_ma[box_no], RHOH); + Array4 rhoH_n(state_new_ma[box_no], RHOH); + Array4 force(force_ma[box_no], NUM_SPECIES); + Array4 fourier(dhat_ma[box_no], NUM_SPECIES); + Array4 diffDiff(dhat_ma[box_no], NUM_SPECIES + 1); + // Assemble deltaT RHS + rhs_ma[box_no](i, j, k) = + dt * ((rhoH_o(i, j, k) - rhoH_n(i, j, k)) * dtinv + force(i, j, k) + + fourier(i, j, k) + diffDiff(i, j, k)); + + Array4 rho(state_new_ma[box_no], DENSITY); + Array4 rhoY(state_new_ma[box_no], FIRSTSPEC); + Array4 T(state_new_ma[box_no], TEMP); + // Get \rho * Cp_{mix} + getCpmixGivenRYT(i, j, k, rho, rhoY, T, rhocp_ma[box_no], leosparm); + rhocp_ma[box_no](i, j, k) *= rho(i, j, k); + + // Save T + tsave_ma[box_no](i, j, k) = T(i, j, k); }); // Set T^{np1} to zero @@ -1664,7 +1703,7 @@ PeleLM::getScalarDiffForce( auto* ldataR_p = getLevelDataReactPtr(lev); auto dn_ma = diffData->Dn[lev].const_arrays(); - auto dnp1_ma = diffData->Dnp1[lev].const_arrays(); + auto dnp1_ma = diffData->Dnp1[lev].const_arrays(); auto r_ma = ldataR_p->I_R.const_arrays(); auto a_ma = advData->AofS[lev].const_arrays(); auto ext_ma = m_extSource[lev]->const_arrays(); @@ -1675,14 +1714,25 @@ PeleLM::getScalarDiffForce( auto a_aux_ma = advData->AofS_aux[lev].const_arrays(); auto dn_aux_ma = diffData->Dn_aux[lev].const_arrays(); auto dnp1_aux_ma = diffData->Dnp1_aux[lev].const_arrays(); - - amrex::ParallelFor(advData->Forcing[lev],[dn_ma,dnp1_ma,r_ma,a_ma,ext_ma,f_ma, dwbar_ma, dT_ma, f_aux_ma, a_aux_ma, dn_aux_ma, dnp1_aux_ma,do_react = m_do_react,use_wbar = m_use_wbar, use_soret = m_use_soret, dp0dt = m_dp0dt,is_closed_ch = m_closed_chamber, nAux = m_nAux,aux_advect_d, aux_diffuse_d] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 ddn(dn_ma[box_no],NUM_SPECIES+1); - Array4 ddnp1(dnp1_ma[box_no],NUM_SPECIES+1); - Array4 extRhoY(ext_ma[box_no],FIRSTSPEC); - Array4 extRhoH(ext_ma[box_no],RHOH); - Array4 fT(f_ma[box_no],NUM_SPECIES); - buildDiffusionForcing(i, j, k, dn_ma[box_no], ddn, dnp1_ma[box_no], ddnp1, r_ma[box_no], a_ma[box_no], dp0dt, is_closed_ch,do_react, f_ma[box_no], fT, dwbar_ma[box_no], dT_ma[box_no], extRhoY, extRhoH, use_wbar, use_soret, f_aux_ma[box_no], a_aux_ma[box_no], dn_aux_ma[box_no], dnp1_aux_ma[box_no] , aux_advect_d, aux_diffuse_d, nAux); + + amrex::ParallelFor( + advData->Forcing[lev], + [dn_ma, dnp1_ma, r_ma, a_ma, ext_ma, f_ma, dwbar_ma, dT_ma, f_aux_ma, + a_aux_ma, dn_aux_ma, dnp1_aux_ma, do_react = m_do_react, + use_wbar = m_use_wbar, use_soret = m_use_soret, dp0dt = m_dp0dt, + is_closed_ch = m_closed_chamber, nAux = m_nAux, aux_advect_d, + aux_diffuse_d] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 ddn(dn_ma[box_no], NUM_SPECIES + 1); + Array4 ddnp1(dnp1_ma[box_no], NUM_SPECIES + 1); + Array4 extRhoY(ext_ma[box_no], FIRSTSPEC); + Array4 extRhoH(ext_ma[box_no], RHOH); + Array4 fT(f_ma[box_no], NUM_SPECIES); + buildDiffusionForcing( + i, j, k, dn_ma[box_no], ddn, dnp1_ma[box_no], ddnp1, r_ma[box_no], + a_ma[box_no], dp0dt, is_closed_ch, do_react, f_ma[box_no], fT, + dwbar_ma[box_no], dT_ma[box_no], extRhoY, extRhoH, use_wbar, + use_soret, f_aux_ma[box_no], a_aux_ma[box_no], dn_aux_ma[box_no], + dnp1_aux_ma[box_no], aux_advect_d, aux_diffuse_d, nAux); }); } Gpu::streamSynchronize(); @@ -1792,9 +1842,9 @@ PeleLM::getDiffusionTensorOpBC( Vector> r(AMREX_SPACEDIM); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if (Geom(0).isPeriodic(idim)) { - AMREX_D_TERM( - r[0][idim] = LinOpBCType::Periodic;, r[1][idim] = LinOpBCType::Periodic; - , r[2][idim] = LinOpBCType::Periodic;); + AMREX_D_TERM(r[0][idim] = LinOpBCType::Periodic; + , r[1][idim] = LinOpBCType::Periodic; + , r[2][idim] = LinOpBCType::Periodic;); } else { for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { auto amrexbc = (a_side == Orientation::low) ? a_bc[dir].lo(idim) diff --git a/Source/PeleLMeX_DiffusionOp.H b/Source/PeleLMeX_DiffusionOp.H index fbb6b1cdb..49dd0e9f4 100644 --- a/Source/PeleLMeX_DiffusionOp.H +++ b/Source/PeleLMeX_DiffusionOp.H @@ -75,7 +75,7 @@ public: void computeDiffFluxes( amrex::Vector> const& - a_fluxes, + a_fluxes, const int flux_comp, amrex::Vector const& a_phi, const int phi_comp, diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index 3c59c936a..be622a1e4 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -280,21 +280,24 @@ DiffusionOp::diffuse_scalar( // Copy the results of the solve back into a_phi // Times rho{np1,kp1} if needed // Don't touch the ghost cells - + if (!have_density) { - for (int lev = 0; lev <= finest_level; ++lev) { - MultiFab::Copy(*a_phi[lev],phi[lev],0,0,ncomp,0); + for (int lev = 0; lev <= finest_level; ++lev) { + MultiFab::Copy(*a_phi[lev], phi[lev], 0, 0, ncomp, 0); } } else { - for (int lev = 0; lev <= finest_level; ++lev) { + for (int lev = 0; lev <= finest_level; ++lev) { auto a_phi_ma = a_phi[lev]->arrays(); - auto phi_ma = phi[lev].const_arrays(); - auto a_rho_ma = a_density[lev]->const_arrays(); - amrex::ParallelFor(phi[lev], [a_phi_ma,a_rho_ma,phi_ma,ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < ncomp; ++n) { - a_phi_ma[box_no](i,j,k,n) = phi_ma[box_no](i,j,k,n) * a_rho_ma[box_no](i,j,k); - } - }); + auto phi_ma = phi[lev].const_arrays(); + auto a_rho_ma = a_density[lev]->const_arrays(); + amrex::ParallelFor( + phi[lev], [a_phi_ma, a_rho_ma, phi_ma, ncomp] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < ncomp; ++n) { + a_phi_ma[box_no](i, j, k, n) = + phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); + } + }); } Gpu::streamSynchronize(); } @@ -488,22 +491,25 @@ DiffusionOp::diffuse_scalar( // Don't touch the ghost cells if (!have_density) { - for (int lev = 0; lev <= finest_level; ++lev) { - MultiFab::Copy(a_phi[lev],phi[lev],0,0,ncomp,0); + for (int lev = 0; lev <= finest_level; ++lev) { + MultiFab::Copy(a_phi[lev], phi[lev], 0, 0, ncomp, 0); } } else { - for (int lev = 0; lev <= finest_level; ++lev) { + for (int lev = 0; lev <= finest_level; ++lev) { auto a_phi_ma = a_phi[lev]->arrays(); - auto phi_ma = phi[lev].const_arrays(); - auto a_rho_ma = a_density[lev]->const_arrays(); - amrex::ParallelFor(phi[lev], [a_phi_ma,a_rho_ma,phi_ma,ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < ncomp; ++n) { - a_phi_ma[box_no](i,j,k,n) = phi_ma[box_no](i,j,k,n) * a_rho_ma[box_no](i,j,k); - } - }); + auto phi_ma = phi[lev].const_arrays(); + auto a_rho_ma = a_density[lev]->const_arrays(); + amrex::ParallelFor( + phi[lev], [a_phi_ma, a_rho_ma, phi_ma, ncomp] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < ncomp; ++n) { + a_phi_ma[box_no](i, j, k, n) = + phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); + } + }); } Gpu::streamSynchronize(); - } + } } #endif @@ -811,9 +817,8 @@ DiffusionOp::computeDiffFluxes( fluxes[lev][idim] = std::make_unique( *a_flux[lev][idim], amrex::make_alias, flux_comp + comp, m_ncomp); } - ebfluxes.push_back( - std::make_unique( - *a_EBflux[lev], amrex::make_alias, ebflux_comp + comp, m_ncomp)); + ebfluxes.push_back(std::make_unique( + *a_EBflux[lev], amrex::make_alias, ebflux_comp + comp, m_ncomp)); component.emplace_back(phi[lev], amrex::make_alias, comp, m_ncomp); if (have_boundary != 0) { boundary.emplace_back( @@ -1170,13 +1175,15 @@ DiffusionTensorOp::compute_divtau( for (int lev = 0; lev <= finest_level; ++lev) { auto divtau_ma = a_divtau[lev]->arrays(); auto rho_ma = a_density[lev]->const_arrays(); - amrex::ParallelFor(*a_divtau[lev],[divtau_ma,rho_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - divtau_ma[box_no](i,j,k,n) /= rho_ma[box_no](i,j,k); - } - }); + amrex::ParallelFor( + *a_divtau[lev], [divtau_ma, rho_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + divtau_ma[box_no](i, j, k, n) /= rho_ma[box_no](i, j, k); + } + }); } - } + } } void @@ -1233,17 +1240,22 @@ DiffusionTensorOp::diffuse_velocity( auto vel_ma = a_vel[lev]->const_arrays(); if (m_pelelm->m_incompressible == 0) { auto rho_ma = a_density[lev]->const_arrays(); - amrex::ParallelFor(rhs[lev],[rhs_ma,vel_ma,rho_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - rhs_ma[box_no](i,j,k,n) = rho_ma[box_no](i,j,k) * vel_ma[box_no](i,j,k,n); - } - }); + amrex::ParallelFor( + rhs[lev], [rhs_ma, vel_ma, rho_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + rhs_ma[box_no](i, j, k, n) = + rho_ma[box_no](i, j, k) * vel_ma[box_no](i, j, k, n); + } + }); } else { - amrex::ParallelFor(rhs[lev],[rhs_ma,vel_ma,rho = m_pelelm->m_rho] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - rhs_ma[box_no](i,j,k,n) = rho * vel_ma[box_no](i,j,k,n); - } - }); + amrex::ParallelFor( + rhs[lev], [rhs_ma, vel_ma, rho = m_pelelm->m_rho] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + rhs_ma[box_no](i, j, k, n) = rho * vel_ma[box_no](i, j, k, n); + } + }); } } diff --git a/Source/PeleLMeX_EB.cpp b/Source/PeleLMeX_EB.cpp index ace760822..4e845cc30 100644 --- a/Source/PeleLMeX_EB.cpp +++ b/Source/PeleLMeX_EB.cpp @@ -91,10 +91,9 @@ PeleLM::redistributeAofS( if (flagfab.getType(bx) != FabType::covered) { if (flagfab.getType(grow(bx, 4)) != FabType::regular) { - AMREX_D_TERM( - auto apx = ebfact.getAreaFrac()[0]->const_array(mfi); - , auto apy = ebfact.getAreaFrac()[1]->const_array(mfi); - , auto apz = ebfact.getAreaFrac()[2]->const_array(mfi);); + AMREX_D_TERM(auto apx = ebfact.getAreaFrac()[0]->const_array(mfi); + , auto apy = ebfact.getAreaFrac()[1]->const_array(mfi); + , auto apz = ebfact.getAreaFrac()[2]->const_array(mfi);); AMREX_D_TERM( Array4 fcx = ebfact.getFaceCent()[0]->const_array(mfi); , Array4 fcy = ebfact.getFaceCent()[1]->const_array(mfi); @@ -221,10 +220,9 @@ PeleLM::redistributeDiff( if (flagfab.getType(bx) != FabType::covered) { if (flagfab.getType(grow(bx, 4)) != FabType::regular) { - AMREX_D_TERM( - auto apx = ebfact.getAreaFrac()[0]->const_array(mfi); - , auto apy = ebfact.getAreaFrac()[1]->const_array(mfi); - , auto apz = ebfact.getAreaFrac()[2]->const_array(mfi);); + AMREX_D_TERM(auto apx = ebfact.getAreaFrac()[0]->const_array(mfi); + , auto apy = ebfact.getAreaFrac()[1]->const_array(mfi); + , auto apz = ebfact.getAreaFrac()[2]->const_array(mfi);); AMREX_D_TERM( Array4 fcx = ebfact.getFaceCent()[0]->const_array(mfi); , Array4 fcy = ebfact.getFaceCent()[1]->const_array(mfi); @@ -274,18 +272,16 @@ PeleLM::initCoveredState() // Zero velocities, typical values on species, 'cold' temperature if (m_incompressible != 0) { coveredState_h.resize(AMREX_SPACEDIM); - AMREX_D_TERM( - coveredState_h[0] = 0.0;, coveredState_h[1] = 0.0; - , coveredState_h[2] = 0.0;) + AMREX_D_TERM(coveredState_h[0] = 0.0;, coveredState_h[1] = 0.0; + , coveredState_h[2] = 0.0;) coveredState_d.resize(AMREX_SPACEDIM); Gpu::copy( Gpu::hostToDevice, coveredState_h.begin(), coveredState_h.end(), coveredState_d.begin()); } else { coveredState_h.resize(NVAR); - AMREX_D_TERM( - coveredState_h[0] = 0.0;, coveredState_h[1] = 0.0; - , coveredState_h[2] = 0.0;) + AMREX_D_TERM(coveredState_h[0] = 0.0;, coveredState_h[1] = 0.0; + , coveredState_h[2] = 0.0;) coveredState_h[DENSITY] = typical_values[DENSITY]; for (int n = 0; n < NUM_SPECIES; n++) { coveredState_h[FIRSTSPEC + n] = typical_values[FIRSTSPEC + n]; @@ -373,15 +369,13 @@ PeleLM::initialRedistribution() (flagfab.getType(amrex::grow(bx, 4)) != FabType::regular)) { Array4 AMREX_D_DECL(fcx, fcy, fcz), ccc, vfrac, AMREX_D_DECL(apx, apy, apz); - AMREX_D_TERM( - fcx = fact.getFaceCent()[0]->const_array(mfi); - , fcy = fact.getFaceCent()[1]->const_array(mfi); - , fcz = fact.getFaceCent()[2]->const_array(mfi);); + AMREX_D_TERM(fcx = fact.getFaceCent()[0]->const_array(mfi); + , fcy = fact.getFaceCent()[1]->const_array(mfi); + , fcz = fact.getFaceCent()[2]->const_array(mfi);); ccc = fact.getCentroid().const_array(mfi); - AMREX_D_TERM( - apx = fact.getAreaFrac()[0]->const_array(mfi); - , apy = fact.getAreaFrac()[1]->const_array(mfi); - , apz = fact.getAreaFrac()[2]->const_array(mfi);); + AMREX_D_TERM(apx = fact.getAreaFrac()[0]->const_array(mfi); + , apy = fact.getAreaFrac()[1]->const_array(mfi); + , apz = fact.getAreaFrac()[2]->const_array(mfi);); vfrac = fact.getVolFrac().const_array(mfi); if (m_incompressible != 0) { @@ -468,9 +462,8 @@ PeleLM::getEBState(int first_comp, int ncomp, const PeleLM::TimeStamp& a_time) Vector> r; r.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back( - std::make_unique( - grids[lev], dmap[lev], ncomp, m_nGrowState, MFInfo(), Factory(lev))); + r.push_back(std::make_unique( + grids[lev], dmap[lev], ncomp, m_nGrowState, MFInfo(), Factory(lev))); getEBState(lev, a_time, *r[lev], first_comp, ncomp); } return r; @@ -587,10 +580,9 @@ PeleLM::getEBState( hasBCNormalEB::value> EBfiller{lprobparm, ProblemSpecificFunctions{}}; const auto& state = ldata_p->state.const_array(mfi); - AMREX_D_TERM( - const auto& ebfc_x = faceCentroid[0]->array(mfi); - , const auto& ebfc_y = faceCentroid[1]->array(mfi); - , const auto& ebfc_z = faceCentroid[2]->array(mfi);); + AMREX_D_TERM(const auto& ebfc_x = faceCentroid[0]->array(mfi); + , const auto& ebfc_y = faceCentroid[1]->array(mfi); + , const auto& ebfc_z = faceCentroid[2]->array(mfi);); const auto& ebnorm = ebfact.getBndryNormal().const_array(mfi); amrex::ParallelFor( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { @@ -646,10 +638,9 @@ PeleLM::getEBDiff( ProblemSpecificFunctions, hasBCTypeEB::value> EBTypfiller{lprobparm, ProblemSpecificFunctions{}}; - AMREX_D_TERM( - const auto& ebfc_x = faceCentroid[0]->array(mfi); - , const auto& ebfc_y = faceCentroid[1]->array(mfi); - , const auto& ebfc_z = faceCentroid[2]->array(mfi);); + AMREX_D_TERM(const auto& ebfc_x = faceCentroid[0]->array(mfi); + , const auto& ebfc_y = faceCentroid[1]->array(mfi); + , const auto& ebfc_z = faceCentroid[2]->array(mfi);); amrex::ParallelFor( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Regular/covered cells -> 0.0 @@ -691,10 +682,10 @@ PeleLM::correct_vel_small_cells( EBCellFlagFab const& flags = EBFactory(lev).getMultiEBCellFlagFab()[mfi]; // Face-centered velocity components - AMREX_D_TERM( - const auto& umac_fab = (a_umac[lev][0])->const_array(mfi); - , const auto& vmac_fab = (a_umac[lev][1])->const_array(mfi); - , const auto& wmac_fab = (a_umac[lev][2])->const_array(mfi);); + AMREX_D_TERM(const auto& umac_fab = (a_umac[lev][0])->const_array(mfi); + , const auto& vmac_fab = (a_umac[lev][1])->const_array(mfi); + , + const auto& wmac_fab = (a_umac[lev][2])->const_array(mfi);); // No cut cells in this FAB if ( @@ -703,13 +694,12 @@ PeleLM::correct_vel_small_cells( // do nothing } else { // Cut cells in this FAB // Face-centered areas - AMREX_D_TERM( - const auto& apx_fab = - EBFactory(lev).getAreaFrac()[0]->const_array(mfi); - , const auto& apy_fab = - EBFactory(lev).getAreaFrac()[1]->const_array(mfi); - , const auto& apz_fab = - EBFactory(lev).getAreaFrac()[2]->const_array(mfi);); + AMREX_D_TERM(const auto& apx_fab = + EBFactory(lev).getAreaFrac()[0]->const_array(mfi); + , const auto& apy_fab = + EBFactory(lev).getAreaFrac()[1]->const_array(mfi); + , const auto& apz_fab = + EBFactory(lev).getAreaFrac()[2]->const_array(mfi);); const auto& vfrac_fab = EBFactory(lev).getVolFrac().const_array(mfi); @@ -786,14 +776,12 @@ void PeleLM::checkEBInflowFunctions() { if (!hasBCNormalEB::value) { - Abort( - "Provided ProblemSpecificFunctions doesn't have a viable bcnormal_eb " - "function"); + Abort("Provided ProblemSpecificFunctions doesn't have a viable bcnormal_eb " + "function"); } if (!hasBCTypeEB::value) { - Abort( - "Provided ProblemSpecificFunctions doesn't have a viable bctype_eb " - "function"); + Abort("Provided ProblemSpecificFunctions doesn't have a viable bctype_eb " + "function"); } if (m_verbose != 0 && m_useEBinflow != 0) { Print() << "WARNING: EB-inflow capability is experimental. Scalar " diff --git a/Source/PeleLMeX_FlowController.cpp b/Source/PeleLMeX_FlowController.cpp index 19d4d5f67..9d248652c 100644 --- a/Source/PeleLMeX_FlowController.cpp +++ b/Source/PeleLMeX_FlowController.cpp @@ -33,9 +33,8 @@ PeleLM::initActiveControl() // Active control checks if ((m_ctrl_useTemp != 0) && (m_ctrl_temperature <= 0.0)) { - amrex::Error( - "active_control.temperature MUST be set with " - "active_control.use_temp = 1"); + amrex::Error("active_control.temperature MUST be set with " + "active_control.use_temp = 1"); } if ((m_ctrl_active != 0) && (m_ctrl_tauControl <= 0.0)) { @@ -343,10 +342,9 @@ PeleLM::getActiveControlLowT(Real& a_coft) idx[AC_FlameDir] -= 1; if (T_arr(idx[0], idx[1], idx[2], TEMP) < AC_Tcross) { Real coor[3] = {0.0}; - AMREX_D_TERM( - coor[0] = prob_lo[0] + (i + 0.5) * dx[0]; - , coor[1] = prob_lo[1] + (j + 0.5) * dx[1]; - , coor[2] = prob_lo[2] + (k + 0.5) * dx[2];); + AMREX_D_TERM(coor[0] = prob_lo[0] + (i + 0.5) * dx[0]; + , coor[1] = prob_lo[1] + (j + 0.5) * dx[1]; + , coor[2] = prob_lo[2] + (k + 0.5) * dx[2];); Real slope = ((T_arr(i, j, k, TEMP)) - T_arr(idx[0], idx[1], idx[2], TEMP)) / dx[AC_FlameDir]; @@ -381,10 +379,9 @@ PeleLM::getActiveControlLowT(Real& a_coft) idx[AC_FlameDir] -= 1; if (T_arr(idx[0], idx[1], idx[2], TEMP) < AC_Tcross) { Real coor[3] = {0.0}; - AMREX_D_TERM( - coor[0] = prob_lo[0] + (i + 0.5) * dx[0]; - , coor[1] = prob_lo[1] + (j + 0.5) * dx[1]; - , coor[2] = prob_lo[2] + (k + 0.5) * dx[2];); + AMREX_D_TERM(coor[0] = prob_lo[0] + (i + 0.5) * dx[0]; + , coor[1] = prob_lo[1] + (j + 0.5) * dx[1]; + , coor[2] = prob_lo[2] + (k + 0.5) * dx[2];); Real slope = ((T_arr(i, j, k, TEMP)) - T_arr(idx[0], idx[1], idx[2], TEMP)) / dx[AC_FlameDir]; diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 3d7f41798..3982dca6a 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -11,11 +11,11 @@ PeleLM::getVelForces( const TimeStamp& a_time, const Vector& a_divTau, const Vector& a_velForce, - int nGrowForce, - int add_gradP) + const int nGrowForce, + const int add_gradP) { BL_PROFILE("PeleLMeX::getVelForces()"); - int has_divTau = static_cast(!a_divTau.empty()); + const int has_divTau = static_cast(!a_divTau.empty()); for (int lev = 0; lev <= finest_level; ++lev) { if (has_divTau != 0) { @@ -34,10 +34,10 @@ PeleLM::getVelForces( void PeleLM::getVelForces( const TimeStamp& a_time, - int lev, + const int lev, MultiFab* a_divTau, MultiFab* a_velForce, - int add_gradP) + const int add_gradP) { // Get level data @@ -49,9 +49,35 @@ PeleLM::getVelForces( auto* ldataGP_p = (m_t_old[lev] < 0.0) ? getLevelDataPtr(lev, AmrNewTime) : getLevelDataPtr(lev, AmrOldTime); - Real time = getTime(lev, a_time); + const Real time = getTime(lev, a_time); + + const int has_divTau = static_cast(a_divTau != nullptr); - int has_divTau = static_cast(a_divTau != nullptr); + auto state_ma = ldata_p->state.const_arrays(); + auto ext_ma = m_extSource[lev]->const_arrays(); + auto force_ma = a_velForce->arrays(); + const auto dx = geom[lev].CellSizeArray(); + + amrex::ParallelFor( + *a_velForce, + [state_ma, ext_ma, force_ma, dx, grav = m_gravity, gp0 = m_background_gp, + ps_dir = m_ctrl_flameDir, is_incomp = m_incompressible, rho_incomp = m_rho, + pseudo_gravity = m_ctrl_pseudoGravity, + dV_control = m_ctrl_dV] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) { + Array4 vel(state_ma[box_no], VELX); + Array4 rho(state_ma[box_no], DENSITY); + Array4 rhoY(state_ma[box_no], FIRSTSPEC); + Array4 rhoh(state_ma[box_no], RHOH); + Array4 temp(state_ma[box_no], TEMP); + Array4 extmom(ext_ma[box_no], VELX); + Array4 extrho(ext_ma[box_no], DENSITY); + makeVelForce( + i, j, k, is_incomp, rho_incomp, pseudo_gravity, ps_dir, a_time, grav, + gp0, dV_control, dx, vel, rho, rhoY, rhoh, temp, extMom, extRho, force); + if (add_gradP != 0 || has_divTau != 0) { + // TLH::HERE!!! Leave Lorentz in second MFIter + } + }); #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) @@ -192,7 +218,8 @@ PeleLM::addSpark(const TimeStamp& a_timestamp) auto const dx = geom[lev].CellSizeArray(); IntVect spark_idx; for (int d = 0; d < AMREX_SPACEDIM; d++) { - spark_idx[d] = (int)((m_spark_location[n][d] - probLo[d]) / dx[d]); + spark_idx[d] = + static_cast((m_spark_location[n][d] - probLo[d]) / dx[d]); } Box domainBox = geom[lev].Domain(); // just a check @@ -256,9 +283,8 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) for (int n = 0; n < MANIFOLD_DIM; ++n) { if (leosparm.is_variance_of[n] >= 0) { if (!m_do_les) { - amrex::Abort( - "PeleLM::addScalarVarianceSources(): cannot add a " - "scalar dissipation without an active LES model"); + amrex::Abort("PeleLM::addScalarVarianceSources(): cannot add a " + "scalar dissipation without an active LES model"); } nvariances += 1; var_of_scalar = FIRSTSPEC + leosparm.is_variance_of[n]; @@ -319,10 +345,9 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) m_leveldata_old[lev]->visc_turb_fc[1].const_arrays(); , auto const& mut_arr_z = m_leveldata_old[lev]->visc_turb_fc[2].const_arrays();) - AMREX_D_TERM( - auto const& gx = grad_fc[lev][0].const_arrays(); - , auto const& gy = grad_fc[lev][1].const_arrays(); - , auto const& gz = grad_fc[lev][2].const_arrays();) + AMREX_D_TERM(auto const& gx = grad_fc[lev][0].const_arrays(); + , auto const& gy = grad_fc[lev][1].const_arrays(); + , auto const& gz = grad_fc[lev][2].const_arrays();) auto extma = m_extSource[lev]->arrays(); auto statema = ldata_p->state.const_arrays(); diff --git a/Source/PeleLMeX_K.H b/Source/PeleLMeX_K.H index 6f00a7697..b4008346e 100644 --- a/Source/PeleLMeX_K.H +++ b/Source/PeleLMeX_K.H @@ -105,13 +105,13 @@ getTransportCoeff( // Soret coefficient scaling, see Howarth, Day, Pitsch & Aspden #if defined(H2_ID) rhotheta(i, j, k, H2_ID) *= 0.664; -#endif +#endif #if defined(H_ID) rhotheta(i, j, k, H_ID) *= 0.58; #endif #if !defined(H2_ID) && !defined(H_ID) amrex::Abort("Running with Soret without light species, waste of time " - "and memory..."); + "and memory..."); #endif } } @@ -462,7 +462,8 @@ EB_intFluxDivergence_K( using namespace amrex::literals; const amrex::Real factor = scaling / vol(i, j, k); - const amrex::Real eb_area = AMREX_D_TERM(1.0, *a_dx, *a_dx) * ebAreaFrac(i, j, k); + const amrex::Real eb_area = + AMREX_D_TERM(1.0, *a_dx, *a_dx) * ebAreaFrac(i, j, k); for (int n = 0; n < ncomp; ++n) { div(i, j, k, n) = AMREX_D_TERM( @@ -960,7 +961,8 @@ buildAdvectionForcing( amrex::Real cpmix_cgs = 0.0_rt; eos.TY2Cp(T(i, j, k), y, cpmix_cgs); - const amrex::Real cpmixinv = 1.0_rt / c2m::Cp(cpmix_cgs); // CGS -> MKS conversion + const amrex::Real cpmixinv = + 1.0_rt / c2m::Cp(cpmix_cgs); // CGS -> MKS conversion forceT(i, j, k) *= rhoinv * cpmixinv; } @@ -1038,9 +1040,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE void reactionRateRhoY( - const int i, - const int j, - const int k, + const int i, + const int j, + const int k, amrex::Array4 const& rhoY, amrex::Array4 const& rhoH, amrex::Array4 const& T, @@ -1203,13 +1205,13 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getGammaInv( - const int i, - const int j, - const int k, - amrex::Array4 const& rhoY, - amrex::Array4 const& T, - pele::physics::eos::EosParm const* - eosparm) noexcept + const int i, + const int j, + const int k, + amrex::Array4 const& rhoY, + amrex::Array4 const& T, + pele::physics::eos::EosParm const* + eosparm) noexcept { using namespace amrex::literals; @@ -1304,10 +1306,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void getTurbViscSmagorinsky( - const int i, - const int j, - const int k, - const amrex::Real prefactor, + const int i, + const int j, + const int k, + const amrex::Real prefactor, amrex::Array4 const& velgrad, amrex::Array4 const& rho, amrex::Array4 const& mu_t) noexcept @@ -1324,10 +1326,10 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void getTurbViscWALE( - const int i, - const int j, - const int k, - const amrex::Real prefactor, + const int i, + const int j, + const int k, + const amrex::Real prefactor, amrex::Array4 const& velgrad, amrex::Array4 const& rho, amrex::Array4 const& mu_t) noexcept @@ -1353,13 +1355,13 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void getTurbViscSigma( - const int i, - const int j, - const int k, - const amrex::Real prefactor, - amrex::Array4 const& velgrad, - amrex::Array4 const& rho, - amrex::Array4 const& mu_t) noexcept + const int i, + const int j, + const int k, + const amrex::Real prefactor, + amrex::Array4 const& velgrad, + amrex::Array4 const& rho, + amrex::Array4 const& mu_t) noexcept { #if (AMREX_SPACEDIM == 2) amrex::ignore_unused(i, j, k, prefactor, velgrad, rho, mu_t); @@ -1415,14 +1417,10 @@ getTurbViscSigma( // Singular values: amrex::Real sigma1 = std::sqrt( std::max(0.0, I[0] / 3.0 + 2.0 * std::sqrt(alpha1) * std::cos(alpha3))); - amrex::Real sigma2 = std::sqrt( - std::max( - 0.0, - I[0] / 3.0 - 2.0 * std::sqrt(alpha1) * std::cos(Pi / 3.0 + alpha3))); - amrex::Real sigma3 = std::sqrt( - std::max( - 0.0, - I[0] / 3.0 - 2.0 * std::sqrt(alpha1) * std::cos(Pi / 3.0 - alpha3))); + amrex::Real sigma2 = std::sqrt(std::max( + 0.0, I[0] / 3.0 - 2.0 * std::sqrt(alpha1) * std::cos(Pi / 3.0 + alpha3))); + amrex::Real sigma3 = std::sqrt(std::max( + 0.0, I[0] / 3.0 - 2.0 * std::sqrt(alpha1) * std::cos(Pi / 3.0 - alpha3))); // Sort sigma2 = std::max(sigma3, sigma2); diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 2cc177da1..aeca2d306 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -436,13 +436,12 @@ PeleLM::WritePlotFile() if (m_do_les && m_plot_les) { constexpr amrex::Real fact = 0.5 / AMREX_SPACEDIM; auto const& plot_arr = mf_plt[lev].arrays(); - AMREX_D_TERM( - auto const& mut_arr_x = - m_leveldata_old[lev]->visc_turb_fc[0].const_arrays(); - , auto const& mut_arr_y = - m_leveldata_old[lev]->visc_turb_fc[1].const_arrays(); - , auto const& mut_arr_z = - m_leveldata_old[lev]->visc_turb_fc[2].const_arrays();) + AMREX_D_TERM(auto const& mut_arr_x = + m_leveldata_old[lev]->visc_turb_fc[0].const_arrays(); + , auto const& mut_arr_y = + m_leveldata_old[lev]->visc_turb_fc[1].const_arrays(); + , auto const& mut_arr_z = + m_leveldata_old[lev]->visc_turb_fc[2].const_arrays();) // interpolate turbulent viscosity from faces to centers amrex::ParallelFor( mf_plt[lev], @@ -863,14 +862,12 @@ void PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) { if (m_incompressible != 0) { - Abort( - " initializing data from a pltfile only available for low-Mach " - "simulations"); + Abort(" initializing data from a pltfile only available for low-Mach " + "simulations"); } if (m_nAux > 0) { - Warning( - " restarting from plotfile with auxiliaries not currently " - "implemented, and will not be captured"); + Warning(" restarting from plotfile with auxiliaries not currently " + "implemented, and will not be captured"); } amrex::Print() << " initData on level " << a_lev << " from pltfile " << a_dataPltFile << "\n"; diff --git a/Source/PeleLMeX_ProblemSpecificFunctions.H b/Source/PeleLMeX_ProblemSpecificFunctions.H index cc64d7bc9..44b34b28b 100644 --- a/Source/PeleLMeX_ProblemSpecificFunctions.H +++ b/Source/PeleLMeX_ProblemSpecificFunctions.H @@ -101,9 +101,8 @@ struct DefaultProblemSpecificFunctions { amrex::ignore_unused( x, aux_ext, idir, sgn, time, geomdata, prob_parm, pmf_data); - amrex::Abort( - "Default empty bcnormal called, please override in your " - "problem specific struct !"); + amrex::Abort("Default empty bcnormal called, please override in your " + "problem specific struct !"); // For filling auxiliary variable boundary conditions // Retrieve nAux with aux_ext.ncomp, then aux_ext[n] = ... } @@ -161,9 +160,8 @@ struct DefaultProblemSpecificFunctions const int /*required_coarsening_level*/, const int /*max_coarsening_level*/) { - amrex::Abort( - "Default EBUserDefined function called! Redefine it in your " - "local ProblemSpecificFunctions struct !"); + amrex::Abort("Default EBUserDefined function called! Redefine it in your " + "local ProblemSpecificFunctions struct !"); /** Notes: * 1. ParmParse any parameter for your geometry * 2. Construct your geometry assembling EB2::* methods diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 04599206c..00fccf361 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -52,9 +52,8 @@ PeleLM::initialProjection() // Get velocity Vector> vel; for (int lev = 0; lev <= finest_level; ++lev) { - vel.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); + vel.push_back(std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); vel[lev]->setBndry(0.0); setInflowBoundaryVel(*vel[lev], lev, AmrNewTime); scaleProj_RZ(lev, *vel[lev]); @@ -268,9 +267,8 @@ PeleLM::velocityProjection( // Get velocity Vector> vel; for (int lev = 0; lev <= finest_level; ++lev) { - vel.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); + vel.push_back(std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); #ifdef AMREX_USE_EB EB_set_covered(*vel[lev], 0.0); #endif diff --git a/Source/PeleLMeX_Setup.cpp b/Source/PeleLMeX_Setup.cpp index cd9e76c2e..0d2c041db 100644 --- a/Source/PeleLMeX_Setup.cpp +++ b/Source/PeleLMeX_Setup.cpp @@ -577,15 +577,15 @@ PeleLM::readParameters() if (mgsc_size == 1) { int mgsc; pp.query("max_grid_size_chem", mgsc); - AMREX_D_TERM( - m_max_grid_size_chem[0] = mgsc;, m_max_grid_size_chem[1] = mgsc; - , m_max_grid_size_chem[2] = mgsc); + AMREX_D_TERM(m_max_grid_size_chem[0] = mgsc; + , m_max_grid_size_chem[1] = mgsc; + , m_max_grid_size_chem[2] = mgsc); } else if (mgsc_size == AMREX_SPACEDIM) { Vector mgsc; pp.getarr("max_grid_size_chem", mgsc, 0, AMREX_SPACEDIM); - AMREX_D_TERM( - m_max_grid_size_chem[0] = mgsc[0];, m_max_grid_size_chem[1] = mgsc[1]; - , m_max_grid_size_chem[2] = mgsc[2]); + AMREX_D_TERM(m_max_grid_size_chem[0] = mgsc[0]; + , m_max_grid_size_chem[1] = mgsc[1]; + , m_max_grid_size_chem[2] = mgsc[2]); } else { Abort("peleLM.max_grid_size_chem should have 1 or AMREX_SPACEDIM values"); } @@ -644,9 +644,8 @@ PeleLM::readParameters() m_advection_type = "BDS"; m_Godunov_ppm = 0; } else { - Abort( - "Unknown 'advection_scheme'. Recognized options are: Godunov_PLM, " - "Godunov_PPM or Godunov_BDS"); + Abort("Unknown 'advection_scheme'. Recognized options are: Godunov_PLM, " + "Godunov_PPM or Godunov_BDS"); } m_predict_advection_type = "Godunov"; // Only option at this point. This will disappear when @@ -843,10 +842,9 @@ PeleLM::checkSetupParams() std::abs( (0.1 * eos_parms.host_parm().Pnom_cgs - prob_parm->P_mean) / prob_parm->P_mean) > 1e-6) { - amrex::Abort( - "For Manifold EOS, pressure in manifold model " - "(manifold.nominal_pressure_cgs) and pressure in PeleLMeX " - "(prob.Pmean) must match"); + amrex::Abort("For Manifold EOS, pressure in manifold model " + "(manifold.nominal_pressure_cgs) and pressure in PeleLMeX " + "(prob.Pmean) must match"); } #endif } @@ -960,15 +958,13 @@ PeleLM::variablesSetup() Print() << " First ODE: " << FIRSTODE << "\n"; ProblemSpecificFunctions::set_ode_names(m_ode_names); if (m_ode_names.size() != NUM_ODE) { - Abort( - "ODEQty names improperly set. Adjust set_ode_names in " - "ProblemSpecificFunctions or NUM_ODE in GNUMakefile"); + Abort("ODEQty names improperly set. Adjust set_ode_names in " + "ProblemSpecificFunctions or NUM_ODE in GNUMakefile"); } for (int n = 0; n < NUM_ODE; ++n) { if (m_ode_names[n].empty()) { - Abort( - "ODEQty names improperly set. Adjust set_ode_names in " - "ProblemSpecificFunctions or NUM_ODE in GNUMakefile"); + Abort("ODEQty names improperly set. Adjust set_ode_names in " + "ProblemSpecificFunctions or NUM_ODE in GNUMakefile"); } stateComponents.emplace_back(FIRSTODE + n, m_ode_names[n]); } @@ -1373,9 +1369,8 @@ PeleLM::evaluateSetup() { Vector var_names( NVAR - 2); // Skip temperature and RhoRT, unused - AMREX_D_TERM( - var_names[VELX] = "A(VELX)";, var_names[VELY] = "A(VELY)"; - , var_names[VELZ] = "A(VELZ)"); + AMREX_D_TERM(var_names[VELX] = "A(VELX)";, var_names[VELY] = "A(VELY)"; + , var_names[VELZ] = "A(VELZ)"); var_names[DENSITY] = "A(Rho)"; for (int n = 0; n < NUM_SPECIES; n++) { var_names[FIRSTSPEC + n] = "A(" + spec_names[n] + ")"; @@ -1512,10 +1507,9 @@ PeleLM::taggingSetup() errTags.push_back(AMRErrorTag(info)); itexists = true; } else { - Abort( - std::string( - "Unrecognized refinement indicator for " + refinement_indicator) - .c_str()); + Abort(std::string( + "Unrecognized refinement indicator for " + refinement_indicator) + .c_str()); } if (!itexists) { diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index b58519d42..135fa4d1a 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -482,9 +482,8 @@ PeleLM::getDiffusivity( amrex::MultiFab::Add( beta_ec[idim], ldata_p->lambda_turb_fc[idim], 0, 0, 1, 0); } else { // Invalid - amrex::Abort( - "getDiffusivity(): LES model is on but cannot provide a " - "turbulent transport coefficient"); + amrex::Abort("getDiffusivity(): LES model is on but cannot provide a " + "turbulent transport coefficient"); } } } diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 7ad46486b..37a2f5e31 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -213,10 +213,10 @@ PeleLM::extFluxDivergenceLevel( #endif for (MFIter mfi(a_divergence, TilingIfNotGPU()); mfi.isValid(); ++mfi) { const Box& bx = mfi.tilebox(); - AMREX_D_TERM( - auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); - , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); - , auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); + AMREX_D_TERM(auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); + , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); + , + auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); auto const& divergence = a_divergence.array(mfi, div_comp); auto const& vol = volume.const_array(mfi); @@ -314,10 +314,10 @@ PeleLM::intFluxDivergenceLevel( #endif for (MFIter mfi(a_divergence, TilingIfNotGPU()); mfi.isValid(); ++mfi) { const Box& bx = mfi.tilebox(); - AMREX_D_TERM( - auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); - , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); - , auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); + AMREX_D_TERM(auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); + , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); + , + auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); auto const& divergence = a_divergence.array(mfi, div_comp); auto const& vol = volume.const_array(mfi); @@ -333,10 +333,9 @@ PeleLM::intFluxDivergenceLevel( }); } else if (flagfab.getType(bx) != FabType::regular) { // EB containing boxes auto vfrac = ebfact.getVolFrac().const_array(mfi); - AMREX_D_TERM( - const auto& afrac_x = areafrac[0]->array(mfi); - , const auto& afrac_y = areafrac[1]->array(mfi); - , const auto& afrac_z = areafrac[2]->array(mfi);); + AMREX_D_TERM(const auto& afrac_x = areafrac[0]->array(mfi); + , const auto& afrac_y = areafrac[1]->array(mfi); + , const auto& afrac_z = areafrac[2]->array(mfi);); amrex::ParallelFor( bx, [ncomp, flag, vfrac, divergence, AMREX_D_DECL(fluxX, fluxY, fluxZ), AMREX_D_DECL(afrac_x, afrac_y, afrac_z), @@ -436,10 +435,10 @@ PeleLM::intFluxDivergenceLevelEB( #endif for (MFIter mfi(a_divergence, TilingIfNotGPU()); mfi.isValid(); ++mfi) { const Box& bx = mfi.tilebox(); - AMREX_D_TERM( - auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); - , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); - , auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); + AMREX_D_TERM(auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); + , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); + , + auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); auto const& divergence = a_divergence.array(mfi, div_comp); auto const& vol = volume.const_array(mfi); @@ -456,10 +455,9 @@ PeleLM::intFluxDivergenceLevelEB( }); } else if (flagfab.getType(bx) != FabType::regular) { // EB containing boxes auto vfrac = ebfact.getVolFrac().const_array(mfi); - AMREX_D_TERM( - const auto& afrac_x = areafrac[0]->array(mfi); - , const auto& afrac_y = areafrac[1]->array(mfi); - , const auto& afrac_z = areafrac[2]->array(mfi);); + AMREX_D_TERM(const auto& afrac_x = areafrac[0]->array(mfi); + , const auto& afrac_y = areafrac[1]->array(mfi); + , const auto& afrac_z = areafrac[2]->array(mfi);); const auto& ebarea = eb_area->array(mfi); amrex::ParallelFor( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { @@ -544,10 +542,9 @@ PeleLM:: // Get the divergence auto const& div_arr = a_divergence.array(mfi, div_comp); - AMREX_D_TERM( - auto const& fx = a_fluxes[0]->const_array(mfi, flux_comp); - , auto const& fy = a_fluxes[1]->const_array(mfi, flux_comp); - , auto const& fz = a_fluxes[2]->const_array(mfi, flux_comp);) + AMREX_D_TERM(auto const& fx = a_fluxes[0]->const_array(mfi, flux_comp); + , auto const& fy = a_fluxes[1]->const_array(mfi, flux_comp); + , auto const& fz = a_fluxes[2]->const_array(mfi, flux_comp);) #ifdef AMREX_USE_EB auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; @@ -681,10 +678,9 @@ PeleLM::advFluxDivergence( // Get the divergence auto const& div_arr = a_divergence.array(mfi, div_comp); - AMREX_D_TERM( - auto const& fx = a_fluxes[0]->const_array(mfi, flux_comp); - , auto const& fy = a_fluxes[1]->const_array(mfi, flux_comp); - , auto const& fz = a_fluxes[2]->const_array(mfi, flux_comp);) + AMREX_D_TERM(auto const& fx = a_fluxes[0]->const_array(mfi, flux_comp); + , auto const& fy = a_fluxes[1]->const_array(mfi, flux_comp); + , auto const& fz = a_fluxes[2]->const_array(mfi, flux_comp);) auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; auto const& vfrac_arr = ebfact.getVolFrac().const_array(mfi); @@ -1560,9 +1556,8 @@ PeleLM::setTypicalValues(const TimeStamp& a_time, int is_init) #if NUM_ODE > 0 for (int n = 0; n < NUM_ODE; n++) { Print() << "\t" << m_ode_names[n] - << std::setw( - std::max( - 0, static_cast(10 - m_ode_names[n].length()))) + << std::setw(std::max( + 0, static_cast(10 - m_ode_names[n].length()))) << std::left << ":" << typical_values[FIRSTODE + n] << '\n'; } #endif @@ -1885,9 +1880,8 @@ PeleLM::initMixtureFraction() found = true; spec_Bilger_fact[n] = 1.0; } else { - amrex::Abort( - "initMixtureFraction: requested manifold parameter " - "found multiple times"); + amrex::Abort("initMixtureFraction: requested manifold parameter " + "found multiple times"); } } else { spec_Bilger_fact[n] = 0.0; diff --git a/Source/Plasma/LinOps/AMReX_MLABecCecLaplacian.cpp b/Source/Plasma/LinOps/AMReX_MLABecCecLaplacian.cpp index 6cd39371f..985188c5d 100644 --- a/Source/Plasma/LinOps/AMReX_MLABecCecLaplacian.cpp +++ b/Source/Plasma/LinOps/AMReX_MLABecCecLaplacian.cpp @@ -249,18 +249,15 @@ MLABecCecLaplacian::averageDownCoeffsSameAmrLevel( #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif for (MFIter mfi(a[mglev], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - AMREX_D_TERM( - Box const& xbx = mfi.nodaltilebox(0); - , Box const& ybx = mfi.nodaltilebox(1); - , Box const& zbx = mfi.nodaltilebox(2)); - AMREX_D_TERM( - Array4 const& bx = b[mglev][0].array(mfi); - , Array4 const& by = b[mglev][1].array(mfi); - , Array4 const& bz = b[mglev][2].array(mfi)); - AMREX_D_TERM( - Array4 const& cx = c[mglev][0].array(mfi); - , Array4 const& cy = c[mglev][1].array(mfi); - , Array4 const& cz = c[mglev][2].array(mfi)); + AMREX_D_TERM(Box const& xbx = mfi.nodaltilebox(0); + , Box const& ybx = mfi.nodaltilebox(1); + , Box const& zbx = mfi.nodaltilebox(2)); + AMREX_D_TERM(Array4 const& bx = b[mglev][0].array(mfi); + , Array4 const& by = b[mglev][1].array(mfi); + , Array4 const& bz = b[mglev][2].array(mfi)); + AMREX_D_TERM(Array4 const& cx = c[mglev][0].array(mfi); + , Array4 const& cy = c[mglev][1].array(mfi); + , Array4 const& cz = c[mglev][2].array(mfi)); Array4 const& osm = m_overset_mask[amrlev][mglev]->const_array(mfi); AMREX_LAUNCH_HOST_DEVICE_LAMBDA_DIM( @@ -366,14 +363,12 @@ MLABecCecLaplacian::Fapply( BL_PROFILE("MLABecCecLaplacian::Fapply()"); const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM( - const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM( - const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const auto dxinv = m_geom[amrlev][mglev].InvCellSizeArray(); @@ -391,14 +386,12 @@ MLABecCecLaplacian::Fapply( const auto& xfab = in.array(mfi); const auto& yfab = out.array(mfi); const auto& afab = acoef.array(mfi); - AMREX_D_TERM( - const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM( - const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); if (m_overset_mask[amrlev][mglev]) { const auto& osm = m_overset_mask[amrlev][mglev]->array(mfi); AMREX_LAUNCH_HOST_DEVICE_LAMBDA(bx, tbx, { @@ -424,14 +417,12 @@ MLABecCecLaplacian::normalize(int amrlev, int mglev, MultiFab& mf) const BL_PROFILE("MLABecCecLaplacian::normalize()"); const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM( - const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM( - const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const auto dxinv = m_geom[amrlev][mglev].InvCellSizeArray(); @@ -448,14 +439,12 @@ MLABecCecLaplacian::normalize(int amrlev, int mglev, MultiFab& mf) const const Box& bx = mfi.tilebox(); const auto& fab = mf.array(mfi); const auto& afab = acoef.array(mfi); - AMREX_D_TERM( - const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM( - const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); AMREX_LAUNCH_HOST_DEVICE_LAMBDA(bx, tbx, { mlabecceclap_normalize( @@ -478,14 +467,12 @@ MLABecCecLaplacian::Fsmooth( } const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM( - const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM( - const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const auto& undrrelxr = m_undrrelxr[amrlev][mglev]; const auto& maskvals = m_maskvals[amrlev][mglev]; @@ -521,13 +508,12 @@ MLABecCecLaplacian::Fsmooth( const int nc = getNComp(); const Real* h = m_geom[amrlev][mglev].CellSize(); - AMREX_D_TERM( - const Real dhxsq = m_b_scalar / (h[0] * h[0]); - , const Real dhysq = m_b_scalar / (h[1] * h[1]); - , const Real dhzsq = m_b_scalar / (h[2] * h[2])); - AMREX_D_TERM( - const Real dhx = m_c_scalar / (h[0]);, const Real dhy = m_c_scalar / (h[1]); - , const Real dhz = m_c_scalar / (h[2])); + AMREX_D_TERM(const Real dhxsq = m_b_scalar / (h[0] * h[0]); + , const Real dhysq = m_b_scalar / (h[1] * h[1]); + , const Real dhzsq = m_b_scalar / (h[2] * h[2])); + AMREX_D_TERM(const Real dhx = m_c_scalar / (h[0]); + , const Real dhy = m_c_scalar / (h[1]); + , const Real dhz = m_c_scalar / (h[2])); const Real alpha = m_a_scalar; const Real omega = m_omega; @@ -556,14 +542,12 @@ MLABecCecLaplacian::Fsmooth( const auto& rhsfab = rhs.array(mfi); const auto& afab = acoef.array(mfi); - AMREX_D_TERM( - const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM( - const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); const auto& f0fab = f0.array(mfi); const auto& f1fab = f1.array(mfi); @@ -651,24 +635,21 @@ MLABecCecLaplacian::checkDiagonalDominance(int amrlev, int mglev) BL_PROFILE("MLABecCecLaplacian::checkDiagonalDominance()"); const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM( - const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM( - const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const int nc = getNComp(); const Real* h = m_geom[amrlev][mglev].CellSize(); - AMREX_D_TERM( - const Real dhxsq = m_b_scalar / (h[0] * h[0]); - , const Real dhysq = m_b_scalar / (h[1] * h[1]); - , const Real dhzsq = m_b_scalar / (h[2] * h[2])); - AMREX_D_TERM( - const Real dhx = m_c_scalar / (h[0]);, const Real dhy = m_c_scalar / (h[1]); - , const Real dhz = m_c_scalar / (h[2])); + AMREX_D_TERM(const Real dhxsq = m_b_scalar / (h[0] * h[0]); + , const Real dhysq = m_b_scalar / (h[1] * h[1]); + , const Real dhzsq = m_b_scalar / (h[2] * h[2])); + AMREX_D_TERM(const Real dhx = m_c_scalar / (h[0]); + , const Real dhy = m_c_scalar / (h[1]); + , const Real dhz = m_c_scalar / (h[2])); const Real alpha = m_a_scalar; MFItInfo mfi_info; @@ -682,14 +663,12 @@ MLABecCecLaplacian::checkDiagonalDominance(int amrlev, int mglev) const Box& tbx = mfi.tilebox(); const auto& afab = acoef.array(mfi); - AMREX_D_TERM( - const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM( - const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); AMREX_LAUNCH_HOST_DEVICE_LAMBDA(tbx, thread_box, { abeccec_chkdiag( @@ -708,24 +687,21 @@ MLABecCecLaplacian::getDiagonal(int amrlev, MultiFab& diag) int mglev = 0; const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM( - const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM( - const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const int nc = getNComp(); const Real* h = m_geom[amrlev][mglev].CellSize(); - AMREX_D_TERM( - const Real dhxsq = m_b_scalar / (h[0] * h[0]); - , const Real dhysq = m_b_scalar / (h[1] * h[1]); - , const Real dhzsq = m_b_scalar / (h[2] * h[2])); - AMREX_D_TERM( - const Real dhx = m_c_scalar / (h[0]);, const Real dhy = m_c_scalar / (h[1]); - , const Real dhz = m_c_scalar / (h[2])); + AMREX_D_TERM(const Real dhxsq = m_b_scalar / (h[0] * h[0]); + , const Real dhysq = m_b_scalar / (h[1] * h[1]); + , const Real dhzsq = m_b_scalar / (h[2] * h[2])); + AMREX_D_TERM(const Real dhx = m_c_scalar / (h[0]); + , const Real dhy = m_c_scalar / (h[1]); + , const Real dhz = m_c_scalar / (h[2])); const Real alpha = m_a_scalar; MFItInfo mfi_info; @@ -739,14 +715,12 @@ MLABecCecLaplacian::getDiagonal(int amrlev, MultiFab& diag) const Box& tbx = mfi.tilebox(); const auto& afab = acoef.array(mfi); - AMREX_D_TERM( - const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM( - const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); const auto& adiag = diag.array(mfi); AMREX_LAUNCH_HOST_DEVICE_LAMBDA(tbx, thread_box, { @@ -767,24 +741,21 @@ MLABecCecLaplacian::getNetFaceCoeff(MultiFab& coeffs_dir, int dir) int mglev = 0.0; const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM( - const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM( - const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const int nc = getNComp(); const Real* h = m_geom[amrlev][mglev].CellSize(); - AMREX_D_TERM( - const Real dhxsq = m_b_scalar / (h[0] * h[0]); - , const Real dhysq = m_b_scalar / (h[1] * h[1]); - , const Real dhzsq = m_b_scalar / (h[2] * h[2])); - AMREX_D_TERM( - const Real dhx = m_c_scalar / (h[0]);, const Real dhy = m_c_scalar / (h[1]); - , const Real dhz = m_c_scalar / (h[2])); + AMREX_D_TERM(const Real dhxsq = m_b_scalar / (h[0] * h[0]); + , const Real dhysq = m_b_scalar / (h[1] * h[1]); + , const Real dhzsq = m_b_scalar / (h[2] * h[2])); + AMREX_D_TERM(const Real dhx = m_c_scalar / (h[0]); + , const Real dhy = m_c_scalar / (h[1]); + , const Real dhz = m_c_scalar / (h[2])); const Real alpha = m_a_scalar; MFItInfo mfi_info; @@ -798,14 +769,12 @@ MLABecCecLaplacian::getNetFaceCoeff(MultiFab& coeffs_dir, int dir) const Box& tbx = mfi.tilebox(); const auto& afab = acoef.array(mfi); - AMREX_D_TERM( - const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM( - const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); const auto& coeffd = coeffs_dir.array(mfi); AMREX_LAUNCH_HOST_DEVICE_LAMBDA(tbx, thread_box, { @@ -858,15 +827,15 @@ MLABecCecLaplacian::FFlux( int face_only, int ncomp) { - AMREX_D_TERM( - const auto bx = bcoef[0]->array();, const auto by = bcoef[1]->array(); - , const auto bz = bcoef[2]->array();); - AMREX_D_TERM( - const auto cx = ccoef[0]->array();, const auto cy = ccoef[1]->array(); - , const auto cz = ccoef[2]->array();); - AMREX_D_TERM( - const auto& fxarr = flux[0]->array();, const auto& fyarr = flux[1]->array(); - , const auto& fzarr = flux[2]->array();); + AMREX_D_TERM(const auto bx = bcoef[0]->array(); + , const auto by = bcoef[1]->array(); + , const auto bz = bcoef[2]->array();); + AMREX_D_TERM(const auto cx = ccoef[0]->array(); + , const auto cy = ccoef[1]->array(); + , const auto cz = ccoef[2]->array();); + AMREX_D_TERM(const auto& fxarr = flux[0]->array(); + , const auto& fyarr = flux[1]->array(); + , const auto& fzarr = flux[2]->array();); const auto& solarr = sol.array(); if (face_only) { diff --git a/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp b/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp index 69af3c5e9..cf4e1c43d 100644 --- a/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp +++ b/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp @@ -121,9 +121,8 @@ MLCellABecCecLap::define( for (amrlev = 1; amrlev < m_num_amr_levels; ++amrlev) { for (int mglev = 1; mglev < m_num_mg_levels[amrlev]; ++mglev) { // for ref_ratio 4 - m_overset_mask[amrlev].push_back( - std::make_unique( - m_grids[amrlev][mglev], m_dmap[amrlev][mglev], 1, 1)); + m_overset_mask[amrlev].push_back(std::make_unique( + m_grids[amrlev][mglev], m_dmap[amrlev][mglev], 1, 1)); #ifdef AMREX_USE_GPU if ( Gpu::inLaunchRegion() && diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index 25d9be7b1..9c01a8ae9 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -669,30 +669,24 @@ PeleLM::getAdvectionFluxesMOL( for (MFIter mfi(a_nE, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM( - const Box& xbx = mfi.grownnodaltilebox(0, 0); - , const Box& ybx = mfi.grownnodaltilebox(1, 0); - , const Box& zbx = mfi.grownnodaltilebox(2, 0)); - - AMREX_D_TERM( - auto const& fx = a_fluxes[0]->array(mfi, 0); - , auto const& fy = a_fluxes[1]->array(mfi, 0); - , auto const& fz = a_fluxes[2]->array(mfi, 0);) - AMREX_D_TERM( - auto const& ueff = a_ueff[0]->const_array(mfi); - , auto const& veff = a_ueff[1]->const_array(mfi); - , auto const& weff = a_ueff[2]->const_array(mfi);) - AMREX_D_TERM( - edgstate[0].resize(xbx, 1);, edgstate[1].resize(ybx, 1); - , edgstate[2].resize(zbx, 1)); - AMREX_D_TERM( - Array4 xstate = edgstate[0].array(); - , Array4 ystate = edgstate[1].array(); - , Array4 zstate = edgstate[2].array()); - AMREX_D_TERM( - Elixir eli_edgex = edgstate[0].elixir(); - , Elixir eli_edgey = edgstate[1].elixir(); - , Elixir eli_edgez = edgstate[2].elixir()); + AMREX_D_TERM(const Box& xbx = mfi.grownnodaltilebox(0, 0); + , const Box& ybx = mfi.grownnodaltilebox(1, 0); + , const Box& zbx = mfi.grownnodaltilebox(2, 0)); + + AMREX_D_TERM(auto const& fx = a_fluxes[0]->array(mfi, 0); + , auto const& fy = a_fluxes[1]->array(mfi, 0); + , auto const& fz = a_fluxes[2]->array(mfi, 0);) + AMREX_D_TERM(auto const& ueff = a_ueff[0]->const_array(mfi); + , auto const& veff = a_ueff[1]->const_array(mfi); + , auto const& weff = a_ueff[2]->const_array(mfi);) + AMREX_D_TERM(edgstate[0].resize(xbx, 1);, edgstate[1].resize(ybx, 1); + , edgstate[2].resize(zbx, 1)); + AMREX_D_TERM(Array4 xstate = edgstate[0].array(); + , Array4 ystate = edgstate[1].array(); + , Array4 zstate = edgstate[2].array()); + AMREX_D_TERM(Elixir eli_edgex = edgstate[0].elixir(); + , Elixir eli_edgey = edgstate[1].elixir(); + , Elixir eli_edgez = edgstate[2].elixir()); auto const& nE_arr = a_nE.const_array(mfi); auto const& divu_arr = a_nE.const_array(mfi); @@ -734,32 +728,26 @@ PeleLM::getAdvectionFluxes( FArrayBox edgstate[AMREX_SPACEDIM]; for (MFIter mfi(a_nE, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM( - const Box& xbx = surroundingNodes(bx, 0); - , const Box& ybx = surroundingNodes(bx, 1); - , const Box& zbx = surroundingNodes(bx, 2)); + AMREX_D_TERM(const Box& xbx = surroundingNodes(bx, 0); + , const Box& ybx = surroundingNodes(bx, 1); + , const Box& zbx = surroundingNodes(bx, 2)); // data arrays auto const& ne_arr = a_nE.const_array(mfi); - AMREX_D_TERM( - Array4 xflux = a_fluxes[0]->array(mfi); - , Array4 yflux = a_fluxes[1]->array(mfi); - , Array4 zflux = a_fluxes[2]->array(mfi)); - AMREX_D_TERM( - Array4 u = a_ueff[0]->const_array(mfi); - , Array4 v = a_ueff[1]->const_array(mfi); - , Array4 w = a_ueff[2]->const_array(mfi);); - AMREX_D_TERM( - edgstate[0].resize(xbx, 1);, edgstate[1].resize(ybx, 1); - , edgstate[2].resize(zbx, 1)); - AMREX_D_TERM( - Array4 xstate = edgstate[0].array(); - , Array4 ystate = edgstate[1].array(); - , Array4 zstate = edgstate[2].array()); - AMREX_D_TERM( - Elixir xstate_eli = edgstate[0].elixir(); - , Elixir ystate_eli = edgstate[1].elixir(); - , Elixir zstate_eli = edgstate[2].elixir()); + AMREX_D_TERM(Array4 xflux = a_fluxes[0]->array(mfi); + , Array4 yflux = a_fluxes[1]->array(mfi); + , Array4 zflux = a_fluxes[2]->array(mfi)); + AMREX_D_TERM(Array4 u = a_ueff[0]->const_array(mfi); + , Array4 v = a_ueff[1]->const_array(mfi); + , Array4 w = a_ueff[2]->const_array(mfi);); + AMREX_D_TERM(edgstate[0].resize(xbx, 1);, edgstate[1].resize(ybx, 1); + , edgstate[2].resize(zbx, 1)); + AMREX_D_TERM(Array4 xstate = edgstate[0].array(); + , Array4 ystate = edgstate[1].array(); + , Array4 zstate = edgstate[2].array()); + AMREX_D_TERM(Elixir xstate_eli = edgstate[0].elixir(); + , Elixir ystate_eli = edgstate[1].elixir(); + , Elixir zstate_eli = edgstate[2].elixir()); // Predict edge states // X From 3c93872fc051ca8aef0380a95ae9a5c75907c956 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 30 Jun 2025 10:26:58 +0200 Subject: [PATCH 10/87] formatting --- Source/PeleLMeX.cpp | 106 ++++--- Source/PeleLMeX_Advection.cpp | 117 ++++---- Source/PeleLMeX_DeriveFunc.cpp | 35 ++- Source/PeleLMeX_DeriveUserDefined.cpp | 5 +- Source/PeleLMeX_Diffusion.cpp | 6 +- Source/PeleLMeX_DiffusionOp.cpp | 5 +- Source/PeleLMeX_EB.cpp | 88 +++--- Source/PeleLMeX_FlowController.cpp | 19 +- Source/PeleLMeX_Forces.cpp | 12 +- Source/PeleLMeX_K.H | 17 +- Source/PeleLMeX_Plot.cpp | 23 +- Source/PeleLMeX_ProblemSpecificFunctions.H | 10 +- Source/PeleLMeX_Projection.cpp | 10 +- Source/PeleLMeX_Setup.cpp | 46 ++-- Source/PeleLMeX_TransportProp.cpp | 5 +- Source/PeleLMeX_Utils.cpp | 62 +++-- .../LinOps/AMReX_MLABecCecLaplacian.cpp | 259 ++++++++++-------- .../Plasma/LinOps/AMReX_MLCellABecCecLap.cpp | 5 +- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 82 +++--- 19 files changed, 521 insertions(+), 391 deletions(-) diff --git a/Source/PeleLMeX.cpp b/Source/PeleLMeX.cpp index 3ebb2b9ef..063b308f0 100644 --- a/Source/PeleLMeX.cpp +++ b/Source/PeleLMeX.cpp @@ -81,25 +81,29 @@ PeleLM::getStateVect(const TimeStamp& a_time) if (a_time == AmrOldTime) { if (m_incompressible != 0) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, 0, AMREX_SPACEDIM)); + r.push_back( + std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, 0, AMREX_SPACEDIM)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, 0, NVAR)); + r.push_back( + std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, 0, NVAR)); } } } else { if (m_incompressible != 0) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, 0, AMREX_SPACEDIM)); + r.push_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, 0, AMREX_SPACEDIM)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, 0, NVAR)); + r.push_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, 0, NVAR)); } } } @@ -113,13 +117,17 @@ PeleLM::getVelocityVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); + r.push_back( + std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, VELX, + AMREX_SPACEDIM)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); + r.push_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, VELX, + AMREX_SPACEDIM)); } } return r; @@ -133,15 +141,17 @@ PeleLM::getSpeciesVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, FIRSTSPEC, - NUM_SPECIES)); + r.push_back( + std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, FIRSTSPEC, + NUM_SPECIES)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, FIRSTSPEC, - NUM_SPECIES)); + r.push_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, FIRSTSPEC, + NUM_SPECIES)); } } return r; @@ -155,13 +165,15 @@ PeleLM::getDensityVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, DENSITY, 1)); + r.push_back( + std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, DENSITY, 1)); } } else if (a_time == AmrNewTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, DENSITY, 1)); + r.push_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, DENSITY, 1)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { @@ -182,13 +194,15 @@ PeleLM::getTempVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, TEMP, 1)); + r.push_back( + std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, TEMP, 1)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, TEMP, 1)); + r.push_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, TEMP, 1)); } } return r; @@ -202,13 +216,15 @@ PeleLM::getRhoHVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, RHOH, 1)); + r.push_back( + std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, RHOH, 1)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, RHOH, 1)); + r.push_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, RHOH, 1)); } } return r; @@ -286,13 +302,15 @@ PeleLM::getAuxVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_old[lev]->auxiliaries, amrex::make_alias, 0, m_nAux)); + r.push_back( + std::make_unique( + m_leveldata_old[lev]->auxiliaries, amrex::make_alias, 0, m_nAux)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_new[lev]->auxiliaries, amrex::make_alias, 0, m_nAux)); + r.push_back( + std::make_unique( + m_leveldata_new[lev]->auxiliaries, amrex::make_alias, 0, m_nAux)); } } return r; @@ -435,13 +453,15 @@ PeleLM::getPhiVVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, PHIV, 1)); + r.push_back( + std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, PHIV, 1)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, PHIV, 1)); + r.push_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, PHIV, 1)); } } return r; @@ -455,13 +475,15 @@ PeleLM::getnEVect(const TimeStamp& a_time) r.reserve(finest_level + 1); if (a_time == AmrOldTime) { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_old[lev]->state, amrex::make_alias, NE, 1)); + r.push_back( + std::make_unique( + m_leveldata_old[lev]->state, amrex::make_alias, NE, 1)); } } else { for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, NE, 1)); + r.push_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, NE, 1)); } } return r; diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 8ce1a91d8..3b5727a8b 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -88,15 +88,18 @@ PeleLM::computeVelocityAdvTerm(std::unique_ptr& advData) for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM(auto const& umac = advData->umac[lev][0].const_array(mfi); - , auto const& vmac = advData->umac[lev][1].const_array(mfi); - , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM(auto const& fx = fluxes[lev][0].array(mfi); - , auto const& fy = fluxes[lev][1].array(mfi); - , auto const& fz = fluxes[lev][2].array(mfi);) - AMREX_D_TERM(auto const& facex = faces[lev][0].array(mfi); - , auto const& facey = faces[lev][1].array(mfi); - , auto const& facez = faces[lev][2].array(mfi);) + AMREX_D_TERM( + auto const& umac = advData->umac[lev][0].const_array(mfi); + , auto const& vmac = advData->umac[lev][1].const_array(mfi); + , auto const& wmac = advData->umac[lev][2].const_array(mfi);) + AMREX_D_TERM( + auto const& fx = fluxes[lev][0].array(mfi); + , auto const& fy = fluxes[lev][1].array(mfi); + , auto const& fz = fluxes[lev][2].array(mfi);) + AMREX_D_TERM( + auto const& facex = faces[lev][0].array(mfi); + , auto const& facey = faces[lev][1].array(mfi); + , auto const& facez = faces[lev][2].array(mfi);) auto const& divu_arr = divu.const_array(mfi); auto const& vel_arr = ldata_p->state.const_array(mfi, VELX); auto const& force_arr = velForces[lev].const_array(mfi); @@ -411,15 +414,18 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM(auto const& umac = advData->umac[lev][0].const_array(mfi); - , auto const& vmac = advData->umac[lev][1].const_array(mfi); - , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM(auto const& fx = fluxes[lev][0].array(mfi, 0); - , auto const& fy = fluxes[lev][1].array(mfi, 0); - , auto const& fz = fluxes[lev][2].array(mfi, 0);) - AMREX_D_TERM(auto const& edgex = edgeState[0].array(mfi, 1); - , auto const& edgey = edgeState[1].array(mfi, 1); - , auto const& edgez = edgeState[2].array(mfi, 1);) + AMREX_D_TERM( + auto const& umac = advData->umac[lev][0].const_array(mfi); + , auto const& vmac = advData->umac[lev][1].const_array(mfi); + , auto const& wmac = advData->umac[lev][2].const_array(mfi);) + AMREX_D_TERM( + auto const& fx = fluxes[lev][0].array(mfi, 0); + , auto const& fy = fluxes[lev][1].array(mfi, 0); + , auto const& fz = fluxes[lev][2].array(mfi, 0);) + AMREX_D_TERM( + auto const& edgex = edgeState[0].array(mfi, 1); + , auto const& edgey = edgeState[1].array(mfi, 1); + , auto const& edgez = edgeState[2].array(mfi, 1);) auto const& divu_arr = divu.const_array(mfi); auto const& rhoY_arr = ldata_p->state.const_array(mfi, FIRSTSPEC); auto const& force_arr = advData->Forcing[lev].const_array(mfi, 0); @@ -455,10 +461,10 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) auto const& udrift = advData->uDrift[lev][0].const_array(mfi, n); , auto const& vdrift = advData->uDrift[lev][1].const_array(mfi, n); , auto const& wdrift = advData->uDrift[lev][2].const_array(mfi, n);) - AMREX_D_TERM(auto const& fx_ions = fluxes[lev][0].array(mfi, ion_idx); - , auto const& fy_ions = fluxes[lev][1].array(mfi, ion_idx); - , - auto const& fz_ions = fluxes[lev][2].array(mfi, ion_idx);) + AMREX_D_TERM( + auto const& fx_ions = fluxes[lev][0].array(mfi, ion_idx); + , auto const& fy_ions = fluxes[lev][1].array(mfi, ion_idx); + , auto const& fz_ions = fluxes[lev][2].array(mfi, ion_idx);) AMREX_D_TERM( auto const& edgex_ions = edgeState[0].array(mfi, 1 + ion_idx); , auto const& edgey_ions = edgeState[1].array(mfi, 1 + ion_idx); @@ -515,12 +521,14 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) auto const& umac = advData->umac[lev][0].const_array(mfi); , auto const& vmac = advData->umac[lev][1].const_array(mfi); , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM(auto const& fx = fluxes_aux[lev][0].array(mfi, 0); - , auto const& fy = fluxes_aux[lev][1].array(mfi, 0); - , auto const& fz = fluxes_aux[lev][2].array(mfi, 0);) - AMREX_D_TERM(auto const& edgex = edgeState_aux[0].array(mfi, 0); - , auto const& edgey = edgeState_aux[1].array(mfi, 0); - , auto const& edgez = edgeState_aux[2].array(mfi, 0);) + AMREX_D_TERM( + auto const& fx = fluxes_aux[lev][0].array(mfi, 0); + , auto const& fy = fluxes_aux[lev][1].array(mfi, 0); + , auto const& fz = fluxes_aux[lev][2].array(mfi, 0);) + AMREX_D_TERM( + auto const& edgex = edgeState_aux[0].array(mfi, 0); + , auto const& edgey = edgeState_aux[1].array(mfi, 0); + , auto const& edgez = edgeState_aux[2].array(mfi, 0);) auto const& divu_arr = divu.const_array(mfi); auto const& aux_arr = ldata_p->auxiliaries.const_array(mfi, 0); auto const& force_arr = advData->Forcing_aux[lev].const_array(mfi, 0); @@ -605,14 +613,16 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM(auto const& umac = advData->umac[lev][0].const_array(mfi); - , auto const& vmac = advData->umac[lev][1].const_array(mfi); - , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM(auto const& fx = fluxes[lev][0].array(mfi, NUM_SPECIES); - , // Put temp fluxes in place of rhoH - auto const& fy = fluxes[lev][1].array(mfi, NUM_SPECIES); - , // will be overwritten later - auto const& fz = fluxes[lev][2].array(mfi, NUM_SPECIES);) + AMREX_D_TERM( + auto const& umac = advData->umac[lev][0].const_array(mfi); + , auto const& vmac = advData->umac[lev][1].const_array(mfi); + , auto const& wmac = advData->umac[lev][2].const_array(mfi);) + AMREX_D_TERM( + auto const& fx = fluxes[lev][0].array(mfi, NUM_SPECIES); + , // Put temp fluxes in place of rhoH + auto const& fy = fluxes[lev][1].array(mfi, NUM_SPECIES); + , // will be overwritten later + auto const& fz = fluxes[lev][2].array(mfi, NUM_SPECIES);) AMREX_D_TERM( auto const& edgex = edgeState[0].array(mfi, NUM_SPECIES + 2); , auto const& edgey = edgeState[1].array(mfi, NUM_SPECIES + 2); @@ -696,12 +706,14 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM(auto const& umac = advData->umac[lev][0].const_array(mfi); - , auto const& vmac = advData->umac[lev][1].const_array(mfi); - , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM(auto const& fx = fluxes[lev][0].array(mfi, NUM_SPECIES); - , auto const& fy = fluxes[lev][1].array(mfi, NUM_SPECIES); - , auto const& fz = fluxes[lev][2].array(mfi, NUM_SPECIES);) + AMREX_D_TERM( + auto const& umac = advData->umac[lev][0].const_array(mfi); + , auto const& vmac = advData->umac[lev][1].const_array(mfi); + , auto const& wmac = advData->umac[lev][2].const_array(mfi);) + AMREX_D_TERM( + auto const& fx = fluxes[lev][0].array(mfi, NUM_SPECIES); + , auto const& fy = fluxes[lev][1].array(mfi, NUM_SPECIES); + , auto const& fz = fluxes[lev][2].array(mfi, NUM_SPECIES);) AMREX_D_TERM( auto const& edgex = edgeState[0].array(mfi, NUM_SPECIES + 1); , auto const& edgey = edgeState[1].array(mfi, NUM_SPECIES + 1); @@ -983,15 +995,18 @@ PeleLM::computePassiveAdvTerms( #endif for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM(auto const& umac = advData->umac[lev][0].const_array(mfi); - , auto const& vmac = advData->umac[lev][1].const_array(mfi); - , auto const& wmac = advData->umac[lev][2].const_array(mfi);) - AMREX_D_TERM(auto const& fx = fluxes[lev][0].array(mfi, 0); - , auto const& fy = fluxes[lev][1].array(mfi, 0); - , auto const& fz = fluxes[lev][2].array(mfi, 0);) - AMREX_D_TERM(auto const& edgex = edgeState[lev][0].array(mfi, 0); - , auto const& edgey = edgeState[lev][1].array(mfi, 0); - , auto const& edgez = edgeState[lev][2].array(mfi, 0);) + AMREX_D_TERM( + auto const& umac = advData->umac[lev][0].const_array(mfi); + , auto const& vmac = advData->umac[lev][1].const_array(mfi); + , auto const& wmac = advData->umac[lev][2].const_array(mfi);) + AMREX_D_TERM( + auto const& fx = fluxes[lev][0].array(mfi, 0); + , auto const& fy = fluxes[lev][1].array(mfi, 0); + , auto const& fz = fluxes[lev][2].array(mfi, 0);) + AMREX_D_TERM( + auto const& edgex = edgeState[lev][0].array(mfi, 0); + , auto const& edgey = edgeState[lev][1].array(mfi, 0); + , auto const& edgez = edgeState[lev][2].array(mfi, 0);) auto const& divu_arr = divu.const_array(mfi); auto const& pass_arr = ldata_p->state.const_array(mfi, state_comp); // TODO: Find way to include diffusive forces for passive scalars that diff --git a/Source/PeleLMeX_DeriveFunc.cpp b/Source/PeleLMeX_DeriveFunc.cpp index bdee0c1ca..cabd51f60 100644 --- a/Source/PeleLMeX_DeriveFunc.cpp +++ b/Source/PeleLMeX_DeriveFunc.cpp @@ -286,9 +286,10 @@ pelelmex_dermgvort( int /*level*/) { - AMREX_D_TERM(const amrex::Real idx = geom.InvCellSize(0); - , const amrex::Real idy = geom.InvCellSize(1); - , const amrex::Real idz = geom.InvCellSize(2);); + AMREX_D_TERM( + const amrex::Real idx = geom.InvCellSize(0); + , const amrex::Real idy = geom.InvCellSize(1); + , const amrex::Real idz = geom.InvCellSize(2);); auto const& dat_arr = statefab.const_array(); auto const& vort_arr = derfab.array(dcomp); @@ -448,9 +449,10 @@ pelelmex_dervort( AMREX_ASSERT(derfab.box().contains(bx)); AMREX_ASSERT(statefab.box().contains(bx)); AMREX_ASSERT(derfab.nComp() >= dcomp + ncomp); - AMREX_D_TERM(const amrex::Real idx = geom.InvCellSize(0); - , const amrex::Real idy = geom.InvCellSize(1); - , const amrex::Real idz = geom.InvCellSize(2);); + AMREX_D_TERM( + const amrex::Real idx = geom.InvCellSize(0); + , const amrex::Real idy = geom.InvCellSize(1); + , const amrex::Real idz = geom.InvCellSize(2);); auto const& dat_arr = statefab.const_array(); auto const& vort_arr = derfab.array(dcomp); @@ -622,9 +624,10 @@ pelelmex_dercoord( amrex::ignore_unused(ncomp); AMREX_ASSERT(derfab.box().contains(bx)); AMREX_ASSERT(derfab.nComp() >= dcomp + ncomp); - AMREX_D_TERM(const amrex::Real dx = geom.CellSize(0); - , const amrex::Real dy = geom.CellSize(1); - , const amrex::Real dz = geom.CellSize(2);); + AMREX_D_TERM( + const amrex::Real dx = geom.CellSize(0); + , const amrex::Real dy = geom.CellSize(1); + , const amrex::Real dz = geom.CellSize(2);); auto const& coord_arr = derfab.array(dcomp); const auto geomdata = geom.data(); @@ -708,9 +711,10 @@ pelelmex_derQcrit( { #if AMREX_SPACEDIM == 3 - AMREX_D_TERM(const amrex::Real idx = geom.InvCellSize(0); - , const amrex::Real idy = geom.InvCellSize(1); - , const amrex::Real idz = geom.InvCellSize(2);); + AMREX_D_TERM( + const amrex::Real idx = geom.InvCellSize(0); + , const amrex::Real idy = geom.InvCellSize(1); + , const amrex::Real idz = geom.InvCellSize(2);); auto const& dat_arr = statefab.const_array(); auto const& qcrit_arr = derfab.array(dcomp); @@ -977,9 +981,10 @@ pelelmex_derenstrophy( int /*level*/) { - AMREX_D_TERM(const amrex::Real idx = geom.InvCellSize(0); - , const amrex::Real idy = geom.InvCellSize(1); - , const amrex::Real idz = geom.InvCellSize(2);); + AMREX_D_TERM( + const amrex::Real idx = geom.InvCellSize(0); + , const amrex::Real idy = geom.InvCellSize(1); + , const amrex::Real idz = geom.InvCellSize(2);); auto const& dat_arr = statefab.const_array(VELX); auto const& rho_arr = (a_pelelm->m_incompressible) != 0 diff --git a/Source/PeleLMeX_DeriveUserDefined.cpp b/Source/PeleLMeX_DeriveUserDefined.cpp index 57bec4c89..b38319017 100644 --- a/Source/PeleLMeX_DeriveUserDefined.cpp +++ b/Source/PeleLMeX_DeriveUserDefined.cpp @@ -34,6 +34,7 @@ pelelmex_deruserdef( const Vector& /*bcrec*/, int /*level*/) { - Abort("Using derUserDefine derived requires providing a definition in local " - "DeriveUserDefined.cpp"); + Abort( + "Using derUserDefine derived requires providing a definition in local " + "DeriveUserDefined.cpp"); } diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 9b0b325ed..0cdfef610 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -1842,9 +1842,9 @@ PeleLM::getDiffusionTensorOpBC( Vector> r(AMREX_SPACEDIM); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if (Geom(0).isPeriodic(idim)) { - AMREX_D_TERM(r[0][idim] = LinOpBCType::Periodic; - , r[1][idim] = LinOpBCType::Periodic; - , r[2][idim] = LinOpBCType::Periodic;); + AMREX_D_TERM( + r[0][idim] = LinOpBCType::Periodic;, r[1][idim] = LinOpBCType::Periodic; + , r[2][idim] = LinOpBCType::Periodic;); } else { for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { auto amrexbc = (a_side == Orientation::low) ? a_bc[dir].lo(idim) diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index be622a1e4..1f75ba0e3 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -817,8 +817,9 @@ DiffusionOp::computeDiffFluxes( fluxes[lev][idim] = std::make_unique( *a_flux[lev][idim], amrex::make_alias, flux_comp + comp, m_ncomp); } - ebfluxes.push_back(std::make_unique( - *a_EBflux[lev], amrex::make_alias, ebflux_comp + comp, m_ncomp)); + ebfluxes.push_back( + std::make_unique( + *a_EBflux[lev], amrex::make_alias, ebflux_comp + comp, m_ncomp)); component.emplace_back(phi[lev], amrex::make_alias, comp, m_ncomp); if (have_boundary != 0) { boundary.emplace_back( diff --git a/Source/PeleLMeX_EB.cpp b/Source/PeleLMeX_EB.cpp index 4e845cc30..ace760822 100644 --- a/Source/PeleLMeX_EB.cpp +++ b/Source/PeleLMeX_EB.cpp @@ -91,9 +91,10 @@ PeleLM::redistributeAofS( if (flagfab.getType(bx) != FabType::covered) { if (flagfab.getType(grow(bx, 4)) != FabType::regular) { - AMREX_D_TERM(auto apx = ebfact.getAreaFrac()[0]->const_array(mfi); - , auto apy = ebfact.getAreaFrac()[1]->const_array(mfi); - , auto apz = ebfact.getAreaFrac()[2]->const_array(mfi);); + AMREX_D_TERM( + auto apx = ebfact.getAreaFrac()[0]->const_array(mfi); + , auto apy = ebfact.getAreaFrac()[1]->const_array(mfi); + , auto apz = ebfact.getAreaFrac()[2]->const_array(mfi);); AMREX_D_TERM( Array4 fcx = ebfact.getFaceCent()[0]->const_array(mfi); , Array4 fcy = ebfact.getFaceCent()[1]->const_array(mfi); @@ -220,9 +221,10 @@ PeleLM::redistributeDiff( if (flagfab.getType(bx) != FabType::covered) { if (flagfab.getType(grow(bx, 4)) != FabType::regular) { - AMREX_D_TERM(auto apx = ebfact.getAreaFrac()[0]->const_array(mfi); - , auto apy = ebfact.getAreaFrac()[1]->const_array(mfi); - , auto apz = ebfact.getAreaFrac()[2]->const_array(mfi);); + AMREX_D_TERM( + auto apx = ebfact.getAreaFrac()[0]->const_array(mfi); + , auto apy = ebfact.getAreaFrac()[1]->const_array(mfi); + , auto apz = ebfact.getAreaFrac()[2]->const_array(mfi);); AMREX_D_TERM( Array4 fcx = ebfact.getFaceCent()[0]->const_array(mfi); , Array4 fcy = ebfact.getFaceCent()[1]->const_array(mfi); @@ -272,16 +274,18 @@ PeleLM::initCoveredState() // Zero velocities, typical values on species, 'cold' temperature if (m_incompressible != 0) { coveredState_h.resize(AMREX_SPACEDIM); - AMREX_D_TERM(coveredState_h[0] = 0.0;, coveredState_h[1] = 0.0; - , coveredState_h[2] = 0.0;) + AMREX_D_TERM( + coveredState_h[0] = 0.0;, coveredState_h[1] = 0.0; + , coveredState_h[2] = 0.0;) coveredState_d.resize(AMREX_SPACEDIM); Gpu::copy( Gpu::hostToDevice, coveredState_h.begin(), coveredState_h.end(), coveredState_d.begin()); } else { coveredState_h.resize(NVAR); - AMREX_D_TERM(coveredState_h[0] = 0.0;, coveredState_h[1] = 0.0; - , coveredState_h[2] = 0.0;) + AMREX_D_TERM( + coveredState_h[0] = 0.0;, coveredState_h[1] = 0.0; + , coveredState_h[2] = 0.0;) coveredState_h[DENSITY] = typical_values[DENSITY]; for (int n = 0; n < NUM_SPECIES; n++) { coveredState_h[FIRSTSPEC + n] = typical_values[FIRSTSPEC + n]; @@ -369,13 +373,15 @@ PeleLM::initialRedistribution() (flagfab.getType(amrex::grow(bx, 4)) != FabType::regular)) { Array4 AMREX_D_DECL(fcx, fcy, fcz), ccc, vfrac, AMREX_D_DECL(apx, apy, apz); - AMREX_D_TERM(fcx = fact.getFaceCent()[0]->const_array(mfi); - , fcy = fact.getFaceCent()[1]->const_array(mfi); - , fcz = fact.getFaceCent()[2]->const_array(mfi);); + AMREX_D_TERM( + fcx = fact.getFaceCent()[0]->const_array(mfi); + , fcy = fact.getFaceCent()[1]->const_array(mfi); + , fcz = fact.getFaceCent()[2]->const_array(mfi);); ccc = fact.getCentroid().const_array(mfi); - AMREX_D_TERM(apx = fact.getAreaFrac()[0]->const_array(mfi); - , apy = fact.getAreaFrac()[1]->const_array(mfi); - , apz = fact.getAreaFrac()[2]->const_array(mfi);); + AMREX_D_TERM( + apx = fact.getAreaFrac()[0]->const_array(mfi); + , apy = fact.getAreaFrac()[1]->const_array(mfi); + , apz = fact.getAreaFrac()[2]->const_array(mfi);); vfrac = fact.getVolFrac().const_array(mfi); if (m_incompressible != 0) { @@ -462,8 +468,9 @@ PeleLM::getEBState(int first_comp, int ncomp, const PeleLM::TimeStamp& a_time) Vector> r; r.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - r.push_back(std::make_unique( - grids[lev], dmap[lev], ncomp, m_nGrowState, MFInfo(), Factory(lev))); + r.push_back( + std::make_unique( + grids[lev], dmap[lev], ncomp, m_nGrowState, MFInfo(), Factory(lev))); getEBState(lev, a_time, *r[lev], first_comp, ncomp); } return r; @@ -580,9 +587,10 @@ PeleLM::getEBState( hasBCNormalEB::value> EBfiller{lprobparm, ProblemSpecificFunctions{}}; const auto& state = ldata_p->state.const_array(mfi); - AMREX_D_TERM(const auto& ebfc_x = faceCentroid[0]->array(mfi); - , const auto& ebfc_y = faceCentroid[1]->array(mfi); - , const auto& ebfc_z = faceCentroid[2]->array(mfi);); + AMREX_D_TERM( + const auto& ebfc_x = faceCentroid[0]->array(mfi); + , const auto& ebfc_y = faceCentroid[1]->array(mfi); + , const auto& ebfc_z = faceCentroid[2]->array(mfi);); const auto& ebnorm = ebfact.getBndryNormal().const_array(mfi); amrex::ParallelFor( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { @@ -638,9 +646,10 @@ PeleLM::getEBDiff( ProblemSpecificFunctions, hasBCTypeEB::value> EBTypfiller{lprobparm, ProblemSpecificFunctions{}}; - AMREX_D_TERM(const auto& ebfc_x = faceCentroid[0]->array(mfi); - , const auto& ebfc_y = faceCentroid[1]->array(mfi); - , const auto& ebfc_z = faceCentroid[2]->array(mfi);); + AMREX_D_TERM( + const auto& ebfc_x = faceCentroid[0]->array(mfi); + , const auto& ebfc_y = faceCentroid[1]->array(mfi); + , const auto& ebfc_z = faceCentroid[2]->array(mfi);); amrex::ParallelFor( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Regular/covered cells -> 0.0 @@ -682,10 +691,10 @@ PeleLM::correct_vel_small_cells( EBCellFlagFab const& flags = EBFactory(lev).getMultiEBCellFlagFab()[mfi]; // Face-centered velocity components - AMREX_D_TERM(const auto& umac_fab = (a_umac[lev][0])->const_array(mfi); - , const auto& vmac_fab = (a_umac[lev][1])->const_array(mfi); - , - const auto& wmac_fab = (a_umac[lev][2])->const_array(mfi);); + AMREX_D_TERM( + const auto& umac_fab = (a_umac[lev][0])->const_array(mfi); + , const auto& vmac_fab = (a_umac[lev][1])->const_array(mfi); + , const auto& wmac_fab = (a_umac[lev][2])->const_array(mfi);); // No cut cells in this FAB if ( @@ -694,12 +703,13 @@ PeleLM::correct_vel_small_cells( // do nothing } else { // Cut cells in this FAB // Face-centered areas - AMREX_D_TERM(const auto& apx_fab = - EBFactory(lev).getAreaFrac()[0]->const_array(mfi); - , const auto& apy_fab = - EBFactory(lev).getAreaFrac()[1]->const_array(mfi); - , const auto& apz_fab = - EBFactory(lev).getAreaFrac()[2]->const_array(mfi);); + AMREX_D_TERM( + const auto& apx_fab = + EBFactory(lev).getAreaFrac()[0]->const_array(mfi); + , const auto& apy_fab = + EBFactory(lev).getAreaFrac()[1]->const_array(mfi); + , const auto& apz_fab = + EBFactory(lev).getAreaFrac()[2]->const_array(mfi);); const auto& vfrac_fab = EBFactory(lev).getVolFrac().const_array(mfi); @@ -776,12 +786,14 @@ void PeleLM::checkEBInflowFunctions() { if (!hasBCNormalEB::value) { - Abort("Provided ProblemSpecificFunctions doesn't have a viable bcnormal_eb " - "function"); + Abort( + "Provided ProblemSpecificFunctions doesn't have a viable bcnormal_eb " + "function"); } if (!hasBCTypeEB::value) { - Abort("Provided ProblemSpecificFunctions doesn't have a viable bctype_eb " - "function"); + Abort( + "Provided ProblemSpecificFunctions doesn't have a viable bctype_eb " + "function"); } if (m_verbose != 0 && m_useEBinflow != 0) { Print() << "WARNING: EB-inflow capability is experimental. Scalar " diff --git a/Source/PeleLMeX_FlowController.cpp b/Source/PeleLMeX_FlowController.cpp index 9d248652c..19d4d5f67 100644 --- a/Source/PeleLMeX_FlowController.cpp +++ b/Source/PeleLMeX_FlowController.cpp @@ -33,8 +33,9 @@ PeleLM::initActiveControl() // Active control checks if ((m_ctrl_useTemp != 0) && (m_ctrl_temperature <= 0.0)) { - amrex::Error("active_control.temperature MUST be set with " - "active_control.use_temp = 1"); + amrex::Error( + "active_control.temperature MUST be set with " + "active_control.use_temp = 1"); } if ((m_ctrl_active != 0) && (m_ctrl_tauControl <= 0.0)) { @@ -342,9 +343,10 @@ PeleLM::getActiveControlLowT(Real& a_coft) idx[AC_FlameDir] -= 1; if (T_arr(idx[0], idx[1], idx[2], TEMP) < AC_Tcross) { Real coor[3] = {0.0}; - AMREX_D_TERM(coor[0] = prob_lo[0] + (i + 0.5) * dx[0]; - , coor[1] = prob_lo[1] + (j + 0.5) * dx[1]; - , coor[2] = prob_lo[2] + (k + 0.5) * dx[2];); + AMREX_D_TERM( + coor[0] = prob_lo[0] + (i + 0.5) * dx[0]; + , coor[1] = prob_lo[1] + (j + 0.5) * dx[1]; + , coor[2] = prob_lo[2] + (k + 0.5) * dx[2];); Real slope = ((T_arr(i, j, k, TEMP)) - T_arr(idx[0], idx[1], idx[2], TEMP)) / dx[AC_FlameDir]; @@ -379,9 +381,10 @@ PeleLM::getActiveControlLowT(Real& a_coft) idx[AC_FlameDir] -= 1; if (T_arr(idx[0], idx[1], idx[2], TEMP) < AC_Tcross) { Real coor[3] = {0.0}; - AMREX_D_TERM(coor[0] = prob_lo[0] + (i + 0.5) * dx[0]; - , coor[1] = prob_lo[1] + (j + 0.5) * dx[1]; - , coor[2] = prob_lo[2] + (k + 0.5) * dx[2];); + AMREX_D_TERM( + coor[0] = prob_lo[0] + (i + 0.5) * dx[0]; + , coor[1] = prob_lo[1] + (j + 0.5) * dx[1]; + , coor[2] = prob_lo[2] + (k + 0.5) * dx[2];); Real slope = ((T_arr(i, j, k, TEMP)) - T_arr(idx[0], idx[1], idx[2], TEMP)) / dx[AC_FlameDir]; diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 3982dca6a..4feec26e5 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -283,8 +283,9 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) for (int n = 0; n < MANIFOLD_DIM; ++n) { if (leosparm.is_variance_of[n] >= 0) { if (!m_do_les) { - amrex::Abort("PeleLM::addScalarVarianceSources(): cannot add a " - "scalar dissipation without an active LES model"); + amrex::Abort( + "PeleLM::addScalarVarianceSources(): cannot add a " + "scalar dissipation without an active LES model"); } nvariances += 1; var_of_scalar = FIRSTSPEC + leosparm.is_variance_of[n]; @@ -345,9 +346,10 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) m_leveldata_old[lev]->visc_turb_fc[1].const_arrays(); , auto const& mut_arr_z = m_leveldata_old[lev]->visc_turb_fc[2].const_arrays();) - AMREX_D_TERM(auto const& gx = grad_fc[lev][0].const_arrays(); - , auto const& gy = grad_fc[lev][1].const_arrays(); - , auto const& gz = grad_fc[lev][2].const_arrays();) + AMREX_D_TERM( + auto const& gx = grad_fc[lev][0].const_arrays(); + , auto const& gy = grad_fc[lev][1].const_arrays(); + , auto const& gz = grad_fc[lev][2].const_arrays();) auto extma = m_extSource[lev]->arrays(); auto statema = ldata_p->state.const_arrays(); diff --git a/Source/PeleLMeX_K.H b/Source/PeleLMeX_K.H index b4008346e..17ca8d238 100644 --- a/Source/PeleLMeX_K.H +++ b/Source/PeleLMeX_K.H @@ -110,8 +110,9 @@ getTransportCoeff( rhotheta(i, j, k, H_ID) *= 0.58; #endif #if !defined(H2_ID) && !defined(H_ID) - amrex::Abort("Running with Soret without light species, waste of time " - "and memory..."); + amrex::Abort( + "Running with Soret without light species, waste of time " + "and memory..."); #endif } } @@ -1417,10 +1418,14 @@ getTurbViscSigma( // Singular values: amrex::Real sigma1 = std::sqrt( std::max(0.0, I[0] / 3.0 + 2.0 * std::sqrt(alpha1) * std::cos(alpha3))); - amrex::Real sigma2 = std::sqrt(std::max( - 0.0, I[0] / 3.0 - 2.0 * std::sqrt(alpha1) * std::cos(Pi / 3.0 + alpha3))); - amrex::Real sigma3 = std::sqrt(std::max( - 0.0, I[0] / 3.0 - 2.0 * std::sqrt(alpha1) * std::cos(Pi / 3.0 - alpha3))); + amrex::Real sigma2 = std::sqrt( + std::max( + 0.0, + I[0] / 3.0 - 2.0 * std::sqrt(alpha1) * std::cos(Pi / 3.0 + alpha3))); + amrex::Real sigma3 = std::sqrt( + std::max( + 0.0, + I[0] / 3.0 - 2.0 * std::sqrt(alpha1) * std::cos(Pi / 3.0 - alpha3))); // Sort sigma2 = std::max(sigma3, sigma2); diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index aeca2d306..2cc177da1 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -436,12 +436,13 @@ PeleLM::WritePlotFile() if (m_do_les && m_plot_les) { constexpr amrex::Real fact = 0.5 / AMREX_SPACEDIM; auto const& plot_arr = mf_plt[lev].arrays(); - AMREX_D_TERM(auto const& mut_arr_x = - m_leveldata_old[lev]->visc_turb_fc[0].const_arrays(); - , auto const& mut_arr_y = - m_leveldata_old[lev]->visc_turb_fc[1].const_arrays(); - , auto const& mut_arr_z = - m_leveldata_old[lev]->visc_turb_fc[2].const_arrays();) + AMREX_D_TERM( + auto const& mut_arr_x = + m_leveldata_old[lev]->visc_turb_fc[0].const_arrays(); + , auto const& mut_arr_y = + m_leveldata_old[lev]->visc_turb_fc[1].const_arrays(); + , auto const& mut_arr_z = + m_leveldata_old[lev]->visc_turb_fc[2].const_arrays();) // interpolate turbulent viscosity from faces to centers amrex::ParallelFor( mf_plt[lev], @@ -862,12 +863,14 @@ void PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) { if (m_incompressible != 0) { - Abort(" initializing data from a pltfile only available for low-Mach " - "simulations"); + Abort( + " initializing data from a pltfile only available for low-Mach " + "simulations"); } if (m_nAux > 0) { - Warning(" restarting from plotfile with auxiliaries not currently " - "implemented, and will not be captured"); + Warning( + " restarting from plotfile with auxiliaries not currently " + "implemented, and will not be captured"); } amrex::Print() << " initData on level " << a_lev << " from pltfile " << a_dataPltFile << "\n"; diff --git a/Source/PeleLMeX_ProblemSpecificFunctions.H b/Source/PeleLMeX_ProblemSpecificFunctions.H index 44b34b28b..cc64d7bc9 100644 --- a/Source/PeleLMeX_ProblemSpecificFunctions.H +++ b/Source/PeleLMeX_ProblemSpecificFunctions.H @@ -101,8 +101,9 @@ struct DefaultProblemSpecificFunctions { amrex::ignore_unused( x, aux_ext, idir, sgn, time, geomdata, prob_parm, pmf_data); - amrex::Abort("Default empty bcnormal called, please override in your " - "problem specific struct !"); + amrex::Abort( + "Default empty bcnormal called, please override in your " + "problem specific struct !"); // For filling auxiliary variable boundary conditions // Retrieve nAux with aux_ext.ncomp, then aux_ext[n] = ... } @@ -160,8 +161,9 @@ struct DefaultProblemSpecificFunctions const int /*required_coarsening_level*/, const int /*max_coarsening_level*/) { - amrex::Abort("Default EBUserDefined function called! Redefine it in your " - "local ProblemSpecificFunctions struct !"); + amrex::Abort( + "Default EBUserDefined function called! Redefine it in your " + "local ProblemSpecificFunctions struct !"); /** Notes: * 1. ParmParse any parameter for your geometry * 2. Construct your geometry assembling EB2::* methods diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 00fccf361..04599206c 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -52,8 +52,9 @@ PeleLM::initialProjection() // Get velocity Vector> vel; for (int lev = 0; lev <= finest_level; ++lev) { - vel.push_back(std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); + vel.push_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); vel[lev]->setBndry(0.0); setInflowBoundaryVel(*vel[lev], lev, AmrNewTime); scaleProj_RZ(lev, *vel[lev]); @@ -267,8 +268,9 @@ PeleLM::velocityProjection( // Get velocity Vector> vel; for (int lev = 0; lev <= finest_level; ++lev) { - vel.push_back(std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); + vel.push_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); #ifdef AMREX_USE_EB EB_set_covered(*vel[lev], 0.0); #endif diff --git a/Source/PeleLMeX_Setup.cpp b/Source/PeleLMeX_Setup.cpp index 0d2c041db..cd9e76c2e 100644 --- a/Source/PeleLMeX_Setup.cpp +++ b/Source/PeleLMeX_Setup.cpp @@ -577,15 +577,15 @@ PeleLM::readParameters() if (mgsc_size == 1) { int mgsc; pp.query("max_grid_size_chem", mgsc); - AMREX_D_TERM(m_max_grid_size_chem[0] = mgsc; - , m_max_grid_size_chem[1] = mgsc; - , m_max_grid_size_chem[2] = mgsc); + AMREX_D_TERM( + m_max_grid_size_chem[0] = mgsc;, m_max_grid_size_chem[1] = mgsc; + , m_max_grid_size_chem[2] = mgsc); } else if (mgsc_size == AMREX_SPACEDIM) { Vector mgsc; pp.getarr("max_grid_size_chem", mgsc, 0, AMREX_SPACEDIM); - AMREX_D_TERM(m_max_grid_size_chem[0] = mgsc[0]; - , m_max_grid_size_chem[1] = mgsc[1]; - , m_max_grid_size_chem[2] = mgsc[2]); + AMREX_D_TERM( + m_max_grid_size_chem[0] = mgsc[0];, m_max_grid_size_chem[1] = mgsc[1]; + , m_max_grid_size_chem[2] = mgsc[2]); } else { Abort("peleLM.max_grid_size_chem should have 1 or AMREX_SPACEDIM values"); } @@ -644,8 +644,9 @@ PeleLM::readParameters() m_advection_type = "BDS"; m_Godunov_ppm = 0; } else { - Abort("Unknown 'advection_scheme'. Recognized options are: Godunov_PLM, " - "Godunov_PPM or Godunov_BDS"); + Abort( + "Unknown 'advection_scheme'. Recognized options are: Godunov_PLM, " + "Godunov_PPM or Godunov_BDS"); } m_predict_advection_type = "Godunov"; // Only option at this point. This will disappear when @@ -842,9 +843,10 @@ PeleLM::checkSetupParams() std::abs( (0.1 * eos_parms.host_parm().Pnom_cgs - prob_parm->P_mean) / prob_parm->P_mean) > 1e-6) { - amrex::Abort("For Manifold EOS, pressure in manifold model " - "(manifold.nominal_pressure_cgs) and pressure in PeleLMeX " - "(prob.Pmean) must match"); + amrex::Abort( + "For Manifold EOS, pressure in manifold model " + "(manifold.nominal_pressure_cgs) and pressure in PeleLMeX " + "(prob.Pmean) must match"); } #endif } @@ -958,13 +960,15 @@ PeleLM::variablesSetup() Print() << " First ODE: " << FIRSTODE << "\n"; ProblemSpecificFunctions::set_ode_names(m_ode_names); if (m_ode_names.size() != NUM_ODE) { - Abort("ODEQty names improperly set. Adjust set_ode_names in " - "ProblemSpecificFunctions or NUM_ODE in GNUMakefile"); + Abort( + "ODEQty names improperly set. Adjust set_ode_names in " + "ProblemSpecificFunctions or NUM_ODE in GNUMakefile"); } for (int n = 0; n < NUM_ODE; ++n) { if (m_ode_names[n].empty()) { - Abort("ODEQty names improperly set. Adjust set_ode_names in " - "ProblemSpecificFunctions or NUM_ODE in GNUMakefile"); + Abort( + "ODEQty names improperly set. Adjust set_ode_names in " + "ProblemSpecificFunctions or NUM_ODE in GNUMakefile"); } stateComponents.emplace_back(FIRSTODE + n, m_ode_names[n]); } @@ -1369,8 +1373,9 @@ PeleLM::evaluateSetup() { Vector var_names( NVAR - 2); // Skip temperature and RhoRT, unused - AMREX_D_TERM(var_names[VELX] = "A(VELX)";, var_names[VELY] = "A(VELY)"; - , var_names[VELZ] = "A(VELZ)"); + AMREX_D_TERM( + var_names[VELX] = "A(VELX)";, var_names[VELY] = "A(VELY)"; + , var_names[VELZ] = "A(VELZ)"); var_names[DENSITY] = "A(Rho)"; for (int n = 0; n < NUM_SPECIES; n++) { var_names[FIRSTSPEC + n] = "A(" + spec_names[n] + ")"; @@ -1507,9 +1512,10 @@ PeleLM::taggingSetup() errTags.push_back(AMRErrorTag(info)); itexists = true; } else { - Abort(std::string( - "Unrecognized refinement indicator for " + refinement_indicator) - .c_str()); + Abort( + std::string( + "Unrecognized refinement indicator for " + refinement_indicator) + .c_str()); } if (!itexists) { diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index 135fa4d1a..b58519d42 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -482,8 +482,9 @@ PeleLM::getDiffusivity( amrex::MultiFab::Add( beta_ec[idim], ldata_p->lambda_turb_fc[idim], 0, 0, 1, 0); } else { // Invalid - amrex::Abort("getDiffusivity(): LES model is on but cannot provide a " - "turbulent transport coefficient"); + amrex::Abort( + "getDiffusivity(): LES model is on but cannot provide a " + "turbulent transport coefficient"); } } } diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 37a2f5e31..7ad46486b 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -213,10 +213,10 @@ PeleLM::extFluxDivergenceLevel( #endif for (MFIter mfi(a_divergence, TilingIfNotGPU()); mfi.isValid(); ++mfi) { const Box& bx = mfi.tilebox(); - AMREX_D_TERM(auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); - , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); - , - auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); + AMREX_D_TERM( + auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); + , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); + , auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); auto const& divergence = a_divergence.array(mfi, div_comp); auto const& vol = volume.const_array(mfi); @@ -314,10 +314,10 @@ PeleLM::intFluxDivergenceLevel( #endif for (MFIter mfi(a_divergence, TilingIfNotGPU()); mfi.isValid(); ++mfi) { const Box& bx = mfi.tilebox(); - AMREX_D_TERM(auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); - , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); - , - auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); + AMREX_D_TERM( + auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); + , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); + , auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); auto const& divergence = a_divergence.array(mfi, div_comp); auto const& vol = volume.const_array(mfi); @@ -333,9 +333,10 @@ PeleLM::intFluxDivergenceLevel( }); } else if (flagfab.getType(bx) != FabType::regular) { // EB containing boxes auto vfrac = ebfact.getVolFrac().const_array(mfi); - AMREX_D_TERM(const auto& afrac_x = areafrac[0]->array(mfi); - , const auto& afrac_y = areafrac[1]->array(mfi); - , const auto& afrac_z = areafrac[2]->array(mfi);); + AMREX_D_TERM( + const auto& afrac_x = areafrac[0]->array(mfi); + , const auto& afrac_y = areafrac[1]->array(mfi); + , const auto& afrac_z = areafrac[2]->array(mfi);); amrex::ParallelFor( bx, [ncomp, flag, vfrac, divergence, AMREX_D_DECL(fluxX, fluxY, fluxZ), AMREX_D_DECL(afrac_x, afrac_y, afrac_z), @@ -435,10 +436,10 @@ PeleLM::intFluxDivergenceLevelEB( #endif for (MFIter mfi(a_divergence, TilingIfNotGPU()); mfi.isValid(); ++mfi) { const Box& bx = mfi.tilebox(); - AMREX_D_TERM(auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); - , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); - , - auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); + AMREX_D_TERM( + auto const& fluxX = a_fluxes[0]->const_array(mfi, flux_comp); + , auto const& fluxY = a_fluxes[1]->const_array(mfi, flux_comp); + , auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); auto const& divergence = a_divergence.array(mfi, div_comp); auto const& vol = volume.const_array(mfi); @@ -455,9 +456,10 @@ PeleLM::intFluxDivergenceLevelEB( }); } else if (flagfab.getType(bx) != FabType::regular) { // EB containing boxes auto vfrac = ebfact.getVolFrac().const_array(mfi); - AMREX_D_TERM(const auto& afrac_x = areafrac[0]->array(mfi); - , const auto& afrac_y = areafrac[1]->array(mfi); - , const auto& afrac_z = areafrac[2]->array(mfi);); + AMREX_D_TERM( + const auto& afrac_x = areafrac[0]->array(mfi); + , const auto& afrac_y = areafrac[1]->array(mfi); + , const auto& afrac_z = areafrac[2]->array(mfi);); const auto& ebarea = eb_area->array(mfi); amrex::ParallelFor( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { @@ -542,9 +544,10 @@ PeleLM:: // Get the divergence auto const& div_arr = a_divergence.array(mfi, div_comp); - AMREX_D_TERM(auto const& fx = a_fluxes[0]->const_array(mfi, flux_comp); - , auto const& fy = a_fluxes[1]->const_array(mfi, flux_comp); - , auto const& fz = a_fluxes[2]->const_array(mfi, flux_comp);) + AMREX_D_TERM( + auto const& fx = a_fluxes[0]->const_array(mfi, flux_comp); + , auto const& fy = a_fluxes[1]->const_array(mfi, flux_comp); + , auto const& fz = a_fluxes[2]->const_array(mfi, flux_comp);) #ifdef AMREX_USE_EB auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; @@ -678,9 +681,10 @@ PeleLM::advFluxDivergence( // Get the divergence auto const& div_arr = a_divergence.array(mfi, div_comp); - AMREX_D_TERM(auto const& fx = a_fluxes[0]->const_array(mfi, flux_comp); - , auto const& fy = a_fluxes[1]->const_array(mfi, flux_comp); - , auto const& fz = a_fluxes[2]->const_array(mfi, flux_comp);) + AMREX_D_TERM( + auto const& fx = a_fluxes[0]->const_array(mfi, flux_comp); + , auto const& fy = a_fluxes[1]->const_array(mfi, flux_comp); + , auto const& fz = a_fluxes[2]->const_array(mfi, flux_comp);) auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; auto const& vfrac_arr = ebfact.getVolFrac().const_array(mfi); @@ -1556,8 +1560,9 @@ PeleLM::setTypicalValues(const TimeStamp& a_time, int is_init) #if NUM_ODE > 0 for (int n = 0; n < NUM_ODE; n++) { Print() << "\t" << m_ode_names[n] - << std::setw(std::max( - 0, static_cast(10 - m_ode_names[n].length()))) + << std::setw( + std::max( + 0, static_cast(10 - m_ode_names[n].length()))) << std::left << ":" << typical_values[FIRSTODE + n] << '\n'; } #endif @@ -1880,8 +1885,9 @@ PeleLM::initMixtureFraction() found = true; spec_Bilger_fact[n] = 1.0; } else { - amrex::Abort("initMixtureFraction: requested manifold parameter " - "found multiple times"); + amrex::Abort( + "initMixtureFraction: requested manifold parameter " + "found multiple times"); } } else { spec_Bilger_fact[n] = 0.0; diff --git a/Source/Plasma/LinOps/AMReX_MLABecCecLaplacian.cpp b/Source/Plasma/LinOps/AMReX_MLABecCecLaplacian.cpp index 985188c5d..6cd39371f 100644 --- a/Source/Plasma/LinOps/AMReX_MLABecCecLaplacian.cpp +++ b/Source/Plasma/LinOps/AMReX_MLABecCecLaplacian.cpp @@ -249,15 +249,18 @@ MLABecCecLaplacian::averageDownCoeffsSameAmrLevel( #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif for (MFIter mfi(a[mglev], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - AMREX_D_TERM(Box const& xbx = mfi.nodaltilebox(0); - , Box const& ybx = mfi.nodaltilebox(1); - , Box const& zbx = mfi.nodaltilebox(2)); - AMREX_D_TERM(Array4 const& bx = b[mglev][0].array(mfi); - , Array4 const& by = b[mglev][1].array(mfi); - , Array4 const& bz = b[mglev][2].array(mfi)); - AMREX_D_TERM(Array4 const& cx = c[mglev][0].array(mfi); - , Array4 const& cy = c[mglev][1].array(mfi); - , Array4 const& cz = c[mglev][2].array(mfi)); + AMREX_D_TERM( + Box const& xbx = mfi.nodaltilebox(0); + , Box const& ybx = mfi.nodaltilebox(1); + , Box const& zbx = mfi.nodaltilebox(2)); + AMREX_D_TERM( + Array4 const& bx = b[mglev][0].array(mfi); + , Array4 const& by = b[mglev][1].array(mfi); + , Array4 const& bz = b[mglev][2].array(mfi)); + AMREX_D_TERM( + Array4 const& cx = c[mglev][0].array(mfi); + , Array4 const& cy = c[mglev][1].array(mfi); + , Array4 const& cz = c[mglev][2].array(mfi)); Array4 const& osm = m_overset_mask[amrlev][mglev]->const_array(mfi); AMREX_LAUNCH_HOST_DEVICE_LAMBDA_DIM( @@ -363,12 +366,14 @@ MLABecCecLaplacian::Fapply( BL_PROFILE("MLABecCecLaplacian::Fapply()"); const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const auto dxinv = m_geom[amrlev][mglev].InvCellSizeArray(); @@ -386,12 +391,14 @@ MLABecCecLaplacian::Fapply( const auto& xfab = in.array(mfi); const auto& yfab = out.array(mfi); const auto& afab = acoef.array(mfi); - AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM( + const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM( + const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); if (m_overset_mask[amrlev][mglev]) { const auto& osm = m_overset_mask[amrlev][mglev]->array(mfi); AMREX_LAUNCH_HOST_DEVICE_LAMBDA(bx, tbx, { @@ -417,12 +424,14 @@ MLABecCecLaplacian::normalize(int amrlev, int mglev, MultiFab& mf) const BL_PROFILE("MLABecCecLaplacian::normalize()"); const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const auto dxinv = m_geom[amrlev][mglev].InvCellSizeArray(); @@ -439,12 +448,14 @@ MLABecCecLaplacian::normalize(int amrlev, int mglev, MultiFab& mf) const const Box& bx = mfi.tilebox(); const auto& fab = mf.array(mfi); const auto& afab = acoef.array(mfi); - AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM( + const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM( + const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); AMREX_LAUNCH_HOST_DEVICE_LAMBDA(bx, tbx, { mlabecceclap_normalize( @@ -467,12 +478,14 @@ MLABecCecLaplacian::Fsmooth( } const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const auto& undrrelxr = m_undrrelxr[amrlev][mglev]; const auto& maskvals = m_maskvals[amrlev][mglev]; @@ -508,12 +521,13 @@ MLABecCecLaplacian::Fsmooth( const int nc = getNComp(); const Real* h = m_geom[amrlev][mglev].CellSize(); - AMREX_D_TERM(const Real dhxsq = m_b_scalar / (h[0] * h[0]); - , const Real dhysq = m_b_scalar / (h[1] * h[1]); - , const Real dhzsq = m_b_scalar / (h[2] * h[2])); - AMREX_D_TERM(const Real dhx = m_c_scalar / (h[0]); - , const Real dhy = m_c_scalar / (h[1]); - , const Real dhz = m_c_scalar / (h[2])); + AMREX_D_TERM( + const Real dhxsq = m_b_scalar / (h[0] * h[0]); + , const Real dhysq = m_b_scalar / (h[1] * h[1]); + , const Real dhzsq = m_b_scalar / (h[2] * h[2])); + AMREX_D_TERM( + const Real dhx = m_c_scalar / (h[0]);, const Real dhy = m_c_scalar / (h[1]); + , const Real dhz = m_c_scalar / (h[2])); const Real alpha = m_a_scalar; const Real omega = m_omega; @@ -542,12 +556,14 @@ MLABecCecLaplacian::Fsmooth( const auto& rhsfab = rhs.array(mfi); const auto& afab = acoef.array(mfi); - AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM( + const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM( + const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); const auto& f0fab = f0.array(mfi); const auto& f1fab = f1.array(mfi); @@ -635,21 +651,24 @@ MLABecCecLaplacian::checkDiagonalDominance(int amrlev, int mglev) BL_PROFILE("MLABecCecLaplacian::checkDiagonalDominance()"); const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const int nc = getNComp(); const Real* h = m_geom[amrlev][mglev].CellSize(); - AMREX_D_TERM(const Real dhxsq = m_b_scalar / (h[0] * h[0]); - , const Real dhysq = m_b_scalar / (h[1] * h[1]); - , const Real dhzsq = m_b_scalar / (h[2] * h[2])); - AMREX_D_TERM(const Real dhx = m_c_scalar / (h[0]); - , const Real dhy = m_c_scalar / (h[1]); - , const Real dhz = m_c_scalar / (h[2])); + AMREX_D_TERM( + const Real dhxsq = m_b_scalar / (h[0] * h[0]); + , const Real dhysq = m_b_scalar / (h[1] * h[1]); + , const Real dhzsq = m_b_scalar / (h[2] * h[2])); + AMREX_D_TERM( + const Real dhx = m_c_scalar / (h[0]);, const Real dhy = m_c_scalar / (h[1]); + , const Real dhz = m_c_scalar / (h[2])); const Real alpha = m_a_scalar; MFItInfo mfi_info; @@ -663,12 +682,14 @@ MLABecCecLaplacian::checkDiagonalDominance(int amrlev, int mglev) const Box& tbx = mfi.tilebox(); const auto& afab = acoef.array(mfi); - AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM( + const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM( + const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); AMREX_LAUNCH_HOST_DEVICE_LAMBDA(tbx, thread_box, { abeccec_chkdiag( @@ -687,21 +708,24 @@ MLABecCecLaplacian::getDiagonal(int amrlev, MultiFab& diag) int mglev = 0; const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const int nc = getNComp(); const Real* h = m_geom[amrlev][mglev].CellSize(); - AMREX_D_TERM(const Real dhxsq = m_b_scalar / (h[0] * h[0]); - , const Real dhysq = m_b_scalar / (h[1] * h[1]); - , const Real dhzsq = m_b_scalar / (h[2] * h[2])); - AMREX_D_TERM(const Real dhx = m_c_scalar / (h[0]); - , const Real dhy = m_c_scalar / (h[1]); - , const Real dhz = m_c_scalar / (h[2])); + AMREX_D_TERM( + const Real dhxsq = m_b_scalar / (h[0] * h[0]); + , const Real dhysq = m_b_scalar / (h[1] * h[1]); + , const Real dhzsq = m_b_scalar / (h[2] * h[2])); + AMREX_D_TERM( + const Real dhx = m_c_scalar / (h[0]);, const Real dhy = m_c_scalar / (h[1]); + , const Real dhz = m_c_scalar / (h[2])); const Real alpha = m_a_scalar; MFItInfo mfi_info; @@ -715,12 +739,14 @@ MLABecCecLaplacian::getDiagonal(int amrlev, MultiFab& diag) const Box& tbx = mfi.tilebox(); const auto& afab = acoef.array(mfi); - AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM( + const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM( + const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); const auto& adiag = diag.array(mfi); AMREX_LAUNCH_HOST_DEVICE_LAMBDA(tbx, thread_box, { @@ -741,21 +767,24 @@ MLABecCecLaplacian::getNetFaceCoeff(MultiFab& coeffs_dir, int dir) int mglev = 0.0; const MultiFab& acoef = m_a_coeffs[amrlev][mglev]; - AMREX_D_TERM(const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; - , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; - , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); - AMREX_D_TERM(const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; - , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; - , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& bxcoef = m_b_coeffs[amrlev][mglev][0]; + , const MultiFab& bycoef = m_b_coeffs[amrlev][mglev][1]; + , const MultiFab& bzcoef = m_b_coeffs[amrlev][mglev][2];); + AMREX_D_TERM( + const MultiFab& cxcoef = m_c_coeffs[amrlev][mglev][0]; + , const MultiFab& cycoef = m_c_coeffs[amrlev][mglev][1]; + , const MultiFab& czcoef = m_c_coeffs[amrlev][mglev][2];); const int nc = getNComp(); const Real* h = m_geom[amrlev][mglev].CellSize(); - AMREX_D_TERM(const Real dhxsq = m_b_scalar / (h[0] * h[0]); - , const Real dhysq = m_b_scalar / (h[1] * h[1]); - , const Real dhzsq = m_b_scalar / (h[2] * h[2])); - AMREX_D_TERM(const Real dhx = m_c_scalar / (h[0]); - , const Real dhy = m_c_scalar / (h[1]); - , const Real dhz = m_c_scalar / (h[2])); + AMREX_D_TERM( + const Real dhxsq = m_b_scalar / (h[0] * h[0]); + , const Real dhysq = m_b_scalar / (h[1] * h[1]); + , const Real dhzsq = m_b_scalar / (h[2] * h[2])); + AMREX_D_TERM( + const Real dhx = m_c_scalar / (h[0]);, const Real dhy = m_c_scalar / (h[1]); + , const Real dhz = m_c_scalar / (h[2])); const Real alpha = m_a_scalar; MFItInfo mfi_info; @@ -769,12 +798,14 @@ MLABecCecLaplacian::getNetFaceCoeff(MultiFab& coeffs_dir, int dir) const Box& tbx = mfi.tilebox(); const auto& afab = acoef.array(mfi); - AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi); - , const auto& byfab = bycoef.array(mfi); - , const auto& bzfab = bzcoef.array(mfi);); - AMREX_D_TERM(const auto& cxfab = cxcoef.array(mfi); - , const auto& cyfab = cycoef.array(mfi); - , const auto& czfab = czcoef.array(mfi);); + AMREX_D_TERM( + const auto& bxfab = bxcoef.array(mfi); + , const auto& byfab = bycoef.array(mfi); + , const auto& bzfab = bzcoef.array(mfi);); + AMREX_D_TERM( + const auto& cxfab = cxcoef.array(mfi); + , const auto& cyfab = cycoef.array(mfi); + , const auto& czfab = czcoef.array(mfi);); const auto& coeffd = coeffs_dir.array(mfi); AMREX_LAUNCH_HOST_DEVICE_LAMBDA(tbx, thread_box, { @@ -827,15 +858,15 @@ MLABecCecLaplacian::FFlux( int face_only, int ncomp) { - AMREX_D_TERM(const auto bx = bcoef[0]->array(); - , const auto by = bcoef[1]->array(); - , const auto bz = bcoef[2]->array();); - AMREX_D_TERM(const auto cx = ccoef[0]->array(); - , const auto cy = ccoef[1]->array(); - , const auto cz = ccoef[2]->array();); - AMREX_D_TERM(const auto& fxarr = flux[0]->array(); - , const auto& fyarr = flux[1]->array(); - , const auto& fzarr = flux[2]->array();); + AMREX_D_TERM( + const auto bx = bcoef[0]->array();, const auto by = bcoef[1]->array(); + , const auto bz = bcoef[2]->array();); + AMREX_D_TERM( + const auto cx = ccoef[0]->array();, const auto cy = ccoef[1]->array(); + , const auto cz = ccoef[2]->array();); + AMREX_D_TERM( + const auto& fxarr = flux[0]->array();, const auto& fyarr = flux[1]->array(); + , const auto& fzarr = flux[2]->array();); const auto& solarr = sol.array(); if (face_only) { diff --git a/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp b/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp index cf4e1c43d..69af3c5e9 100644 --- a/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp +++ b/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp @@ -121,8 +121,9 @@ MLCellABecCecLap::define( for (amrlev = 1; amrlev < m_num_amr_levels; ++amrlev) { for (int mglev = 1; mglev < m_num_mg_levels[amrlev]; ++mglev) { // for ref_ratio 4 - m_overset_mask[amrlev].push_back(std::make_unique( - m_grids[amrlev][mglev], m_dmap[amrlev][mglev], 1, 1)); + m_overset_mask[amrlev].push_back( + std::make_unique( + m_grids[amrlev][mglev], m_dmap[amrlev][mglev], 1, 1)); #ifdef AMREX_USE_GPU if ( Gpu::inLaunchRegion() && diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index 9c01a8ae9..25d9be7b1 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -669,24 +669,30 @@ PeleLM::getAdvectionFluxesMOL( for (MFIter mfi(a_nE, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM(const Box& xbx = mfi.grownnodaltilebox(0, 0); - , const Box& ybx = mfi.grownnodaltilebox(1, 0); - , const Box& zbx = mfi.grownnodaltilebox(2, 0)); - - AMREX_D_TERM(auto const& fx = a_fluxes[0]->array(mfi, 0); - , auto const& fy = a_fluxes[1]->array(mfi, 0); - , auto const& fz = a_fluxes[2]->array(mfi, 0);) - AMREX_D_TERM(auto const& ueff = a_ueff[0]->const_array(mfi); - , auto const& veff = a_ueff[1]->const_array(mfi); - , auto const& weff = a_ueff[2]->const_array(mfi);) - AMREX_D_TERM(edgstate[0].resize(xbx, 1);, edgstate[1].resize(ybx, 1); - , edgstate[2].resize(zbx, 1)); - AMREX_D_TERM(Array4 xstate = edgstate[0].array(); - , Array4 ystate = edgstate[1].array(); - , Array4 zstate = edgstate[2].array()); - AMREX_D_TERM(Elixir eli_edgex = edgstate[0].elixir(); - , Elixir eli_edgey = edgstate[1].elixir(); - , Elixir eli_edgez = edgstate[2].elixir()); + AMREX_D_TERM( + const Box& xbx = mfi.grownnodaltilebox(0, 0); + , const Box& ybx = mfi.grownnodaltilebox(1, 0); + , const Box& zbx = mfi.grownnodaltilebox(2, 0)); + + AMREX_D_TERM( + auto const& fx = a_fluxes[0]->array(mfi, 0); + , auto const& fy = a_fluxes[1]->array(mfi, 0); + , auto const& fz = a_fluxes[2]->array(mfi, 0);) + AMREX_D_TERM( + auto const& ueff = a_ueff[0]->const_array(mfi); + , auto const& veff = a_ueff[1]->const_array(mfi); + , auto const& weff = a_ueff[2]->const_array(mfi);) + AMREX_D_TERM( + edgstate[0].resize(xbx, 1);, edgstate[1].resize(ybx, 1); + , edgstate[2].resize(zbx, 1)); + AMREX_D_TERM( + Array4 xstate = edgstate[0].array(); + , Array4 ystate = edgstate[1].array(); + , Array4 zstate = edgstate[2].array()); + AMREX_D_TERM( + Elixir eli_edgex = edgstate[0].elixir(); + , Elixir eli_edgey = edgstate[1].elixir(); + , Elixir eli_edgez = edgstate[2].elixir()); auto const& nE_arr = a_nE.const_array(mfi); auto const& divu_arr = a_nE.const_array(mfi); @@ -728,26 +734,32 @@ PeleLM::getAdvectionFluxes( FArrayBox edgstate[AMREX_SPACEDIM]; for (MFIter mfi(a_nE, TilingIfNotGPU()); mfi.isValid(); ++mfi) { Box const& bx = mfi.tilebox(); - AMREX_D_TERM(const Box& xbx = surroundingNodes(bx, 0); - , const Box& ybx = surroundingNodes(bx, 1); - , const Box& zbx = surroundingNodes(bx, 2)); + AMREX_D_TERM( + const Box& xbx = surroundingNodes(bx, 0); + , const Box& ybx = surroundingNodes(bx, 1); + , const Box& zbx = surroundingNodes(bx, 2)); // data arrays auto const& ne_arr = a_nE.const_array(mfi); - AMREX_D_TERM(Array4 xflux = a_fluxes[0]->array(mfi); - , Array4 yflux = a_fluxes[1]->array(mfi); - , Array4 zflux = a_fluxes[2]->array(mfi)); - AMREX_D_TERM(Array4 u = a_ueff[0]->const_array(mfi); - , Array4 v = a_ueff[1]->const_array(mfi); - , Array4 w = a_ueff[2]->const_array(mfi);); - AMREX_D_TERM(edgstate[0].resize(xbx, 1);, edgstate[1].resize(ybx, 1); - , edgstate[2].resize(zbx, 1)); - AMREX_D_TERM(Array4 xstate = edgstate[0].array(); - , Array4 ystate = edgstate[1].array(); - , Array4 zstate = edgstate[2].array()); - AMREX_D_TERM(Elixir xstate_eli = edgstate[0].elixir(); - , Elixir ystate_eli = edgstate[1].elixir(); - , Elixir zstate_eli = edgstate[2].elixir()); + AMREX_D_TERM( + Array4 xflux = a_fluxes[0]->array(mfi); + , Array4 yflux = a_fluxes[1]->array(mfi); + , Array4 zflux = a_fluxes[2]->array(mfi)); + AMREX_D_TERM( + Array4 u = a_ueff[0]->const_array(mfi); + , Array4 v = a_ueff[1]->const_array(mfi); + , Array4 w = a_ueff[2]->const_array(mfi);); + AMREX_D_TERM( + edgstate[0].resize(xbx, 1);, edgstate[1].resize(ybx, 1); + , edgstate[2].resize(zbx, 1)); + AMREX_D_TERM( + Array4 xstate = edgstate[0].array(); + , Array4 ystate = edgstate[1].array(); + , Array4 zstate = edgstate[2].array()); + AMREX_D_TERM( + Elixir xstate_eli = edgstate[0].elixir(); + , Elixir ystate_eli = edgstate[1].elixir(); + , Elixir zstate_eli = edgstate[2].elixir()); // Predict edge states // X From 4d63d38ef525ec025a03804bdec7dbb1b20c2c99 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 30 Jun 2025 10:37:28 +0200 Subject: [PATCH 11/87] CI fixes --- Source/PeleLMeX_DiffusionOp.cpp | 2 +- Source/PeleLMeX_Forces.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index 1f75ba0e3..570bad8a9 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -492,7 +492,7 @@ DiffusionOp::diffuse_scalar( if (!have_density) { for (int lev = 0; lev <= finest_level; ++lev) { - MultiFab::Copy(a_phi[lev], phi[lev], 0, 0, ncomp, 0); + MultiFab::Copy(*a_phi[lev], phi[lev], 0, 0, ncomp, 0); } } else { for (int lev = 0; lev <= finest_level; ++lev) { diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 4feec26e5..2dbd2ad2c 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -52,7 +52,7 @@ PeleLM::getVelForces( const Real time = getTime(lev, a_time); const int has_divTau = static_cast(a_divTau != nullptr); - + /* auto state_ma = ldata_p->state.const_arrays(); auto ext_ma = m_extSource[lev]->const_arrays(); auto force_ma = a_velForce->arrays(); @@ -78,7 +78,7 @@ PeleLM::getVelForces( // TLH::HERE!!! Leave Lorentz in second MFIter } }); - + */ #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif From 954aa324dbd6eb6ff4e32db2f68a4330a54d5f75 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 30 Jun 2025 11:34:52 +0200 Subject: [PATCH 12/87] dummy mf --- Source/PeleLMeX_Advection.cpp | 11 ++++++-- Source/PeleLMeX_BPatch.H | 2 +- Source/PeleLMeX_Data.cpp | 2 +- Source/PeleLMeX_Diffusion.cpp | 52 ++++++++++++++++++++++++++--------- 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 3b5727a8b..9b63e3bfe 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -265,6 +265,7 @@ PeleLM::getScalarAdvForce( { int* aux_diffuse_d = convertToDeviceVector(m_DiffTypeAux).dataPtr(); + for (int lev = 0; lev <= finest_level; ++lev) { // Get t^{n} data pointer @@ -272,13 +273,19 @@ PeleLM::getScalarAdvForce( auto* ldataR_p = getLevelDataReactPtr(lev); auto const* leosparm = eos_parms.device_parm(); + MultiFab dummy_mf(grids[lev], dmap[lev], 1, 0); + auto dummy_const_ma = dummy_mf.const_arrays(); + auto dummy_ma = dummy_mf.arrays(); + auto state_ma = ldata_p->state.const_arrays(); auto diffData_ma = diffData->Dn[lev].const_arrays(); - auto diffData_aux_ma = diffData->Dn_aux[lev].const_arrays(); + auto diffData_aux_ma = + (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : dummy_const_ma; auto r_ma = ldataR_p->I_R.const_arrays(); auto ext_ma = m_extSource[lev]->arrays(); auto adv_ma = advData->Forcing[lev].arrays(); - auto adv_aux_ma = advData->Forcing_aux[lev].arrays(); + auto adv_aux_ma = + (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : dummy_ma; amrex::ParallelFor( advData->Forcing[lev], diff --git a/Source/PeleLMeX_BPatch.H b/Source/PeleLMeX_BPatch.H index 485caec5b..cae32fd4d 100644 --- a/Source/PeleLMeX_BPatch.H +++ b/Source/PeleLMeX_BPatch.H @@ -72,7 +72,7 @@ public: } #elif (AMREX_SPACEDIM == 3) amrex::Real zp; - constexpr amrex::Real sqrt2 = sqrt(2.0); + constexpr amrex::Real sqrt2 = 1.4142135623730951; xp = point_coordinate[0]; yp = point_coordinate[1]; diff --git a/Source/PeleLMeX_Data.cpp b/Source/PeleLMeX_Data.cpp index 78a3d7186..9a7a1c968 100644 --- a/Source/PeleLMeX_Data.cpp +++ b/Source/PeleLMeX_Data.cpp @@ -217,7 +217,7 @@ PeleLM::AdvanceAdvData::AdvanceAdvData( ba[lev], dm[lev], AMREX_SPACEDIM, 0, MFInfo(), *factory[lev]); } else { AofS.emplace_back(ba[lev], dm[lev], NVAR, 0, MFInfo(), *factory[lev]); - chi[lev].define(ba[lev], dm[lev], 1, 1, MFInfo(), *factory[lev]); + chi.emplace_back(ba[lev], dm[lev], 1, 1, MFInfo(), *factory[lev]); #ifdef PELE_USE_PLASMA Forcing.emplace_back( ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, MFInfo(), diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 0cdfef610..99db41002 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -1097,8 +1097,14 @@ PeleLM::differentialDiffusionUpdate( auto state_ma = ldata_p->state.const_arrays(); auto fY_ma = advData->Forcing[lev].arrays(); - auto aux_ma = ldata_p->auxiliaries.const_arrays(); - auto fAux_ma = advData->Forcing_aux[lev].arrays(); + + MultiFab dummy_mf(grids[lev], dmap[lev], 1, 0); + auto dummy_const_ma = dummy_mf.const_arrays(); + auto dummy_ma = dummy_mf.arrays(); + + auto aux_ma = + (m_nAux > 0) ? ldata_p->auxiliaries.const_arrays() : dummy_const_ma; + auto fAux_ma = (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : dummy_ma; amrex::ParallelFor( advData->Forcing[lev], @@ -1289,11 +1295,20 @@ PeleLM::differentialDiffusionUpdate( auto state_ma = ldata_p->state.arrays(); auto dhat_ma = diffData->Dhat[lev].const_arrays(); auto force_ma = advData->Forcing[lev].const_arrays(); - auto dwbar_ma = diffData->Dwbar[lev].const_arrays(); - auto dT_ma = diffData->DT[lev].const_arrays(); - auto aux_ma = ldata_p->auxiliaries.arrays(); - auto dhat_aux_ma = diffData->Dhat_aux[lev].const_arrays(); - auto force_aux_ma = advData->Forcing_aux[lev].const_arrays(); + + MultiFab dummy_mf(grids[lev], dmap[lev], 1, 0); + auto dummy_const_ma = dummy_mf.const_arrays(); + auto dummy_ma = dummy_mf.arrays(); + + auto dwbar_ma = + (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dummy_const_ma; + auto dT_ma = + (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dummy_const_ma; + auto aux_ma = (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : dummy_ma; + auto dhat_aux_ma = + (m_nAux > 0) ? diffData->Dhat_aux[lev].const_arrays() : dummy_const_ma; + auto force_aux_ma = + (m_nAux > 0) ? advData->Forcing_aux[lev].const_arrays() : dummy_const_ma; if (m_use_wbar != 0 && m_use_soret != 0) { amrex::ParallelFor( @@ -1708,12 +1723,23 @@ PeleLM::getScalarDiffForce( auto a_ma = advData->AofS[lev].const_arrays(); auto ext_ma = m_extSource[lev]->const_arrays(); auto f_ma = advData->Forcing[lev].arrays(); - auto dwbar_ma = diffData->Dwbar[lev].const_arrays(); - auto dT_ma = diffData->DT[lev].const_arrays(); - auto f_aux_ma = advData->Forcing_aux[lev].arrays(); - auto a_aux_ma = advData->AofS_aux[lev].const_arrays(); - auto dn_aux_ma = diffData->Dn_aux[lev].const_arrays(); - auto dnp1_aux_ma = diffData->Dnp1_aux[lev].const_arrays(); + + MultiFab dummy_mf(grids[lev], dmap[lev], 1, 0); + auto dummy_const_ma = dummy_mf.const_arrays(); + auto dummy_ma = dummy_mf.arrays(); + + auto dwbar_ma = + (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dummy_const_ma; + auto dT_ma = + (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dummy_const_ma; + auto f_aux_ma = + (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : dummy_ma; + auto a_aux_ma = + (m_nAux > 0) ? advData->AofS_aux[lev].const_arrays() : dummy_const_ma; + auto dn_aux_ma = + (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : dummy_const_ma; + auto dnp1_aux_ma = + (m_nAux > 0) ? diffData->Dnp1_aux[lev].const_arrays() : dummy_const_ma; amrex::ParallelFor( advData->Forcing[lev], From 8e8aad0dd50f777cf7524a914ff1591cf0834b8a Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 30 Jun 2025 11:46:20 +0200 Subject: [PATCH 13/87] use species_bc --- Source/PeleLMeX_BC.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/PeleLMeX_BC.cpp b/Source/PeleLMeX_BC.cpp index 4e39e86c5..d68438ea2 100644 --- a/Source/PeleLMeX_BC.cpp +++ b/Source/PeleLMeX_BC.cpp @@ -142,8 +142,8 @@ PeleLM::setBoundaryConditions() // Species for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { for (int n = 0; n < NUM_SPECIES; ++n) { - m_bcrec_state[FIRSTSPEC + n].setLo(idim, density_bc[lo_bc[idim]]); - m_bcrec_state[FIRSTSPEC + n].setHi(idim, density_bc[hi_bc[idim]]); + m_bcrec_state[FIRSTSPEC + n].setLo(idim, species_bc[lo_bc[idim]]); + m_bcrec_state[FIRSTSPEC + n].setHi(idim, species_bc[hi_bc[idim]]); } } From 086e398e5ef6ac54e15ba6e4b86b2527a1039e23 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 30 Jun 2025 12:26:52 +0200 Subject: [PATCH 14/87] wrong memory, remove dummy --- Source/PeleLMeX_Advection.cpp | 13 ++++------ Source/PeleLMeX_Diffusion.cpp | 45 +++++++++++++---------------------- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 9b63e3bfe..724e91058 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -273,19 +273,16 @@ PeleLM::getScalarAdvForce( auto* ldataR_p = getLevelDataReactPtr(lev); auto const* leosparm = eos_parms.device_parm(); - MultiFab dummy_mf(grids[lev], dmap[lev], 1, 0); - auto dummy_const_ma = dummy_mf.const_arrays(); - auto dummy_ma = dummy_mf.arrays(); - auto state_ma = ldata_p->state.const_arrays(); auto diffData_ma = diffData->Dn[lev].const_arrays(); - auto diffData_aux_ma = - (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : dummy_const_ma; + auto adv_ma = advData->Forcing[lev].arrays(); auto r_ma = ldataR_p->I_R.const_arrays(); auto ext_ma = m_extSource[lev]->arrays(); - auto adv_ma = advData->Forcing[lev].arrays(); + + auto diffData_aux_ma = + (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : diffData_ma; auto adv_aux_ma = - (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : dummy_ma; + (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : adv_ma; amrex::ParallelFor( advData->Forcing[lev], diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 99db41002..1445ae2ba 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -1098,13 +1098,9 @@ PeleLM::differentialDiffusionUpdate( auto state_ma = ldata_p->state.const_arrays(); auto fY_ma = advData->Forcing[lev].arrays(); - MultiFab dummy_mf(grids[lev], dmap[lev], 1, 0); - auto dummy_const_ma = dummy_mf.const_arrays(); - auto dummy_ma = dummy_mf.arrays(); - auto aux_ma = - (m_nAux > 0) ? ldata_p->auxiliaries.const_arrays() : dummy_const_ma; - auto fAux_ma = (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : dummy_ma; + (m_nAux > 0) ? ldata_p->auxiliaries.const_arrays() : state_ma; + auto fAux_ma = (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : fY_ma; amrex::ParallelFor( advData->Forcing[lev], @@ -1296,19 +1292,15 @@ PeleLM::differentialDiffusionUpdate( auto dhat_ma = diffData->Dhat[lev].const_arrays(); auto force_ma = advData->Forcing[lev].const_arrays(); - MultiFab dummy_mf(grids[lev], dmap[lev], 1, 0); - auto dummy_const_ma = dummy_mf.const_arrays(); - auto dummy_ma = dummy_mf.arrays(); - auto dwbar_ma = - (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dummy_const_ma; + (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dhat_ma; auto dT_ma = - (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dummy_const_ma; - auto aux_ma = (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : dummy_ma; + (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dhat_ma; + auto aux_ma = (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : state_ma; auto dhat_aux_ma = - (m_nAux > 0) ? diffData->Dhat_aux[lev].const_arrays() : dummy_const_ma; + (m_nAux > 0) ? diffData->Dhat_aux[lev].const_arrays() : dhat_ma; auto force_aux_ma = - (m_nAux > 0) ? advData->Forcing_aux[lev].const_arrays() : dummy_const_ma; + (m_nAux > 0) ? advData->Forcing_aux[lev].const_arrays() : dhat_ma; if (m_use_wbar != 0 && m_use_soret != 0) { amrex::ParallelFor( @@ -1724,22 +1716,18 @@ PeleLM::getScalarDiffForce( auto ext_ma = m_extSource[lev]->const_arrays(); auto f_ma = advData->Forcing[lev].arrays(); - MultiFab dummy_mf(grids[lev], dmap[lev], 1, 0); - auto dummy_const_ma = dummy_mf.const_arrays(); - auto dummy_ma = dummy_mf.arrays(); - auto dwbar_ma = - (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dummy_const_ma; + (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dn_ma; auto dT_ma = - (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dummy_const_ma; + (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dn_ma; auto f_aux_ma = - (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : dummy_ma; + (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : f_ma; auto a_aux_ma = - (m_nAux > 0) ? advData->AofS_aux[lev].const_arrays() : dummy_const_ma; + (m_nAux > 0) ? advData->AofS_aux[lev].const_arrays() : dn_ma; auto dn_aux_ma = - (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : dummy_const_ma; + (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : dn_ma; auto dnp1_aux_ma = - (m_nAux > 0) ? diffData->Dnp1_aux[lev].const_arrays() : dummy_const_ma; + (m_nAux > 0) ? diffData->Dnp1_aux[lev].const_arrays() : dn_ma; amrex::ParallelFor( advData->Forcing[lev], @@ -1748,14 +1736,15 @@ PeleLM::getScalarDiffForce( use_wbar = m_use_wbar, use_soret = m_use_soret, dp0dt = m_dp0dt, is_closed_ch = m_closed_chamber, nAux = m_nAux, aux_advect_d, aux_diffuse_d] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 ddn(dn_ma[box_no], NUM_SPECIES + 1); - Array4 ddnp1(dnp1_ma[box_no], NUM_SPECIES + 1); + Array4 ddn(dn_ma[box_no], NUM_SPECIES + 1); + Array4 ddnp1(dnp1_ma[box_no], NUM_SPECIES + 1); + Array4 a(a_ma[box_no], FIRSTSPEC); Array4 extRhoY(ext_ma[box_no], FIRSTSPEC); Array4 extRhoH(ext_ma[box_no], RHOH); Array4 fT(f_ma[box_no], NUM_SPECIES); buildDiffusionForcing( i, j, k, dn_ma[box_no], ddn, dnp1_ma[box_no], ddnp1, r_ma[box_no], - a_ma[box_no], dp0dt, is_closed_ch, do_react, f_ma[box_no], fT, + a, dp0dt, is_closed_ch, do_react, f_ma[box_no], fT, dwbar_ma[box_no], dT_ma[box_no], extRhoY, extRhoH, use_wbar, use_soret, f_aux_ma[box_no], a_aux_ma[box_no], dn_aux_ma[box_no], dnp1_aux_ma[box_no], aux_advect_d, aux_diffuse_d, nAux); From a029186c797c66af694edf86276e05b2f8f0d6ae Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 30 Jun 2025 12:29:16 +0200 Subject: [PATCH 15/87] formatting --- Source/PeleLMeX_Advection.cpp | 2 +- Source/PeleLMeX_Diffusion.cpp | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 724e91058..90751db0d 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -278,7 +278,7 @@ PeleLM::getScalarAdvForce( auto adv_ma = advData->Forcing[lev].arrays(); auto r_ma = ldataR_p->I_R.const_arrays(); auto ext_ma = m_extSource[lev]->arrays(); - + auto diffData_aux_ma = (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : diffData_ma; auto adv_aux_ma = diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 1445ae2ba..88077ae83 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -1098,8 +1098,7 @@ PeleLM::differentialDiffusionUpdate( auto state_ma = ldata_p->state.const_arrays(); auto fY_ma = advData->Forcing[lev].arrays(); - auto aux_ma = - (m_nAux > 0) ? ldata_p->auxiliaries.const_arrays() : state_ma; + auto aux_ma = (m_nAux > 0) ? ldata_p->auxiliaries.const_arrays() : state_ma; auto fAux_ma = (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : fY_ma; amrex::ParallelFor( @@ -1718,10 +1717,8 @@ PeleLM::getScalarDiffForce( auto dwbar_ma = (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dn_ma; - auto dT_ma = - (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dn_ma; - auto f_aux_ma = - (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : f_ma; + auto dT_ma = (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dn_ma; + auto f_aux_ma = (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : f_ma; auto a_aux_ma = (m_nAux > 0) ? advData->AofS_aux[lev].const_arrays() : dn_ma; auto dn_aux_ma = @@ -1736,17 +1733,17 @@ PeleLM::getScalarDiffForce( use_wbar = m_use_wbar, use_soret = m_use_soret, dp0dt = m_dp0dt, is_closed_ch = m_closed_chamber, nAux = m_nAux, aux_advect_d, aux_diffuse_d] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 ddn(dn_ma[box_no], NUM_SPECIES + 1); - Array4 ddnp1(dnp1_ma[box_no], NUM_SPECIES + 1); - Array4 a(a_ma[box_no], FIRSTSPEC); + Array4 ddn(dn_ma[box_no], NUM_SPECIES + 1); + Array4 ddnp1(dnp1_ma[box_no], NUM_SPECIES + 1); + Array4 a(a_ma[box_no], FIRSTSPEC); Array4 extRhoY(ext_ma[box_no], FIRSTSPEC); Array4 extRhoH(ext_ma[box_no], RHOH); Array4 fT(f_ma[box_no], NUM_SPECIES); buildDiffusionForcing( - i, j, k, dn_ma[box_no], ddn, dnp1_ma[box_no], ddnp1, r_ma[box_no], - a, dp0dt, is_closed_ch, do_react, f_ma[box_no], fT, - dwbar_ma[box_no], dT_ma[box_no], extRhoY, extRhoH, use_wbar, - use_soret, f_aux_ma[box_no], a_aux_ma[box_no], dn_aux_ma[box_no], + i, j, k, dn_ma[box_no], ddn, dnp1_ma[box_no], ddnp1, r_ma[box_no], a, + dp0dt, is_closed_ch, do_react, f_ma[box_no], fT, dwbar_ma[box_no], + dT_ma[box_no], extRhoY, extRhoH, use_wbar, use_soret, + f_aux_ma[box_no], a_aux_ma[box_no], dn_aux_ma[box_no], dnp1_aux_ma[box_no], aux_advect_d, aux_diffuse_d, nAux); }); } From 8cf5a8dac341ea3d0d38b29b0bea837844971c3b Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 30 Jun 2025 12:31:10 +0200 Subject: [PATCH 16/87] naming conv --- Source/PeleLMeX_Advection.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 90751db0d..f7cfb63c4 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -274,19 +274,19 @@ PeleLM::getScalarAdvForce( auto const* leosparm = eos_parms.device_parm(); auto state_ma = ldata_p->state.const_arrays(); - auto diffData_ma = diffData->Dn[lev].const_arrays(); + auto dn_ma = diffData->Dn[lev].const_arrays(); auto adv_ma = advData->Forcing[lev].arrays(); auto r_ma = ldataR_p->I_R.const_arrays(); auto ext_ma = m_extSource[lev]->arrays(); - auto diffData_aux_ma = - (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : diffData_ma; + auto dn_aux_ma = + (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : dn_ma; auto adv_aux_ma = (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : adv_ma; amrex::ParallelFor( advData->Forcing[lev], - [state_ma, diffData_ma, diffData_aux_ma, r_ma, ext_ma, adv_ma, adv_aux_ma, + [state_ma, dn_ma, dn_aux_ma, r_ma, ext_ma, adv_ma, adv_aux_ma, aux_diffuse_d, leosparm, nAux = m_nAux, dp0dt = m_dp0dt, is_closed_ch = m_closed_chamber, do_react = @@ -294,9 +294,9 @@ PeleLM::getScalarAdvForce( Array4 rho(state_ma[box_no], DENSITY); Array4 rhoY(state_ma[box_no], FIRSTSPEC); Array4 T(state_ma[box_no], TEMP); - Array4 dn(diffData_ma[box_no], 0); - Array4 ddn(diffData_ma[box_no], NUM_SPECIES + 1); - Array4 dn_aux(diffData_aux_ma[box_no], 0); + Array4 dn(dn_ma[box_no], 0); + Array4 ddn(dn_ma[box_no], NUM_SPECIES + 1); + Array4 dn_aux(dn_aux_ma[box_no], 0); Array4 r(r_ma[box_no], 0); Array4 extRhoY(ext_ma[box_no], FIRSTSPEC); Array4 extRhoH(ext_ma[box_no], RHOH); @@ -1120,13 +1120,11 @@ PeleLM::updateScalarComp( amrex::ParallelFor( ldataOld_p->state, [state_old_ma, adv_aofs_ma, ext_ma, state_new_ma, state_comp, ncomp, - dt_loc = - m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { for (int n = state_comp; n < state_comp + ncomp; ++n) { state_new_ma[box_no](i, j, k, n) = state_old_ma[box_no](i, j, k, n) + - dt_loc * - (adv_aofs_ma[box_no](i, j, k, n) + ext_ma[box_no](i, j, k, n)); + dt * (adv_aofs_ma[box_no](i, j, k, n) + ext_ma[box_no](i, j, k, n)); } }); } From ac1ee27271ce8d6289454ac5c48b5f56b9f22c6a Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 30 Jun 2025 13:06:02 +0200 Subject: [PATCH 17/87] species_bc --- Source/PeleLMeX_BC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/PeleLMeX_BC.cpp b/Source/PeleLMeX_BC.cpp index d68438ea2..1097fd3b6 100644 --- a/Source/PeleLMeX_BC.cpp +++ b/Source/PeleLMeX_BC.cpp @@ -24,7 +24,7 @@ constexpr int density_bc[] = { constexpr int species_bc[] = { BCType::int_dir, BCType::ext_dir, BCType::foextrap, BCType::reflect_even, - BCType::foextrap, BCType::foextrap, BCType::ext_dir, BCType::ext_dir}; + BCType::foextrap, BCType::foextrap, BCType::foextrap, BCType::foextrap}; constexpr int rhoh_bc[] = { BCType::int_dir, BCType::ext_dir, BCType::foextrap, BCType::reflect_even, From 089082bec2a5c3d2be581bcb11ffc1d6862fb4f8 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 30 Jun 2025 14:25:03 +0200 Subject: [PATCH 18/87] implicit conversion --- Source/PeleLMeX_DiffusionOp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index 570bad8a9..bd8bed8c9 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -281,7 +281,7 @@ DiffusionOp::diffuse_scalar( // Times rho{np1,kp1} if needed // Don't touch the ghost cells - if (!have_density) { + if (have_density == 0) { for (int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(*a_phi[lev], phi[lev], 0, 0, ncomp, 0); } @@ -490,7 +490,7 @@ DiffusionOp::diffuse_scalar( // Times rho{np1,kp1} if needed // Don't touch the ghost cells - if (!have_density) { + if (have_density == 0) { for (int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy(*a_phi[lev], phi[lev], 0, 0, ncomp, 0); } From 546032f90c0d78e63804f59b42854d82f2de3f15 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 30 Jun 2025 20:12:21 +0200 Subject: [PATCH 19/87] forces update --- Source/PeleLMeX.H | 13 --- Source/PeleLMeX_Forces.cpp | 228 +++++++++++++------------------------ 2 files changed, 76 insertions(+), 165 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 6135ef373..b9e04255f 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -831,19 +831,6 @@ public: amrex::MultiFab* a_velForce, const int add_gradP); - void getVelForces( - int lev, - const amrex::Box& bx, - const amrex::Real& a_time, - amrex::Array4 const& force, - amrex::Array4 const& vel, - amrex::Array4 const& rho, - amrex::Array4 const& rhoY, - amrex::Array4 const& rhoh, - amrex::Array4 const& temp, - amrex::Array4 const& extMom, - amrex::Array4 const& extRho); - void addSpark(const PeleLM::TimeStamp& a_time); void addScalarVarianceSources(const PeleLM::TimeStamp& a_time); diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 2dbd2ad2c..2c9f852e9 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -1,6 +1,9 @@ #include #include - +#ifdef PELE_USE_PLASMA +#include +#include +#endif using namespace amrex; // Return velocity forces scaled by rhoInv @@ -52,18 +55,27 @@ PeleLM::getVelForces( const Real time = getTime(lev, a_time); const int has_divTau = static_cast(a_divTau != nullptr); - /* + auto state_ma = ldata_p->state.const_arrays(); auto ext_ma = m_extSource[lev]->const_arrays(); auto force_ma = a_velForce->arrays(); + + auto gp_ma = (add_gradP != 0) ? ldataGP_p->gp.const_arrays() : state_ma; + auto divTau_ma = (has_divTau != 0) ? a_divTau->const_arrays() : state_ma; + const auto dx = geom[lev].CellSizeArray(); amrex::ParallelFor( *a_velForce, - [state_ma, ext_ma, force_ma, dx, grav = m_gravity, gp0 = m_background_gp, - ps_dir = m_ctrl_flameDir, is_incomp = m_incompressible, rho_incomp = m_rho, - pseudo_gravity = m_ctrl_pseudoGravity, - dV_control = m_ctrl_dV] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) { + [state_ma, ext_ma, force_ma, gp_ma, divTau_ma, dx, add_gradP, has_divTau, + time, grav = m_gravity, gp0 = m_background_gp, ps_dir = m_ctrl_flameDir, + is_incomp = m_incompressible, rho_incomp = m_rho, + pseudo_gravity = m_ctrl_pseudoGravity, dV_control = m_ctrl_dV +#ifdef PELE_USE_PLASMA + , + plasma_ba = grids[lev], zk = zk +#endif + ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) { Array4 vel(state_ma[box_no], VELX); Array4 rho(state_ma[box_no], DENSITY); Array4 rhoY(state_ma[box_no], FIRSTSPEC); @@ -72,140 +84,49 @@ PeleLM::getVelForces( Array4 extmom(ext_ma[box_no], VELX); Array4 extrho(ext_ma[box_no], DENSITY); makeVelForce( - i, j, k, is_incomp, rho_incomp, pseudo_gravity, ps_dir, a_time, grav, - gp0, dV_control, dx, vel, rho, rhoY, rhoh, temp, extMom, extRho, force); - if (add_gradP != 0 || has_divTau != 0) { - // TLH::HERE!!! Leave Lorentz in second MFIter - } - }); - */ -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(*a_velForce, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const auto& bx = mfi.tilebox(); - FArrayBox DummyFab(bx, 1); - const auto& vel_arr = ldata_p->state.const_array(mfi, VELX); - const auto& rho_arr = (m_incompressible) != 0 - ? DummyFab.array() - : ldata_p->state.const_array(mfi, DENSITY); - const auto& rhoY_arr = (m_incompressible) != 0 - ? DummyFab.array() - : ldata_p->state.const_array(mfi, FIRSTSPEC); - const auto& rhoh_arr = (m_incompressible) != 0 - ? DummyFab.array() - : ldata_p->state.const_array(mfi, RHOH); - const auto& temp_arr = (m_incompressible) != 0 - ? DummyFab.array() - : ldata_p->state.const_array(mfi, TEMP); - const auto& extmom_arr = m_extSource[lev]->const_array(mfi, VELX); - const auto& extrho_arr = m_extSource[lev]->const_array(mfi, DENSITY); - const auto& force_arr = a_velForce->array(mfi); - - // Get other forces (gravity, ...) - getVelForces( - lev, bx, time, force_arr, vel_arr, rho_arr, rhoY_arr, rhoh_arr, temp_arr, - extmom_arr, extrho_arr); - + i, j, k, is_incomp, rho_incomp, pseudo_gravity, ps_dir, time, grav, gp0, + dV_control, dx, vel, rho, rhoY, rhoh, temp, extmom, extrho, + force_ma[box_no]); #ifdef PELE_USE_PLASMA - const auto& phiV_arr = ldata_p->state.const_array(mfi, PHIV); - const auto& ne_arr = ldata_p->state.const_array(mfi, NE); - addLorentzVelForces(lev, bx, time, force_arr, rhoY_arr, phiV_arr, ne_arr); + Array4 phiV(state_ma[box_no], PHIV); + Array4 nE(state_ma[box_no], NE); + GpuArray blo = plasma_ba[box_no].loVect3d(); + GpuArray bhi = plasma_ba[box_no].hiVect3d(); + addLorentzForce( + i, j, k, blo, bhi, time, dx, zk, rhoY, nE, phiV, force_ma[box_no]); #endif - - // Add pressure gradient and viscous forces (if req.) and scale by density. - int is_incomp = m_incompressible; - Real incomp_rho_inv = 1.0 / m_rho; - if ((add_gradP != 0) || (has_divTau != 0)) { - const auto& gp_arr = - (add_gradP) != 0 ? ldataGP_p->gp.const_array(mfi) : DummyFab.array(); - const auto& divTau_arr = - (has_divTau) != 0 ? a_divTau->const_array(mfi) : DummyFab.array(); - amrex::ParallelFor( - bx, - [incomp_rho_inv, is_incomp, add_gradP, has_divTau, rho_arr, gp_arr, - divTau_arr, force_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - if (is_incomp != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - if (add_gradP != 0) { - force_arr(i, j, k, idim) -= gp_arr(i, j, k, idim); - } - if (has_divTau != 0) { - force_arr(i, j, k, idim) += divTau_arr(i, j, k, idim); - } - force_arr(i, j, k, idim) *= incomp_rho_inv; - } - } else { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - if (add_gradP != 0) { - force_arr(i, j, k, idim) -= gp_arr(i, j, k, idim); - } - if (has_divTau != 0) { - force_arr(i, j, k, idim) += divTau_arr(i, j, k, idim); - } - force_arr(i, j, k, idim) /= rho_arr(i, j, k); - } - } - }); - } else { - amrex::ParallelFor( - bx, [incomp_rho_inv, is_incomp, rho_arr, - force_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - if (is_incomp != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - force_arr(i, j, k, idim) *= incomp_rho_inv; - } - } else { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - force_arr(i, j, k, idim) /= rho_arr(i, j, k); - } - } - }); - } - } -} - -void -PeleLM::getVelForces( - int lev, - const Box& bx, - const Real& a_time, - Array4 const& force, - Array4 const& vel, - Array4 const& rho, - Array4 const& rhoY, - Array4 const& rhoh, - Array4 const& temp, - Array4 const& extMom, - Array4 const& extRho) -{ - const auto dx = geom[lev].CellSizeArray(); - - // Get non-static info for the pseudo gravity forcing - int pseudo_gravity = m_ctrl_pseudoGravity; - const Real dV_control = m_ctrl_dV; - - int is_incomp = m_incompressible; - Real rho_incomp = m_rho; - - amrex::ParallelFor( - bx, - [=, grav = m_gravity, gp0 = m_background_gp, - ps_dir = m_ctrl_flameDir] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - makeVelForce( - i, j, k, is_incomp, rho_incomp, pseudo_gravity, ps_dir, a_time, grav, - gp0, dV_control, dx, vel, rho, rhoY, rhoh, temp, extMom, extRho, force); + // Do we shift these outside ParallelFor? + if (add_gradP != 0) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + force_ma[box_no](i, j, k, idim) -= gp_ma[box_no](i, j, k, idim); + } + } + if (has_divTau != 0) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + force_ma[box_no](i, j, k, idim) += divTau_ma[box_no](i, j, k, idim); + } + } + if (is_incomp != 0) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + force_ma[box_no](i, j, k, idim) /= rho_incomp; + } + } else { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + force_ma[box_no](i, j, k, idim) /= rho(i, j, k); + } + } }); + Gpu::streamSynchronize(); } void PeleLM::addSpark(const TimeStamp& a_timestamp) { - for (int lev = 0; lev <= finest_level; lev++) { - for (int n = 0; n < m_n_sparks; n++) { + for (int lev = 0; lev <= finest_level; ++lev) { + for (int n = 0; n < m_n_sparks; ++n) { // Do the checks first - Real time = getTime(lev, a_timestamp); - bool verb = m_spark_verbose > 1 && lev == 0; + const Real time = getTime(lev, a_timestamp); + const bool verb = m_spark_verbose > 1 && lev == 0; if ( time < m_spark_time[n] || time > m_spark_time[n] + m_spark_duration[n]) { @@ -217,11 +138,11 @@ PeleLM::addSpark(const TimeStamp& a_timestamp) const Real* probLo = geom[lev].ProbLo(); auto const dx = geom[lev].CellSizeArray(); IntVect spark_idx; - for (int d = 0; d < AMREX_SPACEDIM; d++) { + for (int d = 0; d < AMREX_SPACEDIM; ++d) { spark_idx[d] = static_cast((m_spark_location[n][d] - probLo[d]) / dx[d]); } - Box domainBox = geom[lev].Domain(); + const Box domainBox = geom[lev].Domain(); // just a check if (!domainBox.contains(spark_idx)) { Warning(m_spark[n] + " not in domain!"); @@ -230,27 +151,27 @@ PeleLM::addSpark(const TimeStamp& a_timestamp) if (verb) { Print() << m_spark[n] << " active" << std::endl; } + auto const* eosparm = eos_parms.device_parm(); + auto eos = pele::physics::PhysicsType::eos(eosparm); auto statema = getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); auto extma = m_extSource[lev]->arrays(); - auto const* leosparm = eos_parms.device_parm(); amrex::ParallelFor( *m_extSource[lev], - [=, spark_duration = m_spark_duration[n], spark_temp = m_spark_temp[n], - eosparm = leosparm, + [statema, extma, eos, dx, spark_idx, + spark_duration = m_spark_duration[n], spark_temp = m_spark_temp[n], spark_radius = m_spark_radius [n]] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - auto eos = pele::physics::PhysicsType::eos(eosparm); - Real dist_to_center = std::sqrt(AMREX_D_TERM( + const Real dist_to_center = std::sqrt(AMREX_D_TERM( (i - spark_idx[0]) * (i - spark_idx[0]) * dx[0] * dx[0], +(j - spark_idx[1]) * (j - spark_idx[1]) * dx[1] * dx[1], +(k - spark_idx[2]) * (k - spark_idx[2]) * dx[2] * dx[2])); if (dist_to_center < spark_radius) { Real rhoh_src_loc = 0; - Real rho = statema[box_no](i, j, k, DENSITY); + const Real rho = statema[box_no](i, j, k, DENSITY); Real Y[NUM_SPECIES]; - for (int ns = 0; ns < NUM_SPECIES; ns++) { + for (int ns = 0; ns < NUM_SPECIES; ++ns) { Y[ns] = statema[box_no](i, j, k, FIRSTSPEC + ns) / rho; } eos.TY2H(spark_temp, Y, rhoh_src_loc); @@ -258,9 +179,9 @@ PeleLM::addSpark(const TimeStamp& a_timestamp) extma[box_no](i, j, k, RHOH) = rhoh_src_loc; } }); - Gpu::streamSynchronize(); } } + Gpu::streamSynchronize(); } // Manifold model - dissipation rate sources for variances @@ -299,14 +220,14 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) } else if (nvariances > 0) { // Compute scalar gradients (no need to average down here) - int do_avgDown = 0; + constexpr int do_avgDown = 0; auto bcRecScalar = fetchBCRecArray(var_of_scalar, 1); - int nGrow = 0; // No need for ghost face on fluxes + constexpr int nGrow = 0; // No need for ghost face on fluxes Vector> grad_fc(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { grad_fc[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], 1, nGrow, MFInfo(), factory); @@ -319,7 +240,7 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) do_avgDown, var_of_scalar); // Add in Production and Dissipation source terms for subfilter variances - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_timestamp); @@ -357,8 +278,11 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) const amrex::Real vol = AMREX_D_TERM( geom[lev].CellSize(0), *geom[lev].CellSize(1), *geom[lev].CellSize(2)); - const amrex::Real l_scale = - (AMREX_SPACEDIM == 2) ? std::sqrt(vol) : std::cbrt(vol); +#if AMREX_SPACEDIM == 2 + const amrex::Real l_scale = std::sqrt(vol); +#else + const amrex::Real l_scale = std::cbrt(vol); +#endif const amrex::Real inv_l_scale2 = 1.0 / (l_scale * l_scale); amrex::ParallelFor( @@ -366,7 +290,7 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) [=] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept { // Subfilter Scalar Dissipation: Linear Relaxation model // rho chi_sgs = C_chi * mu_t / Delta^2 * Variance - amrex::Real mu_t = + const amrex::Real mu_t = fact * (AMREX_D_TERM( mut_arr_x[bx](i, j, k) + mut_arr_x[bx](i + 1, j, k), @@ -380,7 +304,7 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) // Production term (w/ Smagorinsky closure for turbulent flux) // -2 (rho - rho ) d/dx_j // = 2 *mu_t/Sc_t * d/dx_j * d/dx_j - amrex::Real mu_grad2 = + const amrex::Real mu_grad2 = fact * (AMREX_D_TERM( mut_arr_x[bx](i, j, k) * gx[bx](i, j, k) * gx[bx](i, j, k) + @@ -399,8 +323,8 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) }); } } - Gpu::streamSynchronize(); } + Gpu::streamSynchronize(); } } #endif @@ -409,7 +333,7 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) // Calculate additional external sources (soot, radiation, user defined, etc.) void PeleLM::getExternalSources( - int is_initIter, + const int is_initIter, const PeleLM::TimeStamp& a_timestamp_old, const PeleLM::TimeStamp& a_timestamp_new) { @@ -441,7 +365,7 @@ PeleLM::getExternalSources( // User defined external sources if (m_user_defined_ext_sources) { - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p_old = getLevelDataPtr(lev, a_timestamp_old); auto* ldata_p_new = getLevelDataPtr(lev, a_timestamp_new); auto& ext_src = m_extSource[lev]; From b61935d231d9c029496cc6e59d850dab791067ca Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Thu, 3 Jul 2025 00:42:48 +0200 Subject: [PATCH 20/87] clang-tidy performance --- .clang-tidy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index fe56c6aff..5ec0009cf 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -23,7 +23,8 @@ Checks: 'bugprone-*, -readability-convert-member-functions-to-static, -readability-make-member-function-const, -readability-avoid-nested-conditional-operator, - -readability-function-size' + -readability-function-size, + performance-*' WarningsAsErrors: '' HeaderFilterRegex: 'PeleLMeX\/Source|PeleLMeX\/Exec|PeleLMeX\/Submodules\/PelePhysics\/Source|PeleLMeX\/Submodules\/PelePhysics\/Mechanism' FormatStyle: none From 85df23331e573f851705d7a4bca9ce3fa5397953 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Thu, 3 Jul 2025 01:23:04 +0200 Subject: [PATCH 21/87] const checker --- .clang-tidy | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 5ec0009cf..2f8db03e5 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,7 +7,10 @@ Checks: 'bugprone-*, clang-diagnostic-*, clang-analyzer-*, corecppguidelines-*, - modernize-*, + modernize-loop-convert, + modernize-make-const, + modernize-use-constexpr, + modernize-*, -modernize-avoid-c-arrays, -modernize-use-trailing-return-type, -modernize-use-nodiscard, From d825b6e30d017324e5b1d6e49242c25b9a5e345e Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 4 Jul 2025 08:45:15 +0200 Subject: [PATCH 22/87] latest changes --- .clang-tidy | 3 -- Source/PeleLMeX.H | 24 +++++---- Source/PeleLMeX.cpp | 56 ++++++++++---------- Source/PeleLMeX_BC.cpp | 24 +++++---- Source/PeleLMeX_Init.cpp | 71 ++++++++++++-------------- Source/PeleLMeX_ODEQty.cpp | 4 +- Source/PeleLMeX_Plot.cpp | 101 +++++++++++++++++-------------------- Source/PeleLMeX_Setup.cpp | 4 +- Source/PeleLMeX_UserKeys.H | 16 +++--- 9 files changed, 146 insertions(+), 157 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 2f8db03e5..a4a925c2f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,9 +7,6 @@ Checks: 'bugprone-*, clang-diagnostic-*, clang-analyzer-*, corecppguidelines-*, - modernize-loop-convert, - modernize-make-const, - modernize-use-constexpr, modernize-*, -modernize-avoid-c-arrays, -modernize-use-trailing-return-type, diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index b9e04255f..fb47916d6 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -56,7 +56,7 @@ class PeleLM : public amrex::AmrCore { public: - enum TimeStamp { AmrOldTime, AmrHalfTime, AmrNewTime }; + enum TimeStamp : std::uint8_t { AmrOldTime, AmrHalfTime, AmrNewTime }; // constructor PeleLM(); @@ -84,8 +84,8 @@ public: void regrid(int lbase, amrex::Real time, bool initial = false) override; void MakeNewLevelFromScratch( - int lev, - amrex::Real time, + const int lev, + const amrex::Real time, const amrex::BoxArray& ba, const amrex::DistributionMapping& dm) override; @@ -299,7 +299,7 @@ public: * using the user defined init function * \param lev the target level index */ - void initLevelData(int lev); + void initLevelData(const int lev); /** * \brief Fill the initial level data container @@ -1915,8 +1915,10 @@ public: int m_plot_grad_p = 1; int m_ioDigits = 5; amrex::Vector m_evaluatePlotVars; - bool m_write_hdf5_pltfile = false; bool m_do_patch_flow_variables = false; +#if AMREX_USE_HDF5 + bool m_write_hdf5_pltfile = false; +#endif //----------------------------------------------------------------------------- // ALGORITHM @@ -1964,7 +1966,7 @@ public: amrex::Vector m_spark; amrex::Vector m_spark_time; amrex::Vector m_spark_duration; - amrex::Vector> m_spark_location; + amrex::Vector> m_spark_location; amrex::Vector m_spark_temp; amrex::Vector m_spark_radius; @@ -2095,13 +2097,13 @@ public: // Number of ghost cells #ifdef AMREX_USE_EB - int m_nGrowState = 4; + constexpr int m_nGrowState = 4; #else - int m_nGrowState = 3; + constexpr int m_nGrowState = 3; #endif - int m_nGrowAdv = 1; - int m_nGrowdivu = 1; - int m_nGrowMAC = 1; + constexpr int m_nGrowAdv = 1; + constexpr int m_nGrowdivu = 1; + constexpr int m_nGrowMAC = 1; // Initialization int m_do_init_proj = 1; diff --git a/Source/PeleLMeX.cpp b/Source/PeleLMeX.cpp index 063b308f0..e795799ba 100644 --- a/Source/PeleLMeX.cpp +++ b/Source/PeleLMeX.cpp @@ -43,7 +43,7 @@ PeleLM::~PeleLM() PeleLM::LevelData* PeleLM::getLevelDataPtr( - const int lev, const PeleLM::TimeStamp& a_time, int /*useUMac*/) + const int lev, const TimeStamp a_time, int /*useUMac*/) { AMREX_ASSERT( a_time == AmrOldTime || a_time == AmrNewTime || a_time == AmrHalfTime); @@ -74,7 +74,7 @@ PeleLM::getLevelDataReactPtr(const int lev) } Vector> -PeleLM::getStateVect(const TimeStamp& a_time) +PeleLM::getStateVect(const TimeStamp a_time) { Vector> r; r.reserve(finest_level + 1); @@ -111,7 +111,7 @@ PeleLM::getStateVect(const TimeStamp& a_time) } Vector> -PeleLM::getVelocityVect(const TimeStamp& a_time) +PeleLM::getVelocityVect(const TimeStamp a_time) { Vector> r; r.reserve(finest_level + 1); @@ -134,9 +134,9 @@ PeleLM::getVelocityVect(const TimeStamp& a_time) } Vector> -PeleLM::getSpeciesVect(const TimeStamp& a_time) +PeleLM::getSpeciesVect(const TimeStamp a_time) { - AMREX_ASSERT(!m_incompressible); + AMREX_ASSERT(m_incompressible == 0); Vector> r; r.reserve(finest_level + 1); if (a_time == AmrOldTime) { @@ -158,9 +158,9 @@ PeleLM::getSpeciesVect(const TimeStamp& a_time) } Vector> -PeleLM::getDensityVect(const TimeStamp& a_time) +PeleLM::getDensityVect(const TimeStamp a_time) { - AMREX_ASSERT(!m_incompressible); + AMREX_ASSERT(m_incompressible == 0); Vector> r; r.reserve(finest_level + 1); if (a_time == AmrOldTime) { @@ -187,9 +187,9 @@ PeleLM::getDensityVect(const TimeStamp& a_time) } Vector> -PeleLM::getTempVect(const TimeStamp& a_time) +PeleLM::getTempVect(const TimeStamp a_time) { - AMREX_ASSERT(!m_incompressible); + AMREX_ASSERT(m_incompressible == 0); Vector> r; r.reserve(finest_level + 1); if (a_time == AmrOldTime) { @@ -209,9 +209,9 @@ PeleLM::getTempVect(const TimeStamp& a_time) } Vector> -PeleLM::getRhoHVect(const TimeStamp& a_time) +PeleLM::getRhoHVect(const TimeStamp a_time) { - AMREX_ASSERT(!m_incompressible); + AMREX_ASSERT(m_incompressible == 0); Vector> r; r.reserve(finest_level + 1); if (a_time == AmrOldTime) { @@ -231,9 +231,9 @@ PeleLM::getRhoHVect(const TimeStamp& a_time) } Vector -PeleLM::getDivUVect(const TimeStamp& a_time) +PeleLM::getDivUVect(const TimeStamp a_time) { - AMREX_ASSERT(!m_incompressible); + AMREX_ASSERT(m_incompressible == 0); Vector r; r.reserve(finest_level + 1); if (a_time == AmrOldTime) { @@ -249,9 +249,9 @@ PeleLM::getDivUVect(const TimeStamp& a_time) } Vector -PeleLM::getDiffusivityVect(const TimeStamp& a_time) +PeleLM::getDiffusivityVect(const TimeStamp a_time) { - AMREX_ASSERT(!m_incompressible); + AMREX_ASSERT(m_incompressible == 0); Vector r; r.reserve(finest_level + 1); if (a_time == AmrOldTime) { @@ -267,7 +267,7 @@ PeleLM::getDiffusivityVect(const TimeStamp& a_time) } Vector -PeleLM::getViscosityVect(const TimeStamp& a_time) +PeleLM::getViscosityVect(const TimeStamp a_time) { Vector r; r.reserve(finest_level + 1); @@ -295,7 +295,7 @@ PeleLM::getIRVect() } Vector> -PeleLM::getAuxVect(const TimeStamp& a_time) +PeleLM::getAuxVect(const TimeStamp a_time) { AMREX_ASSERT(m_nAux > 0); Vector> r; @@ -317,7 +317,7 @@ PeleLM::getAuxVect(const TimeStamp& a_time) } Vector -PeleLM::getAuxDiffusivityVect(const TimeStamp& a_time) +PeleLM::getAuxDiffusivityVect(const TimeStamp a_time) { AMREX_ASSERT(m_nAux > 0); Vector r; @@ -335,7 +335,7 @@ PeleLM::getAuxDiffusivityVect(const TimeStamp& a_time) } void -PeleLM::averageDownState(const PeleLM::TimeStamp& a_time) +PeleLM::averageDownState(const TimeStamp a_time) { int nCompState = (m_incompressible) != 0 ? AMREX_SPACEDIM : NVAR; for (int lev = finest_level; lev > 0; --lev) { @@ -352,7 +352,7 @@ PeleLM::averageDownState(const PeleLM::TimeStamp& a_time) } void -PeleLM::averageDownScalars(const PeleLM::TimeStamp& a_time) +PeleLM::averageDownScalars(const TimeStamp a_time) { int nScal = NUM_SPECIES + 3; // rho, rhoYs, rhoH, Temp #ifdef PELE_USE_PLASMA @@ -374,7 +374,7 @@ PeleLM::averageDownScalars(const PeleLM::TimeStamp& a_time) } void -PeleLM::averageDownAux(const PeleLM::TimeStamp& a_time) +PeleLM::averageDownAux(const TimeStamp a_time) { for (int lev = finest_level; lev > 0; --lev) { auto* ldataFine_p = getLevelDataPtr(lev, a_time); @@ -393,7 +393,7 @@ PeleLM::averageDownAux(const PeleLM::TimeStamp& a_time) void PeleLM::averageDown( - const PeleLM::TimeStamp& a_time, const int state_comp, const int ncomp) + const TimeStamp a_time, const int state_comp, const int ncomp) { for (int lev = finest_level; lev > 0; --lev) { auto* ldataFine_p = getLevelDataPtr(lev, a_time); @@ -411,7 +411,7 @@ PeleLM::averageDown( } void -PeleLM::averageDownVelocity(const PeleLM::TimeStamp& a_time) +PeleLM::averageDownVelocity(const TimeStamp a_time) { for (int lev = finest_level; lev > 0; --lev) { auto* ldataFine_p = getLevelDataPtr(lev, a_time); @@ -446,9 +446,9 @@ PeleLM::averageDownReaction() #ifdef PELE_USE_PLASMA Vector> -PeleLM::getPhiVVect(const TimeStamp& a_time) +PeleLM::getPhiVVect(const TimeStamp a_time) { - AMREX_ASSERT(!m_incompressible); + AMREX_ASSERT(m_incompressible == 0); Vector> r; r.reserve(finest_level + 1); if (a_time == AmrOldTime) { @@ -468,9 +468,9 @@ PeleLM::getPhiVVect(const TimeStamp& a_time) } Vector> -PeleLM::getnEVect(const TimeStamp& a_time) +PeleLM::getnEVect(const TimeStamp a_time) { - AMREX_ASSERT(!m_incompressible); + AMREX_ASSERT(m_incompressible == 0); Vector> r; r.reserve(finest_level + 1); if (a_time == AmrOldTime) { @@ -490,7 +490,7 @@ PeleLM::getnEVect(const TimeStamp& a_time) } Vector -PeleLM::getnEDiffusivityVect(const TimeStamp& a_time) +PeleLM::getnEDiffusivityVect(const TimeStamp a_time) { Vector r; r.reserve(finest_level + 1); diff --git a/Source/PeleLMeX_BC.cpp b/Source/PeleLMeX_BC.cpp index 1097fd3b6..c42b4f0b3 100644 --- a/Source/PeleLMeX_BC.cpp +++ b/Source/PeleLMeX_BC.cpp @@ -71,28 +71,34 @@ PeleLM:: const int a_method) const { InterpBase* mapper = nullptr; - - if (a_method == 0) { + + switch (a_method) { + case 0: mapper = &mf_pc_interp; - } else if (a_method == 1) { -// -// Get EB-aware interpolater when needed -// + break; + + case 1: #ifdef AMREX_USE_EB + // Get EB-aware interpolator when needed mapper = (EBFactory(0).isAllRegular()) ? &mf_cell_cons_interp - : &eb_mf_cell_cons_interp; + : &eb_mf_cell_cons_interp; #else mapper = &mf_cell_cons_interp; #endif - } else if (a_method == 2) { + break; + + case 2: #ifdef AMREX_USE_EB Abort("Regrid interpolation method = 2 not available with EB !"); #else mapper = &mf_linear_slope_minmax_interp; #endif - } else { + break; + + default: Abort("Unknown interpolation method"); } + return mapper; } diff --git a/Source/PeleLMeX_Init.cpp b/Source/PeleLMeX_Init.cpp index 0fd0039ee..cfb5469d1 100644 --- a/Source/PeleLMeX_Init.cpp +++ b/Source/PeleLMeX_Init.cpp @@ -24,8 +24,8 @@ PeleLM::Init() void PeleLM::MakeNewLevelFromScratch( - int lev, - amrex::Real time, + const int lev, + const amrex::Real time, const amrex::BoxArray& ba, const amrex::DistributionMapping& dm) { @@ -199,7 +199,7 @@ PeleLM::initData() //---------------------------------------------------------------- // Set typical values - int is_init = 1; + constexpr int is_init = 1; setTypicalValues(AmrNewTime, is_init); // initialize temporals @@ -236,7 +236,7 @@ PeleLM::initData() projectInitSolution(); // Active control - int is_restart = 0; + constexpr int is_restart = 0; activeControl(is_restart); //---------------------------------------------------------------- @@ -299,8 +299,8 @@ PeleLM::initData() m_t_old[lev] = -1.0e200; } m_dt = -1.0; - int is_init = 1; - Real dtInit = computeDt(is_init, AmrNewTime); + constexpr int is_init = 1; + const Real dtInit = computeDt(is_init, AmrNewTime); Print() << " Initial dt: " << dtInit << "\n"; } @@ -332,13 +332,13 @@ PeleLM::initData() updateDiagnostics(); // Active control - int is_restart = 1; + constexpr int is_restart = 1; activeControl(is_restart); } } void -PeleLM::initLevelData(int lev) +PeleLM::initLevelData(const int lev) { BL_PROFILE("PeleLMeX::initLevelData()"); @@ -353,25 +353,18 @@ PeleLM::initLevelData(int lev) // Prob/PMF data ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); - auto const local_m_incompressible = m_incompressible; - -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); - FArrayBox DummyFab(bx, 1); - auto const& state_arr = ldata_p->state.array(mfi); - auto const& aux_arr = - (m_nAux > 0) ? ldata_p->auxiliaries.array(mfi) : DummyFab.array(); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - ProblemSpecificFunctions::initdata( - i, j, k, local_m_incompressible, state_arr, aux_arr, geomdata, - *lprobparm, lpmfdata); + + // don't want to use state for dummy in case user overwrites state in aux + MultiFab dummy_mf(grids[lev],ba[lev],1,0); + + auto state_ma = ldata_p->state.arrays(); + auto aux_ma = (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : dummy_mf.arrays(); + + amrex::ParallelFor(ldata_p->state, [state_ma, aux_ma, geomdata,lprobparm,lpmfdata,is_incomp = m_incompressible] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + ProblemSpecificFunctions::initdata(i,j,k,is_incomp,state_ma[box_no],aux_ma[box_no],geomdata,*lprobparm,lpmfdata); }); - } - if (local_m_incompressible == 0) { + if (m_incompressible == 0) { // Initialize thermodynamic pressure setThermoPress(lev, AmrNewTime); if (m_has_divu != 0) { @@ -383,15 +376,15 @@ PeleLM::initLevelData(int lev) void PeleLM::projectInitSolution() { - const int is_init = 1; - + constexpr int is_init = 1; + #ifdef PELE_USE_PLASMA poissonSolveEF(AmrNewTime); fillPatchPhiV(AmrNewTime); #endif // Post data Init time step estimate - Real dtInit = computeDt(is_init, AmrNewTime); + const Real dtInit = computeDt(is_init, AmrNewTime); Print() << " Initial dt: " << dtInit << "\n"; if (m_do_init_proj != 0) { @@ -400,9 +393,9 @@ PeleLM::projectInitSolution() // Subcycling IAMR/PeleLM first does a projection with no reaction divU // which can make the dt for evaluating I_R better if (m_has_divu != 0) { - int is_initialization = 1; // Yes we are - int computeDiffusionTerm = 1; // Needed here - int do_avgDown = 1; // Always + constexpr int is_initialization = 1; // Yes we are + constexpr int computeDiffusionTerm = 1; // Needed here + constexpr int do_avgDown = 1; // Always // Light version of the diffusion data container std::unique_ptr diffData; @@ -427,7 +420,7 @@ PeleLM::projectInitSolution() //---------------------------------------------------------------- // Initial velocity projection iterations - for (int iter = 0; iter < m_numDivuIter; iter++) { + for (int iter = 0; iter < m_numDivuIter; ++iter) { if (m_do_react != 0) { // The new level data has been filled above // Copy new -> old since old used in advanceChemistry @@ -455,9 +448,9 @@ PeleLM::projectInitSolution() copyStateOldToNew(); } if (m_has_divu != 0) { - int is_initialization = 1; // Yes we are - int computeDiffusionTerm = 1; // Needed here - int do_avgDown = 1; // Always + constexpr int is_initialization = 1; // Yes we are + constexpr int computeDiffusionTerm = 1; // Needed here + constexpr nt do_avgDown = 1; // Always // Light version of the diffusion data container std::unique_ptr diffData; @@ -507,13 +500,13 @@ PeleLM::initialIterations() //---------------------------------------------------------------- // Initial pressure iterations - for (int iter = 0; iter < m_init_iter; iter++) { + for (int iter = 0; iter < m_init_iter; ++iter) { if (m_verbose > 0) { amrex::Print() << "\n ================ INITIAL ITERATION [" << iter << "] ================ \n"; } - int is_init = 1; + constexpr int is_init = 1; Advance(is_init); // Pass new pressure and gp from New to Old @@ -525,7 +518,7 @@ PeleLM::initialIterations() } void -PeleLM::InitFromGridFile(amrex::Real time) +PeleLM::InitFromGridFile(const amrex::Real time) { { const amrex::BoxArray& ba = MakeBaseGrids(); @@ -533,7 +526,7 @@ PeleLM::InitFromGridFile(amrex::Real time) MakeNewLevelFromScratch(0, time, ba, dm); } finest_level = static_cast(m_initial_ba.size()); - for (int lev = 1; lev <= finest_level; lev++) { + for (int lev = 1; lev <= finest_level; ++lev) { const amrex::BoxArray ba = m_initial_ba[lev - 1]; DistributionMapping dm(ba); MakeNewLevelFromScratch(lev, time, ba, dm); diff --git a/Source/PeleLMeX_ODEQty.cpp b/Source/PeleLMeX_ODEQty.cpp index 44bd75df2..e59a3d6dd 100644 --- a/Source/PeleLMeX_ODEQty.cpp +++ b/Source/PeleLMeX_ODEQty.cpp @@ -9,7 +9,7 @@ PeleLM::predictODEQty() { // Uses forward Euler to predict values for ODE qty at tnp1 // If m_ext_sources_SDC = false, no SDC corrections used - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto const& state_arrs = getLevelDataPtr(lev, AmrNewTime)->state.arrays(); auto const& ext_src_arrs = m_extSource[lev]->arrays(); ParallelFor( @@ -24,4 +24,4 @@ PeleLM::predictODEQty() Gpu::streamSynchronize(); } } -#endif \ No newline at end of file +#endif diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 2cc177da1..68274eecf 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -24,7 +24,7 @@ using namespace amrex; namespace { -const std::string level_prefix{"Level_"}; +constexpr std::string level_prefix{"Level_"}; } void @@ -38,9 +38,9 @@ void PeleLM::WriteDebugPlotFile( const Vector& a_MF, const std::string& pltname) { - int nComp = a_MF[0]->nComp(); + const int nComp = a_MF[0]->nComp(); Vector names(nComp); - for (int n = 0; n < nComp; n++) { + for (int n = 0; n < nComp; ++n) { names[n] = "comp" + std::to_string(n); } Vector istep(finest_level + 1, m_nstep); @@ -144,7 +144,7 @@ PeleLM::WritePlotFile() // Derive int deriveEntryCount = 0; - for (int ivar = 0; ivar < m_derivePlotVarCount; ivar++) { + for (int ivar = 0; ivar < m_derivePlotVarCount; ++ivar) { const PeleLMDeriveRec* rec = derive_lst.get(m_derivePlotVars[ivar]); deriveEntryCount += rec->numDerive(); } @@ -174,9 +174,10 @@ PeleLM::WritePlotFile() //---------------------------------------------------------------- // Plot MultiFabs - Vector mf_plt(finest_level + 1); + Vector mf_plt; + mf_plt.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - mf_plt[lev].define(grids[lev], dmap[lev], ncomp, 0, MFInfo(), Factory(lev)); + mf_plt.emplace_back(grids[lev], dmap[lev], ncomp, 0, MFInfo(), Factory(lev)); } //---------------------------------------------------------------- @@ -192,7 +193,7 @@ PeleLM::WritePlotFile() if (m_incompressible == 0) { plt_VarsName.push_back("density"); if (m_plotStateSpec != 0) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { plt_VarsName.push_back("rho.Y(" + names[n] + ")"); } } @@ -204,8 +205,8 @@ PeleLM::WritePlotFile() plt_VarsName.push_back("phiV"); #endif #ifdef PELE_USE_SOOT - for (int mom = 0; mom < NUMSOOTVAR; mom++) { - std::string sootname = soot_model->sootVariableName(mom); + for (int mom = 0; mom < NUMSOOTVAR; ++mom) { + const std::string sootname = soot_model->sootVariableName(mom); plt_VarsName.push_back(sootname); } #endif @@ -227,12 +228,12 @@ PeleLM::WritePlotFile() , plt_VarsName.push_back("gradpz")); } - for (int n = 0; n < m_nAux; n++) { + for (int n = 0; n < m_nAux; ++n) { plt_VarsName.push_back(m_aux_names[n]); } if ((m_do_react != 0) && (m_skipInstantRR == 0) && (m_plot_react != 0)) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { plt_VarsName.push_back("I_R(" + names[n] + ")"); } #ifdef PELE_USE_PLASMA @@ -249,9 +250,9 @@ PeleLM::WritePlotFile() plt_VarsName.push_back("volFrac"); #endif - for (int ivar = 0; ivar < m_derivePlotVarCount; ivar++) { + for (int ivar = 0; ivar < m_derivePlotVarCount; ++ivar) { const PeleLMDeriveRec* rec = derive_lst.get(m_derivePlotVars[ivar]); - for (int dvar = 0; dvar < rec->numDerive(); dvar++) { + for (int dvar = 0; dvar < rec->numDerive(); ++dvar) { plt_VarsName.push_back(rec->variableName(dvar)); } } @@ -281,7 +282,7 @@ PeleLM::WritePlotFile() if (m_do_extraEFdiags) { for (int ivar = 0; ivar < NUM_IONS; ++ivar) { for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - std::string dir = (idim == 0) ? "X" : ((idim == 1) ? "Y" : "Z"); + const std::string dir = (idim == 0) ? "X" : ((idim == 1) ? "Y" : "Z"); plt_VarsName.push_back( "DriftFlux_" + names[NUM_SPECIES - NUM_IONS + ivar] + "_" + dir); } @@ -294,7 +295,7 @@ PeleLM::WritePlotFile() } #if NUM_ODE > 0 - for (int n = 0; n < NUM_ODE; n++) { + for (int n = 0; n < NUM_ODE; ++n) { plt_VarsName.push_back(m_ode_names[n]); } #endif @@ -388,7 +389,7 @@ PeleLM::WritePlotFile() cnt += 1; #endif - for (int ivar = 0; ivar < m_derivePlotVarCount; ivar++) { + for (int ivar = 0; ivar < m_derivePlotVarCount; ++ivar) { std::unique_ptr mf; mf = derive(m_derivePlotVars[ivar], m_cur_time, lev, 0); MultiFab::Copy(mf_plt[lev], *mf, 0, cnt, mf->nComp(), 0); @@ -494,7 +495,7 @@ PeleLM::WritePlotFile() #ifdef PELE_USE_SPRAY if (do_spray_particles) { - bool is_spraycheck = false; + constexpr bool is_spraycheck = false; for (int lev = 0; lev <= finest_level; ++lev) { SprayPC->SprayParticleIO(lev, is_spraycheck, plotfilename); // Remove virtual particles that were made for derived variables @@ -593,7 +594,7 @@ PeleLM::WriteCheckPointFile() amrex::PreBuildDirectorHierarchy( checkpointname, level_prefix, finest_level + 1, true); - bool is_checkpoint = true; + constexpr bool is_checkpoint = true; WriteHeader(checkpointname, is_checkpoint); WriteJobInfo(checkpointname); @@ -636,7 +637,7 @@ PeleLM::WriteCheckPointFile() } #ifdef PELE_USE_SPRAY if (do_spray_particles) { - bool is_spraycheck = true; + constexpr bool is_spraycheck = true; for (int lev = 0; lev <= finest_level; ++lev) { SprayPC->SprayParticleIO(lev, is_spraycheck, checkpointname); } @@ -956,10 +957,10 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) // in case the number of species differs. MultiFab speciesPlt(grids[a_lev], dmap[a_lev], nSpecPlt, 0); pltData.fillPatchFromPlt(a_lev, geom[a_lev], idY, 0, nSpecPlt, speciesPlt); - for (int i = 0; i < NUM_SPECIES; i++) { + for (int i = 0; i < NUM_SPECIES; ++i) { std::string specString = "Y(" + spec_names[i] + ")"; int foundSpec = 0; - for (int iplt = 0; iplt < nSpecPlt; iplt++) { + for (int iplt = 0; iplt < nSpecPlt; ++iplt) { if (specString == plt_vars[idY + iplt]) { MultiFab::Copy(ldata_p->state, speciesPlt, iplt, FIRSTSPEC + i, 1, 0); foundSpec = 1; @@ -973,20 +974,13 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) // Converting units when pltfile is coming from PeleC solution if (pltfileSource == "C") { amrex::Print() << " Converting CGS to MKS units... \n"; -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); - auto const& vel_arr = ldata_p->state.array(mfi, VELX); - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; n++) { - amrex::Real vel_mks = vel_arr(i, j, k, n) * 0.01; - vel_arr(i, j, k, n) = vel_mks; - } - }); - } + auto state_ma = ldata_p->state.arrays(); + amrex::ParallelFor(ldata_p->state, [vel_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 vel(state_ma[box_no],VELX); + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + vel(i,j,k,n) *= 0.01; + } + }); } #ifdef PELE_USE_PLASMA @@ -1004,23 +998,18 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) SootConst sc; amrex::Real* momV = sc.MomOrderV.data(); amrex::Real* momS = sc.MomOrderS.data(); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const Box& bx = mfi.tilebox(); - auto const& soot_arr = ldata_p->state.array(mfi, FIRSTSOOT); - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SOOT_MOMENTS; n++) { - amrex::Real soot_exp = 3. - (3. * momV[n] + 2. * momS[n]); - soot_arr(i, j, k, n) *= std::pow(100., soot_exp); - } - soot_arr(i, j, k, NUMSOOTVAR - 1) *= 1.E6; - }); - } - } + + auto state_ma = ldata_p->state.arrays(); + + amrex::ParallelFor(ldata_p->state,[state_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 soot(state_ma[box_no],FIRSTSOOT); + for (int n = 0; n < NUM_SOOT_MOMENTS; ++n) { + const amrex::Real soot_exp = 3. - (3. * momV[n] + 2. * momS[n]); + soot(i, j, k, n) *= std::pow(100., soot_exp); + } + soot_arr(i, j, k, NUMSOOTVAR - 1) *= 1.E6; + }); + } } else { SootData* const sd = soot_model->getSootData(); amrex::Real moments[NUM_SOOT_MOMENTS + 1]; @@ -1063,7 +1052,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) auto eos = pele::physics::PhysicsType::eos(eosparm); Real massfrac[NUM_SPECIES] = {0.0}; Real sumYs = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { massfrac[n] = rhoY_arr(i, j, k, n); #ifdef N2_ID if (n != N2_ID) { @@ -1087,7 +1076,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) rhoH_arr(i, j, k) = h_cgs * 1.0e-4 * rho_arr(i, j, k); // Fill rhoYs - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoY_arr(i, j, k, n) = massfrac[n] * rho_arr(i, j, k); } }); @@ -1168,11 +1157,11 @@ PeleLM::WriteJobInfo(const std::string& path) const jobInfoFile << " Grid Information\n"; jobInfoFile << PrettyLine; - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { jobInfoFile << " level: " << lev << "\n"; jobInfoFile << " number of boxes = " << grids[lev].size() << "\n"; jobInfoFile << " maximum zones = "; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { jobInfoFile << geom[lev].Domain().length(idim) << " "; } jobInfoFile << "\n\n"; diff --git a/Source/PeleLMeX_Setup.cpp b/Source/PeleLMeX_Setup.cpp index cd9e76c2e..6870da54f 100644 --- a/Source/PeleLMeX_Setup.cpp +++ b/Source/PeleLMeX_Setup.cpp @@ -894,8 +894,10 @@ PeleLM::readIOParameters() pp.query("initial_grid_file", m_initial_grid_file); pp.query("regrid_file", m_regrid_file); pp.query("file_stepDigits", m_ioDigits); - pp.query("use_hdf5_plt", m_write_hdf5_pltfile); pp.query("regrid_interp_method", m_regrid_interp_method); +#ifdef AMREX_USE_HDF5 + pp.query("use_hdf5_plt", m_write_hdf5_pltfile); +#endif AMREX_ASSERT(m_regrid_interp_method == 0 || m_regrid_interp_method == 1); } diff --git a/Source/PeleLMeX_UserKeys.H b/Source/PeleLMeX_UserKeys.H index 097908005..69e23e5ba 100644 --- a/Source/PeleLMeX_UserKeys.H +++ b/Source/PeleLMeX_UserKeys.H @@ -11,7 +11,7 @@ struct BoundaryCondition { BoundaryCondition() = default; - enum { + enum : std::uint8_t { BCInterior = 0, BCInflow, BCOutflow, @@ -41,7 +41,7 @@ const BoundaryCondition boundarycondition; struct NSSolver { NSSolver() = default; - enum { LowMachNumber = 0, Incompressible }; + enum : std::uint8_t { LowMachNumber = 0, Incompressible }; const std::map str2int = { {"lowmachnumber", LowMachNumber}, {"incompressible", Incompressible}, @@ -57,7 +57,7 @@ const NSSolver nssolver; struct Interpolator { Interpolator() = default; - enum { + enum : std::uint8_t { PiecewiseLinearConserv = 0, PiecewiseLinearConservMinMax, PiecewiseConstant @@ -78,7 +78,7 @@ const Interpolator interpolator; struct LESModel { LESModel() = default; - enum { None = 0, Smagorinsky, WALE, Sigma }; + enum : std::uint8_t { None = 0, Smagorinsky, WALE, Sigma }; const std::map str2int = { {"none", None}, {"smagorinsky", Smagorinsky}, @@ -96,7 +96,7 @@ const LESModel lesmodel; struct AdvectionScheme { AdvectionScheme() = default; - enum { + enum : std::uint8_t { Godunov_PLM = 0, Godunov_PPM, Godunov_PPM_WENOZ, @@ -121,7 +121,7 @@ const AdvectionScheme advscheme; struct LoadBalanceCost { LoadBalanceCost() = default; - enum { + enum : std::uint8_t { Ncell = 0, ChemFunctCallAvg, ChemFunctCallMax, @@ -150,7 +150,7 @@ const LoadBalanceCost lbcost; struct LoadBalanceMethod { LoadBalanceMethod() = default; - enum { SFC = 0, Knapsack, RoundRobin }; + enum : std::uint8_t { SFC = 0, Knapsack, RoundRobin }; const std::map str2int = { {"sfc", SFC}, {"knapsack", Knapsack}, @@ -168,7 +168,7 @@ const LoadBalanceMethod lbmethod; struct ChiCorrectionType { ChiCorrectionType() = default; - enum { DivuEveryIter = 0, DivuFirstIter, NoDivu }; + enum : std::uint8_t { DivuEveryIter = 0, DivuFirstIter, NoDivu }; const std::map str2int = { {"divueveryiter", DivuEveryIter}, {"divufirstiter", DivuFirstIter}, From 0458798bc296c558af1d6d41f79cfef0d3132535 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 4 Jul 2025 10:25:59 +0200 Subject: [PATCH 23/87] projection --- Source/PeleLMeX.H | 13 +- Source/PeleLMeX_Projection.cpp | 385 +++++++++++++++++---------------- 2 files changed, 203 insertions(+), 195 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index fb47916d6..734899f09 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -391,7 +391,7 @@ public: * \param a_dt time time step size */ void velocityProjection( - int is_init, const PeleLM::TimeStamp& a_rhoTime, const amrex::Real& a_dt); + const int is_init, const PeleLM::TimeStamp& a_rhoTime, const amrex::Real& a_dt); /** * \brief Actual nodal projection call function. @@ -407,23 +407,24 @@ public: const amrex::Vector& a_sigma, const amrex::Vector& rhs_cc, const amrex::Vector& rhs_nd, - int incremental, - amrex::Real scaling_factor); - + const int incremental, + const amrex::Real scaling_factor); +#if AMREX_SPACEDIM == 2 /** * \brief For 2D-RZ, scale multifab components by radius * including 1 ghost cell on Dirichlet BC * \param a_lev level index * \param a_mf MultiFab to act upon */ - void scaleProj_RZ(int a_lev, amrex::MultiFab& a_mf); + void scaleProj_RZ(const int a_lev, amrex::MultiFab& a_mf); /** * \brief For 2D-RZ, unscale multifab components by radius * \param a_lev level index * \param a_mf MultiFab to act upon */ - void unscaleProj_RZ(int a_lev, amrex::MultiFab& a_mf); + void unscaleProj_RZ(const int a_lev, amrex::MultiFab& a_mf); +#endif //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 04599206c..7c2d10539 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -18,75 +18,80 @@ PeleLM::initialProjection() " W: " << velMax[2] <<) "\n"; } - Real dummy_dt = 1.0; - int incremental = 0; - int nGhost = 0; + constexpr Real dummy_dt = 1.0; + constexpr int incremental = 0; + constexpr int nGhost = 0; // Get sigma : density if not incompressible - Vector> sigma(finest_level + 1); + Vector> sigma; if (m_incompressible == 0) { + sigma.reserve(finest_level+1); for (int lev = 0; lev <= finest_level; ++lev) { - sigma[lev] = std::make_unique( - grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev]); + sigma.emplace_back(std::make_unique( + grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev])); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - Box const& bx = mfi.tilebox(); - auto const& rho_arr = ldata_p->state.const_array(mfi, DENSITY); - auto const& sig_arr = sigma[lev]->array(mfi); - amrex::ParallelFor( - bx, [rho_arr, sig_arr, - dummy_dt] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - sig_arr(i, j, k) = dummy_dt / rho_arr(i, j, k); - }); + auto state_ma = ldata_p->const_arrays(); + auto sigma_ma = sigma[lev]->arrays(); + amrex::ParallelFor(ldata_p,[state_ma,sigma_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rho(state_ma[box_no],DENSITY); + sigma_ma[box_no](i,j,k) = dummy_dt/rho(i,j,k); + }); + Gpu::streamSynchronize(); +#if AMREX_SPACEDIM == 2 + if (geom[lev].IsRZ()) { + scaleProj_RZ(lev, *sigma[lev]); } - scaleProj_RZ(lev, *sigma[lev]); +#endif } } // Get velocity Vector> vel; + vel.reserve(finest_level+1); for (int lev = 0; lev <= finest_level; ++lev) { - vel.push_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); + vel.emplace_back(std::make_unique(m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); vel[lev]->setBndry(0.0); setInflowBoundaryVel(*vel[lev], lev, AmrNewTime); - scaleProj_RZ(lev, *vel[lev]); +#if AMREX_SPACEDIM == 2 + if (geom[lev].IsRZ()) { + scaleProj_RZ(lev, *vel[lev]) + }; +#endif + } - + // Get RHS cc: - divU (- \int{divU}) Real Sbar = 0.0; - Vector rhs_cc(finest_level + 1); + Vector rhs_cc; if ((m_incompressible == 0) && (m_has_divu != 0)) { // Ensure integral of RHS is zero for closed chamber if (m_closed_chamber != 0) { Sbar = MFSum(GetVecOfConstPtrs(getDivUVect(AmrNewTime)), 0); Sbar /= m_uncoveredVol; // Transform in Mean. } + rhs_cc.reserve(finest_level+1); for (int lev = 0; lev <= finest_level; ++lev) { - rhs_cc[lev].define( - grids[lev], dmap[lev], 1, m_leveldata_new[lev]->divu.nGrow()); - MultiFab::Copy( - rhs_cc[lev], m_leveldata_new[lev]->divu, 0, 0, 1, - m_leveldata_new[lev]->divu.nGrow()); + rhs_cc.emplace_back(grids[lev], dmap[lev], 1, m_leveldata_new[lev]->divu.nGrow()); + MultiFab::Copy(rhs_cc[lev], m_leveldata_new[lev]->divu, 0, 0, 1, + m_leveldata_new[lev]->divu.nGrow()); if (m_closed_chamber != 0) { rhs_cc[lev].plus(-Sbar, 0, 1); } - scaleProj_RZ(lev, rhs_cc[lev]); +#if AMREX_SPACEDIM == 2 + if (geom[lev].IsRZ()) { + scaleProj_RZ(lev, rhs_cc[lev]); + } +#endif rhs_cc[lev].mult(-1.0, 0, 1, rhs_cc[lev].nGrow()); } } - + doNodalProject( - GetVecOfPtrs(vel), GetVecOfPtrs(sigma), GetVecOfPtrs(rhs_cc), {}, - incremental, dummy_dt); - + GetVecOfPtrs(vel), GetVecOfPtrs(sigma), GetVecOfPtrs(rhs_cc), {}, + incremental, dummy_dt); + // Set back press and gpress to zero and restore divu // and rescale velocity if 2D-RZ for (int lev = 0; lev <= finest_level; lev++) { @@ -100,7 +105,11 @@ PeleLM::initialProjection() m_leveldata_new[lev]->divu.plus(Sbar, 0, 1); } } - unscaleProj_RZ(lev, *vel[lev]); +#if AMREX_SPACEDIM == 2 + if (geom[lev].IsRZ()) { + unscaleProj_RZ(lev, *vel[lev]); + } +#endif } // In R-Z, AMReX-Hydro do an average down of r*vel. @@ -109,15 +118,13 @@ PeleLM::initialProjection() if (Geom(0).IsRZ()) { averageDownVelocity(AmrNewTime); } - + if (m_verbose != 0) { - Vector velMax(AMREX_SPACEDIM); - velMax = MLNorm0( - GetVecOfConstPtrs(getVelocityVect(AmrNewTime)), 0, AMREX_SPACEDIM); + Vector velMax = MLNorm0(GetVecOfConstPtrs(getVelocityVect(AmrNewTime)), 0, AMREX_SPACEDIM); amrex::Print() << " >> After initial velocity projection: "; amrex::Print() << AMREX_D_TERM( - " U: " << velMax[0] <<, " V: " << velMax[1] <<, - " W: " << velMax[2] <<) "\n"; + " U: " << velMax[0] <<, " V: " << velMax[1] <<, + " W: " << velMax[2] <<) "\n"; } } @@ -130,48 +137,50 @@ PeleLM::initialPressProjection() amrex::Print() << " Initial pressure projection \n"; } - Real dummy_dt = 1.0; - int incremental = 0; - int nGhost = 1; + constexpr Real dummy_dt = 1.0; + constexpr int incremental = 0; + constexpr int nGhost = 1; // Get sigma : density if not incompressible - Vector> sigma(finest_level + 1); + Vector> sigma; if (m_incompressible == 0) { + sigma.reserve(finest_level+1); for (int lev = 0; lev <= finest_level; ++lev) { - sigma[lev] = std::make_unique( - grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev]); + sigma.emplace_back(std::make_unique(grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev])); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - Box const& bx = mfi.tilebox(); - auto const& rho_arr = ldata_p->state.const_array(mfi, DENSITY); - auto const& sig_arr = sigma[lev]->array(mfi); - amrex::ParallelFor( - bx, [rho_arr, sig_arr, - dummy_dt] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - sig_arr(i, j, k) = dummy_dt / rho_arr(i, j, k); - }); + auto state_ma = ldata_p->state.const_arrays(); + auto sigma_ma = sigma[lev]->arrays(); + amrex::ParallelFor(ldata_p->state, [state_ma, sigma_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rho(state_ma[box_no],DENSITY); + sigma_ma[box_no](i,j,k) = dummy_dt/rho(i,j,k); + }); + Gpu::streamSynchronize(); +#if AMREX_SPACEDIM == 2 + if (geom[lev].IsRZ()) { + scaleProj_RZ(lev, *sigma[lev]); } - scaleProj_RZ(lev, *sigma[lev]); +#endif } } // Set the velocity to the gravity field - Vector vel(finest_level + 1); + Vector vel; + vel.reserve(finest_level+1); for (int lev = 0; lev <= finest_level; ++lev) { - vel[lev].define( + vel.emplace_back( grids[lev], dmap[lev], AMREX_SPACEDIM, nGhost, MFInfo(), *m_factory[lev]); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { vel[lev].setVal(m_gravity[idim], idim, 1, 1); } vel[lev].setBndry(0.0); setInflowBoundaryVel(vel[lev], lev, AmrNewTime); - scaleProj_RZ(lev, vel[lev]); +#if AMREX_SPACEDIM == 2 + if (geom[lev].IsRZ()) { + scaleProj_RZ(lev, vel[lev]); + } +#endif } // Done without divU in IAMR @@ -181,77 +190,73 @@ PeleLM::initialPressProjection() void PeleLM::velocityProjection( - int is_initIter, const TimeStamp& a_rhoTime, const Real& a_dt) + const int is_initIter, const TimeStamp& a_rhoTime, const Real& a_dt) { BL_PROFILE("PeleLMeX::velocityProjection()"); - int nGhost = 0; - int incremental = (is_initIter) != 0 ? 1 : 0; + constexpr int nGhost = 0; + const int incremental = (is_initIter) != 0 ? 1 : 0; // Get sigma : scaled density inv. if not incompressible - Vector> sigma(finest_level + 1); + Vector> sigma; if (m_incompressible == 0) { - Vector> rhoHalf(finest_level + 1); - rhoHalf = getDensityVect(a_rhoTime); + Vector> rhoHalf = getDensityVect(a_rhoTime); + sigma.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { + + sigma.emplace_back(std::make_unique(grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev])); - sigma[lev] = std::make_unique( - grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev]); + auto rhoHalf_ma = rhoHalf[lev]->const_arrays(); + auto sigma_ma = sigma[lev]->arrays(); + + amrex::ParallelFor(*rhoHalf[lev], [rhoHalf_ma,sig_ma, dt = a_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + sigma_ma[box_no](i,j,k) = dt/rhoHalf_ma[box_no](i,j,k); + }); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(*rhoHalf[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - Box const& bx = mfi.tilebox(); - auto const& rho_arr = rhoHalf[lev]->const_array(mfi); - auto const& sig_arr = sigma[lev]->array(mfi); - amrex::ParallelFor( - bx, [rho_arr, sig_arr, - a_dt] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - sig_arr(i, j, k) = a_dt / rho_arr(i, j, k); - }); - } #ifdef AMREX_USE_EB EB_set_covered(*sigma[lev], 0.0); #endif - scaleProj_RZ(lev, *sigma[lev]); +#if AMREX_SPACEDIM == 2 + if (geom[lev].IsRZ()) { + scaleProj_RZ(lev, *sigma[lev]); + } +#endif } } if (incremental == 0) { - Vector> rhoHalf(finest_level + 1); + Vector> rhoHalf; if (m_incompressible == 0) { rhoHalf = getDensityVect(a_rhoTime); } + rhoHalf.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldataNew_p->state, TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - Box const& bx = mfi.tilebox(); - auto const& vel_arr = ldataNew_p->state.array(mfi, VELX); - auto const& gp_arr = ldataOld_p->gp.const_array(mfi); - auto const& rho_arr = (m_incompressible) != 0 - ? Array4() - : rhoHalf[lev]->const_array(mfi); - amrex::ParallelFor( - bx, - [vel_arr, gp_arr, rho_arr, a_dt, incompressible = m_incompressible, - rho = m_rho] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - Real soverrho = - (incompressible) != 0 ? a_dt / rho : a_dt / rho_arr(i, j, k); - AMREX_D_TERM(vel_arr(i, j, k, 0) += gp_arr(i, j, k, 0) * soverrho; - , vel_arr(i, j, k, 1) += gp_arr(i, j, k, 1) * soverrho; - , - vel_arr(i, j, k, 2) += gp_arr(i, j, k, 2) * soverrho); - }); + auto state_old_ma = ldataOld_p->arrays(); + auto gp_new_ma = ldataNew_p->const_arrays(); + if (m_incompressible == 0) { + auto rho_ma = rhoHalf[lev]->const_arrays(); + amrex::ParallelFor(ldataNew_p->state, [state_old_ma,gp_new_ma, rho_ma, dt=a_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 vel(state_old_ma[box_no],VELX); + const Real soverrho = dt/rho_ma[box_no](i,j,k); + for (int n = 0; n < NUM_SPECIES; ++n) { + vel(i,j,k,n) += gp_new_ma[box_no](i,j,k,n)*soverrho; + } + }); + } else { + amrex::ParallelFor(ldataNew_p->state, [state_old_ma,gp_new_ma, rho = m_rho, dt=a_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 vel(state_old_ma[box_no],VELX); + const Real soverrho = dt/rho; + for (int n = 0; n < NUM_SPECIES; ++n) { + vel(i,j,k,n) += gp_new_ma[box_no](i,j,k,n)*soverrho; + } + }); } } + Gpu::streamSynchronize(); } // If incremental @@ -267,8 +272,9 @@ PeleLM::velocityProjection( // Get velocity Vector> vel; + vel.reserve(finest_level+1); for (int lev = 0; lev <= finest_level; ++lev) { - vel.push_back( + vel.emplace_back( std::make_unique( m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); #ifdef AMREX_USE_EB @@ -278,7 +284,11 @@ PeleLM::velocityProjection( if (incremental == 0) { setInflowBoundaryVel(*vel[lev], lev, AmrNewTime); } - scaleProj_RZ(lev, *vel[lev]); +#if AMREX_SPACEDIM == 2 + if (geom[lev].IsRZ()) { + scaleProj_RZ(lev, *ve;[lev]); + } +#endif } // To ensure integral of RHS is zero for closed chamber, get mean divU @@ -296,15 +306,15 @@ PeleLM::velocityProjection( // Get RHS cc Vector rhs_cc; if ((m_incompressible == 0) && (m_has_divu != 0)) { - rhs_cc.resize(finest_level + 1); + rhs_cc.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { if (incremental == 0) { auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - rhs_cc[lev].define( + rhs_cc.emplace_back( grids[lev], dmap[lev], 1, ldata_p->divu.nGrow(), MFInfo(), *m_factory[lev]); MultiFab::Copy( - rhs_cc[lev], ldata_p->divu, 0, 0, 1, ldata_p->divu.nGrow()); + rhs_cc[lev], ldata_p->divu, 0, 0, 1, ldata_p->divu.nGrow()); if (m_closed_chamber != 0) { rhs_cc[lev].plus(-SbarNew, 0, 1); } @@ -339,7 +349,11 @@ PeleLM::velocityProjection( #ifdef AMREX_USE_EB EB_set_covered(rhs_cc[lev], 0.0); #endif - scaleProj_RZ(lev, rhs_cc[lev]); +#if AMREX_SPACEDIM == 2 + if (geom[lev].IsRZ()) { + scaleProj_RZ(lev, rhs_cc[lev]); + } +#endif } } @@ -347,30 +361,33 @@ PeleLM::velocityProjection( GetVecOfPtrs(vel), GetVecOfPtrs(sigma), GetVecOfPtrs(rhs_cc), {}, incremental, a_dt); +#if AMREX_SPACEDIM == 2 + for (int lev = 0; lev <=finest_level; ++lev) { + // Unscaling New vel before adding back old one + if (geom[lev].IsRZ()) { + unscaleProj_RZ(lev, *vel[lev]); + } + } +#endif + // If incremental // define back to be U^{np1} by adding U^{n} - // and handles scaling if 2D-RZ if (incremental != 0) { for (int lev = 0; lev <= finest_level; ++lev) { auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - unscaleProj_RZ( - lev, *vel[lev]); // Unscaling New vel before adding back old one - MultiFab::Add( - ldataNew_p->state, ldataOld_p->state, VELX, VELX, AMREX_SPACEDIM, 0); - } - } else { - for (int lev = 0; lev <= finest_level; ++lev) { - unscaleProj_RZ(lev, *vel[lev]); + MultiFab::Add(ldataNew_p->state, ldataOld_p->state, VELX, VELX, AMREX_SPACEDIM, 0); } } - + +#ifdef AMREX_SPACEDIM == 2 // In R-Z, AMReX-Hydro do an average down of r*vel. // Now that we have unscaled vel, need to do average down again // to have consistent vel across levels if (Geom(0).IsRZ()) { averageDownVelocity(AmrNewTime); } +#endif } void @@ -379,8 +396,8 @@ PeleLM::doNodalProject( const Vector& a_sigma, const Vector& rhs_cc, const Vector& rhs_nd, - int incremental, - Real scaling_factor) + const int incremental, + const Real scaling_factor) { // Asserts AMREX_ASSERT(a_vel.size() == a_sigma.size()); @@ -419,7 +436,7 @@ PeleLM::doNodalProject( std::unique_ptr nodal_projector; if (m_incompressible != 0) { - Real constant_sigma = scaling_factor / m_rho; + const Real constant_sigma = scaling_factor / m_rho; nodal_projector = std::make_unique( a_vel, constant_sigma, Geom(0, finest_level), info); } else { @@ -510,77 +527,67 @@ PeleLM::doNodalProject( } } +#if AMREX_SPACEDIM == 2 void PeleLM::scaleProj_RZ( // NOLINT(readability-convert-member-functions-to-static) - int a_lev, - MultiFab& a_mf) + const int a_lev, + MultiFab& a_mf) { -#if AMREX_SPACEDIM == 2 // Scale nodal projection cell-centered mfs by radius - if (geom[a_lev].IsRZ()) { - Box domain = geom[a_lev].Domain(); - auto BCRecVel = fetchBCRecArray(VELX, 1); - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - if (BCRecVel[0].lo(idim) == BCType::ext_dir) { - domain.growLo(idim, 1); - } - if (BCRecVel[0].hi(idim) == BCType::ext_dir) { - domain.growHi(idim, 1); - } + Box domain = geom[a_lev].Domain(); + auto BCRecVel = fetchBCRecArray(VELX, 1); + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + if (BCRecVel[0].lo(idim) == BCType::ext_dir) { + domain.growLo(idim, 1); + } + if (BCRecVel[0].hi(idim) == BCType::ext_dir) { + domain.growHi(idim, 1); } - const Real dr = geom[a_lev].CellSize()[0]; - auto const& mf_ma = a_mf.arrays(); - amrex::ParallelFor( - a_mf, a_mf.nGrowVect(), - [=, ncomp = a_mf.nComp()] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - auto mf = mf_ma[box_no]; - if (domain.contains(i, j, k)) { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) *= (static_cast(i) + 0.5) * dr; - } - } else { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) = 0.0; - } - } - }); - Gpu::streamSynchronize(); } -#else - amrex::ignore_unused(a_lev, a_mf); -#endif + const Real dr = geom[a_lev].CellSize()[0]; + auto const& mf_ma = a_mf.arrays(); + amrex::ParallelFor( + a_mf, a_mf.nGrowVect(), + [mf_ma,dr,domain,ncomp = a_mf.nComp()] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + auto mf = mf_ma[box_no]; + if (domain.contains(i, j, k)) { + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) *= (static_cast(i) + 0.5) * dr; + } + } else { + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) = 0.0; + } + } + }); + Gpu::streamSynchronize(); } void PeleLM:: unscaleProj_RZ( // NOLINT(readability-convert-member-functions-to-static) - int a_lev, + const int a_lev, MultiFab& a_mf) { -#if AMREX_SPACEDIM == 2 // Unscale nodal projection cell-centered mfs by radius - if (geom[a_lev].IsRZ()) { - const Box& domain = geom[a_lev].Domain(); - const Real dr = geom[a_lev].CellSize()[0]; - auto const& mf_ma = a_mf.arrays(); - amrex::ParallelFor( - a_mf, a_mf.nGrowVect(), - [=, ncomp = a_mf.nComp()] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - auto mf = mf_ma[box_no]; - if (domain.contains(i, j, k)) { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) /= (static_cast(i) + 0.5) * dr; - } - } else { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) = 0.0; - } - } - }); - } -#else - amrex::ignore_unused(a_lev, a_mf); -#endif + const Box& domain = geom[a_lev].Domain(); + const Real dr = geom[a_lev].CellSize()[0]; + auto const& mf_ma = a_mf.arrays(); + amrex::ParallelFor( + a_mf, a_mf.nGrowVect(), + [mf_ma, dr, domain, ncomp = a_mf.nComp()] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + auto mf = mf_ma[box_no]; + if (domain.contains(i, j, k)) { + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) /= (static_cast(i) + 0.5) * dr; + } + } else { + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) = 0.0; + } + } + }); + Gpu::streamSynchronize(); } +#endif From cb7ab21e0674bdf84b530386514a2fa4af77625a Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 4 Jul 2025 10:32:25 +0200 Subject: [PATCH 24/87] formatting + endl --- Source/PeleLMeX.H | 6 +- Source/PeleLMeX.cpp | 3 +- Source/PeleLMeX_BC.cpp | 12 +- Source/PeleLMeX_EB.cpp | 3 +- Source/PeleLMeX_Eos.cpp | 2 +- Source/PeleLMeX_Evolve.cpp | 25 ++-- Source/PeleLMeX_Forces.cpp | 6 +- Source/PeleLMeX_Init.cpp | 34 +++-- Source/PeleLMeX_Plot.cpp | 125 +++++++++-------- Source/PeleLMeX_Projection.cpp | 211 ++++++++++++++++------------- Source/PeleLMeX_Regrid.cpp | 4 +- Source/PeleLMeX_Setup.cpp | 47 +++---- Source/PeleLMeX_SprayParticles.cpp | 6 +- Source/PeleLMeX_Temporals.cpp | 3 +- Source/PeleLMeX_TransportProp.cpp | 3 +- Source/PeleLMeX_UMac.cpp | 2 +- 16 files changed, 256 insertions(+), 236 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 734899f09..26705b706 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -391,7 +391,9 @@ public: * \param a_dt time time step size */ void velocityProjection( - const int is_init, const PeleLM::TimeStamp& a_rhoTime, const amrex::Real& a_dt); + const int is_init, + const PeleLM::TimeStamp& a_rhoTime, + const amrex::Real& a_dt); /** * \brief Actual nodal projection call function. @@ -1967,7 +1969,7 @@ public: amrex::Vector m_spark; amrex::Vector m_spark_time; amrex::Vector m_spark_duration; - amrex::Vector> m_spark_location; + amrex::Vector> m_spark_location; amrex::Vector m_spark_temp; amrex::Vector m_spark_radius; diff --git a/Source/PeleLMeX.cpp b/Source/PeleLMeX.cpp index e795799ba..cdafca081 100644 --- a/Source/PeleLMeX.cpp +++ b/Source/PeleLMeX.cpp @@ -42,8 +42,7 @@ PeleLM::~PeleLM() } PeleLM::LevelData* -PeleLM::getLevelDataPtr( - const int lev, const TimeStamp a_time, int /*useUMac*/) +PeleLM::getLevelDataPtr(const int lev, const TimeStamp a_time, int /*useUMac*/) { AMREX_ASSERT( a_time == AmrOldTime || a_time == AmrNewTime || a_time == AmrHalfTime); diff --git a/Source/PeleLMeX_BC.cpp b/Source/PeleLMeX_BC.cpp index c42b4f0b3..2375875ca 100644 --- a/Source/PeleLMeX_BC.cpp +++ b/Source/PeleLMeX_BC.cpp @@ -71,22 +71,22 @@ PeleLM:: const int a_method) const { InterpBase* mapper = nullptr; - + switch (a_method) { case 0: mapper = &mf_pc_interp; break; - + case 1: #ifdef AMREX_USE_EB // Get EB-aware interpolator when needed mapper = (EBFactory(0).isAllRegular()) ? &mf_cell_cons_interp - : &eb_mf_cell_cons_interp; + : &eb_mf_cell_cons_interp; #else mapper = &mf_cell_cons_interp; #endif break; - + case 2: #ifdef AMREX_USE_EB Abort("Regrid interpolation method = 2 not available with EB !"); @@ -94,11 +94,11 @@ PeleLM:: mapper = &mf_linear_slope_minmax_interp; #endif break; - + default: Abort("Unknown interpolation method"); } - + return mapper; } diff --git a/Source/PeleLMeX_EB.cpp b/Source/PeleLMeX_EB.cpp index ace760822..98fff0ce1 100644 --- a/Source/PeleLMeX_EB.cpp +++ b/Source/PeleLMeX_EB.cpp @@ -798,8 +798,7 @@ PeleLM::checkEBInflowFunctions() if (m_verbose != 0 && m_useEBinflow != 0) { Print() << "WARNING: EB-inflow capability is experimental. Scalar " "diffusion is not supported at these boundaries and future " - "interface changes are possible!" - << std::endl; + "interface changes are possible!\n" } } #endif diff --git a/Source/PeleLMeX_Eos.cpp b/Source/PeleLMeX_Eos.cpp index 18d43c876..982ee3bb1 100644 --- a/Source/PeleLMeX_Eos.cpp +++ b/Source/PeleLMeX_Eos.cpp @@ -352,7 +352,7 @@ PeleLM::adjustPandDivU(std::unique_ptr& advData) Print() << " >> Closed chamber pOld: " << m_pOld << ", pNew: " << m_pNew << ", dp0dt: " << m_dp0dt << "\n"; Print() << " >> Total mass old: " << m_massOld - << ", mass new: " << m_massNew << std::endl; + << ", mass new: " << m_massNew << "\n"; } // Return Sbar so that we'll add it back to mac_divu after the MAC projection diff --git a/Source/PeleLMeX_Evolve.cpp b/Source/PeleLMeX_Evolve.cpp index 0712c416a..11945722e 100644 --- a/Source/PeleLMeX_Evolve.cpp +++ b/Source/PeleLMeX_Evolve.cpp @@ -7,7 +7,7 @@ PeleLM::Evolve() { BL_PROFILE("PeleLMeX::Evolve()"); - bool do_not_evolve = + const bool do_not_evolve = ((m_max_step == 0) || ((m_stop_time >= 0.) && (m_cur_time > m_stop_time))); int plt_justDidIt = 0; @@ -48,7 +48,7 @@ PeleLM::Evolve() SprayPostRegrid(); } #endif - int is_init = 0; + constexpr int is_init = 0; Advance(is_init); m_nstep++; m_cur_time += m_dt; @@ -60,7 +60,7 @@ PeleLM::Evolve() #endif // Active control - int is_restart = 0; + constexpr int is_restart = 0; activeControl(is_restart); // Temporals @@ -72,9 +72,9 @@ PeleLM::Evolve() doDiagnostics(); // Check message - bool dump_and_stop = checkMessage("dump_and_stop"); - bool plt_and_continue = checkMessage("plt_and_continue"); - bool chk_and_continue = checkMessage("chk_and_continue"); + const bool dump_and_stop = checkMessage("dump_and_stop"); + const bool plt_and_continue = checkMessage("plt_and_continue"); + const bool chk_and_continue = checkMessage("chk_and_continue"); // Check for plot file if (writePlotNow() || dump_and_stop || plt_and_continue) { @@ -95,9 +95,8 @@ PeleLM::Evolve() if (t_elapsed >= (m_max_wall_time * 3600)) { over_max_wall_time = true; if (m_verbose > 0) { - amrex::Print() << std::endl - << "Reached maximum allowed wall time, stopping ..." - << std::endl; + amrex::Print() + << "\n Reached maximum allowed wall time, stopping ...\n"; } } } @@ -212,13 +211,7 @@ PeleLM::writeCheckNow() const bool PeleLM::doTemporalsNow() const { - bool write_now = false; - - if ((m_do_temporals != 0) && (m_nstep % m_temp_int == 0)) { - write_now = true; - } - - return write_now; + return (m_do_temporals != 0) && (m_nstep % m_temp_int == 0) } bool diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 2c9f852e9..9e7c3b405 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -131,7 +131,7 @@ PeleLM::addSpark(const TimeStamp& a_timestamp) time < m_spark_time[n] || time > m_spark_time[n] + m_spark_duration[n]) { if (verb) { - Print() << m_spark[n] << " not active" << std::endl; + Print() << m_spark[n] << " not active \n"; } continue; } @@ -145,11 +145,11 @@ PeleLM::addSpark(const TimeStamp& a_timestamp) const Box domainBox = geom[lev].Domain(); // just a check if (!domainBox.contains(spark_idx)) { - Warning(m_spark[n] + " not in domain!"); + amrex::Warning(m_spark[n] + " not in domain!"); continue; } if (verb) { - Print() << m_spark[n] << " active" << std::endl; + Print() << m_spark[n] << " active\n"; } auto const* eosparm = eos_parms.device_parm(); auto eos = pele::physics::PhysicsType::eos(eosparm); diff --git a/Source/PeleLMeX_Init.cpp b/Source/PeleLMeX_Init.cpp index cfb5469d1..f3a43d92d 100644 --- a/Source/PeleLMeX_Init.cpp +++ b/Source/PeleLMeX_Init.cpp @@ -32,11 +32,10 @@ PeleLM::MakeNewLevelFromScratch( BL_PROFILE("PeleLMeX::MakeNewLevelFromScratch()"); if (m_verbose > 0) { - amrex::Print() << " Making new level " << lev << " from scratch" - << std::endl; + amrex::Print() << " Making new level " << lev << " from scratch \n"; if (m_verbose > 2 && lev > 0) { auto const dx = geom[lev].CellSizeArray(); - Real vol = AMREX_D_TERM(dx[0], *dx[1], *dx[2]); + const Real vol = AMREX_D_TERM(dx[0], *dx[1], *dx[2]); amrex::Print() << " with " << ba.numPts() << " cells," << ba.size() << " boxes," << " over " @@ -45,7 +44,7 @@ PeleLM::MakeNewLevelFromScratch( << "% of the domain \n"; } if (m_verbose > 3 && lev > 0) { - amrex::Print() << " with BoxArray " << ba << std::endl; + amrex::Print() << " with BoxArray " << ba << "\n"; } } @@ -353,15 +352,22 @@ PeleLM::initLevelData(const int lev) // Prob/PMF data ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); - + // don't want to use state for dummy in case user overwrites state in aux - MultiFab dummy_mf(grids[lev],ba[lev],1,0); - - auto state_ma = ldata_p->state.arrays(); - auto aux_ma = (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : dummy_mf.arrays(); + MultiFab dummy_mf(grids[lev], ba[lev], 1, 0); - amrex::ParallelFor(ldata_p->state, [state_ma, aux_ma, geomdata,lprobparm,lpmfdata,is_incomp = m_incompressible] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - ProblemSpecificFunctions::initdata(i,j,k,is_incomp,state_ma[box_no],aux_ma[box_no],geomdata,*lprobparm,lpmfdata); + auto state_ma = ldata_p->state.arrays(); + auto aux_ma = + (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : dummy_mf.arrays(); + + amrex::ParallelFor( + ldata_p->state, + [state_ma, aux_ma, geomdata, lprobparm, lpmfdata, + is_incomp = + m_incompressible] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + ProblemSpecificFunctions::initdata( + i, j, k, is_incomp, state_ma[box_no], aux_ma[box_no], geomdata, + *lprobparm, lpmfdata); }); if (m_incompressible == 0) { @@ -377,7 +383,7 @@ void PeleLM::projectInitSolution() { constexpr int is_init = 1; - + #ifdef PELE_USE_PLASMA poissonSolveEF(AmrNewTime); fillPatchPhiV(AmrNewTime); @@ -450,7 +456,7 @@ PeleLM::projectInitSolution() if (m_has_divu != 0) { constexpr int is_initialization = 1; // Yes we are constexpr int computeDiffusionTerm = 1; // Needed here - constexpr nt do_avgDown = 1; // Always + constexpr nt do_avgDown = 1; // Always // Light version of the diffusion data container std::unique_ptr diffData; @@ -522,7 +528,7 @@ PeleLM::InitFromGridFile(const amrex::Real time) { { const amrex::BoxArray& ba = MakeBaseGrids(); - DistributionMapping dm(ba); + const DistributionMapping dm(ba); MakeNewLevelFromScratch(0, time, ba, dm); } finest_level = static_cast(m_initial_ba.size()); diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 68274eecf..bb906ecf6 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -23,6 +23,9 @@ using namespace amrex; +namespace m2c = pele::physics::utilities::mks2cgs; +namespace c2m = pele::physics::utilities::cgs2mks; + namespace { constexpr std::string level_prefix{"Level_"}; } @@ -177,7 +180,8 @@ PeleLM::WritePlotFile() Vector mf_plt; mf_plt.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - mf_plt.emplace_back(grids[lev], dmap[lev], ncomp, 0, MFInfo(), Factory(lev)); + mf_plt.emplace_back( + grids[lev], dmap[lev], ncomp, 0, MFInfo(), Factory(lev)); } //---------------------------------------------------------------- @@ -856,7 +860,7 @@ PeleLM::ReadCheckPointFile() } } if (m_verbose != 0) { - amrex::Print() << "Restart complete" << std::endl; + amrex::Print() << "Restart complete \n"; } } @@ -975,12 +979,15 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) if (pltfileSource == "C") { amrex::Print() << " Converting CGS to MKS units... \n"; auto state_ma = ldata_p->state.arrays(); - amrex::ParallelFor(ldata_p->state, [vel_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 vel(state_ma[box_no],VELX); - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - vel(i,j,k,n) *= 0.01; - } - }); + amrex::ParallelFor( + ldata_p->state, + [vel_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 vel(state_ma[box_no], VELX); + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + vel(i, j, k, n) *= 0.01; + } + }); + Gpu::streamSynchronize(); } #ifdef PELE_USE_PLASMA @@ -999,17 +1006,22 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) amrex::Real* momV = sc.MomOrderV.data(); amrex::Real* momS = sc.MomOrderS.data(); - auto state_ma = ldata_p->state.arrays(); - - amrex::ParallelFor(ldata_p->state,[state_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 soot(state_ma[box_no],FIRSTSOOT); - for (int n = 0; n < NUM_SOOT_MOMENTS; ++n) { - const amrex::Real soot_exp = 3. - (3. * momV[n] + 2. * momS[n]); - soot(i, j, k, n) *= std::pow(100., soot_exp); - } - soot_arr(i, j, k, NUMSOOTVAR - 1) *= 1.E6; - }); - } + auto state_ma = ldata_p->state.arrays(); + amrex::Real soot_exp[NUM_SOOT_MOMENTS] = {0.0}; + for (int n = 0; n < NUM_SOOT_MOMENTS; ++n) { + soot_exp[n] = 3. - (3. * momV[n] + 2. * momS[n]); + } + amrex::ParallelFor( + ldata_p->state, [state_ma, soot_exp] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + Array4 soot(state_ma[box_no], FIRSTSOOT); + for (int n = 0; n < NUM_SOOT_MOMENTS; ++n) { + soot(i, j, k, n) *= std::pow(100., soot_exp[n]); + } + soot_arr(i, j, k, NUMSOOTVAR - 1) *= 1.E6; + }); + Gpu::streamSynchronize(); + } } else { SootData* const sd = soot_model->getSootData(); amrex::Real moments[NUM_SOOT_MOMENTS + 1]; @@ -1025,7 +1037,6 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) ldata_p->gp.setVal(0.0); ProbParm const* lprobparm = prob_parm_d; - auto const* leosparm = eos_parms.device_parm(); // If m_do_patch_flow_variables is set as true, call user-defined function to // patch flow variables @@ -1037,51 +1048,47 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) // Enforce rho and rhoH consistent with temperature and mixture // The above handles species mapping (to some extent), but nothing enforce // sum of Ys = 1 -> use N2 in the following if N2 is present -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); - auto const& rho_arr = ldata_p->state.array(mfi, DENSITY); - auto const& rhoY_arr = ldata_p->state.array(mfi, FIRSTSPEC); - auto const& rhoH_arr = ldata_p->state.array(mfi, RHOH); - auto const& temp_arr = ldata_p->state.array(mfi, TEMP); - amrex::ParallelFor( - bx, - [=, eosparm = leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - auto eos = pele::physics::PhysicsType::eos(eosparm); - Real massfrac[NUM_SPECIES] = {0.0}; - Real sumYs = 0.0; - for (int n = 0; n < NUM_SPECIES; ++n) { - massfrac[n] = rhoY_arr(i, j, k, n); + auto state_ma = ldata_p->state.arrays(); + auto const* leosparm = eos_parms.device_parm(); + const Real P_cgs = m2c::P(lprobparm->P_mean); + + amrex::ParallelFor( + ldata_p->state, [state_ma, P_cgs, eosparm = leosparm] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + auto eos = pele::physic::PhysicsType::eos(eosparm); + Array4 rho(state_ma[box_no], DENSITY); + Array4 rhoY(state_ma[box_no], FIRSTSPEC); + Array4 rhoH(state_ma[box_no], RHOH); + Array4 temp(state_ma[box_no], TEMP); + Real massfrac[NUM_SPECIES] = {0.0}; + Real sumYs = 0.0; + for (int n = 0; n < NUM_SPECIES; ++n) { + massfrac[n] = rhoY(i, j, k, n); #ifdef N2_ID - if (n != N2_ID) { - sumYs += massfrac[n]; - } -#endif + if (n != N2_ID) { + sumYs += massfrac[n]; } +#endif + } #ifdef N2_ID - massfrac[N2_ID] = 1.0 - sumYs; + massfrac[N2_ID] = 1.0 - sumYs; #endif + // Get density + Real rho_cgs = 0.0; + eos.PYT2R(P_cgs, massfrac, temp_arr(i, j, k), rho_cgs); + rho(i, j, k) = c2m::Rho(rho_cgs); - // Get density - Real P_cgs = lprobparm->P_mean * 10.0; - Real rho_cgs = 0.0; - eos.PYT2R(P_cgs, massfrac, temp_arr(i, j, k), rho_cgs); - rho_arr(i, j, k) = rho_cgs * 1.0e3; - - // Get enthalpy - Real h_cgs = 0.0; - eos.TY2H(temp_arr(i, j, k), massfrac, h_cgs); - rhoH_arr(i, j, k) = h_cgs * 1.0e-4 * rho_arr(i, j, k); - - // Fill rhoYs - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY_arr(i, j, k, n) = massfrac[n] * rho_arr(i, j, k); - } - }); - } + // Get enthalpy + Real h_cgs = 0.0; + eos.TY2H(temp_arr(i, j, k), massfrac, h_cgs); + rhoH(i, j, k) = c2m::H(h_cgs) * rho_arr(i, j, k); + // Fill rhoYs + for (int n = 0; n < NUM_SPECIES; ++n) { + rhoY(i, j, k, n) = massfrac[n] * rho_arr(i, j, k); + } + }); + Gpu::streamSynchronize(); // Initialize thermodynamic pressure setThermoPress(a_lev, AmrNewTime); if (m_has_divu != 0) { diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 7c2d10539..3fd2ee890 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -25,23 +25,26 @@ PeleLM::initialProjection() // Get sigma : density if not incompressible Vector> sigma; if (m_incompressible == 0) { - sigma.reserve(finest_level+1); + sigma.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - sigma.emplace_back(std::make_unique( - grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev])); + sigma.emplace_back( + std::make_unique( + grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev])); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); auto state_ma = ldata_p->const_arrays(); auto sigma_ma = sigma[lev]->arrays(); - amrex::ParallelFor(ldata_p,[state_ma,sigma_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 rho(state_ma[box_no],DENSITY); - sigma_ma[box_no](i,j,k) = dummy_dt/rho(i,j,k); - }); + amrex::ParallelFor( + ldata_p, [state_ma, sigma_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + Array4 rho(state_ma[box_no], DENSITY); + sigma_ma[box_no](i, j, k) = dummy_dt / rho(i, j, k); + }); Gpu::streamSynchronize(); #if AMREX_SPACEDIM == 2 if (geom[lev].IsRZ()) { - scaleProj_RZ(lev, *sigma[lev]); + scaleProj_RZ(lev, *sigma[lev]); } #endif } @@ -49,49 +52,52 @@ PeleLM::initialProjection() // Get velocity Vector> vel; - vel.reserve(finest_level+1); + vel.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - vel.emplace_back(std::make_unique(m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); + vel.emplace_back( + std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); vel[lev]->setBndry(0.0); setInflowBoundaryVel(*vel[lev], lev, AmrNewTime); #if AMREX_SPACEDIM == 2 if (geom[lev].IsRZ()) { scaleProj_RZ(lev, *vel[lev]) - }; + }; #endif - } - + // Get RHS cc: - divU (- \int{divU}) Real Sbar = 0.0; - Vector rhs_cc; + Vector rhs_cc; if ((m_incompressible == 0) && (m_has_divu != 0)) { // Ensure integral of RHS is zero for closed chamber if (m_closed_chamber != 0) { Sbar = MFSum(GetVecOfConstPtrs(getDivUVect(AmrNewTime)), 0); Sbar /= m_uncoveredVol; // Transform in Mean. } - rhs_cc.reserve(finest_level+1); + rhs_cc.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - rhs_cc.emplace_back(grids[lev], dmap[lev], 1, m_leveldata_new[lev]->divu.nGrow()); - MultiFab::Copy(rhs_cc[lev], m_leveldata_new[lev]->divu, 0, 0, 1, - m_leveldata_new[lev]->divu.nGrow()); + rhs_cc.emplace_back( + grids[lev], dmap[lev], 1, m_leveldata_new[lev]->divu.nGrow()); + MultiFab::Copy( + rhs_cc[lev], m_leveldata_new[lev]->divu, 0, 0, 1, + m_leveldata_new[lev]->divu.nGrow()); if (m_closed_chamber != 0) { rhs_cc[lev].plus(-Sbar, 0, 1); } #if AMREX_SPACEDIM == 2 if (geom[lev].IsRZ()) { - scaleProj_RZ(lev, rhs_cc[lev]); + scaleProj_RZ(lev, rhs_cc[lev]); } #endif rhs_cc[lev].mult(-1.0, 0, 1, rhs_cc[lev].nGrow()); } } - + doNodalProject( - GetVecOfPtrs(vel), GetVecOfPtrs(sigma), GetVecOfPtrs(rhs_cc), {}, - incremental, dummy_dt); - + GetVecOfPtrs(vel), GetVecOfPtrs(sigma), GetVecOfPtrs(rhs_cc), {}, + incremental, dummy_dt); + // Set back press and gpress to zero and restore divu // and rescale velocity if 2D-RZ for (int lev = 0; lev <= finest_level; lev++) { @@ -118,13 +124,14 @@ PeleLM::initialProjection() if (Geom(0).IsRZ()) { averageDownVelocity(AmrNewTime); } - + if (m_verbose != 0) { - Vector velMax = MLNorm0(GetVecOfConstPtrs(getVelocityVect(AmrNewTime)), 0, AMREX_SPACEDIM); + Vector velMax = MLNorm0( + GetVecOfConstPtrs(getVelocityVect(AmrNewTime)), 0, AMREX_SPACEDIM); amrex::Print() << " >> After initial velocity projection: "; amrex::Print() << AMREX_D_TERM( - " U: " << velMax[0] <<, " V: " << velMax[1] <<, - " W: " << velMax[2] <<) "\n"; + " U: " << velMax[0] <<, " V: " << velMax[1] <<, + " W: " << velMax[2] <<) "\n"; } } @@ -144,22 +151,26 @@ PeleLM::initialPressProjection() // Get sigma : density if not incompressible Vector> sigma; if (m_incompressible == 0) { - sigma.reserve(finest_level+1); + sigma.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - sigma.emplace_back(std::make_unique(grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev])); + sigma.emplace_back( + std::make_unique( + grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev])); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); auto state_ma = ldata_p->state.const_arrays(); auto sigma_ma = sigma[lev]->arrays(); - amrex::ParallelFor(ldata_p->state, [state_ma, sigma_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 rho(state_ma[box_no],DENSITY); - sigma_ma[box_no](i,j,k) = dummy_dt/rho(i,j,k); - }); + amrex::ParallelFor( + ldata_p->state, [state_ma, sigma_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + Array4 rho(state_ma[box_no], DENSITY); + sigma_ma[box_no](i, j, k) = dummy_dt / rho(i, j, k); + }); Gpu::streamSynchronize(); #if AMREX_SPACEDIM == 2 if (geom[lev].IsRZ()) { - scaleProj_RZ(lev, *sigma[lev]); + scaleProj_RZ(lev, *sigma[lev]); } #endif } @@ -167,7 +178,7 @@ PeleLM::initialPressProjection() // Set the velocity to the gravity field Vector vel; - vel.reserve(finest_level+1); + vel.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { vel.emplace_back( grids[lev], dmap[lev], AMREX_SPACEDIM, nGhost, MFInfo(), *m_factory[lev]); @@ -177,9 +188,9 @@ PeleLM::initialPressProjection() vel[lev].setBndry(0.0); setInflowBoundaryVel(vel[lev], lev, AmrNewTime); #if AMREX_SPACEDIM == 2 - if (geom[lev].IsRZ()) { - scaleProj_RZ(lev, vel[lev]); - } + if (geom[lev].IsRZ()) { + scaleProj_RZ(lev, vel[lev]); + } #endif } @@ -203,22 +214,26 @@ PeleLM::velocityProjection( Vector> rhoHalf = getDensityVect(a_rhoTime); sigma.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - - sigma.emplace_back(std::make_unique(grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev])); + + sigma.emplace_back( + std::make_unique( + grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev])); auto rhoHalf_ma = rhoHalf[lev]->const_arrays(); auto sigma_ma = sigma[lev]->arrays(); - amrex::ParallelFor(*rhoHalf[lev], [rhoHalf_ma,sig_ma, dt = a_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - sigma_ma[box_no](i,j,k) = dt/rhoHalf_ma[box_no](i,j,k); - }); + amrex::ParallelFor( + *rhoHalf[lev], [rhoHalf_ma, sig_ma, dt = a_dt] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + sigma_ma[box_no](i, j, k) = dt / rhoHalf_ma[box_no](i, j, k); + }); #ifdef AMREX_USE_EB EB_set_covered(*sigma[lev], 0.0); #endif #if AMREX_SPACEDIM == 2 if (geom[lev].IsRZ()) { - scaleProj_RZ(lev, *sigma[lev]); + scaleProj_RZ(lev, *sigma[lev]); } #endif } @@ -238,22 +253,28 @@ PeleLM::velocityProjection( auto state_old_ma = ldataOld_p->arrays(); auto gp_new_ma = ldataNew_p->const_arrays(); if (m_incompressible == 0) { - auto rho_ma = rhoHalf[lev]->const_arrays(); - amrex::ParallelFor(ldataNew_p->state, [state_old_ma,gp_new_ma, rho_ma, dt=a_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 vel(state_old_ma[box_no],VELX); - const Real soverrho = dt/rho_ma[box_no](i,j,k); - for (int n = 0; n < NUM_SPECIES; ++n) { - vel(i,j,k,n) += gp_new_ma[box_no](i,j,k,n)*soverrho; - } - }); + auto rho_ma = rhoHalf[lev]->const_arrays(); + amrex::ParallelFor( + ldataNew_p->state, + [state_old_ma, gp_new_ma, rho_ma, dt = a_dt] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + Array4 vel(state_old_ma[box_no], VELX); + const Real soverrho = dt / rho_ma[box_no](i, j, k); + for (int n = 0; n < NUM_SPECIES; ++n) { + vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; + } + }); } else { - amrex::ParallelFor(ldataNew_p->state, [state_old_ma,gp_new_ma, rho = m_rho, dt=a_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - Array4 vel(state_old_ma[box_no],VELX); - const Real soverrho = dt/rho; - for (int n = 0; n < NUM_SPECIES; ++n) { - vel(i,j,k,n) += gp_new_ma[box_no](i,j,k,n)*soverrho; - } - }); + amrex::ParallelFor( + ldataNew_p->state, + [state_old_ma, gp_new_ma, rho = m_rho, dt = a_dt] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + Array4 vel(state_old_ma[box_no], VELX); + const Real soverrho = dt / rho; + for (int n = 0; n < NUM_SPECIES; ++n) { + vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; + } + }); } } Gpu::streamSynchronize(); @@ -272,7 +293,7 @@ PeleLM::velocityProjection( // Get velocity Vector> vel; - vel.reserve(finest_level+1); + vel.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { vel.emplace_back( std::make_unique( @@ -314,7 +335,7 @@ PeleLM::velocityProjection( grids[lev], dmap[lev], 1, ldata_p->divu.nGrow(), MFInfo(), *m_factory[lev]); MultiFab::Copy( - rhs_cc[lev], ldata_p->divu, 0, 0, 1, ldata_p->divu.nGrow()); + rhs_cc[lev], ldata_p->divu, 0, 0, 1, ldata_p->divu.nGrow()); if (m_closed_chamber != 0) { rhs_cc[lev].plus(-SbarNew, 0, 1); } @@ -351,7 +372,7 @@ PeleLM::velocityProjection( #endif #if AMREX_SPACEDIM == 2 if (geom[lev].IsRZ()) { - scaleProj_RZ(lev, rhs_cc[lev]); + scaleProj_RZ(lev, rhs_cc[lev]); } #endif } @@ -362,25 +383,26 @@ PeleLM::velocityProjection( incremental, a_dt); #if AMREX_SPACEDIM == 2 - for (int lev = 0; lev <=finest_level; ++lev) { + for (int lev = 0; lev <= finest_level; ++lev) { // Unscaling New vel before adding back old one if (geom[lev].IsRZ()) { unscaleProj_RZ(lev, *vel[lev]); } } #endif - + // If incremental // define back to be U^{np1} by adding U^{n} if (incremental != 0) { for (int lev = 0; lev <= finest_level; ++lev) { auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - MultiFab::Add(ldataNew_p->state, ldataOld_p->state, VELX, VELX, AMREX_SPACEDIM, 0); + MultiFab::Add( + ldataNew_p->state, ldataOld_p->state, VELX, VELX, AMREX_SPACEDIM, 0); } } - -#ifdef AMREX_SPACEDIM == 2 + +#ifdef AMREX_SPACEDIM == 2 // In R-Z, AMReX-Hydro do an average down of r*vel. // Now that we have unscaled vel, need to do average down again // to have consistent vel across levels @@ -547,19 +569,20 @@ PeleLM::scaleProj_RZ( // NOLINT(readability-convert-member-functions-to-static) const Real dr = geom[a_lev].CellSize()[0]; auto const& mf_ma = a_mf.arrays(); amrex::ParallelFor( - a_mf, a_mf.nGrowVect(), - [mf_ma,dr,domain,ncomp = a_mf.nComp()] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - auto mf = mf_ma[box_no]; - if (domain.contains(i, j, k)) { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) *= (static_cast(i) + 0.5) * dr; - } - } else { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) = 0.0; - } - } - }); + a_mf, a_mf.nGrowVect(), + [mf_ma, dr, domain, ncomp = a_mf.nComp()] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + auto mf = mf_ma[box_no]; + if (domain.contains(i, j, k)) { + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) *= (static_cast(i) + 0.5) * dr; + } + } else { + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) = 0.0; + } + } + }); Gpu::streamSynchronize(); } @@ -574,20 +597,20 @@ PeleLM:: const Real dr = geom[a_lev].CellSize()[0]; auto const& mf_ma = a_mf.arrays(); amrex::ParallelFor( - a_mf, a_mf.nGrowVect(), - [mf_ma, dr, domain, ncomp = a_mf.nComp()] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - auto mf = mf_ma[box_no]; - if (domain.contains(i, j, k)) { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) /= (static_cast(i) + 0.5) * dr; - } - } else { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) = 0.0; - } - } - }); + a_mf, a_mf.nGrowVect(), + [mf_ma, dr, domain, ncomp = a_mf.nComp()] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + auto mf = mf_ma[box_no]; + if (domain.contains(i, j, k)) { + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) /= (static_cast(i) + 0.5) * dr; + } + } else { + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) = 0.0; + } + } + }); Gpu::streamSynchronize(); } #endif diff --git a/Source/PeleLMeX_Regrid.cpp b/Source/PeleLMeX_Regrid.cpp index 0aa9d8f59..cb0ed12ec 100644 --- a/Source/PeleLMeX_Regrid.cpp +++ b/Source/PeleLMeX_Regrid.cpp @@ -325,7 +325,7 @@ PeleLM::MakeNewLevelFromCoarse( << "% of the domain \n"; } if (m_verbose > 3) { - amrex::Print() << " with BoxArray " << ba << std::endl; + amrex::Print() << " with BoxArray " << ba << "\n"; } } @@ -439,7 +439,7 @@ PeleLM::RemakeLevel( << "% of the domain \n"; } if (m_verbose > 3) { - amrex::Print() << " with BoxArray " << ba << std::endl; + amrex::Print() << " with BoxArray " << ba << "\n"; } } diff --git a/Source/PeleLMeX_Setup.cpp b/Source/PeleLMeX_Setup.cpp index 6870da54f..1d7cac713 100644 --- a/Source/PeleLMeX_Setup.cpp +++ b/Source/PeleLMeX_Setup.cpp @@ -103,34 +103,31 @@ PeleLM::Setup() amrex::Print() << " Using LES in transport with Sc = " << 1.0 / m_Schmidt_inv; if (pele::physics::PhysicsType::eos_type::identifier() == "Manifold") { - amrex::Print() << ", enthalpy not diffused for Manifold EOS " - << std::endl; + amrex::Print() << ", enthalpy not diffused for Manifold EOS \n"; } else { - amrex::Print() << " and Pr = " << 1.0 / m_Prandtl_inv << std::endl; + amrex::Print() << " and Pr = " << 1.0 / m_Prandtl_inv << "\n"; } } else if (m_verbose != 0) { if (m_fixed_Le == 0 && m_fixed_Pr == 0) { if (m_use_soret == 0) { - amrex::Print() << " Using mixture-averaged transport" << std::endl; + amrex::Print() << " Using mixture-averaged transport \n"; } else { amrex::Print() - << " Using mixture-averaged transport with Soret effects" - << std::endl; + << " Using mixture-averaged transport with Soret effects \n"; if (m_soret_boundary_override != 0) { - amrex::Print() - << " Imposing inhomogeneous Neumann conditions " - "for species on isothermal walls. WARNING: use_wbar disabled." - << std::endl; + amrex::Print() << " Imposing inhomogeneous Neumann conditions " + "for species on isothermal walls. WARNING: " + "use_wbar disabled. \n"; } } } else { if (m_fixed_Le != 0) { amrex::Print() << " Using fixed Le = " << 1.0 / m_Lewis_inv - << std::endl; + << "\n"; } if (m_fixed_Pr != 0) { amrex::Print() << " Using fixed Pr = " << 1.0 / m_Prandtl_inv - << std::endl; + << "\n"; } } } @@ -382,21 +379,19 @@ PeleLM::readParameters() pps.get("radius", m_spark_radius[n]); } if (m_spark_verbose > 0) { - Print() << "Spark list:" << std::endl; + Print() << "Spark list: \n"; + ; for (int n = 0; n < m_n_sparks; n++) { - Print() << "Spark " << n << " name: " << m_spark[n] << std::endl; - Print() << "Spark " << n << " time: " << m_spark_time[n] << std::endl; + Print() << "Spark " << n << " name: " << m_spark[n] << "\n"; + Print() << "Spark " << n << " time: " << m_spark_time[n] << "\n"; Print() << "Spark " << n << " duration: " << m_spark_duration[n] - << std::endl; - Print() << "Spark " << n << " location: "; - for (int d = 0; d < AMREX_SPACEDIM; d++) { + << "\n" Print() << "Spark " << n << " location: "; + for (int d = 0; d < AMREX_SPACEDIM; ++d) { Print() << m_spark_location[n][d] << " "; } - Print() << std::endl; - Print() << "Spark " << n << " temperature: " << m_spark_temp[n] - << std::endl; - Print() << "Spark " << n << " radius: " << m_spark_radius[n] - << std::endl; + Print() << "\n"; + Print() << "Spark " << n << " temperature: " << m_spark_temp[n] << "\n"; + Print() << "Spark " << n << " radius: " << m_spark_radius[n] << "\n"; } } } @@ -485,8 +480,7 @@ PeleLM::readParameters() if (m_unity_Le != 0) { m_fixed_Le = 1; amrex::Print() << "WARNING: unity_Le is deprecated and will be removed in " - "future version, use fixed_Le instead" - << std::endl; + "future version, use fixed_Le instead \n"; } if (m_do_les) { // For LES, Prandtl and Schmidt numbers are fixed m_fixed_Le = 1; @@ -522,8 +516,7 @@ PeleLM::readParameters() m_use_wbar = 0; m_use_soret = 0; amrex::Print() << "WARNING: use_wbar and use_soret set to false because " - "fixed_Pr or fixed_Le is true" - << std::endl; + "fixed_Pr or fixed_Le is true \n"; } // Manifold EOS: invPrandtl needs to be 0 because H not used diff --git a/Source/PeleLMeX_SprayParticles.cpp b/Source/PeleLMeX_SprayParticles.cpp index 76c73a74a..539b63588 100644 --- a/Source/PeleLMeX_SprayParticles.cpp +++ b/Source/PeleLMeX_SprayParticles.cpp @@ -173,7 +173,7 @@ PeleLM::SprayInit() SprayInjectRedist(); if (spray_verbose >= 1) { Print() << "Total number of initial particles " - << SprayPC->TotalNumberOfParticles(false, false) << std::endl; + << SprayPC->TotalNumberOfParticles(false, false) << "\n"; } } @@ -278,7 +278,7 @@ PeleLM::SprayMKD(const Real time, const Real dt) setupVirtualParticles(0); for (int lev = 0; lev <= finest_level; ++lev) { if (spray_verbose > 1) { - Print() << "SprayMKDLevel " << lev << std::endl; + Print() << "SprayMKDLevel " << lev << "\n"; } m_spraysource[lev]->setVal(0.); SprayMKDLevel(lev, time, dt); @@ -390,7 +390,7 @@ PeleLM::SprayInjectRedist() Long new_count = SprayPC->TotalNumberOfParticles(true, false); Long num_inj = new_count - prev_count; Print() << "Injected " << num_inj << " particles at time " << m_t_new[0] - << std::endl; + << "\n"; } } diff --git a/Source/PeleLMeX_Temporals.cpp b/Source/PeleLMeX_Temporals.cpp index b407c7333..a2ceb3518 100644 --- a/Source/PeleLMeX_Temporals.cpp +++ b/Source/PeleLMeX_Temporals.cpp @@ -534,8 +534,7 @@ PeleLM::initBPatches(Geometry& a_geom) pp.get("patchnames", bpatch_name[n], n); m_bPatches[n] = std::make_unique(bpatch_name[n], a_geom); if (m_verbose > 0) { - Print() << " Initializing boundary patch: " << bpatch_name[n] - << std::endl; + Print() << " Initializing boundary patch: " << bpatch_name[n] << "\n"; } } } diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index b58519d42..48800fd2e 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -18,8 +18,7 @@ PeleLM::calcTurbViscosity(const TimeStamp& a_time) if (m_les_verbose > 0) { amrex::Print() << " Computing Turbulent Viscosity with LES model: " - << m_les_model << " for time " << getTime(0, a_time) - << std::endl; + << m_les_model << " for time " << getTime(0, a_time) << "\n"; } // Create temporary multifab to store velocity gradient tensor diff --git a/Source/PeleLMeX_UMac.cpp b/Source/PeleLMeX_UMac.cpp index 914933602..ca5ab3821 100644 --- a/Source/PeleLMeX_UMac.cpp +++ b/Source/PeleLMeX_UMac.cpp @@ -157,7 +157,7 @@ PeleLM::addChiIncrement( amrex::Real max_corr = MLNorm0(GetVecOfConstPtrs(chiIncr)) * m_dt / m_dpdtFactor; amrex::Print() << " Before SDC " << a_sdcIter - << ": max relative P mismatch is " << max_corr << std::endl; + << ": max relative P mismatch is " << max_corr << "\n"; } } From 366a2271184dfb965986cfec8abf86d5642f03e6 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 13 Jul 2025 10:34:41 +0100 Subject: [PATCH 25/87] endl --- Source/PeleLMeX_EB.cpp | 3 +-- Source/PeleLMeX_Eos.cpp | 2 +- Source/PeleLMeX_Evolve.cpp | 4 +--- Source/PeleLMeX_Forces.cpp | 4 ++-- Source/PeleLMeX_Init.cpp | 5 ++-- Source/PeleLMeX_Plot.cpp | 2 +- Source/PeleLMeX_Regrid.cpp | 4 ++-- Source/PeleLMeX_Setup.cpp | 38 +++++++++++++----------------- Source/PeleLMeX_SprayParticles.cpp | 6 ++--- Source/PeleLMeX_Temporals.cpp | 2 +- Source/PeleLMeX_TransportProp.cpp | 2 +- Source/PeleLMeX_UMac.cpp | 2 +- 12 files changed, 32 insertions(+), 42 deletions(-) diff --git a/Source/PeleLMeX_EB.cpp b/Source/PeleLMeX_EB.cpp index ace760822..084d288a5 100644 --- a/Source/PeleLMeX_EB.cpp +++ b/Source/PeleLMeX_EB.cpp @@ -798,8 +798,7 @@ PeleLM::checkEBInflowFunctions() if (m_verbose != 0 && m_useEBinflow != 0) { Print() << "WARNING: EB-inflow capability is experimental. Scalar " "diffusion is not supported at these boundaries and future " - "interface changes are possible!" - << std::endl; + "interface changes are possible! \n"; } } #endif diff --git a/Source/PeleLMeX_Eos.cpp b/Source/PeleLMeX_Eos.cpp index 18d43c876..982ee3bb1 100644 --- a/Source/PeleLMeX_Eos.cpp +++ b/Source/PeleLMeX_Eos.cpp @@ -352,7 +352,7 @@ PeleLM::adjustPandDivU(std::unique_ptr& advData) Print() << " >> Closed chamber pOld: " << m_pOld << ", pNew: " << m_pNew << ", dp0dt: " << m_dp0dt << "\n"; Print() << " >> Total mass old: " << m_massOld - << ", mass new: " << m_massNew << std::endl; + << ", mass new: " << m_massNew << "\n"; } // Return Sbar so that we'll add it back to mac_divu after the MAC projection diff --git a/Source/PeleLMeX_Evolve.cpp b/Source/PeleLMeX_Evolve.cpp index 0712c416a..15b7d485d 100644 --- a/Source/PeleLMeX_Evolve.cpp +++ b/Source/PeleLMeX_Evolve.cpp @@ -95,9 +95,7 @@ PeleLM::Evolve() if (t_elapsed >= (m_max_wall_time * 3600)) { over_max_wall_time = true; if (m_verbose > 0) { - amrex::Print() << std::endl - << "Reached maximum allowed wall time, stopping ..." - << std::endl; + amrex::Print() << "\n Reached maximum allowed wall time, stopping ... \n"; } } } diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 3d7f41798..8356c5e14 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -184,7 +184,7 @@ PeleLM::addSpark(const TimeStamp& a_timestamp) time < m_spark_time[n] || time > m_spark_time[n] + m_spark_duration[n]) { if (verb) { - Print() << m_spark[n] << " not active" << std::endl; + Print() << m_spark[n] << " not active \n"; } continue; } @@ -201,7 +201,7 @@ PeleLM::addSpark(const TimeStamp& a_timestamp) continue; } if (verb) { - Print() << m_spark[n] << " active" << std::endl; + Print() << m_spark[n] << " active \n"; } auto statema = getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); diff --git a/Source/PeleLMeX_Init.cpp b/Source/PeleLMeX_Init.cpp index 0fd0039ee..50ae66dbb 100644 --- a/Source/PeleLMeX_Init.cpp +++ b/Source/PeleLMeX_Init.cpp @@ -32,8 +32,7 @@ PeleLM::MakeNewLevelFromScratch( BL_PROFILE("PeleLMeX::MakeNewLevelFromScratch()"); if (m_verbose > 0) { - amrex::Print() << " Making new level " << lev << " from scratch" - << std::endl; + amrex::Print() << " Making new level " << lev << " from scratch \n"; if (m_verbose > 2 && lev > 0) { auto const dx = geom[lev].CellSizeArray(); Real vol = AMREX_D_TERM(dx[0], *dx[1], *dx[2]); @@ -45,7 +44,7 @@ PeleLM::MakeNewLevelFromScratch( << "% of the domain \n"; } if (m_verbose > 3 && lev > 0) { - amrex::Print() << " with BoxArray " << ba << std::endl; + amrex::Print() << " with BoxArray " << ba << "\n"; } } diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 2cc177da1..69dcc992d 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -855,7 +855,7 @@ PeleLM::ReadCheckPointFile() } } if (m_verbose != 0) { - amrex::Print() << "Restart complete" << std::endl; + amrex::Print() << "Restart complete \n"; } } diff --git a/Source/PeleLMeX_Regrid.cpp b/Source/PeleLMeX_Regrid.cpp index 0aa9d8f59..cb0ed12ec 100644 --- a/Source/PeleLMeX_Regrid.cpp +++ b/Source/PeleLMeX_Regrid.cpp @@ -325,7 +325,7 @@ PeleLM::MakeNewLevelFromCoarse( << "% of the domain \n"; } if (m_verbose > 3) { - amrex::Print() << " with BoxArray " << ba << std::endl; + amrex::Print() << " with BoxArray " << ba << "\n"; } } @@ -439,7 +439,7 @@ PeleLM::RemakeLevel( << "% of the domain \n"; } if (m_verbose > 3) { - amrex::Print() << " with BoxArray " << ba << std::endl; + amrex::Print() << " with BoxArray " << ba << "\n"; } } diff --git a/Source/PeleLMeX_Setup.cpp b/Source/PeleLMeX_Setup.cpp index cd9e76c2e..10a55854a 100644 --- a/Source/PeleLMeX_Setup.cpp +++ b/Source/PeleLMeX_Setup.cpp @@ -103,34 +103,31 @@ PeleLM::Setup() amrex::Print() << " Using LES in transport with Sc = " << 1.0 / m_Schmidt_inv; if (pele::physics::PhysicsType::eos_type::identifier() == "Manifold") { - amrex::Print() << ", enthalpy not diffused for Manifold EOS " - << std::endl; + amrex::Print() << ", enthalpy not diffused for Manifold EOS \n"; } else { - amrex::Print() << " and Pr = " << 1.0 / m_Prandtl_inv << std::endl; + amrex::Print() << " and Pr = " << 1.0 / m_Prandtl_inv << "\n"; } } else if (m_verbose != 0) { if (m_fixed_Le == 0 && m_fixed_Pr == 0) { if (m_use_soret == 0) { - amrex::Print() << " Using mixture-averaged transport" << std::endl; + amrex::Print() << " Using mixture-averaged transport \n"; } else { amrex::Print() - << " Using mixture-averaged transport with Soret effects" - << std::endl; + << " Using mixture-averaged transport with Soret effects \n"; if (m_soret_boundary_override != 0) { amrex::Print() << " Imposing inhomogeneous Neumann conditions " - "for species on isothermal walls. WARNING: use_wbar disabled." - << std::endl; + "for species on isothermal walls. WARNING: use_wbar disabled. \n" } } } else { if (m_fixed_Le != 0) { amrex::Print() << " Using fixed Le = " << 1.0 / m_Lewis_inv - << std::endl; + << "\n"; } if (m_fixed_Pr != 0) { amrex::Print() << " Using fixed Pr = " << 1.0 / m_Prandtl_inv - << std::endl; + << "\n"; } } } @@ -382,21 +379,20 @@ PeleLM::readParameters() pps.get("radius", m_spark_radius[n]); } if (m_spark_verbose > 0) { - Print() << "Spark list:" << std::endl; + Print() << "Spark list: \n"; for (int n = 0; n < m_n_sparks; n++) { - Print() << "Spark " << n << " name: " << m_spark[n] << std::endl; - Print() << "Spark " << n << " time: " << m_spark_time[n] << std::endl; + Print() << "Spark " << n << " name: " << m_spark[n] << "\n"; + Print() << "Spark " << n << " time: " << m_spark_time[n] << "\n"; Print() << "Spark " << n << " duration: " << m_spark_duration[n] - << std::endl; + << "\n"; Print() << "Spark " << n << " location: "; for (int d = 0; d < AMREX_SPACEDIM; d++) { Print() << m_spark_location[n][d] << " "; } - Print() << std::endl; - Print() << "Spark " << n << " temperature: " << m_spark_temp[n] - << std::endl; + Print() << "\n Spark " << n << " temperature: " << m_spark_temp[n] + << "\n"; Print() << "Spark " << n << " radius: " << m_spark_radius[n] - << std::endl; + << "\n"; } } } @@ -485,8 +481,7 @@ PeleLM::readParameters() if (m_unity_Le != 0) { m_fixed_Le = 1; amrex::Print() << "WARNING: unity_Le is deprecated and will be removed in " - "future version, use fixed_Le instead" - << std::endl; + "future version, use fixed_Le instead \n" } if (m_do_les) { // For LES, Prandtl and Schmidt numbers are fixed m_fixed_Le = 1; @@ -522,8 +517,7 @@ PeleLM::readParameters() m_use_wbar = 0; m_use_soret = 0; amrex::Print() << "WARNING: use_wbar and use_soret set to false because " - "fixed_Pr or fixed_Le is true" - << std::endl; + "fixed_Pr or fixed_Le is true \n"; } // Manifold EOS: invPrandtl needs to be 0 because H not used diff --git a/Source/PeleLMeX_SprayParticles.cpp b/Source/PeleLMeX_SprayParticles.cpp index 76c73a74a..539b63588 100644 --- a/Source/PeleLMeX_SprayParticles.cpp +++ b/Source/PeleLMeX_SprayParticles.cpp @@ -173,7 +173,7 @@ PeleLM::SprayInit() SprayInjectRedist(); if (spray_verbose >= 1) { Print() << "Total number of initial particles " - << SprayPC->TotalNumberOfParticles(false, false) << std::endl; + << SprayPC->TotalNumberOfParticles(false, false) << "\n"; } } @@ -278,7 +278,7 @@ PeleLM::SprayMKD(const Real time, const Real dt) setupVirtualParticles(0); for (int lev = 0; lev <= finest_level; ++lev) { if (spray_verbose > 1) { - Print() << "SprayMKDLevel " << lev << std::endl; + Print() << "SprayMKDLevel " << lev << "\n"; } m_spraysource[lev]->setVal(0.); SprayMKDLevel(lev, time, dt); @@ -390,7 +390,7 @@ PeleLM::SprayInjectRedist() Long new_count = SprayPC->TotalNumberOfParticles(true, false); Long num_inj = new_count - prev_count; Print() << "Injected " << num_inj << " particles at time " << m_t_new[0] - << std::endl; + << "\n"; } } diff --git a/Source/PeleLMeX_Temporals.cpp b/Source/PeleLMeX_Temporals.cpp index b407c7333..bf3e83c2a 100644 --- a/Source/PeleLMeX_Temporals.cpp +++ b/Source/PeleLMeX_Temporals.cpp @@ -535,7 +535,7 @@ PeleLM::initBPatches(Geometry& a_geom) m_bPatches[n] = std::make_unique(bpatch_name[n], a_geom); if (m_verbose > 0) { Print() << " Initializing boundary patch: " << bpatch_name[n] - << std::endl; + << "\n"; } } } diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index b58519d42..266ab36c6 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -19,7 +19,7 @@ PeleLM::calcTurbViscosity(const TimeStamp& a_time) if (m_les_verbose > 0) { amrex::Print() << " Computing Turbulent Viscosity with LES model: " << m_les_model << " for time " << getTime(0, a_time) - << std::endl; + << "\n"; } // Create temporary multifab to store velocity gradient tensor diff --git a/Source/PeleLMeX_UMac.cpp b/Source/PeleLMeX_UMac.cpp index 914933602..ca5ab3821 100644 --- a/Source/PeleLMeX_UMac.cpp +++ b/Source/PeleLMeX_UMac.cpp @@ -157,7 +157,7 @@ PeleLM::addChiIncrement( amrex::Real max_corr = MLNorm0(GetVecOfConstPtrs(chiIncr)) * m_dt / m_dpdtFactor; amrex::Print() << " Before SDC " << a_sdcIter - << ": max relative P mismatch is " << max_corr << std::endl; + << ": max relative P mismatch is " << max_corr << "\n"; } } From 7098811630f7413cc15efcca709bcdfcc1b8fd3a Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 13 Jul 2025 10:52:10 +0100 Subject: [PATCH 26/87] header fixes --- Source/PeleLMeX.H | 491 +++++++++++++++++++++++----------------------- 1 file changed, 243 insertions(+), 248 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index d3a0ce97c..c406e3fc9 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -84,27 +84,26 @@ public: void regrid(int lbase, amrex::Real time, bool initial = false) override; void MakeNewLevelFromScratch( - int lev, + const int lev, amrex::Real time, const amrex::BoxArray& ba, const amrex::DistributionMapping& dm) override; - void ErrorEst( - int lev, amrex::TagBoxArray& tags, amrex::Real time, int ng) override; + void ErrorEst(const int lev, amrex::TagBoxArray& tags, amrex::Real time, const int ng) override; void MakeNewLevelFromCoarse( - int lev, - amrex::Real time, - const amrex::BoxArray& ba, - const amrex::DistributionMapping& dm) override; + const int lev, + const amrex::Real time, + const amrex::BoxArray& ba, + const amrex::DistributionMapping& dm) override; void RemakeLevel( - int lev, - amrex::Real time, + const int lev, + const amrex::Real time, const amrex::BoxArray& ba, const amrex::DistributionMapping& dm) override; - void ClearLevel(int lev) override; + void ClearLevel(const int lev) override; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -165,12 +164,12 @@ public: amrex::BoxArray const& ba, amrex::DistributionMapping const& dm, amrex::FabFactory const& factory, - int a_incompressible, - int a_has_divu, - int a_nAux, - int a_nGrowState, - int a_use_soret, - int a_do_les); + const int a_incompressible, + const int a_has_divu, + const int a_nAux, + const int a_nGrowState, + const int a_use_soret, + const int a_do_les); // cell-centered state multifabs amrex::MultiFab @@ -224,16 +223,16 @@ public: { AdvanceDiffData() = default; AdvanceDiffData( - int a_finestLevel, + const int a_finestLevel, const amrex::Vector& ba, const amrex::Vector& dm, const amrex::Vector>>& factory, - int a_nGrowAdv, - int a_use_wbar, - int a_use_soret, - int a_nAux, - int is_init = 0); + const int a_nGrowAdv, + const int a_use_wbar, + const int a_use_soret, + const int a_nAux, + const int is_init = 0); amrex::Vector Dn; // Diffusion term t^n amrex::Vector Dnp1; // Diffusion term t^(n+1,k) amrex::Vector Dhat; // Diffusion term t^(n+1,k+1) @@ -258,15 +257,15 @@ public: { AdvanceAdvData() = default; AdvanceAdvData( - int a_finestLevel, + const int a_finestLevel, const amrex::Vector& ba, const amrex::Vector& dm, const amrex::Vector>>& factory, - int a_incompressible, - int a_nAux, - int a_nGrowAdv, - int a_nGrowMAC); + const int a_incompressible, + const int a_nAux, + const int a_nGrowAdv, + const int a_nGrowMAC); amrex::Vector> umac; // MAC face velocity amrex::Vector AofS; // Scalar advection term at t^(n+1/2) @@ -299,14 +298,14 @@ public: * using the user defined init function * \param lev the target level index */ - void initLevelData(int lev); + void initLevelData(const int lev); /** * \brief Fill the initial level data container * using the data from a pltfile * \param a_pltFile path to PeleLMeX plot file */ - void initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile); + void initLevelDataFromPlt(const int a_lev, const std::string& a_dataPltFile); /** * \brief Project the initial solution velocity field, @@ -322,10 +321,10 @@ public: void initialIterations(); // initFromGridFile - void InitFromGridFile(amrex::Real time); + void InitFromGridFile(const amrex::Real time); // regridFromFile - void regridFromGridFile(int lbase, amrex::Real time, bool initial); + void regridFromGridFile(const int lbase, const amrex::Real time, const bool initial); /** * \brief Check the consistency of the run @@ -342,7 +341,7 @@ public: * filling the PeleLM class LayoutData with default method * \param a_lev target level */ - void computeCosts(int a_lev); + void computeCosts(const int a_lev); /** * \brief Compute load balancing cost estimate on a given level @@ -350,8 +349,7 @@ public: * \param a_costs LayoutData holding the cost for each box * \param a_costMethod cost method */ - void computeCosts( - int a_lev, amrex::LayoutData& a_costs, int a_costMethod); + void computeCosts(const int a_lev, amrex::LayoutData& a_costs, int a_costMethod); /** * \brief Create/update the DMap used for chemistry on all levels @@ -362,7 +360,7 @@ public: * \brief Create/update the DMap used for chemistry on a given level * \param a_lev level of interest */ - void loadBalanceChemLev(int a_lev); + void loadBalanceChemLev(const int a_lev); //----------------------------------------------------------------------------- @@ -390,8 +388,7 @@ public: * \param a_rhoTime time used to fill sigma * \param a_dt time time step size */ - void velocityProjection( - int is_init, const PeleLM::TimeStamp& a_rhoTime, const amrex::Real& a_dt); + void velocityProjection(const int is_init, const PeleLM::TimeStamp a_rhoTime, const amrex::Real a_dt); /** * \brief Actual nodal projection call function. @@ -407,23 +404,25 @@ public: const amrex::Vector& a_sigma, const amrex::Vector& rhs_cc, const amrex::Vector& rhs_nd, - int incremental, - amrex::Real scaling_factor); + const int incremental, + const amrex::Real scaling_factor); + #if AMREX_SPACEDIM == 2 /** * \brief For 2D-RZ, scale multifab components by radius * including 1 ghost cell on Dirichlet BC * \param a_lev level index * \param a_mf MultiFab to act upon */ - void scaleProj_RZ(int a_lev, amrex::MultiFab& a_mf); + void scaleProj_RZ(const int a_lev, amrex::MultiFab& a_mf); /** * \brief For 2D-RZ, unscale multifab components by radius * \param a_lev level index * \param a_mf MultiFab to act upon */ - void unscaleProj_RZ(int a_lev, amrex::MultiFab& a_mf); + void unscaleProj_RZ(const int a_lev, amrex::MultiFab& a_mf); +#endif //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -457,8 +456,8 @@ public: * \param advData container for chi and incremented mac_divu */ void addChiIncrement( - int a_sdcIter, - const PeleLM::TimeStamp& a_time, + const int a_sdcIter, + const PeleLM::TimeStamp a_time, std::unique_ptr& advData); /** @@ -469,7 +468,7 @@ public: * \param a_divu velocity divergence constraint (can be empty) */ void macProject( - const PeleLM::TimeStamp& a_time, + const PeleLM::TimeStamp a_time, std::unique_ptr& advData, const amrex::Vector& a_divu); @@ -487,7 +486,7 @@ public: * crse_ratio refinement ratio with the next coarser level */ void create_constrained_umac_grown( - int a_nGrow, + const int a_nGrow, const amrex::Geometry* crse_geom, const amrex::Geometry* fine_geom, amrex::Array u_mac_crse, @@ -511,21 +510,21 @@ public: * filling the specified container of Old or New LevelData * \param a_time either Old or New stamp */ - void calcViscosity(const PeleLM::TimeStamp& a_time); + void calcViscosity(const PeleLM::TimeStamp a_time); /** * \brief Compute the face-centered turbulent viscosity on all levels * filling the specified container of Old or New LevelData * \param a_time either Old or New stamp */ - void calcTurbViscosity(const PeleLM::TimeStamp& a_time); + void calcTurbViscosity(const PeleLM::TimeStamp a_time); /** * \brief Compute the cell-centereds diffusivity on all levels * filling the specified container of Old or New LevelData * \param a_time either Old or New stamp */ - void calcDiffusivity(const PeleLM::TimeStamp& a_time); + void calcDiffusivity(const PeleLM::TimeStamp a_time); // get edge-centered diffusivity on a per level / per comp basis /** @@ -541,14 +540,13 @@ public: * \param a_diff_cc cell-centered data * \param addTurbContrib turbulent contribution increment trigger */ - amrex::Array getDiffusivity( - int lev, - int beta_comp, - int ncomp, - int doZeroVisc, - amrex::Vector bcrec, - const amrex::MultiFab& beta_cc, - int addTurbContrib = 0); + amrex::Array getDiffusivity(const int lev, + const int beta_comp, + const int ncomp, + const int doZeroVisc, + amrex::Vector bcrec, + const amrex::MultiFab& beta_cc, + const int addTurbContrib = 0); /** * \brief Compute the explicit face-centered diffusion fluxes on all levels @@ -561,7 +559,7 @@ public: * container */ void computeDifferentialDiffusionFluxes( - const PeleLM::TimeStamp& a_time, + const PeleLM::TimeStamp a_time, const amrex::Vector>& a_fluxes, const amrex::Vector& a_EBfluxes, @@ -573,11 +571,11 @@ public: a_auxfluxes); void correctIsothermalBoundary( - const TimeStamp& a_time, - const amrex::Vector& a_spec_boundary, - const amrex::Vector>& - a_wbarfluxes, - const amrex::Vector>& + const PeleLM::TimeStamp a_time, + const amrex::Vector& a_spec_boundary, + const amrex::Vector>& + a_wbarfluxes, + const amrex::Vector>& a_soretfluxes); /** @@ -589,9 +587,9 @@ public: * \param is_init initial computation flag */ void computeDifferentialDiffusionTerms( - const PeleLM::TimeStamp& a_time, + const PeleLM::TimeStamp a_time, std::unique_ptr& diffData, - int is_init = 0); + const int is_init = 0); /** * \brief Add the Wbar contribution to the face-centered species diffusion @@ -686,13 +684,13 @@ public: * \param a_deltaT_norm norm of deltaT residual */ void deltaTIter_update( - int a_dtiter, - const amrex::Vector>& - a_fluxes, - const amrex::Vector& a_ebfluxes, - const amrex::Vector& a_Tsave, - std::unique_ptr& diffData, - amrex::Real& a_deltaT_norm); + const int a_dtiter, + const amrex::Vector>& + a_fluxes, + const amrex::Vector& a_ebfluxes, + const amrex::Vector& a_Tsave, + std::unique_ptr& diffData, + amrex::Real& a_deltaT_norm); /** * \brief Compute the viscous force term in the momentum equation using AMReX @@ -703,9 +701,9 @@ public: * scheme property (e.g. 0.5 for Crank Nicholson) */ void computeDivTau( - const PeleLM::TimeStamp& a_time, + const PeleLM::TimeStamp a_time, const amrex::Vector& a_divtau, - int use_density, + const int use_density, amrex::Real scale = 1.0); /** @@ -750,7 +748,7 @@ public: * a_extForcing advection/diffusion forcing */ void advanceChemistry( - int lev, const amrex::Real& a_dt, amrex::MultiFab& a_extForcing); + const int lev, const amrex::Real a_dt, amrex::MultiFab& a_extForcing); /** * \brief Performing the chemistry integration on a given level, for a fixed @@ -761,7 +759,7 @@ public: * \param a_extForcing advection/diffusion forcing */ void advanceChemistryBAChem( - int lev, const amrex::Real& a_dt, amrex::MultiFab& a_extForcing); + const int lev, const amrex::Real a_dt, amrex::MultiFab& a_extForcing); /** * \brief Top-level instantaneous reaction rate function, acting on all levels @@ -778,8 +776,7 @@ public: * \param a_time state time used to compute RR, either Old or New * \param a_I_R outgoing MultiFab for inst. RR container */ - void computeInstantaneousReactionRate( - int lev, const PeleLM::TimeStamp& a_time, amrex::MultiFab* a_I_R); + void computeInstantaneousReactionRate(const int lev, const PeleLM::TimeStamp a_time, amrex::MultiFab* a_I_R); /** * \brief Compute the heat release rate on a given level, using the @@ -787,7 +784,7 @@ public: * \param lev level of interest * \param a_HR outgoing MultiFab */ - void getHeatRelease(int lev, amrex::MultiFab* a_HR); + void getHeatRelease(const int lev, amrex::MultiFab* a_HR); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -798,43 +795,43 @@ public: * \param is_init flag to trigger init-only dt factors * \param a_time state time to work on, either Old or New */ - amrex::Real computeDt(int is_init, const PeleLM::TimeStamp& a_time); + amrex::Real computeDt(const int is_init, const PeleLM::TimeStamp a_time); /** * \brief Compute the CFL step size * \param a_time state time to work on, either Old or New */ - amrex::Real estConvectiveDt(const PeleLM::TimeStamp& a_time); + amrex::Real estConvectiveDt(const PeleLM::TimeStamp a_time); /** * \brief Compute the divU step size * \param a_time state time to work on, either Old or New */ - amrex::Real estDivUDt(const PeleLM::TimeStamp& a_time); - void checkDt(const PeleLM::TimeStamp& a_time, const amrex::Real& a_dt); + amrex::Real estDivUDt(const PeleLM::TimeStamp a_time); + void checkDt(const PeleLM::TimeStamp a_time, const amrex::Real& a_dt); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // FORCES void getVelForces( - const TimeStamp& a_time, - const amrex::Vector& a_divTau, - const amrex::Vector& a_velForce, - int nGrowForce, - int add_gradP); + const PeleLM::TimeStamp a_time, + const amrex::Vector& a_divTau, + const amrex::Vector& a_velForce, + const int nGrowForce, + const int add_gradP); void getVelForces( - const TimeStamp& a_time, - int lev, - amrex::MultiFab* a_divTau, - amrex::MultiFab* a_velForce, - int add_gradP); + const PeleLM::TimeStamp a_time, + const int lev, + amrex::MultiFab* a_divTau, + amrex::MultiFab* a_velForce, + const int add_gradP); void getVelForces( - int lev, + const int lev, const amrex::Box& bx, - const amrex::Real& a_time, + const amrex::Real a_time, amrex::Array4 const& force, amrex::Array4 const& vel, amrex::Array4 const& rho, @@ -844,9 +841,9 @@ public: amrex::Array4 const& extMom, amrex::Array4 const& extRho); - void addSpark(const PeleLM::TimeStamp& a_time); + void addSpark(const PeleLM::TimeStamp a_time); - void addScalarVarianceSources(const PeleLM::TimeStamp& a_time); + void addScalarVarianceSources(const PeleLM::TimeStamp a_time); //----------------------------------------------------------------------------- @@ -890,7 +887,7 @@ public: // Compute the soot source terms void computeSootSource( - const PeleLM::TimeStamp& a_timestamp, const amrex::Real a_dt); + const PeleLM::TimeStamp a_timestamp, const amrex::Real a_dt); // Clip soot moments void clipSootMoments(); @@ -903,7 +900,7 @@ public: void RadInit(); // Compute the radiation source term - void computeRadSource(const PeleLM::TimeStamp& a_timestamp); + void computeRadSource(const PeleLM::TimeStamp a_timestamp); #endif //----------------------------------------------------------------------------- @@ -913,9 +910,9 @@ public: bool m_ext_sources_SDC; bool m_add_variance_sources; void getExternalSources( - int is_initIter, - const PeleLM::TimeStamp& a_timestamp_old, - const PeleLM::TimeStamp& a_timestamp_new); + const int is_initIter, + const PeleLM::TimeStamp a_timestamp_old, + const PeleLM::TimeStamp a_timestamp_new); //----------------------------------------------------------------------------- // EOS @@ -924,21 +921,21 @@ public: * \brief Compute thermodynamic pressure (RhoRT) from state on all levels * \param a_time state time to work on, either Old or New */ - void setThermoPress(const PeleLM::TimeStamp& a_time); + void setThermoPress(const PeleLM::TimeStamp a_time); /** * \brief Compute thermodynamic pressure (RhoRT) from state on a single level * \param lev level of interest * \param a_time state time to work on, either Old or New */ - void setThermoPress(int lev, const PeleLM::TimeStamp& a_time); + void setThermoPress(const int lev, const PeleLM::TimeStamp a_time); /** * \brief Enforce rho = \sum rhoYs on a given level * \param lev level of interest * \param a_time state time to work on, either Old or New */ - void setRhoToSumRhoY(int lev, const PeleLM::TimeStamp& a_time); + void setRhoToSumRhoY(const int lev, const PeleLM::TimeStamp a_time); /** * \brief Compute temperature from rhoY and rhoH on all levels @@ -951,7 +948,7 @@ public: * \param lev level of interest * \param a_time state time to work on, either Old or New */ - void setTemperature(int lev, const PeleLM::TimeStamp& a_time); + void setTemperature(const int lev, const PeleLM::TimeStamp a_time); /** * \brief Compute the divergence constraint from reaction/diffusion @@ -963,11 +960,11 @@ public: * \param diffData container for the diffusion terms */ void calcDivU( - int is_init, - int computeDiff, - int do_avgDown, - const PeleLM::TimeStamp& a_time, - std::unique_ptr& diffData); + const int is_init, + const int computeDiff, + const int do_avgDown, + const PeleLM::TimeStamp a_time, + std::unique_ptr& diffData); /** * \brief Compute the pressure drift term using RhoRT and @@ -976,7 +973,7 @@ public: * \param a_dPdt outgoing container */ void calc_dPdt( - const PeleLM::TimeStamp& a_time, + const PeleLM::TimeStamp a_time, const amrex::Vector& a_dPdt); /** @@ -987,7 +984,7 @@ public: * \param a_dPdt outgoing container */ void - calc_dPdt(int lev, const PeleLM::TimeStamp& a_time, amrex::MultiFab* a_dPdt); + calc_dPdt(const int lev, const PeleLM::TimeStamp a_time, amrex::MultiFab* a_dPdt); /** * \brief For the closed chamber algorithm, compute averaged @@ -1029,7 +1026,7 @@ public: void initBPatches(amrex::Geometry& a_geom); void rhoHBalance(); - void initTemporals(const PeleLM::TimeStamp& a_time = AmrOldTime); + void initTemporals(const PeleLM::TimeStamp a_time = AmrOldTime); void writeTemporals(); void addMassFluxes( const amrex::Array& a_fluxes, @@ -1365,7 +1362,7 @@ public: // Evaluate function void MLevaluate( const amrex::Vector& a_MFVec, - int a_comp, + const int a_comp, int& nComp, const std::string& a_var); @@ -1382,7 +1379,7 @@ public: std::string stateVariableName(int a_index); // Typical values - void setTypicalValues(const PeleLM::TimeStamp& a_time, int is_init = 0); + void setTypicalValues(const PeleLM::TimeStamp a_time, const int is_init = 0); void updateTypicalValuesChem(); void checkMemory(const std::string& a_message) const; @@ -1411,70 +1408,70 @@ public: void initialRedistribution(); void initCoveredState(); - void setCoveredState(const PeleLM::TimeStamp& a_time); - void setCoveredState(int lev, const PeleLM::TimeStamp& a_time); + void setCoveredState(const PeleLM::TimeStamp a_time); + void setCoveredState(const int lev, const PeleLM::TimeStamp a_time); void redistributeAofS( - int a_lev, - amrex::Real& a_dt, - amrex::MultiFab& a_tmpDiv, - int div_comp, - amrex::MultiFab& a_AofS, - int aofs_comp, - amrex::MultiFab& a_state, - int state_comp, - int ncomp, - const amrex::BCRec* d_bc, - const amrex::Geometry& a_geom) const; + const int a_lev, + amrex::Real a_dt, + amrex::MultiFab& a_tmpDiv, + const int div_comp, + amrex::MultiFab& a_AofS, + const int aofs_comp, + amrex::MultiFab& a_state, + const int state_comp, + const int ncomp, + const amrex::BCRec* d_bc, + const amrex::Geometry& a_geom) const; void redistributeDiff( - int a_lev, - const amrex::Real& a_dt, - amrex::MultiFab& a_tmpDiv, - int div_comp, - amrex::MultiFab& a_diff, - int diff_comp, - const amrex::MultiFab& a_state, - int state_comp, - int ncomp, - const amrex::BCRec* d_bc, - const amrex::Geometry& a_geom) const; - - void getCoveredIMask(int a_lev, amrex::iMultiFab& a_imask) const; - - void getEBDistance(int a_lev, amrex::MultiFab& a_signDistLev); + const int a_lev, + const amrex::Real a_dt, + amrex::MultiFab& a_tmpDiv, + const int div_comp, + amrex::MultiFab& a_diff, + const int diff_comp, + const amrex::MultiFab& a_state, + const int state_comp, + const int ncomp, + const amrex::BCRec* d_bc, + const amrex::Geometry& a_geom) const; + + void getCoveredIMask(const int a_lev, amrex::iMultiFab& a_imask) const; + + void getEBDistance(const int a_lev, amrex::MultiFab& a_signDistLev); void extendSignedDistance(amrex::MultiFab* a_signDist, amrex::Real a_extendFactor); void getEBState( - int a_lev, - const PeleLM::TimeStamp& a_time, - amrex::MultiFab& a_EBstate, - int stateComp, - int nComp); + const int a_lev, + const PeleLM::TimeStamp a_time, + amrex::MultiFab& a_EBstate, + const int stateComp, + const int nComp); amrex::Vector> - getEBState(int first_comp, int ncomp, const PeleLM::TimeStamp& a_time); + getEBState(const int first_comp, const int ncomp, const PeleLM::TimeStamp a_time); std::unique_ptr getEBState( - int a_lev, int first_comp, int ncomp, const PeleLM::TimeStamp& a_time); + const int a_lev, const int first_comp, const int ncomp, const PeleLM::TimeStamp a_time); amrex::FArrayBox getEBState( const amrex::MFIter& a_mfi, - int a_lev, - int first_comp, - int ncomp, - const PeleLM::TimeStamp& a_time); + const int a_lev, + const int first_comp, + const int ncomp, + const PeleLM::TimeStamp a_time); void getEBDiff( - int a_lev, - const TimeStamp& a_time, - amrex::MultiFab& a_EBDiff, - int diffComp); + const int a_lev, + const TimeStamp a_time, + amrex::MultiFab& a_EBDiff, + const int diffComp); // static_cast factory into ebfactory - amrex::EBFArrayBoxFactory const& EBFactory(int lev) const noexcept + amrex::EBFArrayBoxFactory const& EBFactory(const int lev) const noexcept { return static_cast(*m_factory[lev]); } @@ -1493,14 +1490,14 @@ public: void advanceSetup(); void oneSDC( - int sdcIter, - std::unique_ptr& advData, - std::unique_ptr& diffData); + const int sdcIter, + std::unique_ptr& advData, + std::unique_ptr& diffData); void copyTransportOldToNew(); - void copyStateNewToOld(int nGhost = 0); + void copyStateNewToOld(const int nGhost = 0); void copyPressNewToOld(); - void copyStateOldToNew(int nGhost = 0); + void copyStateOldToNew(const int nGhost = 0); void copyDiffusionOldToNew(std::unique_ptr& diffData); void computeVelocityAdvTerm(std::unique_ptr& advData); @@ -1511,10 +1508,10 @@ public: std::unique_ptr& diffData); void computeScalarAdvTerms(std::unique_ptr& advData); void computePassiveAdvTerms( - std::unique_ptr& advData, int state_comp, int ncomp); + std::unique_ptr& advData, const int state_comp, const int ncomp); void updateDensity(std::unique_ptr& advData); void updateScalarComp( - std::unique_ptr& advData, int state_comp, int ncomp); + std::unique_ptr& advData, const int state_comp, const int ncomp); void getScalarDiffForce( std::unique_ptr& advData, @@ -1528,29 +1525,29 @@ public: //----------------------------------------------------------------------------- // PLASMA - void poissonSolveEF(const PeleLM::TimeStamp& a_time); + void poissonSolveEF(const PeleLM::TimeStamp a_time); - void calcEFTransport(const PeleLM::TimeStamp& a_time); + void calcEFTransport(const PeleLM::TimeStamp a_time); void initializeElectronNeutral(); void initializeElectronFromMassFraction(); void implicitNonLinearSolve( - int sdcIter, - const amrex::Real& a_dt, - std::unique_ptr& diffData, - std::unique_ptr& advData); + const int sdcIter, + const amrex::Real a_dt, + std::unique_ptr& diffData, + std::unique_ptr& advData); void computeBGcharge( - const amrex::Real& a_time, - std::unique_ptr& diffData, - std::unique_ptr& advData); - + const amrex::Real a_time, + std::unique_ptr& diffData, + std::unique_ptr& advData); + void nonLinearResidual( - const amrex::Real& a_dt, - const amrex::Vector& a_nlstate, - const amrex::Vector& a_nlresid, - int updateScaling, - int updatePrecond); + const amrex::Real a_dt, + const amrex::Vector& a_nlstate, + const amrex::Vector& a_nlresid, + const int updateScaling, + const int updatePrecond); void getAdvectionTerm( const amrex::Vector& a_nE, @@ -1559,52 +1556,50 @@ public: a_gPhiVCur); void getAdvectionFluxes( - int lev, - const amrex::Array& a_fluxes, - const amrex::MultiFab& a_nE, - const amrex::Array& a_ueff, - amrex::BCRec bcrec); + const int lev, + const amrex::Array& a_fluxes, + const amrex::MultiFab& a_nE, + const amrex::Array& a_ueff, + amrex::BCRec bcrec); void getAdvectionFluxesMOL( - int lev, - const amrex::Array& a_fluxes, - const amrex::MultiFab& a_nE, - const amrex::Array& a_ueff, - amrex::BCRec bcrec); + const int lev, + const amrex::Array& a_fluxes, + const amrex::MultiFab& a_nE, + const amrex::Array& a_ueff, + amrex::BCRec bcrec); void ionDriftVelocity(std::unique_ptr& advData); - void ionDriftAddUmac(int lev, std::unique_ptr& advData); + void ionDriftAddUmac(const int lev, std::unique_ptr& advData); - void computeInstantaneousReactionRateEF( - int lev, const PeleLM::TimeStamp& a_time, amrex::MultiFab* a_I_R); + void computeInstantaneousReactionRateEF(const int lev, const PeleLM::TimeStamp& a_time, amrex::MultiFab* a_I_R); amrex::BCRec hackBCChargedParticle(const amrex::Real& zk, const amrex::BCRec& bc_in); - amrex::Real estEFIonsDt(const PeleLM::TimeStamp& a_time); + amrex::Real estEFIonsDt(const PeleLM::TimeStamp a_time); void addLorentzVelForces( - int lev, - const amrex::Box& bx, - const amrex::Real& a_time, - amrex::Array4 const& force, - amrex::Array4 const& rhoY, - amrex::Array4 const& phiV, - amrex::Array4 const& nE); + const int lev, + const amrex::Box& bx, + const amrex::Real a_time, + amrex::Array4 const& force, + amrex::Array4 const& rhoY, + amrex::Array4 const& phiV, + amrex::Array4 const& nE); void nlSolveNorm(const amrex::Vector& a_MF, amrex::Real& norm); int testExitNewton( - int newtonIter, - const amrex::Real& max_res, - const amrex::Real& norm_newtonDir); - + const int newtonIter, + const amrex::Real& max_res, + const amrex::Real& norm_newtonDir); + void updateNLState(const amrex::Vector& a_update); - - void incrementElectronForcing( - int a_sstep, std::unique_ptr& advData); - + + void incrementElectronForcing(const int a_sstep, std::unique_ptr& advData); + void getNLStateScaling(amrex::Real& nEScale, amrex::Real& phiVScale); void getNLResidScaling(amrex::Real& nEScale, amrex::Real& phiVScale); void scaleNLState(const amrex::Real& nEScale, const amrex::Real& phiVScale); @@ -1615,13 +1610,13 @@ public: // get upwinded edge-centered MF from cc MF and ec Vel amrex::Array getUpwindedEdge( - int lev, - int edge_comp, - int ncomp, - amrex::Vector a_bcrec, - const amrex::MultiFab& ccMF, - const amrex::Array& ecVel); - + const int lev, + const int edge_comp, + const int ncomp, + amrex::Vector a_bcrec, + const amrex::MultiFab& ccMF, + const amrex::Array& ecVel); + void jTimesV( const amrex::Vector& a_x, const amrex::Vector& a_Ax); @@ -1640,7 +1635,7 @@ public: // Accessors std::string runMode() const { return m_run_mode; } - static int nCompIR() + static constexpr int nCompIR() { #ifdef PELE_USE_PLASMA return NUM_SPECIES + 1; @@ -1649,7 +1644,7 @@ public: #endif } - static int nCompForcing() + static constexpr int nCompForcing() { #ifdef PELE_USE_PLASMA return NUM_SPECIES + 2; @@ -1664,10 +1659,10 @@ public: } LevelData* - getLevelDataPtr(int lev, const PeleLM::TimeStamp& a_time, int useUmac = 0); - LevelDataReact* getLevelDataReactPtr(int lev); + getLevelDataPtr(const int lev, const PeleLM::TimeStamp a_time, const int useUmac = 0); + LevelDataReact* getLevelDataReactPtr(const int lev); - amrex::Real getTime(int lev, const PeleLM::TimeStamp& a_time) const + amrex::Real getTime(int lev, const PeleLM::TimeStamp a_time) const { AMREX_ASSERT( a_time == AmrOldTime || a_time == AmrNewTime || a_time == AmrHalfTime); @@ -1681,45 +1676,45 @@ public: } amrex::Vector> - getStateVect(const PeleLM::TimeStamp& a_time); + getStateVect(const PeleLM::TimeStamp a_time); amrex::Vector> - getVelocityVect(const PeleLM::TimeStamp& a_time); + getVelocityVect(const PeleLM::TimeStamp a_time); amrex::Vector> - getDensityVect(const PeleLM::TimeStamp& a_time); + getDensityVect(const PeleLM::TimeStamp a_time); amrex::Vector> - getSpeciesVect(const PeleLM::TimeStamp& a_time); + getSpeciesVect(const PeleLM::TimeStamp a_time); amrex::Vector> - getRhoHVect(const PeleLM::TimeStamp& a_time); + getRhoHVect(const PeleLM::TimeStamp a_time); amrex::Vector> - getTempVect(const PeleLM::TimeStamp& a_time); - amrex::Vector getDivUVect(const PeleLM::TimeStamp& a_time); + getTempVect(const PeleLM::TimeStamp a_time); + amrex::Vector getDivUVect(const PeleLM::TimeStamp a_time); amrex::Vector - getDiffusivityVect(const PeleLM::TimeStamp& a_time); + getDiffusivityVect(const PeleLM::TimeStamp a_time); amrex::Vector - getViscosityVect(const PeleLM::TimeStamp& a_time); + getViscosityVect(const PeleLM::TimeStamp a_time); amrex::Vector getIRVect(); amrex::Vector> - getAuxVect(const PeleLM::TimeStamp& a_time); + getAuxVect(const PeleLM::TimeStamp a_time); amrex::Vector - getAuxDiffusivityVect(const PeleLM::TimeStamp& a_time); + getAuxDiffusivityVect(const PeleLM::TimeStamp a_time); #ifdef PELE_USE_PLASMA amrex::Vector> - getPhiVVect(const PeleLM::TimeStamp& a_time); + getPhiVVect(const PeleLM::TimeStamp a_time); amrex::Vector> - getnEVect(const PeleLM::TimeStamp& a_time); + getnEVect(const PeleLM::TimeStamp a_time); amrex::Vector - getnEDiffusivityVect(const PeleLM::TimeStamp& a_time); + getnEDiffusivityVect(const PeleLM::TimeStamp a_time); #endif - amrex::Vector fetchBCRecArray(int scomp, int ncomp); - amrex::Vector fetchBCRecAuxArray(int scomp, int ncomp); - amrex::Vector fetchAdvTypeArray(int scomp, int ncomp); - amrex::Vector fetchDiffTypeArray(int scomp, int ncomp); - amrex::Vector fetchAdvTypeAuxArray(int scomp, int ncomp); - amrex::Vector fetchDiffTypeAuxArray(int scomp, int ncomp); + amrex::Vector fetchBCRecArray(const int scomp, const int ncomp); + amrex::Vector fetchBCRecAuxArray(const int scomp, const int ncomp); + amrex::Vector fetchAdvTypeArray(const int scomp, const int ncomp); + amrex::Vector fetchDiffTypeArray(const int scomp, const int ncomp); + amrex::Vector fetchAdvTypeAuxArray(const int scomp, const int ncomp); + amrex::Vector fetchDiffTypeAuxArray(const int scomp, const int ncomp); DiffusionOp* getDiffusionOp(); - DiffusionOp* getMCDiffusionOp(int ncomp = 1); + DiffusionOp* getMCDiffusionOp(const int ncomp = 1); DiffusionTensorOp* getDiffusionTensorOp(); //----------------------------------------------------------------------------- @@ -2069,13 +2064,13 @@ public: // Number of ghost cells #ifdef AMREX_USE_EB - int m_nGrowState = 4; + static constexpr int m_nGrowState = 4; #else - int m_nGrowState = 3; + static constexpr int m_nGrowState = 3; #endif - int m_nGrowAdv = 1; - int m_nGrowdivu = 1; - int m_nGrowMAC = 1; + static constexpr int m_nGrowAdv = 1; + static constexpr int m_nGrowdivu = 1; + static constexpr int m_nGrowMAC = 1; // Initialization int m_do_init_proj = 1; From caeefe4f394dca285eabfc9be61ae27ae5aa5f22 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 13 Jul 2025 10:59:27 +0100 Subject: [PATCH 27/87] loops --- Source/PeleLMeX_Advance.cpp | 6 +- Source/PeleLMeX_Advection.cpp | 20 ++--- Source/PeleLMeX_BC.cpp | 64 +++++++------- Source/PeleLMeX_BCfill.H | 26 +++--- Source/PeleLMeX_BCfillEB.H | 2 +- Source/PeleLMeX_BPatch.cpp | 8 +- Source/PeleLMeX_Data.cpp | 18 ++-- Source/PeleLMeX_Derive.cpp | 6 +- Source/PeleLMeX_DeriveFunc.cpp | 8 +- Source/PeleLMeX_Diffusion.cpp | 60 ++++++------- Source/PeleLMeX_DiffusionOp.cpp | 18 ++-- Source/PeleLMeX_EB.cpp | 10 +-- Source/PeleLMeX_Eos.cpp | 2 +- Source/PeleLMeX_Evaluate.cpp | 12 +-- Source/PeleLMeX_FlowController.cpp | 8 +- Source/PeleLMeX_Forces.cpp | 22 ++--- Source/PeleLMeX_Init.cpp | 6 +- Source/PeleLMeX_K.H | 88 +++++++++---------- Source/PeleLMeX_ODEQty.cpp | 4 +- Source/PeleLMeX_Plot.cpp | 40 ++++----- Source/PeleLMeX_ProblemSpecificFunctions.H | 4 +- Source/PeleLMeX_Projection.cpp | 6 +- Source/PeleLMeX_Radiation.cpp | 4 +- Source/PeleLMeX_Reactions.cpp | 18 ++-- Source/PeleLMeX_Setup.cpp | 58 ++++++------ Source/PeleLMeX_Soot.cpp | 8 +- Source/PeleLMeX_SprayParticles.cpp | 2 +- Source/PeleLMeX_Temporals.cpp | 40 ++++----- Source/PeleLMeX_TransportProp.cpp | 10 +-- Source/PeleLMeX_UMac.cpp | 2 +- Source/PeleLMeX_Utils.cpp | 62 ++++++------- Source/Plasma/GMRES/MLGMRES.cpp | 6 +- .../Plasma/LinOps/AMReX_MLABecCecLap_3D_K.H | 2 +- Source/Plasma/PeleLMeX_EFIonDrift.cpp | 10 +-- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 18 ++-- Source/Plasma/PeleLMeX_EFPoisson.cpp | 2 +- Source/Plasma/PeleLMeX_EFTimeStep.cpp | 4 +- Source/Plasma/PeleLMeX_EFUtils.cpp | 12 +-- Source/Plasma/PeleLMeX_EF_K.H | 34 +++---- Source/main.cpp | 2 +- 40 files changed, 366 insertions(+), 366 deletions(-) diff --git a/Source/PeleLMeX_Advance.cpp b/Source/PeleLMeX_Advance.cpp index 8d5085205..9496c4dd8 100644 --- a/Source/PeleLMeX_Advance.cpp +++ b/Source/PeleLMeX_Advance.cpp @@ -49,7 +49,7 @@ PeleLM::Advance(int is_initIter) #endif // Update time vectors - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { m_t_old[lev] = m_cur_time; m_t_new[lev] = m_cur_time + m_dt; } @@ -73,7 +73,7 @@ PeleLM::Advance(int is_initIter) finest_level, grids, dmap, m_factory, m_incompressible, m_nAux, m_nGrowAdv, m_nGrowMAC); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { m_extSource[lev]->setVal(0.); } //---------------------------------------------------------------- @@ -88,7 +88,7 @@ PeleLM::Advance(int is_initIter) // Reset velocity flux on boundary faces if doing closed chamber if (m_closed_chamber != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_domainUmacFlux[2 * idim] = 0.0; m_domainUmacFlux[2 * idim + 1] = 0.0; } diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 15dc26bc8..5a335d102 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -22,7 +22,7 @@ PeleLM::computeVelocityAdvTerm(std::unique_ptr& advData) velForces[lev].define( grids[lev], dmap[lev], AMREX_SPACEDIM, nGrow_force, MFInfo(), Factory(lev)); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim].define( amrex::convert(grids[lev], IntVect::TheDimensionVector(idim)), dmap[lev], AMREX_SPACEDIM, 0, MFInfo(), Factory(lev)); @@ -352,7 +352,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) Vector> fluxes(finest_level + 1); Vector> fluxes_aux(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim].define( amrex::convert(grids[lev], IntVect::TheDimensionVector(idim)), dmap[lev], NUM_SPECIES + 1, 0, MFInfo(), @@ -377,7 +377,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) int nGrow = 0; Array edgeState; Array edgeState_aux; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { edgeState[idim].define( amrex::convert(grids[lev], IntVect::TheDimensionVector(idim)), dmap[lev], NUM_SPECIES + 3, nGrow, MFInfo(), Factory(lev)); @@ -455,7 +455,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) fluxes_are_area_weighted, m_advection_type, m_Godunov_ppm_limiter); // Ions one by one - for (int n = 0; n < NUM_IONS; n++) { + for (int n = 0; n < NUM_IONS; ++n) { const int ion_idx = NUM_SPECIES - NUM_IONS + n; auto bcRecIons = fetchBCRecArray(FIRSTSPEC + ion_idx, 1); auto bcRecIons_d = convertToDeviceVector(bcRecIons); @@ -553,9 +553,9 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) fluxes_are_area_weighted, m_advection_type, m_Godunov_ppm_limiter); } // Zero out fluxes for non-advected auxiliaries - for (int n = 0; n < m_nAux; n++) { + for (int n = 0; n < m_nAux; ++n) { if (m_aux_advect[n] == 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes_aux[lev][idim].setVal(0.0, n, 1); } } @@ -575,7 +575,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) #endif // Edge states - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const Box& ebx = amrex::surroundingNodes(bx, idim); auto const& rho_ed = edgeState[idim].array(mfi, 0); auto const& rhoY_ed = edgeState[idim].array(mfi, 1); @@ -666,7 +666,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; #endif - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const Box& ebx = amrex::surroundingNodes(bx, idim); auto const& rho = edgeState[idim].const_array(mfi, 0); auto const& rhoY = edgeState[idim].const_array(mfi, 1); @@ -799,7 +799,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) for (int n = 0; n < NUM_IONS; ++n) { int spec_idx = NUM_SPECIES - NUM_IONS + n; Array, AMREX_SPACEDIM> ionFlux; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { ionFlux[idim].reset( new MultiFab(fluxes[lev][idim], amrex::make_alias, spec_idx, 1)); } @@ -959,7 +959,7 @@ PeleLM::computePassiveAdvTerms( Vector> fluxes(finest_level + 1); Vector> edgeState(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim].define( amrex::convert(grids[lev], IntVect::TheDimensionVector(idim)), dmap[lev], ncomp, 0, MFInfo(), Factory(lev)); diff --git a/Source/PeleLMeX_BC.cpp b/Source/PeleLMeX_BC.cpp index 7c11dbed8..d4b21869d 100644 --- a/Source/PeleLMeX_BC.cpp +++ b/Source/PeleLMeX_BC.cpp @@ -119,8 +119,8 @@ PeleLM::setBoundaryConditions() const int* hi_bc = m_phys_bc.hi(); // Velocity - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int idim2 = 0; idim2 < AMREX_SPACEDIM; idim2++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int idim2 = 0; idim2 < AMREX_SPACEDIM; ++idim2) { if (idim == idim2) { m_bcrec_state[VELX + idim].setLo(idim2, norm_vel_bc[lo_bc[idim2]]); m_bcrec_state[VELX + idim].setHi(idim2, norm_vel_bc[hi_bc[idim2]]); @@ -132,8 +132,8 @@ PeleLM::setBoundaryConditions() } // General forces: use int_dir in interior and foextrap otherwise - for (int i = 0; i < sizeForceBC; i++) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int i = 0; i < sizeForceBC; ++i) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_force[i].setLo(idim, force_bc[lo_bc[idim]]); m_bcrec_force[i].setHi(idim, force_bc[hi_bc[idim]]); } @@ -141,47 +141,47 @@ PeleLM::setBoundaryConditions() if (m_incompressible == 0) { // Density - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[DENSITY].setLo(idim, density_bc[lo_bc[idim]]); m_bcrec_state[DENSITY].setHi(idim, density_bc[hi_bc[idim]]); } // Species - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int n = 0; n < NUM_SPECIES; ++n) { m_bcrec_state[FIRSTSPEC + n].setLo(idim, density_bc[lo_bc[idim]]); m_bcrec_state[FIRSTSPEC + n].setHi(idim, density_bc[hi_bc[idim]]); } } // Enthalpy - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[RHOH].setLo(idim, rhoh_bc[lo_bc[idim]]); m_bcrec_state[RHOH].setHi(idim, rhoh_bc[hi_bc[idim]]); } // Temperature - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[TEMP].setLo(idim, temp_bc[lo_bc[idim]]); m_bcrec_state[TEMP].setHi(idim, temp_bc[hi_bc[idim]]); } // rhoRT: reflect even on all but interior bndy - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[RHORT].setLo(idim, divu_bc[lo_bc[idim]]); m_bcrec_state[RHORT].setHi(idim, divu_bc[hi_bc[idim]]); } // divU if (m_has_divu != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_divu.setLo(idim, divu_bc[lo_bc[idim]]); m_bcrec_divu.setHi(idim, divu_bc[hi_bc[idim]]); } } // auxiliaries - assumed to be the same as species - for (int n = 0; n < m_nAux; n++) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int n = 0; n < m_nAux; ++n) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_aux[n].setLo(idim, aux_bc[lo_bc[idim]]); m_bcrec_aux[n].setHi(idim, aux_bc[hi_bc[idim]]); } @@ -189,7 +189,7 @@ PeleLM::setBoundaryConditions() #ifdef PELE_USE_PLASMA // nE - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[NE].setLo(idim, nE_bc[lo_bc[idim]]); m_bcrec_state[NE].setHi(idim, nE_bc[hi_bc[idim]]); } @@ -197,7 +197,7 @@ PeleLM::setBoundaryConditions() // Get m_phiV_bc const int* lo_phibc = m_phiV_bc.lo(); const int* hi_phibc = m_phiV_bc.hi(); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_bcrec_state[PHIV].setLo(idim, phiV_bc[lo_phibc[idim]]); m_bcrec_state[PHIV].setHi(idim, phiV_bc[hi_phibc[idim]]); } @@ -205,22 +205,22 @@ PeleLM::setBoundaryConditions() // Hack charged species BCs int FIRSTIONinVar = FIRSTSPEC + NUM_SPECIES - NUM_IONS; int FIRSTIONinSpec = NUM_SPECIES - NUM_IONS; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int n = 0; n < NUM_IONS; n++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int n = 0; n < NUM_IONS; ++n) { auto const bcIonSave = m_bcrec_state[FIRSTIONinVar + n]; m_bcrec_state[FIRSTIONinVar + n] = hackBCChargedParticle(zk[FIRSTIONinSpec + n], bcIonSave); } } // Need to hack nE too actually ... - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { auto const bcnESave = m_bcrec_state[NE]; m_bcrec_state[NE] = hackBCChargedParticle(-1.0, bcnESave); } #endif #ifdef PELE_USE_SOOT - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int mom = 0; mom < NUMSOOTVAR; mom++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int mom = 0; mom < NUMSOOTVAR; ++mom) { m_bcrec_state[FIRSTSOOT + mom].setLo(idim, soot_bc[lo_bc[idim]]); m_bcrec_state[FIRSTSOOT + mom].setHi(idim, soot_bc[hi_bc[idim]]); } @@ -233,7 +233,7 @@ Vector PeleLM::fetchBCRecArray(int scomp, int ncomp) { Vector bc(ncomp); - for (int comp = 0; comp < ncomp; comp++) { + for (int comp = 0; comp < ncomp; ++comp) { bc[comp] = m_bcrec_state[scomp + comp]; } return bc; @@ -243,7 +243,7 @@ Vector PeleLM::fetchBCRecAuxArray(int scomp, int ncomp) { Vector bc(ncomp); - for (int comp = 0; comp < ncomp; comp++) { + for (int comp = 0; comp < ncomp; ++comp) { bc[comp] = m_bcrec_aux[scomp + comp]; } return bc; @@ -257,7 +257,7 @@ void PeleLM::fillPatchState(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchState()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { fillPatchState(lev, a_time); } } @@ -284,7 +284,7 @@ void PeleLM::fillPatchDensity(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchDensity()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_time); Real time = getTime(lev, a_time); fillpatch_density(lev, time, ldata_p->state, DENSITY, m_nGrowState); @@ -295,7 +295,7 @@ void PeleLM::fillPatchSpecies(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchSpecies()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_time); Real time = getTime(lev, a_time); fillpatch_species(lev, time, ldata_p->state, FIRSTSPEC, m_nGrowState); @@ -306,7 +306,7 @@ void PeleLM::fillPatchTemp(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchTemp()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_time); Real time = getTime(lev, a_time); fillpatch_temp(lev, time, ldata_p->state, TEMP, m_nGrowState); @@ -317,7 +317,7 @@ void PeleLM::fillPatchAux(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchAux()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_time); Real time = getTime(lev, a_time); fillpatch_aux(lev, time, ldata_p->auxiliaries, m_nGrowState); @@ -329,7 +329,7 @@ void PeleLM::fillPatchPhiV(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::fillPatchPhiV()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto ldata_p = getLevelDataPtr(lev, a_time); Real time = getTime(lev, a_time); fillpatch_phiV(lev, time, ldata_p->state, PHIV, m_nGrowState); @@ -1001,8 +1001,8 @@ PeleLM::setInflowBoundaryVel(MultiFab& a_vel, int lev, TimeStamp a_time) // other to bogus auto realVelBCRec = fetchBCRecArray(VELX, AMREX_SPACEDIM); amrex::Vector dummyVelBCRec(AMREX_SPACEDIM); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int idim2 = 0; idim2 < AMREX_SPACEDIM; idim2++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int idim2 = 0; idim2 < AMREX_SPACEDIM; ++idim2) { if (realVelBCRec[idim].lo(idim2) == BCType::ext_dir) { dummyVelBCRec[idim].setLo(idim2, BCType::ext_dir); } else { @@ -1065,7 +1065,7 @@ PeleLM::fillTurbInflow( // Create box with ghost cells and set them to zero amrex::IntVect growVect(amrex::IntVect::TheUnitVector()); int Grow = 4; // Being conservative - for (int n = 0; n < AMREX_SPACEDIM; n++) { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { growVect[n] = Grow; } growVect[dir] = 0; @@ -1088,7 +1088,7 @@ PeleLM::fillTurbInflow( // Create box with ghost cells and set them to zero amrex::IntVect growVect(amrex::IntVect::TheUnitVector()); int Grow = 4; - for (int n = 0; n < AMREX_SPACEDIM; n++) { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { growVect[n] = Grow; } growVect[dir] = 0; diff --git a/Source/PeleLMeX_BCfill.H b/Source/PeleLMeX_BCfill.H index 07e3e0f0b..390ce25f5 100644 --- a/Source/PeleLMeX_BCfill.H +++ b/Source/PeleLMeX_BCfill.H @@ -56,10 +56,10 @@ struct PeleLMCCFillExtDirState auto iv_3d = amrex::IntVectND<3>(0); AMREX_D_TERM(iv_3d[0] = iv[0];, iv_3d[1] = iv[1];, iv_3d[2] = iv[2];); - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low - for (int n = 0; n < std::min(numcomp, NVAR); n++) { + for (int n = 0; n < std::min(numcomp, NVAR); ++n) { // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; @@ -93,7 +93,7 @@ struct PeleLMCCFillExtDirState } // High - for (int n = 0; n < std::min(numcomp, NVAR); n++) { + for (int n = 0; n < std::min(numcomp, NVAR); ++n) { // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; @@ -176,10 +176,10 @@ struct PeleLMCCFillExtDirAux auto aux_ext = aux.cellData(iv[0], iv[1], iv[2]); #endif - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low - for (int n = 0; n < m_nAux; n++) { + for (int n = 0; n < m_nAux; ++n) { // Get current state component BC const int* bc = bcr[n].data(); @@ -192,7 +192,7 @@ struct PeleLMCCFillExtDirAux } } // High - for (int n = 0; n < m_nAux; n++) { + for (int n = 0; n < m_nAux; ++n) { // Get current state component BC const int* bc = bcr[n].data(); @@ -251,7 +251,7 @@ struct PeleLMCCFillExtDirSpec auto iv_3d = amrex::IntVectND<3>(0); AMREX_D_TERM(iv_3d[0] = iv[0];, iv_3d[1] = iv[1];, iv_3d[2] = iv[2];); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { // Get the species component BC const int* bc = bcr[n].data(); @@ -259,7 +259,7 @@ struct PeleLMCCFillExtDirSpec // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { @@ -346,7 +346,7 @@ struct PeleLMCCFillExtDirDens // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { @@ -430,7 +430,7 @@ struct PeleLMCCFillExtDirRhoH // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { @@ -513,7 +513,7 @@ struct PeleLMCCFillExtDirTemp // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { @@ -598,7 +598,7 @@ struct PeleLMCCFillExtDirnE // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { @@ -684,7 +684,7 @@ struct PeleLMCCFillExtDirPhiV // bcnormal handles all the state components at once amrex::Real s_ext[NVAR] = {0.0}; - for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { + for (int idir = 0; idir < AMREX_SPACEDIM; ++idir) { // Low if ((bc[idir] == amrex::BCType::ext_dir) and (iv[idir] < domlo[idir])) { diff --git a/Source/PeleLMeX_BCfillEB.H b/Source/PeleLMeX_BCfillEB.H index 399952981..de5f4d668 100644 --- a/Source/PeleLMeX_BCfillEB.H +++ b/Source/PeleLMeX_BCfillEB.H @@ -142,7 +142,7 @@ struct PeleLMFillBCStateEB ebh.bcnormal_eb(xface, bcnorm, stateIn, stateExt, time, geom, *lprobparm); // Extract requested entries - for (int n = 0; n < numcomp; n++) { + for (int n = 0; n < numcomp; ++n) { ebState(i, j, k, n) = stateExt[firstcomp + n]; } } diff --git a/Source/PeleLMeX_BPatch.cpp b/Source/PeleLMeX_BPatch.cpp index 527e611b0..346e92d1a 100644 --- a/Source/PeleLMeX_BPatch.cpp +++ b/Source/PeleLMeX_BPatch.cpp @@ -156,19 +156,19 @@ BPatch::BPatch(const std::string& patch_name, const amrex::Geometry& geom) pele::physics::eos::speciesNames(names); names.resize(names.size()); - for (int n = 0; n < names.size(); n++) { + for (int n = 0; n < names.size(); ++n) { m_bpdata_h.speciesIndex[n] = -1; } - for (int m = 0; m < m_bpdata_h.num_species; m++) { - for (int n = 0; n < names.size(); n++) { + for (int m = 0; m < m_bpdata_h.num_species; ++m) { + for (int n = 0; n < names.size(); ++n) { if (speciesList[m] == names[n]) { m_bpdata_h.speciesIndex[m] = n; } } } - for (int n = 0; n < m_bpdata_h.num_species; n++) { + for (int n = 0; n < m_bpdata_h.num_species; ++n) { if (m_bpdata_h.speciesIndex[n] == -1) { std::string msg = "\nError! Unable to find species index " + std::to_string(n); diff --git a/Source/PeleLMeX_Data.cpp b/Source/PeleLMeX_Data.cpp index e5c4c7b94..b9faf75b4 100644 --- a/Source/PeleLMeX_Data.cpp +++ b/Source/PeleLMeX_Data.cpp @@ -105,14 +105,14 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( Dnp1.resize(a_finestLevel + 1); // Define MFs - for (int lev = 0; lev <= a_finestLevel; lev++) { + for (int lev = 0; lev <= a_finestLevel; ++lev) { Dnp1[lev].define( ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, MFInfo(), *factory[lev]); } if (a_nAux > 0) { Dnp1_aux.resize(a_finestLevel + 1); - for (int lev = 0; lev <= a_finestLevel; lev++) { + for (int lev = 0; lev <= a_finestLevel; ++lev) { Dnp1_aux[lev].define( ba[lev], dm[lev], a_nAux, nGrowAdv, MFInfo(), *factory[lev]); } @@ -137,7 +137,7 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( } // Define MFs - for (int lev = 0; lev <= a_finestLevel; lev++) { + for (int lev = 0; lev <= a_finestLevel; ++lev) { Dn[lev].define( ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, MFInfo(), *factory[lev]); Dnp1[lev].define( @@ -203,7 +203,7 @@ PeleLM::AdvanceAdvData::AdvanceAdvData( #endif // Define MFs - for (int lev = 0; lev <= a_finestLevel; lev++) { + for (int lev = 0; lev <= a_finestLevel; ++lev) { for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const BoxArray& faceba = amrex::convert(ba[lev], IntVect::TheDimensionVector(idim)); @@ -245,7 +245,7 @@ void PeleLM::copyStateNewToOld(int nGhost) { AMREX_ASSERT(nGhost <= m_nGrowState); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { if (m_incompressible != 0) { MultiFab::Copy( m_leveldata_old[lev]->state, m_leveldata_new[lev]->state, 0, 0, @@ -271,7 +271,7 @@ PeleLM::copyStateNewToOld(int nGhost) void PeleLM::copyPressNewToOld() { - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy( m_leveldata_old[lev]->press, m_leveldata_new[lev]->press, 0, 0, 1, 1); MultiFab::Copy( @@ -284,7 +284,7 @@ void PeleLM::copyStateOldToNew(int nGhost) { AMREX_ASSERT(nGhost <= m_nGrowState); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { if (m_incompressible != 0) { MultiFab::Copy( m_leveldata_new[lev]->state, m_leveldata_old[lev]->state, 0, 0, @@ -310,7 +310,7 @@ PeleLM::copyStateOldToNew(int nGhost) void PeleLM::copyTransportOldToNew() { - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy( m_leveldata_new[lev]->visc_cc, m_leveldata_old[lev]->visc_cc, 0, 0, 1, 1); if (m_incompressible == 0) { @@ -340,7 +340,7 @@ PeleLM::copyTransportOldToNew() void PeleLM::copyDiffusionOldToNew(std::unique_ptr& diffData) { - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { MultiFab::Copy( diffData->Dnp1[lev], diffData->Dn[lev], 0, 0, NUM_SPECIES + 2, m_nGrowAdv); diff --git a/Source/PeleLMeX_Derive.cpp b/Source/PeleLMeX_Derive.cpp index d1d7a56c6..09ac8a90d 100644 --- a/Source/PeleLMeX_Derive.cpp +++ b/Source/PeleLMeX_Derive.cpp @@ -130,7 +130,7 @@ PeleLMDeriveRec::variableComp(const std::string& a_name) const noexcept if (n_derive == 1) { return 0; } - for (int comp = 0; comp < n_derive; comp++) { + for (int comp = 0; comp < n_derive; ++comp) { if (variable_names[comp] == a_name) { return comp; } @@ -200,7 +200,7 @@ PeleLMDeriveList::canDerive(const std::string& name) const { for (const auto& li : lst) { // Can be either a component name ... - for (int i = 0; i < li.numDerive(); i++) { + for (int i = 0; i < li.numDerive(); ++i) { if (li.variableName(i) == name) { return true; } @@ -218,7 +218,7 @@ PeleLMDeriveList::get(const std::string& name) const { for (const auto& li : lst) { // Can be either a component name ... - for (int i = 0; i < li.numDerive(); i++) { + for (int i = 0; i < li.numDerive(); ++i) { if (li.variableName(i) == name) { return &li; } diff --git a/Source/PeleLMeX_DeriveFunc.cpp b/Source/PeleLMeX_DeriveFunc.cpp index 6228f7b11..cabd51f60 100644 --- a/Source/PeleLMeX_DeriveFunc.cpp +++ b/Source/PeleLMeX_DeriveFunc.cpp @@ -80,7 +80,7 @@ pelelmex_derheatrelease( amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { getHGivenT(i, j, k, temp, Hi, leosparm); HRR(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { HRR(i, j, k) -= Hi(i, j, k, n) * react(i, j, k, n); } }); @@ -153,12 +153,12 @@ pelelmex_dermolefrac( amrex::Real Yt[NUM_SPECIES] = {0.0}; amrex::Real Xt[NUM_SPECIES] = {0.0}; amrex::Real rhoinv = 1.0 / in_dat(i, j, k, DENSITY); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { Yt[n] = in_dat(i, j, k, FIRSTSPEC + n) * rhoinv; } auto eos = pele::physics::PhysicsType::eos(leosparm); eos.Y2X(Yt, Xt); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { der(i, j, k, n) = Xt[n]; } }); @@ -194,7 +194,7 @@ pelelmex_derrhomrhoy( auto der = derfab.array(dcomp); amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { der(i, j, k, 0) = in_dat(i, j, k, DENSITY); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { der(i, j, k, 0) -= in_dat(i, j, k, FIRSTSPEC + n); } }); diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index b4ffa2588..3f5a69c21 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -78,7 +78,7 @@ PeleLM::computeDifferentialDiffusionTerms( for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], NUM_SPECIES + 2, nGrow, MFInfo(), factory); @@ -377,8 +377,8 @@ PeleLM::correctIsothermalBoundary( Vector> soretfluxes(finest_level + 1); if (need_explicit_fluxes) { // need to fill the soret fluxes ourselves - for (int lev = 0; lev <= finest_level; lev++) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int lev = 0; lev <= finest_level; ++lev) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { soretfluxes[lev][idim] = new MultiFab( grids[lev], dmap[lev], NUM_SPECIES, 1, MFInfo(), Factory(lev)); soretfluxes[lev][idim]->setVal(0.0); @@ -388,8 +388,8 @@ PeleLM::correctIsothermalBoundary( soretfluxes, soretfluxes, GetVecOfConstPtrs(getTempVect(a_time)), GetVecOfConstPtrs(getDiffusivityVect(a_time))); } else { // have the lagged ones, alias to them - for (int lev = 0; lev <= finest_level; lev++) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int lev = 0; lev <= finest_level; ++lev) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { soretfluxes[lev][idim] = new MultiFab( *a_soretfluxes[lev][idim], amrex::make_alias, 0, NUM_SPECIES); } @@ -438,7 +438,7 @@ PeleLM::correctIsothermalBoundary( if (on_lo) { // need to move -1 for lo boundary idx[idim] -= 1; } - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { boundary_ar(idx[0], idx[1], idx[2], n) = flux_soret(i, j, k, n); // add lagged wbar flux if (use_wbar != 0 && !need_explicit_fluxes) { @@ -453,8 +453,8 @@ PeleLM::correctIsothermalBoundary( } } // TODO: wbar fluxes disabled for this case - boundary system becomes complex - for (int lev = 0; lev <= finest_level; lev++) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int lev = 0; lev <= finest_level; ++lev) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { delete soretfluxes[lev][idim]; } } @@ -494,7 +494,7 @@ PeleLM::computeDifferentialDiffusionFluxes( MultiFab::Copy( spec_boundary[lev], ldata_p->state, FIRSTSPEC, 0, NUM_SPECIES, 1); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { MultiFab::Divide(spec_boundary[lev], ldata_p->state, DENSITY, n, 1, 1); } } @@ -518,7 +518,7 @@ PeleLM::computeDifferentialDiffusionFluxes( GetVecOfConstPtrs(getDiffusivityVect(a_time)), 0, bcRecSpec, NUM_SPECIES - NUM_IONS, do_avgDown, {}); // Ions one by one - for (int n = 0; n < NUM_IONS; n++) { + for (int n = 0; n < NUM_IONS; ++n) { auto bcRecIons = fetchBCRecArray(FIRSTSPEC + NUM_SPECIES - NUM_IONS + n, 1); getDiffusionOp()->computeDiffFluxes( a_fluxes, NUM_SPECIES - NUM_IONS + n, @@ -697,7 +697,7 @@ PeleLM::addWbarTerm( // isothermal/soret Wbar_boundary_arr(i, j, k) = Wbar_arr(i, j, k); int idx[3] = {i, j, k}; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const auto bc_lo = phys_bc.lo(idim); const auto bc_hi = phys_bc.hi(idim); bool on_lo = (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || @@ -728,7 +728,7 @@ PeleLM::addWbarTerm( for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { gradWbar[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], NUM_SPECIES, nGrow, MFInfo(), factory); @@ -758,7 +758,7 @@ PeleLM::addWbarTerm( #endif { for (MFIter mfi(*a_beta[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { // Get edge centered rhoYs const Box ebx = mfi.nodaltilebox(idim); @@ -804,23 +804,23 @@ PeleLM::addWbarTerm( auto eos = pele::physics::PhysicsType::eos(eosparm); // Get Wbar from rhoYs amrex::Real rho = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rho += rhoY(i, j, k, n); } amrex::Real rho_inv = 1.0 / rho; amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rho_inv; } amrex::Real WBAR = 0.0; eos.Y2WBAR(y, WBAR); WBAR *= 0.001; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { spFlux_ar(i, j, k, n) -= y[n] / WBAR * beta_ar(i, j, k, n) * gradWbar_ar(i, j, k); } if (need_wbar_fluxes != 0) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { spwbarFlux_ar(i, j, k, n) = -y[n] / WBAR * beta_ar(i, j, k, n) * gradWbar_ar(i, j, k); } @@ -855,7 +855,7 @@ PeleLM::addSoretTerm( for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { gradT[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], 1, nGrow, MFInfo(), factory); @@ -884,7 +884,7 @@ PeleLM::addSoretTerm( { FArrayBox T_ed; for (MFIter mfi(*a_beta[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { // Get edge centered rhoYs const Box ebx = mfi.nodaltilebox(idim); @@ -929,13 +929,13 @@ PeleLM::addSoretTerm( ebx, [need_soret_fluxes, gradT_ar, beta_ar, T, spFlux_ar, spsoretFlux_ar] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { spFlux_ar(i, j, k, n) -= beta_ar(i, j, k, n) * gradT_ar(i, j, k) / T(i, j, k); } if (need_soret_fluxes != 0) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { spsoretFlux_ar(i, j, k, n) = -beta_ar(i, j, k, n) * gradT_ar(i, j, k) / T(i, j, k); } @@ -1031,7 +1031,7 @@ PeleLM::computeSpeciesEnthalpyFlux( ebox, [spflux_ar, enthflux_ar, enth_ar] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { enthflux_ar(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { enthflux_ar(i, j, k) += spflux_ar(i, j, k, n) * enth_ar(i, j, k, n); } @@ -1059,7 +1059,7 @@ PeleLM::differentialDiffusionUpdate( for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], NUM_SPECIES + 2, nGrow, MFInfo(), factory); @@ -1105,11 +1105,11 @@ PeleLM::differentialDiffusionUpdate( amrex::ParallelFor( bx, [rhoY_o, fY, aux_o, fAux, dt = m_dt, nAux = m_nAux] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { fY(i, j, k, n) *= dt; fY(i, j, k, n) += rhoY_o(i, j, k, n); } - for (int n = 0; n < nAux; n++) { + for (int n = 0; n < nAux; ++n) { fAux(i, j, k, n) *= dt; fAux(i, j, k, n) += aux_o(i, j, k, n); } @@ -1137,7 +1137,7 @@ PeleLM::differentialDiffusionUpdate( MultiFab::Copy( spec_boundary[lev], ldata_p->state, FIRSTSPEC, 0, NUM_SPECIES, 1); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { MultiFab::Divide(spec_boundary[lev], ldata_p->state, DENSITY, n, 1, 1); } } @@ -1164,7 +1164,7 @@ PeleLM::differentialDiffusionUpdate( GetVecOfConstPtrs(getDiffusivityVect(AmrNewTime)), 0, bcRecSpec, NUM_SPECIES - NUM_IONS, 0, m_dt, {}); // Ions one by one - for (int n = 0; n < NUM_IONS; n++) { + for (int n = 0; n < NUM_IONS; ++n) { auto bcRecIons = fetchBCRecArray(FIRSTSPEC + NUM_SPECIES - NUM_IONS + n, 1); getDiffusionOp()->diffuse_scalar( GetVecOfPtrs(getSpeciesVect(AmrNewTime)), NUM_SPECIES - NUM_IONS + n, @@ -1312,7 +1312,7 @@ PeleLM::differentialDiffusionUpdate( nAux = m_nAux, dt = m_dt, use_wbar = m_use_wbar, use_soret = m_use_soret] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoY(i, j, k, n) = force(i, j, k, n) + dt * dhat(i, j, k, n); if (use_wbar != 0) { rhoY(i, j, k, n) -= dt * dwbar(i, j, k, n); @@ -1321,7 +1321,7 @@ PeleLM::differentialDiffusionUpdate( rhoY(i, j, k, n) -= dt * dT(i, j, k, n); } } - for (int n = 0; n < nAux; n++) { + for (int n = 0; n < nAux; ++n) { aux(i, j, k, n) = force_aux(i, j, k, n) + dt * dhat_aux(i, j, k, n); } }); @@ -1825,7 +1825,7 @@ PeleLM::getDiffusionTensorOpBC( r[0][idim] = LinOpBCType::Periodic;, r[1][idim] = LinOpBCType::Periodic; , r[2][idim] = LinOpBCType::Periodic;); } else { - for (int dir = 0; dir < AMREX_SPACEDIM; dir++) { + for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { auto amrexbc = (a_side == Orientation::low) ? a_bc[dir].lo(idim) : a_bc[dir].hi(idim); if (amrexbc == amrex::BCType::ext_dir) { diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index d5ab45a0f..f81e5f435 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -205,7 +205,7 @@ DiffusionOp::diffuse_scalar( // Set aliases and bcoeff comp for (int lev = 0; lev <= finest_level; ++lev) { if (have_fluxes != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim] = new MultiFab( *a_flux[lev][idim], amrex::make_alias, flux_comp + comp, m_ncomp); } @@ -269,7 +269,7 @@ DiffusionOp::diffuse_scalar( #endif for (int lev = 0; lev <= finest_level; ++lev) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { delete fluxes[lev][idim]; } } @@ -425,7 +425,7 @@ DiffusionOp::diffuse_scalar( // Set aliases and bcoeff comp for (int lev = 0; lev <= finest_level; ++lev) { if (have_fluxes != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim] = new MultiFab( *a_flux[lev][idim], amrex::make_alias, flux_comp + comp, m_ncomp); } @@ -481,7 +481,7 @@ DiffusionOp::diffuse_scalar( mlmg.getFluxes(fluxes, MLMG::Location::FaceCentroid); for (int lev = 0; lev <= finest_level; ++lev) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { delete fluxes[lev][idim]; } } @@ -676,7 +676,7 @@ DiffusionOp::computeDiffFluxes( m_pelelm->getDiffusionLinOpBC(Orientation::high, a_bcrec[comp])); for (int lev = 0; lev <= finest_level; ++lev) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim] = new MultiFab( *a_flux[lev][idim], amrex::make_alias, flux_comp + comp, m_ncomp); } @@ -716,7 +716,7 @@ DiffusionOp::computeDiffFluxes( mlmg.getFluxes(fluxes, GetVecOfPtrs(component), MLMG::Location::FaceCenter); #endif for (int lev = 0; lev <= finest_level; ++lev) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { delete fluxes[lev][idim]; } } @@ -819,7 +819,7 @@ DiffusionOp::computeDiffFluxes( m_pelelm->getDiffusionLinOpBC(Orientation::high, a_bcrec[comp])); for (int lev = 0; lev <= finest_level; ++lev) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim] = std::make_unique( *a_flux[lev][idim], amrex::make_alias, flux_comp + comp, m_ncomp); } @@ -949,7 +949,7 @@ DiffusionOp::avgDownFluxes( // Get the requested components only Array flux_fine; Array flux_crse; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { flux_fine[idim] = new MultiFab(*a_fluxes[lev][idim], amrex::make_alias, flux_comp, ncomp); flux_crse[idim] = new MultiFab( @@ -964,7 +964,7 @@ DiffusionOp::avgDownFluxes( GetArrOfConstPtrs(flux_fine), flux_crse, m_pelelm->refRatio(lev - 1), flux_crse[0]->nGrow()); #endif - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { delete flux_fine[idim]; delete flux_crse[idim]; } diff --git a/Source/PeleLMeX_EB.cpp b/Source/PeleLMeX_EB.cpp index 084d288a5..d822afa85 100644 --- a/Source/PeleLMeX_EB.cpp +++ b/Source/PeleLMeX_EB.cpp @@ -287,7 +287,7 @@ PeleLM::initCoveredState() coveredState_h[0] = 0.0;, coveredState_h[1] = 0.0; , coveredState_h[2] = 0.0;) coveredState_h[DENSITY] = typical_values[DENSITY]; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { coveredState_h[FIRSTSPEC + n] = typical_values[FIRSTSPEC + n]; } coveredState_h[RHOH] = typical_values[RHOH]; @@ -305,7 +305,7 @@ void PeleLM::setCoveredState(const TimeStamp& a_time) { BL_PROFILE("PeleLMeX::setCoveredState()"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { setCoveredState(lev, a_time); } } @@ -526,7 +526,7 @@ PeleLM::getEBState( amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Regular/covered cells -> 0.0 if (flag(i, j, k).isCovered() || flag(i, j, k).isRegular()) { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { ebscal_arr(i, j, k, n) = 0.0; } } else { // cut-cells @@ -596,7 +596,7 @@ PeleLM::getEBState( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Regular/covered cells -> 0.0 if (flag(i, j, k).isCovered() || flag(i, j, k).isRegular()) { - for (int n = 0; n < nComp; n++) { + for (int n = 0; n < nComp; ++n) { ebState(i, j, k, n) = 0.0; } } else { // cut-cells @@ -680,7 +680,7 @@ PeleLM::correct_vel_small_cells( { BL_PROFILE("PeleLMeX::correct_vel_small_cells"); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif diff --git a/Source/PeleLMeX_Eos.cpp b/Source/PeleLMeX_Eos.cpp index 982ee3bb1..9e9d6cd6f 100644 --- a/Source/PeleLMeX_Eos.cpp +++ b/Source/PeleLMeX_Eos.cpp @@ -59,7 +59,7 @@ PeleLM::calcDivU( } // Assemble divU on each level - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_time); diff --git a/Source/PeleLMeX_Evaluate.cpp b/Source/PeleLMeX_Evaluate.cpp index 9c98ec92c..c3e22991a 100644 --- a/Source/PeleLMeX_Evaluate.cpp +++ b/Source/PeleLMeX_Evaluate.cpp @@ -14,7 +14,7 @@ PeleLM::Evaluate() // of the container and entries names int ncomp = 0; Vector plt_VarsName; - for (int ivar = 0; ivar < m_evaluatePlotVarCount; ivar++) { + for (int ivar = 0; ivar < m_evaluatePlotVarCount; ++ivar) { bool itexists = derive_lst.canDerive(m_evaluatePlotVars[ivar]) || evaluate_lst.canDerive(m_evaluatePlotVars[ivar]) || isStateVariable(m_evaluatePlotVars[ivar]); @@ -25,13 +25,13 @@ PeleLM::Evaluate() if (derive_lst.canDerive(m_evaluatePlotVars[ivar])) { const PeleLMDeriveRec* rec = derive_lst.get(m_evaluatePlotVars[ivar]); ncomp += rec->numDerive(); - for (int dvar = 0; dvar < rec->numDerive(); dvar++) { + for (int dvar = 0; dvar < rec->numDerive(); ++dvar) { plt_VarsName.push_back(rec->variableName(dvar)); } } else if (evaluate_lst.canDerive(m_evaluatePlotVars[ivar])) { const PeleLMDeriveRec* rec = evaluate_lst.get(m_evaluatePlotVars[ivar]); ncomp += rec->numDerive(); - for (int dvar = 0; dvar < rec->numDerive(); dvar++) { + for (int dvar = 0; dvar < rec->numDerive(); ++dvar) { plt_VarsName.push_back(rec->variableName(dvar)); } } else if (isStateVariable(m_evaluatePlotVars[ivar])) { @@ -56,7 +56,7 @@ PeleLM::Evaluate() //---------------------------------------------------------------- // Fill the outgoing container int cnt = 0; - for (int ivar = 0; ivar < m_evaluatePlotVarCount; ivar++) { + for (int ivar = 0; ivar < m_evaluatePlotVarCount; ++ivar) { int cntIncr = 0; Print() << " --> Evaluating " << m_evaluatePlotVars[ivar] << "\n"; @@ -267,7 +267,7 @@ PeleLM::evaluateChemExtForces( m_dt = computeDt(0, AmrOldTime); // Update time vectors - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { m_t_old[lev] = m_cur_time; m_t_new[lev] = m_cur_time + m_dt; } @@ -373,7 +373,7 @@ PeleLM::evaluateAdvectionTerms( m_dt = computeDt(0, AmrOldTime); // Update time vectors - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { m_t_old[lev] = m_cur_time; m_t_new[lev] = m_cur_time + m_dt; } diff --git a/Source/PeleLMeX_FlowController.cpp b/Source/PeleLMeX_FlowController.cpp index 19d4d5f67..e76b65c74 100644 --- a/Source/PeleLMeX_FlowController.cpp +++ b/Source/PeleLMeX_FlowController.cpp @@ -102,7 +102,7 @@ PeleLM::initActiveControl() // Compute some active control parameters Real area_tot = 1.0; - for (int idim{0}; idim < AMREX_SPACEDIM; idim++) { + for (int idim{0}; idim < AMREX_SPACEDIM; ++idim) { if (idim != m_ctrl_flameDir) { area_tot *= (Geom(0).ProbHi(idim) - Geom(0).ProbLo(idim)); } @@ -204,7 +204,7 @@ PeleLM::activeControl(int is_restart) if (m_ctrl_nfilled <= 0) { Real velIntegral = 0.0; for (int n = 1; n <= m_ctrl_NavgPts; - n++) { // Piecewise constant velocity over NavgPts last steps + ++n) { // Piecewise constant velocity over NavgPts last steps velIntegral += 0.5 * (m_ctrl_velo_pts[n - 1] + m_ctrl_velo_pts[n]) * (m_ctrl_time_pts[n - 1] - m_ctrl_time_pts[n]); } @@ -308,7 +308,7 @@ PeleLM::activeControl(int is_restart) void PeleLM::getActiveControlLowT(Real& a_coft) { - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { // Get t^{n+1} data pointer auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); @@ -444,7 +444,7 @@ PeleLM::loadActiveControlHistory() } if (m_ctrl_verbose != 0) { Print() << " AC history arrays: \n"; - for (long int n = 0; n < m_ctrl_time_pts.size(); n++) { + for (long int n = 0; n < m_ctrl_time_pts.size(); ++n) { Print() << " [" << n << "] time: " << m_ctrl_time_pts[n] << ", velo: " << m_ctrl_velo_pts[n] << ", coft: " << m_ctrl_cntl_pts[n] << "\n"; diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 8356c5e14..728ca9c56 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -100,7 +100,7 @@ PeleLM::getVelForces( [incomp_rho_inv, is_incomp, add_gradP, has_divTau, rho_arr, gp_arr, divTau_arr, force_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (is_incomp != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if (add_gradP != 0) { force_arr(i, j, k, idim) -= gp_arr(i, j, k, idim); } @@ -110,7 +110,7 @@ PeleLM::getVelForces( force_arr(i, j, k, idim) *= incomp_rho_inv; } } else { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if (add_gradP != 0) { force_arr(i, j, k, idim) -= gp_arr(i, j, k, idim); } @@ -126,11 +126,11 @@ PeleLM::getVelForces( bx, [incomp_rho_inv, is_incomp, rho_arr, force_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (is_incomp != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { force_arr(i, j, k, idim) *= incomp_rho_inv; } } else { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { force_arr(i, j, k, idim) /= rho_arr(i, j, k); } } @@ -175,8 +175,8 @@ PeleLM::getVelForces( void PeleLM::addSpark(const TimeStamp& a_timestamp) { - for (int lev = 0; lev <= finest_level; lev++) { - for (int n = 0; n < m_n_sparks; n++) { + for (int lev = 0; lev <= finest_level; ++lev) { + for (int n = 0; n < m_n_sparks; ++n) { // Do the checks first Real time = getTime(lev, a_timestamp); bool verb = m_spark_verbose > 1 && lev == 0; @@ -191,7 +191,7 @@ PeleLM::addSpark(const TimeStamp& a_timestamp) const Real* probLo = geom[lev].ProbLo(); auto const dx = geom[lev].CellSizeArray(); IntVect spark_idx; - for (int d = 0; d < AMREX_SPACEDIM; d++) { + for (int d = 0; d < AMREX_SPACEDIM; ++d) { spark_idx[d] = (int)((m_spark_location[n][d] - probLo[d]) / dx[d]); } Box domainBox = geom[lev].Domain(); @@ -223,7 +223,7 @@ PeleLM::addSpark(const TimeStamp& a_timestamp) Real rhoh_src_loc = 0; Real rho = statema[box_no](i, j, k, DENSITY); Real Y[NUM_SPECIES]; - for (int ns = 0; ns < NUM_SPECIES; ns++) { + for (int ns = 0; ns < NUM_SPECIES; ++ns) { Y[ns] = statema[box_no](i, j, k, FIRSTSPEC + ns) / rho; } eos.TY2H(spark_temp, Y, rhoh_src_loc); @@ -279,7 +279,7 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { grad_fc[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], 1, nGrow, MFInfo(), factory); @@ -292,7 +292,7 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) do_avgDown, var_of_scalar); // Add in Production and Dissipation source terms for subfilter variances - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_timestamp); @@ -414,7 +414,7 @@ PeleLM::getExternalSources( // User defined external sources if (m_user_defined_ext_sources) { - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p_old = getLevelDataPtr(lev, a_timestamp_old); auto* ldata_p_new = getLevelDataPtr(lev, a_timestamp_new); auto& ext_src = m_extSource[lev]; diff --git a/Source/PeleLMeX_Init.cpp b/Source/PeleLMeX_Init.cpp index 50ae66dbb..3d2358494 100644 --- a/Source/PeleLMeX_Init.cpp +++ b/Source/PeleLMeX_Init.cpp @@ -426,7 +426,7 @@ PeleLM::projectInitSolution() //---------------------------------------------------------------- // Initial velocity projection iterations - for (int iter = 0; iter < m_numDivuIter; iter++) { + for (int iter = 0; iter < m_numDivuIter; ++iter) { if (m_do_react != 0) { // The new level data has been filled above // Copy new -> old since old used in advanceChemistry @@ -506,7 +506,7 @@ PeleLM::initialIterations() //---------------------------------------------------------------- // Initial pressure iterations - for (int iter = 0; iter < m_init_iter; iter++) { + for (int iter = 0; iter < m_init_iter; ++iter) { if (m_verbose > 0) { amrex::Print() << "\n ================ INITIAL ITERATION [" << iter @@ -532,7 +532,7 @@ PeleLM::InitFromGridFile(amrex::Real time) MakeNewLevelFromScratch(0, time, ba, dm); } finest_level = static_cast(m_initial_ba.size()); - for (int lev = 1; lev <= finest_level; lev++) { + for (int lev = 1; lev <= finest_level; ++lev) { const amrex::BoxArray ba = m_initial_ba[lev - 1]; DistributionMapping dm(ba); MakeNewLevelFromScratch(lev, time, ba, dm); diff --git a/Source/PeleLMeX_K.H b/Source/PeleLMeX_K.H index 8567ee637..ad7b876b0 100644 --- a/Source/PeleLMeX_K.H +++ b/Source/PeleLMeX_K.H @@ -38,12 +38,12 @@ getTransportCoeff( // Get rho & Y from rhoY amrex::Real rho = 0.0_rt; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rho += rhoY(i, j, k, n); } amrex::Real rhoinv = 1.0_rt / rho; amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } @@ -76,26 +76,26 @@ getTransportCoeff( eos.TY2Cp(T(i, j, k), y, cpmix_cgs); lambda(i, j, k) = PrInv * c2m::Cp(cpmix_cgs) * mu(i, j, k); amrex::Real ScInv = PrInv * LeInv; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoDi(i, j, k, n) = ScInv * mu(i, j, k); } } else if (do_fixed_Pr) { // fixed Pr, still use species diffs amrex::Real cpmix_cgs = 0.0_rt; eos.TY2Cp(T(i, j, k), y, cpmix_cgs); lambda(i, j, k) = PrInv * c2m::Cp(cpmix_cgs) * mu(i, j, k); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoDi(i, j, k, n) = rhoDi_cgs[n] * Wbar * mwtinv[n] * 1.0e-1_rt; } } else if (do_fixed_Le) { // fixed Le, still use thermal cond lambda(i, j, k) = c2m::Lambda(lambda_cgs); amrex::Real cpmix_cgs = 0.0_rt; eos.TY2Cp(T(i, j, k), y, cpmix_cgs); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoDi(i, j, k, n) = lambda_cgs * 1.0e-1_rt * LeInv / cpmix_cgs; } } else { // full MA model, with Soret if needed lambda(i, j, k) = c2m::Lambda(lambda_cgs); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoDi(i, j, k, n) = rhoDi_cgs[n] * Wbar * mwtinv[n] * 1.0e-1_rt; if (do_soret) { rhotheta(i, j, k, n) = -rhoDi_cgs[n] * chi_loc[n] * 1.0e-1_rt; @@ -147,7 +147,7 @@ getTransportCoeff( amrex::Real rho, rhoinv; amrex::Real y[NUM_SPECIES] = {0.0}; amrex::Real massdens[NUM_SPECIES]; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { massdens[n] = rhoY(i, j, k, n); } auto eos = pele::physics::PhysicsType::eos(eosparm); @@ -172,7 +172,7 @@ getTransportCoeff( dummy_chi, mu_cgs, dummy_xi, lambda_cgs, trans_parm); // Do CGS -> MKS conversions - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoDi(i, j, k, n) = rhoDi_cgs[n] * 1.0e-1_rt; } lambda(i, j, k) = 0.0; // No need to carry lambda for manifold @@ -197,7 +197,7 @@ getVelViscosity( // Get rho & Y from rhoY amrex::Real massdens[NUM_SPECIES]; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { massdens[n] = rhoY(i, j, k, n); } amrex::Real rho = 0.0_rt, rhoinv = 0.0_rt, y[NUM_SPECIES] = {0.0}; @@ -246,7 +246,7 @@ getPGivenRTY( amrex::Real rho_cgs = m2c::Rho(rho(i, j, k)); amrex::Real y[NUM_SPECIES] = {0.0_rt}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } amrex::Real P_cgs = 0.0; @@ -281,12 +281,12 @@ compute_divu( // Get rho & Y from rhoY amrex::Real rho = 0.0_rt; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rho += rhoY(i, j, k, n); } amrex::Real rhoinv = 1.0_rt / rho; amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } @@ -298,7 +298,7 @@ compute_divu( eos.T2Hi(T(i, j, k), hi_cgs); amrex::Real cpmix = c2m::Cp(cpmix_cgs); // CGS -> MKS conversion amrex::Real hi[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { hi[n] = c2m::H(hi_cgs[n]); // CGS -> MKS conversion } @@ -306,7 +306,7 @@ compute_divu( amrex::Real denominv = 1.0_rt / (rho * cpmix * T(i, j, k)); divu(i, j, k) = (specEnthDiff(i, j, k) + tempDiff(i, j, k) + extRhoH(i, j, k)) * denominv; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { amrex::Real specTerm = specDiff(i, j, k, n) + extRhoY(i, j, k, n); if (do_react != 0) { specTerm += rhoYdot(i, j, k, n); @@ -340,7 +340,7 @@ compute_divu( amrex::Real rho, rhoinv; amrex::Real y[NUM_SPECIES] = {0.0_rt}; amrex::Real massdens[NUM_SPECIES] = {0.0_rt}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { massdens[n] = rhoY(i, j, k, n); } @@ -353,7 +353,7 @@ compute_divu( divu(i, j, k) = 0.0; - for (int n = 0; n < MANIFOLD_DIM; n++) { + for (int n = 0; n < MANIFOLD_DIM; ++n) { derivs[n] *= 1.0e3; // Unit conversion CGS -> MKS divu(i, j, k) += derivs[n] * specDiff(i, j, k, n); if (do_react != 0) { @@ -387,7 +387,7 @@ extFluxDivergence_K( amrex::Real factor = scaling / vol(i, j, k); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { div(i, j, k, n) = AMREX_D_TERM( (fluxX(i + 1, j, k, n) - fluxX(i, j, k, n)), +(fluxY(i, j + 1, k, n) - fluxY(i, j, k, n)), @@ -421,7 +421,7 @@ EB_intFluxDivergence_K( amrex::Real factor = scaling / vol(i, j, k); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { div(i, j, k, n) = AMREX_D_TERM( (areax * afracX(i + 1, j, k) * fluxX(i + 1, j, k, n) - areax * afracX(i, j, k) * fluxX(i, j, k, n)), @@ -462,7 +462,7 @@ EB_intFluxDivergence_K( amrex::Real factor = scaling / vol(i, j, k); amrex::Real eb_area = AMREX_D_TERM(1.0, *a_dx, *a_dx) * ebAreaFrac(i, j, k); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { div(i, j, k, n) = AMREX_D_TERM( (areax * afracX(i + 1, j, k) * fluxX(i + 1, j, k, n) - areax * afracX(i, j, k) * fluxX(i, j, k, n)), @@ -496,7 +496,7 @@ intFluxDivergence_K( amrex::Real factor = scaling / vol(i, j, k); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { div(i, j, k, n) = AMREX_D_TERM( (areax * fluxX(i + 1, j, k, n) - areax * fluxX(i, j, k, n)), +(areay * fluxY(i, j + 1, k, n) - areay * fluxY(i, j, k, n)), @@ -528,7 +528,7 @@ intFluxDivergence_rz_K( amrex::Real factor = scaling / vol(i, j, k); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { div(i, j, k, n) = (ax(i + 1, j, k) * fluxX(i + 1, j, k, n) - ax(i, j, k) * fluxX(i, j, k, n)) + (ay(i, j + 1, k) * fluxY(i, j + 1, k, n) - @@ -556,7 +556,7 @@ getMwmixGivenRY( auto eos = pele::physics::PhysicsType::eos(eosparm); amrex::Real rhoinv = 1.0_rt / rho(i, j, k); amrex::Real y[NUM_SPECIES] = {0.0_rt}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } @@ -583,7 +583,7 @@ getGradMwmixGivengradYMwmix( amrex::Real imw[NUM_SPECIES] = {0.0_rt}; eos.inv_molecular_weight(imw); gradMwmix(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { imw[n] *= 1000.0; // CGS -> MKS gradMwmix(i, j, k) += gradY(i, j, k, n) * imw[n]; } @@ -623,7 +623,7 @@ cen2edg_cpp( id_h[dir] -= 1; } if (do_harmonic) { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { if ( (cfab(id_l[0], id_l[1], id_l[2], n) * cfab(id_h[0], id_h[1], id_h[2], n)) > 0.0_rt) { @@ -637,7 +637,7 @@ cen2edg_cpp( } } } else { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { efab(i, j, k, n) = 0.5_rt * (cfab(id_l[0], id_l[1], id_l[2], n) + cfab(id_h[0], id_h[1], id_h[2], n)); } @@ -676,14 +676,14 @@ repair_flux( amrex::Real sumFlux = 0.0_rt; amrex::Real sumRhoYe = 0.0_rt; amrex::Real RhoYe[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { sumFlux += flux(i, j, k, n); RhoYe[n] = 0.5_rt * (rhoY(id_l[0], id_l[1], id_l[2], n) + rhoY(id_h[0], id_h[1], id_h[2], n)); sumRhoYe += RhoYe[n]; } sumRhoYe = 1.0_rt / sumRhoYe; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { flux(i, j, k, n) -= sumFlux * RhoYe[n] * sumRhoYe; } } @@ -712,7 +712,7 @@ repair_flux_eb( amrex::Real sumFlux = 0.0_rt; amrex::Real sumRhoYe = 0.0_rt; amrex::Real RhoYe[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { sumFlux += flux(i, j, k, n); RhoYe[n] = rhoYed(i, j, k, n); if (on_lo) { @@ -724,11 +724,11 @@ repair_flux_eb( sumRhoYe += RhoYe[n]; } sumRhoYe = 1.0_rt / sumRhoYe; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { flux(i, j, k, n) -= sumFlux * RhoYe[n] * sumRhoYe; } } else { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { flux(i, j, k, n) = 0.0_rt; } } @@ -751,7 +751,7 @@ getHGivenT( auto eos = pele::physics::PhysicsType::eos(eosparm); amrex::Real hi_spec[NUM_SPECIES] = {0.0_rt}; eos.T2Hi(T(i, j, k), hi_spec); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { Hi(i, j, k, n) = hi_spec[n] * 0.0001_rt; // CGS -> MKS conversion } } @@ -792,7 +792,7 @@ makeVelForce( } // Gravity and background pressure gradient - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { force(i, j, k, idim) = -gp0[idim] + gravity[idim] * rho_lcl; } @@ -801,7 +801,7 @@ makeVelForce( force(i, j, k, pseudo_gravity_dir) += dV_control * rho_lcl; } - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { force(i, j, k, idim) += extmom(i, j, k, idim) - vel(i, j, k, idim) * extrho(i, j, k); } @@ -827,7 +827,7 @@ getRHmixGivenTY( auto eos = pele::physics::PhysicsType::eos(eosparm); amrex::Real rhoinv = 1.0_rt / rho(i, j, k); amrex::Real y[NUM_SPECIES] = {0.0_rt}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } amrex::Real hmix_cgs = 0.0; @@ -854,7 +854,7 @@ getTfromHY( auto eos = pele::physics::PhysicsType::eos(eosparm); amrex::Real rhoinv = 1.0_rt / rho(i, j, k); amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } amrex::Real h_cgs = m2c::H(rhoH(i, j, k) * rhoinv); @@ -882,7 +882,7 @@ getCpmixGivenRYT( auto eos = pele::physics::PhysicsType::eos(eosparm); amrex::Real rhoinv = 1.0_rt / rho(i, j, k); amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } amrex::Real cpmix_cgs = 0.0; @@ -929,7 +929,7 @@ buildAdvectionForcing( amrex::Real y[NUM_SPECIES] = {0.0}; forceT(i, j, k) = dn(i, j, k, NUM_SPECIES) + ddn(i, j, k); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; // get y forceY(i, j, k, n) = dn(i, j, k, n); // forceY = Dnk if (do_react != 0) { @@ -947,7 +947,7 @@ buildAdvectionForcing( forceT(i, j, k) += dp0dt; // Add dp0/dt } - for (int n = 0; n < nAux; n++) { + for (int n = 0; n < nAux; ++n) { if (aux_diffuse[n] != 0) { forceAux(i, j, k, n) = dn_aux(i, j, k, n); } else { @@ -996,7 +996,7 @@ buildDiffusionForcing( { using namespace amrex::literals; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { forceY(i, j, k, n) = a(i, j, k, n) + 0.5_rt * (dn(i, j, k, n) - dnp1k(i, j, k, n)) + extRhoY(i, j, k, n); @@ -1019,7 +1019,7 @@ buildDiffusionForcing( forceT(i, j, k) += dp0dt; } - for (int n = 0; n < nAux; n++) { + for (int n = 0; n < nAux; ++n) { forceAux(i, j, k, n) = 0.0; if (aux_diffuse[n] != 0) { forceAux(i, j, k, n) += @@ -1064,7 +1064,7 @@ reactionRateRhoY( amrex::Real rho_cgs = m2c::Rho(rho); // rho MKS -> CGS amrex::Real wdot[NUM_SPECIES] = {0.0_rt}; eos.RTY2WDOT(rho_cgs, Tloc, y, wdot); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoYdot(i, j, k, n) = wdot[n] * 1000.0_rt; // CGS -> MKS conversion } } @@ -1083,7 +1083,7 @@ fabMinMax( { using namespace amrex::literals; - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { fab(i, j, k, n) = amrex::max(fmin, amrex::min(fmax, fab(i, j, k, n))); } } @@ -1214,12 +1214,12 @@ getGammaInv( auto eos = pele::physics::PhysicsType::eos(eosparm); // Get rho & Y from rhoY amrex::Real rho = 0.0_rt; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rho += rhoY(i, j, k, n); } amrex::Real rhoinv = 1.0_rt / rho; amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } diff --git a/Source/PeleLMeX_ODEQty.cpp b/Source/PeleLMeX_ODEQty.cpp index 44bd75df2..15fa68b04 100644 --- a/Source/PeleLMeX_ODEQty.cpp +++ b/Source/PeleLMeX_ODEQty.cpp @@ -9,13 +9,13 @@ PeleLM::predictODEQty() { // Uses forward Euler to predict values for ODE qty at tnp1 // If m_ext_sources_SDC = false, no SDC corrections used - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto const& state_arrs = getLevelDataPtr(lev, AmrNewTime)->state.arrays(); auto const& ext_src_arrs = m_extSource[lev]->arrays(); ParallelFor( *m_extSource[lev], [state_arrs, ext_src_arrs, dt = m_dt] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < NUM_ODE; n++) { + for (int n = 0; n < NUM_ODE; ++n) { Real const& B_n = state_arrs[box_no](i, j, k, FIRSTODE + n); Real const& S_ext_n = ext_src_arrs[box_no](i, j, k, FIRSTODE + n); state_arrs[box_no](i, j, k, FIRSTODE + n) = B_n + dt * S_ext_n; diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 69dcc992d..b53f648d4 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -40,7 +40,7 @@ PeleLM::WriteDebugPlotFile( { int nComp = a_MF[0]->nComp(); Vector names(nComp); - for (int n = 0; n < nComp; n++) { + for (int n = 0; n < nComp; ++n) { names[n] = "comp" + std::to_string(n); } Vector istep(finest_level + 1, m_nstep); @@ -144,7 +144,7 @@ PeleLM::WritePlotFile() // Derive int deriveEntryCount = 0; - for (int ivar = 0; ivar < m_derivePlotVarCount; ivar++) { + for (int ivar = 0; ivar < m_derivePlotVarCount; ++ivar) { const PeleLMDeriveRec* rec = derive_lst.get(m_derivePlotVars[ivar]); deriveEntryCount += rec->numDerive(); } @@ -192,7 +192,7 @@ PeleLM::WritePlotFile() if (m_incompressible == 0) { plt_VarsName.push_back("density"); if (m_plotStateSpec != 0) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { plt_VarsName.push_back("rho.Y(" + names[n] + ")"); } } @@ -204,7 +204,7 @@ PeleLM::WritePlotFile() plt_VarsName.push_back("phiV"); #endif #ifdef PELE_USE_SOOT - for (int mom = 0; mom < NUMSOOTVAR; mom++) { + for (int mom = 0; mom < NUMSOOTVAR; ++mom) { std::string sootname = soot_model->sootVariableName(mom); plt_VarsName.push_back(sootname); } @@ -227,12 +227,12 @@ PeleLM::WritePlotFile() , plt_VarsName.push_back("gradpz")); } - for (int n = 0; n < m_nAux; n++) { + for (int n = 0; n < m_nAux; ++n) { plt_VarsName.push_back(m_aux_names[n]); } if ((m_do_react != 0) && (m_skipInstantRR == 0) && (m_plot_react != 0)) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { plt_VarsName.push_back("I_R(" + names[n] + ")"); } #ifdef PELE_USE_PLASMA @@ -249,9 +249,9 @@ PeleLM::WritePlotFile() plt_VarsName.push_back("volFrac"); #endif - for (int ivar = 0; ivar < m_derivePlotVarCount; ivar++) { + for (int ivar = 0; ivar < m_derivePlotVarCount; ++ivar) { const PeleLMDeriveRec* rec = derive_lst.get(m_derivePlotVars[ivar]); - for (int dvar = 0; dvar < rec->numDerive(); dvar++) { + for (int dvar = 0; dvar < rec->numDerive(); ++dvar) { plt_VarsName.push_back(rec->variableName(dvar)); } } @@ -294,7 +294,7 @@ PeleLM::WritePlotFile() } #if NUM_ODE > 0 - for (int n = 0; n < NUM_ODE; n++) { + for (int n = 0; n < NUM_ODE; ++n) { plt_VarsName.push_back(m_ode_names[n]); } #endif @@ -388,7 +388,7 @@ PeleLM::WritePlotFile() cnt += 1; #endif - for (int ivar = 0; ivar < m_derivePlotVarCount; ivar++) { + for (int ivar = 0; ivar < m_derivePlotVarCount; ++ivar) { std::unique_ptr mf; mf = derive(m_derivePlotVars[ivar], m_cur_time, lev, 0); MultiFab::Copy(mf_plt[lev], *mf, 0, cnt, mf->nComp(), 0); @@ -720,7 +720,7 @@ PeleLM::ReadCheckPointFile() std::istringstream lis(line); int i = 0; while (lis >> word) { - prob_lo[i++] = std::stod(word); + prob_lo[++i] = std::stod(word); } } @@ -730,7 +730,7 @@ PeleLM::ReadCheckPointFile() std::istringstream lis(line); int i = 0; while (lis >> word) { - prob_hi[i++] = std::stod(word); + prob_hi[++i] = std::stod(word); } } @@ -956,10 +956,10 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) // in case the number of species differs. MultiFab speciesPlt(grids[a_lev], dmap[a_lev], nSpecPlt, 0); pltData.fillPatchFromPlt(a_lev, geom[a_lev], idY, 0, nSpecPlt, speciesPlt); - for (int i = 0; i < NUM_SPECIES; i++) { + for (int i = 0; i < NUM_SPECIES; ++i) { std::string specString = "Y(" + spec_names[i] + ")"; int foundSpec = 0; - for (int iplt = 0; iplt < nSpecPlt; iplt++) { + for (int iplt = 0; iplt < nSpecPlt; ++iplt) { if (specString == plt_vars[idY + iplt]) { MultiFab::Copy(ldata_p->state, speciesPlt, iplt, FIRSTSPEC + i, 1, 0); foundSpec = 1; @@ -981,7 +981,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) auto const& vel_arr = ldata_p->state.array(mfi, VELX); amrex::ParallelFor( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; n++) { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { amrex::Real vel_mks = vel_arr(i, j, k, n) * 0.01; vel_arr(i, j, k, n) = vel_mks; } @@ -1013,7 +1013,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) auto const& soot_arr = ldata_p->state.array(mfi, FIRSTSOOT); amrex::ParallelFor( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SOOT_MOMENTS; n++) { + for (int n = 0; n < NUM_SOOT_MOMENTS; ++n) { amrex::Real soot_exp = 3. - (3. * momV[n] + 2. * momS[n]); soot_arr(i, j, k, n) *= std::pow(100., soot_exp); } @@ -1063,7 +1063,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) auto eos = pele::physics::PhysicsType::eos(eosparm); Real massfrac[NUM_SPECIES] = {0.0}; Real sumYs = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { massfrac[n] = rhoY_arr(i, j, k, n); #ifdef N2_ID if (n != N2_ID) { @@ -1087,7 +1087,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) rhoH_arr(i, j, k) = h_cgs * 1.0e-4 * rho_arr(i, j, k); // Fill rhoYs - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoY_arr(i, j, k, n) = massfrac[n] * rho_arr(i, j, k); } }); @@ -1168,11 +1168,11 @@ PeleLM::WriteJobInfo(const std::string& path) const jobInfoFile << " Grid Information\n"; jobInfoFile << PrettyLine; - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { jobInfoFile << " level: " << lev << "\n"; jobInfoFile << " number of boxes = " << grids[lev].size() << "\n"; jobInfoFile << " maximum zones = "; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { jobInfoFile << geom[lev].Domain().length(idim) << " "; } jobInfoFile << "\n\n"; diff --git a/Source/PeleLMeX_ProblemSpecificFunctions.H b/Source/PeleLMeX_ProblemSpecificFunctions.H index cc64d7bc9..aae57e459 100644 --- a/Source/PeleLMeX_ProblemSpecificFunctions.H +++ b/Source/PeleLMeX_ProblemSpecificFunctions.H @@ -181,7 +181,7 @@ struct DefaultProblemSpecificFunctions { #if NUM_ODE > 0 a_ode_names.resize(NUM_ODE); - for (int n = 0; n < NUM_ODE; n++) { + for (int n = 0; n < NUM_ODE; ++n) { a_ode_names[n] = "ODE_" + std::to_string(n); } #else @@ -220,7 +220,7 @@ struct DefaultProblemSpecificFunctions * ParallelFor( * *ext_src, * [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - * for (int n = 0; n < NUM_ODE; n++) { + * for (int n = 0; n < NUM_ODE; ++n) { * Real B_n = state_old_arr[box_no](i, j, k, FIRSTODE + n); * Real src = -1.0 * pow(10.0, n + 1) * B_n; * ext_src_arr[box_no](i, j, k, FIRSTODE + n) += src; diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 04599206c..16fd260a0 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -89,7 +89,7 @@ PeleLM::initialProjection() // Set back press and gpress to zero and restore divu // and rescale velocity if 2D-RZ - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); ldata_p->press.setVal(0.0); ldata_p->gp.setVal(0.0); @@ -394,7 +394,7 @@ PeleLM::doNodalProject( // BCs std::array lobc; std::array hibc; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if (Geom(0).isPeriodic(idim)) { lobc[idim] = hibc[idim] = LinOpBCType::Periodic; } else { @@ -454,7 +454,7 @@ PeleLM::doNodalProject( auto phi = nodal_projector->getPhi(); auto gphi = nodal_projector->getGradPhi(); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); diff --git a/Source/PeleLMeX_Radiation.cpp b/Source/PeleLMeX_Radiation.cpp index 50f449dab..06e2d8a1a 100644 --- a/Source/PeleLMeX_Radiation.cpp +++ b/Source/PeleLMeX_Radiation.cpp @@ -42,7 +42,7 @@ PeleLM::computeRadSource(const PeleLM::TimeStamp& a_timestamp) int const coIndx = rad_model->readRadIndices().coIndx; BL_PROFILE_VAR("PeleLM::advance::rad::spec", PLM_RAD_SPEC); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = PeleLM::getLevelDataPtr(lev, a_timestamp); #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) @@ -72,7 +72,7 @@ PeleLM::computeRadSource(const PeleLM::TimeStamp& a_timestamp) BL_PROFILE_VAR("PeleLM::advance::rad::solve", PLM_RAD_SOLV); rad_model->evaluateRad(); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif diff --git a/Source/PeleLMeX_Reactions.cpp b/Source/PeleLMeX_Reactions.cpp index f0998767b..e18160673 100644 --- a/Source/PeleLMeX_Reactions.cpp +++ b/Source/PeleLMeX_Reactions.cpp @@ -69,7 +69,7 @@ PeleLM::advanceChemistry(int lev, const Real& a_dt, MultiFab& a_extForcing) ParallelFor( bx, [rhoY_o, rhoH_o, temp_o, rhoY_n, rhoH_n, temp_n, extF_rhoY, extF_rhoH] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoY_n(i, j, k, n) = rhoY_o(i, j, k, n) * 1.0e-3; extF_rhoY(i, j, k, n) *= 1.0e-3; } @@ -111,7 +111,7 @@ PeleLM::advanceChemistry(int lev, const Real& a_dt, MultiFab& a_extForcing) ParallelFor( bx, [rhoY_n, rhoH_n, extF_rhoY, extF_rhoH] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoY_n(i, j, k, n) *= 1.0e3; extF_rhoY(i, j, k, n) *= 1.0e3; } @@ -231,7 +231,7 @@ PeleLM::advanceChemistryBAChem( ParallelFor( bx, [rhoY_o, rhoH_o, extF_rhoY, extF_rhoH] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoY_o(i, j, k, n) *= 1.0e-3; extF_rhoY(i, j, k, n) *= 1.0e-3; } @@ -282,7 +282,7 @@ PeleLM::advanceChemistryBAChem( // Convert CGS -> MKS ParallelFor( bx, [rhoY_o, rhoH_o] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoY_o(i, j, k, n) *= 1.0e3; } rhoH_o(i, j, k) *= 0.1; @@ -334,13 +334,13 @@ PeleLM::advanceChemistryBAChem( bx, [state_arr, rhoY_o, rhoY_n, rhoH_n, temp_n, extF_rhoY, rhoYdot, dt_inv] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Pass into leveldata_new - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoY_n(i, j, k, n) = state_arr(i, j, k, n); } rhoH_n(i, j, k) = state_arr(i, j, k, NUM_SPECIES); temp_n(i, j, k) = state_arr(i, j, k, NUM_SPECIES + 1); // Compute I_R - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoYdot(i, j, k, n) = -(rhoY_o(i, j, k, n) - rhoY_n(i, j, k, n)) * dt_inv - extF_rhoY(i, j, k, n); @@ -415,7 +415,7 @@ PeleLM::computeInstantaneousReactionRate( bx, [rhoY, rhoH, T, rhoYdot, flag, leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (flag(i, j, k).isCovered()) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoYdot(i, j, k, n) = 0.0; } } else { @@ -463,7 +463,7 @@ PeleLM::getScalarReactForce(std::unique_ptr& advData) amrex::ParallelFor( bx, [rhoY_o, rhoH_o, rhoY_n, rhoH_n, react, extF_rhoY, extF_rhoH, dtinv] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { extF_rhoY(i, j, k, n) = (rhoY_n(i, j, k, n) - rhoY_o(i, j, k, n)) * dtinv - react(i, j, k, n); @@ -497,7 +497,7 @@ PeleLM::getHeatRelease(int a_lev, MultiFab* a_HR) leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { getHGivenT(i, j, k, T, Hi, leosparm); HRR(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { HRR(i, j, k) -= Hi(i, j, k, n) * react(i, j, k, n); } }); diff --git a/Source/PeleLMeX_Setup.cpp b/Source/PeleLMeX_Setup.cpp index 10a55854a..c7710d080 100644 --- a/Source/PeleLMeX_Setup.cpp +++ b/Source/PeleLMeX_Setup.cpp @@ -156,7 +156,7 @@ PeleLM::Setup() #ifdef PELE_USE_PLASMA pele::physics::eos::charge_mass(zk.arr); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { zk[n] *= 1000.0; // CGS->MKS } #endif @@ -241,7 +241,7 @@ PeleLM::readParameters() // Boundary conditions // ----------------------------------------- int isOpenDomain = 0; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { int lo_bc = BoundaryCondition::BCInterior; int hi_bc = BoundaryCondition::BCInterior; parseUserKey(pp, "lo_bc", boundarycondition, lo_bc, idim); @@ -271,7 +271,7 @@ PeleLM::readParameters() Vector hi_bc_char(AMREX_SPACEDIM); ppef.getarr("phiV_lo_bc", lo_bc_char, 0, AMREX_SPACEDIM); ppef.getarr("phiV_hi_bc", hi_bc_char, 0, AMREX_SPACEDIM); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if (lo_bc_char[idim] == "Interior") { m_phiV_bc.setLo(idim, 0); } else if (lo_bc_char[idim] == "Dirichlet") { @@ -295,7 +295,7 @@ PeleLM::readParameters() // Get the polarity of BCs ppef.getarr("phiV_polarity_lo", lo_bc_char, 0, AMREX_SPACEDIM); ppef.getarr("phiV_polarity_hi", hi_bc_char, 0, AMREX_SPACEDIM); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if (lo_bc_char[idim] == "Neutral") { m_phiV_bcpol.setLo(idim, 0); } else if (lo_bc_char[idim] == "Anode") { // Pos. elec = 1 @@ -345,7 +345,7 @@ PeleLM::readParameters() pp.queryarr("gravity", grav, 0, AMREX_SPACEDIM); Vector gp0(AMREX_SPACEDIM, 0); pp.queryarr("gradP0", gp0, 0, AMREX_SPACEDIM); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_background_gp[idim] = gp0[idim]; m_gravity[idim] = grav[idim]; } @@ -367,7 +367,7 @@ PeleLM::readParameters() m_spark_temp.resize(m_n_sparks); m_spark_radius.resize(m_n_sparks); pp.query("spark_verbose", m_spark_verbose); - for (int n = 0; n < m_n_sparks; n++) { + for (int n = 0; n < m_n_sparks; ++n) { pp.get("sparks", m_spark[n], n); std::string spark_prefix = "peleLM." + m_spark[n]; ParmParse pps(spark_prefix); @@ -380,13 +380,13 @@ PeleLM::readParameters() } if (m_spark_verbose > 0) { Print() << "Spark list: \n"; - for (int n = 0; n < m_n_sparks; n++) { + for (int n = 0; n < m_n_sparks; ++n) { Print() << "Spark " << n << " name: " << m_spark[n] << "\n"; Print() << "Spark " << n << " time: " << m_spark_time[n] << "\n"; Print() << "Spark " << n << " duration: " << m_spark_duration[n] << "\n"; Print() << "Spark " << n << " location: "; - for (int d = 0; d < AMREX_SPACEDIM; d++) { + for (int d = 0; d < AMREX_SPACEDIM; ++d) { Print() << m_spark_location[n][d] << " "; } Print() << "\n Spark " << n << " temperature: " << m_spark_temp[n] @@ -404,7 +404,7 @@ PeleLM::readParameters() m_aux_advect.resize(m_nAux); m_DiffTypeAux.resize(m_nAux); m_aux_Schmidt.resize(m_nAux); - for (int n = 0; n < m_nAux; n++) { + for (int n = 0; n < m_nAux; ++n) { pp.get("aux_vars", m_aux_names[n], n); std::string aux_prefix = "peleLM." + m_aux_names[n]; ParmParse ppa(aux_prefix); @@ -460,7 +460,7 @@ PeleLM::readParameters() pp.query("use_wbar", m_use_wbar); if (m_use_soret != 0) { bool isothermal = false; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { isothermal |= (m_phys_bc.lo(idim) == BoundaryCondition::BCSlipWallIsotherm || m_phys_bc.lo(idim) == BoundaryCondition::BCNoSlipWallIsotherm || @@ -732,7 +732,7 @@ PeleLM::readParameters() m_evaluatePlotVarCount = (pp.countval("evaluate_vars")); if (m_evaluatePlotVarCount != 0) { m_evaluatePlotVars.resize(m_evaluatePlotVarCount); - for (int ivar = 0; ivar < m_evaluatePlotVarCount; ivar++) { + for (int ivar = 0; ivar < m_evaluatePlotVarCount; ++ivar) { pp.get("evaluate_vars", m_evaluatePlotVars[ivar], ivar); } } @@ -877,7 +877,7 @@ PeleLM::readIOParameters() m_derivePlotVarCount = (pp.countval("derive_plot_vars")); if (m_derivePlotVarCount != 0) { m_derivePlotVars.resize(m_derivePlotVarCount); - for (int ivar = 0; ivar < m_derivePlotVarCount; ivar++) { + for (int ivar = 0; ivar < m_derivePlotVarCount; ++ivar) { pp.get("derive_plot_vars", m_derivePlotVars[ivar], ivar); } } @@ -926,7 +926,7 @@ PeleLM::variablesSetup() Vector names; pele::physics::eos::speciesNames( names, &(eos_parms.host_parm())); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { stateComponents.emplace_back(FIRSTSPEC + n, "rho.Y(" + names[n] + ")"); reactComponents.emplace_back(n, "I_R(" + names[n] + ")"); } @@ -943,7 +943,7 @@ PeleLM::variablesSetup() stateComponents.emplace_back(PHIV, "PhiV"); #endif #ifdef PELE_USE_SOOT - for (int mom = 0; mom < NUMSOOTVAR; mom++) { + for (int mom = 0; mom < NUMSOOTVAR; ++mom) { std::string sootname = soot_model->sootVariableName(mom); Print() << " " << sootname << ": " << FIRSTSOOT + mom << "\n"; stateComponents.emplace_back(FIRSTSOOT + mom, sootname); @@ -976,7 +976,7 @@ PeleLM::variablesSetup() Print() << " => Total number of state variables: " << NVAR << "\n"; } if (m_nAux > 0) { - for (int n = 0; n < m_nAux; n++) { + for (int n = 0; n < m_nAux; ++n) { Print() << " Auxiliary " + std::to_string(n + 1) + ": " << m_aux_names[n] << "\n"; Print() << " Advective: " << m_aux_advect[n] << "\n"; @@ -1028,7 +1028,7 @@ PeleLM::variablesSetup() m_DiffTypeState[PHIV] = 0; #endif #ifdef PELE_USE_SOOT - for (int mom = 0; mom < NUMSOOTVAR; mom++) { + for (int mom = 0; mom < NUMSOOTVAR; ++mom) { m_AdvTypeState[FIRSTSOOT + mom] = 0; m_DiffTypeState[FIRSTSOOT + mom] = 0; } @@ -1095,11 +1095,11 @@ PeleLM::readGridFile( "You have fewer levels in your inputs file then in your grids file!"); } - for (int lev = 1; lev <= in_finest; lev++) { + for (int lev = 1; lev <= in_finest; ++lev) { BoxList bl; is >> ngrid; STRIP; - for (int i = 0; i < ngrid; i++) { + for (int i = 0; i < ngrid; ++i) { Box bx; is >> bx; STRIP; @@ -1127,14 +1127,14 @@ PeleLM::derivedSetup() // Set species mass fractions Vector var_names_massfrac(NUM_SPECIES); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { var_names_massfrac[n] = "Y(" + spec_names[n] + ")"; } derive_lst.add( "mass_fractions", IndexType::TheCellType(), NUM_SPECIES, var_names_massfrac, pelelmex_dermassfrac, the_same_box); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { var_names_massfrac[n] = "X(" + spec_names[n] + ")"; } derive_lst.add( @@ -1142,12 +1142,12 @@ PeleLM::derivedSetup() var_names_massfrac, pelelmex_dermolefrac, the_same_box); // Species diffusion coefficients - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { var_names_massfrac[n] = "D_" + spec_names[n]; } if (m_use_soret != 0) { var_names_massfrac.resize(2 * NUM_SPECIES); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { var_names_massfrac[n + NUM_SPECIES] = "theta_" + spec_names[n]; } derive_lst.add( @@ -1257,7 +1257,7 @@ PeleLM::derivedSetup() auto& mani_data = eos_parms.host_only_parm().manfunc_par->host_parm(); const int nmanivar = mani_data.Nvar; Vector var_names_maniout(nmanivar); - for (int n = 0; n < nmanivar; n++) { + for (int n = 0; n < nmanivar; ++n) { std::string nametmp = std::string( &(mani_data.varnames)[n * mani_data.len_str], mani_data.len_str); var_names_maniout[n] = "MANI_" + amrex::trim(nametmp); @@ -1353,7 +1353,7 @@ PeleLM::evaluateSetup() // scalar diffusion term { Vector var_names(NUM_SPECIES + 2); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { var_names[n] = "D(" + spec_names[n] + ")"; } var_names[NUM_SPECIES] = "D(RhoH)"; @@ -1371,7 +1371,7 @@ PeleLM::evaluateSetup() var_names[VELX] = "A(VELX)";, var_names[VELY] = "A(VELY)"; , var_names[VELZ] = "A(VELZ)"); var_names[DENSITY] = "A(Rho)"; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { var_names[FIRSTSPEC + n] = "A(" + spec_names[n] + ")"; } var_names[RHOH] = "A(RhoH)"; @@ -1382,12 +1382,12 @@ PeleLM::evaluateSetup() // Chemical state and external chem. forcing (used in ReactEval) { Vector var_names(2 * (NUM_SPECIES + 1) + 1); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { var_names[n] = "rhoY(" + spec_names[n] + ")"; } var_names[NUM_SPECIES] = "rhoH"; var_names[NUM_SPECIES + 1] = "Temp"; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { var_names[NUM_SPECIES + 2 + n] = "F_rhoY(" + spec_names[n] + ")"; } var_names[2 * NUM_SPECIES + 2] = "F_rhoH"; @@ -1399,7 +1399,7 @@ PeleLM::evaluateSetup() // instantaneous reaction rate { Vector var_names(NUM_SPECIES); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { var_names[n] = "I_R(" + spec_names[n] + ")"; } evaluate_lst.add( @@ -1409,7 +1409,7 @@ PeleLM::evaluateSetup() // cell-centered transport coefficients { Vector var_names(NUM_SPECIES + 2); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { var_names[n] = "rhoD(" + spec_names[n] + ")"; } var_names[NUM_SPECIES] = "Lamdba"; diff --git a/Source/PeleLMeX_Soot.cpp b/Source/PeleLMeX_Soot.cpp index 04e96d9fc..73abdcbfb 100644 --- a/Source/PeleLMeX_Soot.cpp +++ b/Source/PeleLMeX_Soot.cpp @@ -35,7 +35,7 @@ void PeleLM::computeSootSource(const PeleLM::TimeStamp& a_timestamp, const Real a_dt) { bool pres_term = false; // Do not include change in pressure in energy - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_timestamp); Real time = getTime(lev, a_timestamp); #ifdef AMREX_USE_OMP @@ -56,7 +56,7 @@ PeleLM::computeSootSource(const PeleLM::TimeStamp& a_timestamp, const Real a_dt) void PeleLM::clipSootMoments() { - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) @@ -68,11 +68,11 @@ PeleLM::clipSootMoments() amrex::ParallelFor( gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { GpuArray moments; - for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; mom++) { + for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; ++mom) { moments[mom] = state_arr(i, j, k, mom); } sd->momConvClipConv(moments.data()); - for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; mom++) { + for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; ++mom) { state_arr(i, j, k, mom) = moments[mom]; } }); diff --git a/Source/PeleLMeX_SprayParticles.cpp b/Source/PeleLMeX_SprayParticles.cpp index 539b63588..5908914c0 100644 --- a/Source/PeleLMeX_SprayParticles.cpp +++ b/Source/PeleLMeX_SprayParticles.cpp @@ -343,7 +343,7 @@ PeleLM::SprayPostRegrid() prev_source.resize(finest_level + 1); changed = true; } else { - for (int lev = 0; lev <= finest_level && !changed; lev++) { + for (int lev = 0; lev <= finest_level && !changed; ++lev) { if (ba_spray[lev] != grids[lev]) { changed = true; } diff --git a/Source/PeleLMeX_Temporals.cpp b/Source/PeleLMeX_Temporals.cpp index bf3e83c2a..064c0a50c 100644 --- a/Source/PeleLMeX_Temporals.cpp +++ b/Source/PeleLMeX_Temporals.cpp @@ -13,23 +13,23 @@ PeleLM::initTemporals(const PeleLM::TimeStamp& a_time) // Reset mass fluxes integrals on domain boundaries if ((m_do_massBalance != 0) && (m_incompressible == 0)) { m_massOld = MFSum(GetVecOfConstPtrs(getDensityVect(a_time)), 0); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_domainMassFlux[2 * idim] = 0.0; m_domainMassFlux[2 * idim + 1] = 0.0; } } if ((m_do_energyBalance != 0) && (m_incompressible == 0)) { m_RhoHOld = MFSum(GetVecOfConstPtrs(getRhoHVect(a_time)), 0); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_domainRhoHFlux[2 * idim] = 0.0; m_domainRhoHFlux[2 * idim + 1] = 0.0; } } if ((m_do_speciesBalance != 0) && (m_incompressible == 0)) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { m_RhoYOld[n] = MFSum(GetVecOfConstPtrs(getSpeciesVect(a_time)), n); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { m_domainRhoYFlux[2 * n * AMREX_SPACEDIM + 2 * idim] = 0.0; m_domainRhoYFlux[1 + 2 * n * AMREX_SPACEDIM + 2 * idim] = 0.0; } @@ -62,7 +62,7 @@ PeleLM::speciesBalancePatch() tmppatchmfrFile << m_nstep << "," << m_cur_time; // Time info for (const auto& m_bPatche : m_bPatches) { BPatch::BpatchDataContainer* bphost = m_bPatche->getHostDataPtr(); - for (int i = 0; i < bphost->num_species; i++) { + for (int i = 0; i < bphost->num_species; ++i) { tmppatchmfrFile << "," << bphost->speciesFlux[i]; } } @@ -77,7 +77,7 @@ PeleLM::speciesBalance() Array dmYdt; Array massYFluxBalance; Array rhoYdots; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { m_RhoYNew[n] = MFSum(GetVecOfConstPtrs(getSpeciesVect(AmrNewTime)), n); rhoYdots[n] = MFSum(GetVecOfConstPtrs(getIRVect()), n); dmYdt[n] = (m_RhoYNew[n] - m_RhoYOld[n]) / m_dt; @@ -91,7 +91,7 @@ PeleLM::speciesBalance() } tmpSpecFile << m_nstep << "," << m_cur_time; // Time info - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { tmpSpecFile << "," << m_RhoYNew[n] // mass of Y << "," << dmYdt[n] // mass temporal derivative << "," << massYFluxBalance[n] // domain boundaries mass fluxes @@ -130,7 +130,7 @@ PeleLM::addMassFluxes( area[2] = dx[0] * dx[1]; #endif - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { auto faceDomain = amrex::convert(a_geom.Domain(), IntVect::TheDimensionVector(idim)); @@ -156,14 +156,14 @@ PeleLM::addMassFluxes( // low Real low = 0.0; if (idx == faceDomain.smallEnd(idim)) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { low += flux(i, j, k, n) * area_ar(i, j, k); } } // high Real high = 0.0; if (idx == faceDomain.bigEnd(idim)) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { high += flux(i, j, k, n) * area_ar(i, j, k); } } @@ -185,14 +185,14 @@ PeleLM::addMassFluxes( // low Real low = 0.0; if (idx == faceDomain.smallEnd(idim)) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { low += flux(i, j, k, n) * area[idim]; } } // high Real high = 0.0; if (idx == faceDomain.bigEnd(idim)) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { high += flux(i, j, k, n) * area[idim]; } } @@ -229,7 +229,7 @@ PeleLM::addUmacFluxes( // Just use level 0 since we are calling after averaging down int lev = 0; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { auto faceDomain = amrex::convert(a_geom.Domain(), IntVect::TheDimensionVector(idim)); @@ -344,7 +344,7 @@ PeleLM::addRhoHFluxes( area[2] = dx[0] * dx[1]; #endif - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { auto faceDomain = amrex::convert(a_geom.Domain(), IntVect::TheDimensionVector(idim)); @@ -442,9 +442,9 @@ PeleLM::addRhoYFluxes( #endif // Outer loop over species - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { // Inner loop over dimensions - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { auto faceDomain = amrex::convert(a_geom.Domain(), IntVect::TheDimensionVector(idim)); @@ -582,7 +582,7 @@ PeleLM::addRhoYFluxesPatch( auto const& fma = a_fluxes[idim]->const_arrays(); // Loop through species specified by user - for (int m = 0; m < bphost->num_species; m++) { + for (int m = 0; m < bphost->num_species; ++m) { Real sum_species_flux_global = 0.0; @@ -737,7 +737,7 @@ PeleLM::openTempFile() std::ios::out | std::ios::app | std::ios_base::binary); tmpSpecFile.precision(12); tmpSpecFile << "iter,time"; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { tmpSpecFile << ",rhoYnew_" << PeleLM::stateVariableName(FIRSTSPEC + n); tmpSpecFile << ",drhoYdt_" << PeleLM::stateVariableName(FIRSTSPEC + n); tmpSpecFile << ",netFlux_" << PeleLM::stateVariableName(FIRSTSPEC + n); @@ -769,7 +769,7 @@ PeleLM::openTempFile() for (const auto& m_bPatche : m_bPatches) { BPatch* patch = m_bPatche.get(); BPatch::BpatchDataContainer bphost = patch->getHostData(); - for (int i = 0; i < bphost.num_species; i++) { + for (int i = 0; i < bphost.num_species; ++i) { tmppatchmfrFile << "," << patch->m_patchname + "_" + patch->speciesList[i]; } @@ -784,7 +784,7 @@ PeleLM::openTempFile() std::ios::out | std::ios::app | std::ios_base::binary); tmpIonsFile.precision(12); tmpIonsFile << "iter,time"; - for (int i = 0; i < AMREX_SPACEDIM; i++) { + for (int i = 0; i < AMREX_SPACEDIM; ++i) { tmpIonsFile << ",curr_" << i << "_low,curr_" << i << "_hi"; } tmpIonsFile << "\n"; diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index 266ab36c6..10c749a81 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -336,7 +336,7 @@ PeleLM::calcDiffusivity(const TimeStamp& a_time) }); // Fill the diff_aux MF with specified Schmidt number - for (int n = 0; n < m_nAux; n++) { + for (int n = 0; n < m_nAux; ++n) { if (m_aux_Schmidt[n] > 0) { MultiFab::Copy( ldata_p->diff_aux_cc, ldata_p->diff_cc, NUM_SPECIES + 1, n, 1, @@ -418,7 +418,7 @@ PeleLM::getDiffusivity( #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif for (MFIter mfi(beta_cc, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const Box ebx = mfi.nodaltilebox(idim); const Box& edomain = amrex::surroundingNodes(domain, idim); const auto& diff_c = beta_cc.const_array(mfi, beta_comp); @@ -466,13 +466,13 @@ PeleLM::getDiffusivity( auto* ldata_p = getLevelDataPtr(lev, tstamp); // Identify and add the correct turbulent contribution - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if ((ncomp == 1) and (beta_comp == 0)) { // Viscosity amrex::MultiFab::Add( beta_ec[idim], ldata_p->visc_turb_fc[idim], 0, 0, 1, 0); } else if ((ncomp == NUM_SPECIES) and (beta_comp == 0)) { // Species // diffusivity - for (int ispec = 0; ispec < NUM_SPECIES; ispec++) { + for (int ispec = 0; ispec < NUM_SPECIES; ++ispec) { amrex::MultiFab::Saxpy( beta_ec[idim], m_Schmidt_inv, ldata_p->visc_turb_fc[idim], 0, ispec, 1, 0); @@ -493,7 +493,7 @@ PeleLM::getDiffusivity( if (doZeroVisc != 0) { ProbParm const* lprobparm = prob_parm_d; const auto geomdata = geom[lev].data(); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const Box& edomain = amrex::surroundingNodes(domain, idim); #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) diff --git a/Source/PeleLMeX_UMac.cpp b/Source/PeleLMeX_UMac.cpp index ca5ab3821..edc6f6cb2 100644 --- a/Source/PeleLMeX_UMac.cpp +++ b/Source/PeleLMeX_UMac.cpp @@ -274,7 +274,7 @@ PeleLM::create_constrained_umac_grown( // Set BCRec for Umac Vector bcrec(1); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { if (crse_geom->isPeriodic(idim)) { bcrec[0].setLo(idim, BCType::int_dir); bcrec[0].setHi(idim, BCType::int_dir); diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 7ad46486b..ff844355e 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -39,7 +39,7 @@ writeBuildInfo() std::cout << "\n"; - for (int n = 1; n <= buildInfoGetNumModules(); n++) { + for (int n = 1; n <= buildInfoGetNumModules(); ++n) { std::cout << buildInfoGetModuleName(n) << ": " << buildInfoGetModuleVal(n) << "\n"; } @@ -238,7 +238,7 @@ PeleLM::extFluxDivergenceLevel( bx, [ncomp, flag, vfrac, divergence, AMREX_D_DECL(fluxX, fluxY, fluxZ), vol, scale] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (flag(i, j, k).isCovered()) { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) = 0.0; } } else if (flag(i, j, k).isRegular()) { @@ -250,7 +250,7 @@ PeleLM::extFluxDivergenceLevel( extFluxDivergence_K( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), vol, scale, divergence); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) *= vfracinv; } } @@ -343,7 +343,7 @@ PeleLM::intFluxDivergenceLevel( AMREX_D_DECL(areax, areay, areaz), vol, scale] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (flag(i, j, k).isCovered()) { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) = 0.0; } } else if (flag(i, j, k).isRegular()) { @@ -356,7 +356,7 @@ PeleLM::intFluxDivergenceLevel( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), AMREX_D_DECL(afrac_x, afrac_y, afrac_z), AMREX_D_DECL(areax, areay, areaz), vol, scale, divergence); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) *= vfracinv; } } @@ -464,7 +464,7 @@ PeleLM::intFluxDivergenceLevelEB( amrex::ParallelFor( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (flag(i, j, k).isCovered()) { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) = 0.0; } } else if (flag(i, j, k).isRegular()) { @@ -478,7 +478,7 @@ PeleLM::intFluxDivergenceLevelEB( AMREX_D_DECL(afrac_x, afrac_y, afrac_z), AMREX_D_DECL(areax, areay, areaz), ebflux, ebarea, vol, dx[0], scale, divergence); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) *= vfracinv; } } @@ -786,7 +786,7 @@ PeleLM::floorSpecies(const TimeStamp& a_time) Real massfrac[NUM_SPECIES] = {0.0}; Real massdens[NUM_SPECIES] = {0.0}; Real rhoinv, h_cgs = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { massdens[n] = sma[box_no](i, j, k, FIRSTSPEC + n); } auto eos = pele::physics::PhysicsType::eos(leosparm); @@ -1211,7 +1211,7 @@ PeleLM::parseVars( // For each entry in the user-provided composition, parse name and value std::string delimiter = ":"; - for (int i = 0; i < varCountIn; i++) { + for (int i = 0; i < varCountIn; ++i) { long unsigned sep = a_stringIn[i].find(delimiter); if (sep == std::string::npos) { Abort( @@ -1221,7 +1221,7 @@ PeleLM::parseVars( Real value = std::stod(a_stringIn[i].substr(sep + 1, a_stringIn[i].length())); int foundIt = 0; - for (int k = 0; k < a_varsNames.size(); k++) { + for (int k = 0; k < a_varsNames.size(); ++k) { if (varNameIn == a_varsNames[k]) { a_rVars[k] = value; foundIt = 1; @@ -1257,17 +1257,17 @@ PeleLM::MLNorm0(const Vector& a_MF, int startcomp, int ncomp) BL_PROFILE("PeleLMeX::MLNorm0()"); AMREX_ASSERT(a_MF[0]->nComp() >= startcomp + ncomp); Vector r(ncomp); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { r[n] = 0.0; } for (int lev = 0; lev < a_MF.size(); ++lev) { if (lev != finest_level) { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { r[n] = std::max( r[n], a_MF[lev]->norm0(*m_coveredMask[lev], startcomp + n, 0, true)); } } else { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { r[n] = std::max(r[n], a_MF[lev]->norm0(startcomp + n, 0, true, true)); } } @@ -1354,7 +1354,7 @@ Vector PeleLM::fetchAdvTypeArray(int scomp, int ncomp) { Vector types(ncomp); - for (int comp = 0; comp < ncomp; comp++) { + for (int comp = 0; comp < ncomp; ++comp) { types[comp] = m_AdvTypeState[scomp + comp]; } return types; @@ -1364,7 +1364,7 @@ Vector PeleLM::fetchDiffTypeArray(int scomp, int ncomp) { Vector types(ncomp); - for (int comp = 0; comp < ncomp; comp++) { + for (int comp = 0; comp < ncomp; ++comp) { types[comp] = m_DiffTypeState[scomp + comp]; } return types; @@ -1374,7 +1374,7 @@ Vector PeleLM::fetchAdvTypeAuxArray(int scomp, int ncomp) { Vector types(ncomp); - for (int comp = 0; comp < ncomp; comp++) { + for (int comp = 0; comp < ncomp; ++comp) { types[comp] = m_AdvTypeAux[scomp + comp]; } return types; @@ -1384,7 +1384,7 @@ Vector PeleLM::fetchDiffTypeAuxArray(int scomp, int ncomp) { Vector types(ncomp); - for (int comp = 0; comp < ncomp; comp++) { + for (int comp = 0; comp < ncomp; ++comp) { types[comp] = m_DiffTypeAux[scomp + comp]; } return types; @@ -1502,7 +1502,7 @@ PeleLM::setTypicalValues(const TimeStamp& a_time, int is_init) : MLmin(GetVecOfConstPtrs(getStateVect(a_time)), 0, NVAR); // Fill typical values vector - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { typical_values[idim] = std::max(stateMax[VELX + idim], std::abs(stateMin[VELX + idim])); } @@ -1510,7 +1510,7 @@ PeleLM::setTypicalValues(const TimeStamp& a_time, int is_init) if (m_incompressible == 0) { // Average between max/min typical_values[DENSITY] = 0.5 * (stateMax[DENSITY] + stateMin[DENSITY]); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { typical_values[FIRSTSPEC + n] = 0.5 * (stateMax[FIRSTSPEC + n] + stateMin[FIRSTSPEC + n]) / typical_values[DENSITY]; @@ -1523,7 +1523,7 @@ PeleLM::setTypicalValues(const TimeStamp& a_time, int is_init) typical_values[NE] = 0.5 * (stateMax[NE] + stateMin[NE]); #endif #if NUM_ODE > 0 - for (int n = 0; n < NUM_ODE; n++) { + for (int n = 0; n < NUM_ODE; ++n) { typical_values[FIRSTODE + n] = 0.5 * (stateMax[FIRSTODE + n] + stateMin[FIRSTODE + n]); } @@ -1548,7 +1548,7 @@ PeleLM::setTypicalValues(const TimeStamp& a_time, int is_init) Vector spec_names; pele::physics::eos::speciesNames( spec_names, &(eos_parms.host_parm())); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { Print() << "\tY_" << spec_names[n] << std::setw( std::max(0, static_cast(8 - spec_names[n].length()))) @@ -1558,7 +1558,7 @@ PeleLM::setTypicalValues(const TimeStamp& a_time, int is_init) Print() << "\tnE: " << typical_values[NE] << '\n'; #endif #if NUM_ODE > 0 - for (int n = 0; n < NUM_ODE; n++) { + for (int n = 0; n < NUM_ODE; ++n) { Print() << "\t" << m_ode_names[n] << std::setw( std::max( @@ -1787,12 +1787,12 @@ PeleLM::MLmax(const Vector& a_MF, int scomp, int ncomp) for (int lev = 0; lev < a_MF.size(); ++lev) { if (lev != finest_level) { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { nmax[n] = std::max(nmax[n], MFmax(a_MF[lev], *m_coveredMask[lev], scomp + n)); } } else { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { nmax[n] = std::max(nmax[n], a_MF[lev]->max(scomp + n, 0, true)); } } @@ -1813,12 +1813,12 @@ PeleLM::MLmin(const Vector& a_MF, int scomp, int ncomp) for (int lev = 0; lev < a_MF.size(); ++lev) { if (lev != finest_level) { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { nmin[n] = std::min(nmin[n], MFmin(a_MF[lev], *m_coveredMask[lev], scomp + n)); } } else { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { nmin[n] = std::min(nmin[n], a_MF[lev]->min(scomp + n, 0, true)); } } @@ -2008,7 +2008,7 @@ PeleLM::initMixtureFraction() Zox = 0.0; for (int i = 0; i < NUM_SPECIES; ++i) { spec_Bilger_fact[i] = 0.0; - for (int k = 0; k < 4; k++) { + for (int k = 0; k < 4; ++k) { spec_Bilger_fact[i] += Beta_mix[k] * (ecompCHON[i * 4 + k] * atwCHON[k] / mwt[i]); } @@ -2033,7 +2033,7 @@ PeleLM::parseComposition( // For each entry in the user-provided composition, parse name and value std::string delimiter = ":"; const int specCountIn = static_cast(compositionIn.size()); - for (int i = 0; i < specCountIn; i++) { + for (int i = 0; i < specCountIn; ++i) { long unsigned sep = compositionIn[i].find(delimiter); if (sep == std::string::npos) { Abort( @@ -2044,7 +2044,7 @@ PeleLM::parseComposition( Real value = std::stod(compositionIn[i].substr(sep + 1, compositionIn[i].length())); int foundIt = 0; - for (int k = 0; k < NUM_SPECIES; k++) { + for (int k = 0; k < NUM_SPECIES; ++k) { if (specNameIn == specNames[k]) { compoIn[k] = value; foundIt = 1; @@ -2068,7 +2068,7 @@ PeleLM::parseComposition( // Fill the massFrac array, convert from mole fraction if necessary if (compositionType == "mass") { // mass - for (int i = 0; i < NUM_SPECIES; i++) { + for (int i = 0; i < NUM_SPECIES; ++i) { massFrac[i] = compoIn[i]; } } else if (compositionType == "mole") { // mole @@ -2115,7 +2115,7 @@ PeleLM::extendSignedDistance(MultiFab* a_signDist, Real a_extendFactor) // boxes using ghost cells If needed, increase the number of loop to extend // the reach of the distance function int nMaxLoop = 4; - for (int dloop = 1; dloop <= nMaxLoop; dloop++) { + for (int dloop = 1; dloop <= nMaxLoop; ++dloop) { #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif diff --git a/Source/Plasma/GMRES/MLGMRES.cpp b/Source/Plasma/GMRES/MLGMRES.cpp index f7c536a7f..ff4612f24 100644 --- a/Source/Plasma/GMRES/MLGMRES.cpp +++ b/Source/Plasma/GMRES/MLGMRES.cpp @@ -41,11 +41,11 @@ MLGMRESSolver::define(PeleLM* a_pelelm, const int a_nComp, const int a_nGrow) KspBase.resize(m_krylovSize + 1); for (int n = 0; n <= m_krylovSize; ++n) { KspBase[n].resize(finest_level + 1); - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { KspBase[n][lev].define(m_grids[lev], m_dmap[lev], m_nComp, m_nGrow); } } - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { Ax[lev].define(m_grids[lev], m_dmap[lev], m_nComp, m_nGrow); res[lev].define(m_grids[lev], m_dmap[lev], m_nComp, m_nGrow); } @@ -335,7 +335,7 @@ MLGMRESSolver::computeMLNorm(const Vector& a_vec) if (m_norm != nullptr) { MEMBER_FUNC_PTR(*m_pelelm, m_norm)(a_vec, r); } else { - for (int comp = 0; comp < m_nComp; comp++) { + for (int comp = 0; comp < m_nComp; ++comp) { Real norm = 0.0; for (int lev = 0; lev <= a_vec.size(); ++lev) { norm += MultiFab::Dot(*a_vec[lev], comp, *a_vec[lev], comp, 1, 0); diff --git a/Source/Plasma/LinOps/AMReX_MLABecCecLap_3D_K.H b/Source/Plasma/LinOps/AMReX_MLABecCecLap_3D_K.H index 9677eda5f..2bf08fdb1 100644 --- a/Source/Plasma/LinOps/AMReX_MLABecCecLap_3D_K.H +++ b/Source/Plasma/LinOps/AMReX_MLABecCecLap_3D_K.H @@ -752,7 +752,7 @@ tridiagonal_solve( Real bet = b_ls(0); u_ls(0) = r_ls(0) / bet; - for (int i = 1; i <= ilen - 1; i++) { + for (int i = 1; i <= ilen - 1; ++i) { gam(i) = c_ls(i - 1) / bet; bet = b_ls(i) - a_ls(i) * gam(i); if (bet == 0) diff --git a/Source/Plasma/PeleLMeX_EFIonDrift.cpp b/Source/Plasma/PeleLMeX_EFIonDrift.cpp index 895a3f6a5..2f50f38bb 100644 --- a/Source/Plasma/PeleLMeX_EFIonDrift.cpp +++ b/Source/Plasma/PeleLMeX_EFIonDrift.cpp @@ -27,7 +27,7 @@ PeleLM::ionDriftVelocity(std::unique_ptr& advData) for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { gphiVOld[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], 1, nGrow, MFInfo(), factory); @@ -80,7 +80,7 @@ PeleLM::ionDriftVelocity(std::unique_ptr& advData) getDiffusivity(lev, 0, NUM_IONS, doZeroVisc, bcRecIons, mobH_cc); // Assemble the ions drift velocity - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif @@ -123,8 +123,8 @@ PeleLM::ionDriftVelocity(std::unique_ptr& advData) // Set BCRec for Umac Vector bcrec(NUM_IONS); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int ion = 0; ion < NUM_IONS; ion++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int ion = 0; ion < NUM_IONS; io++n) { if (geom[lev - 1].isPeriodic(idim)) { bcrec[ion].setLo(idim, BCType::int_dir); bcrec[ion].setHi(idim, BCType::int_dir); @@ -169,7 +169,7 @@ void PeleLM::ionDriftAddUmac(int lev, std::unique_ptr& advData) { // Add umac to the ions drift velocity to get the effective velocity - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index 25d9be7b1..538daef10 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -59,7 +59,7 @@ PeleLM::implicitNonLinearSolve( for (int lev = 0; lev <= finest_level; ++lev) { // Get nl solve data pointer auto ldataNLs_p = getLevelDataNLSolvePtr(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { MultiFab::Copy( ldataNLs_p->umac[idim], advData->umac[lev][idim], 0, 0, 1, 0); } @@ -382,7 +382,7 @@ PeleLM::computeBGcharge( [dt_int, rhoYold, adv_arr, dn_arr, dnp1_arr, dhat_arr, rhoYdot, charge, factor, zk = zk] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { charge(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { Real rhoYprov = rhoYold(i, j, k, n) + dt_int * (adv_arr(i, j, k, n) + @@ -427,7 +427,7 @@ PeleLM::nonLinearResidual( Vector> gradPhiVCur(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { laplacian[lev].define(grids[lev], dmap[lev], 1, 0, MFInfo(), Factory(lev)); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const auto& fba = amrex::convert(grids[lev], IntVect::TheDimensionVector(idim)); gradPhiVCur[lev][idim].define( @@ -554,7 +554,7 @@ PeleLM::getAdvectionTerm( for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { fluxes[lev][idim].define( amrex::convert(ba, IntVect::TheDimensionVector(idim)), dmap[lev], 1, nGrow, MFInfo(), factory); @@ -578,7 +578,7 @@ PeleLM::getAdvectionTerm( getDiffusivity(lev, 0, 1, doZeroVisc, bcRecnE, ldata_p->mobE_cc); // Get the electron effective velocity - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif @@ -987,7 +987,7 @@ PeleLM::setUpPrecond(const Real& a_dt, const Vector& a_nE) if (m_ef_PC_approx == 1) { // Assuming identity of the inverse of DiffOp // Add Stilda pieces Real scalLap = eps0 * epsr / elemCharge; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { neKe_ec[idim].mult(0.5 * a_dt, 0, 1); neKe_ec[idim].plus(scalLap, 0, 1); } @@ -997,7 +997,7 @@ PeleLM::setUpPrecond(const Real& a_dt, const Vector& a_nE) Array Schur_neKe_ec = getUpwindedEdge( lev, 0, 1, bcRecnE, Schur_nEKe, GetArrOfConstPtrs(ldataNLs_p->uEffnE)); Real scalLap = eps0 * epsr / elemCharge; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { Schur_neKe_ec[idim].plus(scalLap, 0, 1); } getPrecondOp()->setStildaOpBCoeff(lev, GetArrOfConstPtrs(Schur_neKe_ec)); @@ -1040,7 +1040,7 @@ PeleLM::getUpwindedEdge( #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif for (MFIter mfi(ccMF, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const Box ebx = mfi.nodaltilebox(idim); const Box& edomain = amrex::surroundingNodes(domain, idim); const auto& ccVal = ccMF.const_array(mfi, edge_comp); @@ -1234,7 +1234,7 @@ PeleLM::nlSolveNorm(const Vector& a_MF, Real& r) { r = 0.0; int nComp = a_MF[0]->nComp(); - for (int comp = 0; comp < nComp; comp++) { + for (int comp = 0; comp < nComp; ++comp) { Real norm = 0.0; for (int lev = 0; lev < a_MF.size(); ++lev) { // TODO : norm not weighted by cell size, should it ? diff --git a/Source/Plasma/PeleLMeX_EFPoisson.cpp b/Source/Plasma/PeleLMeX_EFPoisson.cpp index 065a71c4a..113d92309 100644 --- a/Source/Plasma/PeleLMeX_EFPoisson.cpp +++ b/Source/Plasma/PeleLMeX_EFPoisson.cpp @@ -37,7 +37,7 @@ PeleLM::poissonSolveEF(const TimeStamp& a_time) bx, [rhs, rhoY, nE, factor, zk = zk] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { rhs(i, j, k) = -nE(i, j, k) * elemCharge * factor; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhs(i, j, k) += zk[n] * rhoY(i, j, k, n) * factor; } }); diff --git a/Source/Plasma/PeleLMeX_EFTimeStep.cpp b/Source/Plasma/PeleLMeX_EFTimeStep.cpp index 019ea5825..123c5dd7b 100644 --- a/Source/Plasma/PeleLMeX_EFTimeStep.cpp +++ b/Source/Plasma/PeleLMeX_EFTimeStep.cpp @@ -109,8 +109,8 @@ PeleLM::estEFIonsDt(const TimeStamp& a_time) amrex::ParallelFor( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { Real maxVel = 0.0; - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { - for (int n = 0; n < NUM_IONS; n++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int n = 0; n < NUM_IONS; ++n) { Real ueff = vel(i, j, k, idim) + mob_cc(i, j, k, n) * efield(i, j, k, idim); maxVel = amrex::max(maxVel, std::abs(ueff)); diff --git a/Source/Plasma/PeleLMeX_EFUtils.cpp b/Source/Plasma/PeleLMeX_EFUtils.cpp index c6b3a36c1..80ba8dda8 100644 --- a/Source/Plasma/PeleLMeX_EFUtils.cpp +++ b/Source/Plasma/PeleLMeX_EFUtils.cpp @@ -65,7 +65,7 @@ void PeleLM::getNLStateScaling(Real& nEScale, Real& phiVScale) { Array r = {0.0, 0.0}; - for (int comp = 0; comp < 2; comp++) { + for (int comp = 0; comp < 2; ++comp) { for (int lev = 0; lev <= finest_level; ++lev) { if (lev != finest_level) { r[comp] = std::max( @@ -86,7 +86,7 @@ void PeleLM::getNLResidScaling(Real& nEScale, Real& phiVScale) { Array r = {0.0, 0.0}; - for (int comp = 0; comp < 2; comp++) { + for (int comp = 0; comp < 2; ++comp) { for (int lev = 0; lev <= finest_level; ++lev) { if (lev != finest_level) { r[comp] = std::max( @@ -131,7 +131,7 @@ PeleLM::hackBCChargedParticle(const Real& charge, const BCRec& bc_in) const int* lo_bc = bc_in.lo(); const int* hi_bc = bc_in.hi(); - for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { int lo = lo_bc[idim]; int hi = hi_bc[idim]; @@ -370,14 +370,14 @@ PeleLM::ionsBalance() { // Compute the sum of ions on the domain boundaries Array ionsCurrent{0.0}; - for (int n = NUM_SPECIES - NUM_IONS; n < NUM_SPECIES; n++) { - for (int i = 0; i < 2 * AMREX_SPACEDIM; i++) { + for (int n = NUM_SPECIES - NUM_IONS; n < NUM_SPECIES; ++n) { + for (int i = 0; i < 2 * AMREX_SPACEDIM; ++i) { ionsCurrent[i] += m_domainRhoYFlux[2 * n * AMREX_SPACEDIM + i] * zk[n]; } } tmpIonsFile << m_nstep << "," << m_cur_time; // Time info - for (int i = 0; i < 2 * AMREX_SPACEDIM; i++) { + for (int i = 0; i < 2 * AMREX_SPACEDIM; ++i) { tmpIonsFile << "," << ionsCurrent[i]; // ions current as xlo, xhi, ylo, ... } tmpIonsFile << "\n"; diff --git a/Source/Plasma/PeleLMeX_EF_K.H b/Source/Plasma/PeleLMeX_EF_K.H index 68ccac394..cbb28a9bb 100644 --- a/Source/Plasma/PeleLMeX_EF_K.H +++ b/Source/Plasma/PeleLMeX_EF_K.H @@ -31,12 +31,12 @@ getKappaE( // Get rho & Y from rhoY amrex::Real rho = 0.0_rt; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rho += rhoY(i, j, k, n); } amrex::Real rhoinv = 1.0_rt / rho; amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } @@ -80,11 +80,11 @@ getKappaSp( { using namespace amrex::literals; amrex::Real rho = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rho += rhoY(i, j, k, n); } int ionCnt = 0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { if (a_zk[n] != 0.0) { Ksp(i, j, k, ionCnt) = rhoD(i, j, k, n) * mwt[n] * 0.001 * a_zk[n] / (rho * PP_RU_MKS * T(i, j, k)); @@ -273,7 +273,7 @@ cen2edg_upwind( id_h[dir] -= 1; } - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { if (ueff(i, j, k) > smallVel) { efab(i, j, k, n) = cfab(id_l[0], id_l[1], id_l[2], n); } else if (ueff(i, j, k) < -smallVel) { @@ -303,12 +303,12 @@ reactionRateRhoY_EF( // Get rho from rhoY. Is there a better way ? amrex::Real rho = 0.0_rt; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rho += rhoY(i, j, k, n); } amrex::Real rhoinv = 1.0_rt / rho; amrex::Real y[NUM_SPECIES] = {0.0}; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { y[n] = rhoY(i, j, k, n) * rhoinv; } @@ -328,7 +328,7 @@ reactionRateRhoY_EF( rho = rho * 0.001_rt; // rho MKS -> CGS amrex::Real wdot[NUM_SPECIES] = {0.0}; eos.RTY2WDOT(rho, Tloc, y, wdot); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoYdot(i, j, k, n) = wdot[n] * 1000.0_rt; // CGS -> MKS conversion } nEdot(i, j, k) = wdot[E_ID] * Na * 1.0e6; @@ -380,7 +380,7 @@ addLorentzForce( EFz = -0.5_rt / dx[2] * (phiV(i, j, k + 1) - phiV(i, j, k - 1)); } #endif - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { force(i, j, k, 0) += a_zk[n] * rhoY(i, j, k, n) * EFx; force(i, j, k, 1) += a_zk[n] * rhoY(i, j, k, n) * EFy; #if (AMREX_SPACEDIM == 3) @@ -413,14 +413,14 @@ initElecNeutral( // Get species charge/mass amrex::Real zk[NUM_SPECIES] = {0.0}; pele::physics::eos::charge_mass(zk); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { zk[n] *= 1000.0; // CGS->MKS } // Get mass fractions amrex::Real massfrac[NUM_SPECIES] = {0.0}; amrex::Real rho_inv = 1.0 / rho(i, j, k); - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { massfrac[n] = rhoY(i, j, k, n) * rho_inv; } @@ -429,7 +429,7 @@ initElecNeutral( // First remove Y_nE massfrac[E_ID] = 0.0; amrex::Real sum = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { massfrac[n] = std::max(0.0, massfrac[n]); if (n != N2_ID) sum += massfrac[n]; @@ -438,20 +438,20 @@ initElecNeutral( // Change ions massfrac where charge already < 0.0 amrex::Real chargeDist = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { chargeDist += massfrac[n] * zk[n]; } if (chargeDist < 0.0) { amrex::Real sum_pos_ion = 0.0; amrex::Real mean_zk_pos_ion = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { if (zk[n] > 0.0) { sum_pos_ion += massfrac[n]; mean_zk_pos_ion += massfrac[n] * zk[n]; } } if (sum_pos_ion > 0.0) { - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { if (zk[n] > 0.0) { massfrac[N2_ID] += massfrac[n] / sum_pos_ion * chargeDist / mean_zk_pos_ion * sum_pos_ion; @@ -463,7 +463,7 @@ initElecNeutral( } // Add Electrons chargeDist = 0.0; - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { chargeDist += massfrac[n] * zk[n]; } nE(i, j, k) = std::max(1.0e-24, chargeDist / elemCharge); @@ -481,7 +481,7 @@ initElecNeutral( rhoH(i, j, k) = h_cgs * 1.0e-4 * rho(i, j, k); // Species mass - for (int n = 0; n < NUM_SPECIES; n++) { + for (int n = 0; n < NUM_SPECIES; ++n) { rhoY(i, j, k, n) = massfrac[n] * rho(i, j, k); } diff --git a/Source/main.cpp b/Source/main.cpp index 7f26308c1..df4148aa8 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -14,7 +14,7 @@ main(int argc, char* argv[]) // check to see if it contains --describe if (argc >= 2) { - for (auto i = 1; i < argc; i++) { + for (auto i = 1; i < argc; ++i) { if (std::string(argv[i]) == "--describe") { writeBuildInfo(); return 0; From 68b1d00cc87b96bae44e0134249b568fdc1832ce Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 13 Jul 2025 11:05:31 +0100 Subject: [PATCH 28/87] advection --- Source/PeleLMeX_Advection.cpp | 155 +++++++++++++++++----------------- 1 file changed, 78 insertions(+), 77 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 5a335d102..d3503470a 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -165,7 +165,7 @@ PeleLM::computeVelocityAdvTerm(std::unique_ptr& advData) auto* ldata_p = getLevelDataPtr(lev, AmrOldTime); //---------------------------------------------------------------- // Use a temporary MF to hold divergence before redistribution - int nGrow_divT = 3; + constexpr int nGrow_divT = 3; MultiFab divTmp( grids[lev], dmap[lev], AMREX_SPACEDIM, nGrow_divT, MFInfo(), EBFactory(lev)); @@ -212,7 +212,7 @@ PeleLM::updateVelocity(std::unique_ptr& advData) grids[lev], dmap[lev], AMREX_SPACEDIM, 0, MFInfo(), Factory(lev)); } constexpr int use_density = 0; - const Real CrankNicholsonFactor = 0.5; + constexpr Real CrankNicholsonFactor = 0.5; computeDivTau( AmrOldTime, GetVecOfPtrs(divtau), use_density, CrankNicholsonFactor); @@ -238,27 +238,25 @@ PeleLM::updateVelocity(std::unique_ptr& advData) // Compute provisional new velocity // velForce holds: 1/\rho^{n+1/2} [(gravity+...)^{n+1/2} - \nabla pi^{n} + // 0.5 * divTau^{n}] -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldataOld_p->state, TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - Box const& bx = mfi.tilebox(); - auto const& vel_old = ldataOld_p->state.const_array(mfi, VELX); - auto const& vel_aofs = advData->AofS[lev].const_array(mfi, VELX); - auto const& force = velForces[lev].const_array(mfi); - auto const& vel_new = ldataNew_p->state.array(mfi, VELX); - Real dt_loc = m_dt; - amrex::ParallelFor( - bx, AMREX_SPACEDIM, - [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - vel_new(i, j, k, n) = - vel_old(i, j, k, n) + - dt_loc * (vel_aofs(i, j, k, n) + force(i, j, k, n)); - }); - } + auto state_old_ma = ldataOld_p->state.const_arrays(); + auto adv_aofs_ma = advData->AofS[lev].const_arrays(); + auto force_ma = velForces[lev].const_arrays(); + auto state_new_ma = ldataNew_p->state.arrays(); + amrex::ParallelFor( + ldataOld_p->state, + [state_old_ma, adv_aofs_ma, force_ma, state_new_ma, + dt_loc = + m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + state_new_ma[box_no](i, j, k, VELX + n) = + state_old_ma[box_no](i, j, k, VELX + n) + + dt_loc * (adv_aofs_ma[box_no](i, j, k, VELX + n) + + force_ma[box_no](i, j, k, n)); + } + }); } + Gpu::streamSynchronize(); } void @@ -268,47 +266,51 @@ PeleLM::getScalarAdvForce( { int* aux_diffuse_d = convertToDeviceVector(m_DiffTypeAux).dataPtr(); + auto const* leosparm = eos_parms.device_parm(); + for (int lev = 0; lev <= finest_level; ++lev) { // Get t^{n} data pointer auto* ldata_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataR_p = getLevelDataReactPtr(lev); - auto const* leosparm = eos_parms.device_parm(); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(advData->Forcing[lev], TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const Box& bx = mfi.tilebox(); - FArrayBox DummyFab(bx, 1); - auto const& rho = ldata_p->state.const_array(mfi, DENSITY); - auto const& rhoY = ldata_p->state.const_array(mfi, FIRSTSPEC); - auto const& T = ldata_p->state.const_array(mfi, TEMP); - auto const& dn = diffData->Dn[lev].const_array(mfi, 0); - auto const& ddn = diffData->Dn[lev].const_array(mfi, NUM_SPECIES + 1); - auto const& r = ldataR_p->I_R.const_array(mfi); - auto const& extRhoY = m_extSource[lev]->const_array(mfi, FIRSTSPEC); - auto const& extRhoH = m_extSource[lev]->const_array(mfi, RHOH); - auto const& fY = advData->Forcing[lev].array(mfi, 0); - auto const& fT = advData->Forcing[lev].array(mfi, NUM_SPECIES); - auto const& fAux = (m_nAux > 0) ? advData->Forcing_aux[lev].array(mfi, 0) - : DummyFab.array(); - auto const& dn_aux = (m_nAux > 0) - ? diffData->Dn_aux[lev].const_array(mfi, 0) - : DummyFab.const_array(); - amrex::ParallelFor( - bx, [rho, rhoY, T, dn, ddn, r, fY, fT, fAux, extRhoY, extRhoH, - aux_diffuse_d, dn_aux, nAux = m_nAux, dp0dt = m_dp0dt, - is_closed_ch = m_closed_chamber, do_react = m_do_react, - leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - buildAdvectionForcing( - i, j, k, rho, rhoY, T, dn, ddn, r, extRhoY, extRhoH, dp0dt, - is_closed_ch, do_react, fY, fT, fAux, dn_aux, aux_diffuse_d, nAux, - leosparm); - }); - } + auto state_ma = ldata_p->state.const_arrays(); + auto dn_ma = diffData->Dn[lev].const_arrays(); + auto adv_ma = advData->Forcing[lev].arrays(); + auto r_ma = ldataR_p->I_R.const_arrays(); + auto ext_ma = m_extSource[lev]->arrays(); + + auto dn_aux_ma = + (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : dn_ma; + auto adv_aux_ma = + (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : adv_ma; + + amrex::ParallelFor( + advData->Forcing[lev], + [state_ma, dn_ma, dn_aux_ma, r_ma, ext_ma, adv_ma, adv_aux_ma, + aux_diffuse_d, leosparm, nAux = m_nAux, dp0dt = m_dp0dt, + is_closed_ch = m_closed_chamber, + do_react = + m_do_react] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rho(state_ma[box_no], DENSITY); + Array4 rhoY(state_ma[box_no], FIRSTSPEC); + Array4 T(state_ma[box_no], TEMP); + Array4 dn(dn_ma[box_no], 0); + Array4 ddn(dn_ma[box_no], NUM_SPECIES + 1); + Array4 dn_aux(dn_aux_ma[box_no], 0); + Array4 r(r_ma[box_no], 0); + Array4 extRhoY(ext_ma[box_no], FIRSTSPEC); + Array4 extRhoH(ext_ma[box_no], RHOH); + Array4 fY(adv_ma[box_no], 0); + Array4 fT(adv_ma[box_no], NUM_SPECIES); + Array4 fAux(adv_aux_ma[box_no], 0); + buildAdvectionForcing( + i, j, k, rho, rhoY, T, dn, ddn, r, extRhoY, extRhoH, dp0dt, + is_closed_ch, do_react, fY, fT, fAux, dn_aux, aux_diffuse_d, nAux, + leosparm); + }); } + Gpu::streamSynchronize(); // Fill forcing ghost cells if (advData->Forcing[0].nGrow() > 0) { @@ -945,7 +947,7 @@ PeleLM::updateDensity(std::unique_ptr& advData) void PeleLM::computePassiveAdvTerms( - std::unique_ptr& advData, int state_comp, int ncomp) + std::unique_ptr& advData, const int state_comp, const int ncomp) { //---------------------------------------------------------------- // Get the BCRecs and AdvectionTypes @@ -1014,9 +1016,9 @@ PeleLM::computePassiveAdvTerms( // TODO: Find way to include diffusive forces for passive scalars that // diffuse auto const& force_arr = m_extSource[lev]->const_array(mfi, state_comp); - bool is_velocity = false; - bool fluxes_are_area_weighted = false; - bool knownEdgeState = false; + constexpr bool is_velocity = false; + constexpr bool fluxes_are_area_weighted = false; + constexpr bool knownEdgeState = false; HydroUtils::ComputeFluxesOnBoxFromState( bx, ncomp, mfi, pass_arr, AMREX_D_DECL(fx, fy, fz), AMREX_D_DECL(edgex, edgey, edgez), knownEdgeState, @@ -1107,24 +1109,23 @@ PeleLM::updateScalarComp( // Get level data ptr auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldataNew_p->state, TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - Box const& bx = mfi.tilebox(); - auto const& old_arr = ldataOld_p->state.const_array(mfi, state_comp); - auto const& new_arr = ldataNew_p->state.array(mfi, state_comp); - auto const& a_of_s = advData->AofS[lev].const_array(mfi, state_comp); - auto const& ext = m_extSource[lev]->const_array(mfi, state_comp); - amrex::ParallelFor( - bx, ncomp, - [old_arr, new_arr, a_of_s, ext, - dt = m_dt] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - new_arr(i, j, k, n) = - old_arr(i, j, k, n) + dt * (a_of_s(i, j, k, n) + ext(i, j, k, n)); - }); - } + + auto state_old_ma = ldataOld_p->state.const_arrays(); + auto adv_aofs_ma = advData->AofS[lev].const_arrays(); + auto ext_ma = m_extSource[lev]->const_arrays(); + auto state_new_ma = ldataNew_p->state.arrays(); + + amrex::ParallelFor( + ldataOld_p->state, + [state_old_ma, adv_aofs_ma, ext_ma, state_new_ma, state_comp, ncomp, + dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = state_comp; n < state_comp + ncomp; ++n) { + state_new_ma[box_no](i, j, k, n) = + state_old_ma[box_no](i, j, k, n) + + dt * (adv_aofs_ma[box_no](i, j, k, n) + ext_ma[box_no](i, j, k, n)); + } + }); } + Gpu::streamSynchronize(); averageDown(AmrNewTime, state_comp, ncomp); } From 58e716c92569ad5a9bfeaf75b4cf662c90e5fe03 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 13 Jul 2025 11:09:50 +0100 Subject: [PATCH 29/87] couple of changes --- Source/PeleLMeX.H | 2 +- Source/PeleLMeX_BC.cpp | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index c406e3fc9..8fd9106f4 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -56,7 +56,7 @@ class PeleLM : public amrex::AmrCore { public: - enum TimeStamp { AmrOldTime, AmrHalfTime, AmrNewTime }; + enum TimeStamp : std::uint_8 { AmrOldTime, AmrHalfTime, AmrNewTime }; // constructor PeleLM(); diff --git a/Source/PeleLMeX_BC.cpp b/Source/PeleLMeX_BC.cpp index d4b21869d..ea5b7e5ff 100644 --- a/Source/PeleLMeX_BC.cpp +++ b/Source/PeleLMeX_BC.cpp @@ -10,32 +10,32 @@ // Components are Interior, Inflow, Outflow, Symmetry, & // SlipWallAdiab, NoSlipWallAdiab, SlipWallIsoTherm, NoSlipWallIsoTherm. -int norm_vel_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, +constexpr int norm_vel_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_odd, amrex::BCType::ext_dir, amrex::BCType::ext_dir, amrex::BCType::ext_dir, amrex::BCType::ext_dir}; -int tang_vel_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, +constexpr int tang_vel_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_even, amrex::BCType::hoextrap, amrex::BCType::ext_dir, amrex::BCType::hoextrap, amrex::BCType::ext_dir}; -int density_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, +constexpr int density_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_even, amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::foextrap}; -int species_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, +constexpr int species_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_even, amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::ext_dir, amrex::BCType::ext_dir}; -int rhoh_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, +constexpr int rhoh_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_even, amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::ext_dir, amrex::BCType::ext_dir}; -int temp_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, +constexpr int temp_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_even, amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::ext_dir, amrex::BCType::ext_dir}; @@ -75,7 +75,7 @@ int soot_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, InterpBase* PeleLM:: getInterpolator( // NOLINT(readability-convert-member-functions-to-static) - int a_method) const + const int a_method) const { InterpBase* mapper = nullptr; @@ -230,7 +230,7 @@ PeleLM::setBoundaryConditions() } Vector -PeleLM::fetchBCRecArray(int scomp, int ncomp) +PeleLM::fetchBCRecArray(const int scomp, const int ncomp) { Vector bc(ncomp); for (int comp = 0; comp < ncomp; ++comp) { @@ -240,7 +240,7 @@ PeleLM::fetchBCRecArray(int scomp, int ncomp) } Vector -PeleLM::fetchBCRecAuxArray(int scomp, int ncomp) +PeleLM::fetchBCRecAuxArray(const int scomp, const int ncomp) { Vector bc(ncomp); for (int comp = 0; comp < ncomp; ++comp) { @@ -251,10 +251,10 @@ PeleLM::fetchBCRecAuxArray(int scomp, int ncomp) //----------------------------------------------------------------------------- // The following work directly on the leveldata - +l // Fill the entire class state at once -void -PeleLM::fillPatchState(const TimeStamp& a_time) +voidPe +PeleLM::fillPatchState(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::fillPatchState()"); for (int lev = 0; lev <= finest_level; ++lev) { @@ -264,7 +264,7 @@ PeleLM::fillPatchState(const TimeStamp& a_time) // Fill the a given level class state void -PeleLM::fillPatchState(int lev, const TimeStamp& a_time) +PeleLM::fillPatchState(const int lev, const TimeStamp a_time) { BL_PROFILE("PeleLMeX::fillPatchStateLev()"); From 7ef5f7d45aceec9a8d1aa8145a1bdfe91148b4e2 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 13 Jul 2025 11:45:04 +0100 Subject: [PATCH 30/87] fixes --- Source/PeleLMeX.H | 50 +++++++++++++++---------------- Source/PeleLMeX_BC.cpp | 17 +++++------ Source/PeleLMeX_Diffusion.cpp | 8 ++--- Source/PeleLMeX_Eos.cpp | 22 +++++++------- Source/PeleLMeX_Evolve.cpp | 4 +-- Source/PeleLMeX_Forces.cpp | 12 ++++---- Source/PeleLMeX_Init.cpp | 4 +-- Source/PeleLMeX_Plot.cpp | 14 ++++----- Source/PeleLMeX_Projection.cpp | 18 +++++------ Source/PeleLMeX_Reactions.cpp | 10 +++---- Source/PeleLMeX_Setup.cpp | 3 +- Source/PeleLMeX_Temporals.cpp | 2 +- Source/PeleLMeX_Timestep.cpp | 48 ++++++++++++++--------------- Source/PeleLMeX_TransportProp.cpp | 6 ++-- Source/PeleLMeX_UMac.cpp | 8 ++--- Source/PeleLMeX_Utils.cpp | 4 +-- 16 files changed, 113 insertions(+), 117 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 8ec4bd7e9..deef3cd12 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -777,7 +777,7 @@ public: */ void computeInstantaneousReactionRate( const amrex::Vector& a_I_R, - const PeleLM::TimeStamp& a_time); + const PeleLM::TimeStamp a_time); /** * \brief Compute instantaneous reaction rate on a given level @@ -818,7 +818,7 @@ public: * \param a_time state time to work on, either Old or New */ amrex::Real estDivUDt(const PeleLM::TimeStamp a_time); - void checkDt(const PeleLM::TimeStamp a_time, const amrex::Real& a_dt); + void checkDt(const PeleLM::TimeStamp a_time, const amrex::Real a_dt); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -938,7 +938,7 @@ public: * \brief Compute temperature from rhoY and rhoH on all levels * \param a_time state time to work on, either Old or New */ - void setTemperature(const PeleLM::TimeStamp& a_time); + void setTemperature(const PeleLM::TimeStamp a_time); /** * \brief Compute temperature from rhoY and rhoH on a given level @@ -1057,17 +1057,17 @@ public: void setBoundaryConditions(); // FillPatch the entire class state - void fillPatchState(const PeleLM::TimeStamp& a_time); - void fillPatchState(const int lev, const PeleLM::TimeStamp& a_time); + void fillPatchState(const PeleLM::TimeStamp a_time); + void fillPatchState(const int lev, const PeleLM::TimeStamp a_time); // FillPatch the various state components - void fillPatchDensity(const PeleLM::TimeStamp& a_time); - void fillPatchSpecies(const PeleLM::TimeStamp& a_time); - void fillPatchTemp(const PeleLM::TimeStamp& a_time); - void fillPatchAux(const PeleLM::TimeStamp& a_time); + void fillPatchDensity(const PeleLM::TimeStamp a_time); + void fillPatchSpecies(const PeleLM::TimeStamp a_time); + void fillPatchTemp(const PeleLM::TimeStamp a_time); + void fillPatchAux(const PeleLM::TimeStamp a_time); #ifdef PELE_USE_PLASMA - void fillPatchPhiV(const PeleLM::TimeStamp& a_time); + void fillPatchPhiV(const PeleLM::TimeStamp a_time); #endif // FillPatch and return a MF @@ -1193,16 +1193,16 @@ public: const amrex::Real a_time); // Average down operations - void averageDownState(const PeleLM::TimeStamp& a_time); - void averageDownScalars(const PeleLM::TimeStamp& a_time); - void averageDownVelocity(const PeleLM::TimeStamp& a_time); - void averageDownAux(const PeleLM::TimeStamp& a_time); + void averageDownState(const PeleLM::TimeStamp a_time); + void averageDownScalars(const PeleLM::TimeStamp a_time); + void averageDownVelocity(const PeleLM::TimeStamp a_time); + void averageDownAux(const PeleLM::TimeStamp a_time); void averageDown( - const PeleLM::TimeStamp& a_time, const int state_comp, const int ncomp); + const PeleLM::TimeStamp a_time, const int state_comp, const int ncomp); void averageDownReaction(); #ifdef PELE_USE_PLASMA - void averageDownnE(const PeleLM::TimeStamp& a_time); - void averageDownPhiV(const PeleLM::TimeStamp& a_time); + void averageDownnE(const PeleLM::TimeStamp a_time); + void averageDownPhiV(const PeleLM::TimeStamp a_time); #endif //----------------------------------------------------------------------------- @@ -1360,7 +1360,7 @@ public: int ncomp, amrex::Real scale); - void floorSpecies(const PeleLM::TimeStamp& a_time); + void floorSpecies(const PeleLM::TimeStamp a_time); amrex::Real MLNorm0(const amrex::Vector& a_MF); amrex::Vector MLNorm0( @@ -1616,7 +1616,7 @@ public: void ionDriftAddUmac(const int lev, std::unique_ptr& advData); void computeInstantaneousReactionRateEF( - const int lev, const PeleLM::TimeStamp& a_time, amrex::MultiFab* a_I_R); + const int lev, const PeleLM::TimeStamp a_time, amrex::MultiFab* a_I_R); amrex::BCRec hackBCChargedParticle(const amrex::Real& zk, const amrex::BCRec& bc_in); @@ -1981,7 +1981,7 @@ public: amrex::Vector m_spark; amrex::Vector m_spark_time; amrex::Vector m_spark_duration; - amrex::Vector> m_spark_location; + amrex::Vector> m_spark_location; amrex::Vector m_spark_temp; amrex::Vector m_spark_radius; @@ -2112,13 +2112,13 @@ public: // Number of ghost cells #ifdef AMREX_USE_EB - constexpr int m_nGrowState = 4; + static constexpr int m_nGrowState = 4; #else - constexpr int m_nGrowState = 3; + static constexpr int m_nGrowState = 3; #endif - constexpr int m_nGrowAdv = 1; - constexpr int m_nGrowdivu = 1; - constexpr int m_nGrowMAC = 1; + static constexpr int m_nGrowAdv = 1; + static constexpr int m_nGrowdivu = 1; + static constexpr int m_nGrowMAC = 1; // Initialization int m_do_init_proj = 1; diff --git a/Source/PeleLMeX_BC.cpp b/Source/PeleLMeX_BC.cpp index 58154afc2..28b3a1bb9 100644 --- a/Source/PeleLMeX_BC.cpp +++ b/Source/PeleLMeX_BC.cpp @@ -250,10 +250,9 @@ PeleLM::fetchBCRecAuxArray(const int scomp, const int ncomp) //----------------------------------------------------------------------------- // The following work directly on the leveldata -l - // Fill the entire class state at once - voidPe - PeleLM::fillPatchState(const TimeStamp a_time) +// Fill the entire class state at once +void +PeleLM::fillPatchState(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::fillPatchState()"); for (int lev = 0; lev <= finest_level; ++lev) { @@ -280,7 +279,7 @@ PeleLM::fillPatchState(const int lev, const TimeStamp a_time) // Fill a state components void -PeleLM::fillPatchDensity(const TimeStamp& a_time) +PeleLM::fillPatchDensity(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::fillPatchDensity()"); for (int lev = 0; lev <= finest_level; ++lev) { @@ -291,7 +290,7 @@ PeleLM::fillPatchDensity(const TimeStamp& a_time) } void -PeleLM::fillPatchSpecies(const TimeStamp& a_time) +PeleLM::fillPatchSpecies(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::fillPatchSpecies()"); for (int lev = 0; lev <= finest_level; ++lev) { @@ -302,7 +301,7 @@ PeleLM::fillPatchSpecies(const TimeStamp& a_time) } void -PeleLM::fillPatchTemp(const TimeStamp& a_time) +PeleLM::fillPatchTemp(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::fillPatchTemp()"); for (int lev = 0; lev <= finest_level; ++lev) { @@ -313,7 +312,7 @@ PeleLM::fillPatchTemp(const TimeStamp& a_time) } void -PeleLM::fillPatchAux(const TimeStamp& a_time) +PeleLM::fillPatchAux(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::fillPatchAux()"); for (int lev = 0; lev <= finest_level; ++lev) { @@ -325,7 +324,7 @@ PeleLM::fillPatchAux(const TimeStamp& a_time) #ifdef PELE_USE_PLASMA void -PeleLM::fillPatchPhiV(const TimeStamp& a_time) +PeleLM::fillPatchPhiV(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::fillPatchPhiV()"); for (int lev = 0; lev <= finest_level; ++lev) { diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 88077ae83..fa473a001 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -41,7 +41,7 @@ PeleLM::getDiffusionTensorOp() void PeleLM::computeDifferentialDiffusionTerms( - const TimeStamp& a_time, + const TimeStamp a_time, std::unique_ptr& diffData, const int is_init) { @@ -366,7 +366,7 @@ PeleLM::adjustSpeciesFluxes( void PeleLM::correctIsothermalBoundary( - const TimeStamp& a_time, + const TimeStamp a_time, const Vector& a_spec_boundary, const Vector>& a_wbarfluxes, const Vector>& a_soretfluxes) @@ -464,7 +464,7 @@ PeleLM::correctIsothermalBoundary( void PeleLM::computeDifferentialDiffusionFluxes( - const TimeStamp& a_time, + const TimeStamp a_time, const Vector>& a_fluxes, const Vector& #ifdef AMREX_USE_EB @@ -1763,7 +1763,7 @@ PeleLM::getScalarDiffForce( void PeleLM::computeDivTau( - const TimeStamp& a_time, + const TimeStamp a_time, const Vector& a_divtau, const int use_density, const Real scale) diff --git a/Source/PeleLMeX_Eos.cpp b/Source/PeleLMeX_Eos.cpp index 9e9d6cd6f..47a39908b 100644 --- a/Source/PeleLMeX_Eos.cpp +++ b/Source/PeleLMeX_Eos.cpp @@ -5,7 +5,7 @@ using namespace amrex; void -PeleLM::setThermoPress(const TimeStamp& a_time) +PeleLM::setThermoPress(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::setThermoPress()"); @@ -17,7 +17,7 @@ PeleLM::setThermoPress(const TimeStamp& a_time) } void -PeleLM::setThermoPress(int lev, const TimeStamp& a_time) +PeleLM::setThermoPress(const int lev, const TimeStamp a_time) { AMREX_ASSERT(a_time == AmrOldTime || a_time == AmrNewTime); @@ -40,10 +40,10 @@ PeleLM::setThermoPress(int lev, const TimeStamp& a_time) void PeleLM::calcDivU( - int is_init, - int computeDiff, - int do_avgDown, - const TimeStamp& a_time, + const int is_init, + const int computeDiff, + const int do_avgDown, + const TimeStamp a_time, std::unique_ptr& diffData) { BL_PROFILE("PeleLMeX::calcDivU()"); @@ -183,7 +183,7 @@ PeleLM::calcDivU( } void -PeleLM::setRhoToSumRhoY(int lev, const TimeStamp& a_time) +PeleLM::setRhoToSumRhoY(const int lev, const TimeStamp a_time) { AMREX_ASSERT(a_time == AmrOldTime || a_time == AmrNewTime); @@ -202,7 +202,7 @@ PeleLM::setRhoToSumRhoY(int lev, const TimeStamp& a_time) } void -PeleLM::setTemperature(const TimeStamp& a_time) +PeleLM::setTemperature(const TimeStamp a_time) { BL_PROFILE_VAR("PeleLMeX::setTemperature()", setTemperature); @@ -215,7 +215,7 @@ PeleLM::setTemperature(const TimeStamp& a_time) } void -PeleLM::setTemperature(int lev, const TimeStamp& a_time) +PeleLM::setTemperature(const int lev, const TimeStamp a_time) { AMREX_ASSERT(a_time == AmrOldTime || a_time == AmrNewTime); @@ -237,7 +237,7 @@ PeleLM::setTemperature(int lev, const TimeStamp& a_time) } void -PeleLM::calc_dPdt(const TimeStamp& a_time, const Vector& a_dPdt) +PeleLM::calc_dPdt(const TimeStamp a_time, const Vector& a_dPdt) { BL_PROFILE("PeleLMeX::calc_dPdt()"); @@ -257,7 +257,7 @@ PeleLM::calc_dPdt(const TimeStamp& a_time, const Vector& a_dPdt) } void -PeleLM::calc_dPdt(int lev, const TimeStamp& a_time, MultiFab* a_dPdt) +PeleLM::calc_dPdt(const int lev, const TimeStamp a_time, MultiFab* a_dPdt) { auto const& sma = getLevelDataPtr(lev, a_time)->state.arrays(); auto const& dPdtma = a_dPdt->arrays(); diff --git a/Source/PeleLMeX_Evolve.cpp b/Source/PeleLMeX_Evolve.cpp index 11945722e..46208d268 100644 --- a/Source/PeleLMeX_Evolve.cpp +++ b/Source/PeleLMeX_Evolve.cpp @@ -7,7 +7,7 @@ PeleLM::Evolve() { BL_PROFILE("PeleLMeX::Evolve()"); - const bool do_not_evolve = + bool do_not_evolve = ((m_max_step == 0) || ((m_stop_time >= 0.) && (m_cur_time > m_stop_time))); int plt_justDidIt = 0; @@ -211,7 +211,7 @@ PeleLM::writeCheckNow() const bool PeleLM::doTemporalsNow() const { - return (m_do_temporals != 0) && (m_nstep % m_temp_int == 0) + return (m_do_temporals != 0) && (m_nstep % m_temp_int == 0); } bool diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 9e7c3b405..da0b9da8e 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -11,7 +11,7 @@ using namespace amrex; // including divTau if input Vector not empty void PeleLM::getVelForces( - const TimeStamp& a_time, + const TimeStamp a_time, const Vector& a_divTau, const Vector& a_velForce, const int nGrowForce, @@ -36,7 +36,7 @@ PeleLM::getVelForces( void PeleLM::getVelForces( - const TimeStamp& a_time, + const TimeStamp a_time, const int lev, MultiFab* a_divTau, MultiFab* a_velForce, @@ -120,7 +120,7 @@ PeleLM::getVelForces( } void -PeleLM::addSpark(const TimeStamp& a_timestamp) +PeleLM::addSpark(const TimeStamp a_timestamp) { for (int lev = 0; lev <= finest_level; ++lev) { for (int n = 0; n < m_n_sparks; ++n) { @@ -186,7 +186,7 @@ PeleLM::addSpark(const TimeStamp& a_timestamp) // Manifold model - dissipation rate sources for variances void -PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) +PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) { BL_PROFILE("PeleLM::addScalarVarianceSources"); // no scalar dissipation sources if not using a manifold model @@ -334,8 +334,8 @@ PeleLM::addScalarVarianceSources(const TimeStamp& a_timestamp) void PeleLM::getExternalSources( const int is_initIter, - const PeleLM::TimeStamp& a_timestamp_old, - const PeleLM::TimeStamp& a_timestamp_new) + const PeleLM::TimeStamp a_timestamp_old, + const PeleLM::TimeStamp a_timestamp_new) { amrex::ignore_unused(is_initIter); diff --git a/Source/PeleLMeX_Init.cpp b/Source/PeleLMeX_Init.cpp index f3a43d92d..8aee12a85 100644 --- a/Source/PeleLMeX_Init.cpp +++ b/Source/PeleLMeX_Init.cpp @@ -354,7 +354,7 @@ PeleLM::initLevelData(const int lev) auto const* lpmfdata = pmf_data.device_parm(); // don't want to use state for dummy in case user overwrites state in aux - MultiFab dummy_mf(grids[lev], ba[lev], 1, 0); + MultiFab dummy_mf(grids[lev], dmap[lev], 1, 0); auto state_ma = ldata_p->state.arrays(); auto aux_ma = @@ -456,7 +456,7 @@ PeleLM::projectInitSolution() if (m_has_divu != 0) { constexpr int is_initialization = 1; // Yes we are constexpr int computeDiffusionTerm = 1; // Needed here - constexpr nt do_avgDown = 1; // Always + constexpr int do_avgDown = 1; // Always // Light version of the diffusion data container std::unique_ptr diffData; diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 66532546d..f5070f824 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -27,7 +27,7 @@ namespace m2c = pele::physics::utilities::mks2cgs; namespace c2m = pele::physics::utilities::cgs2mks; namespace { -constexpr std::string level_prefix{"Level_"}; +const std::string level_prefix{"Level_"}; } void @@ -981,7 +981,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) auto state_ma = ldata_p->state.arrays(); amrex::ParallelFor( ldata_p->state, - [vel_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [state_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { Array4 vel(state_ma[box_no], VELX); for (int n = 0; n < AMREX_SPACEDIM; ++n) { vel(i, j, k, n) *= 0.01; @@ -1055,7 +1055,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) amrex::ParallelFor( ldata_p->state, [state_ma, P_cgs, eosparm = leosparm] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { - auto eos = pele::physic::PhysicsType::eos(eosparm); + auto eos = pele::physics::PhysicsType::eos(eosparm); Array4 rho(state_ma[box_no], DENSITY); Array4 rhoY(state_ma[box_no], FIRSTSPEC); Array4 rhoH(state_ma[box_no], RHOH); @@ -1075,17 +1075,17 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) #endif // Get density Real rho_cgs = 0.0; - eos.PYT2R(P_cgs, massfrac, temp_arr(i, j, k), rho_cgs); + eos.PYT2R(P_cgs, massfrac, temp(i, j, k), rho_cgs); rho(i, j, k) = c2m::Rho(rho_cgs); // Get enthalpy Real h_cgs = 0.0; - eos.TY2H(temp_arr(i, j, k), massfrac, h_cgs); - rhoH(i, j, k) = c2m::H(h_cgs) * rho_arr(i, j, k); + eos.TY2H(temp(i, j, k), massfrac, h_cgs); + rhoH(i, j, k) = c2m::H(h_cgs) * rho(i, j, k); // Fill rhoYs for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i, j, k, n) = massfrac[n] * rho_arr(i, j, k); + rhoY(i, j, k, n) = massfrac[n] * rho(i, j, k); } }); Gpu::streamSynchronize(); diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 1d2f2a7c6..2c7875f19 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -33,11 +33,11 @@ PeleLM::initialProjection() grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev])); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - auto state_ma = ldata_p->const_arrays(); + auto state_ma = ldata_p->state.const_arrays(); auto sigma_ma = sigma[lev]->arrays(); amrex::ParallelFor( - ldata_p, [state_ma, sigma_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { + ldata_p->state, [state_ma, sigma_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { Array4 rho(state_ma[box_no], DENSITY); sigma_ma[box_no](i, j, k) = dummy_dt / rho(i, j, k); }); @@ -61,7 +61,7 @@ PeleLM::initialProjection() setInflowBoundaryVel(*vel[lev], lev, AmrNewTime); #if AMREX_SPACEDIM == 2 if (geom[lev].IsRZ()) { - scaleProj_RZ(lev, *vel[lev]) + scaleProj_RZ(lev, *vel[lev]); }; #endif } @@ -201,7 +201,7 @@ PeleLM::initialPressProjection() void PeleLM::velocityProjection( - const int is_initIter, const TimeStamp& a_rhoTime, const Real& a_dt) + const int is_initIter, const TimeStamp a_rhoTime, const Real a_dt) { BL_PROFILE("PeleLMeX::velocityProjection()"); @@ -223,7 +223,7 @@ PeleLM::velocityProjection( auto sigma_ma = sigma[lev]->arrays(); amrex::ParallelFor( - *rhoHalf[lev], [rhoHalf_ma, sig_ma, dt = a_dt] AMREX_GPU_DEVICE( + *rhoHalf[lev], [rhoHalf_ma, sigma_ma, dt = a_dt] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { sigma_ma[box_no](i, j, k) = dt / rhoHalf_ma[box_no](i, j, k); }); @@ -250,8 +250,8 @@ PeleLM::velocityProjection( auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - auto state_old_ma = ldataOld_p->arrays(); - auto gp_new_ma = ldataNew_p->const_arrays(); + auto state_old_ma = ldataOld_p->state.arrays(); + auto gp_new_ma = ldataNew_p->gp.const_arrays(); if (m_incompressible == 0) { auto rho_ma = rhoHalf[lev]->const_arrays(); amrex::ParallelFor( @@ -307,7 +307,7 @@ PeleLM::velocityProjection( } #if AMREX_SPACEDIM == 2 if (geom[lev].IsRZ()) { - scaleProj_RZ(lev, *ve;[lev]); + scaleProj_RZ(lev, *vel[lev]); } #endif } diff --git a/Source/PeleLMeX_Reactions.cpp b/Source/PeleLMeX_Reactions.cpp index e18160673..871d1e52d 100644 --- a/Source/PeleLMeX_Reactions.cpp +++ b/Source/PeleLMeX_Reactions.cpp @@ -29,7 +29,7 @@ PeleLM::advanceChemistry(std::unique_ptr& advData) // This advanceChemistry is called on the finest level // It works with the AmrCore BoxArray and do not involve ParallelCopy void -PeleLM::advanceChemistry(int lev, const Real& a_dt, MultiFab& a_extForcing) +PeleLM::advanceChemistry(const int lev, const Real a_dt, MultiFab& a_extForcing) { BL_PROFILE("PeleLMeX::advanceChemistry_Lev" + std::to_string(lev) + "()"); @@ -179,7 +179,7 @@ PeleLM::advanceChemistry(int lev, const Real& a_dt, MultiFab& a_extForcing) // on uncovered boxes. void PeleLM::advanceChemistryBAChem( - int lev, const Real& a_dt, MultiFab& a_extForcing) + const int lev, const Real a_dt, MultiFab& a_extForcing) { BL_PROFILE("PeleLMeX::advanceChemistry_Lev" + std::to_string(lev) + "()"); @@ -368,7 +368,7 @@ PeleLM::advanceChemistryBAChem( void PeleLM::computeInstantaneousReactionRate( - const Vector& I_R, const TimeStamp& a_time) + const Vector& I_R, const TimeStamp a_time) { for (int lev = 0; lev <= finest_level; ++lev) { #ifdef PELE_USE_PLASMA @@ -381,7 +381,7 @@ PeleLM::computeInstantaneousReactionRate( void PeleLM::computeInstantaneousReactionRate( - int lev, const TimeStamp& a_time, MultiFab* a_I_R) + const int lev, const TimeStamp a_time, MultiFab* a_I_R) { BL_PROFILE("PeleLMeX::computeInstantaneousReactionRate()"); auto* ldata_p = getLevelDataPtr(lev, a_time); @@ -475,7 +475,7 @@ PeleLM::getScalarReactForce(std::unique_ptr& advData) } void -PeleLM::getHeatRelease(int a_lev, MultiFab* a_HR) +PeleLM::getHeatRelease(const int a_lev, MultiFab* a_HR) { auto* ldataNew_p = getLevelDataPtr(a_lev, AmrNewTime); auto* ldataR_p = getLevelDataReactPtr(a_lev); diff --git a/Source/PeleLMeX_Setup.cpp b/Source/PeleLMeX_Setup.cpp index 913bd21f3..bb536d4cc 100644 --- a/Source/PeleLMeX_Setup.cpp +++ b/Source/PeleLMeX_Setup.cpp @@ -385,7 +385,8 @@ PeleLM::readParameters() Print() << "Spark " << n << " name: " << m_spark[n] << "\n"; Print() << "Spark " << n << " time: " << m_spark_time[n] << "\n"; Print() << "Spark " << n << " duration: " << m_spark_duration[n] - << "\n" Print() << "Spark " << n << " location: "; + << "\n"; + Print() << "Spark " << n << " location: "; for (int d = 0; d < AMREX_SPACEDIM; ++d) { Print() << m_spark_location[n][d] << " "; } diff --git a/Source/PeleLMeX_Temporals.cpp b/Source/PeleLMeX_Temporals.cpp index c50206c2d..9d52c12bf 100644 --- a/Source/PeleLMeX_Temporals.cpp +++ b/Source/PeleLMeX_Temporals.cpp @@ -4,7 +4,7 @@ using namespace amrex; void -PeleLM::initTemporals(const PeleLM::TimeStamp& a_time) +PeleLM::initTemporals(const PeleLM::TimeStamp a_time) { if ((m_do_temporals == 0) && !(m_nstep % m_temp_int == 0)) { return; diff --git a/Source/PeleLMeX_Timestep.cpp b/Source/PeleLMeX_Timestep.cpp index 7a33fd72e..8490a0c47 100644 --- a/Source/PeleLMeX_Timestep.cpp +++ b/Source/PeleLMeX_Timestep.cpp @@ -4,7 +4,7 @@ using namespace amrex; Real -PeleLM::computeDt(int is_init, const TimeStamp& a_time) +PeleLM::computeDt(const int is_init, const TimeStamp a_time) { BL_PROFILE("PeleLMeX::computeDt()"); @@ -97,7 +97,7 @@ PeleLM::computeDt(int is_init, const TimeStamp& a_time) } Real -PeleLM::estConvectiveDt(const TimeStamp& a_time) +PeleLM::estConvectiveDt(const TimeStamp a_time) { Real estdt = 1.0e200; @@ -156,7 +156,7 @@ PeleLM::estConvectiveDt(const TimeStamp& a_time) } Real -PeleLM::estDivUDt(const TimeStamp& a_time) +PeleLM::estDivUDt(const TimeStamp a_time) { Real estdt = 1.0e200; @@ -228,7 +228,7 @@ PeleLM::estDivUDt(const TimeStamp& a_time) } void -PeleLM::checkDt(const TimeStamp& a_time, const Real& a_dt) +PeleLM::checkDt(const TimeStamp a_time, const Real a_dt) { BL_PROFILE("PeleLMeX::checkDt()"); @@ -239,27 +239,23 @@ PeleLM::checkDt(const TimeStamp& a_time, const Real& a_dt) for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_time); - - const auto dxinv = geom[lev].InvCellSizeArray(); - -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(ldata_p->state, TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); - auto const& rho = ldata_p->state.const_array(mfi, DENSITY); - auto const& vel = ldata_p->state.const_array(mfi, VELX); - auto const& divu = ldata_p->divu.const_array(mfi); - int divu_checkFlag = m_divu_checkFlag; - auto dtfac = m_divu_dtFactor; - auto rhoMin = m_divu_rhoMin; - amrex::ParallelFor( - bx, [rho, vel, divu, divu_checkFlag, dtfac, rhoMin, dxinv, - a_dt] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - check_divu_dt( - i, j, k, divu_checkFlag, dtfac, rhoMin, dxinv, rho, vel, divu, - a_dt); - }); - } + const GpuArray dxinv = geom[lev].InvCellSizeArray(); + + auto state_ma = ldata_p->state.const_arrays(); + auto divu_ma = ldata_p->divu.const_arrays(); + + amrex::ParallelFor( + ldata_p->state, + [state_ma, divu_ma, dxinv, a_dt, divu_checkFlag = m_divu_checkFlag, + dtfac = m_divu_dtFactor, + rhoMin = + m_divu_rhoMin] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Array4 rho(state_ma[box_no], DENSITY); + Array4 vel(state_ma[box_no], VELX); + Array4 divu = divu_ma[box_no]; + check_divu_dt( + i, j, k, divu_checkFlag, dtfac, rhoMin, dxinv, rho, vel, divu, a_dt); + }); } + Gpu::streamSynchronize(); } diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index 9f6192e34..4a3b8a9af 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -9,7 +9,7 @@ using namespace amrex; void -PeleLM::calcTurbViscosity(const TimeStamp& a_time) +PeleLM::calcTurbViscosity(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::calcTurbViscosity()"); @@ -249,7 +249,7 @@ PeleLM::calcTurbViscosity(const TimeStamp& a_time) } void -PeleLM::calcViscosity(const TimeStamp& a_time) +PeleLM::calcViscosity(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::calcViscosity()"); @@ -282,7 +282,7 @@ PeleLM::calcViscosity(const TimeStamp& a_time) } void -PeleLM::calcDiffusivity(const TimeStamp& a_time) +PeleLM::calcDiffusivity(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::calcDiffusivity()"); diff --git a/Source/PeleLMeX_UMac.cpp b/Source/PeleLMeX_UMac.cpp index edc6f6cb2..0ad2e5d87 100644 --- a/Source/PeleLMeX_UMac.cpp +++ b/Source/PeleLMeX_UMac.cpp @@ -85,8 +85,8 @@ PeleLM::createMACRHS(std::unique_ptr& advData) void PeleLM::addChiIncrement( - int a_sdcIter, - const TimeStamp& a_time, + const int a_sdcIter, + const TimeStamp a_time, std::unique_ptr& advData) { BL_PROFILE("PeleLMeX::addChiIncrement()"); @@ -163,7 +163,7 @@ PeleLM::addChiIncrement( void PeleLM::macProject( - const TimeStamp& a_time, + const TimeStamp a_time, std::unique_ptr& advData, const Vector& a_divu) { @@ -262,7 +262,7 @@ PeleLM::macProject( void PeleLM::create_constrained_umac_grown( - int a_nGrow, + const int a_nGrow, const Geometry* crse_geom, const Geometry* fine_geom, Array u_mac_crse, diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index ff844355e..211698a93 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -758,7 +758,7 @@ PeleLM::advFluxDivergence( #endif void -PeleLM::floorSpecies(const TimeStamp& a_time) +PeleLM::floorSpecies(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::floorSpecies()"); AMREX_ASSERT(a_time == AmrOldTime || a_time == AmrNewTime); @@ -1489,7 +1489,7 @@ cells */ void -PeleLM::setTypicalValues(const TimeStamp& a_time, int is_init) +PeleLM::setTypicalValues(const TimeStamp a_time, const int is_init) { // Get state Max/Min auto stateMax = From 380875566d1e69c131233706ea3ef2ac111a33f8 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 14 Jul 2025 10:33:48 +0200 Subject: [PATCH 31/87] eb and plasma fixes --- Source/PeleLMeX.H | 14 +++--- Source/PeleLMeX_EB.cpp | 63 ++++++++++++++------------ Source/PeleLMeX_Projection.cpp | 2 +- Source/Plasma/PeleLMeX_EFIonDrift.cpp | 2 +- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 28 ++++++------ Source/Plasma/PeleLMeX_EFPoisson.cpp | 24 ++++++++-- Source/Plasma/PeleLMeX_EFReactions.cpp | 2 +- Source/Plasma/PeleLMeX_EFTimeStep.cpp | 2 +- Source/Plasma/PeleLMeX_EFTransport.cpp | 2 +- Source/Plasma/PeleLMeX_EFUtils.cpp | 10 ++-- 10 files changed, 87 insertions(+), 62 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 181ccbb94..54828acd0 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -1627,7 +1627,7 @@ public: const int lev, const PeleLM::TimeStamp a_time, amrex::MultiFab* a_I_R); amrex::BCRec - hackBCChargedParticle(const amrex::Real& zk, const amrex::BCRec& bc_in); + hackBCChargedParticle(const amrex::Real zk, const amrex::BCRec& bc_in); amrex::Real estEFIonsDt(const PeleLM::TimeStamp a_time); @@ -1645,8 +1645,8 @@ public: int testExitNewton( const int newtonIter, - const amrex::Real& max_res, - const amrex::Real& norm_newtonDir); + const amrex::Real max_res, + const amrex::Real norm_newtonDir); void updateNLState(const amrex::Vector& a_update); @@ -1655,11 +1655,11 @@ public: void getNLStateScaling(amrex::Real& nEScale, amrex::Real& phiVScale); void getNLResidScaling(amrex::Real& nEScale, amrex::Real& phiVScale); - void scaleNLState(const amrex::Real& nEScale, const amrex::Real& phiVScale); + void scaleNLState(const amrex::Real nEScale, const amrex::Real phiVScale); void scaleNLResid( const amrex::Vector& a_resid, - const amrex::Real& nEScale, - const amrex::Real& phiVScale); + const amrex::Real nEScale, + const amrex::Real phiVScale); // get upwinded edge-centered MF from cc MF and ec Vel amrex::Array getUpwindedEdge( @@ -1675,7 +1675,7 @@ public: const amrex::Vector& a_Ax); void setUpPrecond( - const amrex::Real& a_dt, const amrex::Vector& a_nE); + const amrex::Real a_dt, const amrex::Vector& a_nE); void applyPrecond( const amrex::Vector& a_v, const amrex::Vector& a_Pv); diff --git a/Source/PeleLMeX_EB.cpp b/Source/PeleLMeX_EB.cpp index 670e2e748..4341b6018 100644 --- a/Source/PeleLMeX_EB.cpp +++ b/Source/PeleLMeX_EB.cpp @@ -58,15 +58,15 @@ PeleLM::makeEBGeometry() void PeleLM::redistributeAofS( - int a_lev, - Real& a_dt, + const int a_lev, + const Real a_dt, MultiFab& a_tmpDiv, - int div_comp, + const int div_comp, MultiFab& a_AofS, - int aofs_comp, + const int aofs_comp, MultiFab& a_state, - int state_comp, - int ncomp, + const int state_comp, + const int ncomp, const BCRec* d_bc, const Geometry& a_geom) const { @@ -139,7 +139,7 @@ PeleLM::redistributeAofS( } void -PeleLM::getCoveredIMask(int a_lev, iMultiFab& a_imask) const +PeleLM::getCoveredIMask(const int a_lev, iMultiFab& a_imask) const { const auto& ebfact = EBFactory(a_lev); const auto& flags = ebfact.getMultiEBCellFlagFab(); @@ -188,15 +188,15 @@ PeleLM::getCoveredIMask(int a_lev, iMultiFab& a_imask) const void PeleLM::redistributeDiff( - int a_lev, - const Real& a_dt, + const int a_lev, + const Real a_dt, MultiFab& a_tmpDiv, - int div_comp, + const int div_comp, MultiFab& a_diff, - int diff_comp, + const int diff_comp, const MultiFab& a_state, - int state_comp, - int ncomp, + const int state_comp, + const int ncomp, const BCRec* d_bc, const Geometry& a_geom) const { @@ -302,7 +302,7 @@ PeleLM::initCoveredState() } void -PeleLM::setCoveredState(const TimeStamp& a_time) +PeleLM::setCoveredState(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::setCoveredState()"); for (int lev = 0; lev <= finest_level; ++lev) { @@ -311,7 +311,7 @@ PeleLM::setCoveredState(const TimeStamp& a_time) } void -PeleLM::setCoveredState(int lev, const TimeStamp& a_time) +PeleLM::setCoveredState(const int lev, const TimeStamp a_time) { AMREX_ASSERT(a_time == AmrOldTime || a_time == AmrNewTime); @@ -411,7 +411,7 @@ PeleLM::initialRedistribution() } void -PeleLM::getEBDistance(int a_lev, MultiFab& a_signDistLev) +PeleLM::getEBDistance(const int a_lev, MultiFab& a_signDistLev) { BL_PROFILE("PeleLMeX::getEBDistance()"); @@ -461,7 +461,8 @@ PeleLM::getEBDistance(int a_lev, MultiFab& a_signDistLev) } Vector> -PeleLM::getEBState(int first_comp, int ncomp, const PeleLM::TimeStamp& a_time) +PeleLM::getEBState( + const int first_comp, const int ncomp, const TimeStamp a_time) { AMREX_ASSERT(first_comp >= VELX); AMREX_ASSERT(first_comp + ncomp <= NVAR); @@ -478,7 +479,10 @@ PeleLM::getEBState(int first_comp, int ncomp, const PeleLM::TimeStamp& a_time) std::unique_ptr PeleLM::getEBState( - int a_lev, int first_comp, int ncomp, const PeleLM::TimeStamp& a_time) + const int a_lev, + const int first_comp, + const int ncomp, + const TimeStamp a_time) { AMREX_ASSERT(first_comp >= VELX); AMREX_ASSERT(first_comp + ncomp <= NVAR); @@ -492,10 +496,10 @@ PeleLM::getEBState( FArrayBox PeleLM::getEBState( MFIter const& a_mfi, - int a_lev, - int first_comp, - int ncomp, - const PeleLM::TimeStamp& a_time) + const int a_lev, + const int first_comp, + const int ncomp, + const TimeStamp a_time) { AMREX_ASSERT(first_comp >= VELX); AMREX_ASSERT(first_comp + ncomp <= NVAR); @@ -545,11 +549,11 @@ PeleLM::getEBState( void PeleLM::getEBState( - int a_lev, - const PeleLM::TimeStamp& a_time, + const int a_lev, + const TimeStamp a_time, MultiFab& a_EBstate, - int stateComp, - int nComp) + const int stateComp, + const int nComp) { AMREX_ASSERT(a_EBstate.nComp() >= nComp); @@ -611,7 +615,10 @@ PeleLM::getEBState( void PeleLM::getEBDiff( - int a_lev, const TimeStamp& a_time, MultiFab& a_EBDiff, int diffComp) + const int a_lev, + const TimeStamp a_time, + MultiFab& a_EBDiff, + const int diffComp) { // Get Geom / EB data ProbParm const* lprobparm = prob_parm_d; @@ -798,7 +805,7 @@ PeleLM::checkEBInflowFunctions() if (m_verbose != 0 && m_useEBinflow != 0) { Print() << "WARNING: EB-inflow capability is experimental. Scalar " "diffusion is not supported at these boundaries and future " - "interface changes are possible!\n" + "interface changes are possible!\n"; } } #endif diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 2c7875f19..af87cb149 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -402,7 +402,7 @@ PeleLM::velocityProjection( } } -#ifdef AMREX_SPACEDIM == 2 +#if AMREX_SPACEDIM == 2 // In R-Z, AMReX-Hydro do an average down of r*vel. // Now that we have unscaled vel, need to do average down again // to have consistent vel across levels diff --git a/Source/Plasma/PeleLMeX_EFIonDrift.cpp b/Source/Plasma/PeleLMeX_EFIonDrift.cpp index d5d1fc26d..4cbc93f09 100644 --- a/Source/Plasma/PeleLMeX_EFIonDrift.cpp +++ b/Source/Plasma/PeleLMeX_EFIonDrift.cpp @@ -124,7 +124,7 @@ PeleLM::ionDriftVelocity(std::unique_ptr& advData) // Set BCRec for Umac Vector bcrec(NUM_IONS); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - for (int ion = 0; ion < NUM_IONS; io++ n) { + for (int ion = 0; ion < NUM_IONS; ++ion) { if (geom[lev - 1].isPeriodic(idim)) { bcrec[ion].setLo(idim, BCType::int_dir); bcrec[ion].setHi(idim, BCType::int_dir); diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index 538daef10..1a3443ed2 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -18,8 +18,8 @@ PeleLM::getPrecondOp() void PeleLM::implicitNonLinearSolve( - int sdcIter, - const Real& a_dt, + const int sdcIter, + const Real a_dt, std::unique_ptr& diffData, std::unique_ptr& advData) { @@ -219,7 +219,7 @@ PeleLM::implicitNonLinearSolve( int PeleLM::testExitNewton( - int newtonIter, const Real& max_res, const Real& norm_NewtonDir) + const int newtonIter, const Real max_res, const Real norm_NewtonDir) { int exit = 0; if (max_res <= m_ef_newtonTol || norm_NewtonDir <= 1e-11) { @@ -313,7 +313,7 @@ PeleLM::updateNLState(const Vector& a_update) void PeleLM::incrementElectronForcing( - int a_sstep, std::unique_ptr& advData) + const int a_sstep, std::unique_ptr& advData) { for (int lev = 0; lev <= finest_level; ++lev) { @@ -349,7 +349,7 @@ PeleLM::incrementElectronForcing( void PeleLM::computeBGcharge( - const Real& a_time, + const Real a_time, std::unique_ptr& diffData, std::unique_ptr& advData) { @@ -399,11 +399,11 @@ PeleLM::computeBGcharge( void PeleLM::nonLinearResidual( - const Real& a_dt, + const Real a_dt, const Vector& a_nlstate, const Vector& a_nlresid, - int updateScaling, - int updatePrecond) + const int updateScaling, + const int updatePrecond) { // Get unscaled copy of the NL state Vector nE(finest_level + 1); @@ -651,7 +651,7 @@ PeleLM::getAdvectionTerm( void PeleLM::getAdvectionFluxesMOL( - int lev, + const int lev, const Array& a_fluxes, const MultiFab& a_nE, const Array& a_ueff, @@ -717,7 +717,7 @@ PeleLM::getAdvectionFluxesMOL( void PeleLM::getAdvectionFluxes( - int lev, + const int lev, const Array& a_fluxes, const MultiFab& a_nE, const Array& a_ueff, @@ -873,7 +873,7 @@ PeleLM::getAdvectionFluxes( } void -PeleLM::setUpPrecond(const Real& a_dt, const Vector& a_nE) +PeleLM::setUpPrecond(const Real a_dt, const Vector& a_nE) { BL_PROFILE("PeleLMeX::setUpPrecond()"); @@ -1009,9 +1009,9 @@ PeleLM::setUpPrecond(const Real& a_dt, const Vector& a_nE) Array PeleLM::getUpwindedEdge( - int lev, - int edge_comp, - int ncomp, + const int lev, + const int edge_comp, + const int ncomp, Vector bcrec, const MultiFab& ccMF, const Array& ecVel) diff --git a/Source/Plasma/PeleLMeX_EFPoisson.cpp b/Source/Plasma/PeleLMeX_EFPoisson.cpp index 113d92309..5741f3389 100644 --- a/Source/Plasma/PeleLMeX_EFPoisson.cpp +++ b/Source/Plasma/PeleLMeX_EFPoisson.cpp @@ -6,7 +6,7 @@ using namespace amrex; void -PeleLM::poissonSolveEF(const TimeStamp& a_time) +PeleLM::poissonSolveEF(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::poissonSolveEF()"); if (ef_verbose) { @@ -17,13 +17,31 @@ PeleLM::poissonSolveEF(const TimeStamp& a_time) auto bcRecPhiV = fetchBCRecArray(PHIV, 1); // Build Poisson RHS: charge distribution - int nGhost = 0; + constexpr int nGhost = 0; + constexpr Real factor = -1.0; Vector> rhsPoisson(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { rhsPoisson[lev].reset(new MultiFab( grids[lev], dmap[lev], 1, nGhost, MFInfo(), *m_factory[lev])); auto ldata_p = getLevelDataPtr(lev, a_time); + + auto state_ma = ldata_p->state.const_arrays(); + auto rhs_ma = rhsPoisson[lev]->arrays(); + + amrex::ParallelFor( + ldata_p->state, [state_ma, rhs_ma, zk = zk] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + Array4 rhoY(state_ma[box_no], FIRSTSPEC); + Array4 nE(state_ma[box_no], NE); + rhs_ma[box_no](i, j, k) = -nE(i, j, k) * elemCharge * factor; + for (int n = 0; n < NUM_SPECIES; ++n) { + rhs_ma[box_no](i, j, k) += zk[n] * rhoY(i, j, k, n) * factor; + } + }); + } + Gpu::streamSynchronize(); + /* #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif @@ -43,7 +61,7 @@ PeleLM::poissonSolveEF(const TimeStamp& a_time) }); } } - + */ // Solve for PhiV getDiffusionOp()->diffuse_scalar( GetVecOfPtrs(getPhiVVect(a_time)), 0, GetVecOfConstPtrs(rhsPoisson), 0, {}, diff --git a/Source/Plasma/PeleLMeX_EFReactions.cpp b/Source/Plasma/PeleLMeX_EFReactions.cpp index c0aa9e7aa..21f68f9fe 100644 --- a/Source/Plasma/PeleLMeX_EFReactions.cpp +++ b/Source/Plasma/PeleLMeX_EFReactions.cpp @@ -5,7 +5,7 @@ using namespace amrex; void PeleLM::computeInstantaneousReactionRateEF( - int lev, const TimeStamp& a_time, MultiFab* a_I_R) + const int lev, const TimeStamp a_time, MultiFab* a_I_R) { auto ldata_p = getLevelDataPtr(lev, a_time); diff --git a/Source/Plasma/PeleLMeX_EFTimeStep.cpp b/Source/Plasma/PeleLMeX_EFTimeStep.cpp index 123c5dd7b..c6a379d2b 100644 --- a/Source/Plasma/PeleLMeX_EFTimeStep.cpp +++ b/Source/Plasma/PeleLMeX_EFTimeStep.cpp @@ -3,7 +3,7 @@ using namespace amrex; Real -PeleLM::estEFIonsDt(const TimeStamp& a_time) +PeleLM::estEFIonsDt(const TimeStamp a_time) { Real estdt = 1.0e200; constexpr Real small = 1.0e-8; diff --git a/Source/Plasma/PeleLMeX_EFTransport.cpp b/Source/Plasma/PeleLMeX_EFTransport.cpp index 4a35479a7..9d4c69b9d 100644 --- a/Source/Plasma/PeleLMeX_EFTransport.cpp +++ b/Source/Plasma/PeleLMeX_EFTransport.cpp @@ -4,7 +4,7 @@ using namespace amrex; void -PeleLM::calcEFTransport(const TimeStamp& a_time) +PeleLM::calcEFTransport(const TimeStamp a_time) { BL_PROFILE("PeleLMeX::calcEFTransport()"); diff --git a/Source/Plasma/PeleLMeX_EFUtils.cpp b/Source/Plasma/PeleLMeX_EFUtils.cpp index 80ba8dda8..afcde55b1 100644 --- a/Source/Plasma/PeleLMeX_EFUtils.cpp +++ b/Source/Plasma/PeleLMeX_EFUtils.cpp @@ -104,7 +104,7 @@ PeleLM::getNLResidScaling(Real& nEScale, Real& phiVScale) } void -PeleLM::scaleNLState(const Real& nEScale, const Real& phiVScale) +PeleLM::scaleNLState(const Real nEScale, const Real phiVScale) { for (int lev = 0; lev <= finest_level; ++lev) { m_leveldatanlsolve[lev]->nlState.mult(1.0 / nE_scale, 0, 1, m_nGrowState); @@ -114,7 +114,7 @@ PeleLM::scaleNLState(const Real& nEScale, const Real& phiVScale) void PeleLM::scaleNLResid( - const Vector& a_resid, const Real& nEScale, const Real& phiVScale) + const Vector& a_resid, const Real nEScale, const Real phiVScale) { for (int lev = 0; lev <= finest_level; ++lev) { a_resid[lev]->mult(1.0 / FnE_scale, 0, 1, 1); @@ -123,7 +123,7 @@ PeleLM::scaleNLResid( } BCRec -PeleLM::hackBCChargedParticle(const Real& charge, const BCRec& bc_in) +PeleLM::hackBCChargedParticle(const Real charge, const BCRec& bc_in) { BCRec bc_hacked; @@ -182,9 +182,9 @@ PeleLM::hackBCChargedParticle(const Real& charge, const BCRec& bc_in) void PeleLM::addLorentzVelForces( - int lev, + const int lev, const Box& bx, - const Real& a_time, + const Real a_time, Array4 const& force, Array4 const& rhoY, Array4 const& phiV, From b50e9cd8055d36537d60aee0db878c8540e9eb2c Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 14 Jul 2025 10:37:55 +0200 Subject: [PATCH 32/87] small change --- Source/PeleLMeX.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/PeleLMeX.cpp b/Source/PeleLMeX.cpp index cdafca081..ef6040c1c 100644 --- a/Source/PeleLMeX.cpp +++ b/Source/PeleLMeX.cpp @@ -42,7 +42,8 @@ PeleLM::~PeleLM() } PeleLM::LevelData* -PeleLM::getLevelDataPtr(const int lev, const TimeStamp a_time, int /*useUMac*/) +PeleLM::getLevelDataPtr( + const int lev, const TimeStamp a_time, const int /*useUMac*/) { AMREX_ASSERT( a_time == AmrOldTime || a_time == AmrNewTime || a_time == AmrHalfTime); @@ -336,7 +337,7 @@ PeleLM::getAuxDiffusivityVect(const TimeStamp a_time) void PeleLM::averageDownState(const TimeStamp a_time) { - int nCompState = (m_incompressible) != 0 ? AMREX_SPACEDIM : NVAR; + const int nCompState = (m_incompressible != 0) ? AMREX_SPACEDIM : NVAR; for (int lev = finest_level; lev > 0; --lev) { auto* ldataFine_p = getLevelDataPtr(lev, a_time); auto* ldataCrse_p = getLevelDataPtr(lev - 1, a_time); @@ -353,9 +354,10 @@ PeleLM::averageDownState(const TimeStamp a_time) void PeleLM::averageDownScalars(const TimeStamp a_time) { - int nScal = NUM_SPECIES + 3; // rho, rhoYs, rhoH, Temp #ifdef PELE_USE_PLASMA - nScal += 2; // rhoRT, nE + constexpr int nScal = NUM_SPECIES + 5; +#else + constexpr int nScal = NUM_SPECIES + 3; #endif for (int lev = finest_level; lev > 0; --lev) { auto* ldataFine_p = getLevelDataPtr(lev, a_time); From 1a4969b6dff0080c9b3e224c30f4f66eb1c7c02f Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 14 Jul 2025 10:49:17 +0200 Subject: [PATCH 33/87] more tweaking and fixes --- Source/PeleLMeX_DiffusionOp.cpp | 5 +++-- Source/PeleLMeX_Plot.cpp | 2 +- Source/PeleLMeX_Projection.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index d11cf3bae..32b749e06 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -176,7 +176,7 @@ DiffusionOp::diffuse_scalar( // => \alpha = 1.0, A is a_acoeff if provided, 1.0 otherwise // => \beta = a_dt, B face centered diffusivity bcoeff^{np1,k} - const Real alpha = (isPoissonSolve) != 0 ? 0.0 : 1.0; + const Real alpha = (isPoissonSolve != 0) ? 0.0 : 1.0; const Real beta = a_dt; m_scal_solve_op->setScalars(alpha, beta); for (int lev = 0; lev <= finest_level; ++lev) { @@ -393,7 +393,7 @@ DiffusionOp::diffuse_scalar( // => \alpha = 1.0, A is a_acoeff if provided, 1.0 otherwise // => \beta = a_dt, B face centered diffusivity bcoeff^{np1,k} - const Real alpha = (isPoissonSolve) != 0 ? 0.0 : 1.0; + const Real alpha = (isPoissonSolve != 0) ? 0.0 : 1.0; const Real beta = a_dt; m_scal_solve_op->setScalars(alpha, beta); for (int lev = 0; lev <= finest_level; ++lev) { @@ -1184,6 +1184,7 @@ DiffusionTensorOp::compute_divtau( } }); } + Gpu::streamSynchronize(); } } diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 658a6f975..8ecff64ce 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -1018,7 +1018,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) for (int n = 0; n < NUM_SOOT_MOMENTS; ++n) { soot(i, j, k, n) *= std::pow(100., soot_exp[n]); } - soot_arr(i, j, k, NUMSOOTVAR - 1) *= 1.E6; + soot(i, j, k, NUMSOOTVAR - 1) *= 1.E6; }); Gpu::streamSynchronize(); } diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index af87cb149..52144895b 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -343,7 +343,7 @@ PeleLM::velocityProjection( } else { auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - rhs_cc[lev].define( + rhs_cc.emplace_back( grids[lev], dmap[lev], 1, ldataOld_p->divu.nGrow(), MFInfo(), *m_factory[lev]); #ifdef AMREX_USE_OMP From 25925a78ace844ff7f838ed04e53554806dbd6d5 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 14 Jul 2025 10:59:05 +0200 Subject: [PATCH 34/87] more fixes --- Source/PeleLMeX_Projection.cpp | 4 ++-- Source/PeleLMeX_Radiation.cpp | 2 +- Source/PeleLMeX_Soot.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 52144895b..b47df64b2 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -260,7 +260,7 @@ PeleLM::velocityProjection( int box_no, int i, int j, int k) noexcept { Array4 vel(state_old_ma[box_no], VELX); const Real soverrho = dt / rho_ma[box_no](i, j, k); - for (int n = 0; n < NUM_SPECIES; ++n) { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; } }); @@ -271,7 +271,7 @@ PeleLM::velocityProjection( int box_no, int i, int j, int k) noexcept { Array4 vel(state_old_ma[box_no], VELX); const Real soverrho = dt / rho; - for (int n = 0; n < NUM_SPECIES; ++n) { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; } }); diff --git a/Source/PeleLMeX_Radiation.cpp b/Source/PeleLMeX_Radiation.cpp index 06e2d8a1a..7b6cd9ccc 100644 --- a/Source/PeleLMeX_Radiation.cpp +++ b/Source/PeleLMeX_Radiation.cpp @@ -35,7 +35,7 @@ PeleLM::RadInit() } void -PeleLM::computeRadSource(const PeleLM::TimeStamp& a_timestamp) +PeleLM::computeRadSource(const TimeStamp a_timestamp) { int const co2Indx = rad_model->readRadIndices().co2Indx; int const h2oIndx = rad_model->readRadIndices().h2oIndx; diff --git a/Source/PeleLMeX_Soot.cpp b/Source/PeleLMeX_Soot.cpp index 73abdcbfb..4c9589fa5 100644 --- a/Source/PeleLMeX_Soot.cpp +++ b/Source/PeleLMeX_Soot.cpp @@ -32,7 +32,7 @@ PeleLM::cleanupSootModel() } void -PeleLM::computeSootSource(const PeleLM::TimeStamp& a_timestamp, const Real a_dt) +PeleLM::computeSootSource(const TimeStamp a_timestamp, const Real a_dt) { bool pres_term = false; // Do not include change in pressure in energy for (int lev = 0; lev <= finest_level; ++lev) { From 7e20d12fc133920d6b74f27a952258d8ca1388a8 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 14 Jul 2025 11:42:38 +0200 Subject: [PATCH 35/87] increment fix --- Source/PeleLMeX_Plot.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 8ecff64ce..be1a46fd5 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -725,7 +725,7 @@ PeleLM::ReadCheckPointFile() std::istringstream lis(line); int i = 0; while (lis >> word) { - prob_lo[++i] = std::stod(word); + prob_lo[i++] = std::stod(word); } } @@ -735,7 +735,7 @@ PeleLM::ReadCheckPointFile() std::istringstream lis(line); int i = 0; while (lis >> word) { - prob_hi[++i] = std::stod(word); + prob_hi[i++] = std::stod(word); } } From e781026998c1c56e2e32042ab44866ef0a509ca8 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Thu, 31 Jul 2025 22:42:09 +0100 Subject: [PATCH 36/87] fixes --- .clang-tidy | 1 - .github/workflows/linux.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index a4a925c2f..d47543daa 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -24,7 +24,6 @@ Checks: 'bugprone-*, -readability-make-member-function-const, -readability-avoid-nested-conditional-operator, -readability-function-size, - performance-*' WarningsAsErrors: '' HeaderFilterRegex: 'PeleLMeX\/Source|PeleLMeX\/Exec|PeleLMeX\/Submodules\/PelePhysics\/Source|PeleLMeX\/Submodules\/PelePhysics\/Mechanism' FormatStyle: none diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 1e1968e5a..e79560e31 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -129,7 +129,7 @@ jobs: - name: Run working-directory: ./Exec/RegTests/EB_BackwardStepFlame/ run: | - mpirun -n 2 ./PeleLMeX2d.gnu.MPI.ex eb_bfs.inp amr.max_step=2 amr.plot_int=-1 amr.check_int=-1 amrex.abort_on_unused_inputs=1 + mpirun -n 2 ./PeleLMeX2d.gnu.MPI.ex eb_bfs.inp amr.max_step=2 amr.plot_int=-1 amr.check_int=-1 amrex.abort_on_unused_inputs=1 mac_proj.verbose=2 mac_proj.atol=5e-11 mac_proj.rtol=5e-11 # Build and Run the Plasma flamesheet with GNU9.3 and MPI support PLASMA: From 390eff6416adc488b84034570cc34b808b4b7709 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Thu, 31 Jul 2025 22:59:05 +0100 Subject: [PATCH 37/87] typo --- .clang-tidy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index d47543daa..bedbba1fd 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -23,7 +23,7 @@ Checks: 'bugprone-*, -readability-convert-member-functions-to-static, -readability-make-member-function-const, -readability-avoid-nested-conditional-operator, - -readability-function-size, + -readability-function-size' WarningsAsErrors: '' HeaderFilterRegex: 'PeleLMeX\/Source|PeleLMeX\/Exec|PeleLMeX\/Submodules\/PelePhysics\/Source|PeleLMeX\/Submodules\/PelePhysics\/Mechanism' FormatStyle: none From 624530c2c107e2b21d08ee591982a7dde95af873 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 1 Aug 2025 09:01:05 +0100 Subject: [PATCH 38/87] tolerance tweak --- Tests/CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index be94bf8fb..dd1c894aa 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -96,6 +96,14 @@ function(add_test_r TEST_NAME TEST_EXE_DIR) set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 18000 PROCESSORS ${PELE_NP} WORKING_DIRECTORY "${CURRENT_TEST_BINARY_DIR}/" LABELS "regression" ATTACHED_FILES "${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.log") endfunction(add_test_r) +#Standard regression test with looser tolerances +function(add_test_rtol TEST_NAME TEST_EXE_DIR) + setup_test() + set(RUNTIME_OPTIONS "amr.max_step=10 mac_proj.atol=5e-11 mac_proj.rtol=5e-11 mac_proj.verbose=2 ${RUNTIME_OPTIONS}") + add_test(${TEST_NAME} bash -c "set -o pipefail && ${MPI_COMMANDS} ${CURRENT_TEST_EXE} ${MPIEXEC_POSTFLAGS} ${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.inp ${RUNTIME_OPTIONS} 2>&1 | tee ${TEST_NAME}.log ${SAVE_GOLDS_COMMAND} ${FCOMPARE_COMMAND}") + set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 18000 PROCESSORS ${PELE_NP} WORKING_DIRECTORY "${CURRENT_TEST_BINARY_DIR}/" LABELS "regression" ATTACHED_FILES "${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.log") +endfunction(add_test_r) + # Regression test with mass conservation verification function(add_test_rv TEST_NAME TEST_EXE_DIR) setup_test() @@ -250,8 +258,8 @@ if(NOT PELE_ENABLE_EB) else() if(PELE_DIM EQUAL 2) add_test_rt(composition-test-${PELE_DIM}d EB_ODEQty) - add_test_r(eb_bfs EB_BackwardStepFlame) - add_test_r(eb_bfs_pp EB_BackwardStepFlame) + add_test_rtol(eb_bfs EB_BackwardStepFlame) + add_test_rtol(eb_bfs_pp EB_BackwardStepFlame) endif() add_test_r(eb-odeqty-${PELE_DIM}d EB_ODEQty) endif() From 38a78b71cf7381681f2fb31e8567b5f7c7429ce2 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Tue, 19 Aug 2025 10:43:48 +0200 Subject: [PATCH 39/87] formatting etc --- Source/PeleLMeX_Advection.cpp | 14 +- Source/PeleLMeX_BC.cpp | 197 ++++++++++++++++-------- Source/PeleLMeX_Data.cpp | 39 +++-- Source/PeleLMeX_Diffusion.cpp | 49 +++--- Source/PeleLMeX_DiffusionOp.cpp | 202 +++++++++++++------------ Source/PeleLMeX_EB.cpp | 7 +- Source/PeleLMeX_Eos.cpp | 12 +- Source/PeleLMeX_FlowController.cpp | 6 +- Source/PeleLMeX_Forces.cpp | 7 +- Source/PeleLMeX_Init.cpp | 2 +- Source/PeleLMeX_K.H | 2 +- Source/PeleLMeX_ODEQty.cpp | 17 ++- Source/PeleLMeX_Plot.cpp | 10 +- Source/PeleLMeX_Projection.cpp | 30 ++-- Source/PeleLMeX_Reactions.cpp | 3 +- Source/PeleLMeX_Setup.cpp | 12 +- Source/PeleLMeX_Soot.cpp | 2 +- Source/PeleLMeX_SprayParticles.cpp | 6 +- Source/PeleLMeX_Temporals.cpp | 7 +- Source/PeleLMeX_Timestep.cpp | 5 +- Source/PeleLMeX_TransportProp.cpp | 3 +- Source/PeleLMeX_Utils.cpp | 27 ++-- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 36 +++-- Source/Plasma/PeleLMeX_EFReactions.cpp | 3 +- Source/Plasma/PeleLMeX_EFTimeStep.cpp | 4 +- Source/Plasma/PeleLMeX_EFUtils.cpp | 8 +- 26 files changed, 418 insertions(+), 292 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 0998004f3..1c26ceab7 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -166,7 +166,8 @@ PeleLM::computeVelocityAdvTerm(std::unique_ptr& advData) //---------------------------------------------------------------- // Use a temporary MF to hold divergence before redistribution constexpr int nGrow_divT = 3; - amrex::MultiFab divTmp(grids[lev], dmap[lev], AMREX_SPACEDIM, nGrow_divT, amrex::MFInfo(), + amrex::MultiFab divTmp( + grids[lev], dmap[lev], AMREX_SPACEDIM, nGrow_divT, amrex::MFInfo(), EBFactory(lev)); divTmp.setVal(0.0); if (m_useEBinflow != 0) { @@ -290,7 +291,7 @@ PeleLM::getScalarAdvForce( is_closed_ch = m_closed_chamber, do_react = m_do_react] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rho(state_ma[box_no], DENSITY); + amrex::Array4 rho(state_ma[box_no], DENSITY); amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); amrex::Array4 T(state_ma[box_no], TEMP); amrex::Array4 dn(dn_ma[box_no], 0); @@ -800,9 +801,10 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) for (int lev = 0; lev <= finest_level; ++lev) { for (int n = 0; n < NUM_IONS; ++n) { const int spec_idx = NUM_SPECIES - NUM_IONS + n; - amrex::Array, AMREX_SPACEDIM> ionFlux; + amrex::Array, AMREX_SPACEDIM> ionFlux; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - ionFlux[idim].reset(new amrex::MultiFab(fluxes[lev][idim], amrex::make_alias, spec_idx, 1)); + ionFlux[idim].reset(new amrex::MultiFab( + fluxes[lev][idim], amrex::make_alias, spec_idx, 1)); } average_face_to_cellcenter( *m_ionsFluxes[lev], n * AMREX_SPACEDIM, GetArrOfConstPtrs(ionFlux)); @@ -1078,7 +1080,9 @@ PeleLM::computePassiveAdvTerms( //---------------------------------------------------------------- // Use a temporary MF to hold divergence before redistribution constexpr int nGrow_divTmp = 3; - amrex::MultiFab divTmp(grids[lev], dmap[lev], ncomp, nGrow_divTmp, amrex::MFInfo(), EBFactory(lev)); + amrex::MultiFab divTmp( + grids[lev], dmap[lev], ncomp, nGrow_divTmp, amrex::MFInfo(), + EBFactory(lev)); divTmp.setVal(0.0); advFluxDivergence( lev, divTmp, 0, divu, GetArrOfConstPtrs(fluxes[lev]), 0, diff --git a/Source/PeleLMeX_BC.cpp b/Source/PeleLMeX_BC.cpp index 206359103..d39c3949a 100644 --- a/Source/PeleLMeX_BC.cpp +++ b/Source/PeleLMeX_BC.cpp @@ -11,58 +11,69 @@ // SlipWallAdiab, NoSlipWallAdiab, SlipWallIsoTherm, NoSlipWallIsoTherm. constexpr int norm_vel_bc[] = { - amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_odd, - amrex::BCType::ext_dir, amrex::BCType::ext_dir, amrex::BCType::ext_dir, amrex::BCType::ext_dir}; + amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, + amrex::BCType::reflect_odd, amrex::BCType::ext_dir, amrex::BCType::ext_dir, + amrex::BCType::ext_dir, amrex::BCType::ext_dir}; constexpr int tang_vel_bc[] = { - amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::hoextrap, amrex::BCType::ext_dir, amrex::BCType::hoextrap, amrex::BCType::ext_dir}; + amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, + amrex::BCType::reflect_even, amrex::BCType::hoextrap, amrex::BCType::ext_dir, + amrex::BCType::hoextrap, amrex::BCType::ext_dir}; constexpr int density_bc[] = { - amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::foextrap}; + amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, + amrex::BCType::reflect_even, amrex::BCType::foextrap, amrex::BCType::foextrap, + amrex::BCType::foextrap, amrex::BCType::foextrap}; constexpr int species_bc[] = { - amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::foextrap}; - -constexpr int rhoh_bc[] = { - amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::ext_dir, amrex::BCType::ext_dir}; - -constexpr int temp_bc[] = { - amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::ext_dir, amrex::BCType::ext_dir}; - -constexpr int aux_bc[] = { - amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::ext_dir, amrex::BCType::ext_dir}; - -constexpr int divu_bc[] = {amrex::BCType::int_dir, amrex::BCType::reflect_even, - amrex::BCType::reflect_even, amrex::BCType::reflect_even, - amrex::BCType::reflect_even, amrex::BCType::reflect_even, - amrex::BCType::reflect_even,amrex::BCType::reflect_even}; + amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::foextrap, + amrex::BCType::reflect_even, amrex::BCType::foextrap, amrex::BCType::foextrap, + amrex::BCType::foextrap, amrex::BCType::foextrap}; + +constexpr int rhoh_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, + amrex::BCType::foextrap, amrex::BCType::reflect_even, + amrex::BCType::foextrap, amrex::BCType::foextrap, + amrex::BCType::ext_dir, amrex::BCType::ext_dir}; + +constexpr int temp_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, + amrex::BCType::foextrap, amrex::BCType::reflect_even, + amrex::BCType::foextrap, amrex::BCType::foextrap, + amrex::BCType::ext_dir, amrex::BCType::ext_dir}; + +constexpr int aux_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, + amrex::BCType::foextrap, amrex::BCType::reflect_even, + amrex::BCType::foextrap, amrex::BCType::foextrap, + amrex::BCType::ext_dir, amrex::BCType::ext_dir}; + +constexpr int divu_bc[] = { + amrex::BCType::int_dir, amrex::BCType::reflect_even, + amrex::BCType::reflect_even, amrex::BCType::reflect_even, + amrex::BCType::reflect_even, amrex::BCType::reflect_even, + amrex::BCType::reflect_even, amrex::BCType::reflect_even}; // Following incflo rather than IAMR here -constexpr int force_bc[] = { - amrex::BCType::int_dir, amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::foextrap, - amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::foextrap, amrex::BCType::foextrap}; +constexpr int force_bc[] = {amrex::BCType::int_dir, amrex::BCType::foextrap, + amrex::BCType::foextrap, amrex::BCType::foextrap, + amrex::BCType::foextrap, amrex::BCType::foextrap, + amrex::BCType::foextrap, amrex::BCType::foextrap}; #ifdef PELE_USE_PLASMA -constexpr int nE_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, - amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::reflect_even, amrex::BCType::reflect_even, - amrex::BCType::ext_dir, amrex::BCType::ext_dir}; +constexpr int nE_bc[] = { + amrex::BCType::int_dir, amrex::BCType::ext_dir, + amrex::BCType::foextrap, amrex::BCType::reflect_even, + amrex::BCType::reflect_even, amrex::BCType::reflect_even, + amrex::BCType::ext_dir, amrex::BCType::ext_dir}; constexpr int phiV_bc[] = { amrex::BCType::int_dir, amrex::BCType::ext_dir, amrex::BCType::reflect_even}; #endif #ifdef PELE_USE_SOOT -constexpr int soot_bc[] = {amrex::BCType::int_dir, amrex::BCType::ext_dir, - amrex::BCType::foextrap, amrex::BCType::reflect_even, - amrex::BCType::reflect_even, amrex::BCType::reflect_even, - amrex::BCType::ext_dir, amrex::BCType::ext_dir}; +constexpr int soot_bc[] = { + amrex::BCType::int_dir, amrex::BCType::ext_dir, + amrex::BCType::foextrap, amrex::BCType::reflect_even, + amrex::BCType::reflect_even, amrex::BCType::reflect_even, + amrex::BCType::ext_dir, amrex::BCType::ext_dir}; #endif amrex::InterpBase* @@ -81,7 +92,7 @@ PeleLM:: #ifdef AMREX_USE_EB // Get EB-aware interpolator when needed mapper = (EBFactory(0).isAllRegular()) ? &amrex::mf_cell_cons_interp - : &amrex::eb_mf_cell_cons_interp; + : &amrex::eb_mf_cell_cons_interp; #else mapper = &amrex::mf_cell_cons_interp; #endif @@ -380,7 +391,10 @@ PeleLM::fillPatchReact(const int lev, const amrex::Real a_time, const int nGrow) // Fill the state void PeleLM::fillpatch_state( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_state, const int nGhost) + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_state, + const int nGhost) { ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); @@ -596,7 +610,10 @@ PeleLM::fillpatch_temp( // Fill the auxiliaries void PeleLM::fillpatch_aux( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_aux, const int nGhost) + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_aux, + const int nGhost) { ProbParm const* lprobparm = prob_parm_d; @@ -702,7 +719,10 @@ PeleLM::fillpatch_phiV( // Fill the divU void PeleLM::fillpatch_divu( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_divu, const int nGhost) + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_divu, + const int nGhost) { if (lev == 0) { amrex::PhysBCFunct> @@ -737,7 +757,10 @@ PeleLM::fillpatch_divu( // -> actually only modifies the ghost cells : fillBoundary, C/F interp, // foextrap on domain BCs void -PeleLM::fillpatch_forces(const amrex::Real a_time, amrex::Vector const& a_force, const int nGrowForce) +PeleLM::fillpatch_forces( + const amrex::Real a_time, + amrex::Vector const& a_force, + const int nGrowForce) { AMREX_ASSERT(a_force[0]->nComp() <= m_bcrec_force.size()); const int nComp = a_force[0]->nComp(); @@ -769,7 +792,10 @@ PeleLM::fillpatch_forces(const amrex::Real a_time, amrex::Vector> @@ -804,7 +830,10 @@ PeleLM::fillpatch_gradp( // Fill the reaction data void PeleLM::fillpatch_reaction( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_I_R, const int nGhost) + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_I_R, + const int nGhost) { if (lev == 0) { amrex::PhysBCFunct> @@ -835,7 +864,10 @@ PeleLM::fillpatch_reaction( // Fill functC void PeleLM::fillpatch_chemFunctCall( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_fctC, const int nGhost) + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_fctC, + const int nGhost) { if (lev == 0) { amrex::PhysBCFunct> @@ -867,7 +899,10 @@ PeleLM::fillpatch_chemFunctCall( // Fill the state void PeleLM::fillcoarsepatch_state( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_state, const int nGhost) + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_state, + const int nGhost) { AMREX_ASSERT(lev > 0); ProbParm const* lprobparm = prob_parm_d; @@ -904,7 +939,10 @@ PeleLM::fillcoarsepatch_state( // Fill the auxiliaries void PeleLM::fillcoarsepatch_aux( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_aux, const int nGhost) + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_aux, + const int nGhost) { AMREX_ASSERT(lev > 0); ProbParm const* lprobparm = prob_parm_d; @@ -935,7 +973,10 @@ PeleLM::fillcoarsepatch_aux( // Fill the grad P void PeleLM::fillcoarsepatch_gradp( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_gp, const int nGhost) + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_gp, + const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -955,7 +996,10 @@ PeleLM::fillcoarsepatch_gradp( // Fill the divu void PeleLM::fillcoarsepatch_divu( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_divu, const int nGhost) + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_divu, + const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -974,7 +1018,10 @@ PeleLM::fillcoarsepatch_divu( // Fill coarse patch of reaction void PeleLM::fillcoarsepatch_reaction( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_I_R, const int nGhost) + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_I_R, + const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -994,7 +1041,10 @@ PeleLM::fillcoarsepatch_reaction( // Fill coarse patch of chem function call void PeleLM::fillcoarsepatch_chemFunctCall( - const int lev, const amrex::Real a_time, amrex::MultiFab& a_fctC, const int nGhost) + const int lev, + const amrex::Real a_time, + amrex::MultiFab& a_fctC, + const int nGhost) { // Interpolator auto* mapper = getInterpolator(m_regrid_interp_method); @@ -1014,7 +1064,8 @@ PeleLM::fillcoarsepatch_chemFunctCall( // Fill the inflow boundary of a velocity MF // used for velocity projection void -PeleLM::setInflowBoundaryVel(amrex::MultiFab& a_vel, const int lev, const TimeStamp a_time) +PeleLM::setInflowBoundaryVel( + amrex::MultiFab& a_vel, const int lev, const TimeStamp a_time) { BL_PROFILE("PeleLMeX::setInflowBoundaryVel()"); @@ -1057,7 +1108,11 @@ PeleLM::setInflowBoundaryVel(amrex::MultiFab& a_vel, const int lev, const TimeSt } void -PeleLM::fillTurbInflow(amrex::MultiFab& a_vel, const int vel_comp, const int lev, const amrex::Real a_time) +PeleLM::fillTurbInflow( + amrex::MultiFab& a_vel, + const int vel_comp, + const int lev, + const amrex::Real a_time) { if (turb_inflow.is_initialized()) { @@ -1068,7 +1123,8 @@ PeleLM::fillTurbInflow(amrex::MultiFab& a_vel, const int vel_comp, const int lev auto velBCRec = fetchBCRecArray(VELX, AMREX_SPACEDIM); // Copy problem parameter structs to host - amrex::Gpu::copy(amrex::Gpu::deviceToHost, probparmDD, probparmDD + 1, probparmDH); + amrex::Gpu::copy( + amrex::Gpu::deviceToHost, probparmDD, probparmDD + 1, probparmDH); #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) @@ -1080,47 +1136,56 @@ PeleLM::fillTurbInflow(amrex::MultiFab& a_vel, const int vel_comp, const int lev for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { - auto bndryBoxLO = amrex::Box(amrex::adjCellLo(geom[lev].Domain(), dir, 4) & bx); - if (velBCRec[0].lo()[dir] == amrex::BCType::ext_dir && bndryBoxLO.ok()) { + auto bndryBoxLO = + amrex::Box(amrex::adjCellLo(geom[lev].Domain(), dir, 4) & bx); + if ( + velBCRec[0].lo()[dir] == amrex::BCType::ext_dir && bndryBoxLO.ok()) { // Create box with ghost cells and set them to zero - amrex::IntVect growVect(amrex::IntVect::TheUnitVector()); + amrex::IntVect growVect(amrex::IntVect::TheUnitVector()); constexpr int Grow = 4; // Being conservative for (int n = 0; n < AMREX_SPACEDIM; ++n) { growVect[n] = Grow; } growVect[dir] = 0; - amrex::Box modDom = geom[lev].Domain(); + amrex::Box modDom = geom[lev].Domain(); modDom.grow(growVect); - auto bndryBoxLO_ghost = amrex::Box(amrex::adjCellLo(modDom, dir, Grow) & bx); + auto bndryBoxLO_ghost = + amrex::Box(amrex::adjCellLo(modDom, dir, Grow) & bx); data.setVal( 0.0, bndryBoxLO_ghost, vel_comp, AMREX_SPACEDIM); turb_inflow.add_turb( - bndryBoxLO, data, 0, geom[lev], a_time, dir, amrex::Orientation::low); + bndryBoxLO, data, 0, geom[lev], a_time, dir, + amrex::Orientation::low); } - auto bndryBoxHI = amrex::Box(amrex::adjCellHi(geom[lev].Domain(), dir, 4) & bx); - if (velBCRec[0].hi()[dir] == amrex::BCType::ext_dir && bndryBoxHI.ok()) { + auto bndryBoxHI = + amrex::Box(amrex::adjCellHi(geom[lev].Domain(), dir, 4) & bx); + if ( + velBCRec[0].hi()[dir] == amrex::BCType::ext_dir && bndryBoxHI.ok()) { // Create box with ghost cells and set them to zero - amrex::IntVect growVect(amrex::IntVect::TheUnitVector()); + amrex::IntVect growVect(amrex::IntVect::TheUnitVector()); constexpr int Grow = 4; for (int n = 0; n < AMREX_SPACEDIM; ++n) { growVect[n] = Grow; } growVect[dir] = 0; - amrex::Box modDom = geom[lev].Domain(); + amrex::Box modDom = geom[lev].Domain(); modDom.grow(growVect); - auto bndryBoxHI_ghost = amrex::Box(amrex::adjCellHi(modDom, dir, Grow) & bx); + auto bndryBoxHI_ghost = + amrex::Box(amrex::adjCellHi(modDom, dir, Grow) & bx); data.setVal( 0.0, bndryBoxHI_ghost, vel_comp, AMREX_SPACEDIM); turb_inflow.add_turb( - bndryBoxHI, data, 0, geom[lev], a_time, dir, amrex::Orientation::high); + bndryBoxHI, data, 0, geom[lev], a_time, dir, + amrex::Orientation::high); } } } // Copy problem parameter structs back to device - amrex::Gpu::copy(amrex::Gpu::hostToDevice, probparmDH, probparmDH + 1, probparmDD); + amrex::Gpu::copy( + amrex::Gpu::hostToDevice, probparmDH, probparmDH + 1, probparmDD); } } diff --git a/Source/PeleLMeX_Data.cpp b/Source/PeleLMeX_Data.cpp index 6eb4a2f63..ac44f55c8 100644 --- a/Source/PeleLMeX_Data.cpp +++ b/Source/PeleLMeX_Data.cpp @@ -94,7 +94,8 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( const int a_finestLevel, const amrex::Vector& ba, const amrex::Vector& dm, - const amrex::Vector>>& factory, + const amrex::Vector>>& + factory, const int nGrowAdv, const int a_use_wbar, const int a_use_soret, @@ -105,12 +106,15 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( Dnp1.reserve(a_finestLevel + 1); // Define MFs for (int lev = 0; lev <= a_finestLevel; ++lev) { - Dnp1.emplace_back(ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, amrex::MFInfo(), *factory[lev]); + Dnp1.emplace_back( + ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, amrex::MFInfo(), + *factory[lev]); } if (a_nAux > 0) { Dnp1_aux.reserve(a_finestLevel + 1); for (int lev = 0; lev <= a_finestLevel; ++lev) { - Dnp1_aux.emplace_back(ba[lev], dm[lev], a_nAux, nGrowAdv, amrex::MFInfo(), *factory[lev]); + Dnp1_aux.emplace_back( + ba[lev], dm[lev], a_nAux, nGrowAdv, amrex::MFInfo(), *factory[lev]); } } } else { @@ -135,14 +139,18 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( // Define MFs for (int lev = 0; lev <= a_finestLevel; ++lev) { Dn.emplace_back( - ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, amrex::MFInfo(), *factory[lev]); + ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, amrex::MFInfo(), + *factory[lev]); Dnp1.emplace_back( - ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, amrex::MFInfo(), *factory[lev]); + ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, amrex::MFInfo(), + *factory[lev]); Dhat.emplace_back( - ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, amrex::MFInfo(), *factory[lev]); + ba[lev], dm[lev], NUM_SPECIES + 2, nGrowAdv, amrex::MFInfo(), + *factory[lev]); if (a_use_wbar != 0) { Dwbar.emplace_back( - ba[lev], dm[lev], NUM_SPECIES, nGrowAdv, amrex::MFInfo(), *factory[lev]); + ba[lev], dm[lev], NUM_SPECIES, nGrowAdv, amrex::MFInfo(), + *factory[lev]); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const amrex::BoxArray& faceba = amrex::convert(ba[lev], amrex::IntVect::TheDimensionVector(idim)); @@ -152,7 +160,8 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( } if (a_use_soret != 0) { DT.emplace_back( - ba[lev], dm[lev], NUM_SPECIES, nGrowAdv, amrex::MFInfo(), *factory[lev]); + ba[lev], dm[lev], NUM_SPECIES, nGrowAdv, amrex::MFInfo(), + *factory[lev]); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const amrex::BoxArray& faceba = amrex::convert(ba[lev], amrex::IntVect::TheDimensionVector(idim)); @@ -162,11 +171,11 @@ PeleLM::AdvanceDiffData::AdvanceDiffData( } if (a_nAux > 0) { Dn_aux.emplace_back( - ba[lev], dm[lev], a_nAux, nGrowAdv, amrex::MFInfo(), *factory[lev]); + ba[lev], dm[lev], a_nAux, nGrowAdv, amrex::MFInfo(), *factory[lev]); Dnp1_aux.emplace_back( - ba[lev], dm[lev], a_nAux, nGrowAdv, amrex::MFInfo(), *factory[lev]); + ba[lev], dm[lev], a_nAux, nGrowAdv, amrex::MFInfo(), *factory[lev]); Dhat_aux.emplace_back( - ba[lev], dm[lev], a_nAux, nGrowAdv, amrex::MFInfo(), *factory[lev]); + ba[lev], dm[lev], a_nAux, nGrowAdv, amrex::MFInfo(), *factory[lev]); } } } @@ -176,7 +185,8 @@ PeleLM::AdvanceAdvData::AdvanceAdvData( const int a_finestLevel, const amrex::Vector& ba, const amrex::Vector& dm, - const amrex::Vector>>& factory, + const amrex::Vector>>& + factory, const int a_incompressible, const int a_nAux, const int nGrowAdv, @@ -212,9 +222,10 @@ PeleLM::AdvanceAdvData::AdvanceAdvData( } if (a_incompressible != 0) { AofS.emplace_back( - ba[lev], dm[lev], AMREX_SPACEDIM, 0, amrex::MFInfo(), *factory[lev]); + ba[lev], dm[lev], AMREX_SPACEDIM, 0, amrex::MFInfo(), *factory[lev]); } else { - AofS.emplace_back(ba[lev], dm[lev], NVAR, 0, amrex::MFInfo(), *factory[lev]); + AofS.emplace_back( + ba[lev], dm[lev], NVAR, 0, amrex::MFInfo(), *factory[lev]); chi.emplace_back(ba[lev], dm[lev], 1, 1, amrex::MFInfo(), *factory[lev]); #ifdef PELE_USE_PLASMA Forcing.emplace_back( diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index d3b28ec41..4deb24187 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -374,8 +374,10 @@ void PeleLM::correctIsothermalBoundary( const TimeStamp a_time, const amrex::Vector& a_spec_boundary, - const amrex::Vector>& a_wbarfluxes, - const amrex::Vector>& a_soretfluxes) + const amrex::Vector>& + a_wbarfluxes, + const amrex::Vector>& + a_soretfluxes) { BL_PROFILE("PeleLMeX::correctIsothermalBoundary()"); auto bcRecSpec = fetchBCRecArray(FIRSTSPEC, NUM_SPECIES); @@ -386,7 +388,8 @@ PeleLM::correctIsothermalBoundary( if (need_explicit_fluxes) { // need to fill the soret fluxes ourselves for (int lev = 0; lev <= finest_level; ++lev) { for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - soretfluxes[lev][idim] = new amrex::MultiFab(grids[lev], dmap[lev], NUM_SPECIES, 1, amrex::MFInfo(), Factory(lev)); + soretfluxes[lev][idim] = new amrex::MultiFab( + grids[lev], dmap[lev], NUM_SPECIES, 1, amrex::MFInfo(), Factory(lev)); soretfluxes[lev][idim]->setVal(0.0); } } @@ -505,7 +508,8 @@ PeleLM::computeDifferentialDiffusionFluxes( amrex::MultiFab::Copy( spec_boundary[lev], ldata_p->state, FIRSTSPEC, 0, NUM_SPECIES, 1); for (int n = 0; n < NUM_SPECIES; ++n) { - amrex::MultiFab::Divide(spec_boundary[lev], ldata_p->state, DENSITY, n, 1, 1); + amrex::MultiFab::Divide( + spec_boundary[lev], ldata_p->state, DENSITY, n, 1, 1); } } // correct the boundary values, pass empty soret & wbar to trigger explicit @@ -773,7 +777,8 @@ PeleLM::addWbarTerm( #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif { - for (amrex::MFIter mfi(*a_beta[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) { + for (amrex::MFIter mfi(*a_beta[lev], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { // Get edge centered rhoYs @@ -900,7 +905,8 @@ PeleLM::addSoretTerm( #endif { amrex::FArrayBox T_ed; - for (amrex::MFIter mfi(*a_beta[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) { + for (amrex::MFIter mfi(*a_beta[lev], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { // Get edge centered rhoYs @@ -1120,7 +1126,7 @@ PeleLM::differentialDiffusionUpdate( [state_ma, fY_ma, aux_ma, fAux_ma, dt = m_dt, nAux = m_nAux] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); + amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); for (int n = 0; n < NUM_SPECIES; ++n) { fY_ma[box_no](i, j, k, n) *= dt; fY_ma[box_no](i, j, k, n) += rhoY(i, j, k, n); @@ -1154,7 +1160,8 @@ PeleLM::differentialDiffusionUpdate( amrex::MultiFab::Copy( spec_boundary[lev], ldata_p->state, FIRSTSPEC, 0, NUM_SPECIES, 1); for (int n = 0; n < NUM_SPECIES; ++n) { - amrex::MultiFab::Divide(spec_boundary[lev], ldata_p->state, DENSITY, n, 1, 1); + amrex::MultiFab::Divide( + spec_boundary[lev], ldata_p->state, DENSITY, n, 1, 1); } } // correct boundary, we have lagged fluxes so lets use them @@ -1321,7 +1328,7 @@ PeleLM::differentialDiffusionUpdate( [state_ma, dhat_ma, force_ma, dwbar_ma, dT_ma, aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); + amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); for (int n = 0; n < NUM_SPECIES; ++n) { rhoY(i, j, k, n) = force_ma[box_no](i, j, k, n) + @@ -1339,7 +1346,7 @@ PeleLM::differentialDiffusionUpdate( [state_ma, dhat_ma, force_ma, dwbar_ma, aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); + amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); for (int n = 0; n < NUM_SPECIES; ++n) { rhoY(i, j, k, n) = force_ma[box_no](i, j, k, n) + @@ -1356,7 +1363,7 @@ PeleLM::differentialDiffusionUpdate( [state_ma, dhat_ma, force_ma, dT_ma, aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); + amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); for (int n = 0; n < NUM_SPECIES; ++n) { rhoY(i, j, k, n) = force_ma[box_no](i, j, k, n) + @@ -1373,7 +1380,7 @@ PeleLM::differentialDiffusionUpdate( [state_ma, dhat_ma, force_ma, aux_ma, dhat_aux_ma, force_aux_ma, nAux = m_nAux, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); + amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); for (int n = 0; n < NUM_SPECIES; ++n) { rhoY(i, j, k, n) = force_ma[box_no](i, j, k, n) + dt * dhat_ma[box_no](i, j, k, n); @@ -1580,17 +1587,18 @@ PeleLM::deltaTIter_prepare( [state_old_ma, state_new_ma, force_ma, dhat_ma, rhs_ma, rhocp_ma, tsave_ma, dtinv, leosparm, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rhoH_o(state_old_ma[box_no], RHOH); - amrex::Array4 rhoH_n(state_new_ma[box_no], RHOH); - amrex::Array4 force(force_ma[box_no], NUM_SPECIES); - amrex::Array4 fourier(dhat_ma[box_no], NUM_SPECIES); - amrex::Array4 diffDiff(dhat_ma[box_no], NUM_SPECIES + 1); + amrex::Array4 rhoH_o(state_old_ma[box_no], RHOH); + amrex::Array4 rhoH_n(state_new_ma[box_no], RHOH); + amrex::Array4 force(force_ma[box_no], NUM_SPECIES); + amrex::Array4 fourier(dhat_ma[box_no], NUM_SPECIES); + amrex::Array4 diffDiff( + dhat_ma[box_no], NUM_SPECIES + 1); // Assemble deltaT RHS rhs_ma[box_no](i, j, k) = dt * ((rhoH_o(i, j, k) - rhoH_n(i, j, k)) * dtinv + force(i, j, k) + fourier(i, j, k) + diffDiff(i, j, k)); - amrex::Array4 rho(state_new_ma[box_no], DENSITY); + amrex::Array4 rho(state_new_ma[box_no], DENSITY); amrex::Array4 rhoY(state_new_ma[box_no], FIRSTSPEC); amrex::Array4 T(state_new_ma[box_no], TEMP); // Get \rho * Cp_{mix} @@ -1754,7 +1762,8 @@ PeleLM::getScalarDiffForce( is_closed_ch = m_closed_chamber, nAux = m_nAux, aux_advect_d, aux_diffuse_d] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { amrex::Array4 ddn(dn_ma[box_no], NUM_SPECIES + 1); - amrex::Array4 ddnp1(dnp1_ma[box_no], NUM_SPECIES + 1); + amrex::Array4 ddnp1( + dnp1_ma[box_no], NUM_SPECIES + 1); amrex::Array4 a(a_ma[box_no], FIRSTSPEC); amrex::Array4 extRhoY(ext_ma[box_no], FIRSTSPEC); amrex::Array4 extRhoH(ext_ma[box_no], RHOH); @@ -1883,7 +1892,7 @@ PeleLM::getDiffusionTensorOpBC( } else { for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) { auto amrexbc = (a_side == amrex::Orientation::low) ? a_bc[dir].lo(idim) - : a_bc[dir].hi(idim); + : a_bc[dir].hi(idim); if (amrexbc == amrex::BCType::ext_dir) { r[dir][idim] = amrex::LinOpBCType::Dirichlet; } else if ( diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index 06a23d542..d14be7d64 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -92,21 +92,21 @@ DiffusionOp::DiffusionOp(PeleLM* a_pelelm, const int ncomp) void DiffusionOp::diffuse_scalar( - amrex::Vector const& a_phi, - const int phi_comp, - amrex::Vector const& a_rhs, - const int rhs_comp, - amrex::Vector> const& a_flux, - const int flux_comp, - amrex::Vector const& a_acoeff, - amrex::Vector const& a_density, - amrex::Vector const& a_bcoeff, - const int bcoeff_comp, - amrex::Vector a_bcrec, - const int ncomp, - const int isPoissonSolve, - const amrex::Real a_dt, - amrex::Vector const& a_boundary) + amrex::Vector const& a_phi, + const int phi_comp, + amrex::Vector const& a_rhs, + const int rhs_comp, + amrex::Vector> const& a_flux, + const int flux_comp, + amrex::Vector const& a_acoeff, + amrex::Vector const& a_density, + amrex::Vector const& a_bcoeff, + const int bcoeff_comp, + amrex::Vector a_bcrec, + const int ncomp, + const int isPoissonSolve, + const amrex::Real a_dt, + amrex::Vector const& a_boundary) { BL_PROFILE("DiffusionOp::diffuse_scalar()"); @@ -291,13 +291,13 @@ DiffusionOp::diffuse_scalar( auto phi_ma = phi[lev].const_arrays(); auto a_rho_ma = a_density[lev]->const_arrays(); amrex::ParallelFor( - phi[lev], [a_phi_ma, a_rho_ma, phi_ma, ncomp] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < ncomp; ++n) { - a_phi_ma[box_no](i, j, k, n) = - phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); - } - }); + phi[lev], [a_phi_ma, a_rho_ma, phi_ma, ncomp] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < ncomp; ++n) { + a_phi_ma[box_no](i, j, k, n) = + phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); + } + }); } amrex::Gpu::streamSynchronize(); } @@ -306,25 +306,25 @@ DiffusionOp::diffuse_scalar( #ifdef AMREX_USE_EB void DiffusionOp::diffuse_scalar( - amrex::Vector const& a_phi, - const int phi_comp, - amrex::Vector const& a_phiEB, - const int /*phiEB_comp*/, - amrex::Vector const& a_rhs, - const int rhs_comp, - amrex::Vector> const& a_flux, - const int flux_comp, - amrex::Vector const& a_acoeff, - amrex::Vector const& a_density, - amrex::Vector const& a_bcoeff, - const int bcoeff_comp, - amrex::Vector const& a_bcoeffEB, - const int /*bcoeffEB_comp*/, - amrex::Vector a_bcrec, - const int ncomp, - const int isPoissonSolve, - const amrex::Real a_dt, - amrex::Vector const& a_boundary) + amrex::Vector const& a_phi, + const int phi_comp, + amrex::Vector const& a_phiEB, + const int /*phiEB_comp*/, + amrex::Vector const& a_rhs, + const int rhs_comp, + amrex::Vector> const& a_flux, + const int flux_comp, + amrex::Vector const& a_acoeff, + amrex::Vector const& a_density, + amrex::Vector const& a_bcoeff, + const int bcoeff_comp, + amrex::Vector const& a_bcoeffEB, + const int /*bcoeffEB_comp*/, + amrex::Vector a_bcrec, + const int ncomp, + const int isPoissonSolve, + const amrex::Real a_dt, + amrex::Vector const& a_boundary) { BL_PROFILE("DiffusionOp::diffuse_scalar()"); @@ -516,14 +516,14 @@ DiffusionOp::diffuse_scalar( void DiffusionOp::computeDiffLap( - amrex::Vector const& a_laps, - const int lap_comp, - amrex::Vector const& a_phi, - const int phi_comp, - amrex::Vector const& a_bcoeff, - const int bcoeff_comp, - amrex::Vector a_bcrec, - const int ncomp) + amrex::Vector const& a_laps, + const int lap_comp, + amrex::Vector const& a_phi, + const int phi_comp, + amrex::Vector const& a_bcoeff, + const int bcoeff_comp, + amrex::Vector a_bcrec, + const int ncomp) { BL_PROFILE("DiffusionOp::computeDiffLap()"); @@ -590,17 +590,17 @@ DiffusionOp::computeDiffLap( void DiffusionOp::computeDiffFluxes( - amrex::Vector> const& a_flux, - const int flux_comp, - amrex::Vector const& a_phi, - const int phi_comp, - amrex::Vector const& a_density, - amrex::Vector const& a_bcoeff, - const int bcoeff_comp, - amrex::Vector a_bcrec, - const int ncomp, - const int do_avgDown, - amrex::Vector const& a_boundary) + amrex::Vector> const& a_flux, + const int flux_comp, + amrex::Vector const& a_phi, + const int phi_comp, + amrex::Vector const& a_density, + amrex::Vector const& a_bcoeff, + const int bcoeff_comp, + amrex::Vector a_bcrec, + const int ncomp, + const int do_avgDown, + amrex::Vector const& a_boundary) { BL_PROFILE("DiffusionOp::computeDiffFluxes()"); @@ -729,21 +729,21 @@ DiffusionOp::computeDiffFluxes( #ifdef AMREX_USE_EB void DiffusionOp::computeDiffFluxes( - amrex::Vector> const& a_flux, - const int flux_comp, - amrex::Vector const& a_EBflux, - const int ebflux_comp, - amrex::Vector const& a_phi, - const int phi_comp, - amrex::Vector const& a_density, - amrex::Vector const& a_bcoeff, - const int bcoeff_comp, - amrex::Vector const& a_EBvalue, - amrex::Vector const& a_EBbcoeff, - amrex::Vector a_bcrec, - const int ncomp, - const int do_avgDown, - amrex::Vector const& a_boundary) + amrex::Vector> const& a_flux, + const int flux_comp, + amrex::Vector const& a_EBflux, + const int ebflux_comp, + amrex::Vector const& a_phi, + const int phi_comp, + amrex::Vector const& a_density, + amrex::Vector const& a_bcoeff, + const int bcoeff_comp, + amrex::Vector const& a_EBvalue, + amrex::Vector const& a_EBbcoeff, + amrex::Vector a_bcrec, + const int ncomp, + const int do_avgDown, + amrex::Vector const& a_boundary) { BL_PROFILE("DiffusionOp::computeDiffFluxes()"); @@ -951,8 +951,8 @@ DiffusionOp::avgDownFluxes( amrex::Array flux_fine; amrex::Array flux_crse; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - flux_fine[idim] = - new amrex::MultiFab(*a_fluxes[lev][idim], amrex::make_alias, flux_comp, ncomp); + flux_fine[idim] = new amrex::MultiFab( + *a_fluxes[lev][idim], amrex::make_alias, flux_comp, ncomp); flux_crse[idim] = new amrex::MultiFab( *a_fluxes[lev - 1][idim], amrex::make_alias, flux_comp, ncomp); } @@ -1099,12 +1099,12 @@ DiffusionTensorOp::computeGradientTensor( void DiffusionTensorOp::compute_divtau( - amrex::Vector const& a_divtau, - amrex::Vector const& a_vel, - amrex::Vector const& a_density, - amrex::Vector const& a_beta, - const amrex::BCRec& a_bcrec, - const amrex::Real scale) + amrex::Vector const& a_divtau, + amrex::Vector const& a_vel, + amrex::Vector const& a_density, + amrex::Vector const& a_beta, + const amrex::BCRec& a_bcrec, + const amrex::Real scale) { const int finest_level = m_pelelm->finestLevel(); @@ -1137,8 +1137,9 @@ DiffusionTensorOp::compute_divtau( } constexpr int doZeroVisc = 0; constexpr int addTurbContrib = 1; - amrex::Array beta_ec = m_pelelm->getDiffusivity( - lev, 0, 1, doZeroVisc, {a_bcrec}, *a_beta[lev], addTurbContrib); + amrex::Array beta_ec = + m_pelelm->getDiffusivity( + lev, 0, 1, doZeroVisc, {a_bcrec}, *a_beta[lev], addTurbContrib); m_apply_op->setShearViscosity( lev, GetArrOfConstPtrs(beta_ec), amrex::MLMG::Location::FaceCentroid); if (m_pelelm->m_useEBinflow != 0) { @@ -1170,8 +1171,9 @@ DiffusionTensorOp::compute_divtau( } constexpr int doZeroVisc = 0; constexpr int addTurbContrib = 1; - amrex::Array beta_ec = m_pelelm->getDiffusivity( - lev, 0, 1, doZeroVisc, {a_bcrec}, *a_beta[lev], addTurbContrib); + amrex::Array beta_ec = + m_pelelm->getDiffusivity( + lev, 0, 1, doZeroVisc, {a_bcrec}, *a_beta[lev], addTurbContrib); m_apply_op->setShearViscosity(lev, GetArrOfConstPtrs(beta_ec)); m_apply_op->setLevelBC(lev, &vel[lev]); } @@ -1185,11 +1187,12 @@ DiffusionTensorOp::compute_divtau( auto divtau_ma = a_divtau[lev]->arrays(); auto rho_ma = a_density[lev]->const_arrays(); amrex::ParallelFor( - *a_divtau[lev], [divtau_ma, rho_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - divtau_ma[box_no](i, j, k, n) /= rho_ma[box_no](i, j, k); - } - }); + *a_divtau[lev], [divtau_ma, rho_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { + divtau_ma[box_no](i, j, k, n) /= rho_ma[box_no](i, j, k); + } + }); } amrex::Gpu::streamSynchronize(); } @@ -1197,11 +1200,11 @@ DiffusionTensorOp::compute_divtau( void DiffusionTensorOp::diffuse_velocity( - amrex::Vector const& a_vel, - amrex::Vector const& a_density, - amrex::Vector const& a_beta, - const amrex::BCRec& a_bcrec, - const amrex::Real a_dt) + amrex::Vector const& a_vel, + amrex::Vector const& a_density, + amrex::Vector const& a_beta, + const amrex::BCRec& a_bcrec, + const amrex::Real a_dt) { const int finest_level = m_pelelm->finestLevel(); @@ -1221,8 +1224,9 @@ DiffusionTensorOp::diffuse_velocity( } constexpr int doZeroVisc = 0; constexpr int addTurbContrib = 1; - amrex::Array beta_ec = m_pelelm->getDiffusivity( - lev, 0, 1, doZeroVisc, {a_bcrec}, *a_beta[lev], addTurbContrib); + amrex::Array beta_ec = + m_pelelm->getDiffusivity( + lev, 0, 1, doZeroVisc, {a_bcrec}, *a_beta[lev], addTurbContrib); #ifdef AMREX_USE_EB m_solve_op->setShearViscosity( lev, GetArrOfConstPtrs(beta_ec), amrex::MLMG::Location::FaceCentroid); diff --git a/Source/PeleLMeX_EB.cpp b/Source/PeleLMeX_EB.cpp index f0bc247bf..56f06ff63 100644 --- a/Source/PeleLMeX_EB.cpp +++ b/Source/PeleLMeX_EB.cpp @@ -821,9 +821,10 @@ PeleLM::checkEBInflowFunctions() "function"); } if (m_verbose != 0 && m_useEBinflow != 0) { - amrex::Print() << "WARNING: EB-inflow capability is experimental. Scalar " - "diffusion is not supported at these boundaries and future " - "interface changes are possible!\n"; + amrex::Print() + << "WARNING: EB-inflow capability is experimental. Scalar " + "diffusion is not supported at these boundaries and future " + "interface changes are possible!\n"; } } #endif diff --git a/Source/PeleLMeX_Eos.cpp b/Source/PeleLMeX_Eos.cpp index 58a1da4e8..5242317b4 100644 --- a/Source/PeleLMeX_Eos.cpp +++ b/Source/PeleLMeX_Eos.cpp @@ -233,7 +233,8 @@ PeleLM::setTemperature(const int lev, const TimeStamp a_time) } void -PeleLM::calc_dPdt(const TimeStamp a_time, const amrex::Vector& a_dPdt) +PeleLM::calc_dPdt( + const TimeStamp a_time, const amrex::Vector& a_dPdt) { BL_PROFILE("PeleLMeX::calc_dPdt()"); @@ -253,7 +254,8 @@ PeleLM::calc_dPdt(const TimeStamp a_time, const amrex::Vector& } void -PeleLM::calc_dPdt(const int lev, const TimeStamp a_time, amrex::MultiFab* a_dPdt) +PeleLM::calc_dPdt( + const int lev, const TimeStamp a_time, amrex::MultiFab* a_dPdt) { auto const& sma = getLevelDataPtr(lev, a_time)->state.arrays(); auto const& dPdtma = a_dPdt->arrays(); @@ -347,10 +349,10 @@ PeleLM::adjustPandDivU(std::unique_ptr& advData) amrex::Gpu::streamSynchronize(); if (m_verbose > 2) { - amrex::Print() << " >> Closed chamber pOld: " << m_pOld << ", pNew: " << m_pNew - << ", dp0dt: " << m_dp0dt << "\n"; + amrex::Print() << " >> Closed chamber pOld: " << m_pOld + << ", pNew: " << m_pNew << ", dp0dt: " << m_dp0dt << "\n"; amrex::Print() << " >> Total mass old: " << m_massOld - << ", mass new: " << m_massNew << "\n"; + << ", mass new: " << m_massNew << "\n"; } // Return Sbar so that we'll add it back to mac_divu after the MAC projection diff --git a/Source/PeleLMeX_FlowController.cpp b/Source/PeleLMeX_FlowController.cpp index 532bd904b..0935aeb91 100644 --- a/Source/PeleLMeX_FlowController.cpp +++ b/Source/PeleLMeX_FlowController.cpp @@ -450,9 +450,9 @@ PeleLM::loadActiveControlHistory() if (m_ctrl_verbose != 0) { amrex::Print() << " AC history arrays: \n"; for (long int n = 0; n < m_ctrl_time_pts.size(); ++n) { - amrex::Print() << " [" << n << "] time: " << m_ctrl_time_pts[n] - << ", velo: " << m_ctrl_velo_pts[n] - << ", coft: " << m_ctrl_cntl_pts[n] << "\n"; + amrex::Print() << " [" << n << "] time: " << m_ctrl_time_pts[n] + << ", velo: " << m_ctrl_velo_pts[n] + << ", coft: " << m_ctrl_cntl_pts[n] << "\n"; } } } else { diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 0b43b731d..7c6ea3ed7 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -70,9 +70,7 @@ PeleLM::getVelForces( amrex::ParallelFor( *a_velForce, [state_ma, ext_ma, force_ma, gp_ma, divTau_ma, dx, add_gradP, has_divTau, - time, grav, gp0, ps_dir, - is_incomp, rho_incomp, - pseudo_gravity, dV_control + time, grav, gp0, ps_dir, is_incomp, rho_incomp, pseudo_gravity, dV_control #ifdef PELE_USE_PLASMA , plasma_ba = grids[lev], zk = zk @@ -224,7 +222,8 @@ PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) constexpr int do_avgDown = 0; auto bcRecScalar = fetchBCRecArray(var_of_scalar, 1); constexpr int nGrow = 0; // No need for ghost face on fluxes - amrex::Vector> grad_fc(finest_level + 1); + amrex::Vector> grad_fc( + finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { const auto& ba = grids[lev]; const auto& factory = Factory(lev); diff --git a/Source/PeleLMeX_Init.cpp b/Source/PeleLMeX_Init.cpp index 937912b40..e27667f86 100644 --- a/Source/PeleLMeX_Init.cpp +++ b/Source/PeleLMeX_Init.cpp @@ -303,7 +303,7 @@ PeleLM::initData() m_dt = -1.0; constexpr int is_init = 1; const amrex::Real dtInit = computeDt(is_init, AmrNewTime); - Print() << " Initial dt: " << dtInit << "\n"; + amrex::Print() << " Initial dt: " << dtInit << "\n"; } // Let's write the initial condition diff --git a/Source/PeleLMeX_K.H b/Source/PeleLMeX_K.H index 60acb054f..491a58572 100644 --- a/Source/PeleLMeX_K.H +++ b/Source/PeleLMeX_K.H @@ -615,7 +615,7 @@ cen2edg_cpp( } else { for (int n = 0; n < ncomp; ++n) { efab(i, j, k, n) = 0.5 * (cfab(id_l[0], id_l[1], id_l[2], n) + - cfab(id_h[0], id_h[1], id_h[2], n)); + cfab(id_h[0], id_h[1], id_h[2], n)); } } } diff --git a/Source/PeleLMeX_ODEQty.cpp b/Source/PeleLMeX_ODEQty.cpp index 6ce7ecde2..e43344351 100644 --- a/Source/PeleLMeX_ODEQty.cpp +++ b/Source/PeleLMeX_ODEQty.cpp @@ -11,13 +11,16 @@ PeleLM::predictODEQty() auto const& state_arrs = getLevelDataPtr(lev, AmrNewTime)->state.arrays(); auto const& ext_src_arrs = m_extSource[lev]->arrays(); const auto dt = m_dt; - amrex::ParallelFor(*m_extSource[lev], [state_arrs, ext_src_arrs, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < NUM_ODE; ++n) { - amrex::Real const& B_n = state_arrs[box_no](i, j, k, FIRSTODE + n); - amrex::Real const& S_ext_n = ext_src_arrs[box_no](i, j, k, FIRSTODE + n); - state_arrs[box_no](i, j, k, FIRSTODE + n) = B_n + dt * S_ext_n; - } - }); + amrex::ParallelFor( + *m_extSource[lev], [state_arrs, ext_src_arrs, dt = m_dt] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < NUM_ODE; ++n) { + amrex::Real const& B_n = state_arrs[box_no](i, j, k, FIRSTODE + n); + amrex::Real const& S_ext_n = + ext_src_arrs[box_no](i, j, k, FIRSTODE + n); + state_arrs[box_no](i, j, k, FIRSTODE + n) = B_n + dt * S_ext_n; + } + }); } amrex::Gpu::streamSynchronize(); } diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index c7419c1d6..7ee45c580 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -21,7 +21,6 @@ #include "PeleLMRad.H" #endif - namespace m2c = pele::physics::utilities::mks2cgs; namespace c2m = pele::physics::utilities::cgs2mks; @@ -179,7 +178,8 @@ PeleLM::WritePlotFile() amrex::Vector mf_plt; mf_plt.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - mf_plt.emplace_back(grids[lev], dmap[lev], ncomp, 0, amrex::MFInfo(), Factory(lev)); + mf_plt.emplace_back( + grids[lev], dmap[lev], ncomp, 0, amrex::MFInfo(), Factory(lev)); } //---------------------------------------------------------------- @@ -1020,7 +1020,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) amrex::ParallelFor( ldata_p->state, [state_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 vel(state_ma[box_no], VELX); + amrex::Array4 vel(state_ma[box_no], VELX); for (int n = 0; n < AMREX_SPACEDIM; ++n) { vel(i, j, k, n) *= 0.01; } @@ -1051,13 +1051,13 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) amrex::ParallelFor( ldata_p->state, [state_ma, soot_exp] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { - amrex::Array4 soot(state_ma[box_no], FIRSTSOOT); + amrex::Array4 soot(state_ma[box_no], FIRSTSOOT); for (int n = 0; n < NUM_SOOT_MOMENTS; ++n) { soot(i, j, k, n) *= std::pow(100., soot_exp[n]); } soot(i, j, k, NUMSOOTVAR - 1) *= 1.E6; }); - amrex::Gpu::streamSynchronize(); + amrex::Gpu::streamSynchronize(); } } else { SootData* const sd = soot_model->getSootData(); diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 438b782fa..be1d3ce14 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -25,16 +25,19 @@ PeleLM::initialProjection() if (m_incompressible == 0) { sigma.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - sigma.emplace_back(std::make_unique(grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); - + sigma.emplace_back( + std::make_unique( + grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); + auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); auto state_ma = ldata_p->state.const_arrays(); auto sigma_ma = sigma[lev]->arrays(); - amrex::ParallelFor(ldata_p->state, [state_ma, sigma_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - amrex::Array4 rho(state_ma[box_no], DENSITY); - sigma_ma[box_no](i, j, k) = dummy_dt / rho(i, j, k); - }); + amrex::ParallelFor( + ldata_p->state, [state_ma, sigma_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + amrex::Array4 rho(state_ma[box_no], DENSITY); + sigma_ma[box_no](i, j, k) = dummy_dt / rho(i, j, k); + }); amrex::Gpu::streamSynchronize(); #if AMREX_SPACEDIM == 2 if (geom[lev].IsRZ()) { @@ -150,7 +153,7 @@ PeleLM::initialPressProjection() sigma.emplace_back( std::make_unique( - grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); + grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); auto state_ma = ldata_p->state.const_arrays(); @@ -175,7 +178,8 @@ PeleLM::initialPressProjection() vel.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { vel.emplace_back( - grids[lev], dmap[lev], AMREX_SPACEDIM, nGhost, amrex::MFInfo(), *m_factory[lev]); + grids[lev], dmap[lev], AMREX_SPACEDIM, nGhost, amrex::MFInfo(), + *m_factory[lev]); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { vel[lev].setVal(m_gravity[idim], idim, 1, 1); } @@ -205,12 +209,14 @@ PeleLM::velocityProjection( // Get sigma : scaled density inv. if not incompressible amrex::Vector> sigma; if (m_incompressible == 0) { - amrex::Vector> rhoHalf = getDensityVect(a_rhoTime); + amrex::Vector> rhoHalf = + getDensityVect(a_rhoTime); sigma.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - + sigma.emplace_back( - std::make_unique(grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); + std::make_unique( + grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); auto rhoHalf_ma = rhoHalf[lev]->const_arrays(); auto sigma_ma = sigma[lev]->arrays(); diff --git a/Source/PeleLMeX_Reactions.cpp b/Source/PeleLMeX_Reactions.cpp index 5560606bc..99f63620e 100644 --- a/Source/PeleLMeX_Reactions.cpp +++ b/Source/PeleLMeX_Reactions.cpp @@ -27,7 +27,8 @@ PeleLM::advanceChemistry(std::unique_ptr& advData) // This advanceChemistry is called on the finest level // It works with the AmrCore BoxArray and do not involve ParallelCopy void -PeleLM::advanceChemistry(const int lev, const amrex::Real a_dt, amrex::MultiFab& a_extForcing) +PeleLM::advanceChemistry( + const int lev, const amrex::Real a_dt, amrex::MultiFab& a_extForcing) { BL_PROFILE("PeleLMeX::advanceChemistry_Lev" + std::to_string(lev) + "()"); diff --git a/Source/PeleLMeX_Setup.cpp b/Source/PeleLMeX_Setup.cpp index 3d457e5bc..099bce4eb 100644 --- a/Source/PeleLMeX_Setup.cpp +++ b/Source/PeleLMeX_Setup.cpp @@ -387,14 +387,16 @@ PeleLM::readParameters() amrex::Print() << "Spark " << n << " name: " << m_spark[n] << "\n"; amrex::Print() << "Spark " << n << " time: " << m_spark_time[n] << "\n"; amrex::Print() << "Spark " << n << " duration: " << m_spark_duration[n] - << "\n"; + << "\n"; amrex::Print() << "Spark " << n << " location: "; for (int d = 0; d < AMREX_SPACEDIM; ++d) { amrex::Print() << m_spark_location[n][d] << " "; } amrex::Print() << "\n"; - amrex::Print() << "Spark " << n << " temperature: " << m_spark_temp[n] << "\n"; - amrex::Print() << "Spark " << n << " radius: " << m_spark_radius[n] << "\n"; + amrex::Print() << "Spark " << n << " temperature: " << m_spark_temp[n] + << "\n"; + amrex::Print() << "Spark " << n << " radius: " << m_spark_radius[n] + << "\n"; } } } @@ -998,8 +1000,8 @@ PeleLM::variablesSetup() } if (m_nAux > 0) { for (int n = 0; n < m_nAux; ++n) { - amrex::Print() << " Auxiliary " + std::to_string(n + 1) + ": " << m_aux_names[n] - << "\n"; + amrex::Print() << " Auxiliary " + std::to_string(n + 1) + ": " + << m_aux_names[n] << "\n"; amrex::Print() << " Advective: " << m_aux_advect[n] << "\n"; amrex::Print() << " Conservative: " << m_AdvTypeAux[n] << "\n"; amrex::Print() << " Diffusive: " << m_DiffTypeAux[n]; diff --git a/Source/PeleLMeX_Soot.cpp b/Source/PeleLMeX_Soot.cpp index ad71328ea..982faf4f2 100644 --- a/Source/PeleLMeX_Soot.cpp +++ b/Source/PeleLMeX_Soot.cpp @@ -65,7 +65,7 @@ PeleLM::clipSootMoments() SootData* sd = soot_model->getSootData_d(); amrex::ParallelFor( gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::GpuArray moments; + amrex::GpuArray moments; for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; ++mom) { moments[mom] = state_arr(i, j, k, mom); } diff --git a/Source/PeleLMeX_SprayParticles.cpp b/Source/PeleLMeX_SprayParticles.cpp index 62a858fb1..c9c08f9db 100644 --- a/Source/PeleLMeX_SprayParticles.cpp +++ b/Source/PeleLMeX_SprayParticles.cpp @@ -170,7 +170,7 @@ PeleLM::SprayInit() SprayInjectRedist(); if (spray_verbose >= 1) { amrex::Print() << "Total number of initial particles " - << SprayPC->TotalNumberOfParticles(false, false) << "\n"; + << SprayPC->TotalNumberOfParticles(false, false) << "\n"; } } @@ -390,8 +390,8 @@ PeleLM::SprayInjectRedist() if (spray_verbose >= 3 && injected) { amrex::Long new_count = SprayPC->TotalNumberOfParticles(true, false); amrex::Long num_inj = new_count - prev_count; - amrex::Print() << "Injected " << num_inj << " particles at time " << m_t_new[0] - << "\n"; + amrex::Print() << "Injected " << num_inj << " particles at time " + << m_t_new[0] << "\n"; } } diff --git a/Source/PeleLMeX_Temporals.cpp b/Source/PeleLMeX_Temporals.cpp index e272807b9..bd3b2f4ec 100644 --- a/Source/PeleLMeX_Temporals.cpp +++ b/Source/PeleLMeX_Temporals.cpp @@ -449,8 +449,8 @@ PeleLM::addRhoYFluxes( for (int n = 0; n < NUM_SPECIES; ++n) { // Inner loop over dimensions for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - auto faceDomain = - amrex::convert(a_geom.Domain(), amrex::IntVect::TheDimensionVector(idim)); + auto faceDomain = amrex::convert( + a_geom.Domain(), amrex::IntVect::TheDimensionVector(idim)); auto const& fma = a_fluxes[idim]->const_arrays(); @@ -540,7 +540,8 @@ PeleLM::initBPatches(amrex::Geometry& a_geom) pp.get("patchnames", bpatch_name[n], n); m_bPatches[n] = std::make_unique(bpatch_name[n], a_geom); if (m_verbose > 0) { - amrex::Print() << " Initializing boundary patch: " << bpatch_name[n] << "\n"; + amrex::Print() << " Initializing boundary patch: " << bpatch_name[n] + << "\n"; } } } diff --git a/Source/PeleLMeX_Timestep.cpp b/Source/PeleLMeX_Timestep.cpp index a903dd112..e0ae8d520 100644 --- a/Source/PeleLMeX_Timestep.cpp +++ b/Source/PeleLMeX_Timestep.cpp @@ -237,7 +237,8 @@ PeleLM::checkDt(const TimeStamp a_time, const amrex::Real a_dt) for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_time); - const amrex::GpuArray dxinv = geom[lev].InvCellSizeArray(); + const amrex::GpuArray dxinv = + geom[lev].InvCellSizeArray(); auto state_ma = ldata_p->state.const_arrays(); auto divu_ma = ldata_p->divu.const_arrays(); @@ -248,7 +249,7 @@ PeleLM::checkDt(const TimeStamp a_time, const amrex::Real a_dt) dtfac = m_divu_dtFactor, rhoMin = m_divu_rhoMin] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rho(state_ma[box_no], DENSITY); + amrex::Array4 rho(state_ma[box_no], DENSITY); amrex::Array4 vel(state_ma[box_no], VELX); amrex::Array4 divu = divu_ma[box_no]; check_divu_dt( diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index 24882d64b..d1221c100 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -423,7 +423,8 @@ PeleLM::getDiffusivity( #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif - for (amrex::MFIter mfi(beta_cc, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi) { + for (amrex::MFIter mfi(beta_cc, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const amrex::Box ebx = mfi.nodaltilebox(idim); const amrex::Box& edomain = amrex::surroundingNodes(domain, idim); diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index e6ef3c291..8c5780496 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -38,8 +38,8 @@ writeBuildInfo() std::cout << "\n"; for (int n = 1; n <= amrex::buildInfoGetNumModules(); ++n) { - std::cout << amrex::buildInfoGetModuleName(n) << ": " << amrex::buildInfoGetModuleVal(n) - << "\n"; + std::cout << amrex::buildInfoGetModuleName(n) << ": " + << amrex::buildInfoGetModuleVal(n) << "\n"; } std::cout << "\n"; @@ -782,9 +782,9 @@ PeleLM::floorSpecies(const TimeStamp a_time) amrex::Array4(sma[box_no], NE)); #endif // Update density and RhoH accordingly ... - amrex::Real massfrac[NUM_SPECIES] = {0.0}; - amrex::Real massdens[NUM_SPECIES] = {0.0}; - amrex::Real rhoinv, h_cgs = 0.0; + amrex::Real massfrac[NUM_SPECIES] = {0.0}; + amrex::Real massdens[NUM_SPECIES] = {0.0}; + amrex::Real rhoinv, h_cgs = 0.0; for (int n = 0; n < NUM_SPECIES; ++n) { massdens[n] = sma[box_no](i, j, k, FIRSTSPEC + n); } @@ -1566,19 +1566,22 @@ PeleLM::setTypicalValues(const TimeStamp a_time, const int is_init) spec_names, &(eos_parms.host_parm())); for (int n = 0; n < NUM_SPECIES; ++n) { amrex::Print() << "\tY_" << spec_names[n] - << std::setw( - amrex::max(0, static_cast(8 - spec_names[n].length()))) - << std::left << ":" << typical_values[FIRSTSPEC + n] << '\n'; + << std::setw( + amrex::max( + 0, static_cast(8 - spec_names[n].length()))) + << std::left << ":" << typical_values[FIRSTSPEC + n] + << '\n'; } #ifdef PELE_USE_PLASMA amrex::Print() << "\tnE: " << typical_values[NE] << '\n'; #endif #if NUM_ODE > 0 for (int n = 0; n < NUM_ODE; ++n) { - amrex::Print() << "\t" << m_ode_names[n] - << std::setw(amrex::max( - 0, static_cast(10 - m_ode_names[n].length()))) - << std::left << ":" << typical_values[FIRSTODE + n] << '\n'; + amrex::Print() + << "\t" << m_ode_names[n] + << std::setw( + amrex::max(0, static_cast(10 - m_ode_names[n].length()))) + << std::left << ":" << typical_values[FIRSTODE + n] << '\n'; } #endif } diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index 319c40817..43ba32b8c 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -218,7 +218,10 @@ PeleLM::implicitNonLinearSolve( } int -PeleLM::testExitNewton(const int newtonIter, const amrex::Real max_res, const amrex::Real norm_NewtonDir) +PeleLM::testExitNewton( + const int newtonIter, + const amrex::Real max_res, + const amrex::Real norm_NewtonDir) { int exit = 0; if (max_res <= m_ef_newtonTol || norm_NewtonDir <= 1e-11) { @@ -347,9 +350,10 @@ PeleLM::incrementElectronForcing( } void -PeleLM::computeBGcharge(const amrex::Real a_time, - std::unique_ptr& diffData, - std::unique_ptr& advData) +PeleLM::computeBGcharge( + const amrex::Real a_time, + std::unique_ptr& diffData, + std::unique_ptr& advData) { // Get integration dt amrex::Real dt_int = a_time - getTime(0, AmrOldTime); @@ -379,7 +383,7 @@ PeleLM::computeBGcharge(const amrex::Real a_time, bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { charge(i, j, k) = 0.0; for (int n = 0; n < NUM_SPECIES; ++n) { - amrex::Real rhoYprov = + amrex::Real rhoYprov = rhoYold(i, j, k, n) + dt_int * (adv_arr(i, j, k, n) + 0.5 * (dn_arr(i, j, k, n) - dnp1_arr(i, j, k, n)) + @@ -395,11 +399,11 @@ PeleLM::computeBGcharge(const amrex::Real a_time, void PeleLM::nonLinearResidual( - const amrex::Real a_dt, - const amrex::Vector& a_nlstate, - const amrex::Vector& a_nlresid, - const int updateScaling, - const int updatePrecond) + const amrex::Real a_dt, + const amrex::Vector& a_nlstate, + const amrex::Vector& a_nlresid, + const int updateScaling, + const int updatePrecond) { // Get unscaled copy of the NL state amrex::Vector nE(finest_level + 1); @@ -423,7 +427,8 @@ PeleLM::nonLinearResidual( amrex::Vector> gradPhiVCur( finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - laplacian[lev].define(grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), Factory(lev)); + laplacian[lev].define( + grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), Factory(lev)); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const auto& fba = amrex::convert(grids[lev], amrex::IntVect::TheDimensionVector(idim)); @@ -877,7 +882,8 @@ PeleLM::getAdvectionFluxes( } void -PeleLM::setUpPrecond(const amrex::Real a_dt, const amrex::Vector& a_nE) +PeleLM::setUpPrecond( + const amrex::Real a_dt, const amrex::Vector& a_nE) { BL_PROFILE("PeleLMeX::setUpPrecond()"); @@ -998,8 +1004,10 @@ PeleLM::setUpPrecond(const amrex::Real a_dt, const amrex::VectorsetStildaOpBCoeff(lev, GetArrOfConstPtrs(neKe_ec)); } else if (m_ef_PC_approx == 2) { // Assuming inverse of the diag of DiffOp // Upwinded Schur edge neKe values - amrex::Array Schur_neKe_ec = getUpwindedEdge( - lev, 0, 1, bcRecnE, Schur_nEKe, GetArrOfConstPtrs(ldataNLs_p->uEffnE)); + amrex::Array Schur_neKe_ec = + getUpwindedEdge( + lev, 0, 1, bcRecnE, Schur_nEKe, + GetArrOfConstPtrs(ldataNLs_p->uEffnE)); amrex::Real scalLap = eps0 * epsr / elemCharge; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { Schur_neKe_ec[idim].plus(scalLap, 0, 1); diff --git a/Source/Plasma/PeleLMeX_EFReactions.cpp b/Source/Plasma/PeleLMeX_EFReactions.cpp index 3295cad80..033e9954b 100644 --- a/Source/Plasma/PeleLMeX_EFReactions.cpp +++ b/Source/Plasma/PeleLMeX_EFReactions.cpp @@ -2,7 +2,8 @@ #include void -PeleLM::computeInstantaneousReactionRateEF(const int lev, const TimeStamp a_time, amrex::MultiFab* a_I_R) +PeleLM::computeInstantaneousReactionRateEF( + const int lev, const TimeStamp a_time, amrex::MultiFab* a_I_R) { auto ldata_p = getLevelDataPtr(lev, a_time); diff --git a/Source/Plasma/PeleLMeX_EFTimeStep.cpp b/Source/Plasma/PeleLMeX_EFTimeStep.cpp index dfcfe40e1..608cd3675 100644 --- a/Source/Plasma/PeleLMeX_EFTimeStep.cpp +++ b/Source/Plasma/PeleLMeX_EFTimeStep.cpp @@ -108,10 +108,10 @@ PeleLM::estEFIonsDt(const TimeStamp a_time) auto const& uDrMax = driftVelMax_cc.array(mfi); amrex::ParallelFor( bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::Real maxVel = 0.0; + amrex::Real maxVel = 0.0; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { for (int n = 0; n < NUM_IONS; ++n) { - amrex::Real ueff = + amrex::Real ueff = vel(i, j, k, idim) + mob_cc(i, j, k, n) * efield(i, j, k, idim); maxVel = amrex::max(maxVel, std::abs(ueff)); } diff --git a/Source/Plasma/PeleLMeX_EFUtils.cpp b/Source/Plasma/PeleLMeX_EFUtils.cpp index c80e381c0..4957de674 100644 --- a/Source/Plasma/PeleLMeX_EFUtils.cpp +++ b/Source/Plasma/PeleLMeX_EFUtils.cpp @@ -111,7 +111,10 @@ PeleLM::scaleNLState(const amrex::Real nEScale, const amrex::Real phiVScale) } void -PeleLM::scaleNLResid(const amrex::Vector& a_resid, const amrex::Real nEScale, const amrex::Real phiVScale) +PeleLM::scaleNLResid( + const amrex::Vector& a_resid, + const amrex::Real nEScale, + const amrex::Real phiVScale) { for (int lev = 0; lev <= finest_level; ++lev) { a_resid[lev]->mult(1.0 / FnE_scale, 0, 1, 1); @@ -120,7 +123,8 @@ PeleLM::scaleNLResid(const amrex::Vector& a_resid, const amrex } amrex::BCRec -PeleLM::hackBCChargedParticle(const amrex::Real charge, const amrex::BCRec& bc_in) +PeleLM::hackBCChargedParticle( + const amrex::Real charge, const amrex::BCRec& bc_in) { amrex::BCRec bc_hacked; From dc5abbfd4b5dffa0ff838343680d97c1a15ce109 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Tue, 19 Aug 2025 10:51:40 +0200 Subject: [PATCH 40/87] efield --- Source/PeleLMeX_Forces.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 7c6ea3ed7..ae0edc870 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -1,6 +1,8 @@ #include #include - +#if PELE_USE_PLASMA +#include +#endif // Return velocity forces scaled by rhoInv // including grapP term if add_gradP = 1 // including divTau if input amrex::Vector not empty From 2a668dccfaa779634f4dc0e6fa6832d1aed2f78b Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Tue, 19 Aug 2025 11:09:03 +0200 Subject: [PATCH 41/87] efield and extras --- Source/PeleLMeX.H | 13 ++++++------ Source/PeleLMeX_Diffusion.cpp | 3 ++- Source/PeleLMeX_Setup.cpp | 6 ++++-- Source/PeleLMeX_TransportProp.cpp | 12 +++++------ Source/PeleLMeX_Utils.cpp | 4 ++-- Source/Plasma/PeleLMeX_EFPoisson.cpp | 30 ++++------------------------ Source/Plasma/PeleLMeX_EFUtils.cpp | 2 +- 7 files changed, 26 insertions(+), 44 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 4244a2e61..fff9c7b88 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -125,8 +125,8 @@ public: void freeProbParm(); // ReadGridFile - void - readGridFile(std::string grid_file, amrex::Vector& input_ba); + void readGridFile( + const std::string& grid_file, amrex::Vector& input_ba); #ifdef PELE_USE_SPRAY // ReadSprayParameters @@ -561,7 +561,7 @@ public: const int beta_comp, const int ncomp, const int doZeroVisc, - amrex::Vector bcrec, + const amrex::Vector& bcrec, const amrex::MultiFab& beta_cc, const int addTurbContrib = 0); @@ -744,7 +744,8 @@ public: */ amrex::Vector> getDiffusionTensorOpBC( - amrex::Orientation::Side a_side, const amrex::Vector a_bc); + const amrex::Orientation::Side a_side, + const amrex::Vector& a_bc); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -1431,8 +1432,8 @@ public: // Mixture fraction & Progress variable void initMixtureFraction(); static void parseComposition( - amrex::Vector compositionIn, - std::string compositionType, + const amrex::Vector& compositionIn, + const std::string& compositionType, amrex::Real* massFrac); static void parseVars( const amrex::Vector& a_varsNames, diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 4deb24187..1bf068d9f 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -1878,7 +1878,8 @@ PeleLM::getDiffusionLinOpBC( amrex::Vector> PeleLM::getDiffusionTensorOpBC( - amrex::Orientation::Side a_side, const amrex::Vector a_bc) + const amrex::Orientation::Side a_side, + const amrex::Vector& a_bc) { AMREX_ASSERT(a_bc.size() == AMREX_SPACEDIM); amrex::Vector> r( diff --git a/Source/PeleLMeX_Setup.cpp b/Source/PeleLMeX_Setup.cpp index 099bce4eb..4b4c06912 100644 --- a/Source/PeleLMeX_Setup.cpp +++ b/Source/PeleLMeX_Setup.cpp @@ -1099,7 +1099,7 @@ PeleLM::variablesSetup() void PeleLM::readGridFile( - std::string grid_file, amrex::Vector& input_ba) + const std::string& grid_file, amrex::Vector& input_ba) { #define STRIP \ while (is.get() != '\n') { \ @@ -1473,7 +1473,9 @@ PeleLM::taggingSetup() "refinement_indicators", refinement_indicators, 0, ppamr.countval("refinement_indicators")); for (const auto& refinement_indicator : refinement_indicators) { - std::string ref_prefix = amr_prefix + "." + refinement_indicator; + std::string ref_prefix = amr_prefix; + ref_prefix += "."; + ref_prefix += refinement_indicator; amrex::ParmParse ppr(ref_prefix); // Tag a given box diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index d1221c100..4b1f6b6ef 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -382,13 +382,13 @@ PeleLM::calcDiffusivity(const TimeStamp a_time) amrex::Array PeleLM::getDiffusivity( - int lev, - int beta_comp, - int ncomp, - int doZeroVisc, - amrex::Vector bcrec, + const int lev, + const int beta_comp, + const int ncomp, + const int doZeroVisc, + amrex::Vector const& bcrec, amrex::MultiFab const& beta_cc, - int addTurbContrib) + const int addTurbContrib) { BL_PROFILE("PeleLMeX::getDiffusivity()"); diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 8c5780496..8987743ad 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -2048,8 +2048,8 @@ PeleLM::initMixtureFraction() void PeleLM::parseComposition( - amrex::Vector compositionIn, - std::string compositionType, + const amrex::Vector& compositionIn, + const std::string& compositionType, amrex::Real* massFrac) { amrex::Real compoIn[NUM_SPECIES] = {0.0}; diff --git a/Source/Plasma/PeleLMeX_EFPoisson.cpp b/Source/Plasma/PeleLMeX_EFPoisson.cpp index a794dceca..bc6161fdb 100644 --- a/Source/Plasma/PeleLMeX_EFPoisson.cpp +++ b/Source/Plasma/PeleLMeX_EFPoisson.cpp @@ -1,5 +1,4 @@ #include -#include #include #include @@ -16,7 +15,7 @@ PeleLM::poissonSolveEF(const TimeStamp a_time) // Build Poisson RHS: charge distribution constexpr int nGhost = 0; - constexpr Real factor = -1.0; + constexpr amrex::Real factor = -1.0; amrex::Vector> rhsPoisson(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { rhsPoisson[lev].reset(new amrex::MultiFab( @@ -30,36 +29,15 @@ PeleLM::poissonSolveEF(const TimeStamp a_time) amrex::ParallelFor( ldata_p->state, [state_ma, rhs_ma, zk = zk] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { - Array4 rhoY(state_ma[box_no], FIRSTSPEC); - Array4 nE(state_ma[box_no], NE); + amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); + amrex::Array4 nE(state_ma[box_no], NE); rhs_ma[box_no](i, j, k) = -nE(i, j, k) * elemCharge * factor; for (int n = 0; n < NUM_SPECIES; ++n) { rhs_ma[box_no](i, j, k) += zk[n] * rhoY(i, j, k, n) * factor; } }); } - Gpu::streamSynchronize(); - /* -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(*rhsPoisson[lev], amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& rhoY = ldata_p->state.const_array(mfi, FIRSTSPEC); - auto const& nE = ldata_p->state.const_array(mfi, NE); - auto const& rhs = rhsPoisson[lev]->array(mfi); - amrex::Real factor = -1.0; // / ( eps0 * epsr); - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - rhs(i, j, k) = -nE(i, j, k) * elemCharge * factor; - for (int n = 0; n < NUM_SPECIES; ++n) { - rhs(i, j, k) += zk[n] * rhoY(i, j, k, n) * factor; - } - }); - } - } - */ + amrex::Gpu::streamSynchronize(); // Solve for PhiV getDiffusionOp()->diffuse_scalar( GetVecOfPtrs(getPhiVVect(a_time)), 0, GetVecOfConstPtrs(rhsPoisson), 0, {}, diff --git a/Source/Plasma/PeleLMeX_EFUtils.cpp b/Source/Plasma/PeleLMeX_EFUtils.cpp index 4957de674..5b582a153 100644 --- a/Source/Plasma/PeleLMeX_EFUtils.cpp +++ b/Source/Plasma/PeleLMeX_EFUtils.cpp @@ -62,7 +62,7 @@ PeleLM::getNLBGChargeVect() void PeleLM::getNLStateScaling(amrex::Real& nEScale, amrex::Real& phiVScale) { - amrex::Array r = {0.0, 0.0}; + amrex::Array r = {0.0, 0.0}; for (int comp = 0; comp < 2; ++comp) { for (int lev = 0; lev <= finest_level; ++lev) { if (lev != finest_level) { From 56c04edb83e8ecfaaa5759cf0924893318c8eec5 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Tue, 19 Aug 2025 11:55:46 +0200 Subject: [PATCH 42/87] more fusing --- .clang-tidy | 2 +- Source/PeleLMeX_Diffusion.cpp | 94 +++++++-------- Source/PeleLMeX_DiffusionOp.cpp | 158 +++++++++++++------------- Source/PeleLMeX_ODEQty.cpp | 2 +- Source/PeleLMeX_TransportProp.cpp | 7 +- Source/Plasma/PeleLMeX_EFIonDrift.cpp | 2 +- 6 files changed, 131 insertions(+), 134 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index bedbba1fd..69b827996 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,7 +7,7 @@ Checks: 'bugprone-*, clang-diagnostic-*, clang-analyzer-*, corecppguidelines-*, - modernize-*, + modernize-*, -modernize-avoid-c-arrays, -modernize-use-trailing-return-type, -modernize-use-nodiscard, diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 1bf068d9f..a14dc6118 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -675,67 +675,67 @@ PeleLM::addWbarTerm( //------------------------------------------------------------------------ // Compute Wbar on all the levels int nGrow = 1; // Need one ghost cell to compute gradWbar - amrex::Vector Wbar(finest_level + 1); + amrex::Vector Wbar; + Wbar.reserve(finest_level + 1); amrex::Vector Wbar_boundary; if (have_boundary != 0) { - Wbar_boundary.resize(finest_level + 1); + Wbar_boundary.reserve(finest_level + 1); } auto const* leosparm = eos_parms.device_parm(); for (int lev = 0; lev <= finest_level; ++lev) { - Wbar[lev].define( + Wbar.emplace_back( grids[lev], dmap[lev], 1, nGrow, amrex::MFInfo(), Factory(lev)); if (have_boundary != 0) { - Wbar_boundary[lev].define( + Wbar_boundary.emplace_back( grids[lev], dmap[lev], 1, nGrow, amrex::MFInfo(), Factory(lev)); } const amrex::Box& domain = geom[lev].Domain(); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(Wbar[lev], amrex::TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const amrex::Box& gbx = mfi.growntilebox(); - auto const& rho_arr = a_rho[lev]->const_array(mfi); - auto const& rhoY_arr = a_spec[lev]->const_array(mfi); - auto const& Wbar_arr = Wbar[lev].array(mfi); - auto const& gradY_arr = - (have_boundary != 0) ? a_boundary[lev]->const_array(mfi) : Wbar_arr; - auto const& Wbar_boundary_arr = - (have_boundary != 0) ? Wbar_boundary[lev].array(mfi) : Wbar_arr; - - const auto phys_bc = m_phys_bc; - amrex::ParallelFor( - gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - getMwmixGivenRY(i, j, k, rho_arr, rhoY_arr, Wbar_arr, leosparm); - if (have_boundary != 0) { // need to impose gradWbar on boundary for - // computeGradient - // for dirichlet boundaries, we'll overwrite inhomog neumann ones - // NOTE: for now, this is skipped since wbar disabled for - // isothermal/soret - Wbar_boundary_arr(i, j, k) = Wbar_arr(i, j, k); - const int idx[3] = {i, j, k}; - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - const auto bc_lo = phys_bc.lo(idim); - const auto bc_hi = phys_bc.hi(idim); - const bool on_lo = - (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || - bc_lo == BoundaryCondition::BCSlipWallIsotherm) && - (idx[idim] < domain.smallEnd(idim)); - const bool on_hi = - (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || - bc_hi == BoundaryCondition::BCSlipWallIsotherm) && - (idx[idim] > domain.bigEnd(idim)); - if (on_lo || on_hi) { - getGradMwmixGivengradYMwmix( - i, j, k, gradY_arr, Wbar_arr, Wbar_boundary_arr, leosparm); - } + auto const& rho_ma = a_rho[lev]->const_arrays(); + auto const& rhoY_ma = a_spec[lev]->const_arrays(); + auto const& Wbar_ma = Wbar[lev].arrays(); + auto const& gradY_ma = + (have_boundary != 0) ? a_boundary[lev]->const_arrays() : rhoY_ma; + auto const& Wbar_boundary_ma = + (have_boundary != 0) ? Wbar_boundary[lev].arrays() : Wbar_ma; + + amrex::ParallelFor( + Wbar[lev], Wbar[lev].nGrowVect(), + [rho_ma, rhoY_ma, Wbar_ma, gradY_ma, Wbar_boundary_ma, have_boundary, + leosparm, domain, + phys_bc = + m_phys_bc] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + getMwmixGivenRY( + i, j, k, rho_ma[box_no], rhoY_ma[box_no], Wbar_ma[box_no], leosparm); + if (have_boundary != 0) { // need to impose gradWbar on boundary for + // computeGradient + // for dirichlet boundaries, we'll overwrite inhomog neumann ones + // NOTE: for now, this is skipped since wbar disabled for + // isothermal/soret + Wbar_boundary_ma[box_no](i, j, k) = Wbar_ma[box_no](i, j, k); + const int idx[3] = {i, j, k}; + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + const auto bc_lo = phys_bc.lo(idim); + const auto bc_hi = phys_bc.hi(idim); + const bool on_lo = + (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || + bc_lo == BoundaryCondition::BCSlipWallIsotherm) && + (idx[idim] < domain.smallEnd(idim)); + const bool on_hi = + (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || + bc_hi == BoundaryCondition::BCSlipWallIsotherm) && + (idx[idim] > domain.bigEnd(idim)); + + if (on_lo || on_hi) { + getGradMwmixGivengradYMwmix( + i, j, k, gradY_ma[box_no], Wbar_ma[box_no], + Wbar_boundary_ma[box_no], leosparm); } } - }); - } + } + }); } - + amrex::Gpu::streamSynchronize(); //------------------------------------------------------------------------ // Compute Wbar gradients and do average down to get gradients consistent // across levels Get the species BCRec diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index d14be7d64..c92bd01dc 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -140,34 +140,32 @@ DiffusionOp::diffuse_scalar( // after adv., when we divide by \rho, it is inconsistent. But it only matters // if it screws up the ghost cell values 'cause interiors are just an initial // solution for the solve. - amrex::Vector phi(finest_level + 1); + amrex::Vector phi; + phi.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - phi[lev].define( + phi.emplace_back( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), ncomp, 1, amrex::MFInfo(), a_phi[lev]->Factory()); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const amrex::Box& gbx = mfi.growntilebox(); - auto const& a_phi_arr = a_phi[lev]->const_array(mfi, phi_comp); - auto const& a_rho_arr = - (have_density) != 0 ? a_density[lev]->const_array(mfi) - : a_phi[lev]->const_array( - mfi); // Get dummy amrex::Array4 if no density - auto const& phi_arr = phi[lev].array(mfi); + if (have_density == 0) { + amrex::MultiFab::Copy( + phi[lev], *a_phi[lev], phi_comp, 0, ncomp, phi[lev].nGrowVect()); + } else { + auto const& a_phi_ma = a_phi[lev]->const_arrays(); + auto const& a_rho_ma = a_density[lev]->const_arrays(); + auto const& phi_ma = phi[lev].arrays(); amrex::ParallelFor( - gbx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - if (have_density != 0) { - phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n) / a_rho_arr(i, j, k); - } else { - phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n); + phi[lev], phi[lev].nGrowVect(), + [a_phi_ma, a_rho_ma, phi_ma, phi_comp, + ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 a_phi(a_phi_ma[box_no], phi_comp); + for (int n = 0; n < ncomp; ++n) { + phi_ma[box_no](i, j, k, n) = + a_phi(i, j, k, n) / a_rho_ma[box_no](i, j, k); } }); + amrex::Gpu::streamSynchronize(); } } - //---------------------------------------------------------------- // Setup solve LinearOp coefficients // LinOp is \alpha A \phi - \beta \nabla \cdot B \nabla \phi = rhs @@ -358,34 +356,32 @@ DiffusionOp::diffuse_scalar( // after adv., when we divide by \rho, it is inconsistent. But it only matters // if it screws up the ghost cell values 'cause interiors are just an initial // solution for the solve. - amrex::Vector phi(finest_level + 1); + amrex::Vector phi; + phi.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - phi[lev].define( + phi.emplace_back( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), ncomp, 1, amrex::MFInfo(), a_phi[lev]->Factory()); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const amrex::Box& gbx = mfi.growntilebox(); - auto const& a_phi_arr = a_phi[lev]->const_array(mfi, phi_comp); - auto const& a_rho_arr = - (have_density) != 0 ? a_density[lev]->const_array(mfi) - : a_phi[lev]->const_array( - mfi); // Get dummy amrex::Array4 if no density - auto const& phi_arr = phi[lev].array(mfi); + if (have_density == 0) { + amrex::MultiFab::Copy( + phi[lev], *a_phi[lev], phi_comp, 0, ncomp, phi[lev].nGrowVect()); + } else { + auto const& a_phi_ma = a_phi[lev]->const_arrays(); + auto const& a_rho_ma = a_rho[lev]->const_arrays(); + auto const& phi_ma = phi[lev].arrays(); amrex::ParallelFor( - gbx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - if (have_density != 0) { - phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n) / a_rho_arr(i, j, k); - } else { - phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n); + phi[lev], phi[lev].nGrowVect(), + [a_phi_ma, a_rho_ma, phi_ma, phi_comp, + ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 a_phi(a_phi_ma[box_no], phi_comp); + for (int n = 0; n < ncomp; ++n) { + phi_ma[box_no](i, j, k, n) = + a_phi(i, j, k, n) / a_rho_ma[box_no](i, j, k); } }); + amrex::Gpu::streamSynchronize(); } } - //---------------------------------------------------------------- // Setup solve LinearOp coefficients // LinOp is \alpha A \phi - \beta \nabla \cdot B \nabla \phi = rhs @@ -395,10 +391,12 @@ DiffusionOp::diffuse_scalar( const amrex::Real alpha = (isPoissonSolve != 0) ? 0.0 : 1.0; const amrex::Real beta = a_dt; m_scal_solve_op->setScalars(alpha, beta); - for (int lev = 0; lev <= finest_level; ++lev) { - if (have_acoeff != 0) { + if (have_acoeff != 0) { + for (int lev = 0; lev <= finest_level; ++lev) { m_scal_solve_op->setACoeffs(lev, *a_acoeff[lev]); - } else { + } + } else { + for (int lev = 0; lev <= finest_level; ++lev) { m_scal_solve_op->setACoeffs(lev, 1.0); } } @@ -619,31 +617,30 @@ DiffusionOp::computeDiffFluxes( // Duplicate phi since it is modified by the LinOp // and if have_density -> divide by density - amrex::Vector phi(finest_level + 1); + amrex::Vector phi; + phi.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - phi[lev].define( + phi.emplace_back( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), ncomp, 1, amrex::MFInfo(), a_phi[lev]->Factory()); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const amrex::Box& gbx = mfi.growntilebox(); - auto const& a_phi_arr = a_phi[lev]->const_array(mfi, phi_comp); - auto const& a_rho_arr = - (have_density) != 0 ? a_density[lev]->const_array(mfi) - : a_phi[lev]->const_array( - mfi); // Get dummy amrex::Array4 if no density - auto const& phi_arr = phi[lev].array(mfi); + if (have_density == 0) { + amrex::MultiFab::Copy( + phi[lev], *a_phi[lev], phi_comp, 0, ncomp, phi[lev].nGrowVect()); + } else { + auto const& a_phi_ma = a_phi[lev]->const_arrays(); + auto const& a_rho_ma = a_density[lev]->const_arrays(); + auto const& phi_ma = phi[lev].arrays(); amrex::ParallelFor( - gbx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - if (have_density != 0) { - phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n) / a_rho_arr(i, j, k); - } else { - phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n); + phi[lev], phi[lev].nGrowVect(), + [a_phi_ma, a_rho_ma, phi_ma, phi_comp, + ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 a_phi(a_phi_ma[box_no], phi_comp); + for (int n = 0; n < ncomp; ++n) { + phi_ma[box_no](i, j, k, n) = + a_phi(i, j, k, n) / a_rho_ma[box_no](i, j, k); } }); + amrex::Gpu::streamSynchronize(); } } @@ -762,31 +759,30 @@ DiffusionOp::computeDiffFluxes( // Duplicate phi since it is modified by the LinOp // and if have_density -> divide by density - amrex::Vector phi(finest_level + 1); + amrex::Vector phi; + phi.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - phi[lev].define( + phi.emplace_back( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), ncomp, 1, amrex::MFInfo(), a_phi[lev]->Factory()); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const amrex::Box& gbx = mfi.growntilebox(); - auto const& a_phi_arr = a_phi[lev]->const_array(mfi, phi_comp); - auto const& a_rho_arr = - (have_density) != 0 ? a_density[lev]->const_array(mfi) - : a_phi[lev]->const_array( - mfi); // Get dummy amrex::Array4 if no density - auto const& phi_arr = phi[lev].array(mfi); + if (have_density == 0) { + amrex::MultiFab::Copy( + phi[lev], *a_phi[lev], phi_comp, 0, ncomp, phi[lev].nGrowVect()); + } else { + auto const& a_phi_ma = a_phi[lev]->const_arrays(); + auto const& a_rho_ma = a_density[lev]->const_arrays(); + auto const& phi_ma = phi[lev].arrays(); amrex::ParallelFor( - gbx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - if (have_density != 0) { - phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n) / a_rho_arr(i, j, k); - } else { - phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n); + phi[lev], phi[lev].nGrowVect(), + [a_phi_ma, a_rho_ma, phi_ma, phi_comp, + ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 a_phi(a_phi_ma[box_no], phi_comp); + for (int n = 0; n < ncomp; ++n) { + phi_ma[box_no](i, j, k, n) = + a_phi(i, j, k, n) / a_rho_ma[box_no](i, j, k); } }); + amrex::Gpu::streamSynchronize(); } } diff --git a/Source/PeleLMeX_ODEQty.cpp b/Source/PeleLMeX_ODEQty.cpp index e43344351..957221727 100644 --- a/Source/PeleLMeX_ODEQty.cpp +++ b/Source/PeleLMeX_ODEQty.cpp @@ -12,7 +12,7 @@ PeleLM::predictODEQty() auto const& ext_src_arrs = m_extSource[lev]->arrays(); const auto dt = m_dt; amrex::ParallelFor( - *m_extSource[lev], [state_arrs, ext_src_arrs, dt = m_dt] AMREX_GPU_DEVICE( + *m_extSource[lev], [state_arrs, ext_src_arrs, dt] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { for (int n = 0; n < NUM_ODE; ++n) { amrex::Real const& B_n = state_arrs[box_no](i, j, k, FIRSTODE + n); diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index 4b1f6b6ef..8f2e58967 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -60,14 +60,15 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) } } else { // get cp_cc (valid in 1 grow cell for interpolation to FCs) - int ngrow = 1; + constexpr int ngrow = 1; auto const* leosparm = eos_parms.device_parm(); cp_cc.define(ba, dm, 1, ngrow, amrex::MFInfo(), factory); auto const& state_arr = ldata_p->state.const_arrays(); auto const& cp_arr = cp_cc.arrays(); amrex::ParallelFor( cp_cc, cp_cc.nGrowVect(), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [state_arr, cp_arr, + leosparm] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { getCpmixGivenRYT( i, j, k, amrex::Array4(state_arr[box_no], DENSITY), @@ -78,7 +79,7 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) amrex::Gpu::streamSynchronize(); // this function really just interpolates CCs to FCs in this case - int doZeroVisc = 0; + constexpr int doZeroVisc = 0; auto bcRec = fetchBCRecArray(DENSITY, 1); dens_fc = getDiffusivity(lev, DENSITY, 1, doZeroVisc, {bcRec}, ldata_p->state); diff --git a/Source/Plasma/PeleLMeX_EFIonDrift.cpp b/Source/Plasma/PeleLMeX_EFIonDrift.cpp index 9ee14d754..04add160e 100644 --- a/Source/Plasma/PeleLMeX_EFIonDrift.cpp +++ b/Source/Plasma/PeleLMeX_EFIonDrift.cpp @@ -37,7 +37,7 @@ PeleLM::ionDriftVelocity(std::unique_ptr& advData) } } - int do_avgDown = 0; // TODO or should I ? + constexpr int do_avgDown = 0; // TODO or should I ? auto bcRecPhiV = fetchBCRecArray(PHIV, 1); getDiffusionOp()->computeGradient( GetVecOfArrOfPtrs(gphiVOld), {}, // don't need the laplacian out From 8e8b2c144cced9dfbc6ff2f8e880d491f6017d3f Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Tue, 19 Aug 2025 12:06:04 +0200 Subject: [PATCH 43/87] typo --- Source/PeleLMeX_DiffusionOp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index c92bd01dc..43f57bf46 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -367,7 +367,7 @@ DiffusionOp::diffuse_scalar( phi[lev], *a_phi[lev], phi_comp, 0, ncomp, phi[lev].nGrowVect()); } else { auto const& a_phi_ma = a_phi[lev]->const_arrays(); - auto const& a_rho_ma = a_rho[lev]->const_arrays(); + auto const& a_rho_ma = a_density[lev]->const_arrays(); auto const& phi_ma = phi[lev].arrays(); amrex::ParallelFor( phi[lev], phi[lev].nGrowVect(), From 37c5b9b937ea9ba15737aba64fd7a396175bae25 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Tue, 19 Aug 2025 13:03:00 +0200 Subject: [PATCH 44/87] duplicate + emplace --- Source/PeleLMeX_DiffusionOp.cpp | 55 ++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index 43f57bf46..620ac15c8 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -157,10 +157,11 @@ DiffusionOp::diffuse_scalar( phi[lev], phi[lev].nGrowVect(), [a_phi_ma, a_rho_ma, phi_ma, phi_comp, ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 a_phi(a_phi_ma[box_no], phi_comp); + amrex::Array4 a_phi_arr( + a_phi_ma[box_no], phi_comp); for (int n = 0; n < ncomp; ++n) { phi_ma[box_no](i, j, k, n) = - a_phi(i, j, k, n) / a_rho_ma[box_no](i, j, k); + a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); } }); amrex::Gpu::streamSynchronize(); @@ -373,10 +374,11 @@ DiffusionOp::diffuse_scalar( phi[lev], phi[lev].nGrowVect(), [a_phi_ma, a_rho_ma, phi_ma, phi_comp, ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 a_phi(a_phi_ma[box_no], phi_comp); + amrex::Array4 a_phi_arr( + a_phi_ma[box_no], phi_comp); for (int n = 0; n < ncomp; ++n) { phi_ma[box_no](i, j, k, n) = - a_phi(i, j, k, n) / a_rho_ma[box_no](i, j, k); + a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); } }); amrex::Gpu::streamSynchronize(); @@ -536,9 +538,10 @@ DiffusionOp::computeDiffLap( const int finest_level = m_pelelm->finestLevel(); // Copy phi with 1 ghost cell - amrex::Vector phi(finest_level + 1); + amrex::Vector phi; + phi.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - phi[lev].define( + phi.emplace_back( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), ncomp, 1, amrex::MFInfo(), a_phi[lev]->Factory()); amrex::MultiFab::Copy(phi[lev], *a_phi[lev], phi_comp, 0, ncomp, 1); @@ -634,10 +637,11 @@ DiffusionOp::computeDiffFluxes( phi[lev], phi[lev].nGrowVect(), [a_phi_ma, a_rho_ma, phi_ma, phi_comp, ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 a_phi(a_phi_ma[box_no], phi_comp); + amrex::Array4 a_phi_arr( + a_phi_ma[box_no], phi_comp); for (int n = 0; n < ncomp; ++n) { phi_ma[box_no](i, j, k, n) = - a_phi(i, j, k, n) / a_rho_ma[box_no](i, j, k); + a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); } }); amrex::Gpu::streamSynchronize(); @@ -776,10 +780,11 @@ DiffusionOp::computeDiffFluxes( phi[lev], phi[lev].nGrowVect(), [a_phi_ma, a_rho_ma, phi_ma, phi_comp, ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 a_phi(a_phi_ma[box_no], phi_comp); + amrex::Array4 a_phi_arr( + a_phi_ma[box_no], phi_comp); for (int n = 0; n < ncomp; ++n) { phi_ma[box_no](i, j, k, n) = - a_phi(i, j, k, n) / a_rho_ma[box_no](i, j, k); + a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); } }); amrex::Gpu::streamSynchronize(); @@ -891,14 +896,16 @@ DiffusionOp::computeGradient( // Duplicate phi since it is modified by the LinOp // and setup level BCs - amrex::Vector phi(finest_level + 1); - amrex::Vector boundary(finest_level + 1); + amrex::Vector phi; + phi.reserve(finest_level + 1); + amrex::Vector boundary; + boundary.reserve(finest_level + 1); amrex::Vector laps; for (int lev = 0; lev <= finest_level; ++lev) { - phi[lev].define( + phi.emplace_back( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), 1, 1, amrex::MFInfo(), a_phi[lev]->Factory()); - boundary[lev].define( + boundary.emplace_back( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), 1, 1, amrex::MFInfo(), a_phi[lev]->Factory()); @@ -1055,9 +1062,10 @@ DiffusionTensorOp::computeGradientTensor( const int finest_level = m_pelelm->finestLevel(); // Duplicate vel since it may be modified by the TensorOp - amrex::Vector vel(finest_level + 1); + amrex::Vector vel; + vel.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - vel[lev].define( + vel.emplace_back( a_vel[lev]->boxArray(), a_vel[lev]->DistributionMap(), AMREX_SPACEDIM, 1, amrex::MFInfo(), a_vel[lev]->Factory()); amrex::MultiFab::Copy(vel[lev], *a_vel[lev], 0, 0, AMREX_SPACEDIM, 1); @@ -1107,9 +1115,10 @@ DiffusionTensorOp::compute_divtau( const int have_density = (a_density.empty()) ? 0 : 1; // Duplicate vel since it is modified by the TensorOp - amrex::Vector vel(finest_level + 1); + amrex::Vector vel; + vel.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - vel[lev].define( + vel.emplace_back( a_vel[lev]->boxArray(), a_vel[lev]->DistributionMap(), AMREX_SPACEDIM, 2, amrex::MFInfo(), a_vel[lev]->Factory()); amrex::MultiFab::Copy(vel[lev], *a_vel[lev], 0, 0, AMREX_SPACEDIM, 2); @@ -1117,9 +1126,10 @@ DiffusionTensorOp::compute_divtau( #ifdef AMREX_USE_EB // Need a temporary divTau to apply redistribution - amrex::Vector divtau_tmp(finest_level + 1); + amrex::Vector divtau_tmp; + divtau_tmp.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - divtau_tmp[lev].define( + divtau_tmp.emplace_back( a_divtau[lev]->boxArray(), a_divtau[lev]->DistributionMap(), AMREX_SPACEDIM, 2, amrex::MFInfo(), a_divtau[lev]->Factory()); divtau_tmp[lev].setVal(0.0); @@ -1240,9 +1250,10 @@ DiffusionTensorOp::diffuse_velocity( m_solve_op->setLevelBC(lev, a_vel[lev]); } - amrex::Vector rhs(finest_level + 1); + amrex::Vector rhs; + rhs.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - rhs[lev].define( + rhs.emplace_back( a_vel[lev]->boxArray(), a_vel[lev]->DistributionMap(), AMREX_SPACEDIM, 0); auto rhs_ma = rhs[lev].arrays(); auto vel_ma = a_vel[lev]->const_arrays(); From d831c08a205200c992396d028b72e5f136d6b445 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Tue, 19 Aug 2025 20:01:29 +0200 Subject: [PATCH 45/87] no [=] --- .clang-tidy | 3 +- Source/PeleLMeX_Advection.cpp | 22 +- Source/PeleLMeX_DeriveFunc.cpp | 1078 +++++++++-------- Source/PeleLMeX_Diffusion.cpp | 32 +- Source/PeleLMeX_EB.cpp | 77 +- Source/PeleLMeX_Eos.cpp | 26 +- Source/PeleLMeX_FlowController.cpp | 8 +- Source/PeleLMeX_Forces.cpp | 11 +- Source/PeleLMeX_Init.cpp | 35 +- Source/PeleLMeX_Plot.cpp | 20 +- Source/PeleLMeX_ProblemSpecificFunctions.H | 10 +- Source/PeleLMeX_Projection.cpp | 48 +- Source/PeleLMeX_Reactions.cpp | 82 +- Source/PeleLMeX_Soot.cpp | 41 +- Source/PeleLMeX_Tagging.cpp | 23 +- Source/PeleLMeX_Temporals.cpp | 43 +- Source/PeleLMeX_TransportProp.cpp | 174 ++- Source/PeleLMeX_UMac.cpp | 68 +- Source/PeleLMeX_Utils.cpp | 177 ++- .../Plasma/LinOps/AMReX_MLCellABecCecLap.cpp | 2 +- Source/Plasma/PeleLMeX_EFDeriveFunc.cpp | 221 ++-- Source/Plasma/PeleLMeX_EFIonDrift.cpp | 78 +- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 252 ++-- Source/Plasma/PeleLMeX_EFReactions.cpp | 26 +- Source/Plasma/PeleLMeX_EFTimeStep.cpp | 142 +-- Source/Plasma/PeleLMeX_EFTransport.cpp | 40 +- Source/Plasma/PeleLMeX_EFUtils.cpp | 66 +- 27 files changed, 1512 insertions(+), 1293 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 69b827996..6e9188e4e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,7 +7,8 @@ Checks: 'bugprone-*, clang-diagnostic-*, clang-analyzer-*, corecppguidelines-*, - modernize-*, + cppcoreguidelines-avoid-capture-default, + modernize-*, -modernize-avoid-c-arrays, -modernize-use-trailing-return-type, -modernize-use-nodiscard, diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 1c26ceab7..de70b18e1 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -587,7 +587,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) #ifdef AMREX_USE_EB if (flagfab.getType(ebx) == amrex::FabType::covered) { // Covered boxes amrex::ParallelFor( - ebx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ebx, [rho_ed] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { rho_ed(i, j, k) = 0.0; }); } else if ( @@ -595,7 +595,8 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) // boxes const auto& afrac = areafrac[idim]->array(mfi); amrex::ParallelFor( - ebx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ebx, [rho_ed, afrac, + rhoY_ed] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { rho_ed(i, j, k) = 0.0; if (afrac(i, j, k) > 0.0) { // Uncovered faces pele::physics::PhysicsType::eos_type::RY2R( @@ -606,7 +607,8 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) #endif { amrex::ParallelFor( - ebx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ebx, + [rhoY_ed, rho_ed] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { pele::physics::PhysicsType::eos_type::RY2R( rhoY_ed.cellData(i, j, k), rho_ed(i, j, k)); }); @@ -679,7 +681,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) #ifdef AMREX_USE_EB if (flagfab.getType(ebx) == amrex::FabType::covered) { // Covered boxes amrex::ParallelFor( - ebx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ebx, [rhoHm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { rhoHm(i, j, k) = 0.0; }); } else if ( @@ -687,7 +689,8 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) // boxes const auto& afrac = areafrac[idim]->array(mfi); amrex::ParallelFor( - ebx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ebx, [rhoHm, afrac, rhoY, T, rho, + leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (afrac(i, j, k) <= 0.0) { // Covered faces rhoHm(i, j, k) = 0.0; } else { @@ -698,7 +701,8 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) #endif { amrex::ParallelFor( - ebx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ebx, [rho, rhoY, T, rhoHm, + leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { getRHmixGivenTY(i, j, k, rho, rhoY, T, rhoHm, leosparm); }); } @@ -914,7 +918,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) auto aofsma = advData->AofS[lev].arrays(); amrex::ParallelFor( advData->AofS[lev], - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [aofsma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { pele::physics::PhysicsType::eos_type::RY2R( aofsma[box_no].cellData(i, j, k), aofsma[box_no](i, j, k, DENSITY), FIRSTSPEC); @@ -935,8 +939,8 @@ PeleLM::updateDensity(std::unique_ptr& advData) const auto dt = m_dt; amrex::ParallelFor( - advData->AofS[lev], - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + advData->AofS[lev], [sma_o, sma_n, aofsma, extma, dt] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { sma_n[box_no](i, j, k, DENSITY) = sma_o[box_no](i, j, k, DENSITY) + dt * (aofsma[box_no](i, j, k, DENSITY) + diff --git a/Source/PeleLMeX_DeriveFunc.cpp b/Source/PeleLMeX_DeriveFunc.cpp index 4f4a7a5ce..bfbc441a4 100644 --- a/Source/PeleLMeX_DeriveFunc.cpp +++ b/Source/PeleLMeX_DeriveFunc.cpp @@ -37,9 +37,10 @@ pelelmex_dertemp( AMREX_ASSERT(!a_pelelm->m_incompressible); auto const in_dat = statefab.array(); auto der = derfab.array(dcomp); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - der(i, j, k) = in_dat(i, j, k, TEMP); - }); + amrex::ParallelFor( + bx, [der, in_dat] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + der(i, j, k) = in_dat(i, j, k, TEMP); + }); } // @@ -75,13 +76,15 @@ pelelmex_derheatrelease( auto const& Hi = EnthFab.array(); auto HRR = derfab.array(dcomp); auto const* leosparm = a_pelelm->eos_parms.device_parm(); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - getHGivenT(i, j, k, temp, Hi, leosparm); - HRR(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; ++n) { - HRR(i, j, k) -= Hi(i, j, k, n) * react(i, j, k, n); - } - }); + amrex::ParallelFor( + bx, [temp, Hi, leosparm, HRR, + react] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + getHGivenT(i, j, k, temp, Hi, leosparm); + HRR(i, j, k) = 0.0; + for (int n = 0; n < NUM_SPECIES; ++n) { + HRR(i, j, k) -= Hi(i, j, k, n) * react(i, j, k, n); + } + }); } // @@ -113,8 +116,9 @@ pelelmex_dermassfrac( auto const in_dat = statefab.array(); auto der = derfab.array(dcomp); amrex::ParallelFor( - bx, NUM_SPECIES, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - amrex::Real rhoinv = 1.0 / in_dat(i, j, k, DENSITY); + bx, NUM_SPECIES, + [in_dat, der] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + const amrex::Real rhoinv = 1.0 / in_dat(i, j, k, DENSITY); der(i, j, k, n) = in_dat(i, j, k, FIRSTSPEC + n) * rhoinv; }); } @@ -147,19 +151,20 @@ pelelmex_dermolefrac( auto const in_dat = statefab.array(); auto der = derfab.array(dcomp); auto const* leosparm = a_pelelm->eos_parms.device_parm(); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::Real Yt[NUM_SPECIES] = {0.0}; - amrex::Real Xt[NUM_SPECIES] = {0.0}; - amrex::Real rhoinv = 1.0 / in_dat(i, j, k, DENSITY); - for (int n = 0; n < NUM_SPECIES; ++n) { - Yt[n] = in_dat(i, j, k, FIRSTSPEC + n) * rhoinv; - } - auto eos = pele::physics::PhysicsType::eos(leosparm); - eos.Y2X(Yt, Xt); - for (int n = 0; n < NUM_SPECIES; ++n) { - der(i, j, k, n) = Xt[n]; - } - }); + amrex::ParallelFor( + bx, [in_dat, leosparm, der] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::Real Yt[NUM_SPECIES] = {0.0}; + amrex::Real Xt[NUM_SPECIES] = {0.0}; + amrex::Real rhoinv = 1.0 / in_dat(i, j, k, DENSITY); + for (int n = 0; n < NUM_SPECIES; ++n) { + Yt[n] = in_dat(i, j, k, FIRSTSPEC + n) * rhoinv; + } + auto eos = pele::physics::PhysicsType::eos(leosparm); + eos.Y2X(Yt, Xt); + for (int n = 0; n < NUM_SPECIES; ++n) { + der(i, j, k, n) = Xt[n]; + } + }); } // @@ -190,12 +195,13 @@ pelelmex_derrhomrhoy( AMREX_ASSERT(!a_pelelm->m_incompressible); auto const in_dat = statefab.array(); auto der = derfab.array(dcomp); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - der(i, j, k, 0) = in_dat(i, j, k, DENSITY); - for (int n = 0; n < NUM_SPECIES; ++n) { - der(i, j, k, 0) -= in_dat(i, j, k, FIRSTSPEC + n); - } - }); + amrex::ParallelFor( + bx, [der, in_dat] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + der(i, j, k, 0) = in_dat(i, j, k, DENSITY); + for (int n = 0; n < NUM_SPECIES; ++n) { + der(i, j, k, 0) -= in_dat(i, j, k, FIRSTSPEC + n); + } + }); } // @@ -220,19 +226,20 @@ pelelmex_deravgpress( AMREX_ASSERT(derfab.box().contains(bx)); auto const in_dat = pressfab.array(); auto der = derfab.array(dcomp); - amrex::Real factor = 1.0 / (AMREX_D_TERM(2.0, *2.0, *2.0)); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - der(i, j, k) = - factor * (in_dat(i + 1, j, k) + in_dat(i, j, k) + constexpr amrex::Real factor = 1.0 / (AMREX_D_TERM(2.0, *2.0, *2.0)); + amrex::ParallelFor( + bx, [der, in_dat] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + der(i, j, k) = + factor * (in_dat(i + 1, j, k) + in_dat(i, j, k) #if (AMREX_SPACEDIM >= 2) - + in_dat(i + 1, j + 1, k) + in_dat(i, j + 1, k) + + in_dat(i + 1, j + 1, k) + in_dat(i, j + 1, k) #if (AMREX_SPACEDIM == 3) - + in_dat(i + 1, j, k + 1) + in_dat(i, j, k + 1) + - in_dat(i + 1, j + 1, k + 1) + in_dat(i, j + 1, k + 1) + + in_dat(i + 1, j, k + 1) + in_dat(i, j, k + 1) + + in_dat(i + 1, j + 1, k + 1) + in_dat(i, j + 1, k + 1) #endif #endif - ); - }); + ); + }); } // @@ -258,11 +265,12 @@ pelelmex_dermgvel( AMREX_ASSERT(statefab.box().contains(bx)); auto const vel = statefab.array(VELX); auto der = derfab.array(dcomp); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - der(i, j, k) = std::sqrt((AMREX_D_TERM( - vel(i, j, k, 0) * vel(i, j, k, 0), +vel(i, j, k, 1) * vel(i, j, k, 1), - +vel(i, j, k, 2) * vel(i, j, k, 2)))); - }); + amrex::ParallelFor( + bx, [der, vel] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + der(i, j, k) = std::sqrt((AMREX_D_TERM( + vel(i, j, k, 0) * vel(i, j, k, 0), +vel(i, j, k, 1) * vel(i, j, k, 1), + +vel(i, j, k, 2) * vel(i, j, k, 2)))); + }); } // @@ -299,58 +307,68 @@ pelelmex_dermgvort( auto typ = flags.getType(bx); if (typ == amrex::FabType::covered) { - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - vort_arr(i, j, k) = 0.0; - }); + amrex::ParallelFor( + bx, [vort_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + vort_arr(i, j, k) = 0.0; + }); } else if (typ == amrex::FabType::singlevalued) { const auto& flag_fab = flags.const_array(); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - constexpr amrex::Real c0 = -1.5; - constexpr amrex::Real c1 = 2.0; - constexpr amrex::Real c2 = -0.5; - if (flag_fab(i, j, k).isCovered()) { - vort_arr(i, j, k) = 0.0; - } else { - // Define interpolation lambda - auto onesided = []( - const amrex::Real& v0, const amrex::Real& v1, - const amrex::Real& v2) -> amrex::Real { - return c0 * v0 + c1 * v1 + c2 * v2; - }; - - amrex::Real vx = 0.0; - amrex::Real uy = 0.0; -#if (AMREX_SPACEDIM == 2) - // Need to check if there are covered cells in neighbours -- - // -- if so, use one-sided difference computation (but still quadratic) - if (!flag_fab(i, j, k).isConnected(1, 0, 0)) { - vx = -onesided( - dat_arr(i, j, k, 1), dat_arr(i - 1, j, k, 1), - dat_arr(i - 2, j, k, 1)) * - idx; - } else if (!flag_fab(i, j, k).isConnected(-1, 0, 0)) { - vx = onesided( - dat_arr(i, j, k, 1), dat_arr(i + 1, j, k, 1), - dat_arr(i + 2, j, k, 1)) * - idx; - } else { - vx = 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; - } - // Do the same in y-direction - if (!flag_fab(i, j, k).isConnected(0, 1, 0)) { - uy = -onesided( - dat_arr(i, j, k, 0), dat_arr(i, j - 1, k, 0), - dat_arr(i, j - 2, k, 0)) * - idy; - } else if (!flag_fab(i, j, k).isConnected(0, -1, 0)) { - uy = onesided( - dat_arr(i, j, k, 0), dat_arr(i, j + 1, k, 0), - dat_arr(i, j + 2, k, 0)) * - idy; + amrex::ParallelFor( + bx, [vort_arr, dat_arr, flag_fab, idx, idy +#if AMREX_SPACEDIM == 3 + , + idz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + constexpr amrex::Real c0 = -1.5; + constexpr amrex::Real c1 = 2.0; + constexpr amrex::Real c2 = -0.5; + if (flag_fab(i, j, k).isCovered()) { + vort_arr(i, j, k) = 0.0; } else { - uy = 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; - } - vort_arr(i, j, k) = std::abs(vx - uy); + // Define interpolation lambda + auto onesided = []( + const amrex::Real& v0, const amrex::Real& v1, + const amrex::Real& v2) -> amrex::Real { + return c0 * v0 + c1 * v1 + c2 * v2; + }; + + amrex::Real vx = 0.0; + amrex::Real uy = 0.0; +#if (AMREX_SPACEDIM == 2) + // Need to check if there are covered cells in neighbours -- + // -- if so, use one-sided difference computation (but still + // quadratic) + if (!flag_fab(i, j, k).isConnected(1, 0, 0)) { + vx = -onesided( + dat_arr(i, j, k, 1), dat_arr(i - 1, j, k, 1), + dat_arr(i - 2, j, k, 1)) * + idx; + } else if (!flag_fab(i, j, k).isConnected(-1, 0, 0)) { + vx = onesided( + dat_arr(i, j, k, 1), dat_arr(i + 1, j, k, 1), + dat_arr(i + 2, j, k, 1)) * + idx; + } else { + vx = + 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; + } + // Do the same in y-direction + if (!flag_fab(i, j, k).isConnected(0, 1, 0)) { + uy = -onesided( + dat_arr(i, j, k, 0), dat_arr(i, j - 1, k, 0), + dat_arr(i, j - 2, k, 0)) * + idy; + } else if (!flag_fab(i, j, k).isConnected(0, -1, 0)) { + uy = onesided( + dat_arr(i, j, k, 0), dat_arr(i, j + 1, k, 0), + dat_arr(i, j + 2, k, 0)) * + idy; + } else { + uy = + 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; + } + vort_arr(i, j, k) = std::abs(vx - uy); #elif (AMREX_SPACEDIM == 3) amrex::Real wx = 0.0; @@ -396,32 +414,38 @@ pelelmex_dermgvort( } vort_arr(i,j,k) = std::sqrt((wy-vz)*(wy-vz) + (uz-wx)*(uz-wx) + (vx-uy)*(vx-uy)); #endif - } - }); + } + }); } else #endif // Check on EB { - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::ParallelFor( + bx, [dat_arr, vort_arr, idx, idy +#if (AMREX_SPACEDIM == 3) + , + idz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { #if (AMREX_SPACEDIM == 2) - amrex::Real vx = - 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; - amrex::Real uy = - 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; - vort_arr(i, j, k) = std::abs(vx - uy); + const amrex::Real vx = + 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; + const amrex::Real uy = + 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; + vort_arr(i, j, k) = std::abs(vx - uy); #elif (AMREX_SPACEDIM == 3) - amrex::Real vx = 0.5 * (dat_arr(i+1,j,k,1) - dat_arr(i-1,j,k,1)) * idx; - amrex::Real wx = 0.5 * (dat_arr(i+1,j,k,2) - dat_arr(i-1,j,k,2)) * idx; + const amrex::Real vx = 0.5 * (dat_arr(i+1,j,k,1) - dat_arr(i-1,j,k,1)) * idx; + const amrex::Real wx = 0.5 * (dat_arr(i+1,j,k,2) - dat_arr(i-1,j,k,2)) * idx; - amrex::Real uy = 0.5 * (dat_arr(i,j+1,k,0) - dat_arr(i,j-1,k,0)) * idy; - amrex::Real wy = 0.5 * (dat_arr(i,j+1,k,2) - dat_arr(i,j-1,k,2)) * idy; - - amrex::Real uz = 0.5 * (dat_arr(i,j,k+1,0) - dat_arr(i,j,k-1,0)) * idz; - amrex::Real vz = 0.5 * (dat_arr(i,j,k+1,1) - dat_arr(i,j,k-1,1)) * idz; + const amrex::Real uy = 0.5 * (dat_arr(i,j+1,k,0) - dat_arr(i,j-1,k,0)) * idy; + const amrex::Real wy = 0.5 * (dat_arr(i,j+1,k,2) - dat_arr(i,j-1,k,2)) * idy; + + const amrex::Real uz = 0.5 * (dat_arr(i,j,k+1,0) - dat_arr(i,j,k-1,0)) * idz; + const amrex::Real vz = 0.5 * (dat_arr(i,j,k+1,1) - dat_arr(i,j,k-1,1)) * idz; vort_arr(i,j,k) = std::sqrt((wy-vz)*(wy-vz) + (uz-wx)*(uz-wx) + (vx-uy)*(vx-uy)); #endif - }); + }); } } @@ -444,7 +468,6 @@ pelelmex_dervort( int /*level*/) { - amrex::ignore_unused(ncomp, bx); AMREX_ASSERT(derfab.box().contains(bx)); AMREX_ASSERT(statefab.box().contains(bx)); AMREX_ASSERT(derfab.nComp() >= dcomp + ncomp); @@ -464,60 +487,70 @@ pelelmex_dervort( if (typ == amrex::FabType::covered) { amrex::ParallelFor( - bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + bx, ncomp, + [vort_arr] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { vort_arr(i, j, k, n) = 0.0; }); } else if (typ == amrex::FabType::singlevalued) { const auto& flag_fab = flags.const_array(); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - constexpr amrex::Real c0 = -1.5; - constexpr amrex::Real c1 = 2.0; - constexpr amrex::Real c2 = -0.5; - if (flag_fab(i, j, k).isCovered()) { - for (int n{0}; n < ncomp; ++n) { - vort_arr(i, j, k, n) = 0.0; - } - } else { - // Define interpolation lambda - auto onesided = []( - const amrex::Real& v0, const amrex::Real& v1, - const amrex::Real& v2) -> amrex::Real { - return c0 * v0 + c1 * v1 + c2 * v2; - }; - - amrex::Real vx = 0.0; - amrex::Real uy = 0.0; -#if (AMREX_SPACEDIM == 2) - // Need to check if there are covered cells in neighbours -- - // -- if so, use one-sided difference computation (but still quadratic) - if (!flag_fab(i, j, k).isConnected(1, 0, 0)) { - vx = -onesided( - dat_arr(i, j, k, 1), dat_arr(i - 1, j, k, 1), - dat_arr(i - 2, j, k, 1)) * - idx; - } else if (!flag_fab(i, j, k).isConnected(-1, 0, 0)) { - vx = onesided( - dat_arr(i, j, k, 1), dat_arr(i + 1, j, k, 1), - dat_arr(i + 2, j, k, 1)) * - idx; - } else { - vx = 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; - } - // Do the same in y-direction - if (!flag_fab(i, j, k).isConnected(0, 1, 0)) { - uy = -onesided( - dat_arr(i, j, k, 0), dat_arr(i, j - 1, k, 0), - dat_arr(i, j - 2, k, 0)) * - idy; - } else if (!flag_fab(i, j, k).isConnected(0, -1, 0)) { - uy = onesided( - dat_arr(i, j, k, 0), dat_arr(i, j + 1, k, 0), - dat_arr(i, j + 2, k, 0)) * - idy; + amrex::ParallelFor( + bx, [vort_arr, flag_fab, dat_arr, ncomp, idx, idy +#if (AMREX_SPACEDIM == 3) + , + idz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + constexpr amrex::Real c0 = -1.5; + constexpr amrex::Real c1 = 2.0; + constexpr amrex::Real c2 = -0.5; + if (flag_fab(i, j, k).isCovered()) { + for (int n{0}; n < ncomp; ++n) { + vort_arr(i, j, k, n) = 0.0; + } } else { - uy = 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; - } - vort_arr(i, j, k) = vx - uy; + // Define interpolation lambda + auto onesided = []( + const amrex::Real& v0, const amrex::Real& v1, + const amrex::Real& v2) -> amrex::Real { + return c0 * v0 + c1 * v1 + c2 * v2; + }; + + amrex::Real vx = 0.0; + amrex::Real uy = 0.0; +#if (AMREX_SPACEDIM == 2) + // Need to check if there are covered cells in neighbours -- + // -- if so, use one-sided difference computation (but still + // quadratic) + if (!flag_fab(i, j, k).isConnected(1, 0, 0)) { + vx = -onesided( + dat_arr(i, j, k, 1), dat_arr(i - 1, j, k, 1), + dat_arr(i - 2, j, k, 1)) * + idx; + } else if (!flag_fab(i, j, k).isConnected(-1, 0, 0)) { + vx = onesided( + dat_arr(i, j, k, 1), dat_arr(i + 1, j, k, 1), + dat_arr(i + 2, j, k, 1)) * + idx; + } else { + vx = + 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; + } + // Do the same in y-direction + if (!flag_fab(i, j, k).isConnected(0, 1, 0)) { + uy = -onesided( + dat_arr(i, j, k, 0), dat_arr(i, j - 1, k, 0), + dat_arr(i, j - 2, k, 0)) * + idy; + } else if (!flag_fab(i, j, k).isConnected(0, -1, 0)) { + uy = onesided( + dat_arr(i, j, k, 0), dat_arr(i, j + 1, k, 0), + dat_arr(i, j + 2, k, 0)) * + idy; + } else { + uy = + 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; + } + vort_arr(i, j, k) = vx - uy; #elif (AMREX_SPACEDIM == 3) amrex::Real wx = 0.0; @@ -565,19 +598,25 @@ pelelmex_dervort( vort_arr(i,j,k,1) = (uz-wx)*(uz-wx); vort_arr(i,j,k,2) = (vx-uy)*(vx-uy); #endif - } - }); + } + }); } else #endif // Check on EB { - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::ParallelFor( + bx, [dat_arr, vort_arr, idx, idy +#if (AMREX_SPACEDIM == 3) + , + idz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { #if (AMREX_SPACEDIM == 2) - amrex::Real vx = - 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; - amrex::Real uy = - 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; - vort_arr(i, j, k) = vx - uy; + amrex::Real vx = + 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; + amrex::Real uy = + 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; + vort_arr(i, j, k) = vx - uy; #elif (AMREX_SPACEDIM == 3) amrex::Real vx = 0.5 * (dat_arr(i+1,j,k,1) - dat_arr(i-1,j,k,1)) * idx; @@ -593,7 +632,7 @@ pelelmex_dervort( vort_arr(i,j,k,1) = (uz-wx)*(uz-wx); vort_arr(i,j,k,2) = (vx-uy)*(vx-uy); #endif - }); + }); } } @@ -644,30 +683,43 @@ pelelmex_dercoord( const auto& flag_arr = flags.const_array(); const auto& ccent_fab = ebfab.getCentroidData(); const auto& ccent_arr = ccent_fab->const_array(); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - const amrex::Real* prob_lo = geomdata.ProbLo(); - if (flag_arr(i, j, k).isCovered() || flag_arr(i, j, k).isRegular()) { - AMREX_D_TERM(coord_arr(i, j, k, 0) = prob_lo[0] + (i + 0.5) * dx; - , coord_arr(i, j, k, 1) = prob_lo[1] + (j + 0.5) * dy; - , coord_arr(i, j, k, 2) = prob_lo[2] + (k + 0.5) * dz;); - } else { - AMREX_D_TERM(coord_arr(i, j, k, 0) = - prob_lo[0] + (i + 0.5 + ccent_arr(i, j, k, 0)) * dx; - , coord_arr(i, j, k, 1) = - prob_lo[1] + (j + 0.5 + ccent_arr(i, j, k, 1)) * dy; - , coord_arr(i, j, k, 2) = + amrex::ParallelFor( + bx, [flag_arr, ccent_arr, coord_arr, geomdata, dx, dy +#if (AMREX_SPACEDIM == 3) + , + dz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + const amrex::Real* prob_lo = geomdata.ProbLo(); + if (flag_arr(i, j, k).isCovered() || flag_arr(i, j, k).isRegular()) { + AMREX_D_TERM(coord_arr(i, j, k, 0) = prob_lo[0] + (i + 0.5) * dx; + , coord_arr(i, j, k, 1) = prob_lo[1] + (j + 0.5) * dy; + , coord_arr(i, j, k, 2) = prob_lo[2] + (k + 0.5) * dz;); + } else { + AMREX_D_TERM(coord_arr(i, j, k, 0) = + prob_lo[0] + (i + 0.5 + ccent_arr(i, j, k, 0)) * dx; + , coord_arr(i, j, k, 1) = + prob_lo[1] + (j + 0.5 + ccent_arr(i, j, k, 1)) * dy; + , + coord_arr(i, j, k, 2) = prob_lo[2] + (k + 0.5 + ccent_arr(i, j, k, 2)) * dz;); - } - }); + } + }); } else #endif { - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - const amrex::Real* prob_lo = geomdata.ProbLo(); - AMREX_D_TERM(coord_arr(i, j, k, 0) = prob_lo[0] + (i + 0.5) * dx; - , coord_arr(i, j, k, 1) = prob_lo[1] + (j + 0.5) * dy; - , coord_arr(i, j, k, 2) = prob_lo[2] + (k + 0.5) * dz;); - }); + const amrex::Real* prob_lo = geomdata.ProbLo(); + amrex::ParallelFor( + bx, [coord_arr, prob_lo, dx, dy +#if (AMREX_SPACEDIM == 3) + , + dz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + AMREX_D_TERM(coord_arr(i, j, k, 0) = prob_lo[0] + (i + 0.5) * dx; + , coord_arr(i, j, k, 1) = prob_lo[1] + (j + 0.5) * dy; + , coord_arr(i, j, k, 2) = prob_lo[2] + (k + 0.5) * dz;); + }); } } @@ -726,132 +778,191 @@ pelelmex_derQcrit( auto typ = flags.getType(bx); if (typ == amrex::FabType::covered) { - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - qcrit_arr(i, j, k) = 0.0; - }); + amrex::ParallelFor( + bx, [qcrit_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + qcrit_arr(i, j, k) = 0.0; + }); } else if (typ == amrex::FabType::singlevalued) { const auto& flag_fab = flags.const_array(); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - if (flag_fab(i, j, k).isCovered()) { - qcrit_arr(i, j, k) = 0.0; - } else { - // Define interpolation lambda - constexpr amrex::Real c0 = -1.5; - constexpr amrex::Real c1 = 2.0; - constexpr amrex::Real c2 = -0.5; - auto onesided = []( - const amrex::Real& v0, const amrex::Real& v1, - const amrex::Real& v2) -> amrex::Real { - return c0 * v0 + c1 * v1 + c2 * v2; - }; + amrex::ParallelFor( + bx, [qcrit_arr, flag_fab, idx, idy +#if (AMREX_SPACEDIM == 3) + , + idz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + if (flag_fab(i, j, k).isCovered()) { + qcrit_arr(i, j, k) = 0.0; + } else { + // Define interpolation lambda + constexpr amrex::Real c0 = -1.5; + constexpr amrex::Real c1 = 2.0; + constexpr amrex::Real c2 = -0.5; + auto onesided = []( + const amrex::Real& v0, const amrex::Real& v1, + const amrex::Real& v2) -> amrex::Real { + return c0 * v0 + c1 * v1 + c2 * v2; + }; + + // Strain rate tensor + amrex::Array2D gradU; + if (!flag_fab(i, j, k).isConnected(1, 0, 0)) { + gradU(0, 0) = -onesided( + dat_arr(i, j, k, 0), dat_arr(i - 1, j, k, 0), + dat_arr(i - 2, j, k, 0)) * + idx; + gradU(1, 0) = -onesided( + dat_arr(i, j, k, 1), dat_arr(i - 1, j, k, 1), + dat_arr(i - 2, j, k, 1)) * + idx; + gradU(2, 0) = -onesided( + dat_arr(i, j, k, 2), dat_arr(i - 1, j, k, 2), + dat_arr(i - 2, j, k, 2)) * + idx; + } else if (!flag_fab(i, j, k).isConnected(-1, 0, 0)) { + gradU(0, 0) = onesided( + dat_arr(i, j, k, 0), dat_arr(i + 1, j, k, 0), + dat_arr(i + 2, j, k, 0)) * + idx; + gradU(1, 0) = onesided( + dat_arr(i, j, k, 1), dat_arr(i + 1, j, k, 1), + dat_arr(i + 2, j, k, 1)) * + idx; + gradU(2, 0) = onesided( + dat_arr(i, j, k, 2), dat_arr(i + 1, j, k, 2), + dat_arr(i + 2, j, k, 2)) * + idx; + } else { + gradU(0, 0) = + 0.5 * (dat_arr(i + 1, j, k, 0) - dat_arr(i - 1, j, k, 0)) * idx; + gradU(1, 0) = + 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; + gradU(2, 0) = + 0.5 * (dat_arr(i + 1, j, k, 2) - dat_arr(i - 1, j, k, 2)) * idx; + } + if (!flag_fab(i, j, k).isConnected(0, 1, 0)) { + gradU(0, 1) = -onesided( + dat_arr(i, j, k, 0), dat_arr(i, j - 1, k, 0), + dat_arr(i, j - 2, k, 0)) * + idy; + gradU(1, 1) = -onesided( + dat_arr(i, j, k, 1), dat_arr(i, j - 1, k, 1), + dat_arr(i, j - 2, k, 1)) * + idy; + gradU(2, 1) = -onesided( + dat_arr(i, j, k, 2), dat_arr(i, j - 1, k, 2), + dat_arr(i, j - 2, k, 2)) * + idy; + } else if (!flag_fab(i, j, k).isConnected(0, -1, 0)) { + gradU(0, 1) = onesided( + dat_arr(i, j, k, 0), dat_arr(i, j + 1, k, 0), + dat_arr(i, j + 2, k, 0)) * + idy; + gradU(1, 1) = onesided( + dat_arr(i, j, k, 1), dat_arr(i, j + 1, k, 1), + dat_arr(i, j + 2, k, 1)) * + idy; + gradU(2, 1) = onesided( + dat_arr(i, j, k, 2), dat_arr(i, j + 1, k, 2), + dat_arr(i, j + 2, k, 2)) * + idy; + } else { + gradU(0, 1) = + 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; + gradU(1, 1) = + 0.5 * (dat_arr(i, j + 1, k, 1) - dat_arr(i, j - 1, k, 1)) * idy; + gradU(2, 1) = + 0.5 * (dat_arr(i, j + 1, k, 2) - dat_arr(i, j - 1, k, 2)) * idy; + } + if (!flag_fab(i, j, k).isConnected(0, 0, 1)) { + gradU(0, 2) = -onesided( + dat_arr(i, j, k, 0), dat_arr(i, j, k - 1, 0), + dat_arr(i, j, k - 2, 0)) * + idz; + gradU(1, 2) = -onesided( + dat_arr(i, j, k, 1), dat_arr(i, j, k - 1, 1), + dat_arr(i, j, k - 2, 1)) * + idz; + gradU(2, 2) = -onesided( + dat_arr(i, j, k, 2), dat_arr(i, j, k - 1, 2), + dat_arr(i, j, k - 2, 2)) * + idz; + } else if (!flag_fab(i, j, k).isConnected(0, 0, -1)) { + gradU(0, 2) = onesided( + dat_arr(i, j, k, 0), dat_arr(i, j, k + 1, 0), + dat_arr(i, j, k + 2, 0)) * + idz; + gradU(1, 2) = onesided( + dat_arr(i, j, k, 1), dat_arr(i, j, k + 1, 1), + dat_arr(i, j, k + 2, 1)) * + idz; + gradU(2, 2) = onesided( + dat_arr(i, j, k, 2), dat_arr(i, j, k + 1, 2), + dat_arr(i, j, k + 2, 2)) * + idz; + } else { + gradU(0, 2) = + 0.5 * (dat_arr(i, j, k + 1, 0) - dat_arr(i, j, k - 1, 0)) * idz; + gradU(1, 2) = + 0.5 * (dat_arr(i, j, k + 1, 1) - dat_arr(i, j, k - 1, 1)) * idz; + gradU(2, 2) = + 0.5 * (dat_arr(i, j, k + 1, 2) - dat_arr(i, j, k - 1, 2)) * idz; + } + // Divu + const amrex::Real divU = gradU(0, 0) + gradU(1, 1) + gradU(2, 2); + + // Directly Assemble Sym. & AntiSym. into Qcrit. + // Remove divU (dilatation) from the Sym. tensor (due to + // mixing/reaction most often) + qcrit_arr(i, j, k) = 0.0; + for (int dim1 = 0; dim1 < AMREX_SPACEDIM; ++dim1) { + for (int dim2 = 0; dim2 < AMREX_SPACEDIM; ++dim2) { + const amrex::Real Ohm = + 0.5 * (gradU(dim1, dim2) - gradU(dim2, dim1)); + const amrex::Real Sij = + 0.5 * (gradU(dim1, dim2) + gradU(dim2, dim1)); + if (dim1 == dim2) { + Sij -= divU / static_cast(AMREX_SPACEDIM); + } + qcrit_arr(i, j, k) += Ohm * Ohm - Sij * Sij; + } + } + } + }); + } else +#endif + { + amrex::ParallelFor( + bx, [dat_arr, qcrit_arr, idx, idy +#if (AMREX_SPACEDIM == 3) + , + idz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Strain rate tensor amrex::Array2D gradU; - if (!flag_fab(i, j, k).isConnected(1, 0, 0)) { - gradU(0, 0) = -onesided( - dat_arr(i, j, k, 0), dat_arr(i - 1, j, k, 0), - dat_arr(i - 2, j, k, 0)) * - idx; - gradU(1, 0) = -onesided( - dat_arr(i, j, k, 1), dat_arr(i - 1, j, k, 1), - dat_arr(i - 2, j, k, 1)) * - idx; - gradU(2, 0) = -onesided( - dat_arr(i, j, k, 2), dat_arr(i - 1, j, k, 2), - dat_arr(i - 2, j, k, 2)) * - idx; - } else if (!flag_fab(i, j, k).isConnected(-1, 0, 0)) { - gradU(0, 0) = onesided( - dat_arr(i, j, k, 0), dat_arr(i + 1, j, k, 0), - dat_arr(i + 2, j, k, 0)) * - idx; - gradU(1, 0) = onesided( - dat_arr(i, j, k, 1), dat_arr(i + 1, j, k, 1), - dat_arr(i + 2, j, k, 1)) * - idx; - gradU(2, 0) = onesided( - dat_arr(i, j, k, 2), dat_arr(i + 1, j, k, 2), - dat_arr(i + 2, j, k, 2)) * - idx; - } else { - gradU(0, 0) = - 0.5 * (dat_arr(i + 1, j, k, 0) - dat_arr(i - 1, j, k, 0)) * idx; - gradU(1, 0) = - 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; - gradU(2, 0) = - 0.5 * (dat_arr(i + 1, j, k, 2) - dat_arr(i - 1, j, k, 2)) * idx; - } - if (!flag_fab(i, j, k).isConnected(0, 1, 0)) { - gradU(0, 1) = -onesided( - dat_arr(i, j, k, 0), dat_arr(i, j - 1, k, 0), - dat_arr(i, j - 2, k, 0)) * - idy; - gradU(1, 1) = -onesided( - dat_arr(i, j, k, 1), dat_arr(i, j - 1, k, 1), - dat_arr(i, j - 2, k, 1)) * - idy; - gradU(2, 1) = -onesided( - dat_arr(i, j, k, 2), dat_arr(i, j - 1, k, 2), - dat_arr(i, j - 2, k, 2)) * - idy; - } else if (!flag_fab(i, j, k).isConnected(0, -1, 0)) { - gradU(0, 1) = onesided( - dat_arr(i, j, k, 0), dat_arr(i, j + 1, k, 0), - dat_arr(i, j + 2, k, 0)) * - idy; - gradU(1, 1) = onesided( - dat_arr(i, j, k, 1), dat_arr(i, j + 1, k, 1), - dat_arr(i, j + 2, k, 1)) * - idy; - gradU(2, 1) = onesided( - dat_arr(i, j, k, 2), dat_arr(i, j + 1, k, 2), - dat_arr(i, j + 2, k, 2)) * - idy; - } else { - gradU(0, 1) = - 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; - gradU(1, 1) = - 0.5 * (dat_arr(i, j + 1, k, 1) - dat_arr(i, j - 1, k, 1)) * idy; - gradU(2, 1) = - 0.5 * (dat_arr(i, j + 1, k, 2) - dat_arr(i, j - 1, k, 2)) * idy; - } - if (!flag_fab(i, j, k).isConnected(0, 0, 1)) { - gradU(0, 2) = -onesided( - dat_arr(i, j, k, 0), dat_arr(i, j, k - 1, 0), - dat_arr(i, j, k - 2, 0)) * - idz; - gradU(1, 2) = -onesided( - dat_arr(i, j, k, 1), dat_arr(i, j, k - 1, 1), - dat_arr(i, j, k - 2, 1)) * - idz; - gradU(2, 2) = -onesided( - dat_arr(i, j, k, 2), dat_arr(i, j, k - 1, 2), - dat_arr(i, j, k - 2, 2)) * - idz; - } else if (!flag_fab(i, j, k).isConnected(0, 0, -1)) { - gradU(0, 2) = onesided( - dat_arr(i, j, k, 0), dat_arr(i, j, k + 1, 0), - dat_arr(i, j, k + 2, 0)) * - idz; - gradU(1, 2) = onesided( - dat_arr(i, j, k, 1), dat_arr(i, j, k + 1, 1), - dat_arr(i, j, k + 2, 1)) * - idz; - gradU(2, 2) = onesided( - dat_arr(i, j, k, 2), dat_arr(i, j, k + 1, 2), - dat_arr(i, j, k + 2, 2)) * - idz; - } else { - gradU(0, 2) = - 0.5 * (dat_arr(i, j, k + 1, 0) - dat_arr(i, j, k - 1, 0)) * idz; - gradU(1, 2) = - 0.5 * (dat_arr(i, j, k + 1, 1) - dat_arr(i, j, k - 1, 1)) * idz; - gradU(2, 2) = - 0.5 * (dat_arr(i, j, k + 1, 2) - dat_arr(i, j, k - 1, 2)) * idz; - } + gradU(0, 0) = + 0.5 * (dat_arr(i + 1, j, k, 0) - dat_arr(i - 1, j, k, 0)) * idx; + gradU(0, 1) = + 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; + gradU(0, 2) = + 0.5 * (dat_arr(i, j, k + 1, 0) - dat_arr(i, j, k - 1, 0)) * idz; + gradU(1, 0) = + 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; + gradU(1, 1) = + 0.5 * (dat_arr(i, j + 1, k, 1) - dat_arr(i, j - 1, k, 1)) * idy; + gradU(1, 2) = + 0.5 * (dat_arr(i, j, k + 1, 1) - dat_arr(i, j, k - 1, 1)) * idz; + gradU(2, 0) = + 0.5 * (dat_arr(i + 1, j, k, 2) - dat_arr(i - 1, j, k, 2)) * idx; + gradU(2, 1) = + 0.5 * (dat_arr(i, j + 1, k, 2) - dat_arr(i, j - 1, k, 2)) * idy; + gradU(2, 2) = + 0.5 * (dat_arr(i, j, k + 1, 2) - dat_arr(i, j, k - 1, 2)) * idz; // Divu - amrex::Real divU = gradU(0, 0) + gradU(1, 1) + gradU(2, 2); + const amrex::Real divU = gradU(0, 0) + gradU(1, 1) + gradU(2, 2); // Directly Assemble Sym. & AntiSym. into Qcrit. // Remove divU (dilatation) from the Sym. tensor (due to mixing/reaction @@ -859,59 +970,16 @@ pelelmex_derQcrit( qcrit_arr(i, j, k) = 0.0; for (int dim1 = 0; dim1 < AMREX_SPACEDIM; ++dim1) { for (int dim2 = 0; dim2 < AMREX_SPACEDIM; ++dim2) { - amrex::Real Ohm = 0.5 * (gradU(dim1, dim2) - gradU(dim2, dim1)); + const amrex::Real Ohm = + 0.5 * (gradU(dim1, dim2) - gradU(dim2, dim1)); amrex::Real Sij = 0.5 * (gradU(dim1, dim2) + gradU(dim2, dim1)); if (dim1 == dim2) { - Sij -= divU / AMREX_SPACEDIM; + Sij -= divU / static_cast(AMREX_SPACEDIM); } qcrit_arr(i, j, k) += Ohm * Ohm - Sij * Sij; } } - } - }); - } else -#endif - { - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - // Strain rate tensor - amrex::Array2D gradU; - gradU(0, 0) = - 0.5 * (dat_arr(i + 1, j, k, 0) - dat_arr(i - 1, j, k, 0)) * idx; - gradU(0, 1) = - 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; - gradU(0, 2) = - 0.5 * (dat_arr(i, j, k + 1, 0) - dat_arr(i, j, k - 1, 0)) * idz; - gradU(1, 0) = - 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; - gradU(1, 1) = - 0.5 * (dat_arr(i, j + 1, k, 1) - dat_arr(i, j - 1, k, 1)) * idy; - gradU(1, 2) = - 0.5 * (dat_arr(i, j, k + 1, 1) - dat_arr(i, j, k - 1, 1)) * idz; - gradU(2, 0) = - 0.5 * (dat_arr(i + 1, j, k, 2) - dat_arr(i - 1, j, k, 2)) * idx; - gradU(2, 1) = - 0.5 * (dat_arr(i, j + 1, k, 2) - dat_arr(i, j - 1, k, 2)) * idy; - gradU(2, 2) = - 0.5 * (dat_arr(i, j, k + 1, 2) - dat_arr(i, j, k - 1, 2)) * idz; - - // Divu - amrex::Real divU = gradU(0, 0) + gradU(1, 1) + gradU(2, 2); - - // Directly Assemble Sym. & AntiSym. into Qcrit. - // Remove divU (dilatation) from the Sym. tensor (due to mixing/reaction - // most often) - qcrit_arr(i, j, k) = 0.0; - for (int dim1 = 0; dim1 < AMREX_SPACEDIM; ++dim1) { - for (int dim2 = 0; dim2 < AMREX_SPACEDIM; ++dim2) { - amrex::Real Ohm = 0.5 * (gradU(dim1, dim2) - gradU(dim2, dim1)); - amrex::Real Sij = 0.5 * (gradU(dim1, dim2) + gradU(dim2, dim1)); - if (dim1 == dim2) { - Sij -= divU / AMREX_SPACEDIM; - } - qcrit_arr(i, j, k) += Ohm * Ohm - Sij * Sij; - } - } - }); + }); } #endif } @@ -941,24 +1009,26 @@ pelelmex_derkineticenergy( auto const vel = statefab.array(VELX); auto der = derfab.array(dcomp); const auto rho = a_pelelm->m_rho; - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - der(i, j, k) = - 0.5 * rho * - (AMREX_D_TERM( - vel(i, j, k, 0) * vel(i, j, k, 0), +vel(i, j, k, 1) * vel(i, j, k, 1), - +vel(i, j, k, 2) * vel(i, j, k, 2))); - }); + amrex::ParallelFor( + bx, [der, vel, rho] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + der(i, j, k) = 0.5 * rho * + (AMREX_D_TERM( + vel(i, j, k, 0) * vel(i, j, k, 0), + +vel(i, j, k, 1) * vel(i, j, k, 1), + +vel(i, j, k, 2) * vel(i, j, k, 2))); + }); } else { auto const rho = statefab.array(DENSITY); auto const vel = statefab.array(VELX); auto der = derfab.array(dcomp); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - der(i, j, k) = - 0.5 * rho(i, j, k) * - (AMREX_D_TERM( - vel(i, j, k, 0) * vel(i, j, k, 0), +vel(i, j, k, 1) * vel(i, j, k, 1), - +vel(i, j, k, 2) * vel(i, j, k, 2))); - }); + amrex::ParallelFor( + bx, [der, vel, rho] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + der(i, j, k) = 0.5 * rho(i, j, k) * + (AMREX_D_TERM( + vel(i, j, k, 0) * vel(i, j, k, 0), + +vel(i, j, k, 1) * vel(i, j, k, 1), + +vel(i, j, k, 2) * vel(i, j, k, 2))); + }); } } @@ -999,65 +1069,74 @@ pelelmex_derenstrophy( auto typ = flags.getType(bx); if (typ == amrex::FabType::covered) { - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - ens_arr(i, j, k) = 0.0; - }); + amrex::ParallelFor( + bx, [ens_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ens_arr(i, j, k) = 0.0; + }); } else if (typ == amrex::FabType::singlevalued) { const auto& flag_fab = flags.const_array(); const auto incomp = a_pelelm->m_incompressible; const auto rho = a_pelelm->m_rho; - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - constexpr amrex::Real c0 = -1.5; - constexpr amrex::Real c1 = 2.0; - constexpr amrex::Real c2 = -0.5; - if (flag_fab(i, j, k).isCovered()) { - ens_arr(i, j, k) = 0.0; - } else { - amrex::Real l_rho = rho; - if (incomp == 0) { - l_rho = rho_arr(i, j, k); - } - // Define interpolation lambda - auto onesided = []( - const amrex::Real& v0, const amrex::Real& v1, - const amrex::Real& v2) -> amrex::Real { - return c0 * v0 + c1 * v1 + c2 * v2; - }; - - amrex::Real vx = 0.0; - amrex::Real uy = 0.0; -#if (AMREX_SPACEDIM == 2) - // Need to check if there are covered cells in neighbours -- - // -- if so, use one-sided difference computation (but still - // quadratic) - if (!flag_fab(i, j, k).isConnected(1, 0, 0)) { - vx = -onesided( - dat_arr(i, j, k, 1), dat_arr(i - 1, j, k, 1), - dat_arr(i - 2, j, k, 1)) * - idx; - } else if (!flag_fab(i, j, k).isConnected(-1, 0, 0)) { - vx = onesided( - dat_arr(i, j, k, 1), dat_arr(i + 1, j, k, 1), - dat_arr(i + 2, j, k, 1)) * - idx; - } else { - vx = 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; - } - // Do the same in y-direction - if (!flag_fab(i, j, k).isConnected(0, 1, 0)) { - uy = -onesided( - dat_arr(i, j, k, 0), dat_arr(i, j - 1, k, 0), - dat_arr(i, j - 2, k, 0)) * - idy; - } else if (!flag_fab(i, j, k).isConnected(0, -1, 0)) { - uy = onesided( - dat_arr(i, j, k, 0), dat_arr(i, j + 1, k, 0), - dat_arr(i, j + 2, k, 0)) * - idy; + amrex::ParallelFor( + bx, [ens_arr, flag_fab, dat_arr, rho, incomp, rho_arr, idx, idy +#if (AMREX_SPACEDIM == 3) + , + idz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + constexpr amrex::Real c0 = -1.5; + constexpr amrex::Real c1 = 2.0; + constexpr amrex::Real c2 = -0.5; + if (flag_fab(i, j, k).isCovered()) { + ens_arr(i, j, k) = 0.0; } else { - uy = 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; - } - ens_arr(i, j, k) = 0.5 * l_rho * (vx - uy) * (vx - uy); + amrex::Real l_rho = rho; + if (incomp == 0) { + l_rho = rho_arr(i, j, k); + } + // Define interpolation lambda + auto onesided = []( + const amrex::Real& v0, const amrex::Real& v1, + const amrex::Real& v2) -> amrex::Real { + return c0 * v0 + c1 * v1 + c2 * v2; + }; + + amrex::Real vx = 0.0; + amrex::Real uy = 0.0; +#if (AMREX_SPACEDIM == 2) + // Need to check if there are covered cells in neighbours -- + // -- if so, use one-sided difference computation (but still + // quadratic) + if (!flag_fab(i, j, k).isConnected(1, 0, 0)) { + vx = -onesided( + dat_arr(i, j, k, 1), dat_arr(i - 1, j, k, 1), + dat_arr(i - 2, j, k, 1)) * + idx; + } else if (!flag_fab(i, j, k).isConnected(-1, 0, 0)) { + vx = onesided( + dat_arr(i, j, k, 1), dat_arr(i + 1, j, k, 1), + dat_arr(i + 2, j, k, 1)) * + idx; + } else { + vx = + 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; + } + // Do the same in y-direction + if (!flag_fab(i, j, k).isConnected(0, 1, 0)) { + uy = -onesided( + dat_arr(i, j, k, 0), dat_arr(i, j - 1, k, 0), + dat_arr(i, j - 2, k, 0)) * + idy; + } else if (!flag_fab(i, j, k).isConnected(0, -1, 0)) { + uy = onesided( + dat_arr(i, j, k, 0), dat_arr(i, j + 1, k, 0), + dat_arr(i, j + 2, k, 0)) * + idy; + } else { + uy = + 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; + } + ens_arr(i, j, k) = 0.5 * l_rho * (vx - uy) * (vx - uy); #elif (AMREX_SPACEDIM == 3) amrex::Real wx = 0.0; @@ -1148,24 +1227,30 @@ pelelmex_derenstrophy( ((wy - vz) * (wy - vz) + (uz - wx) * (uz - wx) + (vx - uy) * (vx - uy)); #endif - } - }); + } + }); } else #endif { const auto incomp = a_pelelm->m_incompressible; const auto rho = a_pelelm->m_rho; - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::Real l_rho = rho; - if (incomp == 0) { - l_rho = rho_arr(i, j, k); - } + amrex::ParallelFor( + bx, [rho_arr, dat_arr, rho, incomp, ens_arr, idx, idy +#if (AMREX_SPACEDIM == 3) + , + idz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::Real l_rho = rho; + if (incomp == 0) { + l_rho = rho_arr(i, j, k); + } #if (AMREX_SPACEDIM == 2) - amrex::Real vx = - 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; - amrex::Real uy = - 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; - ens_arr(i, j, k) = 0.5 * l_rho * (vx - uy) * (vx - uy); + amrex::Real vx = + 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; + amrex::Real uy = + 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; + ens_arr(i, j, k) = 0.5 * l_rho * (vx - uy) * (vx - uy); #elif (AMREX_SPACEDIM == 3) amrex::Real vx = @@ -1187,7 +1272,7 @@ pelelmex_derenstrophy( ((wy - vz) * (wy - vz) + (uz - wx) * (uz - wx) + (vx - uy) * (vx - uy)); #endif - }); + }); } } @@ -1230,14 +1315,16 @@ pelelmex_dermixfrac( fact_Bilger[n] = a_pelelm->spec_Bilger_fact[n]; } - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::Real rho_inv = 1.0 / density(i, j, k); - mixt_frac(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; ++n) { - mixt_frac(i, j, k) += (rhoY(i, j, k, n) * fact_Bilger[n]) * rho_inv; - } - mixt_frac(i, j, k) = (mixt_frac(i, j, k) - Zox_lcl) * denom_inv; - }); + amrex::ParallelFor( + bx, [density, mixt_frac, rhoY, Zox_lcl, denom_inv, + fact_Bilger] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + const amrex::Real rho_inv = 1.0 / density(i, j, k); + mixt_frac(i, j, k) = 0.0; + for (int n = 0; n < NUM_SPECIES; ++n) { + mixt_frac(i, j, k) += (rhoY(i, j, k, n) * fact_Bilger[n]) * rho_inv; + } + mixt_frac(i, j, k) = (mixt_frac(i, j, k) - Zox_lcl) * denom_inv; + }); } // @@ -1273,28 +1360,30 @@ pelelmex_derprogvar( auto const temp = statefab.array(TEMP); auto prog_var = derfab.array(dcomp); - amrex::Real C0_lcl = a_pelelm->m_C0; - amrex::Real C1_lcl = a_pelelm->m_C1; - amrex::Real denom_inv = 1.0 / (C1_lcl - C0_lcl); + const amrex::Real C0_lcl = a_pelelm->m_C0; + const amrex::Real C1_lcl = a_pelelm->m_C1; + const amrex::Real denom_inv = 1.0 / (C1_lcl - C0_lcl); amrex::GpuArray Cweights; for (int n = 0; n < NUM_SPECIES + 1; ++n) { Cweights[n] = a_pelelm->m_Cweights[n]; } const auto revert = a_pelelm->m_Crevert; - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::Real rho_inv = 1.0 / density(i, j, k); - prog_var(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; ++n) { - prog_var(i, j, k) += (rhoY(i, j, k, n) * Cweights[n]) * rho_inv; - } - prog_var(i, j, k) += temp(i, j, k) * Cweights[NUM_SPECIES]; - if (revert != 0) { - prog_var(i, j, k) = 1.0 - (prog_var(i, j, k) - C0_lcl) * denom_inv; - } else { - prog_var(i, j, k) = (prog_var(i, j, k) - C0_lcl) * denom_inv; - } - }); + amrex::ParallelFor( + bx, [density, prog_var, rhoY, Cweights, denom_inv, C0_lcl, temp, + revert] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::Real rho_inv = 1.0 / density(i, j, k); + prog_var(i, j, k) = 0.0; + for (int n = 0; n < NUM_SPECIES; ++n) { + prog_var(i, j, k) += (rhoY(i, j, k, n) * Cweights[n]) * rho_inv; + } + prog_var(i, j, k) += temp(i, j, k) * Cweights[NUM_SPECIES]; + if (revert != 0) { + prog_var(i, j, k) = 1.0 - (prog_var(i, j, k) - C0_lcl) * denom_inv; + } else { + prog_var(i, j, k) = (prog_var(i, j, k) - C0_lcl) * denom_inv; + } + }); } // @@ -1327,9 +1416,11 @@ pelelmex_dervisc( auto const& T = statefab.array(TEMP); auto der = derfab.array(dcomp); auto const* ltransparm = a_pelelm->trans_parms.device_parm(); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - getVelViscosity(i, j, k, rhoY, T, der, ltransparm); - }); + amrex::ParallelFor( + bx, [rhoY, T, der, + ltransparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + getVelViscosity(i, j, k, rhoY, T, der, ltransparm); + }); } } @@ -1376,11 +1467,14 @@ pelelmex_derdiffc( : dummies.array(2); // dummy for no soret amrex::Real LeInv = a_pelelm->m_Lewis_inv; amrex::Real PrInv = a_pelelm->m_Prandtl_inv; - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - getTransportCoeff( - i, j, k, do_fixed_Le, do_fixed_Pr, do_soret, LeInv, PrInv, rhoY, T, rhoD, - rhotheta, lambda, mu, ltransparm, leosparm); - }); + amrex::ParallelFor( + bx, [do_fixed_Le, do_fixed_Pr, do_soret, LeInv, PrInv, rhoY, T, rhoD, + rhotheta, lambda, mu, ltransparm, + leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + getTransportCoeff( + i, j, k, do_fixed_Le, do_fixed_Pr, do_soret, LeInv, PrInv, rhoY, T, + rhoD, rhotheta, lambda, mu, ltransparm, leosparm); + }); } // @@ -1419,11 +1513,14 @@ pelelmex_derlambda( auto const* leosparm = a_pelelm->eos_parms.device_parm(); amrex::Real LeInv = a_pelelm->m_Lewis_inv; amrex::Real PrInv = a_pelelm->m_Prandtl_inv; - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - getTransportCoeff( - i, j, k, do_fixed_Le, do_fixed_Pr, do_soret, LeInv, PrInv, rhoY, T, rhoD, - rhotheta, lambda, mu, ltransparm, leosparm); - }); + amrex::ParallelFor( + bx, [do_fixed_Le, do_fixed_Pr, do_soret, LeInv, PrInv, rhoY, T, rhoD, + rhotheta, lambda, mu, ltransparm, + leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + getTransportCoeff( + i, j, k, do_fixed_Le, do_fixed_Pr, do_soret, LeInv, PrInv, rhoY, T, + rhoD, rhotheta, lambda, mu, ltransparm, leosparm); + }); } // @@ -1447,9 +1544,10 @@ pelelmex_derdmap( AMREX_ASSERT(derfab.box().contains(bx)); auto der = derfab.array(dcomp); const int myrank = amrex::ParallelDescriptor::MyProc(); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - der(i, j, k) = myrank; - }); + amrex::ParallelFor( + bx, [der, myrank] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + der(i, j, k) = myrank; + }); } // @@ -1528,18 +1626,20 @@ pelelmex_dermaniout( auto const in_spec = statefab.array(FIRSTSPEC); auto der = derfab.array(dcomp); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::Real rho, rhoinv, maniparm[NUM_SPECIES]; - pele::physics::PhysicsType::eos_type::RY2RRinvY( - in_spec.cellData(i, j, k), rho, rhoinv, maniparm); - pele::physics::BlackBoxFunctionFactory< - pele::physics::eos::ManifoldFunctionType> - manfunc{d_manf_data}; - - // TODO: use get_all_values instead - for (int n = 0; n < nmanivar; ++n) { - manfunc.get_func()->get_value(n, maniparm, der(i, j, k, n)); - } - }); + amrex::ParallelFor( + bx, [in_spec, der, d_manf_data, + nmanivar] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::Real rho, rhoinv, maniparm[NUM_SPECIES]; + pele::physics::PhysicsType::eos_type::RY2RRinvY( + in_spec.cellData(i, j, k), rho, rhoinv, maniparm); + pele::physics::BlackBoxFunctionFactory< + pele::physics::eos::ManifoldFunctionType> + manfunc{d_manf_data}; + + // TODO: use get_all_values instead + for (int n = 0; n < nmanivar; ++n) { + manfunc.get_func()->get_value(n, maniparm, der(i, j, k, n)); + } + }); } #endif diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index a14dc6118..30f50dd5b 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -434,7 +434,9 @@ PeleLM::correctIsothermalBoundary( auto const& boundary_ar = a_spec_boundary[lev]->array(mfi); const auto use_wbar = m_use_wbar; amrex::ParallelFor( - ebx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ebx, [bc_lo, bc_hi, idim, need_explicit_fluxes, edomain, flux_soret, + rhoD_ec, flux_wbar, boundary_ar, + use_wbar] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { int idx[3] = {i, j, k}; const bool on_lo = (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || @@ -818,9 +820,12 @@ PeleLM::addWbarTerm( // \overline{W} with beta_m = \rho * D_m * overline(W) / W_k below // need to divide by \overline(W) const auto* eosparm = leosparm; + auto eos = pele::physics::PhysicsType::eos(eosparm); + amrex::ParallelFor( - ebx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - auto eos = pele::physics::PhysicsType::eos(eosparm); + ebx, + [eos, rhoY, gradWbar_ar, beta_ar, spFlux_ar, spwbarFlux_ar, + need_wbar_fluxes] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Get Wbar from rhoYs amrex::Real rho = 0.0; for (int n = 0; n < NUM_SPECIES; ++n) { @@ -1007,14 +1012,15 @@ PeleLM::computeSpeciesEnthalpyFlux( auto const& flag = flagfab.const_array(); if (flagfab.getType(gbx) == amrex::FabType::covered) { // Covered boxes amrex::ParallelFor( - gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + gbx, [Hi_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { Hi_arr(i, j, k) = 0.0; }); } else if ( flagfab.getType(gbx) != amrex::FabType::regular) { // EB containing // boxes amrex::ParallelFor( - gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + gbx, [Hi_arr, flag, Temp_arr, + leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (flag(i, j, k).isCovered()) { Hi_arr(i, j, k) = 0.0; } else { @@ -1025,7 +1031,8 @@ PeleLM::computeSpeciesEnthalpyFlux( #endif { amrex::ParallelFor( - gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + gbx, [Temp_arr, Hi_arr, + leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { getHGivenT(i, j, k, Temp_arr, Hi_arr, leosparm); }); } @@ -1053,7 +1060,8 @@ PeleLM::computeSpeciesEnthalpyFlux( a_fluxes[lev][idim]->array(mfi, NUM_SPECIES + 1); auto const& enth_ar = Enth_ec[idim].const_array(mfi); amrex::ParallelFor( - ebox, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ebox, [enthflux_ar, spflux_ar, + enth_ar] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { enthflux_ar(i, j, k) = 0.0; for (int n = 0; n < NUM_SPECIES; ++n) { enthflux_ar(i, j, k) += @@ -1246,7 +1254,8 @@ PeleLM::differentialDiffusionUpdate( diffData->wbar_fluxes[lev][idim].const_array(mfi); amrex::ParallelFor( ebx, NUM_SPECIES, - [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + [flux_spec, + flux_wbar] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { flux_spec(i, j, k, n) += flux_wbar(i, j, k, n); }); } @@ -1269,7 +1278,8 @@ PeleLM::differentialDiffusionUpdate( diffData->soret_fluxes[lev][idim].const_array(mfi); amrex::ParallelFor( ebx, NUM_SPECIES, - [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + [flux_spec, + flux_soret] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { flux_spec(i, j, k, n) += flux_soret(i, j, k, n); }); } @@ -1710,8 +1720,8 @@ PeleLM::deltaTIter_update( auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); auto const& sma = ldata_p->state.arrays(); amrex::ParallelFor( - ldata_p->state, - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + ldata_p->state, [sma, leosparm] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { getRHmixGivenTY( i, j, k, amrex::Array4(sma[box_no], DENSITY), amrex::Array4(sma[box_no], FIRSTSPEC), diff --git a/Source/PeleLMeX_EB.cpp b/Source/PeleLMeX_EB.cpp index 56f06ff63..796f4b8cf 100644 --- a/Source/PeleLMeX_EB.cpp +++ b/Source/PeleLMeX_EB.cpp @@ -120,7 +120,7 @@ PeleLM::redistributeAofS( if (m_adv_redist_type == "FluxRedist") { amrex::ParallelFor( amrex::Box(scratch), - [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + [scratch] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { scratch(i, j, k) = 1.; }); } @@ -132,7 +132,9 @@ PeleLM::redistributeAofS( } else { // Move data to AofS for regular bx amrex::ParallelFor( - bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + bx, ncomp, + [aofs_ar, + divT_ar] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { aofs_ar(i, j, k, n) = divT_ar(i, j, k, n); }); } @@ -256,7 +258,7 @@ PeleLM::redistributeDiff( if (m_diff_redist_type == "FluxRedist") { amrex::ParallelFor( amrex::Box(scratch), - [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + [scratch] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { scratch(i, j, k) = 1.; }); } @@ -268,7 +270,9 @@ PeleLM::redistributeDiff( } else { // Move data to AofS for regular bx amrex::ParallelFor( - bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + bx, ncomp, + [diff_ar, + divT_ar] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { diff_ar(i, j, k, n) = divT_ar(i, j, k, n); }); } @@ -540,21 +544,31 @@ PeleLM::getEBState( , const auto& ebfc_y = ebfact.getFaceCent()[1]->const_array(a_mfi); , const auto& ebfc_z = ebfact.getFaceCent()[2]->const_array(a_mfi);); const auto& ebnorm = ebfact.getBndryNormal().const_array(a_mfi); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - // Regular/covered cells -> 0.0 - if (flag(i, j, k).isCovered() || flag(i, j, k).isRegular()) { - for (int n = 0; n < ncomp; ++n) { - ebscal_arr(i, j, k, n) = 0.0; + amrex::ParallelFor( + bx, [flag, ebscal_arr, state, ebnorm, ncomp, EBfiller, first_comp, + geomdata, time, ebfc_x, ebfc_y +#if (AMREX_SPACEDIM == 3) + , + ebfc_z +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + // Regular/covered cells -> 0.0 + if (flag(i, j, k).isCovered() || flag(i, j, k).isRegular()) { + for (int n = 0; n < ncomp; ++n) { + ebscal_arr(i, j, k, n) = 0.0; + } + } else { // cut-cells + EBfiller( + i, j, k, state, ebscal_arr, first_comp, ncomp, + AMREX_D_DECL(ebfc_x, ebfc_y, ebfc_z), ebnorm, geomdata, time); } - } else { // cut-cells - EBfiller( - i, j, k, state, ebscal_arr, first_comp, ncomp, - AMREX_D_DECL(ebfc_x, ebfc_y, ebfc_z), ebnorm, geomdata, time); - } - }); + }); } else { - AMREX_PARALLEL_FOR_4D( - bx, ncomp, i, j, k, n, { ebscal_arr(i, j, k, n) = 0.0; }); + amrex::ParallelFor( + bx, ncomp, + [ebscal_arr] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + ebscal_arr(i, j, k, n) = 0.0; + }); } return r; @@ -611,7 +625,13 @@ PeleLM::getEBState( , const auto& ebfc_z = faceCentroid[2]->array(mfi);); const auto& ebnorm = ebfact.getBndryNormal().const_array(mfi); amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [flag, ebState, state, EBfiller, stateComp, nComp, ebnorm, geomdata, + time, ebfc_x, ebfc_y +#if (AMREX_SPACEDIM == 3) + , + ebfc_z +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Regular/covered cells -> 0.0 if (flag(i, j, k).isCovered() || flag(i, j, k).isRegular()) { for (int n = 0; n < nComp; ++n) { @@ -673,7 +693,13 @@ PeleLM::getEBDiff( , const auto& ebfc_y = faceCentroid[1]->array(mfi); , const auto& ebfc_z = faceCentroid[2]->array(mfi);); amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, + [flag, ebdiff, diff_cc, EBTypfiller, geomdata, lprobparm, ebfc_x, ebfc_y +#if (AMREX_SPACEDIM == 3) + , + ebfc_z +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Regular/covered cells -> 0.0 if (flag(i, j, k).isCovered() || flag(i, j, k).isRegular()) { ebdiff(i, j, k) = 0.0; @@ -743,18 +769,23 @@ PeleLM::correct_vel_small_cells( // This FAB has cut cells -- we define the centroid value in terms of // the MAC velocities onfaces amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [vfrac_fab, ccvel_fab, umac_fab, apx_fab, vmac_fab, apy_fab +#if (AMREX_SPACEDIM == 3) + , + wmac_fab, apz_fab +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (vfrac_fab(i, j, k) > 0.0 && vfrac_fab(i, j, k) < 5.e-3) { AMREX_D_TERM( - amrex::Real u_avg = + const amrex::Real u_avg = (apx_fab(i, j, k) * umac_fab(i, j, k) + apx_fab(i + 1, j, k) * umac_fab(i + 1, j, k)) / (apx_fab(i, j, k) + apx_fab(i + 1, j, k)); - , amrex::Real v_avg = + , const amrex::Real v_avg = (apy_fab(i, j, k) * vmac_fab(i, j, k) + apy_fab(i, j + 1, k) * vmac_fab(i, j + 1, k)) / (apy_fab(i, j, k) + apy_fab(i, j + 1, k)); - , amrex::Real w_avg = + , const amrex::Real w_avg = (apz_fab(i, j, k) * wmac_fab(i, j, k) + apz_fab(i, j, k + 1) * wmac_fab(i, j, k + 1)) / (apz_fab(i, j, k) + apz_fab(i, j, k + 1));); diff --git a/Source/PeleLMeX_Eos.cpp b/Source/PeleLMeX_Eos.cpp index 5242317b4..acee42d10 100644 --- a/Source/PeleLMeX_Eos.cpp +++ b/Source/PeleLMeX_Eos.cpp @@ -26,7 +26,7 @@ PeleLM::setThermoPress(const int lev, const TimeStamp a_time) amrex::ParallelFor( ldata_p->state, - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [sma, leosparm] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { getPGivenRTY( i, j, k, amrex::Array4(sma[box_no], DENSITY), amrex::Array4(sma[box_no], FIRSTSPEC), @@ -126,14 +126,16 @@ PeleLM::calcDivU( #ifdef AMREX_USE_EB if (flagfab.getType(bx) == amrex::FabType::covered) { // Covered boxes amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [divu] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { divu(i, j, k) = 0.0; }); } else if (flagfab.getType(bx) != amrex::FabType::regular) { // EB // containing // boxes amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, + [flag, divu, rhoY, T, SpecD, Fourier, DiffDiff, r, extRhoY, extRhoH, + use_react, leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (flag(i, j, k).isCovered()) { divu(i, j, k) = 0.0; } else { @@ -146,7 +148,9 @@ PeleLM::calcDivU( #endif { amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, + [divu, rhoY, T, SpecD, Fourier, DiffDiff, r, extRhoY, extRhoH, + use_react, leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { compute_divu( i, j, k, rhoY, T, SpecD, Fourier, DiffDiff, r, extRhoY, extRhoH, divu, use_react, leosparm); @@ -189,7 +193,7 @@ PeleLM::setRhoToSumRhoY(const int lev, const TimeStamp a_time) amrex::ParallelFor( ldata_p->state, - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [sma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { pele::physics::PhysicsType::eos_type::RY2R( sma[box_no].cellData(i, j, k), sma[box_no](i, j, k, DENSITY), FIRSTSPEC); @@ -222,7 +226,7 @@ PeleLM::setTemperature(const int lev, const TimeStamp a_time) amrex::ParallelFor( ldata_p->state, - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [sma, leosparm] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { getTfromHY( i, j, k, amrex::Array4(sma[box_no], DENSITY), amrex::Array4(sma[box_no], FIRSTSPEC), @@ -265,7 +269,8 @@ PeleLM::calc_dPdt( const auto dt = m_dt; const auto dpdt_fac = m_dpdtFactor; amrex::ParallelFor( - *a_dPdt, [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + *a_dPdt, [dPdtma, sma, p_amb, dt, dpdt_fac] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { auto dPdta = dPdtma[box_no]; auto sa = sma[box_no]; dPdta(i, j, k) = @@ -295,7 +300,8 @@ PeleLM::adjustPandDivU(std::unique_ptr& advData) const auto pNew = m_pNew; amrex::ParallelFor( *ThetaHalft[lev], - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [tma, sma_o, sma_n, pOld, pNew, + leosparm] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { auto theta = tma[box_no]; amrex::Real gammaInv_o = getGammaInv( i, j, k, amrex::Array4(sma_o[box_no], FIRSTSPEC), @@ -338,8 +344,8 @@ PeleLM::adjustPandDivU(std::unique_ptr& advData) auto const& tma = ThetaHalft[lev]->arrays(); auto const& uma = advData->mac_divu[lev].arrays(); amrex::ParallelFor( - *ThetaHalft[lev], - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + *ThetaHalft[lev], [uma, Sbar, Thetabar, divu_vol, tma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { auto theta = tma[box_no]; uma[box_no](i, j, k) -= (theta(i, j, k) * Sbar / Thetabar - diff --git a/Source/PeleLMeX_FlowController.cpp b/Source/PeleLMeX_FlowController.cpp index 0935aeb91..e93ebc055 100644 --- a/Source/PeleLMeX_FlowController.cpp +++ b/Source/PeleLMeX_FlowController.cpp @@ -81,7 +81,9 @@ PeleLM::initActiveControl() amrex::Box dumbx({AMREX_D_DECL(0, 0, 0)}, {AMREX_D_DECL(0, 0, 0)}); amrex::ParallelFor( - dumbx, [=] AMREX_GPU_DEVICE(int /*i*/, int /*j*/, int /*k*/) noexcept { + dumbx, + [x, fake_state, s_ext_d, ctrl_flameDir_l, time_l, geomdata, lprobparm, + lpmfdata] AMREX_GPU_DEVICE(int /*i*/, int /*j*/, int /*k*/) noexcept { const auto s_in = fake_state.cellData(0, 0, 0); ProblemSpecificFunctions::bcnormal( x, s_in, s_ext_d, ctrl_flameDir_l, 1, time_l, geomdata, *lprobparm, @@ -328,7 +330,7 @@ PeleLM::getActiveControlLowT(amrex::Real& a_coft) if (lev != finest_level) { lowT = amrex::ReduceMin( ldata_p->state, *m_coveredMask[lev], 0, - [=] AMREX_GPU_HOST_DEVICE( + [geomdata, AC_Tcross, AC_FlameDir] AMREX_GPU_HOST_DEVICE( amrex::Box const& bx, amrex::Array4 const& T_arr, amrex::Array4 const& covered_arr) -> amrex::Real { const auto lo = amrex::lbound(bx); @@ -368,7 +370,7 @@ PeleLM::getActiveControlLowT(amrex::Real& a_coft) } else { lowT = amrex::ReduceMin( ldata_p->state, 0, - [=] AMREX_GPU_HOST_DEVICE( + [geomdata, AC_Tcross, AC_FlameDir] AMREX_GPU_HOST_DEVICE( amrex::Box const& bx, amrex::Array4 const& T_arr) -> amrex::Real { const auto lo = amrex::lbound(bx); diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index ae0edc870..269e9e8f8 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -288,8 +288,13 @@ PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) const amrex::Real inv_l_scale2 = 1.0 / (l_scale * l_scale); amrex::ParallelFor( - *m_extSource[lev], - [=] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept { + *m_extSource[lev], [extma, statema, n, C_chi, ScInv, inv_l_scale2, + mut_arr_x, gx, mut_arr_y, gy +#if (AMREX_SPACEDIM == 3) + , + mut_arr_z, gz +#endif + ] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept { // Subfilter Scalar Dissipation: Linear Relaxation model // rho chi_sgs = C_chi * mu_t / Delta^2 * Variance const amrex::Real mu_t = @@ -326,7 +331,7 @@ PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) } } } - Gpu::streamSynchronize(); + amrex::Gpu::streamSynchronize(); } } #endif diff --git a/Source/PeleLMeX_Init.cpp b/Source/PeleLMeX_Init.cpp index e27667f86..8f975696a 100644 --- a/Source/PeleLMeX_Init.cpp +++ b/Source/PeleLMeX_Init.cpp @@ -148,25 +148,22 @@ PeleLM::MakeNewLevelFromScratch( amrex::MFInfo(), EBFactory(0)); FillSignedDistance(signDist, true); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(*m_signedDist0, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.growntilebox(); - auto const& sd_cc = m_signedDist0->array(mfi); - auto const& sd_nd = signDist.const_array(mfi); - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::Real fac = AMREX_D_PICK(0.5, 0.25, 0.125); - sd_cc(i, j, k) = AMREX_D_TERM( - sd_nd(i, j, k) + sd_nd(i + 1, j, k), - +sd_nd(i, j + 1, k) + sd_nd(i + 1, j + 1, k), - +sd_nd(i, j, k + 1) + sd_nd(i + 1, j, k + 1) + - sd_nd(i, j + 1, k + 1) + sd_nd(i + 1, j + 1, k + 1)); - sd_cc(i, j, k) *= fac; - }); - } + constexpr amrex::Real fac = AMREX_D_PICK(0.5, 0.25, 0.125); + auto const& sd_cc_ma = m_signedDist0->arrays(); + auto const& sd_nd_ma = signDist.const_arrays(); + amrex::ParallelFor( + *m_signedDist0, m_signedDist0->nGrowVect(), + [sd_cc_ma, + sd_nd_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + sd_cc_ma[box_no](i, j, k) = AMREX_D_TERM( + sd_nd_ma[box_no](i, j, k) + sd_nd_ma[box_no](i + 1, j, k), + +sd_nd_ma[box_no](i, j + 1, k) + sd_nd_ma[box_no](i + 1, j + 1, k), + +sd_nd_ma[box_no](i, j, k + 1) + sd_nd_ma[box_no](i + 1, j, k + 1) + + sd_nd_ma[box_no](i, j + 1, k + 1) + + sd_nd_ma[box_no](i + 1, j + 1, k + 1)); + sd_cc_ma[box_no](i, j, k) *= fac; + }); + amrex::Gpu::streamSynchronize(); m_signedDist0->FillBoundary(geom[0].periodicity()); extendSignedDistance(m_signedDist0.get(), extentFactor); } diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 7ee45c580..49adeaf58 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -456,8 +456,12 @@ PeleLM::WritePlotFile() m_leveldata_old[lev]->visc_turb_fc[2].const_arrays();) // interpolate turbulent viscosity from faces to centers amrex::ParallelFor( - mf_plt[lev], - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + mf_plt[lev], [plot_arr, cnt, mut_arr_x, mut_arr_y +#if (AMREX_SPACEDIM == 3) + , + mut_arr_z +#endif + ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { plot_arr[box_no](i, j, k, cnt) = fact * (AMREX_D_TERM( @@ -1187,11 +1191,13 @@ PeleLM::addLevelVelocityDataFromPlt(int a_lev, const std::string& a_velPltFile) amrex::FArrayBox DummyFab(bx, 1); auto const& state_arr = ldata_p->state.array(mfi); auto const& tmpVel_arr = tmpVel.array(mfi); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; n++) { - state_arr(i, j, k, XVEL + n) += tmpVel_arr(i, j, k, n); - } - }); + amrex::ParallelFor( + bx, + [state_arr, tmpVel_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; n++) { + state_arr(i, j, k, XVEL + n) += tmpVel_arr(i, j, k, n); + } + }); } } diff --git a/Source/PeleLMeX_ProblemSpecificFunctions.H b/Source/PeleLMeX_ProblemSpecificFunctions.H index c009f264d..c40c1693f 100644 --- a/Source/PeleLMeX_ProblemSpecificFunctions.H +++ b/Source/PeleLMeX_ProblemSpecificFunctions.H @@ -219,11 +219,11 @@ struct DefaultProblemSpecificFunctions * auto const& state_old_arr = state_old.const_arrays(); * ParallelFor( * *ext_src, - * [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - * for (int n = 0; n < NUM_ODE; ++n) { - * amrex::Real B_n = state_old_arr[box_no](i, j, k, FIRSTODE + n); - * amrex::Real src = -1.0 * pow(10.0, n + 1) * B_n; - * ext_src_arr[box_no](i, j, k, FIRSTODE + n) += src; + * [ext_src_arr] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) + * noexcept { for (int n = 0; n < NUM_ODE; ++n) { amrex::Real B_n = + * state_old_arr[box_no](i, j, k, FIRSTODE + n); amrex::Real src = -1.0 * + * pow(10.0, n + 1) * B_n; ext_src_arr[box_no](i, j, k, FIRSTODE + n) += + * src; * } * }); * amrex::Gpu::streamSynchronize(); diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index be1d3ce14..d6294cdd8 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -344,25 +344,27 @@ PeleLM::velocityProjection( rhs_cc.emplace_back( grids[lev], dmap[lev], 1, ldataOld_p->divu.nGrow(), amrex::MFInfo(), *m_factory[lev]); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(rhs_cc[lev], amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& gbx = mfi.growntilebox(); - const auto& divu_o = ldataOld_p->divu.const_array(mfi); - const auto& divu_n = ldataNew_p->divu.const_array(mfi); - const auto& rhs = rhs_cc[lev].array(mfi); - const auto is_closed_ch = m_closed_chamber; + + auto const& divu_o_ma = ldataOld_p->divu.const_arrays(); + auto const& divu_n_ma = ldataNew_p->divu.const_arrays(); + auto const& rhs_ma = rhs_cc[lev].arrays(); + + amrex::ParallelFor( + rhs_cc[lev], rhs_cc[lev].nGrowVect(), + [divu_o_ma, divu_n_ma, + rhs_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + rhs_ma[box_no](i, j, k) = + -(divu_n_ma[box_no](i, j, k) - divu_o_ma[box_no](i, j, k)); + }); + if (m_closed_chamber != 0) { amrex::ParallelFor( - gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - rhs(i, j, k) = -(divu_n(i, j, k) - divu_o(i, j, k)); - if (is_closed_ch != 0) { - rhs(i, j, k) += - SbarNew - SbarOld; // subtract the mean, but rhs's already - - } + rhs_cc[lev], rhs_cc[lev].nGrowVect(), + [rhs_ma, SbarNew, SbarOld] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + rhs_ma[box_no](i, j, k) += SbarNew - SbarOld; }); } + amrex::Gpu::streamSynchronize(); } #ifdef AMREX_USE_EB EB_set_covered(rhs_cc[lev], 0.0); @@ -380,8 +382,8 @@ PeleLM::velocityProjection( incremental, a_dt); #if AMREX_SPACEDIM == 2 + // Unscaling New vel before adding back old one for (int lev = 0; lev <= finest_level; ++lev) { - // Unscaling New vel before adding back old one if (geom[lev].IsRZ()) { unscaleProj_RZ(lev, *vel[lev]); } @@ -508,21 +510,25 @@ PeleLM::doNodalProject( if (incremental != 0) { amrex::ParallelFor( tbx, AMREX_SPACEDIM, - [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + [gp_lev_arr, + gp_proj_arr] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { gp_lev_arr(i, j, k, n) += gp_proj_arr(i, j, k, n); }); amrex::ParallelFor( - nbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + nbx, [p_lev_arr, + p_proj_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { p_lev_arr(i, j, k) += p_proj_arr(i, j, k); }); } else { amrex::ParallelFor( tbx, AMREX_SPACEDIM, - [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + [gp_lev_arr, + gp_proj_arr] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { gp_lev_arr(i, j, k, n) = gp_proj_arr(i, j, k, n); }); amrex::ParallelFor( - nbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + nbx, [p_lev_arr, + p_proj_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { p_lev_arr(i, j, k) = p_proj_arr(i, j, k); }); } diff --git a/Source/PeleLMeX_Reactions.cpp b/Source/PeleLMeX_Reactions.cpp index 99f63620e..f1df5fa50 100644 --- a/Source/PeleLMeX_Reactions.cpp +++ b/Source/PeleLMeX_Reactions.cpp @@ -86,10 +86,12 @@ PeleLM::advanceChemistry( auto eos = pele::physics::PhysicsType::eos(&eos_parms.host_parm()); amrex::Real mwt[NUM_SPECIES] = {0.0}; eos.molecular_weight(mwt); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - rhoYe_n(i, j, k) = nE_o(i, j, k) / Na * mwt[E_ID] * 1.0e-6; - FrhoYe(i, j, k) = FnE(i, j, k) / Na * mwt[E_ID] * 1.0e-6; - }); + amrex::ParallelFor( + bx, [rhoYe_n, nE_o, mwt, FrhoYe, + FnE] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + rhoYe_n(i, j, k) = nE_o(i, j, k) / Na * mwt[E_ID] * 1.0e-6; + FrhoYe(i, j, k) = FnE(i, j, k) / Na * mwt[E_ID] * 1.0e-6; + }); #endif amrex::Real dt_incr = a_dt; @@ -121,11 +123,13 @@ PeleLM::advanceChemistry( auto const& nE_n = ldataNew_p->state.array(mfi, NE); amrex::Real invmwt[NUM_SPECIES] = {0.0}; eos.inv_molecular_weight(invmwt); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - nE_n(i, j, k) = rhoYe_n(i, j, k) * Na * invmwt[E_ID] * 1.0e3; - rhoYe_n(i, j, k) = 0.0; - extF_rhoY(i, j, k, E_ID) = 0.0; - }); + amrex::ParallelFor( + bx, [nE_n, rhoYe_n, invmwt, + extF_rhoY] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + nE_n(i, j, k) = rhoYe_n(i, j, k) * Na * invmwt[E_ID] * 1.0e3; + rhoYe_n(i, j, k) = 0.0; + extF_rhoY(i, j, k, E_ID) = 0.0; + }); #endif #ifdef AMREX_USE_GPU @@ -147,7 +151,8 @@ PeleLM::advanceChemistry( amrex::Real dt_inv = 1.0 / a_dt; amrex::ParallelFor( bx, NUM_SPECIES, - [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + [rhoYdot, rhoY_o, rhoY_n, dt_inv, + extF_rhoY] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { rhoYdot(i, j, k, n) = -(rhoY_o(i, j, k, n) - rhoY_n(i, j, k, n)) * dt_inv - extF_rhoY(i, j, k, n); @@ -158,9 +163,12 @@ PeleLM::advanceChemistry( auto const& nE_n = ldataNew_p->state.const_array(mfi, NE); auto const& FnE = a_extForcing.const_array(mfi, NUM_SPECIES + 1); auto const& nEdot = ldataR_p->I_R.array(mfi, NUM_SPECIES); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - nEdot(i, j, k) = -(nE_o(i, j, k) - nE_n(i, j, k)) * dt_inv - FnE(i, j, k); - }); + amrex::ParallelFor( + bx, [nEdot, nE_o, nE_n, dt_inv, + FnE] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + nEdot(i, j, k) = + -(nE_o(i, j, k) - nE_n(i, j, k)) * dt_inv - FnE(i, j, k); + }); #endif } } @@ -241,10 +249,12 @@ PeleLM::advanceChemistryBAChem( auto eos = pele::physics::PhysicsType::eos(&eos_parms.host_parm()); amrex::Real mwt[NUM_SPECIES] = {0.0}; eos.molecular_weight(mwt); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - rhoYe_o(i, j, k) = nE_o(i, j, k) / Na * mwt[E_ID] * 1.0e-6; - FrhoYe(i, j, k) = FnE(i, j, k) / Na * mwt[E_ID] * 1.0e-6; - }); + amrex::ParallelFor( + bx, [rhoYe_o, nE_o, mwt, FrhoYe, + FnE] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + rhoYe_o(i, j, k) = nE_o(i, j, k) / Na * mwt[E_ID] * 1.0e-6; + FrhoYe(i, j, k) = FnE(i, j, k) / Na * mwt[E_ID] * 1.0e-6; + }); #endif // Do reaction only on uncovered box @@ -266,7 +276,7 @@ PeleLM::advanceChemistryBAChem( } else { // Just set the function call to 0.0 amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [fcl] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { fcl(i, j, k) = 0.0; }); } @@ -284,10 +294,12 @@ PeleLM::advanceChemistryBAChem( // rhoY_e -> nE and set rhoY_e to zero amrex::Real invmwt[NUM_SPECIES] = {0.0}; eos.inv_molecular_weight(invmwt); - ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - nE_o(i, j, k) = rhoYe_o(i, j, k) * Na * invmwt[E_ID] * 1.0e3; - rhoYe_o(i, j, k) = 0.0; - }); + ParallelFor( + bx, + [nE_o, rhoYe_o, invmwt] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + nE_o(i, j, k) = rhoYe_o(i, j, k) * Na * invmwt[E_ID] * 1.0e3; + rhoYe_o(i, j, k) = 0.0; + }); #endif #ifdef AMREX_USE_GPU @@ -343,12 +355,15 @@ PeleLM::advanceChemistryBAChem( auto const& nE_n = ldataNew_p->state.array(mfi, NE); auto const& FnE = a_extForcing.const_array(mfi, NUM_SPECIES + 1); auto const& nEdot = ldataR_p->I_R.array(mfi, NUM_SPECIES); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - // Pass into leveldata_new - nE_n(i, j, k) = nE_arr(i, j, k); - // Compute I_R - nEdot(i, j, k) = -(nE_o(i, j, k) - nE_n(i, j, k)) * dt_inv - FnE(i, j, k); - }); + amrex::ParallelFor( + bx, [nE_n, nE_arr, nEdot, nE_o, dt_inv, + FnE] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + // Pass into leveldata_new + nE_n(i, j, k) = nE_arr(i, j, k); + // Compute I_R + nEdot(i, j, k) = + -(nE_o(i, j, k) - nE_n(i, j, k)) * dt_inv - FnE(i, j, k); + }); #endif } } @@ -395,14 +410,15 @@ PeleLM::computeInstantaneousReactionRate( if (flagfab.getType(bx) == amrex::FabType::covered) { // Covered boxes amrex::ParallelFor( bx, NUM_SPECIES, - [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + [rhoYdot] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { rhoYdot(i, j, k, n) = 0.0; }); } else if (flagfab.getType(bx) != amrex::FabType::regular) { // EB // containing // boxes amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [rhoYdot, flag, rhoY, rhoH, T, + leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (flag(i, j, k).isCovered()) { for (int n = 0; n < NUM_SPECIES; ++n) { rhoYdot(i, j, k, n) = 0.0; @@ -415,7 +431,8 @@ PeleLM::computeInstantaneousReactionRate( #endif { amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [rhoY, rhoH, T, rhoYdot, + leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { reactionRateRhoY(i, j, k, rhoY, rhoH, T, rhoYdot, leosparm); }); } @@ -482,7 +499,8 @@ PeleLM::getHeatRelease(const int a_lev, amrex::MultiFab* a_HR) auto const& Hi = EnthFab.array(); auto const& HRR = a_HR->array(mfi); amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [T, Hi, leosparm, HRR, + react] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { getHGivenT(i, j, k, T, Hi, leosparm); HRR(i, j, k) = 0.0; for (int n = 0; n < NUM_SPECIES; ++n) { diff --git a/Source/PeleLMeX_Soot.cpp b/Source/PeleLMeX_Soot.cpp index 982faf4f2..a123f100d 100644 --- a/Source/PeleLMeX_Soot.cpp +++ b/Source/PeleLMeX_Soot.cpp @@ -31,10 +31,11 @@ PeleLM::cleanupSootModel() void PeleLM::computeSootSource(const TimeStamp a_timestamp, const amrex::Real a_dt) { - bool pres_term = false; // Do not include change in pressure in energy + constexpr bool pres_term = + false; // Do not include change in pressure in energy for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, a_timestamp); - amrex::Real time = getTime(lev, a_timestamp); + const amrex::Real time = getTime(lev, a_timestamp); #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif @@ -53,29 +54,25 @@ PeleLM::computeSootSource(const TimeStamp a_timestamp, const amrex::Real a_dt) void PeleLM::clipSootMoments() { + SootData* sd = soot_model->getSootData_d(); for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - amrex::Box const& gbx = mfi.tilebox(); - auto const& state_arr = ldata_p->state.array(mfi, FIRSTSOOT); - SootData* sd = soot_model->getSootData_d(); - amrex::ParallelFor( - gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::GpuArray moments; - for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; ++mom) { - moments[mom] = state_arr(i, j, k, mom); - } - sd->momConvClipConv(moments.data()); - for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; ++mom) { - state_arr(i, j, k, mom) = moments[mom]; - } - }); - } + auto const& state_ma = ldata_p->state.arrays(); + amrex::ParallelFor( + ldata_p->state, [state_ma, sd] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + amrex::Array4 state_arr(state_ma[box_no], FIRSTSOOT); + amrex::GpuArray moments; + for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; ++mom) { + moments[mom] = state_arr(i, j, k, mom); + } + sd->momConvClipConv(moments.data()); + for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; ++mom) { + state_arr(i, j, k, mom) = moments[mom]; + } + }); } + amrex::Gpu::streamSynchronize(); } // TODO: This isn't working yet diff --git a/Source/PeleLMeX_Tagging.cpp b/Source/PeleLMeX_Tagging.cpp index e1ace5a1c..de0a187a3 100644 --- a/Source/PeleLMeX_Tagging.cpp +++ b/Source/PeleLMeX_Tagging.cpp @@ -40,11 +40,12 @@ PeleLM::ErrorEst( const auto& bx = mfi.tilebox(); auto tag = tags.array(mfi); auto vfrac = EBFactory(lev).getVolFrac().const_array(mfi); - amrex::ParallelFor(bx, [=] AMREX_GPU_HOST_DEVICE(int i, int j, int k) { - if (vfrac(i, j, k) <= 0.0) { - tag(i, j, k) = amrex::TagBox::CLEAR; - } - }); + amrex::ParallelFor( + bx, [tag, vfrac] AMREX_GPU_HOST_DEVICE(int i, int j, int k) { + if (vfrac(i, j, k) <= 0.0) { + tag(i, j, k) = amrex::TagBox::CLEAR; + } + }); } // Untag cell close to EB @@ -73,11 +74,13 @@ PeleLM::ErrorEst( const auto& bx = mfi.tilebox(); const auto& dist = signDist.const_array(mfi); auto tag = tags.array(mfi); - amrex::ParallelFor(bx, [=] AMREX_GPU_HOST_DEVICE(int i, int j, int k) { - if (dist(i, j, k) < clearTagDist) { - tag(i, j, k) = amrex::TagBox::CLEAR; - } - }); + amrex::ParallelFor( + bx, + [dist, clearTagDist, tag] AMREX_GPU_HOST_DEVICE(int i, int j, int k) { + if (dist(i, j, k) < clearTagDist) { + tag(i, j, k) = amrex::TagBox::CLEAR; + } + }); } } #endif diff --git a/Source/PeleLMeX_Temporals.cpp b/Source/PeleLMeX_Temporals.cpp index bd3b2f4ec..81e57814f 100644 --- a/Source/PeleLMeX_Temporals.cpp +++ b/Source/PeleLMeX_Temporals.cpp @@ -146,8 +146,9 @@ PeleLM::addMassFluxes( amrex::TypeList{}, amrex::TypeList{}, *a_fluxes[idim], amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [fma, ama, idim, faceDomain] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { amrex::Array4 const& flux = fma[box_no]; amrex::Array4 const& area_ar = ama[box_no]; @@ -177,8 +178,9 @@ PeleLM::addMassFluxes( amrex::TypeList{}, amrex::TypeList{}, *a_fluxes[idim], amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [fma, idim, faceDomain, area] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { amrex::Array4 const& flux = fma[box_no]; int idx = (idim == 0) ? i : ((idim == 1) ? j : k); @@ -247,8 +249,9 @@ PeleLM::addUmacFluxes( amrex::TypeList{}, amrex::TypeList{}, advData->umac[lev][idim], amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [fma, ama, idim, faceDomain] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { amrex::Array4 const& flux = fma[box_no]; amrex::Array4 const& area_ar = ama[box_no]; @@ -274,8 +277,9 @@ PeleLM::addUmacFluxes( amrex::TypeList{}, amrex::TypeList{}, advData->umac[lev][idim], amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [fma, idim, faceDomain, area] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { amrex::Array4 const& flux = fma[box_no]; int idx = (idim == 0) ? i : ((idim == 1) ? j : k); @@ -364,8 +368,9 @@ PeleLM::addRhoHFluxes( amrex::TypeList{}, amrex::TypeList{}, *a_fluxes[idim], amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [fma, ama, idim, faceDomain] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { amrex::Array4 const& flux = fma[box_no]; amrex::Array4 const& area_ar = ama[box_no]; @@ -391,8 +396,9 @@ PeleLM::addRhoHFluxes( amrex::TypeList{}, amrex::TypeList{}, *a_fluxes[idim], amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [fma, idim, faceDomain, area] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { amrex::Array4 const& flux = fma[box_no]; int idx = (idim == 0) ? i : ((idim == 1) ? j : k); @@ -466,8 +472,9 @@ PeleLM::addRhoYFluxes( amrex::TypeList{}, amrex::TypeList{}, *a_fluxes[idim], amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [fma, ama, idim, faceDomain, n] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { amrex::Array4 const& flux = fma[box_no]; amrex::Array4 const& area_ar = ama[box_no]; @@ -493,8 +500,9 @@ PeleLM::addRhoYFluxes( amrex::TypeList{}, amrex::TypeList{}, *a_fluxes[idim], amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [fma, idim, faceDomain, area, n] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { amrex::Array4 const& flux = fma[box_no]; int idx = (idim == 0) ? i : ((idim == 1) ? j : k); @@ -597,7 +605,8 @@ PeleLM::addRhoYFluxesPatch( amrex::TypeList{}, amrex::TypeList{}, *a_fluxes[idim], amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept + [fma, bpdevice, faceDomain, idim, prob_lo, dx, m, + area] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept -> amrex::GpuTuple { amrex::Array4 const& flux = fma[box_no]; int idx = diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index 8f2e58967..f7e4656af 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -93,8 +93,9 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) auto const& mut_arr = ldata_p->visc_turb_fc[idim].arrays(); const amrex::Real vol = AMREX_D_TERM( geom[lev].CellSize(0), *geom[lev].CellSize(1), *geom[lev].CellSize(2)); + const amrex::Real l_scale = - (AMREX_SPACEDIM == 2) ? std::sqrt(vol) : std::cbrt(vol); + AMREX_D_PICK(vol, std::sqrt(vol), std::cbrt(vol)); #ifdef AMREX_USE_EB auto const& ebfact = EBFactory(lev); @@ -105,44 +106,29 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) m_les_cs_smag * m_les_cs_smag * l_scale * l_scale; amrex::ParallelFor( ldata_p->visc_turb_fc[idim], ldata_p->visc_turb_fc[idim].nGrowVect(), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [prefact, idim, velgrad_arr, dens_arr, mut_arr +#ifdef AMREX_USE_EB + , + vfrac +#endif + ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { getTurbViscSmagorinsky( i, j, k, prefact, amrex::Array4(velgrad_arr[box_no]), amrex::Array4(dens_arr[box_no]), amrex::Array4(mut_arr[box_no])); #ifdef AMREX_USE_EB - if (idim == 0) { - const amrex::Real vfr_m = - (AMREX_SPACEDIM == 2) ? vfrac[box_no](i - 1, j, k) - : std::cbrt(vfrac[box_no](i - 1, j, k)) * - std::cbrt(vfrac[box_no](i - 1, j, k)); - const amrex::Real vfr_p = (AMREX_SPACEDIM == 2) - ? vfrac[box_no](i, j, k) - : std::cbrt(vfrac[box_no](i, j, k)) * - std::cbrt(vfrac[box_no](i, j, k)); - mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); - } else if (idim == 1) { - const amrex::Real vfr_m = - (AMREX_SPACEDIM == 2) ? vfrac[box_no](i, j - 1, k) - : std::cbrt(vfrac[box_no](i, j - 1, k)) * - std::cbrt(vfrac[box_no](i, j - 1, k)); - const amrex::Real vfr_p = (AMREX_SPACEDIM == 2) - ? vfrac[box_no](i, j, k) - : std::cbrt(vfrac[box_no](i, j, k)) * - std::cbrt(vfrac[box_no](i, j, k)); - mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); - } else if (idim == 2) { - const amrex::Real vfr_m = - (AMREX_SPACEDIM == 2) ? vfrac[box_no](i, j, k - 1) - : std::cbrt(vfrac[box_no](i, j, k - 1)) * - std::cbrt(vfrac[box_no](i, j, k - 1)); - const amrex::Real vfr_p = (AMREX_SPACEDIM == 2) - ? vfrac[box_no](i, j, k) - : std::cbrt(vfrac[box_no](i, j, k)) * - std::cbrt(vfrac[box_no](i, j, k)); - mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); - } + int idx[3] = {i, j, k}; + idx[idim] -= 1; + const amrex::Real vfr_m = AMREX_D_PICK( + 1.0, vfrac[box_no](idx[0], idx[1], idx[2]), + std::cbrt( + vfrac[box_no](idx[0], idx[1], idx[2]) * + vfrac[box_no](idx[0], idx[1], idx[2]))); + const amrex::Real vfr_p = AMREX_D_PICK( + 1.0, vfrac[box_no](i, j, k), + std::cbrt(vfrac[box_no](i, j, k) * vfrac[box_no](i, j, k))); + mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); #endif }); } else if (m_les_model == "WALE") { @@ -150,44 +136,29 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) m_les_cm_wale * m_les_cm_wale * l_scale * l_scale; amrex::ParallelFor( ldata_p->visc_turb_fc[idim], ldata_p->visc_turb_fc[idim].nGrowVect(), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [prefact, idim, velgrad_arr, dens_arr, mut_arr +#ifdef AMREX_USE_EB + , + vfrac +#endif + ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { getTurbViscWALE( i, j, k, prefact, amrex::Array4(velgrad_arr[box_no]), amrex::Array4(dens_arr[box_no]), amrex::Array4(mut_arr[box_no])); #ifdef AMREX_USE_EB - if (idim == 0) { - const amrex::Real vfr_m = - (AMREX_SPACEDIM == 2) ? vfrac[box_no](i - 1, j, k) - : std::cbrt(vfrac[box_no](i - 1, j, k)) * - std::cbrt(vfrac[box_no](i - 1, j, k)); - const amrex::Real vfr_p = (AMREX_SPACEDIM == 2) - ? vfrac[box_no](i, j, k) - : std::cbrt(vfrac[box_no](i, j, k)) * - std::cbrt(vfrac[box_no](i, j, k)); - mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); - } else if (idim == 1) { - const amrex::Real vfr_m = - (AMREX_SPACEDIM == 2) ? vfrac[box_no](i, j - 1, k) - : std::cbrt(vfrac[box_no](i, j - 1, k)) * - std::cbrt(vfrac[box_no](i, j - 1, k)); - const amrex::Real vfr_p = (AMREX_SPACEDIM == 2) - ? vfrac[box_no](i, j, k) - : std::cbrt(vfrac[box_no](i, j, k)) * - std::cbrt(vfrac[box_no](i, j, k)); - mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); - } else if (idim == 2) { - const amrex::Real vfr_m = - (AMREX_SPACEDIM == 2) ? vfrac[box_no](i, j, k - 1) - : std::cbrt(vfrac[box_no](i, j, k - 1)) * - std::cbrt(vfrac[box_no](i, j, k - 1)); - const amrex::Real vfr_p = (AMREX_SPACEDIM == 2) - ? vfrac[box_no](i, j, k) - : std::cbrt(vfrac[box_no](i, j, k)) * - std::cbrt(vfrac[box_no](i, j, k)); - mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); - } + int idx[3] = {i, j, k}; + idx[idim] -= 1; + const amrex::Real vfr_m = AMREX_D_PICK( + 1.0, vfrac[box_no](idx[0], idx[1], idx[2]), + std::cbrt( + vfrac[box_no](idx[0], idx[1], idx[2]) * + vfrac[box_no](idx[0], idx[1], idx[2]))); + const amrex::Real vfr_p = AMREX_D_PICK( + 1.0, vfrac[box_no](i, j, k), + std::cbrt(vfrac[box_no](i, j, k) * vfrac[box_no](i, j, k))); + mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); #endif }); } else if (m_les_model == "Sigma") { @@ -195,44 +166,29 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) m_les_cs_sigma * m_les_cs_sigma * l_scale * l_scale; amrex::ParallelFor( ldata_p->visc_turb_fc[idim], ldata_p->visc_turb_fc[idim].nGrowVect(), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [prefact, idim, velgrad_arr, dens_arr, mut_arr +#ifdef AMREX_USE_EB + , + vfrac +#endif + ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { getTurbViscSigma( i, j, k, prefact, amrex::Array4(velgrad_arr[box_no]), amrex::Array4(dens_arr[box_no]), amrex::Array4(mut_arr[box_no])); #ifdef AMREX_USE_EB - if (idim == 0) { - const amrex::Real vfr_m = - (AMREX_SPACEDIM == 2) ? vfrac[box_no](i - 1, j, k) - : std::cbrt(vfrac[box_no](i - 1, j, k)) * - std::cbrt(vfrac[box_no](i - 1, j, k)); - const amrex::Real vfr_p = (AMREX_SPACEDIM == 2) - ? vfrac[box_no](i, j, k) - : std::cbrt(vfrac[box_no](i, j, k)) * - std::cbrt(vfrac[box_no](i, j, k)); - mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); - } else if (idim == 1) { - const amrex::Real vfr_m = - (AMREX_SPACEDIM == 2) ? vfrac[box_no](i, j - 1, k) - : std::cbrt(vfrac[box_no](i, j - 1, k)) * - std::cbrt(vfrac[box_no](i, j - 1, k)); - const amrex::Real vfr_p = (AMREX_SPACEDIM == 2) - ? vfrac[box_no](i, j, k) - : std::cbrt(vfrac[box_no](i, j, k)) * - std::cbrt(vfrac[box_no](i, j, k)); - mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); - } else if (idim == 2) { - const amrex::Real vfr_m = - (AMREX_SPACEDIM == 2) ? vfrac[box_no](i, j, k - 1) - : std::cbrt(vfrac[box_no](i, j, k - 1)) * - std::cbrt(vfrac[box_no](i, j, k - 1)); - const amrex::Real vfr_p = (AMREX_SPACEDIM == 2) - ? vfrac[box_no](i, j, k) - : std::cbrt(vfrac[box_no](i, j, k)) * - std::cbrt(vfrac[box_no](i, j, k)); - mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); - } + int idx[3] = {i, j, k}; + idx[idim] -= 1; + const amrex::Real vfr_m = AMREX_D_PICK( + 1.0, vfrac[box_no](idx[0], idx[1], idx[2]), + std::cbrt( + vfrac[box_no](idx[0], idx[1], idx[2]) * + vfrac[box_no](idx[0], idx[1], idx[2]))); + const amrex::Real vfr_p = AMREX_D_PICK( + 1.0, vfrac[box_no](i, j, k), + std::cbrt(vfrac[box_no](i, j, k) * vfrac[box_no](i, j, k))); + mut_arr[box_no](i, j, k) *= amrex::min(vfr_m, vfr_p); #endif }); } @@ -273,7 +229,8 @@ PeleLM::calcViscosity(const TimeStamp a_time) amrex::ParallelFor( ldata_p->visc_cc, ldata_p->visc_cc.nGrowVect(), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [sma, vma, ltransparm] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { getVelViscosity( i, j, k, amrex::Array4(sma[box_no], FIRSTSPEC), amrex::Array4(sma[box_no], TEMP), @@ -321,7 +278,13 @@ PeleLM::calcDiffusivity(const TimeStamp a_time) amrex::ParallelFor( ldata_p->diff_cc, ldata_p->diff_cc.nGrowVect(), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [sma, dma, soret_idx, ltransparm, do_fixed_Le, do_fixed_Pr, do_soret, + Le_inv, Pr_inv, leosparm +#if PELE_USE_PLASMA + , + kma, mwt, zk = zk +#endif + ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { getTransportCoeff( i, j, k, do_fixed_Le, do_fixed_Pr, do_soret, Le_inv, Pr_inv, amrex::Array4(sma[box_no], FIRSTSPEC), @@ -359,13 +322,14 @@ PeleLM::calcDiffusivity(const TimeStamp a_time) const auto& factory = ldata_p->diff_cc.Factory(); amrex::MultiFab cp_cc; - int ngrow = ldata_p->diff_cc.nGrow(); + const int ngrow = ldata_p->diff_cc.nGrow(); cp_cc.define(ba, dm, 1, ngrow, amrex::MFInfo(), factory); auto const& state_arr = ldata_p->state.const_arrays(); auto const& cp_arr = cp_cc.arrays(); amrex::ParallelFor( cp_cc, cp_cc.nGrowVect(), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [state_arr, cp_arr, leosparm] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { getCpmixGivenRYT( i, j, k, amrex::Array4(state_arr[box_no], DENSITY), @@ -419,7 +383,7 @@ PeleLM::getDiffusivity( EB_set_covered_faces(GetArrOfPtrs(beta_ec), 1.234e40); #else // NON-EB : use cen2edg_cpp - bool use_harmonic_avg = m_harm_avg_cen2edge != 0; + const bool use_harmonic_avg = m_harm_avg_cen2edge != 0; #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) @@ -434,7 +398,8 @@ PeleLM::getDiffusivity( const auto bc_lo = bcrec[0].lo(idim); const auto bc_hi = bcrec[0].hi(idim); amrex::ParallelFor( - ebx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ebx, [bc_lo, bc_hi, diff_ec, use_harmonic_avg, ncomp, idim, edomain, + diff_c] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { int idx[3] = {i, j, k}; bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && @@ -510,7 +475,8 @@ PeleLM::getDiffusivity( const amrex::Box ebx = mfi.tilebox(); const auto& diff_ec = beta_ec[idim].array(mfi); amrex::ParallelFor( - ebx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ebx, [diff_ec, geomdata, edomain, idim, beta_comp, ncomp, + lprobparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { ProblemSpecificFunctions::zero_visc( i, j, k, diff_ec, geomdata, edomain, idim, beta_comp, ncomp, *lprobparm); diff --git a/Source/PeleLMeX_UMac.cpp b/Source/PeleLMeX_UMac.cpp index da39c0f29..94fcac032 100644 --- a/Source/PeleLMeX_UMac.cpp +++ b/Source/PeleLMeX_UMac.cpp @@ -106,50 +106,44 @@ PeleLM::addChiIncrement( // Both mac_divu and chiIncr have properly filled ghost cells -> work on // grownbox for (int lev = 0; lev <= finest_level; ++lev) { -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(advData->chi[lev], amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& gbx = mfi.growntilebox(); - auto const& chiInc_ar = chiIncr[lev].const_array(mfi); - auto const& chi_ar = advData->chi[lev].array(mfi); - auto const& mac_divu_ar = advData->mac_divu[lev].array(mfi); + if (a_sdcIter == 1) { + // fill chi on first SDC iter if (m_chi_correction_type == ChiCorrectionType::DivuFirstIter) { + auto const& chiInc_ma = chiIncr[lev].const_arrays(); + auto const& chi_ma = advData->chi[lev].arrays(); + auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); amrex::ParallelFor( - gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - if (a_sdcIter == 1) { - chi_ar(i, j, k) = chiInc_ar(i, j, k) + mac_divu_ar(i, j, k); - } else { - chi_ar(i, j, k) += chiInc_ar(i, j, k); - } - mac_divu_ar(i, j, k) = chi_ar(i, j, k); - }); - } else if (m_chi_correction_type == ChiCorrectionType::NoDivu) { - amrex::ParallelFor( - gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - if (a_sdcIter == 1) { - chi_ar(i, j, k) = chiInc_ar(i, j, k); - } else { - chi_ar(i, j, k) += chiInc_ar(i, j, k); - } - mac_divu_ar(i, j, k) = chi_ar(i, j, k); - }); - } else { // Default: use updated divu every iteration - amrex::ParallelFor( - gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - if (a_sdcIter == 1) { - chi_ar(i, j, k) = chiInc_ar(i, j, k); - } else { - chi_ar(i, j, k) += chiInc_ar(i, j, k); - } - mac_divu_ar(i, j, k) += chi_ar(i, j, k); + advData->chi[lev], advData->chi[lev].nGrowVect(), + [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + chi_ma[box_no](i, j, k) = + chiInc_ma[box_no](i, j, k) + mac_divu_ma[box_no](i, j, k); }); + amrex::Gpu::streamSynchronize(); + } else { + amrex::MultiFab::Copy( + advData->chi[lev], chiIncr[lev], 0, 0, 1, + advData->chi[lev].nGrowVect()); } + } else { + amrex::MultiFab::Add( + advData->chi[lev], chiIncr[lev], 0, 0, 1, + advData->chi[lev].nGrowVect()); + } + if ( + m_chi_correction_type == ChiCorrectionType::DivuFirstIter || + m_chi_correction_type == ChiCorrectionType::NoDivu) { + amrex::MultiFab::Copy( + advData->mac_divu[lev], advData->chi[lev], 0, 0, 1, + advData->chi[lev].nGrowVect()); + } else { + amrex::MultiFab::Add( + advData->mac_divu[lev], advData->chi[lev], 0, 0, 1, + advData->chi[lev].nGrowVect()); } } if (m_print_chi_convergence) { - amrex::Real max_corr = + const amrex::Real max_corr = MLNorm0(GetVecOfConstPtrs(chiIncr)) * m_dt / m_dpdtFactor; amrex::Print() << " Before SDC " << a_sdcIter << ": max relative P mismatch is " << max_corr << "\n"; diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 8987743ad..1f8ee9458 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -228,7 +228,8 @@ PeleLM::extFluxDivergenceLevel( #ifdef AMREX_USE_EB if (flagfab.getType(bx) == amrex::FabType::covered) { // Covered boxes amrex::ParallelFor( - bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + bx, ncomp, + [divergence] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { divergence(i, j, k, n) = 0.0; }); } else if (flagfab.getType(bx) != amrex::FabType::regular) { // EB @@ -236,7 +237,12 @@ PeleLM::extFluxDivergenceLevel( // boxes auto vfrac = ebfact.getVolFrac().const_array(mfi); amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [flag, divergence, ncomp, vol, scale, vfrac, fluxX, fluxY +#if (AMREX_SPACEDIM == 3) + , + fluxZ +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (flag(i, j, k).isCovered()) { for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) = 0.0; @@ -246,7 +252,7 @@ PeleLM::extFluxDivergenceLevel( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), vol, scale, divergence); } else { - amrex::Real vfracinv = 1.0 / vfrac(i, j, k); + const amrex::Real vfracinv = 1.0 / vfrac(i, j, k); extFluxDivergence_K( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), vol, scale, divergence); @@ -259,7 +265,12 @@ PeleLM::extFluxDivergenceLevel( #endif { amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [ncomp, vol, scale, divergence, fluxX, fluxY +#if (AMREX_SPACEDIM == 3) + , + fluxZ +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { extFluxDivergence_K( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), vol, scale, divergence); @@ -327,7 +338,8 @@ PeleLM::intFluxDivergenceLevel( if (flagfab.getType(bx) == amrex::FabType::covered) { // Covered boxes amrex::ParallelFor( - bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + bx, ncomp, + [divergence] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { divergence(i, j, k, n) = 0.0; }); } else if (flagfab.getType(bx) != amrex::FabType::regular) { // EB @@ -339,7 +351,13 @@ PeleLM::intFluxDivergenceLevel( , const auto& afrac_y = areafrac[1]->array(mfi); , const auto& afrac_z = areafrac[2]->array(mfi);); amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [flag, divergence, ncomp, vol, scale, vfrac, fluxX, areax, afrac_x, + fluxY, areay, afrac_y +#if (AMREX_SPACEDIM == 3) + , + fluxZ, areaz, afrac_z +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (flag(i, j, k).isCovered()) { for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) = 0.0; @@ -349,7 +367,7 @@ PeleLM::intFluxDivergenceLevel( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), AMREX_D_DECL(areax, areay, areaz), vol, scale, divergence); } else { - amrex::Real vfracinv = 1.0 / vfrac(i, j, k); + const amrex::Real vfracinv = 1.0 / vfrac(i, j, k); EB_intFluxDivergence_K( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), AMREX_D_DECL(afrac_x, afrac_y, afrac_z), @@ -367,16 +385,21 @@ PeleLM::intFluxDivergenceLevel( amrex::Array4 const& ax = mf_ax.const_array(mfi); amrex::Array4 const& ay = mf_ay.const_array(mfi); amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [ncomp, ax, ay, fluxX, fluxY, vol, scale, + divergence] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { intFluxDivergence_rz_K( - i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), ax, ay, vol, - scale, divergence); + i, j, k, ncomp, fluxX, fluxY, ax, ay, vol, scale, divergence); }); } else #endif { amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [ncomp, vol, scale, divergence, fluxX, areax, fluxY, areay +#if (AMREX_SPACEDIM == 3) + , + fluxZ, areaz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { intFluxDivergence_K( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), AMREX_D_DECL(areax, areay, areaz), vol, scale, divergence); @@ -447,7 +470,8 @@ PeleLM::intFluxDivergenceLevelEB( if (flagfab.getType(bx) == amrex::FabType::covered) { // Covered boxes amrex::ParallelFor( - bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + bx, ncomp, + [divergence] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { divergence(i, j, k, n) = 0.0; }); } else if (flagfab.getType(bx) != amrex::FabType::regular) { // EB @@ -460,7 +484,13 @@ PeleLM::intFluxDivergenceLevelEB( , const auto& afrac_z = areafrac[2]->array(mfi);); const auto& ebarea = eb_area->array(mfi); amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [flag, divergence, vol, scale, ncomp, ebflux, ebarea, dx, vfrac, + fluxX, areax, afrac_x, fluxY, areay, afrac_y +#if (AMREX_SPACEDIM == 3) + , + fluxZ, areaz, afrac_z +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (flag(i, j, k).isCovered()) { for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) = 0.0; @@ -470,7 +500,7 @@ PeleLM::intFluxDivergenceLevelEB( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), AMREX_D_DECL(areax, areay, areaz), vol, scale, divergence); } else { - amrex::Real vfracinv = 1.0 / vfrac(i, j, k); + const amrex::Real vfracinv = 1.0 / vfrac(i, j, k); EB_intFluxDivergence_K( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), AMREX_D_DECL(afrac_x, afrac_y, afrac_z), @@ -485,7 +515,12 @@ PeleLM::intFluxDivergenceLevelEB( #endif { amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [ncomp, vol, scale, divergence, fluxX, areax, fluxY, areay +#if (AMREX_SPACEDIM == 3) + , + fluxZ, areaz +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { intFluxDivergence_K( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), AMREX_D_DECL(areax, areay, areaz), vol, scale, divergence); @@ -579,16 +614,23 @@ PeleLM:: , auto const& apy_arr = ebfact.getAreaFrac()[1]->const_array(mfi); , auto const& apz_arr = ebfact.getAreaFrac()[2]->const_array(mfi);); amrex::ParallelFor( - bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + bx, ncomp, + [l_conserv_d, vfrac_arr, div_arr, divu_arr, apx_arr, facex, apy_arr, + facey +#if (AMREX_SPACEDIM == 3) + , + apz_arr, facez +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { if ((l_conserv_d[n] == 0) && vfrac_arr(i, j, k) > 0.) { - amrex::Real qwsum = AMREX_D_TERM( + const amrex::Real qwsum = AMREX_D_TERM( apx_arr(i, j, k) * facex(i, j, k, n) + apx_arr(i + 1, j, k) * facex(i + 1, j, k, n), +apy_arr(i, j, k) * facey(i, j, k, n) + apy_arr(i, j + 1, k) * facey(i, j + 1, k, n), +apz_arr(i, j, k) * facez(i, j, k, n) + apz_arr(i, j, k + 1) * facez(i, j, k + 1, n)); - amrex::Real areasum = AMREX_D_TERM( + const amrex::Real areasum = AMREX_D_TERM( apx_arr(i, j, k) + apx_arr(i + 1, j, k), +apy_arr(i, j, k) + apy_arr(i, j + 1, k), +apz_arr(i, j, k) + apz_arr(i, j, k + 1)); @@ -605,15 +647,16 @@ PeleLM:: amrex::Array4 const& ax = mf_ax.const_array(mfi); amrex::Array4 const& ay = mf_ay.const_array(mfi); amrex::ParallelFor( - bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + bx, ncomp, + [l_conserv_d, ax, ay, facex, facey, divu_arr, + div_arr] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { if (l_conserv_d[n] == 0) { amrex::Real qavg = AMREX_D_TERM( ax(i, j, k) * facex(i, j, k, n) + ax(i + 1, j, k) * facex(i + 1, j, k, n), +ay(i, j, k) * facey(i, j, k, n) + - ay(i, j + 1, k) * facey(i, j + 1, k, n), - +0.0); - amrex::Real areasum = + ay(i, j + 1, k) * facey(i, j + 1, k, n), ); + const amrex::Real areasum = ax(i, j, k) + ax(i + 1, j, k) + ay(i, j, k) + ay(i, j + 1, k); qavg /= areasum; // Note that because we define adv update as MINUS div(u q), here @@ -625,7 +668,13 @@ PeleLM:: #endif { amrex::ParallelFor( - bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + bx, ncomp, + [l_conserv_d, div_arr, divu_arr, facex, facey +#if (AMREX_SPACEDIM == 3) + , + facez +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { if (l_conserv_d[n] == 0) { amrex::Real qavg = AMREX_D_TERM( facex(i, j, k, n) + facex(i + 1, j, k, n), @@ -718,16 +767,23 @@ PeleLM::advFluxDivergence( , auto const& apy_arr = ebfact.getAreaFrac()[1]->const_array(mfi); , auto const& apz_arr = ebfact.getAreaFrac()[2]->const_array(mfi);); amrex::ParallelFor( - bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + bx, ncomp, + [l_conserv_d, vfrac_arr, div_arr, divu_arr, facex, apx_arr, facey, + apy_arr +#if (AMREX_SPACEDIM == 3) + , + facez, apz_arr +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { if (l_conserv_d[n] == 0 && vfrac_arr(i, j, k) > 0.) { - amrex::Real qwsum = AMREX_D_TERM( + const amrex::Real qwsum = AMREX_D_TERM( apx_arr(i, j, k) * facex(i, j, k, n) + apx_arr(i + 1, j, k) * facex(i + 1, j, k, n), +apy_arr(i, j, k) * facey(i, j, k, n) + apy_arr(i, j + 1, k) * facey(i, j + 1, k, n), +apz_arr(i, j, k) * facez(i, j, k, n) + apz_arr(i, j, k + 1) * facez(i, j, k + 1, n)); - amrex::Real areasum = AMREX_D_TERM( + const amrex::Real areasum = AMREX_D_TERM( apx_arr(i, j, k) + apx_arr(i + 1, j, k), +apy_arr(i, j, k) + apy_arr(i, j + 1, k), +apz_arr(i, j, k) + apz_arr(i, j, k + 1)); @@ -738,7 +794,13 @@ PeleLM::advFluxDivergence( }); } else { amrex::ParallelFor( - bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + bx, ncomp, + [l_conserv_d, div_arr, divu_arr, facex, facey +#if (AMREX_SPACEDIM == 3) + , + facez +#endif + ] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { if (l_conserv_d[n] == 0) { amrex::Real qavg = AMREX_D_TERM( facex(i, j, k, n) + facex(i + 1, j, k, n), @@ -771,8 +833,8 @@ PeleLM::floorSpecies(const TimeStamp a_time) auto const* leosparm = eos_parms.device_parm(); amrex::ParallelFor( - ldata_p->state, - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + ldata_p->state, [sma, leosparm] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { fabMinMax( i, j, k, NUM_SPECIES, 0.0, AMREX_REAL_MAX, amrex::Array4(sma[box_no], FIRSTSPEC)); @@ -825,7 +887,7 @@ PeleLM::resetCoveredMask() baf.intersections(grids[lev][mfi.index()], isects); for (const auto& is : isects) { amrex::ParallelFor( - is.second, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + is.second, [mask] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { mask(i, j, k) = 0; }); } @@ -1297,7 +1359,7 @@ PeleLM::isStateVariable(std::string_view a_name) // Check state return std::any_of( stateComponents.begin(), stateComponents.end(), - [=](const auto& stateComponent) { + [a_name](const auto& stateComponent) { return std::get<1>(stateComponent) == a_name; }); } @@ -1308,7 +1370,7 @@ PeleLM::isReactVariable(std::string_view a_name) // Check reaction state return std::any_of( reactComponents.begin(), reactComponents.end(), - [=](const auto& reactComponent) { + [a_name](const auto& reactComponent) { return std::get<1>(reactComponent) == a_name; }); } @@ -1643,8 +1705,9 @@ PeleLM::MFmax( mx = ParReduce( amrex::TypeList{}, amrex::TypeList{}, *a_MF, amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [flagsma, mask, ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { if (flagsma[box_no](i, j, k).isCovered() || !mask[box_no](i, j, k)) { return AMREX_REAL_LOWEST; } else { @@ -1681,8 +1744,9 @@ PeleLM::MFmax( mx = ParReduce( amrex::TypeList{}, amrex::TypeList{}, *a_MF, amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [mask, ma, comp] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { if (!mask[box_no](i, j, k)) { return AMREX_REAL_LOWEST; } else { @@ -1732,8 +1796,9 @@ PeleLM::MFmin( mn = ParReduce( amrex::TypeList{}, amrex::TypeList{}, *a_MF, amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [flagsma, mask, ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { if (flagsma[box_no](i, j, k).isCovered() || !mask[box_no](i, j, k)) { return AMREX_REAL_MAX; } else { @@ -1770,8 +1835,9 @@ PeleLM::MFmin( mn = ParReduce( amrex::TypeList{}, amrex::TypeList{}, *a_MF, amrex::IntVect(0), - [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept - -> amrex::GpuTuple { + [mask, ma, comp] AMREX_GPU_DEVICE( + int box_no, int i, int j, + int k) noexcept -> amrex::GpuTuple { if (!mask[box_no](i, j, k)) { return AMREX_REAL_MAX; } else { @@ -2120,28 +2186,26 @@ PeleLM::extendSignedDistance( // signed distance and propagates it manually up to the point where we need to // have it for derefining. const auto geomdata = geom[0].data(); - amrex::Real maxSignedDist = a_signDist->max(0); + const amrex::Real maxSignedDist = a_signDist->max(0); const auto& ebfactory = dynamic_cast(a_signDist->Factory()); const auto& flags = ebfactory.getMultiEBCellFlagFab(); - int nGrowFac = flags.nGrow() + 1; + const int nGrowFac = flags.nGrow() + 1; // First set the region far away at the max value we need -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(*a_signDist, amrex::TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const amrex::Box& bx = mfi.growntilebox(); - auto const& sd_cc = a_signDist->array(mfi); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - if (sd_cc(i, j, k) >= maxSignedDist - 1e-12) { - const amrex::Real* dx = geomdata.CellSize(); - sd_cc(i, j, k) = nGrowFac * dx[0] * a_extendFactor; + + auto const& sd_cc_ma = a_signDist->arrays(); + const amrex::Real* dx = geomdata.CellSize(); + const amrex::Real sd_cc_fact = nGrowFac * dx[0] * a_extendFactor; + amrex::ParallelFor( + *a_signDist, a_signDist->nGrowVect(), + [sd_cc_ma, maxSignedDist, + sd_cc_fact] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + if (sd_cc_ma[box_no](i, j, k) > maxSignedDist - 1e-12) { + sd_cc_ma[box_no](i, j, k) = sd_cc_fact; } }); - } - + amrex::Gpu::streamSynchronize(); // Iteratively compute the distance function in boxes, propagating across // boxes using ghost cells If needed, increase the number of loop to extend // the reach of the distance function @@ -2159,7 +2223,8 @@ PeleLM::extendSignedDistance( } auto const& sd_cc = a_signDist->array(mfi); amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bx, [gbx, geomdata, a_extendFactor, sd_cc, + maxSignedDist] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { const auto glo = amrex::lbound(gbx); const auto ghi = amrex::ubound(gbx); const amrex::Real* dx = geomdata.CellSize(); diff --git a/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp b/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp index 69af3c5e9..0e713c61f 100644 --- a/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp +++ b/Source/Plasma/LinOps/AMReX_MLCellABecCecLap.cpp @@ -80,7 +80,7 @@ MLCellABecCecLap::define( Array4 const& cmsk = crse->array(mfi); reduce_op.eval( bx, reduce_data, - [=] AMREX_GPU_HOST_DEVICE(Box const& b) -> ReduceTuple { + [cmsk, fmsk] AMREX_GPU_HOST_DEVICE(Box const& b) -> ReduceTuple { return {coarsen_overset_mask(b, cmsk, fmsk)}; }); } diff --git a/Source/Plasma/PeleLMeX_EFDeriveFunc.cpp b/Source/Plasma/PeleLMeX_EFDeriveFunc.cpp index ddca235a0..bbe4be7e3 100644 --- a/Source/Plasma/PeleLMeX_EFDeriveFunc.cpp +++ b/Source/Plasma/PeleLMeX_EFDeriveFunc.cpp @@ -29,13 +29,14 @@ pelelmex_derchargedist( amrex::GpuArray zk; pele::physics::eos::charge_mass(zk.arr); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - der(i, j, k) = -nE(i, j, k) * elemCharge; - for (int n = 0; n < NUM_SPECIES; ++n) { - der(i, j, k) += - zk[n] * 1000.0 * rhoY(i, j, k, n); // CGS->MKS conversion of zk - } - }); + amrex::ParallelFor( + bx, [der, nE, zk, rhoY] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + der(i, j, k) = -nE(i, j, k) * elemCharge; + for (int n = 0; n < NUM_SPECIES; ++n) { + der(i, j, k) += + zk[n] * 1000.0 * rhoY(i, j, k, n); // CGS->MKS conversion of zk + } + }); } void @@ -60,22 +61,25 @@ pelelmex_derefx( const auto dxinv = geomdata.InvCellSizeArray(); const auto domain = geomdata.Domain(); - amrex::Real factor = -0.5 * dxinv[0]; + const amrex::Real factor = -0.5 * dxinv[0]; const auto bc_lo = bcrec[PHIV].lo(0); const auto bc_hi = bcrec[PHIV].hi(0); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && i <= domain.smallEnd(0)); - bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && i >= domain.bigEnd(0)); - der(i, j, k) = factor * (phiV(i + 1, j, k) - phiV(i - 1, j, k)); - if (on_lo) - der(i, j, k) = - factor * (phiV(i + 1, j, k) + phiV(i, j, k) - 2.0 * phiV(i - 1, j, k)); - if (on_hi) - der(i, j, k) = - factor * (2.0 * phiV(i + 1, j, k) - phiV(i, j, k) - phiV(i - 1, j, k)); - }); + amrex::ParallelFor( + bx, [bc_lo, bc_hi, domain, factor, phiV, + der] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bool on_lo = + ((bc_lo == amrex::BCType::ext_dir) && i <= domain.smallEnd(0)); + bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && i >= domain.bigEnd(0)); + der(i, j, k) = factor * (phiV(i + 1, j, k) - phiV(i - 1, j, k)); + if (on_lo) + der(i, j, k) = factor * (phiV(i + 1, j, k) + phiV(i, j, k) - + 2.0 * phiV(i - 1, j, k)); + if (on_hi) + der(i, j, k) = factor * (2.0 * phiV(i + 1, j, k) - phiV(i, j, k) - + phiV(i - 1, j, k)); + }); } void @@ -105,30 +109,33 @@ pelelmex_derLorentzx( const auto dxinv = geomdata.InvCellSizeArray(); const auto domain = geomdata.Domain(); - amrex::Real factor = -0.5 * dxinv[0]; + const amrex::Real factor = -0.5 * dxinv[0]; const auto bc_lo = bcrec[PHIV].lo(0); const auto bc_hi = bcrec[PHIV].hi(0); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - // Get gradient of PhiV - bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && i <= domain.smallEnd(0)); - bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && i >= domain.bigEnd(0)); - amrex::Real EFx = factor * (phiV(i + 1, j, k) - phiV(i - 1, j, k)); - if (on_lo) - EFx = - factor * (phiV(i + 1, j, k) + phiV(i, j, k) - 2.0 * phiV(i - 1, j, k)); - if (on_hi) - EFx = - factor * (2.0 * phiV(i + 1, j, k) - phiV(i, j, k) - phiV(i - 1, j, k)); - - // Assemble Lorentz force in X - der(i, j, k) = -nE(i, j, k) * elemCharge * EFx; - for (int n = 0; n < NUM_SPECIES; ++n) { - der(i, j, k) += - zk[n] * 1000.0 * rhoY(i, j, k, n) * EFx; // CGS->MKS conversion of zk - } - }); + amrex::ParallelFor( + bx, [bc_lo, bc_hi, domain, factor, phiV, der, nE, zk, + rhoY] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + // Get gradient of PhiV + bool on_lo = + ((bc_lo == amrex::BCType::ext_dir) && i <= domain.smallEnd(0)); + bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && i >= domain.bigEnd(0)); + amrex::Real EFx = factor * (phiV(i + 1, j, k) - phiV(i - 1, j, k)); + if (on_lo) + EFx = factor * + (phiV(i + 1, j, k) + phiV(i, j, k) - 2.0 * phiV(i - 1, j, k)); + if (on_hi) + EFx = factor * + (2.0 * phiV(i + 1, j, k) - phiV(i, j, k) - phiV(i - 1, j, k)); + + // Assemble Lorentz force in X + der(i, j, k) = -nE(i, j, k) * elemCharge * EFx; + for (int n = 0; n < NUM_SPECIES; ++n) { + der(i, j, k) += + zk[n] * 1000.0 * rhoY(i, j, k, n) * EFx; // CGS->MKS conversion of zk + } + }); } #if (AMREX_SPACEDIM > 1) @@ -154,22 +161,25 @@ pelelmex_derefy( const auto dxinv = geomdata.InvCellSizeArray(); const auto domain = geomdata.Domain(); - amrex::Real factor = -0.5 * dxinv[1]; + const amrex::Real factor = -0.5 * dxinv[1]; const auto bc_lo = bcrec[PHIV].lo(1); const auto bc_hi = bcrec[PHIV].hi(1); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && j <= domain.smallEnd(1)); - bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && j >= domain.bigEnd(1)); - der(i, j, k) = factor * (phiV(i, j + 1, k) - phiV(i, j - 1, k)); - if (on_lo) - der(i, j, k) = - factor * (phiV(i, j + 1, k) + phiV(i, j, k) - 2.0 * phiV(i, j - 1, k)); - if (on_hi) - der(i, j, k) = - factor * (2.0 * phiV(i, j + 1, k) - phiV(i, j, k) - phiV(i, j - 1, k)); - }); + amrex::ParallelFor( + bx, [bc_lo, bc_hi, domain, der, phiV, + factor] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bool on_lo = + ((bc_lo == amrex::BCType::ext_dir) && j <= domain.smallEnd(1)); + bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && j >= domain.bigEnd(1)); + der(i, j, k) = factor * (phiV(i, j + 1, k) - phiV(i, j - 1, k)); + if (on_lo) + der(i, j, k) = factor * (phiV(i, j + 1, k) + phiV(i, j, k) - + 2.0 * phiV(i, j - 1, k)); + if (on_hi) + der(i, j, k) = factor * (2.0 * phiV(i, j + 1, k) - phiV(i, j, k) - + phiV(i, j - 1, k)); + }); } void @@ -199,30 +209,33 @@ pelelmex_derLorentzy( const auto dxinv = geomdata.InvCellSizeArray(); const auto domain = geomdata.Domain(); - amrex::Real factor = -0.5 * dxinv[1]; + const amrex::Real factor = -0.5 * dxinv[1]; const auto bc_lo = bcrec[PHIV].lo(1); const auto bc_hi = bcrec[PHIV].hi(1); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - // Get gradient of PhiV - bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && j <= domain.smallEnd(1)); - bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && j >= domain.bigEnd(1)); - amrex::Real EFy = factor * (phiV(i, j + 1, k) - phiV(i, j - 1, k)); - if (on_lo) - EFy = - factor * (phiV(i, j + 1, k) + phiV(i, j, k) - 2.0 * phiV(i, j - 1, k)); - if (on_hi) - EFy = - factor * (2.0 * phiV(i, j - 1, k) - phiV(i, j, k) - phiV(i, j - 1, k)); - - // Assemble Lorentz force in Y - der(i, j, k) = -nE(i, j, k) * elemCharge * EFy; - for (int n = 0; n < NUM_SPECIES; ++n) { - der(i, j, k) += - zk[n] * 1000.0 * rhoY(i, j, k, n) * EFy; // CGS->MKS conversion of zk - } - }); + amrex::ParallelFor( + bx, [bc_lo, bc_hi, domain, factor, der, nE, phiV, rhoY, + zk] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + // Get gradient of PhiV + bool on_lo = + ((bc_lo == amrex::BCType::ext_dir) && j <= domain.smallEnd(1)); + bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && j >= domain.bigEnd(1)); + amrex::Real EFy = factor * (phiV(i, j + 1, k) - phiV(i, j - 1, k)); + if (on_lo) + EFy = factor * + (phiV(i, j + 1, k) + phiV(i, j, k) - 2.0 * phiV(i, j - 1, k)); + if (on_hi) + EFy = factor * + (2.0 * phiV(i, j - 1, k) - phiV(i, j, k) - phiV(i, j - 1, k)); + + // Assemble Lorentz force in Y + der(i, j, k) = -nE(i, j, k) * elemCharge * EFy; + for (int n = 0; n < NUM_SPECIES; ++n) { + der(i, j, k) += + zk[n] * 1000.0 * rhoY(i, j, k, n) * EFy; // CGS->MKS conversion of zk + } + }); } #if (AMREX_SPACEDIM > 2) @@ -253,17 +266,20 @@ pelelmex_derefz( const auto bc_lo = bcrec[PHIV].lo(2); const auto bc_hi = bcrec[PHIV].hi(2); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && k <= domain.smallEnd(2)); - bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && k >= domain.bigEnd(2)); - der(i, j, k) = factor * (phiV(i, j, k + 1) - phiV(i, j, k - 1)); - if (on_lo) - der(i, j, k) = - factor * (phiV(i, j, k + 1) + phiV(i, j, k) - 2.0 * phiV(i, j, k - 1)); - if (on_hi) - der(i, j, k) = - factor * (2.0 * phiV(i, j, k + 1) - phiV(i, j, k) - phiV(i, j, k - 1)); - }); + amrex::ParallelFor( + bx, [bc_lo, bc_hi, domain, der, phiV, + factor] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bool on_lo = + ((bc_lo == amrex::BCType::ext_dir) && k <= domain.smallEnd(2)); + bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && k >= domain.bigEnd(2)); + der(i, j, k) = factor * (phiV(i, j, k + 1) - phiV(i, j, k - 1)); + if (on_lo) + der(i, j, k) = factor * (phiV(i, j, k + 1) + phiV(i, j, k) - + 2.0 * phiV(i, j, k - 1)); + if (on_hi) + der(i, j, k) = factor * (2.0 * phiV(i, j, k + 1) - phiV(i, j, k) - + phiV(i, j, k - 1)); + }); } void @@ -298,25 +314,28 @@ pelelmex_derLorentzz( const auto bc_lo = bcrec[PHIV].lo(2); const auto bc_hi = bcrec[PHIV].hi(2); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - // Get gradient of PhiV - bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && k <= domain.smallEnd(2)); - bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && k >= domain.bigEnd(2)); - amrex::Real EFz = factor * (phiV(i, j, k + 1) - phiV(i, j, k - 1)); - if (on_lo) - EFz = - factor * (phiV(i, j, k + 1) + phiV(i, j, k) - 2.0 * phiV(i, j, k - 1)); - if (on_hi) - EFz = - factor * (2.0 * phiV(i, j, k + 1) - phiV(i, j, k) - phiV(i, j, k - 1)); - - // Assemble Lorentz force in Z - der(i, j, k) = -nE(i, j, k) * elemCharge * EFz; - for (int n = 0; n < NUM_SPECIES; ++n) { - der(i, j, k) += - zk[n] * 1000.0 * rhoY(i, j, k, n) * EFz; // CGS->MKS conversion of zk - } - }); + amrex::ParallelFor( + bx, [bc_lo, bc_hi, domain, factor, phiV, der, nE, zk, + rhoY] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + // Get gradient of PhiV + bool on_lo = + ((bc_lo == amrex::BCType::ext_dir) && k <= domain.smallEnd(2)); + bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && k >= domain.bigEnd(2)); + amrex::Real EFz = factor * (phiV(i, j, k + 1) - phiV(i, j, k - 1)); + if (on_lo) + EFz = factor * + (phiV(i, j, k + 1) + phiV(i, j, k) - 2.0 * phiV(i, j, k - 1)); + if (on_hi) + EFz = factor * + (2.0 * phiV(i, j, k + 1) - phiV(i, j, k) - phiV(i, j, k - 1)); + + // Assemble Lorentz force in Z + der(i, j, k) = -nE(i, j, k) * elemCharge * EFz; + for (int n = 0; n < NUM_SPECIES; ++n) { + der(i, j, k) += + zk[n] * 1000.0 * rhoY(i, j, k, n) * EFz; // CGS->MKS conversion of zk + } + }); } #endif #endif diff --git a/Source/Plasma/PeleLMeX_EFIonDrift.cpp b/Source/Plasma/PeleLMeX_EFIonDrift.cpp index 04add160e..2fb086749 100644 --- a/Source/Plasma/PeleLMeX_EFIonDrift.cpp +++ b/Source/Plasma/PeleLMeX_EFIonDrift.cpp @@ -58,48 +58,43 @@ PeleLM::ionDriftVelocity(std::unique_ptr& advData) auto ldataNew_p = getLevelDataPtr(lev, AmrNewTime); amrex::MultiFab mobH_cc(grids[lev], dmap[lev], NUM_IONS, 1); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(mobH_cc, amrex::TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const amrex::Box& gbx = mfi.growntilebox(); - const auto& mob_o = ldataOld_p->mob_cc.const_array(mfi); - const auto& mob_n = ldataNew_p->mob_cc.const_array(mfi); - const auto& mob_h = mobH_cc.array(mfi); - amrex::ParallelFor( - gbx, NUM_IONS, - [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - mob_h(i, j, k, n) = 0.5 * (mob_o(i, j, k, n) + mob_n(i, j, k, n)); - }); - } + auto const& mob_o_ma = ldataOld_p->mob_cc.const_arrays(); + auto const& mob_n_ma = ldataNew_p->mob_cc.const_arrays(); + auto const& mob_h_ma = mobH_cc.arrays(); + + amrex::ParallelFor( + mobH_cc, mobH_cc.nGrowVect(), + [mob_o_ma, mob_n_ma, + mob_h_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < NUM_IONS; ++n) { + mob_h_ma[box_no](i, j, k, n) = + 0.5 * (mob_o_ma[box_no](i, j, k, n) + mob_n_ma[box_no](i, j, k, n)); + } + }); // Get the face centered ions mobility - int doZeroVisc = 0; + constexpr int doZeroVisc = 0; amrex::Array mobH_ec = getDiffusivity(lev, 0, NUM_IONS, doZeroVisc, bcRecIons, mobH_cc); // Assemble the ions drift velocity for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(mobH_ec[idim], amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box bx = mfi.tilebox(); - const auto& mob_h = mobH_ec[idim].const_array(mfi); - const auto& gp_o = gphiVOld[lev][idim].const_array(mfi); - const auto& gp_n = gphiVNew[lev][idim].const_array(mfi); - const auto& Ud_Sp = advData->uDrift[lev][idim].array(mfi); - amrex::ParallelFor( - bx, NUM_IONS, - [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - Ud_Sp(i, j, k, n) = - mob_h(i, j, k, n) * -0.5 * (gp_o(i, j, k) + gp_n(i, j, k)); - }); - } + auto const& mob_h_ma = mobH_ec[idim].const_arrays(); + auto const& gp_o_ma = gphiVOld[lev][idim].const_arrays(); + auto const& gp_n_ma = gphiVNew[lev][idim].const_arrays(); + auto const& Ud_Sp_ma = advData->uDrift[lev][idim].arrays(); + amrex::ParallelFor( + mobH_ec[idim], [mob_h_ma, gp_o_ma, gp_n_ma, Ud_Sp_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + for (int n = 0; n < NUM_IONS; ++n) { + Ud_Sp_ma[box_no](i, j, k, n) = + mob_h_ma[box_no](i, j, k, n) * -0.5 * + (gp_o_ma[box_no](i, j, k) + gp_n_ma[box_no](i, j, k)); + } + }); } } + amrex::Gpu::streamSynchronize(); //---------------------------------------------------------------- // Average down faces @@ -173,20 +168,9 @@ PeleLM::ionDriftAddUmac(int lev, std::unique_ptr& advData) { // Add umac to the ions drift velocity to get the effective velocity for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(advData->umac[lev][idim], amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box gbx = mfi.growntilebox(); - const auto& umac = advData->umac[lev][idim].const_array(mfi); - const auto& Ud_Sp = advData->uDrift[lev][idim].array(mfi); - amrex::ParallelFor( - gbx, NUM_IONS, - [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - Ud_Sp(i, j, k, n) += umac(i, j, k); - }); - } + amrex::MultiFab::Add( + advData->uDrift[lev][idim], advData->umac[lev][idim], 0, 0, 1, + advData->umac[lev][idim].nGrowVect()); advData->uDrift[lev][idim].FillBoundary(geom[lev].periodicity()); } } diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index 43ba32b8c..b2531c923 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -323,30 +323,39 @@ PeleLM::incrementElectronForcing( auto ldataR_p = getLevelDataReactPtr(lev); // Reaction auto ldataNLs_p = getLevelDataNLSolvePtr(lev); // NL data -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& nE_o = ldata_p->state.const_array(mfi, NE); - auto const& nE_n = ldataNLs_p->nlState.const_array(mfi); - auto const& I_R_nE = ldataR_p->I_R.const_array(mfi, NUM_SPECIES); - auto const& FnE = advData->Forcing[lev].array(mfi, NUM_SPECIES + 1); - amrex::Real scaling = nE_scale; - amrex::Real dtinv = 1.0 / dtsub; + auto const& state_o_ma = ldata_p->state.const_arrays(); + auto const& nE_n_ma = ldataNLs_p->nlState.const_arrays(); + auto const& I_R_ma = ldataR_p->I_R.const_arrays(); + auto const& F_ma = advData->Forcing[lev].arrays(); + const amrex::Real scaling = nE_scale; + const amrex::Real dtinv = 1.0 / dtsub; + if (a_sstep == 0) { amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - if (a_sstep == 0) { - FnE(i, j, k) = (nE_n(i, j, k) * scaling - nE_o(i, j, k)) * dtinv - - I_R_nE(i, j, k); - } else { - FnE(i, j, k) += (nE_n(i, j, k) * scaling - nE_o(i, j, k)) * dtinv - - I_R_nE(i, j, k); - } + ldata_p->state, + [state_o_ma, nE_n_ma, I_R_ma, F_ma, scaling, + dtinv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 nE_o(state_o_ma[box_no], NE); + amrex::Array4 I_R_nE(I_R_ma[box_no], NUM_SPECIES); + amrex::Array4 FnE(F_ma[box_no], NUM_SPECIES + 1); + FnE(i, j, k) = + (nE_n_ma[box_no](i, j, k) * scaling - nE_o(i, j, k)) * dtinv - + I_R_nE(i, j, k); + }); + } else { + amrex::ParallelFor( + ldata_p->state, + [state_o_ma, nE_n_ma, I_R_ma, F_ma, scaling, + dtinv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 nE_o(state_o_ma[box_no], NE); + amrex::Array4 I_R_nE(I_R_ma[box_no], NUM_SPECIES); + amrex::Array4 FnE(F_ma[box_no], NUM_SPECIES + 1); + FnE(i, j, k) += + (nE_n_ma[box_no](i, j, k) * scaling - nE_o(i, j, k)) * dtinv - + I_R_nE(i, j, k); }); } } + amrex::Gpu::streamSynchronize(); } void @@ -356,7 +365,7 @@ PeleLM::computeBGcharge( std::unique_ptr& advData) { // Get integration dt - amrex::Real dt_int = a_time - getTime(0, AmrOldTime); + const amrex::Real dt_int = a_time - getTime(0, AmrOldTime); for (int lev = 0; lev <= finest_level; ++lev) { // Get data pointers @@ -364,37 +373,37 @@ PeleLM::computeBGcharge( auto ldataR_p = getLevelDataReactPtr(lev); // Reaction auto ldataNLs_p = getLevelDataNLSolvePtr(lev); // NL data -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi( - ldataNLs_p->backgroundCharge, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& rhoYold = ldata_p->state.const_array(mfi, FIRSTSPEC); - auto const& adv_arr = advData->AofS[lev].const_array(mfi, FIRSTSPEC); - auto const& dn_arr = diffData->Dn[lev].const_array(mfi); - auto const& dnp1_arr = diffData->Dnp1[lev].const_array(mfi); - auto const& dhat_arr = diffData->Dhat[lev].const_array(mfi); - auto const& rhoYdot = ldataR_p->I_R.const_array(mfi); - auto const& charge = ldataNLs_p->backgroundCharge.array(mfi); - amrex::Real factor = 1.0 / elemCharge; - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - charge(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; ++n) { - amrex::Real rhoYprov = - rhoYold(i, j, k, n) + - dt_int * (adv_arr(i, j, k, n) + - 0.5 * (dn_arr(i, j, k, n) - dnp1_arr(i, j, k, n)) + - dhat_arr(i, j, k, n) + rhoYdot(i, j, k, n)); - rhoYprov = amrex::max(rhoYprov, 0.0); - charge(i, j, k) += zk[n] * rhoYprov; - } - charge(i, j, k) *= factor; - }); - } + auto const& state_old_ma = ldata_p->state.const_arrays(); + auto const& adv_ma = advData->AofS[lev].const_arrays(); + auto const& dn_ma = diffData->Dn[lev].const_arrays(); + auto const& dnp1_ma = diffData->Dnp1[lev].const_arrays(); + auto const& dhat_ma = diffData->Dhat[lev].const_arrays(); + auto const& rhoYdot_ma = ldataR_p->I_R.const_arrays(); + auto const& charge_ma = ldataNLs_p->backgroundCharge.arrays(); + constexpr amrex::Real factor = 1.0 / elemCharge; + amrex::ParallelFor( + ldataNLs_p->backgroundCharge, + [state_old_ma, adv_ma, dn_ma, dnp1_ma, dhat_ma, rhoYdot_ma, charge_ma, + dt_int, + zk = zk] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 rhoYold( + state_old_ma[box_no], FIRSTSPEC); + amrex::Array4 adv(adv_ma[box_no], FIRSTSPEC); + charge_ma[box_no](i, j, k) = 0.0; + for (int n = 0; n < NUM_SPECIES; ++n) { + amrex::Real rhoYprov = + rhoYold(i, j, k, n) + + dt_int * + (adv(i, j, k, n) + + 0.5 * (dn_ma[box_no](i, j, k, n) - dnp1_ma[box_no](i, j, k, n)) + + dhat_ma[box_no](i, j, k, n) + rhoYdot_ma[box_no](i, j, k, n)); + rhoYprov = amrex::max(rhoYprov, 0.0); + charge_ma[box_no](i, j, k) += zk[n] * rhoYprov; + } + charge_ma[box_no](i, j, k) *= factor; + }); } + amrex::Gpu::streamSynchronize(); } void @@ -480,34 +489,35 @@ PeleLM::nonLinearResidual( // Init the ghostcells too a_nlresid[lev]->setVal(0.0); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldataNLs_p->nlResid, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& I_R_nE = ldataR_p->I_R.const_array(mfi, NUM_SPECIES); - auto const& lapPhiV = laplacian[lev].const_array(mfi); - auto const& ne_diff = diffnE[lev].const_array(mfi); - auto const& ne_adv = advnE[lev].const_array(mfi); - auto const& ne_curr = nE[lev].const_array(mfi); - auto const& ne_old = ldataOld_p->state.const_array(mfi, NE); - auto const& charge = ldataNLs_p->backgroundCharge.const_array(mfi); - auto const& res_nE = a_nlresid[lev]->array(mfi, 0); - auto const& res_phiV = a_nlresid[lev]->array(mfi, 1); - amrex::Real scalLap = eps0 * epsr / elemCharge; - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - res_nE(i, j, k) = - ne_old(i, j, k) - ne_curr(i, j, k) + - a_dt * (ne_diff(i, j, k) + ne_adv(i, j, k) + I_R_nE(i, j, k)); - res_phiV(i, j, k) = - lapPhiV(i, j, k) * scalLap - ne_curr(i, j, k) + charge(i, j, k); - res_nE(i, j, k) *= -1.0; // NLresidual is -RHS - res_phiV(i, j, k) *= -1.0; // NLresidual is -RHS - }); - } + auto const& I_R_ma = ldataR_p->I_R.const_arrays(); + auto const& lapPhiV_ma = laplacian[lev].const_arrays(); + auto const& ne_diff_ma = diffnE[lev].const_arrays(); + auto const& ne_adv_ma = advnE[lev].const_arrays(); + auto const& ne_curr_ma = nE[lev].const_arrays(); + auto const& state_old_ma = ldataOld_p->state.const_arrays(); + auto const& charge_ma = ldataNLs_p->backgroundCharge.const_arrays(); + auto const& res_ma = a_nlresid[lev]->arrays(); + constexpr amrex::Real scalLap = eps0 * epsr / elemCharge; + amrex::ParallelFor( + ldataNLs_p->nlResid, + [I_R_ma, lapPhiV_ma, ne_diff_ma, ne_adv_ma, ne_curr_ma, state_old_ma, + charge_ma, res_ma, + a_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 res_nE(res_ma[box_no], 0); + amrex::Array4 res_phiV(res_ma[box_no], 1); + amrex::Array4 I_R_nE(I_R_ma[box_no], NUM_SPECIES); + amrex::Array4 ne_old(state_old_ma[box_no], NE); + res_nE(i, j, k) = ne_old(i, j, k) - ne_curr_ma[box_no](i, j, k) + + a_dt * (ne_diff_ma[box_no](i, j, k) + + ne_adv_ma[box_no](i, j, k) + I_R_nE(i, j, k)); + res_phiV(i, j, k) = lapPhiV_ma[box_no](i, j, k) * scalLap - + ne_curr_ma[box_no](i, j, k) + + charge_ma[box_no](i, j, k); + res_nE(i, j, k) *= -1.0; // NLresidual is -RHS + res_phiV(i, j, k) *= -1.0; // NLresidual is -RHS + }); } + amrex::Gpu::streamSynchronize(); // WriteDebugPlotFile(GetVecOfConstPtrs(a_nlresid),"UnscalednlResid"); // /* @@ -575,32 +585,29 @@ PeleLM::getAdvectionTerm( auto ldataNLs_p = getLevelDataNLSolvePtr(lev); // Get the face centered electron mobility - int doZeroVisc = 0; + constexpr int doZeroVisc = 0; amrex::Array mobE_ec = getDiffusivity(lev, 0, 1, doZeroVisc, bcRecnE, ldata_p->mobE_cc); // Get the electron effective velocity for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldataNLs_p->uEffnE[idim], amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& ueff = ldataNLs_p->uEffnE[idim].array(mfi); - auto const& umac = ldataNLs_p->umac[idim].const_array(mfi); - auto const& gphi_c = a_gPhiVCur[lev][idim]->const_array(mfi); - auto const& gphi_o = ldataNLs_p->gPhiVOld[idim].const_array(mfi); - auto const& kappa_e = mobE_ec[idim].const_array(mfi); - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - ueff(i, j, k) = - umac(i, j, k) - kappa_e(i, j, k) * -1.0 * 0.5 * - (gphi_c(i, j, k) + gphi_o(i, j, k)); - }); - } + auto const& ueff_ma = ldataNLs_p->uEffnE[idim].arrays(); + auto const& umac_ma = ldataNLs_p->umac[idim].const_arrays(); + auto const& gphi_c_ma = a_gPhiVCur[lev][idim]->const_arrays(); + auto const& gphi_o_ma = ldataNLs_p->gPhiVOld[idim].const_arrays(); + auto const& kappa_e_ma = mobE_ec[idim].const_arrays(); + amrex::ParallelFor( + ldataNLs_p->uEffnE[idim], + [ueff_ma, umac_ma, gphi_c_ma, gphi_o_ma, kappa_e_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + ueff_ma[box_no](i, j, k) = + umac_ma[box_no](i, j, k) - + kappa_e_ma[box_no](i, j, k) * -1.0 * 0.5 * + (gphi_c_ma[box_no](i, j, k) + gphi_o_ma[box_no](i, j, k)); + }); } } + amrex::Gpu::streamSynchronize(); // Average down the Ueff /* @@ -773,7 +780,8 @@ PeleLM::getAdvectionFluxes( const auto bc_hi = bcrec.hi(0); amrex::ParallelFor( - xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + xbx, [bc_lo, bc_hi, edomain, ne_arr, xstate, u, order, domain, + xbx] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { int idx[3] = {i, j, k}; bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && @@ -804,7 +812,8 @@ PeleLM::getAdvectionFluxes( const auto bc_hi = bcrec.hi(1); amrex::ParallelFor( - ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ybx, [bc_lo, bc_hi, edomain, domain, order, ystate, ne_arr, v, + ybx] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { int idx[3] = {i, j, k}; bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && @@ -835,7 +844,8 @@ PeleLM::getAdvectionFluxes( const auto bc_hi = bcrec.hi(2); amrex::ParallelFor( - zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + zbx, [bc_lo, bc_hi, edomain, zstate, order, ne_arr, w, zbx, + domain] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { int idx[3] = {i, j, k}; bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && @@ -862,17 +872,17 @@ PeleLM::getAdvectionFluxes( // Computing fluxes amrex::ParallelFor( - xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + xbx, [xflux, u, xstate] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { xflux(i, j, k) = u(i, j, k) * xstate(i, j, k); }); #if (AMREX_SPACEDIM > 1) amrex::ParallelFor( - ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ybx, [yflux, v, ystate] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { yflux(i, j, k) = v(i, j, k) * ystate(i, j, k); }); #if (AMREX_SPACEDIM == 3) amrex::ParallelFor( - zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + zbx, [zflux, w, zstate] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { zflux(i, j, k) = w(i, j, k) * zstate(i, j, k); }); #endif @@ -963,6 +973,33 @@ PeleLM::setUpPrecond( Schur_nEKe.define(grids[lev], dmap[lev], 1, 1); } + auto const& neke_ma = nEKe.arrays(); + auto const& kappaE_ma = ldata_p->mobE_cc.arrays(); + auto const& ne_arr_ma = a_nE[lev]->const_arrays(); + auto const& Schur_ma = + (m_ef_PC_approx == 2) ? Schur_nEKe.arrays() : nEKe.arrays(); + auto const& diffOp_diag_ma = + (m_ef_PC_approx == 2) ? diagDiffOp[lev].arrays() : nEKe.arrays(); + const int do_Schur = (m_ef_PC_approx == 2) ? 1 : 0; + + amrex::ParallelFor( + nEKe, nEKe.nGrowVect(), + [neke_ma, kappaE_ma, + ne_arr_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + neke_ma[box_no](i, j, k) = + kappaE_ma[box_no](i, j, k) * ne_arr_ma[box_no](i, j, k); + }); + if (do_Schur == 1) { + amrex::ParallelFor( + nEKe, nEKe.nGrowVect(), + [neke_ma, Schur_ma, diffOp_diag_ma, + a_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + Schur_ma[box_no](i, j, k) = -a_dt * 0.5 * neke_ma[box_no](i, j, k) / + diffOp_diag_ma[box_no](i, j, k); + }); + } + amrex::Gpu::streamSynchronize(); + /* #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif @@ -978,13 +1015,15 @@ PeleLM::setUpPrecond( (m_ef_PC_approx == 2) ? diagDiffOp[lev].array(mfi) : nEKe.array(mfi); int do_Schur = (m_ef_PC_approx == 2) ? 1 : 0; amrex::ParallelFor( - gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + gbx, [] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { neke(i, j, k) = kappaE(i, j, k) * ne_arr(i, j, k); if (do_Schur) { Schur(i, j, k) = -a_dt * 0.5 * neke(i, j, k) / diffOp_diag(i, j, k); } }); - } + + } + */ // Upwinded edge neKe values amrex::Array neKe_ec = getUpwindedEdge( @@ -1061,7 +1100,8 @@ PeleLM::getUpwindedEdge( const auto bc_lo = bcrec[0].lo(idim); const auto bc_hi = bcrec[0].hi(idim); amrex::ParallelFor( - ebx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ebx, [bc_lo, bc_hi, idim, edomain, ecUeff, ccVal, + ecVal] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { int idx[3] = {i, j, k}; bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && diff --git a/Source/Plasma/PeleLMeX_EFReactions.cpp b/Source/Plasma/PeleLMeX_EFReactions.cpp index 033e9954b..b1256542f 100644 --- a/Source/Plasma/PeleLMeX_EFReactions.cpp +++ b/Source/Plasma/PeleLMeX_EFReactions.cpp @@ -7,21 +7,19 @@ PeleLM::computeInstantaneousReactionRateEF( { auto ldata_p = getLevelDataPtr(lev, a_time); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& rhoY = ldata_p->state.const_array(mfi, FIRSTSPEC); - auto const& rhoH = ldata_p->state.const_array(mfi, RHOH); - auto const& nE = ldata_p->state.const_array(mfi, NE); - auto const& T = ldata_p->state.const_array(mfi, TEMP); - auto const& rhoYdot = a_I_R->array(mfi); - auto const& nEdot = a_I_R->array(mfi, NUM_SPECIES); + auto const& state_ma = ldata_p->state.const_arrays(); + auto const& I_R_ma = a_I_R->arrays(); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::ParallelFor( + ldata_p->state, [state_ma, I_R_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); + amrex::Array4 rhoH(state_ma[box_no], RHOH); + amrex::Array4 nE(state_ma[box_no], NE); + amrex::Array4 T(state_ma[box_no], TEMP); + amrex::Array4 rhoYdot(I_R_ma[box_no], 0); + amrex::Array4 nEdot(I_R_ma[box_no], NE); reactionRateRhoY_EF(i, j, k, rhoY, rhoH, T, nE, rhoYdot, nEdot); }); - } + amrex::Gpu::streamSynchronize(); } diff --git a/Source/Plasma/PeleLMeX_EFTimeStep.cpp b/Source/Plasma/PeleLMeX_EFTimeStep.cpp index 608cd3675..b8beb9996 100644 --- a/Source/Plasma/PeleLMeX_EFTimeStep.cpp +++ b/Source/Plasma/PeleLMeX_EFTimeStep.cpp @@ -23,103 +23,67 @@ PeleLM::estEFIonsDt(const TimeStamp a_time) const auto dxinv = Geom(lev).InvCellSizeArray(); const auto domain = Geom(lev).Domain(); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& phiV = ldata_p->state.const_array(mfi, PHIV); - auto const& efield = efield_cc.array(mfi, 0); - - // X - auto bc_lo = bcRecPhiV[0].lo(0); - auto bc_hi = bcRecPhiV[0].hi(0); - amrex::Real factor = -0.5 * dxinv[0]; - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - bool on_lo = - ((bc_lo == amrex::BCType::ext_dir) && i <= domain.smallEnd(0)); - bool on_hi = - ((bc_hi == amrex::BCType::ext_dir) && i >= domain.bigEnd(0)); - efield(i, j, k, 0) = factor * (phiV(i + 1, j, k) - phiV(i - 1, j, k)); - if (on_lo) - efield(i, j, k, 0) = factor * (phiV(i + 1, j, k) + phiV(i, j, k) - - 2.0 * phiV(i - 1, j, k)); - if (on_hi) - efield(i, j, k, 0) = factor * (2.0 * phiV(i + 1, j, k) - - phiV(i, j, k) - phiV(i - 1, j, k)); - }); - -#if (AMREX_SPACEDIM > 1) - // Y - bc_lo = bcRecPhiV[0].lo(1); - bc_hi = bcRecPhiV[0].hi(1); - factor = -0.5 * dxinv[1]; - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - bool on_lo = - ((bc_lo == amrex::BCType::ext_dir) && j <= domain.smallEnd(1)); - bool on_hi = - ((bc_hi == amrex::BCType::ext_dir) && j >= domain.bigEnd(1)); - efield(i, j, k, 1) = factor * (phiV(i, j + 1, k) - phiV(i, j - 1, k)); - if (on_lo) - efield(i, j, k, 1) = factor * (phiV(i, j + 1, k) + phiV(i, j, k) - - 2.0 * phiV(i, j - 1, k)); - if (on_hi) - efield(i, j, k, 1) = factor * (2.0 * phiV(i, j + 1, k) - - phiV(i, j, k) - phiV(i, j - 1, k)); - }); + auto const& state_ma = ldata_p->state.const_arrays(); + auto const& efield_ma = efield_cc.arrays(); -#if (AMREX_SPACEDIM > 2) - // Z - bc_lo = bcRecPhiV[0].lo(2); - bc_hi = bcRecPhiV[0].hi(2); - factor = -0.5 * dxinv[2]; + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + auto bc_lo = bcRecPhiV[0].lo(idim); + auto bc_hi = bcRecPhiV[0].hi(idim); + const amrex::Real factor = -0.5 * dxinv[idim]; amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - bool on_lo = - ((bc_lo == amrex::BCType::ext_dir) && k <= domain.smallEnd(2)); - bool on_hi = - ((bc_hi == amrex::BCType::ext_dir) && k >= domain.bigEnd(2)); - efield(i, j, k, 2) = factor * (phiV(i, j, k + 1) - phiV(i, j, k - 1)); - if (on_lo) - efield(i, j, k, 2) = factor * (phiV(i, j, k + 1) + phiV(i, j, k) - - 2.0 * phiV(i, j, k - 1)); - if (on_hi) - efield(i, j, k, 2) = factor * (2.0 * phiV(i, j, k + 1) - - phiV(i, j, k) - phiV(i, j, k - 1)); + ldata_p->state, + [bc_lo, bc_hi, efield_ma, state_ma, factor, domain, + idim] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + int idx[3] = {i, j, k}; + amrex::Array4 phiV(state_ma[box_no], PHIV); + const bool on_lo = + ((bc_lo == amrex::BCType::ext_dir) && + idx[idim] <= domain.smallEnd(idim)); + const bool on_hi = + ((bc_hi == amrex::BCType::ext_dir) && + idx[idim] >= domain.bigEnd(idim)); + // use idx for idxp + idx[idim] += 1; + int idxm[3] = {i, j, k}; + idxm[idim] -= 1; + efield_ma[box_no](i, j, k, idim) = + factor * + (phiV(idx[0], idx[1], idx[2]) - phiV(idxm[0], idxm[1], idxm[2])); + if (on_lo) { + efield_ma[box_no](i, j, k, idim) = + factor * (phiV(idx[0], idx[1], idx[2]) + phiV(i, j, k) - + 2.0 * phiV(idxm[0], idxm[1], idxm[2])); + } + if (on_hi) { + efield_ma[box_no](i, j, k, idim) = + factor * (2.0 * phiV(idx[0], idx[1], idx[2]) - phiV(i, j, k) - + phiV(idxm[0], idxm[1], idxm[2])); + } }); -#endif -#endif } + auto const& efield_const_ma = efield_cc.const_arrays(); + auto const& mob_cc_ma = ldata_p->mob_cc.const_arrays(); + auto const& uDrMax_ma = driftVelMax_cc.arrays(); // Get cell centered max effective velocities across // all dimension/ions -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& vel = ldata_p->state.const_array(mfi, VELX); - auto const& efield = efield_cc.const_array(mfi); - auto const& mob_cc = ldata_p->mob_cc.const_array(mfi); - auto const& uDrMax = driftVelMax_cc.array(mfi); - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - amrex::Real maxVel = 0.0; - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - for (int n = 0; n < NUM_IONS; ++n) { - amrex::Real ueff = - vel(i, j, k, idim) + mob_cc(i, j, k, n) * efield(i, j, k, idim); - maxVel = amrex::max(maxVel, std::abs(ueff)); - } + amrex::ParallelFor( + ldata_p->state, + [state_ma, efield_const_ma, mob_cc_ma, + uDrMax_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 vel(state_ma[box_no], VELX); + amrex::Real maxVel = 0.0; + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + for (int n = 0; n < NUM_IONS; ++n) { + amrex::Real ueff = + vel(i, j, k, idim) + mob_cc_ma[box_no](i, j, k, n) * + efield_const_ma[box_no](i, j, k, idim); + maxVel = amrex::max(maxVel, std::abs(ueff)); } - uDrMax(i, j, k) = maxVel; - }); - } - + } + uDrMax_ma[box_no](i, j, k) = maxVel; + }); + amrex::Gpu::streamSynchronize(); const auto dx = Geom(lev).CellSizeArray(); amrex::Real cfl_lcl = m_cfl; estdt_lev = amrex::ReduceMin( diff --git a/Source/Plasma/PeleLMeX_EFTransport.cpp b/Source/Plasma/PeleLMeX_EFTransport.cpp index 7649cd620..0e8fb2f30 100644 --- a/Source/Plasma/PeleLMeX_EFTransport.cpp +++ b/Source/Plasma/PeleLMeX_EFTransport.cpp @@ -9,25 +9,25 @@ PeleLM::calcEFTransport(const TimeStamp a_time) for (int lev = 0; lev <= finest_level; ++lev) { auto ldata_p = getLevelDataPtr(lev, a_time); auto dxinv = Geom(lev).InvCellSizeArray(); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldata_p->diffE_cc, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& gbx = mfi.growntilebox(); - auto const& mobE = ldata_p->mobE_cc.array(mfi); - auto const& diffE = ldata_p->diffE_cc.array(mfi); - auto const& rhoY = ldata_p->state.const_array(mfi, FIRSTSPEC); - auto const& phiV = ldata_p->state.const_array(mfi, PHIV); - auto const& T = ldata_p->state.const_array(mfi, TEMP); - amrex::Real factor = PP_RU_MKS / (Na * elemCharge); - const auto useTab = m_electronKappaTab; - const auto fixedKe = m_fixedKappaE; - amrex::ParallelFor( - gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - getKappaE(i, j, k, useTab, fixedKe, dxinv, rhoY, phiV, T, mobE); - getDiffE(i, j, k, factor, T, mobE, diffE); - }); - } + + auto const& mobE_ma = ldata_p->mobE_cc.arrays(); + auto const& diffE_ma = ldata_p->diffE_cc.arrays(); + auto const& state_ma = ldata_p->state.const_arrays(); + const auto useTab = m_electronKappaTab; + const auto fixedKe = m_fixedKappaE; + + amrex::ParallelFor( + ldata_p->diffE_cc, ldata_p->diffE_cc.nGrowVect(), + [useTab, fixedKe, dxinv, mobE_ma, diffE_ma, + state_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + constexpr amrex::Real factor = PP_RU_MKS / (Na * elemCharge); + amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); + amrex::Array4 phiV(state_ma[box_no], PHIV); + amrex::Array4 T(state_ma[box_no], TEMP); + getKappaE( + i, j, k, useTab, fixedKe, dxinv, rhoY, phiV, T, mobE_ma[box_no]); + getDiffE(i, j, k, factor, T, mobE_ma[box_no], diffE_ma[box_no]); + }); } + amrex::Gpu::streamSynchronize(); } diff --git a/Source/Plasma/PeleLMeX_EFUtils.cpp b/Source/Plasma/PeleLMeX_EFUtils.cpp index 5b582a153..4e67e6d2d 100644 --- a/Source/Plasma/PeleLMeX_EFUtils.cpp +++ b/Source/Plasma/PeleLMeX_EFUtils.cpp @@ -193,9 +193,11 @@ PeleLM::addLorentzVelForces( amrex::GpuArray blo = bx.loVect3d(); amrex::GpuArray bhi = bx.hiVect3d(); - amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - addLorentzForce(i, j, k, blo, bhi, a_time, dx, zk, rhoY, nE, phiV, force); - }); + amrex::ParallelFor( + bx, [blo, bhi, a_time, dx, zk = zk, rhoY, nE, phiV, + force] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + addLorentzForce(i, j, k, blo, bhi, a_time, dx, zk, rhoY, nE, phiV, force); + }); } void @@ -208,43 +210,35 @@ PeleLM::initializeElectronNeutral() // Get level data new time pointer auto ldata_p = getLevelDataPtr(lev, AmrNewTime); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& rho = ldata_p->state.array(mfi, DENSITY); - auto const& rhoY = ldata_p->state.array(mfi, FIRSTSPEC); - auto const& rhoH = ldata_p->state.array(mfi, RHOH); - auto const& temp = ldata_p->state.array(mfi, TEMP); - auto const& nE = ldata_p->state.array(mfi, NE); - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - initElecNeutral(i, j, k, rho, rhoY, rhoH, temp, nE, *lprobparm); - }); - } + auto const& state_ma = ldata_p->state.arrays(); + + amrex::ParallelFor( + ldata_p->state, [state_ma, lprobparm] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + amrex::Array4 rho(state_ma[box_no], DENSITY); + amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); + amrex::Array4 rhoH(state_ma[box_no], RHOH); + amrex::Array4 temp(state_ma[box_no], TEMP); + amrex::Array4 nE(state_ma[box_no], NE); + initElecNeutral(i, j, k, rho, rhoY, rhoH, temp, nE, *lprobparm); + }); // Convert I_R(Y_nE) into I_R(nE) and set I_R(Y_nE) to zero auto ldataR_p = getLevelDataReactPtr(lev); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldataR_p->I_R, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& YnEdot = ldataR_p->I_R.array(mfi, E_ID); - auto const& nEdot = ldataR_p->I_R.array(mfi, NUM_SPECIES); - auto eos = pele::physics::PhysicsType::eos(); - amrex::Real invmwt[NUM_SPECIES] = {0.0}; - eos.inv_molecular_weight(invmwt); - amrex::ParallelFor( - bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - nEdot(i, j, k) = YnEdot(i, j, k) * Na * invmwt[E_ID] * 1.0e3; - YnEdot(i, j, k) = 0.0; - }); - } + auto const& I_R_ma = ldataR_p->I_R.arrays(); + auto eos = pele::physics::PhysicsType::eos(); + amrex::Real invmwt[NUM_SPECIES] = {0.0}; + eos.inv_molecular_weight(invmwt); + amrex::ParallelFor( + ldataR_p->I_R, [I_R_ma, invmwt] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + amrex::Array4 YnEdot(I_R_ma[box_no], E_ID); + amrex::Array4 nEdot(I_R_ma[box_no], NUM_SPECIES); + nEdot(i, j, k) = YnEdot(i, j, k) * Na * invmwt[E_ID] * 1.0e3; + YnEdot(i, j, k) = 0.0; + }); } + amrex::Gpu::streamSynchronize(); } void From 43649b3ddaebb58deaeae403a940e407b1b180b7 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Tue, 19 Aug 2025 20:06:09 +0200 Subject: [PATCH 46/87] missing capture --- Source/PeleLMeX_DeriveFunc.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/PeleLMeX_DeriveFunc.cpp b/Source/PeleLMeX_DeriveFunc.cpp index bfbc441a4..1f6222b04 100644 --- a/Source/PeleLMeX_DeriveFunc.cpp +++ b/Source/PeleLMeX_DeriveFunc.cpp @@ -785,7 +785,7 @@ pelelmex_derQcrit( } else if (typ == amrex::FabType::singlevalued) { const auto& flag_fab = flags.const_array(); amrex::ParallelFor( - bx, [qcrit_arr, flag_fab, idx, idy + bx, [qcrit_arr, dat_arr, flag_fab, idx, idy #if (AMREX_SPACEDIM == 3) , idz @@ -920,8 +920,7 @@ pelelmex_derQcrit( for (int dim2 = 0; dim2 < AMREX_SPACEDIM; ++dim2) { const amrex::Real Ohm = 0.5 * (gradU(dim1, dim2) - gradU(dim2, dim1)); - const amrex::Real Sij = - 0.5 * (gradU(dim1, dim2) + gradU(dim2, dim1)); + amrex::Real Sij = 0.5 * (gradU(dim1, dim2) + gradU(dim2, dim1)); if (dim1 == dim2) { Sij -= divU / static_cast(AMREX_SPACEDIM); } From 6285da4b0ace764e452ab96b8d574945bfd37179 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Tue, 19 Aug 2025 23:47:49 +0200 Subject: [PATCH 47/87] indexing --- Source/PeleLMeX_DeriveFunc.cpp | 1 + Source/PeleLMeX_TransportProp.cpp | 8 ++++---- Source/Plasma/PeleLMeX_EFReactions.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/PeleLMeX_DeriveFunc.cpp b/Source/PeleLMeX_DeriveFunc.cpp index 1f6222b04..02f262d1d 100644 --- a/Source/PeleLMeX_DeriveFunc.cpp +++ b/Source/PeleLMeX_DeriveFunc.cpp @@ -468,6 +468,7 @@ pelelmex_dervort( int /*level*/) { + amrex::ignore_unused(ncomp); AMREX_ASSERT(derfab.box().contains(bx)); AMREX_ASSERT(statefab.box().contains(bx)); AMREX_ASSERT(derfab.nComp() >= dcomp + ncomp); diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index f7e4656af..6d2b66e72 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -1,4 +1,4 @@ -#include + #include #include #include #include @@ -106,7 +106,7 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) m_les_cs_smag * m_les_cs_smag * l_scale * l_scale; amrex::ParallelFor( ldata_p->visc_turb_fc[idim], ldata_p->visc_turb_fc[idim].nGrowVect(), - [prefact, idim, velgrad_arr, dens_arr, mut_arr + [prefact, velgrad_arr, dens_arr, mut_arr #ifdef AMREX_USE_EB , vfrac @@ -136,7 +136,7 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) m_les_cm_wale * m_les_cm_wale * l_scale * l_scale; amrex::ParallelFor( ldata_p->visc_turb_fc[idim], ldata_p->visc_turb_fc[idim].nGrowVect(), - [prefact, idim, velgrad_arr, dens_arr, mut_arr + [prefact, velgrad_arr, dens_arr, mut_arr #ifdef AMREX_USE_EB , vfrac @@ -166,7 +166,7 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) m_les_cs_sigma * m_les_cs_sigma * l_scale * l_scale; amrex::ParallelFor( ldata_p->visc_turb_fc[idim], ldata_p->visc_turb_fc[idim].nGrowVect(), - [prefact, idim, velgrad_arr, dens_arr, mut_arr + [prefact, velgrad_arr, dens_arr, mut_arr #ifdef AMREX_USE_EB , vfrac diff --git a/Source/Plasma/PeleLMeX_EFReactions.cpp b/Source/Plasma/PeleLMeX_EFReactions.cpp index b1256542f..c45fd09d1 100644 --- a/Source/Plasma/PeleLMeX_EFReactions.cpp +++ b/Source/Plasma/PeleLMeX_EFReactions.cpp @@ -18,7 +18,7 @@ PeleLM::computeInstantaneousReactionRateEF( amrex::Array4 nE(state_ma[box_no], NE); amrex::Array4 T(state_ma[box_no], TEMP); amrex::Array4 rhoYdot(I_R_ma[box_no], 0); - amrex::Array4 nEdot(I_R_ma[box_no], NE); + amrex::Array4 nEdot(I_R_ma[box_no], NUM_SPECIES); reactionRateRhoY_EF(i, j, k, rhoY, rhoH, T, nE, rhoYdot, nEdot); }); amrex::Gpu::streamSynchronize(); From bea3d82ec196adcdf2ef5d1b1cd377a79ea896a6 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Tue, 19 Aug 2025 23:49:00 +0200 Subject: [PATCH 48/87] rogue space --- Source/PeleLMeX_TransportProp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index 6d2b66e72..7901ea3e4 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -1,4 +1,4 @@ - #include +#include #include #include #include From 90327e4d5aa81878d78d67a19041f2ec1bcaf218 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Wed, 20 Aug 2025 00:36:58 +0200 Subject: [PATCH 49/87] formatting and capture --- .clang-tidy | 2 +- Source/PeleLMeX_DeriveFunc.cpp | 3 +-- Source/PeleLMeX_TransportProp.cpp | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 6e9188e4e..d357cce9c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,7 +7,7 @@ Checks: 'bugprone-*, clang-diagnostic-*, clang-analyzer-*, corecppguidelines-*, - cppcoreguidelines-avoid-capture-default, + cppcoreguidelines-avoid-capture-default, modernize-*, -modernize-avoid-c-arrays, -modernize-use-trailing-return-type, diff --git a/Source/PeleLMeX_DeriveFunc.cpp b/Source/PeleLMeX_DeriveFunc.cpp index 02f262d1d..8e7dd3da0 100644 --- a/Source/PeleLMeX_DeriveFunc.cpp +++ b/Source/PeleLMeX_DeriveFunc.cpp @@ -466,9 +466,8 @@ pelelmex_dervort( amrex::Real /*time*/, const amrex::Vector& /*bcrec*/, int /*level*/) - { - amrex::ignore_unused(ncomp); + amrex::ignore_unused(ncomp); AMREX_ASSERT(derfab.box().contains(bx)); AMREX_ASSERT(statefab.box().contains(bx)); AMREX_ASSERT(derfab.nComp() >= dcomp + ncomp); diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index 7901ea3e4..6ad6174f7 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -109,7 +109,7 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) [prefact, velgrad_arr, dens_arr, mut_arr #ifdef AMREX_USE_EB , - vfrac + vfrac, idim #endif ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { getTurbViscSmagorinsky( @@ -139,7 +139,7 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) [prefact, velgrad_arr, dens_arr, mut_arr #ifdef AMREX_USE_EB , - vfrac + vfrac, idim #endif ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { getTurbViscWALE( @@ -169,7 +169,7 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) [prefact, velgrad_arr, dens_arr, mut_arr #ifdef AMREX_USE_EB , - vfrac + vfrac, idim #endif ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { getTurbViscSigma( From aa9a88e05e12337c58cc930553186708c95b4f09 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Wed, 20 Aug 2025 01:03:26 +0200 Subject: [PATCH 50/87] more const and duplicates --- Source/PeleLMeX.H | 94 +++++++++++++++--------------- Source/PeleLMeX_Utils.cpp | 116 +++++++++++++++++++------------------- 2 files changed, 104 insertions(+), 106 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index fff9c7b88..50c8e2c18 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -1270,104 +1270,104 @@ public: // flux divergence void fluxDivergence( const amrex::Vector& a_divergence, - int div_comp, + const int div_comp, const amrex::Vector>& a_fluxes, - int flux_comp, - int ncomp, - int intensiveFluxes, - amrex::Real scale); + const int flux_comp, + const int ncomp, + const int intensiveFluxes, + const amrex::Real scale); void fluxDivergence( const amrex::Vector& a_divergence, - int div_comp, + const int div_comp, const amrex::Vector>& a_fluxes, - int flux_comp, + const int flux_comp, const amrex::Vector& a_EBfluxes, - int ebflux_comp, - int ncomp, - int intensiveFluxes, - amrex::Real scale); + const int ebflux_comp, + const int ncomp, + const int intensiveFluxes, + const amrex::Real scale); void fluxDivergenceRD( const amrex::Vector& a_state, - int state_comp, + const int state_comp, const amrex::Vector& a_divergence, - int div_comp, + const int div_comp, const amrex::Vector>& a_fluxes, - int flux_comp, + const int flux_comp, const amrex::Vector& a_EBfluxes, - int ebflux_comp, - int ncomp, - int intensiveFluxes, + const int ebflux_comp, + const int ncomp, + const int intensiveFluxes, const amrex::BCRec* state_bc_d, const amrex::Real& scale, const amrex::Real& a_dt); void advFluxDivergence( - int a_lev, + const int a_lev, amrex::MultiFab& a_divergence, - int div_comp, + const int div_comp, amrex::MultiFab& a_divu, const amrex::Array& a_fluxes, - int flux_comp, + const int flux_comp, const amrex::Array& a_faceState, - int face_comp, - int ncomp, + const int face_comp, + const int ncomp, int const* l_conserv_d, const amrex::Geometry& a_geom, - amrex::Real scale, - bool fluxes_are_area_weighted) const; + const amrex::Real scale, + const bool fluxes_are_area_weighted) const; #ifdef AMREX_USE_EB void advFluxDivergence( - int a_lev, + const int a_lev, amrex::MultiFab& a_divergence, - int div_comp, + const int div_comp, amrex::MultiFab& a_divu, const amrex::Array& a_fluxes, - int flux_comp, + const int flux_comp, const amrex::Array& a_faceState, - int face_comp, + const int face_comp, const amrex::MultiFab* a_EBvelocity, const amrex::MultiFab* a_EBvalue, - int ncomp, + const int ncomp, int const* l_conserv_d, const amrex::Geometry& a_geom, - amrex::Real scale, - bool fluxes_are_area_weighted) const; + const amrex::Real scale, + const bool fluxes_are_area_weighted) const; #endif void extFluxDivergenceLevel( - int lev, + const int lev, amrex::MultiFab& a_divergence, - int div_comp, + const int div_comp, const amrex::Array& a_fluxes, - int flux_comp, - int ncomp, - amrex::Real scale); + const int flux_comp, + const int ncomp, + const amrex::Real scale); void intFluxDivergenceLevel( - int lev, + const int lev, amrex::MultiFab& a_divergence, - int div_comp, + const int div_comp, const amrex::Array& a_fluxes, - int flux_comp, - int ncomp, - amrex::Real scale); + const int flux_comp, + const int ncomp, + const amrex::Real scale); void intFluxDivergenceLevelEB( - int lev, + const int lev, amrex::MultiFab& a_divergence, - int div_comp, + const int div_comp, const amrex::Array& a_fluxes, - int flux_comp, + const int flux_comp, const amrex::MultiFab* a_EBfluxes, - int ebflux_comp, - int ncomp, - amrex::Real scale); + const int ebflux_comp, + const int ncomp, + const amrex::Real scale); void floorSpecies(const PeleLM::TimeStamp a_time); diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 1f8ee9458..78bcecf0a 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -70,11 +70,11 @@ writeBuildInfo() void PeleLM::fluxDivergence( const amrex::Vector& a_divergence, - int div_comp, + const int div_comp, const amrex::Vector>& a_fluxes, - int flux_comp, - int ncomp, - int intensiveFluxes, + const int flux_comp, + const int ncomp, + const int intensiveFluxes, amrex::Real scale) { BL_PROFILE("PeleLMeX::fluxDivergence()"); @@ -97,14 +97,14 @@ PeleLM::fluxDivergence( void PeleLM::fluxDivergence( const amrex::Vector& a_divergence, - int div_comp, + const int div_comp, const amrex::Vector>& a_fluxes, - int flux_comp, + const int flux_comp, const amrex::Vector& a_EBfluxes, - int ebflux_comp, - int ncomp, - int intensiveFluxes, - amrex::Real scale) + const int ebflux_comp, + const int ncomp, + const int intensiveFluxes, + const amrex::Real scale) { BL_PROFILE("PeleLMeX::fluxDivergence()"); @@ -127,26 +127,26 @@ PeleLM::fluxDivergence( void PeleLM::fluxDivergenceRD( const amrex::Vector& a_state, - int state_comp, + const int state_comp, const amrex::Vector& a_divergence, - int div_comp, + const int div_comp, const amrex::Vector>& a_fluxes, - int flux_comp, + const int flux_comp, const amrex::Vector& a_EBfluxes, - int ebflux_comp, - int ncomp, - int intensiveFluxes, + const int ebflux_comp, + const int ncomp, + const int intensiveFluxes, const amrex::BCRec* state_bc_d, const amrex::Real& scale, const amrex::Real& a_dt) { BL_PROFILE("PeleLMeX::fluxDivergenceRD()"); #ifdef AMREX_USE_EB - int have_ebfluxes = (a_EBfluxes.empty()) ? 0 : 1; + const int have_ebfluxes = (a_EBfluxes.empty()) ? 0 : 1; for (int lev = 0; lev <= finest_level; ++lev) { //---------------------------------------------------------------- // Use a temporary MF to hold divergence before redistribution - int nGrow_divTmp = 3; + constexpr int nGrow_divTmp = 3; amrex::MultiFab divTmp( grids[lev], dmap[lev], ncomp, nGrow_divTmp, amrex::MFInfo(), EBFactory(lev)); @@ -188,13 +188,13 @@ PeleLM::fluxDivergenceRD( void PeleLM::extFluxDivergenceLevel( - int lev, + const int lev, amrex::MultiFab& a_divergence, - int div_comp, + const int div_comp, const amrex::Array& a_fluxes, - int flux_comp, - int ncomp, - amrex::Real scale) + const int flux_comp, + const int ncomp, + const amrex::Real scale) { AMREX_ASSERT(a_divergence.nComp() >= div_comp + ncomp); @@ -281,13 +281,13 @@ PeleLM::extFluxDivergenceLevel( void PeleLM::intFluxDivergenceLevel( - int lev, + const int lev, amrex::MultiFab& a_divergence, - int div_comp, + const int div_comp, const amrex::Array& a_fluxes, - int flux_comp, - int ncomp, - amrex::Real scale) + const int flux_comp, + const int ncomp, + const amrex::Real scale) { AMREX_ASSERT(a_divergence.nComp() >= div_comp + ncomp); @@ -411,15 +411,15 @@ PeleLM::intFluxDivergenceLevel( void PeleLM::intFluxDivergenceLevelEB( - int lev, + const int lev, amrex::MultiFab& a_divergence, - int div_comp, + const int div_comp, const amrex::Array& a_fluxes, - int flux_comp, + const int flux_comp, const amrex::MultiFab* a_EBfluxes, - int ebflux_comp, - int ncomp, - amrex::Real scale) + const int ebflux_comp, + const int ncomp, + const amrex::Real scale) { AMREX_ASSERT(a_divergence.nComp() >= div_comp + ncomp); @@ -530,21 +530,20 @@ PeleLM::intFluxDivergenceLevelEB( } void -PeleLM:: - advFluxDivergence( // NOLINT(readability-convert-member-functions-to-static) - int a_lev, - amrex::MultiFab& a_divergence, - int div_comp, - amrex::MultiFab& a_divu, - const amrex::Array& a_fluxes, - int flux_comp, - const amrex::Array& a_faceState, - int face_comp, - int ncomp, - int const* l_conserv_d, - const amrex::Geometry& a_geom, - amrex::Real scale, - bool fluxes_are_area_weighted) const +PeleLM::advFluxDivergence( + const int a_lev, + amrex::MultiFab& a_divergence, + const int div_comp, + amrex::MultiFab& a_divu, + const amrex::Array& a_fluxes, + const int flux_comp, + const amrex::Array& a_faceState, + const int face_comp, + const int ncomp, + int const* l_conserv_d, + const amrex::Geometry& a_geom, + const amrex::Real scale, + const bool fluxes_are_area_weighted) const { BL_PROFILE("PeleLMeX::advFluxDivergence()"); @@ -694,21 +693,21 @@ PeleLM:: #ifdef AMREX_USE_EB void PeleLM::advFluxDivergence( - int a_lev, + const int a_lev, amrex::MultiFab& a_divergence, - int div_comp, + const int div_comp, amrex::MultiFab& a_divu, const amrex::Array& a_fluxes, - int flux_comp, + const int flux_comp, const amrex::Array& a_faceState, - int face_comp, + const int face_comp, const amrex::MultiFab* a_EBvelocity, const amrex::MultiFab* a_EBvalue, - int ncomp, + const int ncomp, int const* l_conserv_d, const amrex::Geometry& a_geom, - amrex::Real scale, - bool fluxes_are_area_weighted) const + const amrex::Real scale, + const bool fluxes_are_area_weighted) const { BL_PROFILE("PeleLM::advFluxDivergence()"); @@ -2209,7 +2208,7 @@ PeleLM::extendSignedDistance( // Iteratively compute the distance function in boxes, propagating across // boxes using ghost cells If needed, increase the number of loop to extend // the reach of the distance function - int nMaxLoop = 4; + constexpr int nMaxLoop = 4; for (int dloop = 1; dloop <= nMaxLoop; ++dloop) { #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) @@ -2223,11 +2222,10 @@ PeleLM::extendSignedDistance( } auto const& sd_cc = a_signDist->array(mfi); amrex::ParallelFor( - bx, [gbx, geomdata, a_extendFactor, sd_cc, + bx, [gbx, dx, a_extendFactor, sd_cc, maxSignedDist] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { const auto glo = amrex::lbound(gbx); const auto ghi = amrex::ubound(gbx); - const amrex::Real* dx = geomdata.CellSize(); amrex::Real extendedDist = dx[0] * a_extendFactor; if (sd_cc(i, j, k) >= maxSignedDist - 1e-12) { amrex::Real closestEBDist = 1e12; From a22edb27fa86961a511ed0a45d4b1d802f3feb9c Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Wed, 20 Aug 2025 01:38:18 +0200 Subject: [PATCH 51/87] more emplacing --- Source/PeleLMeX.H | 14 +++-- Source/PeleLMeX_Advection.cpp | 20 ++++--- Source/PeleLMeX_Diffusion.cpp | 65 +++++++++++++---------- Source/PeleLMeX_Evaluate.cpp | 23 ++++---- Source/PeleLMeX_UMac.cpp | 56 ++++++++++---------- Source/PeleLMeX_Utils.cpp | 18 ++++--- Source/Plasma/GMRES/MLGMRES.cpp | 14 ++--- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 79 ++++++++++++++++------------ 8 files changed, 163 insertions(+), 126 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 50c8e2c18..e17ea8c1e 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -1399,10 +1399,16 @@ public: void getActiveControlLowT(amrex::Real& a_coft); // Derived variable evaluation - std::unique_ptr - derive(const std::string& a_name, amrex::Real a_time, int lev, int nGrow); - std::unique_ptr - deriveComp(const std::string& a_name, amrex::Real a_time, int lev, int nGrow); + std::unique_ptr derive( + const std::string& a_name, + const amrex::Real a_time, + const int lev, + const int nGrow); + std::unique_ptr deriveComp( + const std::string& a_name, + const amrex::Real a_time, + const int lev, + const int nGrow); // Evaluate function void MLevaluate( diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index de70b18e1..f7a026660 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -9,16 +9,18 @@ PeleLM::computeVelocityAdvTerm(std::unique_ptr& advData) //---------------------------------------------------------------- // Create temporary containers constexpr int nGrow_force = 1; - amrex::Vector divtau(finest_level + 1); - amrex::Vector velForces(finest_level + 1); + amrex::Vector divtau; + divtau.reserve(finest_level + 1); + amrex::Vector velForces; + velForces.reserve(finest_level + 1); amrex::Vector> fluxes( finest_level + 1); amrex::Vector> faces( finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - divtau[lev].define( + divtau.emplace_back( grids[lev], dmap[lev], AMREX_SPACEDIM, 0, amrex::MFInfo(), Factory(lev)); - velForces[lev].define( + velForces.emplace_back( grids[lev], dmap[lev], AMREX_SPACEDIM, nGrow_force, amrex::MFInfo(), Factory(lev)); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { @@ -206,9 +208,10 @@ PeleLM::updateVelocity(std::unique_ptr& advData) { //---------------------------------------------------------------- // Compute t^n divTau - amrex::Vector divtau(finest_level + 1); + amrex::Vector divtau; + divtau.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - divtau[lev].define( + divtau.emplace_back( grids[lev], dmap[lev], AMREX_SPACEDIM, 0, amrex::MFInfo(), Factory(lev)); } constexpr int use_density = 0; @@ -219,9 +222,10 @@ PeleLM::updateVelocity(std::unique_ptr& advData) //---------------------------------------------------------------- // Get velocity forcing at half time including lagged grad P term constexpr int nGrow_force = 1; - amrex::Vector velForces(finest_level + 1); + amrex::Vector velForces; + velForces.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - velForces[lev].define(grids[lev], dmap[lev], AMREX_SPACEDIM, nGrow_force); + velForces.emplace_back(grids[lev], dmap[lev], AMREX_SPACEDIM, nGrow_force); } constexpr int add_gradP = 1; getVelForces( diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 30f50dd5b..43dcd12e7 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -90,10 +90,11 @@ PeleLM::computeDifferentialDiffusionTerms( } } #ifdef AMREX_USE_EB - amrex::Vector EBfluxes(finest_level + 1); + amrex::Vector EBfluxes; if (m_isothermalEB != 0) { + EBfluxes.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - EBfluxes[lev].define( + EBfluxes.emplace_back( grids[lev], dmap[lev], 1, nGrow, amrex::MFInfo(), Factory(lev)); } } @@ -496,13 +497,12 @@ PeleLM::computeDifferentialDiffusionFluxes( amrex::Vector spec_boundary; if (m_soret_boundary_override != 0) { - spec_boundary.resize(finest_level + 1); + spec_boundary.reserve(finest_level + 1); // this is the same regardless of lagged or not for (int lev = 0; lev <= finest_level; ++lev) { - auto* ldata_p = getLevelDataPtr(lev, a_time); - spec_boundary[lev].define( + spec_boundary.emplace_back( grids[lev], dmap[lev], NUM_SPECIES, 1, amrex::MFInfo(), Factory(lev)); - + auto* ldata_p = getLevelDataPtr(lev, a_time); // if we have a mix of Dirichlet and Isothermal walls, we need to give // Dirichlet boundaries and divide by density since diffuse_scalar doesn't // touch this boundary MF @@ -608,10 +608,11 @@ PeleLM::computeDifferentialDiffusionFluxes( if (m_isothermalEB != 0) { AMREX_ASSERT(!a_EBfluxes.empty()); // Set up EB dirichlet value and diffusivity - amrex::Vector EBdiff(finest_level + 1); + amrex::Vector EBdiff; + EBdiff.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - EBdiff[lev].define( + EBdiff.emplace_back( grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), EBFactory(lev)); getEBDiff(lev, a_time, EBdiff[lev], NUM_SPECIES); } @@ -1105,10 +1106,11 @@ PeleLM::differentialDiffusionUpdate( } } #ifdef AMREX_USE_EB - amrex::Vector EBfluxes(finest_level + 1); + amrex::Vector EBfluxes; if (m_isothermalEB != 0) { + EBfluxes.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - EBfluxes[lev].define( + EBfluxes.emplace_back( grids[lev], dmap[lev], 1, nGrow, amrex::MFInfo(), Factory(lev)); } } @@ -1154,11 +1156,11 @@ PeleLM::differentialDiffusionUpdate( auto bcRecAux = fetchBCRecAuxArray(0, m_nAux); amrex::Vector spec_boundary; if (m_soret_boundary_override != 0) { - spec_boundary.resize(finest_level + 1); + spec_boundary.reserve(finest_level + 1); // this is the same regardless of lagged or not for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - spec_boundary[lev].define( + spec_boundary.emplace_back( grids[lev], dmap[lev], NUM_SPECIES, 1, amrex::MFInfo(), Factory(lev)); // if we have a mix of Dirichlet and Isothermal walls, we need to give @@ -1424,9 +1426,10 @@ PeleLM::differentialDiffusionUpdate( #ifdef AMREX_USE_EB if (m_isothermalEB != 0) { // Set up EB dirichlet value and diffusivity - amrex::Vector EBdiff(finest_level + 1); + amrex::Vector EBdiff; + EBdiff.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - EBdiff[lev].define( + EBdiff.emplace_back( grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), EBFactory(lev)); getEBDiff(lev, AmrNewTime, EBdiff[lev], NUM_SPECIES); } @@ -1479,17 +1482,18 @@ PeleLM::differentialDiffusionUpdate( //------------------------------------------------------------------------ // Temporary data holders - amrex::Vector rhs( - finest_level + 1); // Linear deltaT solve RHS - amrex::Vector Tsave( - finest_level + 1); // Storage of T while working on deltaT - amrex::Vector RhoCp( - finest_level + 1); // Acoeff of the linear solve + amrex::Vector rhs; + rhs.reserve(finest_level + 1); // Linear deltaT solve RHS + amrex::Vector Tsave; + Tsave.reserve(finest_level + 1); // Storage of T while working on deltaT + amrex::Vector RhoCp; + RhoCp.reserve(finest_level + 1); // Acoeff of the linear solve for (int lev = 0; lev <= finest_level; ++lev) { - rhs[lev].define(grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), Factory(lev)); - Tsave[lev].define( + rhs.emplace_back( + grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), Factory(lev)); + Tsave.emplace_back( grids[lev], dmap[lev], 1, 1, amrex::MFInfo(), Factory(lev)); - RhoCp[lev].define( + RhoCp.emplace_back( grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), Factory(lev)); } @@ -1513,12 +1517,14 @@ PeleLM::differentialDiffusionUpdate( if (m_isothermalEB != 0) { // Set up EB dirichlet value and diffusivity // Dirichlet value is deltaT - amrex::Vector EBvalue(finest_level + 1); - amrex::Vector EBdiff(finest_level + 1); + amrex::Vector EBvalue; + EBvalue.reserve(finest_level + 1); + amrex::Vector EBdiff; + EBdiff.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - EBvalue[lev].define( + EBvalue.emplace_back( grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), EBFactory(lev)); - EBdiff[lev].define( + EBdiff.emplace_back( grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), EBFactory(lev)); getEBDiff(lev, AmrNewTime, EBdiff[lev], NUM_SPECIES); EBvalue[lev].setVal(0.0); @@ -1667,9 +1673,10 @@ PeleLM::deltaTIter_update( #ifdef AMREX_USE_EB if (m_isothermalEB != 0) { // Set up EB dirichlet value and diffusivity - amrex::Vector EBdiff(finest_level + 1); + amrex::Vector EBdiff; + EBdiff.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - EBdiff[lev].define( + EBdiff.emplace_back( grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), EBFactory(lev)); getEBDiff(lev, AmrNewTime, EBdiff[lev], NUM_SPECIES); } diff --git a/Source/PeleLMeX_Evaluate.cpp b/Source/PeleLMeX_Evaluate.cpp index c2f1d9a75..7e2916fbd 100644 --- a/Source/PeleLMeX_Evaluate.cpp +++ b/Source/PeleLMeX_Evaluate.cpp @@ -40,9 +40,10 @@ PeleLM::Evaluate() //---------------------------------------------------------------- // Define the outgoing container - amrex::Vector mf_plt(finest_level + 1); + amrex::Vector mf_plt; + mf_plt.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - mf_plt[lev].define( + mf_plt.emplace_back( grids[lev], dmap[lev], ncomp, 0, amrex::MFInfo(), Factory(lev)); } @@ -96,7 +97,7 @@ PeleLM::Evaluate() void PeleLM::MLevaluate( const amrex::Vector& a_MFVec, - int a_comp, + const int a_comp, int& nComp, const std::string& a_var) { @@ -105,9 +106,9 @@ PeleLM::MLevaluate( // used in PeleLM:::Evolve if (a_var == "divU") { - int is_initialization = 0; // No, use IRR - int computeDiffusionTerm = 1; // Needed here - int do_avgDown = 1; // Always + constexpr int is_initialization = 0; // No, use IRR + constexpr int computeDiffusionTerm = 1; // Needed here + constexpr int do_avgDown = 1; // Always // Light version of the diffusion data container std::unique_ptr diffData; @@ -124,9 +125,9 @@ PeleLM::MLevaluate( nComp = 1; } else if (a_var == "velProj") { // Will need DivU - int is_initialization = 0; // No, use IRR - int computeDiffusionTerm = 1; // Needed here - int do_avgDown = 1; // Always + constexpr int is_initialization = 0; // No, use IRR + constexpr int computeDiffusionTerm = 1; // Needed here + constexpr int do_avgDown = 1; // Always // Light version of the diffusion data container std::unique_ptr diffData; @@ -149,7 +150,7 @@ PeleLM::MLevaluate( nComp = AMREX_SPACEDIM; } else if (a_var == "divTau") { // Velocity tensor components - int use_density = 0; + constexpr int use_density = 0; amrex::Vector> aliasDivTau( finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { @@ -241,7 +242,7 @@ PeleLM::MLevaluate( } } else if (a_var == "velForce") { // Velocity forces used in computing the velocity advance - int add_gradP = 0; + constexpr int add_gradP = 0; amrex::Vector> aliasMFVec( finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { diff --git a/Source/PeleLMeX_UMac.cpp b/Source/PeleLMeX_UMac.cpp index 94fcac032..503f0aa9d 100644 --- a/Source/PeleLMeX_UMac.cpp +++ b/Source/PeleLMeX_UMac.cpp @@ -20,23 +20,25 @@ PeleLM::predictVelocity(std::unique_ptr& advData) //---------------------------------------------------------------- // Get viscous forces - int nGrow_force = 1; - amrex::Vector divtau(finest_level + 1); - amrex::Vector velForces(finest_level + 1); + constexpr int nGrow_force = 1; + amrex::Vector divtau; + divtau.reserve(finest_level + 1); + amrex::Vector velForces; + velForces.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - divtau[lev].define( + divtau.emplace_back( grids[lev], dmap[lev], AMREX_SPACEDIM, 0, amrex::MFInfo(), Factory(lev)); - velForces[lev].define( + velForces.emplace_back( grids[lev], dmap[lev], AMREX_SPACEDIM, nGrow_force, amrex::MFInfo(), Factory(lev)); } - int use_density = 0; + constexpr int use_density = 0; computeDivTau(AmrOldTime, GetVecOfPtrs(divtau), use_density); //---------------------------------------------------------------- // Gather all the velocity forces // F = [ (gravity+...) - gradP + divTau ] / rho - int add_gradP = 1; + constexpr int add_gradP = 1; getVelForces( AmrOldTime, GetVecOfPtrs(divtau), GetVecOfPtrs(velForces), nGrow_force, add_gradP); @@ -89,10 +91,11 @@ PeleLM::addChiIncrement( { BL_PROFILE("PeleLMeX::addChiIncrement()"); - int nGrow = m_nGrowAdv; - amrex::Vector chiIncr(finest_level + 1); + const int nGrow = m_nGrowAdv; + amrex::Vector chiIncr; + chiIncr.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - chiIncr[lev].define( + chiIncr.emplace_back( grids[lev], dmap[lev], 1, nGrow, amrex::MFInfo(), Factory(lev)); } @@ -158,7 +161,7 @@ PeleLM::macProject( { BL_PROFILE("PeleLMeX::macProject()"); - int has_divu = static_cast(!a_divu.empty()); + const int has_divu = static_cast(!a_divu.empty()); // Get face rho inv auto bcRec = fetchBCRecArray(DENSITY, 1); @@ -175,7 +178,7 @@ PeleLM::macProject( } } else { auto* ldata_p = getLevelDataPtr(lev, a_time); - int doZeroVisc = 0; + constexpr int doZeroVisc = 0; rho_inv[lev] = getDiffusivity(lev, DENSITY, 1, doZeroVisc, {bcRec}, ldata_p->state); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { @@ -232,22 +235,19 @@ PeleLM::macProject( } // FillBoundary umac - for (int lev = 0; lev <= finest_level; ++lev) { - if (lev > 0) { - // We need to fill the MAC velocities outside the fine region so we can - // use them in the Godunov method - amrex::IntVect rr = - geom[lev].Domain().size() / geom[lev - 1].Domain().size(); - create_constrained_umac_grown( - m_nGrowMAC, &geom[lev - 1], &geom[lev], - GetArrOfPtrs(advData->umac[lev - 1]), GetArrOfPtrs(advData->umac[lev]), - rr); - } else { - AMREX_D_TERM( - advData->umac[lev][0].FillBoundary(geom[lev].periodicity()); - , advData->umac[lev][1].FillBoundary(geom[lev].periodicity()); - , advData->umac[lev][2].FillBoundary(geom[lev].periodicity())); - } + // Do coarse first + AMREX_D_TERM(advData->umac[0][0].FillBoundary(geom[0].periodicity()); + , advData->umac[0][1].FillBoundary(geom[0].periodicity()); + , advData->umac[0][2].FillBoundary(geom[0].periodicity())); + for (int lev = 1; lev <= finest_level; ++lev) { + // We need to fill the MAC velocities outside the fine region so we can + // use them in the Godunov method + const amrex::IntVect rr = + geom[lev].Domain().size() / geom[lev - 1].Domain().size(); + create_constrained_umac_grown( + m_nGrowMAC, &geom[lev - 1], &geom[lev], + GetArrOfPtrs(advData->umac[lev - 1]), GetArrOfPtrs(advData->umac[lev]), + rr); } } diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 78bcecf0a..6490b928f 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -960,9 +960,10 @@ PeleLM::resetCoveredMask() //---------------------------------------------------------------------------- // Need to compute the uncovered volume if (m_uncoveredVol < 0.0) { - amrex::Vector dummy(finest_level + 1); + amrex::Vector dummy; + dummy.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - dummy[lev].define( + dummy.emplace_back( grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), *m_factory[lev]); dummy[lev].setVal(1.0); } @@ -985,7 +986,7 @@ PeleLM::loadBalanceChem() } void -PeleLM::loadBalanceChemLev(int a_lev) +PeleLM::loadBalanceChemLev(const int a_lev) { amrex::LayoutData new_cost(*m_baChem[a_lev], *m_dmapChem[a_lev]); computeCosts(a_lev, new_cost, m_loadBalanceCostChem); @@ -997,7 +998,6 @@ PeleLM::loadBalanceChemLev(int a_lev) amrex::DistributionMapping test_dmap; // Build the test dmap, w/o braodcasting if (m_loadBalanceMethodChem == LoadBalanceMethod::SFC) { - test_dmap = amrex::DistributionMapping::makeSFC( new_cost, currentEfficiency, testEfficiency, false, amrex::ParallelDescriptor::IOProcessorNumber()); @@ -1059,7 +1059,10 @@ PeleLM::loadBalanceChemLev(int a_lev) // Return a unique_ptr with the entire derive std::unique_ptr PeleLM::derive( - const std::string& a_name, amrex::Real a_time, int lev, int nGrow) + const std::string& a_name, + const amrex::Real a_time, + const int lev, + const int nGrow) { BL_PROFILE("PeleLMeX::derive()"); AMREX_ASSERT(nGrow >= 0); @@ -1126,7 +1129,10 @@ PeleLM::derive( // Return a unique_ptr with only the required component of a derive std::unique_ptr PeleLM::deriveComp( - const std::string& a_name, amrex::Real a_time, int lev, int nGrow) + const std::string& a_name, + const amrex::Real a_time, + const int lev, + const int nGrow) { BL_PROFILE("PeleLMeX::derive()"); AMREX_ASSERT(nGrow >= 0); diff --git a/Source/Plasma/GMRES/MLGMRES.cpp b/Source/Plasma/GMRES/MLGMRES.cpp index 6b8b9939f..c9c77b759 100644 --- a/Source/Plasma/GMRES/MLGMRES.cpp +++ b/Source/Plasma/GMRES/MLGMRES.cpp @@ -18,13 +18,13 @@ MLGMRESSolver::define(PeleLM* a_pelelm, const int a_nComp, const int a_nGrow) m_pelelm = a_pelelm; - int finest_level = m_pelelm->finestLevel(); + const int finest_level = m_pelelm->finestLevel(); // Resize level vector m_grids.resize(finest_level + 1); m_dmap.resize(finest_level + 1); - Ax.resize(finest_level + 1); - res.resize(finest_level + 1); + Ax.reserve(finest_level + 1); + res.reserve(finest_level + 1); // Grab stuff from AmrCore m_geom = m_pelelm->Geom(0, finest_level); @@ -38,14 +38,14 @@ MLGMRESSolver::define(PeleLM* a_pelelm, const int a_nComp, const int a_nGrow) // Build krylov base memory and work MFs KspBase.resize(m_krylovSize + 1); for (int n = 0; n <= m_krylovSize; ++n) { - KspBase[n].resize(finest_level + 1); + KspBase[n].reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - KspBase[n][lev].define(m_grids[lev], m_dmap[lev], m_nComp, m_nGrow); + KspBase[n].emplace_back(m_grids[lev], m_dmap[lev], m_nComp, m_nGrow); } } for (int lev = 0; lev <= finest_level; ++lev) { - Ax[lev].define(m_grids[lev], m_dmap[lev], m_nComp, m_nGrow); - res[lev].define(m_grids[lev], m_dmap[lev], m_nComp, m_nGrow); + Ax.emplace_back(m_grids[lev], m_dmap[lev], m_nComp, m_nGrow); + res.emplace_back(m_grids[lev], m_dmap[lev], m_nComp, m_nGrow); } // Work Reals diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index b2531c923..fa4a00169 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -48,7 +48,7 @@ PeleLM::implicitNonLinearSolve( } // Gradient of PhiV at t^{n} - int do_avgDown = 0; // TODO or should I ? + constexpr int do_avgDown = 0; // TODO or should I ? auto bcRecPhiV = fetchBCRecArray(PHIV, 1); getDiffusionOp()->computeGradient( getNLgradPhiVVect(), {}, // don't need the laplacian out @@ -141,9 +141,10 @@ PeleLM::implicitNonLinearSolve( } // Solve for Newton direction - amrex::Vector newtonDir(finest_level + 1); + amrex::Vector newtonDir; + newtonDir.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - newtonDir[lev].define( + newtonDir.emplace_back( grids[lev], dmap[lev], 2, 1, amrex::MFInfo(), Factory(lev)); newtonDir[lev].setVal(0.0, 0, 2, 1); } @@ -380,7 +381,6 @@ PeleLM::computeBGcharge( auto const& dhat_ma = diffData->Dhat[lev].const_arrays(); auto const& rhoYdot_ma = ldataR_p->I_R.const_arrays(); auto const& charge_ma = ldataNLs_p->backgroundCharge.arrays(); - constexpr amrex::Real factor = 1.0 / elemCharge; amrex::ParallelFor( ldataNLs_p->backgroundCharge, [state_old_ma, adv_ma, dn_ma, dnp1_ma, dhat_ma, rhoYdot_ma, charge_ma, @@ -390,6 +390,7 @@ PeleLM::computeBGcharge( state_old_ma[box_no], FIRSTSPEC); amrex::Array4 adv(adv_ma[box_no], FIRSTSPEC); charge_ma[box_no](i, j, k) = 0.0; + constexpr amrex::Real factor = 1.0 / elemCharge; for (int n = 0; n < NUM_SPECIES; ++n) { amrex::Real rhoYprov = rhoYold(i, j, k, n) + @@ -415,12 +416,14 @@ PeleLM::nonLinearResidual( const int updatePrecond) { // Get unscaled copy of the NL state - amrex::Vector nE(finest_level + 1); - amrex::Vector phiV(finest_level + 1); + amrex::Vector nE; + nE.reserve(finest_level + 1); + amrex::Vector phiV; + phiV.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - nE[lev].define( + nE.emplace_back( grids[lev], dmap[lev], 1, m_nGrowState, amrex::MFInfo(), Factory(lev)); - phiV[lev].define( + phiV.emplace_back( grids[lev], dmap[lev], 1, m_nGrowState, amrex::MFInfo(), Factory(lev)); amrex::MultiFab::Copy(nE[lev], *a_nlstate[lev], 0, 0, 1, m_nGrowState); nE[lev].mult(nE_scale, 0, 1, m_nGrowState); @@ -432,11 +435,12 @@ PeleLM::nonLinearResidual( fillPatchNLnE(m_cur_time, GetVecOfPtrs(nE), m_nGrowState); // Get L(phiV) and Grad(phiV) - amrex::Vector laplacian(finest_level + 1); + amrex::Vector laplacian; + laplacian.reserve(finest_level + 1); amrex::Vector> gradPhiVCur( finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - laplacian[lev].define( + laplacian.emplace_back( grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), Factory(lev)); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { const auto& fba = @@ -445,16 +449,17 @@ PeleLM::nonLinearResidual( fba, dmap[lev], 1, 0, amrex::MFInfo(), Factory(lev)); } } - int do_avgDown = 0; // TODO or should I ? + constexpr int do_avgDown = 0; // TODO or should I ? auto bcRecPhiV = fetchBCRecArray(PHIV, 1); getDiffusionOp()->computeGradient( GetVecOfArrOfPtrs(gradPhiVCur), GetVecOfPtrs(laplacian), GetVecOfConstPtrs(phiV), {}, bcRecPhiV[0], do_avgDown); // Get nE diffusion term - amrex::Vector diffnE(finest_level + 1); + amrex::Vector diffnE; + diffnE.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - diffnE[lev].define( + diffnE.emplace_back( grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), Factory(lev)); } auto bcRecnE = fetchBCRecArray(NE, 1); @@ -466,9 +471,10 @@ PeleLM::nonLinearResidual( // amrex::VisMF::Write(diffnE[0],"diffnEnlResid"); // Get nE advection term - amrex::Vector advnE(finest_level + 1); + amrex::Vector advnE; + advnE.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - advnE[lev].define( + advnE.emplace_back( grids[lev], dmap[lev], 1, 0, amrex::MFInfo(), Factory(lev)); } getAdvectionTerm( @@ -932,10 +938,11 @@ PeleLM::setUpPrecond( } // Stilda approx first-order - amrex::Vector diagDiffOp(finest_level + 1); + amrex::Vector diagDiffOp; + diagDiffOp.reserve(finest_level + 1); if (m_ef_PC_approx == 2) { for (int lev = 0; lev <= finest_level; ++lev) { - diagDiffOp[lev].define(grids[lev], dmap[lev], 1, 1); + diagDiffOp.emplace_back(grids[lev], dmap[lev], 1, 1); getPrecondOp()->getDiffOpDiagonal(lev, diagDiffOp[lev]); diagDiffOp[lev].mult(FnE_scale / nE_scale); } @@ -1139,21 +1146,23 @@ PeleLM::jTimesV( m_ef_lambda_jfnk * (m_ef_lambda_jfnk + nl_stateNorm / vNorm); if (m_ef_diffT_jfnk == 1) { - amrex::Vector statePert(finest_level + 1); - amrex::Vector residPert(finest_level + 1); + amrex::Vector statePert; + statePert.reserve(finest_level + 1); + amrex::Vector residPert; + residPert.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { auto ldataNLs_p = getLevelDataNLSolvePtr(lev); - statePert[lev].define( + statePert.emplace_back( grids[lev], dmap[lev], 2, m_nGrowState, amrex::MFInfo(), Factory(lev)); - residPert[lev].define( + residPert.emplace_back( grids[lev], dmap[lev], 2, m_nGrowState, amrex::MFInfo(), Factory(lev)); amrex::MultiFab::Copy( statePert[lev], ldataNLs_p->nlState, 0, 0, 2, m_nGrowState); amrex::MultiFab::Saxpy(statePert[lev], delta_pert, *a_v[lev], 0, 0, 2, 0); } - int update_scaling = 0; - int update_precond = 0; + constexpr int update_scaling = 0; + constexpr int update_precond = 0; nonLinearResidual( dtsub, GetVecOfPtrs(statePert), GetVecOfPtrs(residPert), update_scaling, update_precond); @@ -1166,19 +1175,23 @@ PeleLM::jTimesV( a_Jv[lev]->mult(-1.0 / delta_pert); } } else if (m_ef_diffT_jfnk == 2) { - amrex::Vector statePertPls(finest_level + 1); - amrex::Vector residPertPls(finest_level + 1); - amrex::Vector statePertMns(finest_level + 1); - amrex::Vector residPertMns(finest_level + 1); + amrex::Vector statePertPls; + statePertPls.reserve(finest_level + 1); + amrex::Vector residPertPls; + residPertPls.reserve(finest_level + 1); + amrex::Vector statePertMns; + statePertMns.reserve(finest_level + 1); + amrex::Vector residPertMns; + residPertMns.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { auto ldataNLs_p = getLevelDataNLSolvePtr(lev); - statePertPls[lev].define( + statePertPls.emplace_back( grids[lev], dmap[lev], 2, m_nGrowState, amrex::MFInfo(), Factory(lev)); - residPertPls[lev].define( + residPertPls.emplace_back( grids[lev], dmap[lev], 2, m_nGrowState, amrex::MFInfo(), Factory(lev)); - statePertMns[lev].define( + statePertMns.emplace_back( grids[lev], dmap[lev], 2, m_nGrowState, amrex::MFInfo(), Factory(lev)); - residPertMns[lev].define( + residPertMns.emplace_back( grids[lev], dmap[lev], 2, m_nGrowState, amrex::MFInfo(), Factory(lev)); amrex::MultiFab::Copy( statePertPls[lev], ldataNLs_p->nlState, 0, 0, 2, m_nGrowState); @@ -1190,8 +1203,8 @@ PeleLM::jTimesV( statePertMns[lev], -delta_pert, *a_v[lev], 0, 0, 2, 0); } - int update_scaling = 0; - int update_precond = 0; + constexpr int update_scaling = 0; + constexpr int update_precond = 0; nonLinearResidual( dtsub, GetVecOfPtrs(statePertPls), GetVecOfPtrs(residPertPls), update_scaling, update_precond); From e61ecdcfcaac8689bb60dac405d199885127ff6a Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Wed, 20 Aug 2025 02:36:02 +0200 Subject: [PATCH 52/87] missing capture, consts --- Source/PeleLMeX.H | 26 +++++++++++++++++--------- Source/PeleLMeX_Utils.cpp | 22 ++++++++++++++-------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index e17ea8c1e..0d1cfbbaa 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -1374,21 +1374,29 @@ public: amrex::Real MLNorm0(const amrex::Vector& a_MF); amrex::Vector MLNorm0( const amrex::Vector& a_MF, - int startcomp, - int ncomp); + const int startcomp, + const int ncomp); amrex::Real - MFSum(const amrex::Vector& a_MF, int comp); - static amrex::Real - MFmax(const amrex::MultiFab* a_MF, const amrex::iMultiFab& a_mask, int comp); - static amrex::Real - MFmin(const amrex::MultiFab* a_MF, const amrex::iMultiFab& a_mask, int comp); + MFSum(const amrex::Vector& a_MF, const int comp); + static amrex::Real MFmax( + const amrex::MultiFab* a_MF, + const amrex::iMultiFab& a_mask, + const int comp); + static amrex::Real MFmin( + const amrex::MultiFab* a_MF, + const amrex::iMultiFab& a_mask, + const int comp); amrex::Vector MLmax( - const amrex::Vector& a_MF, int scomp, int ncomp); + const amrex::Vector& a_MF, + const int scomp, + const int ncomp); amrex::Vector MLmin( - const amrex::Vector& a_MF, int scomp, int ncomp); + const amrex::Vector& a_MF, + const int scomp, + const int ncomp); void resetCoveredMask(); diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 6490b928f..50881dd79 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -1334,7 +1334,9 @@ PeleLM::MLNorm0(const amrex::Vector& a_MF) amrex::Vector PeleLM::MLNorm0( - const amrex::Vector& a_MF, int startcomp, int ncomp) + const amrex::Vector& a_MF, + const int startcomp, + const int ncomp) { BL_PROFILE("PeleLMeX::MLNorm0()"); AMREX_ASSERT(a_MF[0]->nComp() >= startcomp + ncomp); @@ -1473,7 +1475,7 @@ PeleLM::fetchDiffTypeAuxArray(int scomp, int ncomp) } amrex::Real -PeleLM::MFSum(const amrex::Vector& a_mf, int comp) +PeleLM::MFSum(const amrex::Vector& a_mf, const int comp) { BL_PROFILE("PeleLMeX::MFSum()"); // Get the integral of the MF, not including the fine-covered and @@ -1692,7 +1694,7 @@ PeleLM::updateTypicalValuesChem() // amrex::MultiFab max, excluding EB-covered/fine-covered cells, local amrex::Real PeleLM::MFmax( - const amrex::MultiFab* a_MF, const amrex::iMultiFab& a_mask, int comp) + const amrex::MultiFab* a_MF, const amrex::iMultiFab& a_mask, const int comp) { BL_PROFILE("PeleLMeX::MFmax()"); amrex::Real mx = std::numeric_limits::lowest(); @@ -1710,7 +1712,7 @@ PeleLM::MFmax( mx = ParReduce( amrex::TypeList{}, amrex::TypeList{}, *a_MF, amrex::IntVect(0), - [flagsma, mask, ma] AMREX_GPU_DEVICE( + [flagsma, mask, ma, comp] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept -> amrex::GpuTuple { if (flagsma[box_no](i, j, k).isCovered() || !mask[box_no](i, j, k)) { @@ -1783,7 +1785,7 @@ PeleLM::MFmax( // amrex::MultiFab min, excluding EB-covered/fine-covered cells, local amrex::Real PeleLM::MFmin( - const amrex::MultiFab* a_MF, const amrex::iMultiFab& a_mask, int comp) + const amrex::MultiFab* a_MF, const amrex::iMultiFab& a_mask, const int comp) { BL_PROFILE("PeleLMeX::MFmin()"); amrex::Real mn = std::numeric_limits::max(); @@ -1801,7 +1803,7 @@ PeleLM::MFmin( mn = ParReduce( amrex::TypeList{}, amrex::TypeList{}, *a_MF, amrex::IntVect(0), - [flagsma, mask, ma] AMREX_GPU_DEVICE( + [flagsma, mask, ma, comp] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept -> amrex::GpuTuple { if (flagsma[box_no](i, j, k).isCovered() || !mask[box_no](i, j, k)) { @@ -1874,7 +1876,9 @@ PeleLM::MFmin( // MultiLevel max, exlucing EB-covered/fine-covered cells amrex::Vector PeleLM::MLmax( - const amrex::Vector& a_MF, int scomp, int ncomp) + const amrex::Vector& a_MF, + const int scomp, + const int ncomp) { BL_PROFILE("PeleLMeX::MLmax()"); AMREX_ASSERT(a_MF[0]->nComp() >= scomp + ncomp); @@ -1901,7 +1905,9 @@ PeleLM::MLmax( // MultiLevel min, exlucing EB-covered/fine-covered cells amrex::Vector PeleLM::MLmin( - const amrex::Vector& a_MF, int scomp, int ncomp) + const amrex::Vector& a_MF, + const int scomp, + const int ncomp) { BL_PROFILE("PeleLMeX::MLmin()"); AMREX_ASSERT(a_MF[0]->nComp() >= scomp + ncomp); From 95a8dbeb426e530f73309beaae8618bd0f7907ca Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Wed, 20 Aug 2025 02:39:06 +0200 Subject: [PATCH 53/87] bot fix --- Source/PeleLMeX_DeriveFunc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/PeleLMeX_DeriveFunc.cpp b/Source/PeleLMeX_DeriveFunc.cpp index 8e7dd3da0..3bf7ba605 100644 --- a/Source/PeleLMeX_DeriveFunc.cpp +++ b/Source/PeleLMeX_DeriveFunc.cpp @@ -226,9 +226,9 @@ pelelmex_deravgpress( AMREX_ASSERT(derfab.box().contains(bx)); auto const in_dat = pressfab.array(); auto der = derfab.array(dcomp); - constexpr amrex::Real factor = 1.0 / (AMREX_D_TERM(2.0, *2.0, *2.0)); amrex::ParallelFor( bx, [der, in_dat] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + constexpr amrex::Real factor = 1.0 / (AMREX_D_TERM(2.0, *2.0, *2.0)); der(i, j, k) = factor * (in_dat(i + 1, j, k) + in_dat(i, j, k) #if (AMREX_SPACEDIM >= 2) From 179ddb0015b46c18137784d06211b66108ffb9c2 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Wed, 20 Aug 2025 02:41:39 +0200 Subject: [PATCH 54/87] constexpr in lambda --- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index fa4a00169..13dd39224 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -503,7 +503,6 @@ PeleLM::nonLinearResidual( auto const& state_old_ma = ldataOld_p->state.const_arrays(); auto const& charge_ma = ldataNLs_p->backgroundCharge.const_arrays(); auto const& res_ma = a_nlresid[lev]->arrays(); - constexpr amrex::Real scalLap = eps0 * epsr / elemCharge; amrex::ParallelFor( ldataNLs_p->nlResid, [I_R_ma, lapPhiV_ma, ne_diff_ma, ne_adv_ma, ne_curr_ma, state_old_ma, @@ -516,6 +515,7 @@ PeleLM::nonLinearResidual( res_nE(i, j, k) = ne_old(i, j, k) - ne_curr_ma[box_no](i, j, k) + a_dt * (ne_diff_ma[box_no](i, j, k) + ne_adv_ma[box_no](i, j, k) + I_R_nE(i, j, k)); + constexpr amrex::Real scalLap = eps0 * epsr / elemCharge; res_phiV(i, j, k) = lapPhiV_ma[box_no](i, j, k) * scalLap - ne_curr_ma[box_no](i, j, k) + charge_ma[box_no](i, j, k); From 67122cfc83c44e00c0ba3c5101837a27d98bca52 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Wed, 20 Aug 2025 16:23:30 +0200 Subject: [PATCH 55/87] more consts, plus switch --- Source/PeleLMeX.H | 7 ++++-- Source/PeleLMeX_Advance.cpp | 2 +- Source/PeleLMeX_Eos.cpp | 18 +++++++------- Source/PeleLMeX_Regrid.cpp | 48 ++++++++++++++++++++++++------------- Source/PeleLMeX_Utils.cpp | 27 +++++++++------------ 5 files changed, 58 insertions(+), 44 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 0d1cfbbaa..212a60a71 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -82,7 +82,10 @@ public: //----------------------------------------------------------------------------- // Virtual AmrCore functions - void regrid(int lbase, amrex::Real time, bool initial = false) override; + void regrid( + const int lbase, + const amrex::Real time, + const bool initial = false) override; void MakeNewLevelFromScratch( const int lev, @@ -93,7 +96,7 @@ public: void ErrorEst( const int lev, amrex::TagBoxArray& tags, - amrex::Real time, + const amrex::Real time, const int ng) override; void MakeNewLevelFromCoarse( diff --git a/Source/PeleLMeX_Advance.cpp b/Source/PeleLMeX_Advance.cpp index fd2055764..c3355733d 100644 --- a/Source/PeleLMeX_Advance.cpp +++ b/Source/PeleLMeX_Advance.cpp @@ -10,7 +10,7 @@ PeleLM::Advance(const int is_initIter) #ifdef AMREX_MEM_PROFILING // Memory profiler if compiled - MemProfiler::report("STEP [" + std::to_string(m_nstep) + "]"); + amrex::MemProfiler::report("STEP [" + std::to_string(m_nstep) + "]"); #endif // Start timing current time step diff --git a/Source/PeleLMeX_Eos.cpp b/Source/PeleLMeX_Eos.cpp index acee42d10..8b643414a 100644 --- a/Source/PeleLMeX_Eos.cpp +++ b/Source/PeleLMeX_Eos.cpp @@ -176,7 +176,7 @@ PeleLM::calcDivU( // fillPatch a_time divu to get properly filled ghost cells for (int lev = 0; lev <= finest_level; ++lev) { - amrex::Real time = getTime(lev, a_time); + const amrex::Real time = getTime(lev, a_time); auto* ldata_p = getLevelDataPtr(lev, a_time); fillpatch_divu(lev, time, ldata_p->divu, m_nGrowdivu); } @@ -303,10 +303,10 @@ PeleLM::adjustPandDivU(std::unique_ptr& advData) [tma, sma_o, sma_n, pOld, pNew, leosparm] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { auto theta = tma[box_no]; - amrex::Real gammaInv_o = getGammaInv( + const amrex::Real gammaInv_o = getGammaInv( i, j, k, amrex::Array4(sma_o[box_no], FIRSTSPEC), amrex::Array4(sma_o[box_no], TEMP), leosparm); - amrex::Real gammaInv_n = getGammaInv( + const amrex::Real gammaInv_n = getGammaInv( i, j, k, amrex::Array4(sma_n[box_no], FIRSTSPEC), amrex::Array4(sma_n[box_no], TEMP), leosparm); theta(i, j, k) = 0.5 * (gammaInv_o / pOld + gammaInv_n / pNew); @@ -315,10 +315,10 @@ PeleLM::adjustPandDivU(std::unique_ptr& advData) amrex::Gpu::streamSynchronize(); // Get the mean mac_divu (Sbar) and mean theta - amrex::Real Sbar = MFSum(GetVecOfConstPtrs(advData->mac_divu), 0); - Sbar /= m_uncoveredVol; - amrex::Real Thetabar = MFSum(GetVecOfConstPtrs(ThetaHalft), 0); - Thetabar /= m_uncoveredVol; + const amrex::Real Sbar = + MFSum(GetVecOfConstPtrs(advData->mac_divu), 0) / m_uncoveredVol; + const amrex::Real Thetabar = + MFSum(GetVecOfConstPtrs(ThetaHalft), 0) / m_uncoveredVol; // Adjust for (int lev = 0; lev <= finest_level; ++lev) { @@ -329,11 +329,11 @@ PeleLM::adjustPandDivU(std::unique_ptr& advData) } // Compute 1/Volume * int(U_inflow)dA across all boundary faces - amrex::Real umacFluxBalance = AMREX_D_TERM( + const amrex::Real umacFluxBalance = AMREX_D_TERM( m_domainUmacFlux[0] + m_domainUmacFlux[1], +m_domainUmacFlux[2] + m_domainUmacFlux[3], +m_domainUmacFlux[4] + m_domainUmacFlux[5]); - amrex::Real divu_vol = umacFluxBalance / m_uncoveredVol; + const amrex::Real divu_vol = umacFluxBalance / m_uncoveredVol; // Advance the ambient pressure m_pNew = m_pOld + m_dt * (Sbar - divu_vol) / Thetabar; diff --git a/Source/PeleLMeX_Regrid.cpp b/Source/PeleLMeX_Regrid.cpp index 061baec2b..16f6606f5 100644 --- a/Source/PeleLMeX_Regrid.cpp +++ b/Source/PeleLMeX_Regrid.cpp @@ -2,7 +2,7 @@ #include void -PeleLM::regrid(int lbase, amrex::Real time, bool initial) +PeleLM::regrid(const int lbase, const amrex::Real time, const bool initial) { BL_PROFILE("PeleLMeX::regrid()"); @@ -307,8 +307,8 @@ PeleLM::regrid(int lbase, amrex::Real time, bool initial) void PeleLM::MakeNewLevelFromCoarse( - int lev, - amrex::Real time, + const int lev, + const amrex::Real time, const amrex::BoxArray& ba, const amrex::DistributionMapping& dm) { @@ -423,8 +423,8 @@ PeleLM::MakeNewLevelFromCoarse( void PeleLM::RemakeLevel( - int lev, - amrex::Real time, + const int lev, + const amrex::Real time, const amrex::BoxArray& ba, const amrex::DistributionMapping& dm) { @@ -538,7 +538,7 @@ PeleLM::RemakeLevel( } void -PeleLM::ClearLevel(int lev) +PeleLM::ClearLevel(const int lev) { BL_PROFILE("PeleLMeX::ClearLevel()"); @@ -571,32 +571,43 @@ PeleLM::ClearLevel(int lev) void PeleLM::computeCosts( - int a_lev, amrex::LayoutData& a_costs, int a_costMethod) + const int a_lev, + amrex::LayoutData& a_costs, + const int a_costMethod) { - if (a_costMethod == LoadBalanceCost::Ncell) { + switch (a_costMethod) { + case LoadBalanceCost::Ncell: { for (amrex::MFIter mfi(a_costs, false); mfi.isValid(); ++mfi) { a_costs[mfi] = static_cast(mfi.validbox().numPts()); } - } else if (a_costMethod == LoadBalanceCost::ChemFunctCallAvg) { + return; + } + case LoadBalanceCost::ChemFunctCallAvg: { amrex::MultiFab costMF(a_costs.boxArray(), a_costs.DistributionMap(), 1, 0); fillpatch_chemFunctCall(a_lev, m_cur_time, costMF, 0); for (amrex::MFIter mfi(costMF, false); mfi.isValid(); ++mfi) { a_costs[mfi] = costMF[mfi].sum(mfi.validbox(), 0) / static_cast(mfi.validbox().numPts()); } - } else if (a_costMethod == LoadBalanceCost::ChemFunctCallMax) { + return; + } + case LoadBalanceCost::ChemFunctCallMax: { amrex::MultiFab costMF(a_costs.boxArray(), a_costs.DistributionMap(), 1, 0); fillpatch_chemFunctCall(a_lev, m_cur_time, costMF, 0); for (amrex::MFIter mfi(costMF, false); mfi.isValid(); ++mfi) { a_costs[mfi] = costMF[mfi].max(mfi.validbox(), 0); } - } else if (a_costMethod == LoadBalanceCost::ChemFunctCallSum) { + return; + } + case LoadBalanceCost::ChemFunctCallSum: { amrex::MultiFab costMF(a_costs.boxArray(), a_costs.DistributionMap(), 1, 0); fillpatch_chemFunctCall(a_lev, m_cur_time, costMF, 0); for (amrex::MFIter mfi(costMF, false); mfi.isValid(); ++mfi) { a_costs[mfi] = costMF[mfi].sum(mfi.validbox(), 0); } - } else if (a_costMethod == LoadBalanceCost::UserDefinedDerivedAvg) { + return; + } + case LoadBalanceCost::UserDefinedDerivedAvg: { amrex::MultiFab costMF(a_costs.boxArray(), a_costs.DistributionMap(), 1, 0); costMF.setVal(0.0); std::unique_ptr mf; @@ -606,7 +617,9 @@ PeleLM::computeCosts( a_costs[mfi] = costMF[mfi].sum(mfi.validbox(), 0) / static_cast(mfi.validbox().numPts()); } - } else if (a_costMethod == LoadBalanceCost::UserDefinedDerivedSum) { + return; + } + case LoadBalanceCost::UserDefinedDerivedSum: { amrex::MultiFab costMF(a_costs.boxArray(), a_costs.DistributionMap(), 1, 0); costMF.setVal(0.0); std::unique_ptr mf; @@ -615,13 +628,15 @@ PeleLM::computeCosts( for (amrex::MFIter mfi(costMF, false); mfi.isValid(); ++mfi) { a_costs[mfi] = costMF[mfi].sum(mfi.validbox(), 0); } - } else { + return; + } + default: amrex::Abort(" Unknown cost estimate method !"); } } void -PeleLM::computeCosts(int a_lev) +PeleLM::computeCosts(const int a_lev) { computeCosts(a_lev, *m_costs[a_lev], m_loadBalanceCost); } @@ -651,7 +666,8 @@ PeleLM::resetMacProjector() } void -PeleLM::regridFromGridFile(int lbase, amrex::Real time, bool /*initial*/) +PeleLM::regridFromGridFile( + const int lbase, const amrex::Real time, const bool /*initial*/) { const int new_finest = static_cast(m_regrid_ba.size()); amrex::Vector new_grids(finest_level + 2); diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 50881dd79..c60db9726 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -219,13 +219,10 @@ PeleLM::extFluxDivergenceLevel( , auto const& fluxZ = a_fluxes[2]->const_array(mfi, flux_comp);); auto const& divergence = a_divergence.array(mfi, div_comp); auto const& vol = volume.const_array(mfi); - #ifdef AMREX_USE_EB auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; auto const& flag = flagfab.const_array(); -#endif -#ifdef AMREX_USE_EB if (flagfab.getType(bx) == amrex::FabType::covered) { // Covered boxes amrex::ParallelFor( bx, ncomp, @@ -238,26 +235,24 @@ PeleLM::extFluxDivergenceLevel( auto vfrac = ebfact.getVolFrac().const_array(mfi); amrex::ParallelFor( bx, [flag, divergence, ncomp, vol, scale, vfrac, fluxX, fluxY -#if (AMREX_SPACEDIM == 3) +#if AMREX_SPACEDIM == 3 , fluxZ #endif ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - if (flag(i, j, k).isCovered()) { - for (int n = 0; n < ncomp; ++n) { + if (flag(i, j, k).isCovered()) { // Covered cell + for (int n = 0; n < ncomp; n++) { divergence(i, j, k, n) = 0.0; } - } else if (flag(i, j, k).isRegular()) { + } else { // Regular or cut cell extFluxDivergence_K( i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), vol, scale, divergence); - } else { - const amrex::Real vfracinv = 1.0 / vfrac(i, j, k); - extFluxDivergence_K( - i, j, k, ncomp, AMREX_D_DECL(fluxX, fluxY, fluxZ), vol, scale, - divergence); - for (int n = 0; n < ncomp; ++n) { - divergence(i, j, k, n) *= vfracinv; + if (!flag(i, j, k).isRegular()) { // Cut cell + const amrex::Real vfracinv = 1.0 / vfrac(i, j, k); + for (int n = 0; n < ncomp; n++) { + divergence(i, j, k, n) *= vfracinv; + } } } }); @@ -266,7 +261,7 @@ PeleLM::extFluxDivergenceLevel( { amrex::ParallelFor( bx, [ncomp, vol, scale, divergence, fluxX, fluxY -#if (AMREX_SPACEDIM == 3) +#if AMREX_SPACEDIM == 3 , fluxZ #endif @@ -358,7 +353,7 @@ PeleLM::intFluxDivergenceLevel( fluxZ, areaz, afrac_z #endif ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - if (flag(i, j, k).isCovered()) { + if (flag(i, j, k).isCovered()) { // Covered cells for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) = 0.0; } From 98f4d7b0bd3096190d88a49b1ef41ddc9b624ca1 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Wed, 20 Aug 2025 16:27:03 +0200 Subject: [PATCH 56/87] more loops --- Source/PeleLMeX_Data.cpp | 2 +- Source/PeleLMeX_Plot.cpp | 4 ++-- Source/PeleLMeX_Utils.cpp | 8 ++++---- Source/Plasma/LinOps/AMReX_MLABecCecLap_3D_K.H | 2 +- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/PeleLMeX_Data.cpp b/Source/PeleLMeX_Data.cpp index ac44f55c8..a18063fa6 100644 --- a/Source/PeleLMeX_Data.cpp +++ b/Source/PeleLMeX_Data.cpp @@ -363,7 +363,7 @@ bool PeleLM::checkForNaNs() { bool contains_nan = false; - for (int lev = 0; lev <= finest_level; lev++) { + for (int lev = 0; lev <= finest_level; ++lev) { if ( m_leveldata_new[lev]->state.contains_nan() || m_leveldata_new[lev]->state.contains_inf()) { diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 49adeaf58..2de37cc89 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -995,7 +995,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) } } if (foundSpec == 0) { - for (int iplt = 0; iplt < plt_vars.size(); iplt++) { + for (int iplt = 0; iplt < plt_vars.size(); ++iplt) { if (specString == plt_vars[iplt]) { foundSpec = 1; if (m_verbose > 0) { @@ -1194,7 +1194,7 @@ PeleLM::addLevelVelocityDataFromPlt(int a_lev, const std::string& a_velPltFile) amrex::ParallelFor( bx, [state_arr, tmpVel_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; n++) { + for (int n = 0; n < AMREX_SPACEDIM; ++n) { state_arr(i, j, k, XVEL + n) += tmpVel_arr(i, j, k, n); } }); diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index c60db9726..708989c97 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -241,7 +241,7 @@ PeleLM::extFluxDivergenceLevel( #endif ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { if (flag(i, j, k).isCovered()) { // Covered cell - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) = 0.0; } } else { // Regular or cut cell @@ -250,7 +250,7 @@ PeleLM::extFluxDivergenceLevel( divergence); if (!flag(i, j, k).isRegular()) { // Cut cell const amrex::Real vfracinv = 1.0 / vfrac(i, j, k); - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { divergence(i, j, k, n) *= vfracinv; } } @@ -1887,7 +1887,7 @@ PeleLM::MLmax( amrex::max(nmax[n], MFmax(a_MF[lev], *m_coveredMask[lev], scomp + n)); } } else { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { nmax[n] = amrex::max(nmax[n], a_MF[lev]->max(scomp + n, 0, true)); } } @@ -1916,7 +1916,7 @@ PeleLM::MLmin( amrex::min(nmin[n], MFmin(a_MF[lev], *m_coveredMask[lev], scomp + n)); } } else { - for (int n = 0; n < ncomp; n++) { + for (int n = 0; n < ncomp; ++n) { nmin[n] = amrex::min(nmin[n], a_MF[lev]->min(scomp + n, 0, true)); } } diff --git a/Source/Plasma/LinOps/AMReX_MLABecCecLap_3D_K.H b/Source/Plasma/LinOps/AMReX_MLABecCecLap_3D_K.H index 2bf08fdb1..f0c4e2f29 100644 --- a/Source/Plasma/LinOps/AMReX_MLABecCecLap_3D_K.H +++ b/Source/Plasma/LinOps/AMReX_MLABecCecLap_3D_K.H @@ -759,7 +759,7 @@ tridiagonal_solve( amrex::Abort(">>>TRIDIAG FAILED"); u_ls(i) = (r_ls(i) - a_ls(i) * u_ls(i - 1)) / bet; } - for (int i = ilen - 2; i >= 0; i--) { + for (int i = ilen - 2; i >= 0; --i) { u_ls(i) = u_ls(i) - gam(i + 1) * u_ls(i + 1); } } diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index 13dd39224..765ddfea1 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -82,7 +82,7 @@ PeleLM::implicitNonLinearSolve( if (ef_substep > 1) amrex::Abort("Non-linear solve sub-stepping not re-implemented yet"); int NK_tot_count = 0; - for (int sstep = 0; sstep < ef_substep; sstep++) { + for (int sstep = 0; sstep < ef_substep; ++sstep) { curtime = getTime(0, AmrOldTime) + (sstep + 1) * dtsub; // ----------------- From d141d09c8c5357413bae5b614fdbb2c5f506137d Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Thu, 21 Aug 2025 20:56:09 +0200 Subject: [PATCH 57/87] better streamsyncs --- Source/PeleLMeX_Diffusion.cpp | 11 +++--- Source/PeleLMeX_DiffusionOp.cpp | 1 + Source/PeleLMeX_Eos.cpp | 2 +- Source/PeleLMeX_Forces.cpp | 53 ++++++++++++++------------- Source/PeleLMeX_Init.cpp | 4 +- Source/PeleLMeX_Projection.cpp | 32 ++++++++-------- Source/PeleLMeX_Timestep.cpp | 2 +- Source/PeleLMeX_TransportProp.cpp | 4 +- Source/PeleLMeX_Utils.cpp | 2 +- Source/Plasma/PeleLMeX_EFIonDrift.cpp | 3 +- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 28 +------------- Source/Plasma/PeleLMeX_EFPoisson.cpp | 4 +- Source/Plasma/PeleLMeX_EFTimeStep.cpp | 3 +- Source/Plasma/PeleLMeX_EFUtils.cpp | 2 +- 14 files changed, 66 insertions(+), 85 deletions(-) diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 43dcd12e7..0cd5f3e07 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -737,8 +737,8 @@ PeleLM::addWbarTerm( } } }); + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); //------------------------------------------------------------------------ // Compute Wbar gradients and do average down to get gradients consistent // across levels Get the species BCRec @@ -1624,12 +1624,11 @@ PeleLM::deltaTIter_prepare( // Save T tsave_ma[box_no](i, j, k) = T(i, j, k); }); - + amrex::Gpu::streamSynchronize(); // Set T^{np1} to zero // Include one ghost cell to ensure levelBC at zero for linear solve ldataNew_p->state.setVal(0.0, TEMP, 1, 1); } - amrex::Gpu::streamSynchronize(); } void @@ -1722,8 +1721,8 @@ PeleLM::deltaTIter_update( //------------------------------------------------------------------------ // Recompute RhoH + auto const* leosparm = eos_parms.device_parm(); for (int lev = 0; lev <= finest_level; ++lev) { - auto const* leosparm = eos_parms.device_parm(); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); auto const& sma = ldata_p->state.arrays(); amrex::ParallelFor( @@ -1745,8 +1744,8 @@ PeleLM::getScalarDiffForce( std::unique_ptr& diffData) { - int* aux_advect_d = convertToDeviceVector(m_aux_advect).dataPtr(); - int* aux_diffuse_d = convertToDeviceVector(m_DiffTypeAux).dataPtr(); + const int* aux_advect_d = convertToDeviceVector(m_aux_advect).dataPtr(); + const int* aux_diffuse_d = convertToDeviceVector(m_DiffTypeAux).dataPtr(); for (int lev = 0; lev <= finest_level; ++lev) { diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index 620ac15c8..baba0f25f 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -1276,6 +1276,7 @@ DiffusionTensorOp::diffuse_velocity( } }); } + amrex::Gpu::streamSynchronize(); } amrex::MLMG mlmg(*m_solve_op); diff --git a/Source/PeleLMeX_Eos.cpp b/Source/PeleLMeX_Eos.cpp index 8b643414a..cb84c110c 100644 --- a/Source/PeleLMeX_Eos.cpp +++ b/Source/PeleLMeX_Eos.cpp @@ -311,8 +311,8 @@ PeleLM::adjustPandDivU(std::unique_ptr& advData) amrex::Array4(sma_n[box_no], TEMP), leosparm); theta(i, j, k) = 0.5 * (gammaInv_o / pOld + gammaInv_n / pNew); }); + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); // Get the mean mac_divu (Sbar) and mean theta const amrex::Real Sbar = diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 269e9e8f8..9437a2fe7 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -57,8 +57,8 @@ PeleLM::getVelForces( auto ext_ma = m_extSource[lev]->const_arrays(); auto force_ma = a_velForce->arrays(); - auto gp_ma = (add_gradP != 0) ? ldataGP_p->gp.const_arrays() : state_ma; - auto divTau_ma = (has_divTau != 0) ? a_divTau->const_arrays() : state_ma; + // auto gp_ma = (add_gradP != 0) ? ldataGP_p->gp.const_arrays() : state_ma; + // auto divTau_ma = (has_divTau != 0) ? a_divTau->const_arrays() : state_ma; const auto dx = geom[lev].CellSizeArray(); const int pseudo_gravity = m_ctrl_pseudoGravity; @@ -71,7 +71,7 @@ PeleLM::getVelForces( amrex::ParallelFor( *a_velForce, - [state_ma, ext_ma, force_ma, gp_ma, divTau_ma, dx, add_gradP, has_divTau, + [state_ma, ext_ma, force_ma, dx, /*gp_ma, divTau_ma,add_gradP,has_divTau,*/ time, grav, gp0, ps_dir, is_incomp, rho_incomp, pseudo_gravity, dV_control #ifdef PELE_USE_PLASMA , @@ -97,28 +97,28 @@ PeleLM::getVelForces( addLorentzForce( i, j, k, blo, bhi, time, dx, zk, rhoY, nE, phiV, force_ma[box_no]); #endif - // Do we shift these outside ParallelFor? - if (add_gradP != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - force_ma[box_no](i, j, k, idim) -= gp_ma[box_no](i, j, k, idim); - } - } - if (has_divTau != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - force_ma[box_no](i, j, k, idim) += divTau_ma[box_no](i, j, k, idim); - } - } - if (is_incomp != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - force_ma[box_no](i, j, k, idim) /= rho_incomp; - } - } else { + }); + amrex::Gpu::streamSynchronize(); + if (add_gradP != 0) { + amrex::MultiFab::Subtract( + *a_velForce, ldataGP_p->gp, 0, 0, AMREX_SPACEDIM, 0); + } + if (has_divTau != 0) { + amrex::MultiFab::Add(*a_velForce, *a_divTau, 0, 0, AMREX_SPACEDIM, 0); + } + if (is_incomp != 0) { + a_velForce->mult(1.0 / rho_incomp, 0, AMREX_SPACEDIM, 0); + } else { + amrex::ParallelFor( + *a_velForce, [force_ma, state_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + amrex::Array4 rho(state_ma[box_no], DENSITY); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { force_ma[box_no](i, j, k, idim) /= rho(i, j, k); } - } - }); - amrex::Gpu::streamSynchronize(); + }); + amrex::Gpu::streamSynchronize(); + } } void @@ -241,6 +241,11 @@ PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) GetVecOfConstPtrs(getStateVect(a_timestamp)), {}, bcRecScalar[0], do_avgDown, var_of_scalar); + constexpr amrex::Real fact = + 0.5 / static_cast(AMREX_SPACEDIM); + const amrex::Real C_chi = m_les_c_chi; + const amrex::Real ScInv = m_Schmidt_inv; + // Add in Production and Dissipation source terms for subfilter variances for (int lev = 0; lev <= finest_level; ++lev) { @@ -258,10 +263,6 @@ PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) for (int n = 0; n < MANIFOLD_DIM; ++n) { if (leosparm.is_variance_of[n] >= 0) { - constexpr amrex::Real fact = 0.5 / AMREX_SPACEDIM; - const amrex::Real C_chi = m_les_c_chi; - const amrex::Real ScInv = m_Schmidt_inv; - AMREX_D_TERM( auto const& mut_arr_x = m_leveldata_old[lev]->visc_turb_fc[0].const_arrays(); diff --git a/Source/PeleLMeX_Init.cpp b/Source/PeleLMeX_Init.cpp index 8f975696a..2614a209d 100644 --- a/Source/PeleLMeX_Init.cpp +++ b/Source/PeleLMeX_Init.cpp @@ -148,7 +148,6 @@ PeleLM::MakeNewLevelFromScratch( amrex::MFInfo(), EBFactory(0)); FillSignedDistance(signDist, true); - constexpr amrex::Real fac = AMREX_D_PICK(0.5, 0.25, 0.125); auto const& sd_cc_ma = m_signedDist0->arrays(); auto const& sd_nd_ma = signDist.const_arrays(); amrex::ParallelFor( @@ -161,7 +160,7 @@ PeleLM::MakeNewLevelFromScratch( +sd_nd_ma[box_no](i, j, k + 1) + sd_nd_ma[box_no](i + 1, j, k + 1) + sd_nd_ma[box_no](i, j + 1, k + 1) + sd_nd_ma[box_no](i + 1, j + 1, k + 1)); - sd_cc_ma[box_no](i, j, k) *= fac; + sd_cc_ma[box_no](i, j, k) *= AMREX_D_PICK(0.5, 0.25, 0.125); }); amrex::Gpu::streamSynchronize(); m_signedDist0->FillBoundary(geom[0].periodicity()); @@ -369,6 +368,7 @@ PeleLM::initLevelData(const int lev) i, j, k, is_incomp, state_ma[box_no], aux_ma[box_no], geomdata, *lprobparm, lpmfdata); }); + amrex::Gpu::streamSynchronize(); if (m_incompressible == 0) { // Initialize thermodynamic pressure diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index d6294cdd8..7b8ccdc2c 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -226,6 +226,7 @@ PeleLM::velocityProjection( int box_no, int i, int j, int k) noexcept { sigma_ma[box_no](i, j, k) = dt / rhoHalf_ma[box_no](i, j, k); }); + amrex::Gpu::streamSynchronize(); #ifdef AMREX_USE_EB EB_set_covered(*sigma[lev], 0.0); #endif @@ -238,19 +239,14 @@ PeleLM::velocityProjection( } if (incremental == 0) { - amrex::Vector> rhoHalf; if (m_incompressible == 0) { - rhoHalf = getDensityVect(a_rhoTime); - } - rhoHalf.reserve(finest_level + 1); - for (int lev = 0; lev <= finest_level; ++lev) { - - auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); - auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - - auto state_old_ma = ldataOld_p->state.arrays(); - auto gp_new_ma = ldataNew_p->gp.const_arrays(); - if (m_incompressible == 0) { + amrex::Vector> rhoHalf = + getDensityVect(a_rhoTime); + for (int lev = 0; lev <= finest_level; ++lev) { + auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); + auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); + auto state_old_ma = ldataOld_p->state.arrays(); + auto gp_new_ma = ldataNew_p->gp.const_arrays(); auto rho_ma = rhoHalf[lev]->const_arrays(); amrex::ParallelFor( ldataNew_p->state, @@ -262,13 +258,19 @@ PeleLM::velocityProjection( vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; } }); - } else { + } + } else { + for (int lev = 0; lev <= finest_level; ++lev) { + auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); + auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); + auto state_old_ma = ldataOld_p->state.arrays(); + auto gp_new_ma = ldataNew_p->gp.const_arrays(); + const amrex::Real soverrho = m_dt / m_rho; amrex::ParallelFor( ldataNew_p->state, - [state_old_ma, gp_new_ma, rho = m_rho, dt = a_dt] AMREX_GPU_DEVICE( + [state_old_ma, gp_new_ma, soverrho] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { amrex::Array4 vel(state_old_ma[box_no], VELX); - const amrex::Real soverrho = dt / rho; for (int n = 0; n < AMREX_SPACEDIM; ++n) { vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; } diff --git a/Source/PeleLMeX_Timestep.cpp b/Source/PeleLMeX_Timestep.cpp index e0ae8d520..45c2bb456 100644 --- a/Source/PeleLMeX_Timestep.cpp +++ b/Source/PeleLMeX_Timestep.cpp @@ -255,6 +255,6 @@ PeleLM::checkDt(const TimeStamp a_time, const amrex::Real a_dt) check_divu_dt( i, j, k, divu_checkFlag, dtfac, rhoMin, dxinv, rho, vel, divu, a_dt); }); + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index 6ad6174f7..df648c813 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -303,6 +303,7 @@ PeleLM::calcDiffusivity(const TimeStamp a_time) amrex::Array4(kma[box_no], 0)); #endif }); + amrex::Gpu::streamSynchronize(); // Fill the diff_aux MF with specified Schmidt number for (int n = 0; n < m_nAux; ++n) { @@ -337,12 +338,11 @@ PeleLM::calcDiffusivity(const TimeStamp a_time) amrex::Array4(state_arr[box_no], TEMP), amrex::Array4(cp_arr[box_no]), leosparm); }); - + amrex::Gpu::streamSynchronize(); ldata_p->diff_aux_cc.divide(cp_cc, n, 1, ldata_p->diff_cc.nGrow()); } } } - amrex::Gpu::streamSynchronize(); } amrex::Array diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 708989c97..4f11523b0 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -851,8 +851,8 @@ PeleLM::floorSpecies(const TimeStamp a_time) sma[box_no](i, j, k, RHOH) = h_cgs * 1.0e-4 * sma[box_no](i, j, k, DENSITY); }); - amrex::Gpu::streamSynchronize(); } + amrex::Gpu::streamSynchronize(); } void diff --git a/Source/Plasma/PeleLMeX_EFIonDrift.cpp b/Source/Plasma/PeleLMeX_EFIonDrift.cpp index 2fb086749..c8cadcd57 100644 --- a/Source/Plasma/PeleLMeX_EFIonDrift.cpp +++ b/Source/Plasma/PeleLMeX_EFIonDrift.cpp @@ -72,6 +72,7 @@ PeleLM::ionDriftVelocity(std::unique_ptr& advData) 0.5 * (mob_o_ma[box_no](i, j, k, n) + mob_n_ma[box_no](i, j, k, n)); } }); + amrex::Gpu::streamSynchronize(); // Get the face centered ions mobility constexpr int doZeroVisc = 0; amrex::Array mobH_ec = @@ -93,8 +94,8 @@ PeleLM::ionDriftVelocity(std::unique_ptr& advData) } }); } + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); //---------------------------------------------------------------- // Average down faces diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index 765ddfea1..7676b8f23 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -318,8 +318,8 @@ void PeleLM::incrementElectronForcing( const int a_sstep, std::unique_ptr& advData) { - for (int lev = 0; lev <= finest_level; ++lev) { + for (int lev = 0; lev <= finest_level; ++lev) { auto ldata_p = getLevelDataPtr(lev, AmrOldTime); // Old time electron auto ldataR_p = getLevelDataReactPtr(lev); // Reaction auto ldataNLs_p = getLevelDataNLSolvePtr(lev); // NL data @@ -996,6 +996,7 @@ PeleLM::setUpPrecond( neke_ma[box_no](i, j, k) = kappaE_ma[box_no](i, j, k) * ne_arr_ma[box_no](i, j, k); }); + amrex::Gpu::streamSynchronize(); if (do_Schur == 1) { amrex::ParallelFor( nEKe, nEKe.nGrowVect(), @@ -1006,31 +1007,6 @@ PeleLM::setUpPrecond( }); } amrex::Gpu::streamSynchronize(); - /* -#ifdef AMREX_USE_OMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(nEKe, amrex::TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const amrex::Box& gbx = mfi.growntilebox(); - auto const& neke = nEKe.array(mfi); - auto const& kappaE = ldata_p->mobE_cc.array(mfi); - auto const& ne_arr = a_nE[lev]->const_array(mfi); - auto const& Schur = - (m_ef_PC_approx == 2) ? Schur_nEKe.array(mfi) : nEKe.array(mfi); - auto const& diffOp_diag = - (m_ef_PC_approx == 2) ? diagDiffOp[lev].array(mfi) : nEKe.array(mfi); - int do_Schur = (m_ef_PC_approx == 2) ? 1 : 0; - amrex::ParallelFor( - gbx, [] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - neke(i, j, k) = kappaE(i, j, k) * ne_arr(i, j, k); - if (do_Schur) { - Schur(i, j, k) = -a_dt * 0.5 * neke(i, j, k) / diffOp_diag(i, j, k); - } - }); - - } - */ // Upwinded edge neKe values amrex::Array neKe_ec = getUpwindedEdge( diff --git a/Source/Plasma/PeleLMeX_EFPoisson.cpp b/Source/Plasma/PeleLMeX_EFPoisson.cpp index bc6161fdb..88aaec09f 100644 --- a/Source/Plasma/PeleLMeX_EFPoisson.cpp +++ b/Source/Plasma/PeleLMeX_EFPoisson.cpp @@ -15,7 +15,6 @@ PeleLM::poissonSolveEF(const TimeStamp a_time) // Build Poisson RHS: charge distribution constexpr int nGhost = 0; - constexpr amrex::Real factor = -1.0; amrex::Vector> rhsPoisson(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { rhsPoisson[lev].reset(new amrex::MultiFab( @@ -31,13 +30,14 @@ PeleLM::poissonSolveEF(const TimeStamp a_time) int box_no, int i, int j, int k) noexcept { amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); amrex::Array4 nE(state_ma[box_no], NE); + constexpr amrex::Real factor = -1.0; rhs_ma[box_no](i, j, k) = -nE(i, j, k) * elemCharge * factor; for (int n = 0; n < NUM_SPECIES; ++n) { rhs_ma[box_no](i, j, k) += zk[n] * rhoY(i, j, k, n) * factor; } }); + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); // Solve for PhiV getDiffusionOp()->diffuse_scalar( GetVecOfPtrs(getPhiVVect(a_time)), 0, GetVecOfConstPtrs(rhsPoisson), 0, {}, diff --git a/Source/Plasma/PeleLMeX_EFTimeStep.cpp b/Source/Plasma/PeleLMeX_EFTimeStep.cpp index b8beb9996..5161bfdfe 100644 --- a/Source/Plasma/PeleLMeX_EFTimeStep.cpp +++ b/Source/Plasma/PeleLMeX_EFTimeStep.cpp @@ -61,6 +61,7 @@ PeleLM::estEFIonsDt(const TimeStamp a_time) } }); } + amrex::Gpu::streamSynchronize(); auto const& efield_const_ma = efield_cc.const_arrays(); auto const& mob_cc_ma = ldata_p->mob_cc.const_arrays(); @@ -85,7 +86,7 @@ PeleLM::estEFIonsDt(const TimeStamp a_time) }); amrex::Gpu::streamSynchronize(); const auto dx = Geom(lev).CellSizeArray(); - amrex::Real cfl_lcl = m_cfl; + const amrex::Real cfl_lcl = m_cfl; estdt_lev = amrex::ReduceMin( driftVelMax_cc, 0, [dx, cfl_lcl] AMREX_GPU_HOST_DEVICE( diff --git a/Source/Plasma/PeleLMeX_EFUtils.cpp b/Source/Plasma/PeleLMeX_EFUtils.cpp index 4e67e6d2d..c3bb84ffa 100644 --- a/Source/Plasma/PeleLMeX_EFUtils.cpp +++ b/Source/Plasma/PeleLMeX_EFUtils.cpp @@ -222,7 +222,7 @@ PeleLM::initializeElectronNeutral() amrex::Array4 nE(state_ma[box_no], NE); initElecNeutral(i, j, k, rho, rhoY, rhoH, temp, nE, *lprobparm); }); - + amrex::Gpu::streamSynchronize(); // Convert I_R(Y_nE) into I_R(nE) and set I_R(Y_nE) to zero auto ldataR_p = getLevelDataReactPtr(lev); auto const& I_R_ma = ldataR_p->I_R.arrays(); From e41af65929bdd5cc3225ce081f166cec89edd068 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Thu, 21 Aug 2025 20:59:33 +0200 Subject: [PATCH 58/87] remove comments --- Source/PeleLMeX_Forces.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 9437a2fe7..85dd32c98 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -57,9 +57,6 @@ PeleLM::getVelForces( auto ext_ma = m_extSource[lev]->const_arrays(); auto force_ma = a_velForce->arrays(); - // auto gp_ma = (add_gradP != 0) ? ldataGP_p->gp.const_arrays() : state_ma; - // auto divTau_ma = (has_divTau != 0) ? a_divTau->const_arrays() : state_ma; - const auto dx = geom[lev].CellSizeArray(); const int pseudo_gravity = m_ctrl_pseudoGravity; const amrex::Real dV_control = m_ctrl_dV; @@ -70,12 +67,11 @@ PeleLM::getVelForces( const int ps_dir = m_ctrl_flameDir; amrex::ParallelFor( - *a_velForce, - [state_ma, ext_ma, force_ma, dx, /*gp_ma, divTau_ma,add_gradP,has_divTau,*/ - time, grav, gp0, ps_dir, is_incomp, rho_incomp, pseudo_gravity, dV_control + *a_velForce, [state_ma, ext_ma, force_ma, dx, time, grav, gp0, ps_dir, + is_incomp, rho_incomp, pseudo_gravity, dV_control #ifdef PELE_USE_PLASMA - , - plasma_ba = grids[lev], zk = zk + , + plasma_ba = grids[lev], zk = zk #endif ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) { amrex::Array4 vel(state_ma[box_no], VELX); From c8f7a729f00c10e98563b5797d4d9fc7c3085205 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 22 Aug 2025 10:24:37 +0200 Subject: [PATCH 59/87] combine kernels, const& --- Source/PeleLMeX_Advection.cpp | 36 +++++----- Source/PeleLMeX_Diffusion.cpp | 67 +++++++++--------- Source/PeleLMeX_DiffusionOp.cpp | 22 +++--- Source/PeleLMeX_Forces.cpp | 100 ++++++++++++++++++--------- Source/PeleLMeX_Init.cpp | 4 +- Source/PeleLMeX_K.H | 5 -- Source/PeleLMeX_Plot.cpp | 6 +- Source/PeleLMeX_Projection.cpp | 22 +++--- Source/PeleLMeX_Timestep.cpp | 4 +- Source/PeleLMeX_TransportProp.cpp | 2 +- Source/PeleLMeX_UMac.cpp | 87 ++++++++++++++--------- Source/Plasma/PeleLMeX_EFPoisson.cpp | 4 +- 12 files changed, 209 insertions(+), 150 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index f7a026660..144f52ed5 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -242,10 +242,10 @@ PeleLM::updateVelocity(std::unique_ptr& advData) // Compute provisional new velocity // velForce holds: 1/\rho^{n+1/2} [(gravity+...)^{n+1/2} - \nabla pi^{n} + // 0.5 * divTau^{n}] - auto state_old_ma = ldataOld_p->state.const_arrays(); - auto adv_aofs_ma = advData->AofS[lev].const_arrays(); - auto force_ma = velForces[lev].const_arrays(); - auto state_new_ma = ldataNew_p->state.arrays(); + auto const& state_old_ma = ldataOld_p->state.const_arrays(); + auto const& adv_aofs_ma = advData->AofS[lev].const_arrays(); + auto const& force_ma = velForces[lev].const_arrays(); + auto const& state_new_ma = ldataNew_p->state.arrays(); amrex::ParallelFor( ldataOld_p->state, [state_old_ma, adv_aofs_ma, force_ma, state_new_ma, @@ -277,15 +277,15 @@ PeleLM::getScalarAdvForce( auto* ldata_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataR_p = getLevelDataReactPtr(lev); - auto state_ma = ldata_p->state.const_arrays(); - auto dn_ma = diffData->Dn[lev].const_arrays(); - auto adv_ma = advData->Forcing[lev].arrays(); - auto r_ma = ldataR_p->I_R.const_arrays(); - auto ext_ma = m_extSource[lev]->arrays(); + auto const& state_ma = ldata_p->state.const_arrays(); + auto const& dn_ma = diffData->Dn[lev].const_arrays(); + auto const& adv_ma = advData->Forcing[lev].arrays(); + auto const& r_ma = ldataR_p->I_R.const_arrays(); + auto const& ext_ma = m_extSource[lev]->arrays(); - auto dn_aux_ma = + auto const& dn_aux_ma = (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : dn_ma; - auto adv_aux_ma = + auto const& adv_aux_ma = (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : adv_ma; amrex::ParallelFor( @@ -919,7 +919,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) //---------------------------------------------------------------- // Sum over the species AofS to get the density advection term for (int lev = 0; lev <= finest_level; ++lev) { - auto aofsma = advData->AofS[lev].arrays(); + auto const& aofsma = advData->AofS[lev].arrays(); amrex::ParallelFor( advData->AofS[lev], [aofsma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { @@ -938,8 +938,8 @@ PeleLM::updateDensity(std::unique_ptr& advData) // Get MultiArrays auto const& sma_o = getLevelDataPtr(lev, AmrOldTime)->state.arrays(); auto const& sma_n = getLevelDataPtr(lev, AmrNewTime)->state.arrays(); - auto aofsma = advData->AofS[lev].const_arrays(); - auto extma = m_extSource[lev]->const_arrays(); + auto const& aofsma = advData->AofS[lev].const_arrays(); + auto const& extma = m_extSource[lev]->const_arrays(); const auto dt = m_dt; amrex::ParallelFor( @@ -1126,10 +1126,10 @@ PeleLM::updateScalarComp( auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - auto state_old_ma = ldataOld_p->state.const_arrays(); - auto adv_aofs_ma = advData->AofS[lev].const_arrays(); - auto ext_ma = m_extSource[lev]->const_arrays(); - auto state_new_ma = ldataNew_p->state.arrays(); + auto const& state_old_ma = ldataOld_p->state.const_arrays(); + auto const& adv_aofs_ma = advData->AofS[lev].const_arrays(); + auto const& ext_ma = m_extSource[lev]->const_arrays(); + auto const& state_new_ma = ldataNew_p->state.arrays(); amrex::ParallelFor( ldataOld_p->state, diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 0cd5f3e07..db7aa4b9b 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -1125,11 +1125,13 @@ PeleLM::differentialDiffusionUpdate( // Get t^{n} data pointer auto* ldata_p = getLevelDataPtr(lev, AmrOldTime); - auto state_ma = ldata_p->state.const_arrays(); - auto fY_ma = advData->Forcing[lev].arrays(); + auto const& state_ma = ldata_p->state.const_arrays(); + auto const& fY_ma = advData->Forcing[lev].arrays(); - auto aux_ma = (m_nAux > 0) ? ldata_p->auxiliaries.const_arrays() : state_ma; - auto fAux_ma = (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : fY_ma; + auto const& aux_ma = + (m_nAux > 0) ? ldata_p->auxiliaries.const_arrays() : state_ma; + auto const& fAux_ma = + (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : fY_ma; amrex::ParallelFor( advData->Forcing[lev], @@ -1320,18 +1322,19 @@ PeleLM::differentialDiffusionUpdate( auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - auto state_ma = ldata_p->state.arrays(); - auto dhat_ma = diffData->Dhat[lev].const_arrays(); - auto force_ma = advData->Forcing[lev].const_arrays(); + auto const& state_ma = ldata_p->state.arrays(); + auto const& dhat_ma = diffData->Dhat[lev].const_arrays(); + auto const& force_ma = advData->Forcing[lev].const_arrays(); - auto dwbar_ma = + auto const& dwbar_ma = (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dhat_ma; - auto dT_ma = + auto const& dT_ma = (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dhat_ma; - auto aux_ma = (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : state_ma; - auto dhat_aux_ma = + auto const& aux_ma = + (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : state_ma; + auto const& dhat_aux_ma = (m_nAux > 0) ? diffData->Dhat_aux[lev].const_arrays() : dhat_ma; - auto force_aux_ma = + auto const& force_aux_ma = (m_nAux > 0) ? advData->Forcing_aux[lev].const_arrays() : dhat_ma; if (m_use_wbar != 0 && m_use_soret != 0) { @@ -1590,13 +1593,13 @@ PeleLM::deltaTIter_prepare( auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - auto state_old_ma = ldataOld_p->state.const_arrays(); - auto state_new_ma = ldataNew_p->state.const_arrays(); - auto force_ma = advData->Forcing[lev].const_arrays(); - auto dhat_ma = diffData->Dhat[lev].const_arrays(); - auto rhs_ma = a_rhs[lev]->arrays(); - auto rhocp_ma = a_rhoCp[lev]->arrays(); - auto tsave_ma = a_Tsave[lev]->arrays(); + auto const& state_old_ma = ldataOld_p->state.const_arrays(); + auto const& state_new_ma = ldataNew_p->state.const_arrays(); + auto const& force_ma = advData->Forcing[lev].const_arrays(); + auto const& dhat_ma = diffData->Dhat[lev].const_arrays(); + auto const& rhs_ma = a_rhs[lev]->arrays(); + auto const& rhocp_ma = a_rhoCp[lev]->arrays(); + auto const& tsave_ma = a_Tsave[lev]->arrays(); amrex::ParallelFor( ldataNew_p->state, @@ -1752,22 +1755,24 @@ PeleLM::getScalarDiffForce( // Get t^{n} data pointer auto* ldataR_p = getLevelDataReactPtr(lev); - auto dn_ma = diffData->Dn[lev].const_arrays(); - auto dnp1_ma = diffData->Dnp1[lev].const_arrays(); - auto r_ma = ldataR_p->I_R.const_arrays(); - auto a_ma = advData->AofS[lev].const_arrays(); - auto ext_ma = m_extSource[lev]->const_arrays(); - auto f_ma = advData->Forcing[lev].arrays(); + auto const& dn_ma = diffData->Dn[lev].const_arrays(); + auto const& dnp1_ma = diffData->Dnp1[lev].const_arrays(); + auto const& r_ma = ldataR_p->I_R.const_arrays(); + auto const& a_ma = advData->AofS[lev].const_arrays(); + auto const& ext_ma = m_extSource[lev]->const_arrays(); + auto const& f_ma = advData->Forcing[lev].arrays(); - auto dwbar_ma = + auto const& dwbar_ma = (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dn_ma; - auto dT_ma = (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dn_ma; - auto f_aux_ma = (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : f_ma; - auto a_aux_ma = + auto const& dT_ma = + (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dn_ma; + auto const& f_aux_ma = + (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : f_ma; + auto const& a_aux_ma = (m_nAux > 0) ? advData->AofS_aux[lev].const_arrays() : dn_ma; - auto dn_aux_ma = + auto const& dn_aux_ma = (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : dn_ma; - auto dnp1_aux_ma = + auto const& dnp1_aux_ma = (m_nAux > 0) ? diffData->Dnp1_aux[lev].const_arrays() : dn_ma; amrex::ParallelFor( diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index baba0f25f..084626da7 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -286,9 +286,9 @@ DiffusionOp::diffuse_scalar( } } else { for (int lev = 0; lev <= finest_level; ++lev) { - auto a_phi_ma = a_phi[lev]->arrays(); - auto phi_ma = phi[lev].const_arrays(); - auto a_rho_ma = a_density[lev]->const_arrays(); + auto const& a_phi_ma = a_phi[lev]->arrays(); + auto const& phi_ma = phi[lev].const_arrays(); + auto const& a_rho_ma = a_density[lev]->const_arrays(); amrex::ParallelFor( phi[lev], [a_phi_ma, a_rho_ma, phi_ma, ncomp] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { @@ -497,9 +497,9 @@ DiffusionOp::diffuse_scalar( } } else { for (int lev = 0; lev <= finest_level; ++lev) { - auto a_phi_ma = a_phi[lev]->arrays(); - auto phi_ma = phi[lev].const_arrays(); - auto a_rho_ma = a_density[lev]->const_arrays(); + auto const& a_phi_ma = a_phi[lev]->arrays(); + auto const& phi_ma = phi[lev].const_arrays(); + auto const& a_rho_ma = a_density[lev]->const_arrays(); amrex::ParallelFor( phi[lev], [a_phi_ma, a_rho_ma, phi_ma, ncomp] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { @@ -1190,8 +1190,8 @@ DiffusionTensorOp::compute_divtau( if (have_density != 0) { for (int lev = 0; lev <= finest_level; ++lev) { - auto divtau_ma = a_divtau[lev]->arrays(); - auto rho_ma = a_density[lev]->const_arrays(); + auto const& divtau_ma = a_divtau[lev]->arrays(); + auto const& rho_ma = a_density[lev]->const_arrays(); amrex::ParallelFor( *a_divtau[lev], [divtau_ma, rho_ma] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { @@ -1255,10 +1255,10 @@ DiffusionTensorOp::diffuse_velocity( for (int lev = 0; lev <= finest_level; ++lev) { rhs.emplace_back( a_vel[lev]->boxArray(), a_vel[lev]->DistributionMap(), AMREX_SPACEDIM, 0); - auto rhs_ma = rhs[lev].arrays(); - auto vel_ma = a_vel[lev]->const_arrays(); + auto const& rhs_ma = rhs[lev].arrays(); + auto const& vel_ma = a_vel[lev]->const_arrays(); if (m_pelelm->m_incompressible == 0) { - auto rho_ma = a_density[lev]->const_arrays(); + auto const& rho_ma = a_density[lev]->const_arrays(); amrex::ParallelFor( rhs[lev], [rhs_ma, vel_ma, rho_ma] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 85dd32c98..a5757dc10 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -51,57 +51,92 @@ PeleLM::getVelForces( const amrex::Real time = getTime(lev, a_time); + const int is_incomp = m_incompressible; + const amrex::Real rho_incomp = m_rho; const int has_divTau = static_cast(a_divTau != nullptr); - auto state_ma = ldata_p->state.const_arrays(); - auto ext_ma = m_extSource[lev]->const_arrays(); - auto force_ma = a_velForce->arrays(); - - const auto dx = geom[lev].CellSizeArray(); const int pseudo_gravity = m_ctrl_pseudoGravity; const amrex::Real dV_control = m_ctrl_dV; - const int is_incomp = m_incompressible; - const amrex::Real rho_incomp = m_rho; const auto grav = m_gravity; const auto gp0 = m_background_gp; const int ps_dir = m_ctrl_flameDir; + auto const& state_ma = ldata_p->state.const_arrays(); + auto const& ext_ma = m_extSource[lev]->const_arrays(); + auto const& force_ma = a_velForce->arrays(); + auto const& gp_ma = ldataGP_p->gp.const_arrays(); + auto const& divTau_ma = a_divTau->const_arrays(); + +#ifdef PELE_USE_PLASMA + auto const& dx = geom[lev].CellSizeArray(); + auto const& ba = grids[lev]; + auto const& zkl = zk; +#endif + amrex::ParallelFor( - *a_velForce, [state_ma, ext_ma, force_ma, dx, time, grav, gp0, ps_dir, - is_incomp, rho_incomp, pseudo_gravity, dV_control + *a_velForce, + [state_ma, ext_ma, force_ma, grav, gp0, ps_dir, add_gradP, gp_ma, + has_divTau, divTau_ma, is_incomp, rho_incomp, pseudo_gravity, dV_control #ifdef PELE_USE_PLASMA - , - plasma_ba = grids[lev], zk = zk + , + dx, time, ba, zkl #endif ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) { amrex::Array4 vel(state_ma[box_no], VELX); - amrex::Array4 rho(state_ma[box_no], DENSITY); - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - amrex::Array4 rhoh(state_ma[box_no], RHOH); - amrex::Array4 temp(state_ma[box_no], TEMP); amrex::Array4 extmom(ext_ma[box_no], VELX); - amrex::Array4 extrho(ext_ma[box_no], DENSITY); + amrex::Array4 rho; + amrex::Array4 extrho; + if (is_incomp == 0) { + rho = amrex::Array4(state_ma[box_no], DENSITY); + extrho = amrex::Array4(ext_ma[box_no], DENSITY); + } + // background gp, pseudo grav, ext sources makeVelForce( - i, j, k, is_incomp, rho_incomp, pseudo_gravity, ps_dir, time, grav, gp0, - dV_control, dx, vel, rho, rhoY, rhoh, temp, extmom, extrho, - force_ma[box_no]); + i, j, k, is_incomp, rho_incomp, pseudo_gravity, ps_dir, grav, gp0, + dV_control, vel, rho, extmom, extrho, force_ma[box_no]); #ifdef PELE_USE_PLASMA + amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); + amrex::Array4 rhoh(state_ma[box_no], RHOH); + amrex::Array4 temp(state_ma[box_no], TEMP); amrex::Array4 phiV(state_ma[box_no], PHIV); amrex::Array4 nE(state_ma[box_no], NE); - amrex::GpuArray blo = plasma_ba[box_no].loVect3d(); - amrex::GpuArray bhi = plasma_ba[box_no].hiVect3d(); + amrex::GpuArray blo = ba[box_no].loVect3d(); + amrex::GpuArray bhi = ba[box_no].hiVect3d(); addLorentzForce( - i, j, k, blo, bhi, time, dx, zk, rhoY, nE, phiV, force_ma[box_no]); + i, j, k, blo, bhi, time, dx, zkl, rhoY, nE, phiV, force_ma[box_no]); #endif + if (add_gradP != 0) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + force_ma[box_no](i, j, k, idim) -= gp_ma[box_no](i, j, k, idim); + } + } + if (has_divTau != 0) { + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + force_ma[box_no](i, j, k, idim) += divTau_ma[box_no](i, j, k, idim); + } + } }); amrex::Gpu::streamSynchronize(); - if (add_gradP != 0) { - amrex::MultiFab::Subtract( - *a_velForce, ldataGP_p->gp, 0, 0, AMREX_SPACEDIM, 0); - } - if (has_divTau != 0) { - amrex::MultiFab::Add(*a_velForce, *a_divTau, 0, 0, AMREX_SPACEDIM, 0); + // Add forcing terms to maintain turbulence + // note: if m_incompressible == 0 then m_rho is unused by + // addTurbVelForces + if (m_do_turbulent_forcing) { +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(*a_velForce, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const auto& bx = mfi.tilebox(); + amrex::FArrayBox DummyFab(bx, 1); + const auto& rho_arr = (is_incomp != 0) + ? DummyFab.array() + : ldata_p->state.const_array(mfi, DENSITY); + const auto& force_arr = a_velForce->array(mfi); + turb_forcing.addTurbVelForces( + geom[lev].data(), bx, time, force_arr, rho_arr, is_incomp, rho_incomp); + } } + if (is_incomp != 0) { a_velForce->mult(1.0 / rho_incomp, 0, AMREX_SPACEDIM, 0); } else { @@ -152,8 +187,9 @@ PeleLM::addSpark(const TimeStamp a_timestamp) auto const* eosparm = eos_parms.device_parm(); auto eos = pele::physics::PhysicsType::eos(eosparm); - auto statema = getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); - auto extma = m_extSource[lev]->arrays(); + auto const& statema = + getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); + auto const& extma = m_extSource[lev]->arrays(); amrex::ParallelFor( *m_extSource[lev], [statema, extma, eos, dx, spark_idx, @@ -270,8 +306,8 @@ PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) auto const& gx = grad_fc[lev][0].const_arrays(); , auto const& gy = grad_fc[lev][1].const_arrays(); , auto const& gz = grad_fc[lev][2].const_arrays();) - auto extma = m_extSource[lev]->arrays(); - auto statema = ldata_p->state.const_arrays(); + auto const& extma = m_extSource[lev]->arrays(); + auto const& statema = ldata_p->state.const_arrays(); // l_scale will also need modification for EB const amrex::Real vol = AMREX_D_TERM( diff --git a/Source/PeleLMeX_Init.cpp b/Source/PeleLMeX_Init.cpp index 2614a209d..55ca06962 100644 --- a/Source/PeleLMeX_Init.cpp +++ b/Source/PeleLMeX_Init.cpp @@ -355,8 +355,8 @@ PeleLM::initLevelData(const int lev) // don't want to use state for dummy in case user overwrites state in aux amrex::MultiFab dummy_mf(grids[lev], dmap[lev], 1, 0); - auto state_ma = ldata_p->state.arrays(); - auto aux_ma = + auto const& state_ma = ldata_p->state.arrays(); + auto const& aux_ma = (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : dummy_mf.arrays(); amrex::ParallelFor( diff --git a/Source/PeleLMeX_K.H b/Source/PeleLMeX_K.H index 491a58572..43301ba38 100644 --- a/Source/PeleLMeX_K.H +++ b/Source/PeleLMeX_K.H @@ -737,16 +737,11 @@ makeVelForce( const amrex::Real rho_incomp, const int pseudo_gravity, const int pseudo_gravity_dir, - const amrex::Real /*time*/, amrex::GpuArray const& gravity, amrex::GpuArray const& gp0, const amrex::Real dV_control, - amrex::GpuArray const& /*dx*/, amrex::Array4 const& vel, amrex::Array4 const& rho, - amrex::Array4 const& /*rhoY*/, - amrex::Array4 const& /*rhoh*/, - amrex::Array4 const& /*temp*/, amrex::Array4 const& extmom, amrex::Array4 const& extrho, amrex::Array4 const& force) noexcept diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 2de37cc89..a0d4d2ab6 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -1020,7 +1020,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) // Converting units when pltfile is coming from PeleC solution if (pltfileSource == "C") { amrex::Print() << " Converting CGS to MKS units... \n"; - auto state_ma = ldata_p->state.arrays(); + auto const& state_ma = ldata_p->state.arrays(); amrex::ParallelFor( ldata_p->state, [state_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { @@ -1047,7 +1047,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) SootConst sc; amrex::Real* momV = sc.MomOrderV.data(); amrex::Real* momS = sc.MomOrderS.data(); - auto state_ma = ldata_p->state.arrays(); + auto const& state_ma = ldata_p->state.arrays(); amrex::Real soot_exp[NUM_SOOT_MOMENTS] = {0.0}; for (int n = 0; n < NUM_SOOT_MOMENTS; ++n) { soot_exp[n] = 3. - (3. * momV[n] + 2. * momS[n]); @@ -1089,7 +1089,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) // Enforce rho and rhoH consistent with temperature and mixture // The above handles species mapping (to some extent), but nothing enforce // sum of Ys = 1 -> use N2 in the following if N2 is present - auto state_ma = ldata_p->state.arrays(); + auto const& state_ma = ldata_p->state.arrays(); auto const* leosparm = eos_parms.device_parm(); const amrex::Real P_cgs = m2c::P(lprobparm->P_mean); diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 7b8ccdc2c..556dae4e5 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -30,8 +30,8 @@ PeleLM::initialProjection() grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - auto state_ma = ldata_p->state.const_arrays(); - auto sigma_ma = sigma[lev]->arrays(); + auto const& state_ma = ldata_p->state.const_arrays(); + auto const& sigma_ma = sigma[lev]->arrays(); amrex::ParallelFor( ldata_p->state, [state_ma, sigma_ma] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { @@ -156,8 +156,8 @@ PeleLM::initialPressProjection() grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - auto state_ma = ldata_p->state.const_arrays(); - auto sigma_ma = sigma[lev]->arrays(); + auto const& state_ma = ldata_p->state.const_arrays(); + auto const& sigma_ma = sigma[lev]->arrays(); amrex::ParallelFor( ldata_p->state, [state_ma, sigma_ma] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { @@ -218,8 +218,8 @@ PeleLM::velocityProjection( std::make_unique( grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); - auto rhoHalf_ma = rhoHalf[lev]->const_arrays(); - auto sigma_ma = sigma[lev]->arrays(); + auto const& rhoHalf_ma = rhoHalf[lev]->const_arrays(); + auto const& sigma_ma = sigma[lev]->arrays(); amrex::ParallelFor( *rhoHalf[lev], [rhoHalf_ma, sigma_ma, dt = a_dt] AMREX_GPU_DEVICE( @@ -245,9 +245,9 @@ PeleLM::velocityProjection( for (int lev = 0; lev <= finest_level; ++lev) { auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - auto state_old_ma = ldataOld_p->state.arrays(); - auto gp_new_ma = ldataNew_p->gp.const_arrays(); - auto rho_ma = rhoHalf[lev]->const_arrays(); + auto const& state_old_ma = ldataOld_p->state.arrays(); + auto const& gp_new_ma = ldataNew_p->gp.const_arrays(); + auto const& rho_ma = rhoHalf[lev]->const_arrays(); amrex::ParallelFor( ldataNew_p->state, [state_old_ma, gp_new_ma, rho_ma, dt = a_dt] AMREX_GPU_DEVICE( @@ -263,8 +263,8 @@ PeleLM::velocityProjection( for (int lev = 0; lev <= finest_level; ++lev) { auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - auto state_old_ma = ldataOld_p->state.arrays(); - auto gp_new_ma = ldataNew_p->gp.const_arrays(); + auto const& state_old_ma = ldataOld_p->state.arrays(); + auto const& gp_new_ma = ldataNew_p->gp.const_arrays(); const amrex::Real soverrho = m_dt / m_rho; amrex::ParallelFor( ldataNew_p->state, diff --git a/Source/PeleLMeX_Timestep.cpp b/Source/PeleLMeX_Timestep.cpp index 45c2bb456..c033bb543 100644 --- a/Source/PeleLMeX_Timestep.cpp +++ b/Source/PeleLMeX_Timestep.cpp @@ -240,8 +240,8 @@ PeleLM::checkDt(const TimeStamp a_time, const amrex::Real a_dt) const amrex::GpuArray dxinv = geom[lev].InvCellSizeArray(); - auto state_ma = ldata_p->state.const_arrays(); - auto divu_ma = ldata_p->divu.const_arrays(); + auto const& state_ma = ldata_p->state.const_arrays(); + auto const& divu_ma = ldata_p->divu.const_arrays(); amrex::ParallelFor( ldata_p->state, diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index df648c813..c30c208c1 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -99,7 +99,7 @@ PeleLM::calcTurbViscosity(const TimeStamp a_time) #ifdef AMREX_USE_EB auto const& ebfact = EBFactory(lev); - auto const vfrac = ebfact.getVolFrac().const_arrays(); + auto const& vfrac = ebfact.getVolFrac().const_arrays(); #endif if (m_les_model == "Smagorinsky") { const amrex::Real prefact = diff --git a/Source/PeleLMeX_UMac.cpp b/Source/PeleLMeX_UMac.cpp index 503f0aa9d..fbe0f53a0 100644 --- a/Source/PeleLMeX_UMac.cpp +++ b/Source/PeleLMeX_UMac.cpp @@ -108,43 +108,66 @@ PeleLM::addChiIncrement( // Add chiIncr to chi and add chi to mac_divu // Both mac_divu and chiIncr have properly filled ghost cells -> work on // grownbox - for (int lev = 0; lev <= finest_level; ++lev) { - if (a_sdcIter == 1) { - // fill chi on first SDC iter - if (m_chi_correction_type == ChiCorrectionType::DivuFirstIter) { - auto const& chiInc_ma = chiIncr[lev].const_arrays(); - auto const& chi_ma = advData->chi[lev].arrays(); - auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); - amrex::ParallelFor( - advData->chi[lev], advData->chi[lev].nGrowVect(), - [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { + switch (m_chi_correction_type) { + case ChiCorrectionType::DivuFirstIter: { + for (int lev = 0; lev <= finest_level; ++lev) { + auto const& chiInc_ma = chiIncr[lev].const_arrays(); + auto const& chi_ma = advData->chi[lev].arrays(); + auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); + amrex::ParallelFor( + advData->chi[lev], advData->chi[lev].nGrowVect(), + [chi_ma, chiInc_ma, mac_divu_ma, + a_sdcIter] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + if (a_sdcIter == 1) { chi_ma[box_no](i, j, k) = chiInc_ma[box_no](i, j, k) + mac_divu_ma[box_no](i, j, k); - }); - amrex::Gpu::streamSynchronize(); - } else { - amrex::MultiFab::Copy( - advData->chi[lev], chiIncr[lev], 0, 0, 1, - advData->chi[lev].nGrowVect()); - } - } else { - amrex::MultiFab::Add( - advData->chi[lev], chiIncr[lev], 0, 0, 1, - advData->chi[lev].nGrowVect()); + } else { + chi_ma[box_no](i, j, k) += chiInc_ma[box_no](i, j, k); + } + mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); + }); } - if ( - m_chi_correction_type == ChiCorrectionType::DivuFirstIter || - m_chi_correction_type == ChiCorrectionType::NoDivu) { - amrex::MultiFab::Copy( - advData->mac_divu[lev], advData->chi[lev], 0, 0, 1, - advData->chi[lev].nGrowVect()); - } else { - amrex::MultiFab::Add( - advData->mac_divu[lev], advData->chi[lev], 0, 0, 1, - advData->chi[lev].nGrowVect()); + break; + } + case ChiCorrectionType::NoDivu: { + for (int lev = 0; lev <= finest_level; ++lev) { + auto const& chiInc_ma = chiIncr[lev].const_arrays(); + auto const& chi_ma = advData->chi[lev].arrays(); + auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); + amrex::ParallelFor( + advData->chi[lev], advData->chi[lev].nGrowVect(), + [chi_ma, chiInc_ma, mac_divu_ma, + a_sdcIter] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + if (a_sdcIter == 1) { + chi_ma[box_no](i, j, k) = chiInc_ma[box_no](i, j, k); + } else { + chi_ma[box_no](i, j, k) += chiInc_ma[box_no](i, j, k); + } + mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); + }); + } + break; + } + default: { + for (int lev = 0; lev <= finest_level; ++lev) { + auto const& chiInc_ma = chiIncr[lev].const_arrays(); + auto const& chi_ma = advData->chi[lev].arrays(); + auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); + amrex::ParallelFor( + advData->chi[lev], advData->chi[lev].nGrowVect(), + [chi_ma, chiInc_ma, mac_divu_ma, + a_sdcIter] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + if (a_sdcIter == 1) { + chi_ma[box_no](i, j, k) = chiInc_ma[box_no](i, j, k); + } else { + chi_ma[box_no](i, j, k) += chiInc_ma[box_no](i, j, k); + } + mac_divu_ma[box_no](i, j, k) += chi_ma[box_no](i, j, k); + }); } } + } + amrex::Gpu::streamSynchronize(); if (m_print_chi_convergence) { const amrex::Real max_corr = MLNorm0(GetVecOfConstPtrs(chiIncr)) * m_dt / m_dpdtFactor; diff --git a/Source/Plasma/PeleLMeX_EFPoisson.cpp b/Source/Plasma/PeleLMeX_EFPoisson.cpp index 88aaec09f..5da531a04 100644 --- a/Source/Plasma/PeleLMeX_EFPoisson.cpp +++ b/Source/Plasma/PeleLMeX_EFPoisson.cpp @@ -22,8 +22,8 @@ PeleLM::poissonSolveEF(const TimeStamp a_time) auto ldata_p = getLevelDataPtr(lev, a_time); - auto state_ma = ldata_p->state.const_arrays(); - auto rhs_ma = rhsPoisson[lev]->arrays(); + auto const& state_ma = ldata_p->state.const_arrays(); + auto const& rhs_ma = rhsPoisson[lev]->arrays(); amrex::ParallelFor( ldata_p->state, [state_ma, rhs_ma, zk = zk] AMREX_GPU_DEVICE( From d2fa3a6a8812d9c47f49a50b8431101a7b15484d Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 22 Aug 2025 10:31:09 +0200 Subject: [PATCH 60/87] wrong incomp --- Source/PeleLMeX_Forces.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index a5757dc10..2357801c4 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -86,7 +86,7 @@ PeleLM::getVelForces( amrex::Array4 extmom(ext_ma[box_no], VELX); amrex::Array4 rho; amrex::Array4 extrho; - if (is_incomp == 0) { + if (is_incomp != 0) { rho = amrex::Array4(state_ma[box_no], DENSITY); extrho = amrex::Array4(ext_ma[box_no], DENSITY); } From 55f11b42e240ba9b747eec71c2a048a7ac17d2e4 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 22 Aug 2025 10:39:16 +0200 Subject: [PATCH 61/87] fix typos --- Source/PeleLMeX_Forces.cpp | 5 +++-- Source/PeleLMeX_Timestep.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 2357801c4..0e2d489bb 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -65,7 +65,8 @@ PeleLM::getVelForces( auto const& ext_ma = m_extSource[lev]->const_arrays(); auto const& force_ma = a_velForce->arrays(); auto const& gp_ma = ldataGP_p->gp.const_arrays(); - auto const& divTau_ma = a_divTau->const_arrays(); + auto const& divTau_ma = + (has_divTau != 0) ? a_divTau->const_arrays() : state_ma; #ifdef PELE_USE_PLASMA auto const& dx = geom[lev].CellSizeArray(); @@ -86,7 +87,7 @@ PeleLM::getVelForces( amrex::Array4 extmom(ext_ma[box_no], VELX); amrex::Array4 rho; amrex::Array4 extrho; - if (is_incomp != 0) { + if (is_incomp == 0) { rho = amrex::Array4(state_ma[box_no], DENSITY); extrho = amrex::Array4(ext_ma[box_no], DENSITY); } diff --git a/Source/PeleLMeX_Timestep.cpp b/Source/PeleLMeX_Timestep.cpp index c033bb543..9a491e113 100644 --- a/Source/PeleLMeX_Timestep.cpp +++ b/Source/PeleLMeX_Timestep.cpp @@ -114,12 +114,12 @@ PeleLM::estConvectiveDt(const TimeStamp a_time) //---------------------------------------------------------------- // Get velocity forces - int nGrow_force = 0; + constexpr int nGrow_force = 0; amrex::MultiFab velForces( grids[lev], dmap[lev], AMREX_SPACEDIM, nGrow_force, amrex::MFInfo(), Factory(lev)); - int add_gradP = 1; + constexpr int add_gradP = 1; getVelForces(a_time, lev, nullptr, &velForces, add_gradP); //---------------------------------------------------------------- From 871f0694da0e9ad549685653f8941d7bee89bacb Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 22 Aug 2025 11:10:37 +0200 Subject: [PATCH 62/87] incomp fixes --- Source/PeleLMeX_Forces.cpp | 11 ++++++----- Source/PeleLMeX_Projection.cpp | 34 +++++++++++++--------------------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 0e2d489bb..eda2b424c 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -85,11 +85,12 @@ PeleLM::getVelForces( ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) { amrex::Array4 vel(state_ma[box_no], VELX); amrex::Array4 extmom(ext_ma[box_no], VELX); - amrex::Array4 rho; - amrex::Array4 extrho; - if (is_incomp == 0) { - rho = amrex::Array4(state_ma[box_no], DENSITY); - extrho = amrex::Array4(ext_ma[box_no], DENSITY); + amrex::Array4 rho(state_ma[box_no], DENSITY); + amrex::Array4 extrho(ext_ma[box_no], DENSITY); + // overwrite if incompressible, just to point to something + if (is_incomp != 0) { + rho = vel; + extrho = extmom; } // background gp, pseudo grav, ext sources makeVelForce( diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 556dae4e5..aca27273e 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -16,18 +16,16 @@ PeleLM::initialProjection() " W: " << velMax[2] <<) "\n"; } - constexpr amrex::Real dummy_dt = 1.0; constexpr int incremental = 0; constexpr int nGhost = 0; + constexpr amrex::Real dummy_dt = 1.0; // Get sigma : density if not incompressible - amrex::Vector> sigma; + amrex::Vector> sigma(finest_level + 1); if (m_incompressible == 0) { - sigma.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - sigma.emplace_back( - std::make_unique( - grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); + sigma[lev] = std::make_unique( + grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev]); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); auto const& state_ma = ldata_p->state.const_arrays(); @@ -48,12 +46,10 @@ PeleLM::initialProjection() } // Get velocity - amrex::Vector> vel; - vel.reserve(finest_level + 1); + amrex::Vector> vel(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - vel.emplace_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); + vel[lev] = std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM); vel[lev]->setBndry(0.0); setInflowBoundaryVel(*vel[lev], lev, AmrNewTime); #if AMREX_SPACEDIM == 2 @@ -207,16 +203,14 @@ PeleLM::velocityProjection( const int incremental = (is_initIter) != 0 ? 1 : 0; // Get sigma : scaled density inv. if not incompressible - amrex::Vector> sigma; + amrex::Vector> sigma(finest_level + 1); if (m_incompressible == 0) { amrex::Vector> rhoHalf = getDensityVect(a_rhoTime); - sigma.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - sigma.emplace_back( - std::make_unique( - grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); + sigma[lev] = std::make_unique( + grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev]); auto const& rhoHalf_ma = rhoHalf[lev]->const_arrays(); auto const& sigma_ma = sigma[lev]->arrays(); @@ -292,12 +286,10 @@ PeleLM::velocityProjection( } // Get velocity - amrex::Vector> vel; - vel.reserve(finest_level + 1); + amrex::Vector> vel(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - vel.emplace_back( - std::make_unique( - m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM)); + vel[lev] = std::make_unique( + m_leveldata_new[lev]->state, amrex::make_alias, VELX, AMREX_SPACEDIM); #ifdef AMREX_USE_EB EB_set_covered(*vel[lev], 0.0); #endif From e47b332d6a2c9b5d7c146f7c47cd13eeb85612f6 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 22 Aug 2025 11:50:17 +0200 Subject: [PATCH 63/87] shift syncs inside --- Source/PeleLMeX_Advection.cpp | 9 ++++++--- Source/PeleLMeX_Diffusion.cpp | 9 ++++++--- Source/PeleLMeX_DiffusionOp.cpp | 9 ++++++--- Source/PeleLMeX_Forces.cpp | 3 ++- Source/PeleLMeX_Projection.cpp | 21 ++++++++++----------- Source/PeleLMeX_Soot.cpp | 3 ++- Source/PeleLMeX_UMac.cpp | 7 ++++++- Source/PeleLMeX_Utils.cpp | 3 ++- 8 files changed, 40 insertions(+), 24 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 144f52ed5..fbf443995 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -258,8 +258,9 @@ PeleLM::updateVelocity(std::unique_ptr& advData) force_ma[box_no](i, j, k, n)); } }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } void @@ -312,8 +313,9 @@ PeleLM::getScalarAdvForce( is_closed_ch, do_react, fY, fT, fAux, dn_aux, aux_diffuse_d, nAux, leosparm); }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); // Fill forcing ghost cells if (advData->Forcing[0].nGrow() > 0) { fillpatch_forces( @@ -1141,7 +1143,8 @@ PeleLM::updateScalarComp( dt * (adv_aofs_ma[box_no](i, j, k, n) + ext_ma[box_no](i, j, k, n)); } }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); averageDown(AmrNewTime, state_comp, ncomp); } diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index db7aa4b9b..dec34a533 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -1148,8 +1148,9 @@ PeleLM::differentialDiffusionUpdate( fAux_ma[box_no](i, j, k, n) += aux_ma[box_no](i, j, k, n); } }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); //------------------------------------------------------------------------ // Species diffusion solve @@ -1406,8 +1407,9 @@ PeleLM::differentialDiffusionUpdate( } }); } + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); // FillPatch species again before going into the enthalpy solve fillPatchSpecies(AmrNewTime); @@ -1796,8 +1798,9 @@ PeleLM::getScalarDiffForce( f_aux_ma[box_no], a_aux_ma[box_no], dn_aux_ma[box_no], dnp1_aux_ma[box_no], aux_advect_d, aux_diffuse_d, nAux); }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); // Fill forcing ghost cells if (advData->Forcing[0].nGrow() > 0) { diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index 084626da7..e470e8e1c 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -297,8 +297,9 @@ DiffusionOp::diffuse_scalar( phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); } }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } } @@ -508,8 +509,9 @@ DiffusionOp::diffuse_scalar( phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); } }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } } #endif @@ -1199,8 +1201,9 @@ DiffusionTensorOp::compute_divtau( divtau_ma[box_no](i, j, k, n) /= rho_ma[box_no](i, j, k); } }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } } diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index eda2b424c..aada3fd43 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -214,9 +214,10 @@ PeleLM::addSpark(const TimeStamp a_timestamp) extma[box_no](i, j, k, RHOH) = rhoh_src_loc; } }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } } - amrex::Gpu::streamSynchronize(); } // Manifold model - dissipation rate sources for variances diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index aca27273e..f751ed9cb 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -252,6 +252,8 @@ PeleLM::velocityProjection( vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; } }); + // Shift outside? (w/below) + amrex::Gpu::streamSynchronize(); } } else { for (int lev = 0; lev <= finest_level; ++lev) { @@ -269,9 +271,10 @@ PeleLM::velocityProjection( vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; } }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } } - amrex::Gpu::streamSynchronize(); } // If incremental @@ -345,19 +348,15 @@ PeleLM::velocityProjection( amrex::ParallelFor( rhs_cc[lev], rhs_cc[lev].nGrowVect(), - [divu_o_ma, divu_n_ma, - rhs_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [divu_o_ma, divu_n_ma, rhs_ma, SbarNew, SbarOld, + is_closed_chamber = + m_closed_chamber] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { rhs_ma[box_no](i, j, k) = -(divu_n_ma[box_no](i, j, k) - divu_o_ma[box_no](i, j, k)); - }); - if (m_closed_chamber != 0) { - amrex::ParallelFor( - rhs_cc[lev], rhs_cc[lev].nGrowVect(), - [rhs_ma, SbarNew, SbarOld] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { + if (is_closed_chamber != 0) { rhs_ma[box_no](i, j, k) += SbarNew - SbarOld; - }); - } + } + }); amrex::Gpu::streamSynchronize(); } #ifdef AMREX_USE_EB diff --git a/Source/PeleLMeX_Soot.cpp b/Source/PeleLMeX_Soot.cpp index a123f100d..ded250cfd 100644 --- a/Source/PeleLMeX_Soot.cpp +++ b/Source/PeleLMeX_Soot.cpp @@ -71,8 +71,9 @@ PeleLM::clipSootMoments() state_arr(i, j, k, mom) = moments[mom]; } }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } // TODO: This isn't working yet diff --git a/Source/PeleLMeX_UMac.cpp b/Source/PeleLMeX_UMac.cpp index fbe0f53a0..87fda9fa2 100644 --- a/Source/PeleLMeX_UMac.cpp +++ b/Source/PeleLMeX_UMac.cpp @@ -126,6 +126,8 @@ PeleLM::addChiIncrement( } mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } break; } @@ -145,6 +147,8 @@ PeleLM::addChiIncrement( } mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } break; } @@ -164,10 +168,11 @@ PeleLM::addChiIncrement( } mac_divu_ma[box_no](i, j, k) += chi_ma[box_no](i, j, k); }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } } } - amrex::Gpu::streamSynchronize(); if (m_print_chi_convergence) { const amrex::Real max_corr = MLNorm0(GetVecOfConstPtrs(chiIncr)) * m_dt / m_dpdtFactor; diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 4f11523b0..2e57b6efd 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -851,8 +851,9 @@ PeleLM::floorSpecies(const TimeStamp a_time) sma[box_no](i, j, k, RHOH) = h_cgs * 1.0e-4 * sma[box_no](i, j, k, DENSITY); }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } void From fc73a41fe0fe644b372121bec9a2b38660bd3ca7 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 22 Aug 2025 14:35:40 +0200 Subject: [PATCH 64/87] much more const, tweaks --- Source/PeleLMeX.H | 94 +++++++++++----------- Source/PeleLMeX_Advance.cpp | 4 +- Source/PeleLMeX_Advection.cpp | 18 ++--- Source/PeleLMeX_Data.cpp | 2 +- Source/PeleLMeX_Diffusion.cpp | 18 ++--- Source/PeleLMeX_Eos.cpp | 4 +- Source/PeleLMeX_FlowController.cpp | 2 +- Source/PeleLMeX_Plot.cpp | 2 +- Source/PeleLMeX_Reactions.cpp | 4 +- Source/PeleLMeX_Temporals.cpp | 6 +- Source/PeleLMeX_UMac.cpp | 12 +-- Source/PeleLMeX_Utils.cpp | 2 +- Source/Plasma/PeleLMeX_EFIonDrift.cpp | 8 +- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 108 +++++++++++++------------- Source/Plasma/PeleLMeX_EFTimeStep.cpp | 3 +- Source/Plasma/PeleLMeX_EFUtils.cpp | 2 +- 16 files changed, 149 insertions(+), 140 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 212a60a71..4d9a4e424 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -458,14 +458,14 @@ public: * from cell-centered ones * \param advData container for the face-centered velocity umac */ - void predictVelocity(std::unique_ptr& advData); + void predictVelocity(const std::unique_ptr& advData); /** * \brief Create MAC projection RHS by fillpatching divU * between old and new time * \param advData container for mac_divu */ - void createMACRHS(std::unique_ptr& advData); + void createMACRHS(const std::unique_ptr& advData); /** * \brief Create MAC projection RHS by fillpatching divU @@ -477,7 +477,7 @@ public: void addChiIncrement( const int a_sdcIter, const PeleLM::TimeStamp a_time, - std::unique_ptr& advData); + const std::unique_ptr& advData); /** * \brief Perform MAC projection to obtained divergence constrained @@ -488,7 +488,7 @@ public: */ void macProject( const PeleLM::TimeStamp a_time, - std::unique_ptr& advData, + const std::unique_ptr& advData, const amrex::Vector& a_divu); /** @@ -508,8 +508,8 @@ public: const int a_nGrow, const amrex::Geometry* crse_geom, const amrex::Geometry* fine_geom, - amrex::Array u_mac_crse, - amrex::Array u_mac_fine, + const amrex::Array& u_mac_crse, + const amrex::Array& u_mac_fine, const amrex::IntVect& crse_ratio); /** @@ -608,7 +608,7 @@ public: */ void computeDifferentialDiffusionTerms( const PeleLM::TimeStamp a_time, - std::unique_ptr& diffData, + const std::unique_ptr& diffData, const int is_init = 0); /** @@ -676,8 +676,8 @@ public: * \param diffData container for the returning implicit diffusion term */ void differentialDiffusionUpdate( - std::unique_ptr& advData, - std::unique_ptr& diffData); + const std::unique_ptr& advData, + const std::unique_ptr& diffData); /** * \brief Setup the implicit deltaT linear solve @@ -691,8 +691,8 @@ public: const amrex::Vector& a_rhs, const amrex::Vector& a_Tsave, const amrex::Vector& a_rhoCp, - std::unique_ptr& advData, - std::unique_ptr& diffData); + const std::unique_ptr& advData, + const std::unique_ptr& diffData); /** * \brief Restore state, update enthalpy and compute fluxes after deltaT @@ -709,7 +709,7 @@ public: a_fluxes, const amrex::Vector& a_ebfluxes, const amrex::Vector& a_Tsave, - std::unique_ptr& diffData, + const std::unique_ptr& diffData, amrex::Real& a_deltaT_norm); /** @@ -724,7 +724,7 @@ public: const PeleLM::TimeStamp a_time, const amrex::Vector& a_divtau, const int use_density, - amrex::Real scale = 1.0); + const amrex::Real scale = 1.0); /** * \brief Implicit diffusion of the of velocity field using AMReX @@ -760,7 +760,7 @@ public: * the advection/diffusion component of the advance function in the SDC * context */ - void advanceChemistry(std::unique_ptr& advData); + void advanceChemistry(const std::unique_ptr& advData); /** * \brief Performing the chemistry integration on a given level, for a fixed @@ -973,7 +973,7 @@ public: const int computeDiff, const int do_avgDown, const PeleLM::TimeStamp a_time, - std::unique_ptr& diffData); + const std::unique_ptr& diffData); /** * \brief Compute the pressure drift term using RhoRT and @@ -1001,7 +1001,7 @@ public: * thermodynamic pressure. Return the mean divU. * \param advData container including mac_divu */ - amrex::Real adjustPandDivU(std::unique_ptr& advData); + amrex::Real adjustPandDivU(const std::unique_ptr& advData); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -1013,7 +1013,7 @@ public: void ReadCheckPointFile(); bool writeCheckNow() const; void WriteJobInfo(const std::string& path) const; - void WriteHeader(const std::string& name, bool is_checkpoint) const; + void WriteHeader(const std::string& name, const bool is_checkpoint) const; void WriteDebugPlotFile( const amrex::Vector& a_MF, const std::string& pltname); @@ -1032,7 +1032,7 @@ public: void massBalance(); void speciesBalance(); void speciesBalancePatch(); - void initBPatches(amrex::Geometry& a_geom); + void initBPatches(const amrex::Geometry& a_geom); void rhoHBalance(); void initTemporals(const PeleLM::TimeStamp a_time = AmrOldTime); @@ -1052,7 +1052,8 @@ public: const amrex::Geometry& a_geom, const amrex::Real& a_factor = 1.0); void addUmacFluxes( - std::unique_ptr& advData, const amrex::Geometry& a_geom); + const std::unique_ptr& advData, + const amrex::Geometry& a_geom); void openTempFile(); void closeTempFile(); bool doTemporalsNow() const; @@ -1060,7 +1061,7 @@ public: //----------------------------------------------------------------------------- // BOUNDARY CONDITIONS / FILLPATCH - amrex::InterpBase* getInterpolator(int a_method = 1) const; + amrex::InterpBase* getInterpolator(const int a_method = 1) const; // Interpolation method for regrid (default to cell cons interp) int m_regrid_interp_method = 1; @@ -1405,7 +1406,7 @@ public: // Active control void initActiveControl(); - void activeControl(int is_restart); + void activeControl(const int is_restart); void loadActiveControlHistory(); void getActiveControlLowT(amrex::Real& a_coft); @@ -1503,8 +1504,8 @@ public: void getEBDistance(const int a_lev, amrex::MultiFab& a_signDistLev); - void - extendSignedDistance(amrex::MultiFab* a_signDist, amrex::Real a_extendFactor); + void extendSignedDistance( + amrex::MultiFab* a_signDist, const amrex::Real a_extendFactor); void getEBState( const int a_lev, @@ -1556,38 +1557,38 @@ public: void oneSDC( const int sdcIter, - std::unique_ptr& advData, - std::unique_ptr& diffData); + const std::unique_ptr& advData, + const std::unique_ptr& diffData); bool checkForNaNs(); void copyTransportOldToNew(); void copyStateNewToOld(const int nGhost = 0); void copyPressNewToOld(); void copyStateOldToNew(const int nGhost = 0); - void copyDiffusionOldToNew(std::unique_ptr& diffData); + void copyDiffusionOldToNew(const std::unique_ptr& diffData); - void computeVelocityAdvTerm(std::unique_ptr& advData); - void updateVelocity(std::unique_ptr& advData); + void computeVelocityAdvTerm(const std::unique_ptr& advData); + void updateVelocity(const std::unique_ptr& advData); void getScalarAdvForce( - std::unique_ptr& advData, - std::unique_ptr& diffData); - void computeScalarAdvTerms(std::unique_ptr& advData); + const std::unique_ptr& advData, + const std::unique_ptr& diffData); + void computeScalarAdvTerms(const std::unique_ptr& advData); void computePassiveAdvTerms( - std::unique_ptr& advData, + const std::unique_ptr& advData, const int state_comp, const int ncomp); - void updateDensity(std::unique_ptr& advData); + void updateDensity(const std::unique_ptr& advData); void updateScalarComp( - std::unique_ptr& advData, + const std::unique_ptr& advData, const int state_comp, const int ncomp); void getScalarDiffForce( - std::unique_ptr& advData, - std::unique_ptr& diffData); + const std::unique_ptr& advData, + const std::unique_ptr& diffData); - void getScalarReactForce(std::unique_ptr& advData); + void getScalarReactForce(const std::unique_ptr& advData); //----------------------------------------------------------------------------- #ifdef PELE_USE_PLASMA @@ -1605,12 +1606,12 @@ public: void implicitNonLinearSolve( const int sdcIter, const amrex::Real a_dt, - std::unique_ptr& diffData, - std::unique_ptr& advData); + const std::unique_ptr& diffData, + const std::unique_ptr& advData); void computeBGcharge( const amrex::Real a_time, - std::unique_ptr& diffData, - std::unique_ptr& advData); + const std::unique_ptr& diffData, + const std::unique_ptr& advData); void nonLinearResidual( const amrex::Real a_dt, @@ -1639,8 +1640,9 @@ public: const amrex::Array& a_ueff, amrex::BCRec bcrec); - void ionDriftVelocity(std::unique_ptr& advData); - void ionDriftAddUmac(const int lev, std::unique_ptr& advData); + void ionDriftVelocity(const std::unique_ptr& advData); + void ionDriftAddUmac( + const int lev, const std::unique_ptr& advData); void computeInstantaneousReactionRateEF( const int lev, const PeleLM::TimeStamp a_time, amrex::MultiFab* a_I_R); @@ -1670,7 +1672,7 @@ public: void updateNLState(const amrex::Vector& a_update); void incrementElectronForcing( - const int a_sstep, std::unique_ptr& advData); + const int a_sstep, const std::unique_ptr& advData); void getNLStateScaling(amrex::Real& nEScale, amrex::Real& phiVScale); void getNLResidScaling(amrex::Real& nEScale, amrex::Real& phiVScale); @@ -1685,7 +1687,7 @@ public: const int lev, const int edge_comp, const int ncomp, - amrex::Vector a_bcrec, + const amrex::Vector& a_bcrec, const amrex::MultiFab& ccMF, const amrex::Array& ecVel); @@ -1734,7 +1736,7 @@ public: const int lev, const PeleLM::TimeStamp a_time, const int useUmac = 0); LevelDataReact* getLevelDataReactPtr(const int lev); - amrex::Real getTime(int lev, const PeleLM::TimeStamp a_time) const + amrex::Real getTime(const int lev, const PeleLM::TimeStamp a_time) const { AMREX_ASSERT( a_time == AmrOldTime || a_time == AmrNewTime || a_time == AmrHalfTime); diff --git a/Source/PeleLMeX_Advance.cpp b/Source/PeleLMeX_Advance.cpp index c3355733d..bb3e3c158 100644 --- a/Source/PeleLMeX_Advance.cpp +++ b/Source/PeleLMeX_Advance.cpp @@ -268,8 +268,8 @@ PeleLM::Advance(const int is_initIter) void PeleLM::oneSDC( const int sdcIter, - std::unique_ptr& advData, - std::unique_ptr& diffData) + const std::unique_ptr& advData, + const std::unique_ptr& diffData) { BL_PROFILE("PeleLMeX::oneSDC()"); m_sdcIter = sdcIter; diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index fbf443995..24cc4ccdb 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -4,7 +4,7 @@ #include void -PeleLM::computeVelocityAdvTerm(std::unique_ptr& advData) +PeleLM::computeVelocityAdvTerm(const std::unique_ptr& advData) { //---------------------------------------------------------------- // Create temporary containers @@ -204,7 +204,7 @@ PeleLM::computeVelocityAdvTerm(std::unique_ptr& advData) } void -PeleLM::updateVelocity(std::unique_ptr& advData) +PeleLM::updateVelocity(const std::unique_ptr& advData) { //---------------------------------------------------------------- // Compute t^n divTau @@ -265,11 +265,11 @@ PeleLM::updateVelocity(std::unique_ptr& advData) void PeleLM::getScalarAdvForce( - std::unique_ptr& advData, - std::unique_ptr& diffData) + const std::unique_ptr& advData, + const std::unique_ptr& diffData) { - int* aux_diffuse_d = convertToDeviceVector(m_DiffTypeAux).dataPtr(); + const int* aux_diffuse_d = convertToDeviceVector(m_DiffTypeAux).dataPtr(); auto const* leosparm = eos_parms.device_parm(); for (int lev = 0; lev <= finest_level; ++lev) { @@ -332,7 +332,7 @@ PeleLM::getScalarAdvForce( } void -PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) +PeleLM::computeScalarAdvTerms(const std::unique_ptr& advData) { //---------------------------------------------------------------- @@ -934,7 +934,7 @@ PeleLM::computeScalarAdvTerms(std::unique_ptr& advData) } void -PeleLM::updateDensity(std::unique_ptr& advData) +PeleLM::updateDensity(const std::unique_ptr& advData) { for (int lev = 0; lev <= finest_level; ++lev) { // Get MultiArrays @@ -958,7 +958,7 @@ PeleLM::updateDensity(std::unique_ptr& advData) void PeleLM::computePassiveAdvTerms( - std::unique_ptr& advData, + const std::unique_ptr& advData, const int state_comp, const int ncomp) { @@ -1119,7 +1119,7 @@ PeleLM::computePassiveAdvTerms( void PeleLM::updateScalarComp( - std::unique_ptr& advData, + const std::unique_ptr& advData, const int state_comp, const int ncomp) { diff --git a/Source/PeleLMeX_Data.cpp b/Source/PeleLMeX_Data.cpp index a18063fa6..8260d7e79 100644 --- a/Source/PeleLMeX_Data.cpp +++ b/Source/PeleLMeX_Data.cpp @@ -345,7 +345,7 @@ PeleLM::copyTransportOldToNew() } void -PeleLM::copyDiffusionOldToNew(std::unique_ptr& diffData) +PeleLM::copyDiffusionOldToNew(const std::unique_ptr& diffData) { for (int lev = 0; lev <= finest_level; ++lev) { amrex::MultiFab::Copy( diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index dec34a533..dc96fe1e2 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -40,7 +40,7 @@ PeleLM::getDiffusionTensorOp() void PeleLM::computeDifferentialDiffusionTerms( const TimeStamp a_time, - std::unique_ptr& diffData, + const std::unique_ptr& diffData, const int is_init) { BL_PROFILE("PeleLMeX::computeDifferentialDiffusionTerms()"); @@ -1076,8 +1076,8 @@ PeleLM::computeSpeciesEnthalpyFlux( void PeleLM::differentialDiffusionUpdate( - std::unique_ptr& advData, - std::unique_ptr& diffData) + const std::unique_ptr& advData, + const std::unique_ptr& diffData) { BL_PROFILE("PeleLMeX::differentialDiffusionUpdate()"); @@ -1585,8 +1585,8 @@ PeleLM::deltaTIter_prepare( const amrex::Vector& a_rhs, const amrex::Vector& a_Tsave, const amrex::Vector& a_rhoCp, - std::unique_ptr& advData, - std::unique_ptr& diffData) + const std::unique_ptr& advData, + const std::unique_ptr& diffData) { auto const* leosparm = eos_parms.device_parm(); const amrex::Real dtinv = 1.0 / m_dt; @@ -1638,11 +1638,11 @@ PeleLM::deltaTIter_prepare( void PeleLM::deltaTIter_update( - int a_dtiter, + const int a_dtiter, const amrex::Vector>& a_fluxes, const amrex::Vector& a_ebfluxes, const amrex::Vector& a_Tsave, - std::unique_ptr& diffData, + const std::unique_ptr& diffData, amrex::Real& a_deltaT_norm) { #ifndef AMREX_USE_EB @@ -1745,8 +1745,8 @@ PeleLM::deltaTIter_update( void PeleLM::getScalarDiffForce( - std::unique_ptr& advData, - std::unique_ptr& diffData) + const std::unique_ptr& advData, + const std::unique_ptr& diffData) { const int* aux_advect_d = convertToDeviceVector(m_aux_advect).dataPtr(); diff --git a/Source/PeleLMeX_Eos.cpp b/Source/PeleLMeX_Eos.cpp index cb84c110c..525c8831f 100644 --- a/Source/PeleLMeX_Eos.cpp +++ b/Source/PeleLMeX_Eos.cpp @@ -42,7 +42,7 @@ PeleLM::calcDivU( const int computeDiff, const int do_avgDown, const TimeStamp a_time, - std::unique_ptr& diffData) + const std::unique_ptr& diffData) { BL_PROFILE("PeleLMeX::calcDivU()"); @@ -280,7 +280,7 @@ PeleLM::calc_dPdt( } amrex::Real -PeleLM::adjustPandDivU(std::unique_ptr& advData) +PeleLM::adjustPandDivU(const std::unique_ptr& advData) { BL_PROFILE("PeleLMeX::adjustPandDivU()"); diff --git a/Source/PeleLMeX_FlowController.cpp b/Source/PeleLMeX_FlowController.cpp index e93ebc055..6488f2391 100644 --- a/Source/PeleLMeX_FlowController.cpp +++ b/Source/PeleLMeX_FlowController.cpp @@ -140,7 +140,7 @@ PeleLM::initActiveControl() } void -PeleLM::activeControl(int is_restart) +PeleLM::activeControl(const int is_restart) { if (m_ctrl_active == 0) { return; diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index a0d4d2ab6..95b209347 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -519,7 +519,7 @@ PeleLM::WritePlotFile() } void -PeleLM::WriteHeader(const std::string& name, bool is_checkpoint) const +PeleLM::WriteHeader(const std::string& name, const bool is_checkpoint) const { if (amrex::ParallelDescriptor::IOProcessor()) { std::string HeaderFileName(name + "/Header"); diff --git a/Source/PeleLMeX_Reactions.cpp b/Source/PeleLMeX_Reactions.cpp index f1df5fa50..e6949cb05 100644 --- a/Source/PeleLMeX_Reactions.cpp +++ b/Source/PeleLMeX_Reactions.cpp @@ -5,7 +5,7 @@ #endif void -PeleLM::advanceChemistry(std::unique_ptr& advData) +PeleLM::advanceChemistry(const std::unique_ptr& advData) { BL_PROFILE("PeleLMeX::advanceChemistry()"); @@ -440,7 +440,7 @@ PeleLM::computeInstantaneousReactionRate( } void -PeleLM::getScalarReactForce(std::unique_ptr& advData) +PeleLM::getScalarReactForce(const std::unique_ptr& advData) { // The differentialDiffusionUpdate just provided the {np1,kp1} AD state // -> use it to build the external forcing for the chemistry diff --git a/Source/PeleLMeX_Temporals.cpp b/Source/PeleLMeX_Temporals.cpp index 81e57814f..fc6ab93a6 100644 --- a/Source/PeleLMeX_Temporals.cpp +++ b/Source/PeleLMeX_Temporals.cpp @@ -212,7 +212,7 @@ PeleLM::addMassFluxes( void PeleLM::addUmacFluxes( - std::unique_ptr& advData, const amrex::Geometry& a_geom) + const std::unique_ptr& advData, const amrex::Geometry& a_geom) { // Get the face areas const amrex::Real* dx = a_geom.CellSize(); @@ -229,7 +229,7 @@ PeleLM::addUmacFluxes( #endif // Just use level 0 since we are calling after averaging down - int lev = 0; + constexpr int lev = 0; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { auto faceDomain = @@ -531,7 +531,7 @@ PeleLM::addRhoYFluxes( } void -PeleLM::initBPatches(amrex::Geometry& a_geom) +PeleLM::initBPatches(const amrex::Geometry& a_geom) { std::string pele_prefix = "peleLM.bpatch"; amrex::ParmParse pp(pele_prefix); diff --git a/Source/PeleLMeX_UMac.cpp b/Source/PeleLMeX_UMac.cpp index 87fda9fa2..a1339bb31 100644 --- a/Source/PeleLMeX_UMac.cpp +++ b/Source/PeleLMeX_UMac.cpp @@ -5,7 +5,7 @@ #include void -PeleLM::predictVelocity(std::unique_ptr& advData) +PeleLM::predictVelocity(const std::unique_ptr& advData) { BL_PROFILE("PeleLMeX::predictVelocity()"); @@ -73,7 +73,7 @@ PeleLM::predictVelocity(std::unique_ptr& advData) } void -PeleLM::createMACRHS(std::unique_ptr& advData) +PeleLM::createMACRHS(const std::unique_ptr& advData) { BL_PROFILE("PeleLMeX::createMACRHS()"); @@ -87,7 +87,7 @@ void PeleLM::addChiIncrement( const int a_sdcIter, const TimeStamp a_time, - std::unique_ptr& advData) + const std::unique_ptr& advData) { BL_PROFILE("PeleLMeX::addChiIncrement()"); @@ -184,7 +184,7 @@ PeleLM::addChiIncrement( void PeleLM::macProject( const TimeStamp a_time, - std::unique_ptr& advData, + const std::unique_ptr& advData, const amrex::Vector& a_divu) { BL_PROFILE("PeleLMeX::macProject()"); @@ -284,8 +284,8 @@ PeleLM::create_constrained_umac_grown( const int a_nGrow, const amrex::Geometry* crse_geom, const amrex::Geometry* fine_geom, - amrex::Array u_mac_crse, - amrex::Array u_mac_fine, + const amrex::Array& u_mac_crse, + const amrex::Array& u_mac_fine, const amrex::IntVect& crse_ratio) { // Divergence preserving interp diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index 2e57b6efd..b8717cdd8 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -2186,7 +2186,7 @@ PeleLM::parseComposition( // Extend the cell-centered based signed distance function void PeleLM::extendSignedDistance( - amrex::MultiFab* a_signDist, amrex::Real a_extendFactor) + amrex::MultiFab* a_signDist, const amrex::Real a_extendFactor) { BL_PROFILE("PeleLMeX::extendSignedDistance()"); // This is a not-so-pretty piece of code that'll take AMReX cell-averaged diff --git a/Source/Plasma/PeleLMeX_EFIonDrift.cpp b/Source/Plasma/PeleLMeX_EFIonDrift.cpp index c8cadcd57..ca26ebc10 100644 --- a/Source/Plasma/PeleLMeX_EFIonDrift.cpp +++ b/Source/Plasma/PeleLMeX_EFIonDrift.cpp @@ -5,7 +5,7 @@ #include void -PeleLM::ionDriftVelocity(std::unique_ptr& advData) +PeleLM::ionDriftVelocity(const std::unique_ptr& advData) { //---------------------------------------------------------------- // set udrift boundaries to zero @@ -93,8 +93,9 @@ PeleLM::ionDriftVelocity(std::unique_ptr& advData) (gp_o_ma[box_no](i, j, k) + gp_n_ma[box_no](i, j, k)); } }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } //---------------------------------------------------------------- @@ -165,7 +166,8 @@ PeleLM::ionDriftVelocity(std::unique_ptr& advData) } void -PeleLM::ionDriftAddUmac(int lev, std::unique_ptr& advData) +PeleLM::ionDriftAddUmac( + const int lev, const std::unique_ptr& advData) { // Add umac to the ions drift velocity to get the effective velocity for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index 7676b8f23..dad8c0c37 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -18,8 +18,8 @@ void PeleLM::implicitNonLinearSolve( const int sdcIter, const amrex::Real a_dt, - std::unique_ptr& diffData, - std::unique_ptr& advData) + const std::unique_ptr& diffData, + const std::unique_ptr& advData) { BL_PROFILE_VAR("PeleLMeX::implicitNonLinearSolve()", implicitNonLinearSolve); @@ -316,7 +316,7 @@ PeleLM::updateNLState(const amrex::Vector& a_update) void PeleLM::incrementElectronForcing( - const int a_sstep, std::unique_ptr& advData) + const int a_sstep, const std::unique_ptr& advData) { for (int lev = 0; lev <= finest_level; ++lev) { @@ -342,6 +342,8 @@ PeleLM::incrementElectronForcing( (nE_n_ma[box_no](i, j, k) * scaling - nE_o(i, j, k)) * dtinv - I_R_nE(i, j, k); }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } else { amrex::ParallelFor( ldata_p->state, @@ -354,16 +356,17 @@ PeleLM::incrementElectronForcing( (nE_n_ma[box_no](i, j, k) * scaling - nE_o(i, j, k)) * dtinv - I_R_nE(i, j, k); }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } } - amrex::Gpu::streamSynchronize(); } void PeleLM::computeBGcharge( const amrex::Real a_time, - std::unique_ptr& diffData, - std::unique_ptr& advData) + const std::unique_ptr& diffData, + const std::unique_ptr& advData) { // Get integration dt const amrex::Real dt_int = a_time - getTime(0, AmrOldTime); @@ -403,8 +406,9 @@ PeleLM::computeBGcharge( } charge_ma[box_no](i, j, k) *= factor; }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } void @@ -522,8 +526,9 @@ PeleLM::nonLinearResidual( res_nE(i, j, k) *= -1.0; // NLresidual is -RHS res_phiV(i, j, k) *= -1.0; // NLresidual is -RHS }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); // WriteDebugPlotFile(GetVecOfConstPtrs(a_nlresid),"UnscalednlResid"); // /* @@ -611,9 +616,10 @@ PeleLM::getAdvectionTerm( kappa_e_ma[box_no](i, j, k) * -1.0 * 0.5 * (gphi_c_ma[box_no](i, j, k) + gphi_o_ma[box_no](i, j, k)); }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } } - amrex::Gpu::streamSynchronize(); // Average down the Ueff /* @@ -658,7 +664,7 @@ PeleLM::getAdvectionTerm( } // Compute divergence - int intensiveFluxes = 1; + constexpr int intensiveFluxes = 1; fluxDivergence( a_advTerm, 0, GetVecOfArrOfPtrs(fluxes), 0, 1, intensiveFluxes, -1.0); } @@ -713,9 +719,9 @@ PeleLM::getAdvectionFluxesMOL( auto const& divu_arr = a_nE.const_array(mfi); auto const& force_arr = a_nE.const_array(mfi); - bool is_velocity = false; - bool fluxes_are_area_weighted = false; - bool knownEdgeState = false; + constexpr bool is_velocity = false; + constexpr bool fluxes_are_area_weighted = false; + constexpr bool knownEdgeState = false; std::string mol = "MOL"; HydroUtils::ComputeFluxesOnBoxFromState( bx, 1, mfi, nE_arr, AMREX_D_DECL(fx, fy, fz), @@ -740,7 +746,7 @@ PeleLM::getAdvectionFluxes( { const amrex::Box& domain = geom[lev].Domain(); - int order = m_nEAdvOrder; + const int order = m_nEAdvOrder; #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) @@ -788,21 +794,21 @@ PeleLM::getAdvectionFluxes( amrex::ParallelFor( xbx, [bc_lo, bc_hi, edomain, ne_arr, xstate, u, order, domain, xbx] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - bool on_lo = + const int idx[3] = {i, j, k}; + const bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && (idx[0] <= edomain.smallEnd(0))); - bool on_hi = + const bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && (idx[0] >= edomain.bigEnd(0))); if (order == 1) { xstate(i, j, k) = ef_edge_state_extdir(i, j, k, 0, on_lo, on_hi, ne_arr, u); } else if (order == 2) { - bool extdir_or_ho_lo = (bc_lo == amrex::BCType::ext_dir) || - (bc_lo == amrex::BCType::hoextrap); - bool extdir_or_ho_hi = (bc_hi == amrex::BCType::ext_dir) || - (bc_hi == amrex::BCType::hoextrap); + const bool extdir_or_ho_lo = (bc_lo == amrex::BCType::ext_dir) || + (bc_lo == amrex::BCType::hoextrap); + const bool extdir_or_ho_hi = (bc_hi == amrex::BCType::ext_dir) || + (bc_hi == amrex::BCType::hoextrap); xstate(i, j, k) = ef_edge_state_2ndO_extdir( i, j, k, 0, on_lo, on_hi, extdir_or_ho_lo, extdir_or_ho_hi, domain.smallEnd(0), domain.bigEnd(0), ne_arr, u, xbx); @@ -820,21 +826,21 @@ PeleLM::getAdvectionFluxes( amrex::ParallelFor( ybx, [bc_lo, bc_hi, edomain, domain, order, ystate, ne_arr, v, ybx] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - bool on_lo = + const int idx[3] = {i, j, k}; + const bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && (idx[1] <= edomain.smallEnd(1))); - bool on_hi = + const bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && (idx[1] >= edomain.bigEnd(1))); if (order == 1) { ystate(i, j, k) = ef_edge_state_extdir(i, j, k, 1, on_lo, on_hi, ne_arr, v); } else if (order == 2) { - bool extdir_or_ho_lo = (bc_lo == amrex::BCType::ext_dir) || - (bc_lo == amrex::BCType::hoextrap); - bool extdir_or_ho_hi = (bc_hi == amrex::BCType::ext_dir) || - (bc_hi == amrex::BCType::hoextrap); + const bool extdir_or_ho_lo = (bc_lo == amrex::BCType::ext_dir) || + (bc_lo == amrex::BCType::hoextrap); + const bool extdir_or_ho_hi = (bc_hi == amrex::BCType::ext_dir) || + (bc_hi == amrex::BCType::hoextrap); ystate(i, j, k) = ef_edge_state_2ndO_extdir( i, j, k, 1, on_lo, on_hi, extdir_or_ho_lo, extdir_or_ho_hi, domain.smallEnd(1), domain.bigEnd(1), ne_arr, v, ybx); @@ -852,21 +858,21 @@ PeleLM::getAdvectionFluxes( amrex::ParallelFor( zbx, [bc_lo, bc_hi, edomain, zstate, order, ne_arr, w, zbx, domain] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - bool on_lo = + const int idx[3] = {i, j, k}; + const bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && (idx[2] <= edomain.smallEnd(2))); - bool on_hi = + const bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && (idx[2] >= edomain.bigEnd(2))); if (order == 1) { zstate(i, j, k) = ef_edge_state_extdir(i, j, k, 2, on_lo, on_hi, ne_arr, w); } else if (order == 2) { - bool extdir_or_ho_lo = (bc_lo == amrex::BCType::ext_dir) || - (bc_lo == amrex::BCType::hoextrap); - bool extdir_or_ho_hi = (bc_hi == amrex::BCType::ext_dir) || - (bc_hi == amrex::BCType::hoextrap); + const bool extdir_or_ho_lo = (bc_lo == amrex::BCType::ext_dir) || + (bc_lo == amrex::BCType::hoextrap); + const bool extdir_or_ho_hi = (bc_hi == amrex::BCType::ext_dir) || + (bc_hi == amrex::BCType::hoextrap); zstate(i, j, k) = ef_edge_state_2ndO_extdir( i, j, k, 2, on_lo, on_hi, extdir_or_ho_lo, extdir_or_ho_hi, domain.smallEnd(2), domain.bigEnd(2), ne_arr, w, zbx); @@ -928,7 +934,7 @@ PeleLM::setUpPrecond( // Get nl solve data pointer auto ldataNLs_p = getLevelDataNLSolvePtr(lev); - int doZeroVisc = 0; + constexpr int doZeroVisc = 0; amrex::Array diffE_ec = getDiffusivity(lev, 0, 1, doZeroVisc, bcRecnE, ldata_p->diffE_cc); @@ -991,21 +997,15 @@ PeleLM::setUpPrecond( amrex::ParallelFor( nEKe, nEKe.nGrowVect(), - [neke_ma, kappaE_ma, - ne_arr_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [neke_ma, kappaE_ma, ne_arr_ma, Schur_ma, diffOp_diag_ma, a_dt, + do_Schur] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { neke_ma[box_no](i, j, k) = kappaE_ma[box_no](i, j, k) * ne_arr_ma[box_no](i, j, k); - }); - amrex::Gpu::streamSynchronize(); - if (do_Schur == 1) { - amrex::ParallelFor( - nEKe, nEKe.nGrowVect(), - [neke_ma, Schur_ma, diffOp_diag_ma, - a_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + if (do_Schur == 1) { Schur_ma[box_no](i, j, k) = -a_dt * 0.5 * neke_ma[box_no](i, j, k) / diffOp_diag_ma[box_no](i, j, k); - }); - } + } + }); amrex::Gpu::streamSynchronize(); // Upwinded edge neKe values @@ -1046,7 +1046,7 @@ PeleLM::getUpwindedEdge( const int lev, const int edge_comp, const int ncomp, - amrex::Vector bcrec, + const amrex::Vector& bcrec, const amrex::MultiFab& ccMF, const amrex::Array& ecVel) { @@ -1085,11 +1085,11 @@ PeleLM::getUpwindedEdge( amrex::ParallelFor( ebx, [bc_lo, bc_hi, idim, edomain, ecUeff, ccVal, ecVal] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - bool on_lo = + const int idx[3] = {i, j, k}; + const bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && (idx[idim] <= edomain.smallEnd(idim))); - bool on_hi = + const bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && (idx[idim] >= edomain.bigEnd(idim))); cen2edg_upwind(i, j, k, idim, 1, on_lo, on_hi, ecUeff, ccVal, ecVal); @@ -1207,9 +1207,13 @@ PeleLM::applyPrecond( // Setup aliases and temps amrex::Vector nE_al; + nE_al.reserve(finest_level + 1); amrex::Vector phiV_al; + phiV_al.reserve(finest_level + 1); amrex::Vector PnE_al; + PnE_al.reserve(finest_level + 1); amrex::Vector PphiV_al; + PphiV_al.reserve(finest_level + 1); amrex::Vector> temp(finest_level + 1); amrex::Vector> temp2(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { @@ -1280,7 +1284,7 @@ void PeleLM::nlSolveNorm(const amrex::Vector& a_MF, amrex::Real& r) { r = 0.0; - int nComp = a_MF[0]->nComp(); + const int nComp = a_MF[0]->nComp(); for (int comp = 0; comp < nComp; ++comp) { amrex::Real norm = 0.0; for (int lev = 0; lev < a_MF.size(); ++lev) { diff --git a/Source/Plasma/PeleLMeX_EFTimeStep.cpp b/Source/Plasma/PeleLMeX_EFTimeStep.cpp index 5161bfdfe..2cbf826bd 100644 --- a/Source/Plasma/PeleLMeX_EFTimeStep.cpp +++ b/Source/Plasma/PeleLMeX_EFTimeStep.cpp @@ -60,8 +60,9 @@ PeleLM::estEFIonsDt(const TimeStamp a_time) phiV(idxm[0], idxm[1], idxm[2])); } }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); auto const& efield_const_ma = efield_cc.const_arrays(); auto const& mob_cc_ma = ldata_p->mob_cc.const_arrays(); diff --git a/Source/Plasma/PeleLMeX_EFUtils.cpp b/Source/Plasma/PeleLMeX_EFUtils.cpp index c3bb84ffa..12a5b25cd 100644 --- a/Source/Plasma/PeleLMeX_EFUtils.cpp +++ b/Source/Plasma/PeleLMeX_EFUtils.cpp @@ -237,8 +237,8 @@ PeleLM::initializeElectronNeutral() nEdot(i, j, k) = YnEdot(i, j, k) * Na * invmwt[E_ID] * 1.0e3; YnEdot(i, j, k) = 0.0; }); + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } void From 84a21e8bfff65a17410aaff78ff360c76d1c590a Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 22 Aug 2025 16:04:37 +0200 Subject: [PATCH 65/87] compile const, endl clang-tidy --- .clang-tidy | 1 + Source/PeleLMeX_Init.cpp | 5 +++-- Source/PeleLMeX_Tagging.cpp | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index d357cce9c..0f6f498da 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -8,6 +8,7 @@ Checks: 'bugprone-*, clang-analyzer-*, corecppguidelines-*, cppcoreguidelines-avoid-capture-default, + performance-avoid-endl, modernize-*, -modernize-avoid-c-arrays, -modernize-use-trailing-return-type, diff --git a/Source/PeleLMeX_Init.cpp b/Source/PeleLMeX_Init.cpp index 55ca06962..acfd3380d 100644 --- a/Source/PeleLMeX_Init.cpp +++ b/Source/PeleLMeX_Init.cpp @@ -140,8 +140,9 @@ PeleLM::MakeNewLevelFromScratch( static_cast(refRatio(ilev - 1)[0]), static_cast(ilev)); } - extentFactor *= - std::sqrt(2.0) * m_derefineEBBuffer; // Account for diagonals + // Account for diagonals + constexpr amrex::Real sqrt2 = 1.4142135623730951; + extentFactor *= sqrt2 * m_derefineEBBuffer; amrex::MultiFab signDist( convert(grids[0], amrex::IntVect::TheUnitVector()), dmap[0], 1, 1, diff --git a/Source/PeleLMeX_Tagging.cpp b/Source/PeleLMeX_Tagging.cpp index de0a187a3..46861a921 100644 --- a/Source/PeleLMeX_Tagging.cpp +++ b/Source/PeleLMeX_Tagging.cpp @@ -56,7 +56,8 @@ PeleLM::ErrorEst( getEBDistance(lev, signDist); // Estimate how far I need to derefine - amrex::Real diagFac = std::sqrt(2.0) * m_derefineEBBuffer; + constexpr amrex::Real sqrt2 = 1.4142135623730951; + const amrex::Real diagFac = sqrt2 * m_derefineEBBuffer; amrex::Real clearTagDist = Geom(m_EB_refine_LevMax).CellSize(0) * static_cast(nErrorBuf(m_EB_refine_LevMax)) * diagFac; From 72830dc1d11ac265c779826c01c5f3b7fd6e8f99 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 22 Aug 2025 17:13:23 +0200 Subject: [PATCH 66/87] remove endl checks --- .clang-tidy | 1 - Source/PeleLMeX_Plot.cpp | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 0f6f498da..d357cce9c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -8,7 +8,6 @@ Checks: 'bugprone-*, clang-analyzer-*, corecppguidelines-*, cppcoreguidelines-avoid-capture-default, - performance-avoid-endl, modernize-*, -modernize-avoid-c-arrays, -modernize-use-trailing-return-type, diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 95b209347..893086b45 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -989,8 +989,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) foundSpec = 1; if (m_verbose > 0) { amrex::Print() << "Loading species " << specName - << " from plotfile species " << specString - << std::endl; + << " from plotfile species " << specString << "\n"; } } } @@ -1000,8 +999,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) foundSpec = 1; if (m_verbose > 0) { amrex::Print() << "Loading species " << specName - << " from plotfile entry " << specString - << std::endl; + << " from plotfile entry " << specString << "\n"; } pltData.fillPatchFromPlt( a_lev, geom[a_lev], iplt, FIRSTSPEC + i, 1, ldata_p->state); @@ -1012,7 +1010,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) ldata_p->state.setVal(0.0, FIRSTSPEC + i, 1); if (m_verbose > 0) { amrex::Print() << "For species " << specName << " entry " << specString - << " not found in plot file, setting to 0 " << std::endl; + << " not found in plot file, setting to 0\n"; } } } From d5c030796f6876bd4f9edce571c0f4e922cf9ab8 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sat, 23 Aug 2025 18:26:06 +0200 Subject: [PATCH 67/87] streamsync moves, n loops, no ba --- Source/PeleLMeX_Advection.cpp | 39 ++-- Source/PeleLMeX_Diffusion.cpp | 152 ++++++------ Source/PeleLMeX_DiffusionOp.cpp | 99 ++++---- Source/PeleLMeX_Forces.cpp | 308 ++++++++++++------------- Source/PeleLMeX_ODEQty.cpp | 2 +- Source/PeleLMeX_Plot.cpp | 19 +- Source/PeleLMeX_Projection.cpp | 44 ++-- Source/Plasma/PeleLMeX_EFTransport.cpp | 2 +- 8 files changed, 298 insertions(+), 367 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index 24cc4ccdb..ea221f1db 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -247,16 +247,14 @@ PeleLM::updateVelocity(const std::unique_ptr& advData) auto const& force_ma = velForces[lev].const_arrays(); auto const& state_new_ma = ldataNew_p->state.arrays(); amrex::ParallelFor( - ldataOld_p->state, + ldataOld_p->state, amrex::IntVect(0), AMREX_SPACEDIM, [state_old_ma, adv_aofs_ma, force_ma, state_new_ma, dt_loc = - m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - state_new_ma[box_no](i, j, k, VELX + n) = - state_old_ma[box_no](i, j, k, VELX + n) + - dt_loc * (adv_aofs_ma[box_no](i, j, k, VELX + n) + - force_ma[box_no](i, j, k, n)); - } + m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { + state_new_ma[box_no](i, j, k, VELX + n) = + state_old_ma[box_no](i, j, k, VELX + n) + + dt_loc * (adv_aofs_ma[box_no](i, j, k, VELX + n) + + force_ma[box_no](i, j, k, n)); }); // Shift outside? amrex::Gpu::streamSynchronize(); @@ -1134,17 +1132,22 @@ PeleLM::updateScalarComp( auto const& state_new_ma = ldataNew_p->state.arrays(); amrex::ParallelFor( - ldataOld_p->state, - [state_old_ma, adv_aofs_ma, ext_ma, state_new_ma, state_comp, ncomp, - dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = state_comp; n < state_comp + ncomp; ++n) { - state_new_ma[box_no](i, j, k, n) = - state_old_ma[box_no](i, j, k, n) + - dt * (adv_aofs_ma[box_no](i, j, k, n) + ext_ma[box_no](i, j, k, n)); - } + ldataOld_p->state, amrex::IntVect(0), ncomp, + [state_old_ma, adv_aofs_ma, ext_ma, state_new_ma, state_comp, // ncomp, + dt = + m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { + amrex::Array4 state_new_arr( + state_new_ma[box_no], state_comp); + amrex::Array4 state_old_arr( + state_old_ma[box_no], state_comp); + amrex::Array4 adv_aofs_arr( + adv_aofs_ma[box_no], state_comp); + amrex::Array4 ext_arr(ext_ma[box_no], state_comp); + state_new_arr(i, j, k, n) = + state_old_arr(i, j, k, n) + + dt * (adv_aofs_arr(i, j, k, n) + ext_arr(i, j, k, n)); }); - // Shift outside? - amrex::Gpu::streamSynchronize(); } + amrex::Gpu::streamSynchronize(); averageDown(AmrNewTime, state_comp, ncomp); } diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index dc96fe1e2..799e12b3d 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -955,21 +955,22 @@ PeleLM::addSoretTerm( // Soret flux is : - rho * D_m * chi_m * \nabla T / T // with beta_m = rho * D_m * chi_m below amrex::ParallelFor( - ebx, - [need_soret_fluxes, gradT_ar, beta_ar, T, spFlux_ar, - spsoretFlux_ar] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; ++n) { - spFlux_ar(i, j, k, n) -= - beta_ar(i, j, k, n) * gradT_ar(i, j, k) / T(i, j, k); - } - - if (need_soret_fluxes != 0) { - for (int n = 0; n < NUM_SPECIES; ++n) { - spsoretFlux_ar(i, j, k, n) = - -beta_ar(i, j, k, n) * gradT_ar(i, j, k) / T(i, j, k); - } - } + ebx, NUM_SPECIES, + [gradT_ar, beta_ar, T, + spFlux_ar] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + spFlux_ar(i, j, k, n) -= + beta_ar(i, j, k, n) * gradT_ar(i, j, k) / T(i, j, k); }); + + if (need_soret_fluxes != 0) { + amrex::ParallelFor( + ebx, NUM_SPECIES, + [gradT_ar, beta_ar, T, spsoretFlux_ar] AMREX_GPU_DEVICE( + int i, int j, int k, int n) noexcept { + spsoretFlux_ar(i, j, k, n) = + -beta_ar(i, j, k, n) * gradT_ar(i, j, k) / T(i, j, k); + }); + } } } } @@ -1133,20 +1134,21 @@ PeleLM::differentialDiffusionUpdate( auto const& fAux_ma = (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : fY_ma; + auto dt = m_dt; amrex::ParallelFor( - advData->Forcing[lev], - [state_ma, fY_ma, aux_ma, fAux_ma, dt = m_dt, - nAux = - m_nAux] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + advData->Forcing[lev], amrex::IntVect(0), NUM_SPECIES, + [state_ma, fY_ma, + dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - for (int n = 0; n < NUM_SPECIES; ++n) { - fY_ma[box_no](i, j, k, n) *= dt; - fY_ma[box_no](i, j, k, n) += rhoY(i, j, k, n); - } - for (int n = 0; n < nAux; ++n) { - fAux_ma[box_no](i, j, k, n) *= dt; - fAux_ma[box_no](i, j, k, n) += aux_ma[box_no](i, j, k, n); - } + fY_ma[box_no](i, j, k, n) *= dt; + fY_ma[box_no](i, j, k, n) += rhoY(i, j, k, n); + }); + amrex::ParallelFor( + advData->Forcing[lev], amrex::IntVect(0), m_nAux, + [aux_ma, fAux_ma, + dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { + fAux_ma[box_no](i, j, k, n) *= dt; + fAux_ma[box_no](i, j, k, n) += aux_ma[box_no](i, j, k, n); }); // Shift outside? amrex::Gpu::streamSynchronize(); @@ -1331,82 +1333,62 @@ PeleLM::differentialDiffusionUpdate( (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dhat_ma; auto const& dT_ma = (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dhat_ma; - auto const& aux_ma = - (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : state_ma; - auto const& dhat_aux_ma = - (m_nAux > 0) ? diffData->Dhat_aux[lev].const_arrays() : dhat_ma; - auto const& force_aux_ma = - (m_nAux > 0) ? advData->Forcing_aux[lev].const_arrays() : dhat_ma; - + auto dt = m_dt; if (m_use_wbar != 0 && m_use_soret != 0) { amrex::ParallelFor( - ldata_p->state, - [state_ma, dhat_ma, force_ma, dwbar_ma, dT_ma, aux_ma, dhat_aux_ma, - force_aux_ma, nAux = m_nAux, - dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + ldata_p->state, amrex::IntVect(0), NUM_SPECIES, + [state_ma, dhat_ma, force_ma, dwbar_ma, dT_ma, + dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i, j, k, n) = - force_ma[box_no](i, j, k, n) + - dt * (dhat_ma[box_no](i, j, k, n) - dwbar_ma[box_no](i, j, k, n) - - dT_ma[box_no](i, j, k, n)); - } - for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + - dt * dhat_aux_ma[box_no](i, j, k, n); - } + rhoY(i, j, k, n) = + force_ma[box_no](i, j, k, n) + + dt * (dhat_ma[box_no](i, j, k, n) - dwbar_ma[box_no](i, j, k, n) - + dT_ma[box_no](i, j, k, n)); }); } else if (m_use_wbar != 0) { amrex::ParallelFor( - ldata_p->state, - [state_ma, dhat_ma, force_ma, dwbar_ma, aux_ma, dhat_aux_ma, - force_aux_ma, nAux = m_nAux, - dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + ldata_p->state, amrex::IntVect(0), NUM_SPECIES, + [state_ma, dhat_ma, force_ma, dwbar_ma, + dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i, j, k, n) = - force_ma[box_no](i, j, k, n) + - dt * (dhat_ma[box_no](i, j, k, n) - dwbar_ma[box_no](i, j, k, n)); - } - for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + - dt * dhat_aux_ma[box_no](i, j, k, n); - } + rhoY(i, j, k, n) = + force_ma[box_no](i, j, k, n) + + dt * (dhat_ma[box_no](i, j, k, n) - dwbar_ma[box_no](i, j, k, n)); }); } else if (m_use_soret != 0) { amrex::ParallelFor( - ldata_p->state, - [state_ma, dhat_ma, force_ma, dT_ma, aux_ma, dhat_aux_ma, force_aux_ma, - nAux = m_nAux, - dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + ldata_p->state, amrex::IntVect(0), NUM_SPECIES, + [state_ma, dhat_ma, force_ma, dT_ma, + dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i, j, k, n) = - force_ma[box_no](i, j, k, n) + - dt * (dhat_ma[box_no](i, j, k, n) - dT_ma[box_no](i, j, k, n)); - } - for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + - dt * dhat_aux_ma[box_no](i, j, k, n); - } + rhoY(i, j, k, n) = + force_ma[box_no](i, j, k, n) + + dt * (dhat_ma[box_no](i, j, k, n) - dT_ma[box_no](i, j, k, n)); }); } else { amrex::ParallelFor( - ldata_p->state, - [state_ma, dhat_ma, force_ma, aux_ma, dhat_aux_ma, force_aux_ma, - nAux = m_nAux, - dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + ldata_p->state, amrex::IntVect(0), NUM_SPECIES, + [state_ma, dhat_ma, force_ma, + dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i, j, k, n) = - force_ma[box_no](i, j, k, n) + dt * dhat_ma[box_no](i, j, k, n); - } - for (int n = 0; n < nAux; ++n) { - aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + - dt * dhat_aux_ma[box_no](i, j, k, n); - } + rhoY(i, j, k, n) = + force_ma[box_no](i, j, k, n) + dt * dhat_ma[box_no](i, j, k, n); }); } + auto const& aux_ma = + (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : state_ma; + auto const& dhat_aux_ma = + (m_nAux > 0) ? diffData->Dhat_aux[lev].const_arrays() : dhat_ma; + auto const& force_aux_ma = + (m_nAux > 0) ? advData->Forcing_aux[lev].const_arrays() : dhat_ma; + amrex::ParallelFor( + ldata_p->state, amrex::IntVect(0), m_nAux, + [aux_ma, dhat_aux_ma, force_aux_ma, + dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { + aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + + dt * dhat_aux_ma[box_no](i, j, k, n); + }); + // Shift outside? amrex::Gpu::streamSynchronize(); } diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index e470e8e1c..9f696257a 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -154,15 +154,13 @@ DiffusionOp::diffuse_scalar( auto const& a_rho_ma = a_density[lev]->const_arrays(); auto const& phi_ma = phi[lev].arrays(); amrex::ParallelFor( - phi[lev], phi[lev].nGrowVect(), - [a_phi_ma, a_rho_ma, phi_ma, phi_comp, - ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + phi[lev], phi[lev].nGrowVect(), ncomp, + [a_phi_ma, a_rho_ma, phi_ma, phi_comp] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 a_phi_arr( a_phi_ma[box_no], phi_comp); - for (int n = 0; n < ncomp; ++n) { - phi_ma[box_no](i, j, k, n) = - a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); - } + phi_ma[box_no](i, j, k, n) = + a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); }); amrex::Gpu::streamSynchronize(); } @@ -290,12 +288,11 @@ DiffusionOp::diffuse_scalar( auto const& phi_ma = phi[lev].const_arrays(); auto const& a_rho_ma = a_density[lev]->const_arrays(); amrex::ParallelFor( - phi[lev], [a_phi_ma, a_rho_ma, phi_ma, ncomp] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < ncomp; ++n) { - a_phi_ma[box_no](i, j, k, n) = - phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); - } + phi[lev], amrex::IntVect(0), ncomp, + [a_phi_ma, a_rho_ma, phi_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { + a_phi_ma[box_no](i, j, k, n) = + phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); }); // Shift outside? amrex::Gpu::streamSynchronize(); @@ -372,15 +369,13 @@ DiffusionOp::diffuse_scalar( auto const& a_rho_ma = a_density[lev]->const_arrays(); auto const& phi_ma = phi[lev].arrays(); amrex::ParallelFor( - phi[lev], phi[lev].nGrowVect(), - [a_phi_ma, a_rho_ma, phi_ma, phi_comp, - ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + phi[lev], phi[lev].nGrowVect(), ncomp, + [a_phi_ma, a_rho_ma, phi_ma, phi_comp] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 a_phi_arr( a_phi_ma[box_no], phi_comp); - for (int n = 0; n < ncomp; ++n) { - phi_ma[box_no](i, j, k, n) = - a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); - } + phi_ma[box_no](i, j, k, n) = + a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); }); amrex::Gpu::streamSynchronize(); } @@ -502,12 +497,11 @@ DiffusionOp::diffuse_scalar( auto const& phi_ma = phi[lev].const_arrays(); auto const& a_rho_ma = a_density[lev]->const_arrays(); amrex::ParallelFor( - phi[lev], [a_phi_ma, a_rho_ma, phi_ma, ncomp] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < ncomp; ++n) { - a_phi_ma[box_no](i, j, k, n) = - phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); - } + phi[lev], amrex::IntVect(0), ncomp, + [a_phi_ma, a_rho_ma, phi_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { + a_phi_ma[box_no](i, j, k, n) = + phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); }); // Shift outside? amrex::Gpu::streamSynchronize(); @@ -636,15 +630,13 @@ DiffusionOp::computeDiffFluxes( auto const& a_rho_ma = a_density[lev]->const_arrays(); auto const& phi_ma = phi[lev].arrays(); amrex::ParallelFor( - phi[lev], phi[lev].nGrowVect(), - [a_phi_ma, a_rho_ma, phi_ma, phi_comp, - ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + phi[lev], phi[lev].nGrowVect(), ncomp, + [a_phi_ma, a_rho_ma, phi_ma, phi_comp] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 a_phi_arr( a_phi_ma[box_no], phi_comp); - for (int n = 0; n < ncomp; ++n) { - phi_ma[box_no](i, j, k, n) = - a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); - } + phi_ma[box_no](i, j, k, n) = + a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); }); amrex::Gpu::streamSynchronize(); } @@ -779,15 +771,13 @@ DiffusionOp::computeDiffFluxes( auto const& a_rho_ma = a_density[lev]->const_arrays(); auto const& phi_ma = phi[lev].arrays(); amrex::ParallelFor( - phi[lev], phi[lev].nGrowVect(), - [a_phi_ma, a_rho_ma, phi_ma, phi_comp, - ncomp] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + phi[lev], phi[lev].nGrowVect(), ncomp, + [a_phi_ma, a_rho_ma, phi_ma, phi_comp] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 a_phi_arr( a_phi_ma[box_no], phi_comp); - for (int n = 0; n < ncomp; ++n) { - phi_ma[box_no](i, j, k, n) = - a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); - } + phi_ma[box_no](i, j, k, n) = + a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); }); amrex::Gpu::streamSynchronize(); } @@ -1195,11 +1185,10 @@ DiffusionTensorOp::compute_divtau( auto const& divtau_ma = a_divtau[lev]->arrays(); auto const& rho_ma = a_density[lev]->const_arrays(); amrex::ParallelFor( - *a_divtau[lev], [divtau_ma, rho_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - divtau_ma[box_no](i, j, k, n) /= rho_ma[box_no](i, j, k); - } + *a_divtau[lev], amrex::IntVect(0), AMREX_SPACEDIM, + [divtau_ma, rho_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { + divtau_ma[box_no](i, j, k, n) /= rho_ma[box_no](i, j, k); }); // Shift outside? amrex::Gpu::streamSynchronize(); @@ -1263,20 +1252,18 @@ DiffusionTensorOp::diffuse_velocity( if (m_pelelm->m_incompressible == 0) { auto const& rho_ma = a_density[lev]->const_arrays(); amrex::ParallelFor( - rhs[lev], [rhs_ma, vel_ma, rho_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - rhs_ma[box_no](i, j, k, n) = - rho_ma[box_no](i, j, k) * vel_ma[box_no](i, j, k, n); - } + rhs[lev], amrex::IntVect(0), AMREX_SPACEDIM, + [rhs_ma, vel_ma, rho_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { + rhs_ma[box_no](i, j, k, n) = + rho_ma[box_no](i, j, k) * vel_ma[box_no](i, j, k, n); }); } else { amrex::ParallelFor( - rhs[lev], [rhs_ma, vel_ma, rho = m_pelelm->m_rho] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - rhs_ma[box_no](i, j, k, n) = rho * vel_ma[box_no](i, j, k, n); - } + rhs[lev], amrex::IntVect(0), AMREX_SPACEDIM, + [rhs_ma, vel_ma, rho = m_pelelm->m_rho] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { + rhs_ma[box_no](i, j, k, n) = rho * vel_ma[box_no](i, j, k, n); }); } amrex::Gpu::streamSynchronize(); diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index aada3fd43..2d53c6cbc 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -53,7 +53,6 @@ PeleLM::getVelForces( const int is_incomp = m_incompressible; const amrex::Real rho_incomp = m_rho; - const int has_divTau = static_cast(a_divTau != nullptr); const int pseudo_gravity = m_ctrl_pseudoGravity; const amrex::Real dV_control = m_ctrl_dV; @@ -64,25 +63,12 @@ PeleLM::getVelForces( auto const& state_ma = ldata_p->state.const_arrays(); auto const& ext_ma = m_extSource[lev]->const_arrays(); auto const& force_ma = a_velForce->arrays(); - auto const& gp_ma = ldataGP_p->gp.const_arrays(); - auto const& divTau_ma = - (has_divTau != 0) ? a_divTau->const_arrays() : state_ma; - -#ifdef PELE_USE_PLASMA - auto const& dx = geom[lev].CellSizeArray(); - auto const& ba = grids[lev]; - auto const& zkl = zk; -#endif amrex::ParallelFor( *a_velForce, - [state_ma, ext_ma, force_ma, grav, gp0, ps_dir, add_gradP, gp_ma, - has_divTau, divTau_ma, is_incomp, rho_incomp, pseudo_gravity, dV_control -#ifdef PELE_USE_PLASMA - , - dx, time, ba, zkl -#endif - ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) { + [state_ma, ext_ma, force_ma, grav, gp0, ps_dir, is_incomp, rho_incomp, + pseudo_gravity, + dV_control] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) { amrex::Array4 vel(state_ma[box_no], VELX); amrex::Array4 extmom(ext_ma[box_no], VELX); amrex::Array4 rho(state_ma[box_no], DENSITY); @@ -96,33 +82,21 @@ PeleLM::getVelForces( makeVelForce( i, j, k, is_incomp, rho_incomp, pseudo_gravity, ps_dir, grav, gp0, dV_control, vel, rho, extmom, extrho, force_ma[box_no]); -#ifdef PELE_USE_PLASMA - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - amrex::Array4 rhoh(state_ma[box_no], RHOH); - amrex::Array4 temp(state_ma[box_no], TEMP); - amrex::Array4 phiV(state_ma[box_no], PHIV); - amrex::Array4 nE(state_ma[box_no], NE); - amrex::GpuArray blo = ba[box_no].loVect3d(); - amrex::GpuArray bhi = ba[box_no].hiVect3d(); - addLorentzForce( - i, j, k, blo, bhi, time, dx, zkl, rhoY, nE, phiV, force_ma[box_no]); -#endif - if (add_gradP != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - force_ma[box_no](i, j, k, idim) -= gp_ma[box_no](i, j, k, idim); - } - } - if (has_divTau != 0) { - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - force_ma[box_no](i, j, k, idim) += divTau_ma[box_no](i, j, k, idim); - } - } }); amrex::Gpu::streamSynchronize(); - // Add forcing terms to maintain turbulence - // note: if m_incompressible == 0 then m_rho is unused by - // addTurbVelForces + + if (add_gradP != 0) { + amrex::MultiFab::Subtract( + *a_velForce, ldataGP_p->gp, 0, 0, AMREX_SPACEDIM, 0); + } + const int has_divTau = static_cast(a_divTau != nullptr); + if (has_divTau != 0) { + amrex::MultiFab::Add(*a_velForce, *a_divTau, 0, 0, AMREX_SPACEDIM, 0); + } + +#ifndef PELE_USE_PLASMA if (m_do_turbulent_forcing) { +#endif #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif @@ -130,104 +104,120 @@ PeleLM::getVelForces( ++mfi) { const auto& bx = mfi.tilebox(); amrex::FArrayBox DummyFab(bx, 1); - const auto& rho_arr = (is_incomp != 0) + const auto& rho_arr = (m_incompressible != 0) ? DummyFab.array() : ldata_p->state.const_array(mfi, DENSITY); const auto& force_arr = a_velForce->array(mfi); - turb_forcing.addTurbVelForces( - geom[lev].data(), bx, time, force_arr, rho_arr, is_incomp, rho_incomp); +#ifdef PELE_USE_PLASMA + const auto& rhoY_arr = (m_incompressible != 0) + ? DummyFab.array() + : ldata_p->state.const_array(mfi, FIRSTSPEC); + const auto& rhoh_arr = (m_incompressible != 0) + ? DummyFab.array() + : ldata_p->state.const_array(mfi, RHOH); + const auto& temp_arr = (m_incompressible != 0) + ? DummyFab.array() + : ldata_p->state.const_array(mfi, TEMP); + const auto& phiV_arr = ldata_p->state.const_array(mfi, PHIV); + const auto& ne_arr = ldata_p->state.const_array(mfi, NE); + addLorentzVelForces(lev, bx, time, force_arr, rhoY_arr, phiV_arr, ne_arr); + if (m_do_turbulent_forcing) { +#endif + // Add forcing terms to maintain turbulence + // note: if m_incompressible == 0 then m_rho is unused by + // addTurbVelForce + turb_forcing.addTurbVelForces( + geom[lev].data(), bx, time, force_arr, rho_arr, is_incomp, + rho_incomp); + } } - } - if (is_incomp != 0) { - a_velForce->mult(1.0 / rho_incomp, 0, AMREX_SPACEDIM, 0); - } else { - amrex::ParallelFor( - *a_velForce, [force_ma, state_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - amrex::Array4 rho(state_ma[box_no], DENSITY); - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - force_ma[box_no](i, j, k, idim) /= rho(i, j, k); - } - }); - amrex::Gpu::streamSynchronize(); + if (is_incomp != 0) { + a_velForce->mult(1.0 / rho_incomp, 0, AMREX_SPACEDIM, 0); + } else { + amrex::ParallelFor( + *a_velForce, amrex::IntVect(0), AMREX_SPACEDIM, + [force_ma, state_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { + amrex::Array4 rho(state_ma[box_no], DENSITY); + force_ma[box_no](i, j, k, n) /= rho(i, j, k); + }); + amrex::Gpu::streamSynchronize(); + } } -} -void -PeleLM::addSpark(const TimeStamp a_timestamp) -{ - for (int lev = 0; lev <= finest_level; ++lev) { - for (int n = 0; n < m_n_sparks; ++n) { - // Do the checks first - const amrex::Real time = getTime(lev, a_timestamp); - const bool verb = m_spark_verbose > 1 && lev == 0; - if ( - time < m_spark_time[n] || - time > m_spark_time[n] + m_spark_duration[n]) { + void PeleLM::addSpark(const TimeStamp a_timestamp) + { + for (int lev = 0; lev <= finest_level; ++lev) { + for (int n = 0; n < m_n_sparks; ++n) { + // Do the checks first + const amrex::Real time = getTime(lev, a_timestamp); + const bool verb = m_spark_verbose > 1 && lev == 0; + if ( + time < m_spark_time[n] || + time > m_spark_time[n] + m_spark_duration[n]) { + if (verb) { + amrex::Print() << m_spark[n] << " not active \n"; + } + continue; + } + const amrex::Real* probLo = geom[lev].ProbLo(); + auto const dx = geom[lev].CellSizeArray(); + amrex::IntVect spark_idx; + for (int d = 0; d < AMREX_SPACEDIM; ++d) { + spark_idx[d] = + static_cast((m_spark_location[n][d] - probLo[d]) / dx[d]); + } + const amrex::Box domainBox = geom[lev].Domain(); + // just a check + if (!domainBox.contains(spark_idx)) { + amrex::Warning(m_spark[n] + " not in domain!"); + continue; + } if (verb) { - amrex::Print() << m_spark[n] << " not active \n"; + amrex::Print() << m_spark[n] << " active\n"; } - continue; - } - const amrex::Real* probLo = geom[lev].ProbLo(); - auto const dx = geom[lev].CellSizeArray(); - amrex::IntVect spark_idx; - for (int d = 0; d < AMREX_SPACEDIM; ++d) { - spark_idx[d] = - static_cast((m_spark_location[n][d] - probLo[d]) / dx[d]); - } - const amrex::Box domainBox = geom[lev].Domain(); - // just a check - if (!domainBox.contains(spark_idx)) { - amrex::Warning(m_spark[n] + " not in domain!"); - continue; - } - if (verb) { - amrex::Print() << m_spark[n] << " active\n"; - } - auto const* eosparm = eos_parms.device_parm(); - auto eos = pele::physics::PhysicsType::eos(eosparm); - - auto const& statema = - getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); - auto const& extma = m_extSource[lev]->arrays(); - amrex::ParallelFor( - *m_extSource[lev], - [statema, extma, eos, dx, spark_idx, - spark_duration = m_spark_duration[n], spark_temp = m_spark_temp[n], - spark_radius = m_spark_radius - [n]] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - const amrex::Real dist_to_center = std::sqrt(AMREX_D_TERM( - (i - spark_idx[0]) * (i - spark_idx[0]) * dx[0] * dx[0], - +(j - spark_idx[1]) * (j - spark_idx[1]) * dx[1] * dx[1], - +(k - spark_idx[2]) * (k - spark_idx[2]) * dx[2] * dx[2])); - if (dist_to_center < spark_radius) { - amrex::Real rhoh_src_loc = 0; - const amrex::Real rho = statema[box_no](i, j, k, DENSITY); - amrex::Real Y[NUM_SPECIES]; - for (int ns = 0; ns < NUM_SPECIES; ++ns) { - Y[ns] = statema[box_no](i, j, k, FIRSTSPEC + ns) / rho; + auto const* eosparm = eos_parms.device_parm(); + auto eos = pele::physics::PhysicsType::eos(eosparm); + + auto const& statema = + getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); + auto const& extma = m_extSource[lev]->arrays(); + amrex::ParallelFor( + *m_extSource[lev], + [statema, extma, eos, dx, spark_idx, + spark_duration = m_spark_duration[n], spark_temp = m_spark_temp[n], + spark_radius = m_spark_radius + [n]] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + const amrex::Real dist_to_center = std::sqrt(AMREX_D_TERM( + (i - spark_idx[0]) * (i - spark_idx[0]) * dx[0] * dx[0], + +(j - spark_idx[1]) * (j - spark_idx[1]) * dx[1] * dx[1], + +(k - spark_idx[2]) * (k - spark_idx[2]) * dx[2] * dx[2])); + if (dist_to_center < spark_radius) { + amrex::Real rhoh_src_loc = 0; + const amrex::Real rho = statema[box_no](i, j, k, DENSITY); + amrex::Real Y[NUM_SPECIES]; + for (int ns = 0; ns < NUM_SPECIES; ++ns) { + Y[ns] = statema[box_no](i, j, k, FIRSTSPEC + ns) / rho; + } + eos.TY2H(spark_temp, Y, rhoh_src_loc); + rhoh_src_loc *= rho * 1e-4 / spark_duration; + extma[box_no](i, j, k, RHOH) = rhoh_src_loc; } - eos.TY2H(spark_temp, Y, rhoh_src_loc); - rhoh_src_loc *= rho * 1e-4 / spark_duration; - extma[box_no](i, j, k, RHOH) = rhoh_src_loc; - } - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); + }); + // Shift outside? + amrex::Gpu::streamSynchronize(); + } } } -} -// Manifold model - dissipation rate sources for variances -void -PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) -{ - BL_PROFILE("PeleLM::addScalarVarianceSources"); - // no scalar dissipation sources if not using a manifold model + // Manifold model - dissipation rate sources for variances + void PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) + { + BL_PROFILE("PeleLM::addScalarVarianceSources"); + // no scalar dissipation sources if not using a manifold model #ifndef USE_MANIFOLD_EOS - amrex::ignore_unused(a_timestamp); + amrex::ignore_unused(a_timestamp); #else if (m_add_variance_sources) { @@ -364,57 +354,55 @@ PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) extma[bx](i, j, k, FIRSTSPEC + n) += 2.0 * ScInv * mu_grad2; }); + amrex::Gpu::streamSynchronize(); } } } - amrex::Gpu::streamSynchronize(); } } #endif -} + } -// Calculate additional external sources (soot, radiation, user defined, etc.) -void -PeleLM::getExternalSources( - const int is_initIter, - const PeleLM::TimeStamp a_timestamp_old, - const PeleLM::TimeStamp a_timestamp_new) -{ - amrex::ignore_unused(is_initIter); + // Calculate additional external sources (soot, radiation, user defined, etc.) + void PeleLM::getExternalSources( + const int is_initIter, const PeleLM::TimeStamp a_timestamp_old, + const PeleLM::TimeStamp a_timestamp_new) + { + amrex::ignore_unused(is_initIter); - if (m_n_sparks > 0) { - addSpark(a_timestamp_old); - } + if (m_n_sparks > 0) { + addSpark(a_timestamp_old); + } #ifdef PELE_USE_SPRAY - if (is_initIter == 0) { - SprayMKD(m_cur_time, m_dt); - } + if (is_initIter == 0) { + SprayMKD(m_cur_time, m_dt); + } #endif #ifdef PELE_USE_SOOT - if (do_soot_solve) { - computeSootSource(a_timestamp_old, m_dt); - } + if (do_soot_solve) { + computeSootSource(a_timestamp_old, m_dt); + } #endif #ifdef PELE_USE_RADIATION - if (do_rad_solve) { - BL_PROFILE_VAR("PeleLM::advance::rad", PLM_RAD); - computeRadSource(a_timestamp_old); - BL_PROFILE_VAR_STOP(PLM_RAD); - } + if (do_rad_solve) { + BL_PROFILE_VAR("PeleLM::advance::rad", PLM_RAD); + computeRadSource(a_timestamp_old); + BL_PROFILE_VAR_STOP(PLM_RAD); + } #endif - addScalarVarianceSources(a_timestamp_old); + addScalarVarianceSources(a_timestamp_old); - // User defined external sources - if (m_user_defined_ext_sources) { - for (int lev = 0; lev <= finest_level; ++lev) { - auto* ldata_p_old = getLevelDataPtr(lev, a_timestamp_old); - auto* ldata_p_new = getLevelDataPtr(lev, a_timestamp_new); - auto& ext_src = m_extSource[lev]; - ProblemSpecificFunctions::modify_ext_sources( - getTime(lev, a_timestamp_old), m_dt, ldata_p_old->state, - ldata_p_new->state, ext_src, geom[lev].data(), prob_parm_d); + // User defined external sources + if (m_user_defined_ext_sources) { + for (int lev = 0; lev <= finest_level; ++lev) { + auto* ldata_p_old = getLevelDataPtr(lev, a_timestamp_old); + auto* ldata_p_new = getLevelDataPtr(lev, a_timestamp_new); + auto& ext_src = m_extSource[lev]; + ProblemSpecificFunctions::modify_ext_sources( + getTime(lev, a_timestamp_old), m_dt, ldata_p_old->state, + ldata_p_new->state, ext_src, geom[lev].data(), prob_parm_d); + } } } -} diff --git a/Source/PeleLMeX_ODEQty.cpp b/Source/PeleLMeX_ODEQty.cpp index 957221727..061779ac5 100644 --- a/Source/PeleLMeX_ODEQty.cpp +++ b/Source/PeleLMeX_ODEQty.cpp @@ -21,7 +21,7 @@ PeleLM::predictODEQty() state_arrs[box_no](i, j, k, FIRSTODE + n) = B_n + dt * S_ext_n; } }); + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } #endif diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 893086b45..c36e6ce3d 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -1179,24 +1179,7 @@ PeleLM::addLevelVelocityDataFromPlt(int a_lev, const std::string& a_velPltFile) a_lev, geom[a_lev], idXvel, sComp0, AMREX_SPACEDIM, tmpVel); // scale the velocity tmpVel.mult(m_velocity_plotfile_scale); - -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - amrex::FArrayBox DummyFab(bx, 1); - auto const& state_arr = ldata_p->state.array(mfi); - auto const& tmpVel_arr = tmpVel.array(mfi); - amrex::ParallelFor( - bx, - [state_arr, tmpVel_arr] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - state_arr(i, j, k, XVEL + n) += tmpVel_arr(i, j, k, n); - } - }); - } + amrex::MultiFab::Add(ldata_p->state, tmpVel, 0, VELX, AMREX_SPACEDIM, 0); } void diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index f751ed9cb..656a637c6 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -243,14 +243,12 @@ PeleLM::velocityProjection( auto const& gp_new_ma = ldataNew_p->gp.const_arrays(); auto const& rho_ma = rhoHalf[lev]->const_arrays(); amrex::ParallelFor( - ldataNew_p->state, + ldataNew_p->state, amrex::IntVect(0), AMREX_SPACEDIM, [state_old_ma, gp_new_ma, rho_ma, dt = a_dt] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { + int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 vel(state_old_ma[box_no], VELX); const amrex::Real soverrho = dt / rho_ma[box_no](i, j, k); - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; - } + vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; }); // Shift outside? (w/below) amrex::Gpu::streamSynchronize(); @@ -263,13 +261,11 @@ PeleLM::velocityProjection( auto const& gp_new_ma = ldataNew_p->gp.const_arrays(); const amrex::Real soverrho = m_dt / m_rho; amrex::ParallelFor( - ldataNew_p->state, + ldataNew_p->state, amrex::IntVect(0), AMREX_SPACEDIM, [state_old_ma, gp_new_ma, soverrho] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { + int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 vel(state_old_ma[box_no], VELX); - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; - } + vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; }); // Shift outside? amrex::Gpu::streamSynchronize(); @@ -562,18 +558,14 @@ PeleLM::scaleProj_RZ( // NOLINT(readability-convert-member-functions-to-static) const amrex::Real dr = geom[a_lev].CellSize()[0]; auto const& mf_ma = a_mf.arrays(); amrex::ParallelFor( - a_mf, a_mf.nGrowVect(), - [mf_ma, dr, domain, ncomp = a_mf.nComp()] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { + a_mf, a_mf.nGrowVect(), a_mf.nComp(), + [mf_ma, dr, + domain] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { auto mf = mf_ma[box_no]; if (domain.contains(i, j, k)) { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) *= (static_cast(i) + 0.5) * dr; - } + mf(i, j, k, n) *= (static_cast(i) + 0.5) * dr; } else { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) = 0.0; - } + mf(i, j, k, n) = 0.0; } }); amrex::Gpu::streamSynchronize(); @@ -590,18 +582,14 @@ PeleLM:: const amrex::Real dr = geom[a_lev].CellSize()[0]; auto const& mf_ma = a_mf.arrays(); amrex::ParallelFor( - a_mf, a_mf.nGrowVect(), - [mf_ma, dr, domain, ncomp = a_mf.nComp()] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { + a_mf, a_mf.nGrowVect(), a_mf.nComp(), + [mf_ma, dr, + domain] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { auto mf = mf_ma[box_no]; if (domain.contains(i, j, k)) { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) /= (static_cast(i) + 0.5) * dr; - } + mf(i, j, k, n) /= (static_cast(i) + 0.5) * dr; } else { - for (int n = 0; n < ncomp; ++n) { - mf(i, j, k, n) = 0.0; - } + mf(i, j, k, n) = 0.0; } }); amrex::Gpu::streamSynchronize(); diff --git a/Source/Plasma/PeleLMeX_EFTransport.cpp b/Source/Plasma/PeleLMeX_EFTransport.cpp index 0e8fb2f30..156273c23 100644 --- a/Source/Plasma/PeleLMeX_EFTransport.cpp +++ b/Source/Plasma/PeleLMeX_EFTransport.cpp @@ -28,6 +28,6 @@ PeleLM::calcEFTransport(const TimeStamp a_time) i, j, k, useTab, fixedKe, dxinv, rhoY, phiV, T, mobE_ma[box_no]); getDiffE(i, j, k, factor, T, mobE_ma[box_no], diffE_ma[box_no]); }); + amrex::Gpu::streamSynchronize(); } - amrex::Gpu::streamSynchronize(); } From 5c0d0124e1c99e51864f45bbbbf3e3e67e379342 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sat, 23 Aug 2025 18:37:19 +0200 Subject: [PATCH 68/87] fix indentations --- Source/PeleLMeX_Forces.cpp | 229 +++++++++++++++++++------------------ 1 file changed, 118 insertions(+), 111 deletions(-) diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 2d53c6cbc..0f5bde479 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -95,8 +95,9 @@ PeleLM::getVelForces( } #ifndef PELE_USE_PLASMA - if (m_do_turbulent_forcing) { + if (m_do_turbulent_forcing) #endif + { #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif @@ -121,8 +122,9 @@ PeleLM::getVelForces( const auto& phiV_arr = ldata_p->state.const_array(mfi, PHIV); const auto& ne_arr = ldata_p->state.const_array(mfi, NE); addLorentzVelForces(lev, bx, time, force_arr, rhoY_arr, phiV_arr, ne_arr); - if (m_do_turbulent_forcing) { + if (m_do_turbulent_forcing) #endif + { // Add forcing terms to maintain turbulence // note: if m_incompressible == 0 then m_rho is unused by // addTurbVelForce @@ -131,93 +133,96 @@ PeleLM::getVelForces( rho_incomp); } } + } - if (is_incomp != 0) { - a_velForce->mult(1.0 / rho_incomp, 0, AMREX_SPACEDIM, 0); - } else { - amrex::ParallelFor( - *a_velForce, amrex::IntVect(0), AMREX_SPACEDIM, - [force_ma, state_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 rho(state_ma[box_no], DENSITY); - force_ma[box_no](i, j, k, n) /= rho(i, j, k); - }); - amrex::Gpu::streamSynchronize(); - } + if (is_incomp != 0) { + a_velForce->mult(1.0 / rho_incomp, 0, AMREX_SPACEDIM, 0); + } else { + amrex::ParallelFor( + *a_velForce, amrex::IntVect(0), AMREX_SPACEDIM, + [force_ma, state_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { + amrex::Array4 rho(state_ma[box_no], DENSITY); + force_ma[box_no](i, j, k, n) /= rho(i, j, k); + }); + amrex::Gpu::streamSynchronize(); } +} - void PeleLM::addSpark(const TimeStamp a_timestamp) - { - for (int lev = 0; lev <= finest_level; ++lev) { - for (int n = 0; n < m_n_sparks; ++n) { - // Do the checks first - const amrex::Real time = getTime(lev, a_timestamp); - const bool verb = m_spark_verbose > 1 && lev == 0; - if ( - time < m_spark_time[n] || - time > m_spark_time[n] + m_spark_duration[n]) { - if (verb) { - amrex::Print() << m_spark[n] << " not active \n"; - } - continue; - } - const amrex::Real* probLo = geom[lev].ProbLo(); - auto const dx = geom[lev].CellSizeArray(); - amrex::IntVect spark_idx; - for (int d = 0; d < AMREX_SPACEDIM; ++d) { - spark_idx[d] = - static_cast((m_spark_location[n][d] - probLo[d]) / dx[d]); - } - const amrex::Box domainBox = geom[lev].Domain(); - // just a check - if (!domainBox.contains(spark_idx)) { - amrex::Warning(m_spark[n] + " not in domain!"); - continue; - } +void +PeleLM::addSpark(const TimeStamp a_timestamp) +{ + for (int lev = 0; lev <= finest_level; ++lev) { + for (int n = 0; n < m_n_sparks; ++n) { + // Do the checks first + const amrex::Real time = getTime(lev, a_timestamp); + const bool verb = m_spark_verbose > 1 && lev == 0; + if ( + time < m_spark_time[n] || + time > m_spark_time[n] + m_spark_duration[n]) { if (verb) { - amrex::Print() << m_spark[n] << " active\n"; + amrex::Print() << m_spark[n] << " not active \n"; } - auto const* eosparm = eos_parms.device_parm(); - auto eos = pele::physics::PhysicsType::eos(eosparm); - - auto const& statema = - getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); - auto const& extma = m_extSource[lev]->arrays(); - amrex::ParallelFor( - *m_extSource[lev], - [statema, extma, eos, dx, spark_idx, - spark_duration = m_spark_duration[n], spark_temp = m_spark_temp[n], - spark_radius = m_spark_radius - [n]] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - const amrex::Real dist_to_center = std::sqrt(AMREX_D_TERM( - (i - spark_idx[0]) * (i - spark_idx[0]) * dx[0] * dx[0], - +(j - spark_idx[1]) * (j - spark_idx[1]) * dx[1] * dx[1], - +(k - spark_idx[2]) * (k - spark_idx[2]) * dx[2] * dx[2])); - if (dist_to_center < spark_radius) { - amrex::Real rhoh_src_loc = 0; - const amrex::Real rho = statema[box_no](i, j, k, DENSITY); - amrex::Real Y[NUM_SPECIES]; - for (int ns = 0; ns < NUM_SPECIES; ++ns) { - Y[ns] = statema[box_no](i, j, k, FIRSTSPEC + ns) / rho; - } - eos.TY2H(spark_temp, Y, rhoh_src_loc); - rhoh_src_loc *= rho * 1e-4 / spark_duration; - extma[box_no](i, j, k, RHOH) = rhoh_src_loc; - } - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); + continue; } + const amrex::Real* probLo = geom[lev].ProbLo(); + auto const dx = geom[lev].CellSizeArray(); + amrex::IntVect spark_idx; + for (int d = 0; d < AMREX_SPACEDIM; ++d) { + spark_idx[d] = + static_cast((m_spark_location[n][d] - probLo[d]) / dx[d]); + } + const amrex::Box domainBox = geom[lev].Domain(); + // just a check + if (!domainBox.contains(spark_idx)) { + amrex::Warning(m_spark[n] + " not in domain!"); + continue; + } + if (verb) { + amrex::Print() << m_spark[n] << " active\n"; + } + auto const* eosparm = eos_parms.device_parm(); + auto eos = pele::physics::PhysicsType::eos(eosparm); + + auto const& statema = + getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); + auto const& extma = m_extSource[lev]->arrays(); + amrex::ParallelFor( + *m_extSource[lev], + [statema, extma, eos, dx, spark_idx, + spark_duration = m_spark_duration[n], spark_temp = m_spark_temp[n], + spark_radius = m_spark_radius + [n]] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + const amrex::Real dist_to_center = std::sqrt(AMREX_D_TERM( + (i - spark_idx[0]) * (i - spark_idx[0]) * dx[0] * dx[0], + +(j - spark_idx[1]) * (j - spark_idx[1]) * dx[1] * dx[1], + +(k - spark_idx[2]) * (k - spark_idx[2]) * dx[2] * dx[2])); + if (dist_to_center < spark_radius) { + amrex::Real rhoh_src_loc = 0; + const amrex::Real rho = statema[box_no](i, j, k, DENSITY); + amrex::Real Y[NUM_SPECIES]; + for (int ns = 0; ns < NUM_SPECIES; ++ns) { + Y[ns] = statema[box_no](i, j, k, FIRSTSPEC + ns) / rho; + } + eos.TY2H(spark_temp, Y, rhoh_src_loc); + rhoh_src_loc *= rho * 1e-4 / spark_duration; + extma[box_no](i, j, k, RHOH) = rhoh_src_loc; + } + }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } } +} - // Manifold model - dissipation rate sources for variances - void PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) - { - BL_PROFILE("PeleLM::addScalarVarianceSources"); - // no scalar dissipation sources if not using a manifold model +// Manifold model - dissipation rate sources for variances +void +PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) +{ + BL_PROFILE("PeleLM::addScalarVarianceSources"); + // no scalar dissipation sources if not using a manifold model #ifndef USE_MANIFOLD_EOS - amrex::ignore_unused(a_timestamp); + amrex::ignore_unused(a_timestamp); #else if (m_add_variance_sources) { @@ -361,48 +366,50 @@ PeleLM::getVelForces( } } #endif - } +} - // Calculate additional external sources (soot, radiation, user defined, etc.) - void PeleLM::getExternalSources( - const int is_initIter, const PeleLM::TimeStamp a_timestamp_old, - const PeleLM::TimeStamp a_timestamp_new) - { - amrex::ignore_unused(is_initIter); +// Calculate additional external sources (soot, radiation, user defined, etc.) +void +PeleLM::getExternalSources( + const int is_initIter, + const PeleLM::TimeStamp a_timestamp_old, + const PeleLM::TimeStamp a_timestamp_new) +{ + amrex::ignore_unused(is_initIter); - if (m_n_sparks > 0) { - addSpark(a_timestamp_old); - } + if (m_n_sparks > 0) { + addSpark(a_timestamp_old); + } #ifdef PELE_USE_SPRAY - if (is_initIter == 0) { - SprayMKD(m_cur_time, m_dt); - } + if (is_initIter == 0) { + SprayMKD(m_cur_time, m_dt); + } #endif #ifdef PELE_USE_SOOT - if (do_soot_solve) { - computeSootSource(a_timestamp_old, m_dt); - } + if (do_soot_solve) { + computeSootSource(a_timestamp_old, m_dt); + } #endif #ifdef PELE_USE_RADIATION - if (do_rad_solve) { - BL_PROFILE_VAR("PeleLM::advance::rad", PLM_RAD); - computeRadSource(a_timestamp_old); - BL_PROFILE_VAR_STOP(PLM_RAD); - } + if (do_rad_solve) { + BL_PROFILE_VAR("PeleLM::advance::rad", PLM_RAD); + computeRadSource(a_timestamp_old); + BL_PROFILE_VAR_STOP(PLM_RAD); + } #endif - addScalarVarianceSources(a_timestamp_old); + addScalarVarianceSources(a_timestamp_old); - // User defined external sources - if (m_user_defined_ext_sources) { - for (int lev = 0; lev <= finest_level; ++lev) { - auto* ldata_p_old = getLevelDataPtr(lev, a_timestamp_old); - auto* ldata_p_new = getLevelDataPtr(lev, a_timestamp_new); - auto& ext_src = m_extSource[lev]; - ProblemSpecificFunctions::modify_ext_sources( - getTime(lev, a_timestamp_old), m_dt, ldata_p_old->state, - ldata_p_new->state, ext_src, geom[lev].data(), prob_parm_d); - } + // User defined external sources + if (m_user_defined_ext_sources) { + for (int lev = 0; lev <= finest_level; ++lev) { + auto* ldata_p_old = getLevelDataPtr(lev, a_timestamp_old); + auto* ldata_p_new = getLevelDataPtr(lev, a_timestamp_new); + auto& ext_src = m_extSource[lev]; + ProblemSpecificFunctions::modify_ext_sources( + getTime(lev, a_timestamp_old), m_dt, ldata_p_old->state, + ldata_p_new->state, ext_src, geom[lev].data(), prob_parm_d); } } +} From a8f96ae86696ea64e84520ce2cbd7c3325502576 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 24 Aug 2025 14:30:07 +0200 Subject: [PATCH 69/87] unnecessary header, tol test --- Source/PeleLMeX_Forces.cpp | 4 +--- Tests/CMakeLists.txt | 12 ++---------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 0f5bde479..2392d9b68 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -1,8 +1,6 @@ #include #include -#if PELE_USE_PLASMA -#include -#endif + // Return velocity forces scaled by rhoInv // including grapP term if add_gradP = 1 // including divTau if input amrex::Vector not empty diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index dd1c894aa..b4b3c4e20 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -96,14 +96,6 @@ function(add_test_r TEST_NAME TEST_EXE_DIR) set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 18000 PROCESSORS ${PELE_NP} WORKING_DIRECTORY "${CURRENT_TEST_BINARY_DIR}/" LABELS "regression" ATTACHED_FILES "${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.log") endfunction(add_test_r) -#Standard regression test with looser tolerances -function(add_test_rtol TEST_NAME TEST_EXE_DIR) - setup_test() - set(RUNTIME_OPTIONS "amr.max_step=10 mac_proj.atol=5e-11 mac_proj.rtol=5e-11 mac_proj.verbose=2 ${RUNTIME_OPTIONS}") - add_test(${TEST_NAME} bash -c "set -o pipefail && ${MPI_COMMANDS} ${CURRENT_TEST_EXE} ${MPIEXEC_POSTFLAGS} ${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.inp ${RUNTIME_OPTIONS} 2>&1 | tee ${TEST_NAME}.log ${SAVE_GOLDS_COMMAND} ${FCOMPARE_COMMAND}") - set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 18000 PROCESSORS ${PELE_NP} WORKING_DIRECTORY "${CURRENT_TEST_BINARY_DIR}/" LABELS "regression" ATTACHED_FILES "${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.log") -endfunction(add_test_r) - # Regression test with mass conservation verification function(add_test_rv TEST_NAME TEST_EXE_DIR) setup_test() @@ -258,8 +250,8 @@ if(NOT PELE_ENABLE_EB) else() if(PELE_DIM EQUAL 2) add_test_rt(composition-test-${PELE_DIM}d EB_ODEQty) - add_test_rtol(eb_bfs EB_BackwardStepFlame) - add_test_rtol(eb_bfs_pp EB_BackwardStepFlame) + add_test_rt(eb_bfs EB_BackwardStepFlame) + add_test_rt(eb_bfs_pp EB_BackwardStepFlame) endif() add_test_r(eb-odeqty-${PELE_DIM}d EB_ODEQty) endif() From 7ce250898abb552375577c9e3bfd3240e5b55f86 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 24 Aug 2025 14:35:02 +0200 Subject: [PATCH 70/87] typo --- Tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index b4b3c4e20..be94bf8fb 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -250,8 +250,8 @@ if(NOT PELE_ENABLE_EB) else() if(PELE_DIM EQUAL 2) add_test_rt(composition-test-${PELE_DIM}d EB_ODEQty) - add_test_rt(eb_bfs EB_BackwardStepFlame) - add_test_rt(eb_bfs_pp EB_BackwardStepFlame) + add_test_r(eb_bfs EB_BackwardStepFlame) + add_test_r(eb_bfs_pp EB_BackwardStepFlame) endif() add_test_r(eb-odeqty-${PELE_DIM}d EB_ODEQty) endif() From 59c3151fa321fe02b88abcc975c2a3cb2071d1ae Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 24 Aug 2025 14:47:19 +0200 Subject: [PATCH 71/87] ebbfs tols --- Tests/CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index be94bf8fb..dd1c894aa 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -96,6 +96,14 @@ function(add_test_r TEST_NAME TEST_EXE_DIR) set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 18000 PROCESSORS ${PELE_NP} WORKING_DIRECTORY "${CURRENT_TEST_BINARY_DIR}/" LABELS "regression" ATTACHED_FILES "${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.log") endfunction(add_test_r) +#Standard regression test with looser tolerances +function(add_test_rtol TEST_NAME TEST_EXE_DIR) + setup_test() + set(RUNTIME_OPTIONS "amr.max_step=10 mac_proj.atol=5e-11 mac_proj.rtol=5e-11 mac_proj.verbose=2 ${RUNTIME_OPTIONS}") + add_test(${TEST_NAME} bash -c "set -o pipefail && ${MPI_COMMANDS} ${CURRENT_TEST_EXE} ${MPIEXEC_POSTFLAGS} ${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.inp ${RUNTIME_OPTIONS} 2>&1 | tee ${TEST_NAME}.log ${SAVE_GOLDS_COMMAND} ${FCOMPARE_COMMAND}") + set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 18000 PROCESSORS ${PELE_NP} WORKING_DIRECTORY "${CURRENT_TEST_BINARY_DIR}/" LABELS "regression" ATTACHED_FILES "${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.log") +endfunction(add_test_r) + # Regression test with mass conservation verification function(add_test_rv TEST_NAME TEST_EXE_DIR) setup_test() @@ -250,8 +258,8 @@ if(NOT PELE_ENABLE_EB) else() if(PELE_DIM EQUAL 2) add_test_rt(composition-test-${PELE_DIM}d EB_ODEQty) - add_test_r(eb_bfs EB_BackwardStepFlame) - add_test_r(eb_bfs_pp EB_BackwardStepFlame) + add_test_rtol(eb_bfs EB_BackwardStepFlame) + add_test_rtol(eb_bfs_pp EB_BackwardStepFlame) endif() add_test_r(eb-odeqty-${PELE_DIM}d EB_ODEQty) endif() From 27ca5d9dcbf92de2565125b2831a534a86636037 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 24 Aug 2025 16:23:11 +0200 Subject: [PATCH 72/87] couple more things --- Source/PeleLMeX_Advection.cpp | 2 +- Source/PeleLMeX_Projection.cpp | 25 +++++++++++++++---------- Source/PeleLMeX_TransportProp.cpp | 6 +++--- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index ea221f1db..cf3b25690 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -1133,7 +1133,7 @@ PeleLM::updateScalarComp( amrex::ParallelFor( ldataOld_p->state, amrex::IntVect(0), ncomp, - [state_old_ma, adv_aofs_ma, ext_ma, state_new_ma, state_comp, // ncomp, + [state_old_ma, adv_aofs_ma, ext_ma, state_new_ma, state_comp, dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { amrex::Array4 state_new_arr( diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 656a637c6..eb5396129 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -307,11 +307,11 @@ PeleLM::velocityProjection( amrex::Real SbarOld = 0.0; amrex::Real SbarNew = 0.0; if ((m_closed_chamber != 0) && (m_incompressible == 0)) { - SbarNew = MFSum(GetVecOfConstPtrs(getDivUVect(AmrNewTime)), 0); - SbarNew /= m_uncoveredVol; // Transform in Mean. + SbarNew = MFSum(GetVecOfConstPtrs(getDivUVect(AmrNewTime)), 0) / + m_uncoveredVol; // Transform in Mean. if (incremental != 0) { - SbarOld = MFSum(GetVecOfConstPtrs(getDivUVect(AmrOldTime)), 0); - SbarOld /= m_uncoveredVol; // Transform in Mean. + SbarOld = MFSum(GetVecOfConstPtrs(getDivUVect(AmrOldTime)), 0) / + m_uncoveredVol; // Transform in Mean. } } @@ -344,16 +344,21 @@ PeleLM::velocityProjection( amrex::ParallelFor( rhs_cc[lev], rhs_cc[lev].nGrowVect(), - [divu_o_ma, divu_n_ma, rhs_ma, SbarNew, SbarOld, - is_closed_chamber = - m_closed_chamber] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + [divu_o_ma, divu_n_ma, + rhs_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { rhs_ma[box_no](i, j, k) = -(divu_n_ma[box_no](i, j, k) - divu_o_ma[box_no](i, j, k)); - if (is_closed_chamber != 0) { - rhs_ma[box_no](i, j, k) += SbarNew - SbarOld; - } }); amrex::Gpu::streamSynchronize(); + if (m_closed_chamber != 0) { + amrex::ParallelFor( + rhs_cc[lev], rhs_cc[lev].nGrowVect(), + [rhs_ma, SbarNew, SbarOld] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + rhs_ma[box_no](i, j, k) += SbarNew - SbarOld; + }); + amrex::Gpu::streamSynchronize(); + } } #ifdef AMREX_USE_EB EB_set_covered(rhs_cc[lev], 0.0); diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index c30c208c1..1751c02a8 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -400,11 +400,11 @@ PeleLM::getDiffusivity( amrex::ParallelFor( ebx, [bc_lo, bc_hi, diff_ec, use_harmonic_avg, ncomp, idim, edomain, diff_c] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - bool on_lo = + const int idx[3] = {i, j, k}; + const bool on_lo = ((bc_lo == amrex::BCType::ext_dir) && (idx[idim] <= edomain.smallEnd(idim))); - bool on_hi = + const bool on_hi = ((bc_hi == amrex::BCType::ext_dir) && (idx[idim] >= edomain.bigEnd(idim))); cen2edg_cpp( From 6397b2f7c2bcc88a55c68d471d825d2f131fb295 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 24 Aug 2025 16:31:35 +0200 Subject: [PATCH 73/87] simplify --- Source/PeleLMeX_Projection.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index eb5396129..35bb163cb 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -351,13 +351,7 @@ PeleLM::velocityProjection( }); amrex::Gpu::streamSynchronize(); if (m_closed_chamber != 0) { - amrex::ParallelFor( - rhs_cc[lev], rhs_cc[lev].nGrowVect(), - [rhs_ma, SbarNew, SbarOld] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - rhs_ma[box_no](i, j, k) += SbarNew - SbarOld; - }); - amrex::Gpu::streamSynchronize(); + rhs_cc[lev].plus(SbarNew - SbarOld, 0, 1); } } #ifdef AMREX_USE_EB From 5f76f8684be39b764099f2785dbeed2ce38d6a23 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 24 Aug 2025 16:36:28 +0200 Subject: [PATCH 74/87] ngrow --- Source/PeleLMeX_Projection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 35bb163cb..7e84de1f6 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -351,7 +351,7 @@ PeleLM::velocityProjection( }); amrex::Gpu::streamSynchronize(); if (m_closed_chamber != 0) { - rhs_cc[lev].plus(SbarNew - SbarOld, 0, 1); + rhs_cc[lev].plus(SbarNew - SbarOld, 0, 1, ldataOld_p->divu.nGrow()); } } #ifdef AMREX_USE_EB From 5ddfe7c438023cc3768b8c9ed97c906a575f2e0b Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 24 Aug 2025 21:57:32 +0200 Subject: [PATCH 75/87] reaction fusing --- Source/PeleLMeX_Diffusion.cpp | 36 ++-- Source/PeleLMeX_Reactions.cpp | 309 +++++++++++++++++----------------- Source/PeleLMeX_UMac.cpp | 140 ++++++++------- 3 files changed, 253 insertions(+), 232 deletions(-) diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 799e12b3d..193915c6f 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -1328,13 +1328,11 @@ PeleLM::differentialDiffusionUpdate( auto const& state_ma = ldata_p->state.arrays(); auto const& dhat_ma = diffData->Dhat[lev].const_arrays(); auto const& force_ma = advData->Forcing[lev].const_arrays(); - - auto const& dwbar_ma = - (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dhat_ma; - auto const& dT_ma = - (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dhat_ma; auto dt = m_dt; + if (m_use_wbar != 0 && m_use_soret != 0) { + auto const& dwbar_ma = diffData->Dwbar[lev].const_arrays(); + auto const& dT_ma = diffData->DT[lev].const_arrays(); amrex::ParallelFor( ldata_p->state, amrex::IntVect(0), NUM_SPECIES, [state_ma, dhat_ma, force_ma, dwbar_ma, dT_ma, @@ -1346,6 +1344,7 @@ PeleLM::differentialDiffusionUpdate( dT_ma[box_no](i, j, k, n)); }); } else if (m_use_wbar != 0) { + auto const& dwbar_ma = diffData->Dwbar[lev].const_arrays(); amrex::ParallelFor( ldata_p->state, amrex::IntVect(0), NUM_SPECIES, [state_ma, dhat_ma, force_ma, dwbar_ma, @@ -1356,6 +1355,7 @@ PeleLM::differentialDiffusionUpdate( dt * (dhat_ma[box_no](i, j, k, n) - dwbar_ma[box_no](i, j, k, n)); }); } else if (m_use_soret != 0) { + auto const& dT_ma = diffData->DT[lev].const_arrays(); amrex::ParallelFor( ldata_p->state, amrex::IntVect(0), NUM_SPECIES, [state_ma, dhat_ma, force_ma, dT_ma, @@ -1375,20 +1375,18 @@ PeleLM::differentialDiffusionUpdate( force_ma[box_no](i, j, k, n) + dt * dhat_ma[box_no](i, j, k, n); }); } - auto const& aux_ma = - (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : state_ma; - auto const& dhat_aux_ma = - (m_nAux > 0) ? diffData->Dhat_aux[lev].const_arrays() : dhat_ma; - auto const& force_aux_ma = - (m_nAux > 0) ? advData->Forcing_aux[lev].const_arrays() : dhat_ma; - amrex::ParallelFor( - ldata_p->state, amrex::IntVect(0), m_nAux, - [aux_ma, dhat_aux_ma, force_aux_ma, - dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + - dt * dhat_aux_ma[box_no](i, j, k, n); - }); - + if (m_nAux > 0) { + auto const& aux_ma = ldata_p->auxiliaries.arrays(); + auto const& dhat_aux_ma = diffData->Dhat_aux[lev].const_arrays(); + auto const& force_aux_ma = advData->Forcing_aux[lev].const_arrays(); + amrex::ParallelFor( + ldata_p->state, amrex::IntVect(0), m_nAux, + [aux_ma, dhat_aux_ma, force_aux_ma, + dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { + aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + + dt * dhat_aux_ma[box_no](i, j, k, n); + }); + } // Shift outside? amrex::Gpu::streamSynchronize(); } diff --git a/Source/PeleLMeX_Reactions.cpp b/Source/PeleLMeX_Reactions.cpp index e6949cb05..e5d0d6c61 100644 --- a/Source/PeleLMeX_Reactions.cpp +++ b/Source/PeleLMeX_Reactions.cpp @@ -66,15 +66,19 @@ PeleLM::advanceChemistry( // Reset new to old and convert MKS -> CGS amrex::ParallelFor( - bx, [rhoY_o, rhoH_o, temp_o, rhoY_n, rhoH_n, temp_n, extF_rhoY, + bx, NUM_SPECIES, + [rhoY_o, rhoY_n, + extF_rhoY] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + rhoY_n(i, j, k, n) = m2c::Rho(rhoY_o(i, j, k, n)); + extF_rhoY(i, j, k, n) = m2c::Rho(extF_rhoY(i, j, k, n)); + ; + }); + amrex::ParallelFor( + bx, [temp_n, temp_o, rhoH_n, rhoH_o, extF_rhoH] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY_n(i, j, k, n) = rhoY_o(i, j, k, n) * 1.0e-3; - extF_rhoY(i, j, k, n) *= 1.0e-3; - } temp_n(i, j, k) = temp_o(i, j, k); - rhoH_n(i, j, k) = rhoH_o(i, j, k) * 10.0; - extF_rhoH(i, j, k) *= 10.0; + rhoH_n(i, j, k) = m2c::RhoH(rhoH_o(i, j, k)); + extF_rhoH(i, j, k) = m2c::RhoH(extF_rhoH(i, j, k)); }); #ifdef PELE_USE_PLASMA @@ -108,16 +112,17 @@ PeleLM::advanceChemistry( // Convert CGS -> MKS amrex::ParallelFor( - bx, [rhoY_n, rhoH_n, extF_rhoY, - extF_rhoH] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY_n(i, j, k, n) *= 1.0e3; - extF_rhoY(i, j, k, n) *= 1.0e3; - } - rhoH_n(i, j, k) *= 0.1; - extF_rhoH(i, j, k) *= 0.1; + bx, NUM_SPECIES, + [rhoY_n, + extF_rhoY] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + rhoY_n(i, j, k, n) = c2m::Rho(rhoY_n(i, j, k, n)); // 1.0e3; + extF_rhoY(i, j, k, n) = c2m::Rho(extF_rhoY(i, j, k, n)); // 1.0e3; + }); + amrex::ParallelFor( + bx, [rhoH_n, extF_rhoH] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + rhoH_n(i, j, k) = c2m::RhoH(rhoH_n(i, j, k)); + extF_rhoH(i, j, k) = c2m::RhoH(extF_rhoH(i, j, k)); }); - #ifdef PELE_USE_PLASMA // rhoY_e -> nE and set rhoY_e to zero auto const& nE_n = ldataNew_p->state.array(mfi, NE); @@ -138,39 +143,35 @@ PeleLM::advanceChemistry( } // Set reaction term -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(ldataNew_p->state, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& rhoY_o = ldataOld_p->state.const_array(mfi, FIRSTSPEC); - auto const& rhoY_n = ldataNew_p->state.const_array(mfi, FIRSTSPEC); - auto const& extF_rhoY = a_extForcing.const_array(mfi, 0); - auto const& rhoYdot = ldataR_p->I_R.array(mfi, 0); - amrex::Real dt_inv = 1.0 / a_dt; - amrex::ParallelFor( - bx, NUM_SPECIES, - [rhoYdot, rhoY_o, rhoY_n, dt_inv, - extF_rhoY] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - rhoYdot(i, j, k, n) = - -(rhoY_o(i, j, k, n) - rhoY_n(i, j, k, n)) * dt_inv - - extF_rhoY(i, j, k, n); - }); + auto const& state_o_ma = ldataOld_p->state.const_arrays(); + auto const& state_n_ma = ldataNew_p->state.const_arrays(); + auto const& extF_ma = a_extForcing.const_arrays(); + auto const& rhoYdot_ma = ldataR_p->I_R.arrays(); + const amrex::Real dt_inv = 1.0 / a_dt; + amrex::ParallelFor( + ldataNew_p->state, amrex::IntVect(0), NUM_SPECIES, + [state_o_ma, state_n_ma, extF_ma, rhoYdot_ma, + dt_inv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { + amrex::Array4 rhoY_o(state_o_ma[box_no], FIRSTSPEC); + amrex::Array4 rhoY_n(state_n_ma[box_no], FIRSTSPEC); + rhoYdot_ma[box_no](i, j, k, n) = + -(rhoY_o(i, j, k, n) - rhoY_n(i, j, k, n)) * dt_inv - + extF_ma[box_no](i, j, k, n); + }); #ifdef PELE_USE_PLASMA - auto const& nE_o = ldataOld_p->state.const_array(mfi, NE); - auto const& nE_n = ldataNew_p->state.const_array(mfi, NE); - auto const& FnE = a_extForcing.const_array(mfi, NUM_SPECIES + 1); - auto const& nEdot = ldataR_p->I_R.array(mfi, NUM_SPECIES); - amrex::ParallelFor( - bx, [nEdot, nE_o, nE_n, dt_inv, - FnE] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - nEdot(i, j, k) = - -(nE_o(i, j, k) - nE_n(i, j, k)) * dt_inv - FnE(i, j, k); - }); + amrex::ParallelFor( + ldataNew_p->state, + [state_n_ma, state_o_ma, extF_ma, rhoYdot_ma, + dt_inv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 nE_o(state_o_ma[box_no], NE); + amrex::Array4 nE_n(state_n_ma[box_no], NE); + amrex::Array4 FnE(extF_ma[box_no], NUM_SPECIES + 1); + amrex::Array4 nEdot(rhoYdot_ma[box_no], NUM_SPECIES); + nEdot(i, j, k) = -(nE_o(i, j, k) - nE_n(i, j, k)) * dt_inv - FnE(i, j, k); + }); #endif - } + amrex::Gpu::streamSynchronize(); } // This advanceChemistry works with BoxArrays built such that each box @@ -230,16 +231,18 @@ PeleLM::advanceChemistryBAChem( // Convert MKS -> CGS amrex::ParallelFor( - bx, [rhoY_o, rhoH_o, extF_rhoY, - extF_rhoH] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY_o(i, j, k, n) *= 1.0e-3; - extF_rhoY(i, j, k, n) *= 1.0e-3; - } - rhoH_o(i, j, k) *= 10.0; - extF_rhoH(i, j, k) *= 10.0; + bx, NUM_SPECIES, + [rhoY_o, + extF_rhoY] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + rhoY_o(i, j, k, n) = m2c::Rho(rhoY_o(i, j, k, n)); + extF_rhoY(i, j, k, n) = m2c::Rho(extF_rhoY(i, j, k, n)); + ; + }); + amrex::ParallelFor( + bx, [rhoH_o, extF_rhoH] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + rhoH_o(i, j, k) = m2c::RhoH(rhoH_o(i, j, k)); + extF_rhoH(i, j, k) = m2c::RhoH(extF_rhoH(i, j, k)); }); - #ifdef PELE_USE_PLASMA // Pass nE -> rhoY_e & FnE -> FrhoY_e auto const& nE_o = chemnE.array(mfi); @@ -258,7 +261,7 @@ PeleLM::advanceChemistryBAChem( #endif // Do reaction only on uncovered box - int do_reactionBox = m_baChemFlag[lev][mfi.index()]; + const int do_reactionBox = m_baChemFlag[lev][mfi.index()]; if (do_reactionBox != 0) { // Do reaction as usual using PelePhysics chemistry integrator @@ -283,13 +286,14 @@ PeleLM::advanceChemistryBAChem( // Convert CGS -> MKS amrex::ParallelFor( - bx, [rhoY_o, rhoH_o] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY_o(i, j, k, n) *= 1.0e3; - } - rhoH_o(i, j, k) *= 0.1; + bx, NUM_SPECIES, + [rhoY_o] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + rhoY_o(i, j, k, n) = c2m::Rho(rhoY_o(i, j, k, n)); + }); + amrex::ParallelFor( + bx, [rhoH_o] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + rhoH_o(i, j, k) = c2m::RhoH(rhoH_o(i, j, k)); }); - #ifdef PELE_USE_PLASMA // rhoY_e -> nE and set rhoY_e to zero amrex::Real invmwt[NUM_SPECIES] = {0.0}; @@ -315,57 +319,51 @@ PeleLM::advanceChemistryBAChem( #ifdef PELE_USE_PLASMA amrex::MultiFab nETemp(grids[lev], dmap[lev], 1, 0); nETemp.ParallelCopy(chemnE, 0, 0, 1); + auto const& nE_tmp_ma = nETemp.const_arrays(); #endif // Pass from temp state MF to leveldata and set reaction term -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) + auto const& state_tmp_ma = StateTemp.const_arrays(); + auto const& state_o_ma = ldataOld_p->state.const_arrays(); + auto const& state_n_ma = ldataNew_p->state.arrays(); + auto const& extF_ma = a_extForcing.const_arrays(); + auto const& rhoYdot_ma = ldataR_p->I_R.arrays(); + const amrex::Real dt_inv = 1.0 / a_dt; + + amrex::ParallelFor( + ldataNew_p->state, amrex::IntVect(0), NUM_SPECIES, + [state_tmp_ma, state_n_ma, state_o_ma, extF_ma, rhoYdot_ma, + dt_inv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { + amrex::Array4 rhoY_o(state_o_ma[box_no], FIRSTSPEC); + amrex::Array4 rhoY_n(state_n_ma[box_no], FIRSTSPEC); + rhoY_n(i, j, k, n) = state_tmp_ma[box_no](i, j, k, n); + rhoYdot_ma[box_no](i, j, k, n) = + -(rhoY_o(i, j, k, n) - rhoY_n(i, j, k, n)) * dt_inv - + extF_ma[box_no](i, j, k, n); + }); + amrex::ParallelFor( + ldataNew_p->state, [state_tmp_ma, state_n_ma +#ifdef PELE_USE_PLASMA + , + state_o_ma, extF_ma, rhoYdot_ma, nE_tmp_ma, dt_inv #endif - for (amrex::MFIter mfi(ldataNew_p->state, amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& state_arr = StateTemp.const_array(mfi); - auto const& rhoY_o = ldataOld_p->state.const_array(mfi, FIRSTSPEC); - auto const& rhoY_n = ldataNew_p->state.array(mfi, FIRSTSPEC); - auto const& rhoH_n = ldataNew_p->state.array(mfi, RHOH); - auto const& temp_n = ldataNew_p->state.array(mfi, TEMP); - auto const& extF_rhoY = a_extForcing.const_array(mfi, 0); - auto const& rhoYdot = ldataR_p->I_R.array(mfi, 0); - amrex::Real dt_inv = 1.0 / a_dt; - amrex::ParallelFor( - bx, [state_arr, rhoY_o, rhoY_n, rhoH_n, temp_n, extF_rhoY, rhoYdot, - dt_inv] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - // Pass into leveldata_new - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY_n(i, j, k, n) = state_arr(i, j, k, n); - } - rhoH_n(i, j, k) = state_arr(i, j, k, NUM_SPECIES); - temp_n(i, j, k) = state_arr(i, j, k, NUM_SPECIES + 1); - // Compute I_R - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoYdot(i, j, k, n) = - -(rhoY_o(i, j, k, n) - rhoY_n(i, j, k, n)) * dt_inv - - extF_rhoY(i, j, k, n); - } - }); - + ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 rhoH_n(state_n_ma[box_no], RHOH); + amrex::Array4 temp_n(state_n_ma[box_no], TEMP); + rhoH_n(i, j, k) = state_tmp_ma[box_no](i, j, k, NUM_SPECIES); + temp_n(i, j, k) = state_tmp_ma[box_no](i, j, k, NUM_SPECIES + 1); #ifdef PELE_USE_PLASMA - auto const& nE_arr = nETemp.const_array(mfi); - auto const& nE_o = ldataOld_p->state.const_array(mfi, NE); - auto const& nE_n = ldataNew_p->state.array(mfi, NE); - auto const& FnE = a_extForcing.const_array(mfi, NUM_SPECIES + 1); - auto const& nEdot = ldataR_p->I_R.array(mfi, NUM_SPECIES); - amrex::ParallelFor( - bx, [nE_n, nE_arr, nEdot, nE_o, dt_inv, - FnE] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - // Pass into leveldata_new - nE_n(i, j, k) = nE_arr(i, j, k); - // Compute I_R - nEdot(i, j, k) = - -(nE_o(i, j, k) - nE_n(i, j, k)) * dt_inv - FnE(i, j, k); - }); + amrex::Array4 nE_n(state_n_ma[box_no], NE); + amrex::Array4 nE_o(state_o_ma[box_no], NE); + amrex::Array4 FnE(extF_ma[box_no], NUM_SPECIES + 1); + amrex::Array4 nEdot(rhoYdot_ma[box_no], NUM_SPECIES); + // Pass into leveldata_new + nE_n(i, j, k) = nE_tmp_ma[box_no](i, j, k); + // Compute I_R + nEdot(i, j, k) = -(nE_o(i, j, k) - nE_n(i, j, k)) * dt_inv - FnE(i, j, k); #endif - } + }); + amrex::Gpu::streamSynchronize(); } void @@ -451,31 +449,32 @@ PeleLM::getScalarReactForce(const std::unique_ptr& advData) auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); auto* ldataR_p = getLevelDataReactPtr(lev); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - for (amrex::MFIter mfi(advData->Forcing[lev], amrex::TilingIfNotGPU()); - mfi.isValid(); ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - auto const& rhoY_o = ldataOld_p->state.const_array(mfi, FIRSTSPEC); - auto const& rhoH_o = ldataOld_p->state.const_array(mfi, RHOH); - auto const& rhoY_n = ldataNew_p->state.const_array(mfi, FIRSTSPEC); - auto const& rhoH_n = ldataNew_p->state.const_array(mfi, RHOH); - auto const& react = ldataR_p->I_R.const_array(mfi, 0); - auto const& extF_rhoY = advData->Forcing[lev].array(mfi, 0); - auto const& extF_rhoH = advData->Forcing[lev].array(mfi, NUM_SPECIES); - amrex::Real dtinv = 1.0 / m_dt; - amrex::ParallelFor( - bx, [rhoY_o, rhoH_o, rhoY_n, rhoH_n, react, extF_rhoY, extF_rhoH, - dtinv] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - for (int n = 0; n < NUM_SPECIES; ++n) { - extF_rhoY(i, j, k, n) = - (rhoY_n(i, j, k, n) - rhoY_o(i, j, k, n)) * dtinv - - react(i, j, k, n); - } - extF_rhoH(i, j, k) = (rhoH_n(i, j, k) - rhoH_o(i, j, k)) * dtinv; - }); - } + auto const& state_o_ma = ldataOld_p->state.const_arrays(); + auto const& state_n_ma = ldataNew_p->state.const_arrays(); + auto const& react_ma = ldataR_p->I_R.const_arrays(); + auto const& extF_ma = advData->Forcing[lev].arrays(); + const amrex::Real dtinv = 1.0 / m_dt; + + amrex::ParallelFor( + advData->Forcing[lev], amrex::IntVect(0), NUM_SPECIES, + [state_o_ma, state_n_ma, extF_ma, react_ma, dtinv] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { + amrex::Array4 rhoY_n(state_n_ma[box_no], FIRSTSPEC); + amrex::Array4 rhoY_o(state_o_ma[box_no], FIRSTSPEC); + extF_ma[box_no](i, j, k, n) = + (rhoY_n(i, j, k, n) - rhoY_o(i, j, k, n)) * dtinv - + react_ma[box_no](i, j, k, n); + }); + amrex::ParallelFor( + advData->Forcing[lev], + [state_o_ma, state_n_ma, extF_ma, + dtinv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + amrex::Array4 extF_rhoH(extF_ma[box_no], RHOH); + amrex::Array4 rhoH_n(state_o_ma[box_no], RHOH); + amrex::Array4 rhoH_o(state_o_ma[box_no], RHOH); + extF_rhoH(i, j, k) = (rhoH_n(i, j, k) - rhoH_o(i, j, k)) * dtinv; + }); + amrex::Gpu::streamSynchronize(); } } @@ -484,29 +483,27 @@ PeleLM::getHeatRelease(const int a_lev, amrex::MultiFab* a_HR) { auto* ldataNew_p = getLevelDataPtr(a_lev, AmrNewTime); auto* ldataR_p = getLevelDataReactPtr(a_lev); - auto const* leosparm = eos_parms.device_parm(); -#ifdef AMREX_USE_OMP -#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) -#endif - { - for (amrex::MFIter mfi(*a_HR, amrex::TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const amrex::Box& bx = mfi.tilebox(); - amrex::FArrayBox EnthFab(bx, NUM_SPECIES, amrex::The_Async_Arena()); - auto const& react = ldataR_p->I_R.const_array(mfi, 0); - auto const& T = ldataNew_p->state.const_array(mfi, TEMP); - auto const& Hi = EnthFab.array(); - auto const& HRR = a_HR->array(mfi); - amrex::ParallelFor( - bx, [T, Hi, leosparm, HRR, - react] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - getHGivenT(i, j, k, T, Hi, leosparm); - HRR(i, j, k) = 0.0; - for (int n = 0; n < NUM_SPECIES; ++n) { - HRR(i, j, k) -= Hi(i, j, k, n) * react(i, j, k, n); - } - }); - } - } + auto const* leosparm = eos_parms.device_parm(); + auto const& react_ma = ldataR_p->I_R.const_arrays(); + auto const& state_n_ma = ldataNew_p->state.const_arrays(); + amrex::MultiFab Enth(grids[a_lev], dmap[a_lev], NUM_SPECIES, 0); + auto const& enth_ma = Enth.arrays(); + amrex::ParallelFor( + *a_HR, [react_ma, state_n_ma, enth_ma, leosparm] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + amrex::Array4 T(state_n_ma[box_no], TEMP); + getHGivenT(i, j, k, T, enth_ma[box_no], leosparm); + }); + amrex::Gpu::streamSynchronize(); + a_HR->setVal(0.0); + auto const& HRR_ma = a_HR->arrays(); + amrex::ParallelFor( + *a_HR, amrex::IntVect(0), NUM_SPECIES, + [react_ma, HRR_ma, enth_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k, int n) noexcept { + HRR_ma[box_no](i, j, k) -= + enth_ma[box_no](i, j, k, n) * react_ma[box_no](i, j, k, n); + }); + amrex::Gpu::streamSynchronize(); } diff --git a/Source/PeleLMeX_UMac.cpp b/Source/PeleLMeX_UMac.cpp index a1339bb31..88e9bf5fa 100644 --- a/Source/PeleLMeX_UMac.cpp +++ b/Source/PeleLMeX_UMac.cpp @@ -108,71 +108,97 @@ PeleLM::addChiIncrement( // Add chiIncr to chi and add chi to mac_divu // Both mac_divu and chiIncr have properly filled ghost cells -> work on // grownbox - switch (m_chi_correction_type) { - case ChiCorrectionType::DivuFirstIter: { - for (int lev = 0; lev <= finest_level; ++lev) { - auto const& chiInc_ma = chiIncr[lev].const_arrays(); - auto const& chi_ma = advData->chi[lev].arrays(); - auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); - amrex::ParallelFor( - advData->chi[lev], advData->chi[lev].nGrowVect(), - [chi_ma, chiInc_ma, mac_divu_ma, - a_sdcIter] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - if (a_sdcIter == 1) { + + if (a_sdcIter == 1) { + switch (m_chi_correction_type) { + case ChiCorrectionType::DivuFirstIter: { + for (int lev = 0; lev <= finest_level; ++lev) { + auto const& chiInc_ma = chiIncr[lev].const_arrays(); + auto const& chi_ma = advData->chi[lev].arrays(); + auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); + amrex::ParallelFor( + advData->chi[lev], advData->chi[lev].nGrowVect(), + [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { chi_ma[box_no](i, j, k) = chiInc_ma[box_no](i, j, k) + mac_divu_ma[box_no](i, j, k); - } else { - chi_ma[box_no](i, j, k) += chiInc_ma[box_no](i, j, k); - } - mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); + mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); + }); + // Shift outside? + amrex::Gpu::streamSynchronize(); + } + break; } - break; - } - case ChiCorrectionType::NoDivu: { - for (int lev = 0; lev <= finest_level; ++lev) { - auto const& chiInc_ma = chiIncr[lev].const_arrays(); - auto const& chi_ma = advData->chi[lev].arrays(); - auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); - amrex::ParallelFor( - advData->chi[lev], advData->chi[lev].nGrowVect(), - [chi_ma, chiInc_ma, mac_divu_ma, - a_sdcIter] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - if (a_sdcIter == 1) { + case ChiCorrectionType::NoDivu: { + for (int lev = 0; lev <= finest_level; ++lev) { + auto const& chiInc_ma = chiIncr[lev].const_arrays(); + auto const& chi_ma = advData->chi[lev].arrays(); + auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); + amrex::ParallelFor( + advData->chi[lev], advData->chi[lev].nGrowVect(), + [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { chi_ma[box_no](i, j, k) = chiInc_ma[box_no](i, j, k); - } else { - chi_ma[box_no](i, j, k) += chiInc_ma[box_no](i, j, k); - } - mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); + mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); + }); + // Shift outside? + amrex::Gpu::streamSynchronize(); + } + break; } - break; - } - default: { - for (int lev = 0; lev <= finest_level; ++lev) { - auto const& chiInc_ma = chiIncr[lev].const_arrays(); - auto const& chi_ma = advData->chi[lev].arrays(); - auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); - amrex::ParallelFor( - advData->chi[lev], advData->chi[lev].nGrowVect(), - [chi_ma, chiInc_ma, mac_divu_ma, - a_sdcIter] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - if (a_sdcIter == 1) { + default: { + for (int lev = 0; lev <= finest_level; ++lev) { + auto const& chiInc_ma = chiIncr[lev].const_arrays(); + auto const& chi_ma = advData->chi[lev].arrays(); + auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); + amrex::ParallelFor( + advData->chi[lev], advData->chi[lev].nGrowVect(), + [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { chi_ma[box_no](i, j, k) = chiInc_ma[box_no](i, j, k); - } else { + mac_divu_ma[box_no](i, j, k) += chi_ma[box_no](i, j, k); + }); + // Shift outside? + amrex::Gpu::streamSynchronize(); + } + } + } + } else { + if ( + m_chi_correction_type == ChiCorrectionType::DivuFirstIter || + m_chi_correction_type == ChiCorrectionType::NoDivu) { + for (int lev = 0; lev <= finest_level; ++lev) { + auto const& chiInc_ma = chiIncr[lev].const_arrays(); + auto const& chi_ma = advData->chi[lev].arrays(); + auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); + amrex::ParallelFor( + advData->chi[lev], advData->chi[lev].nGrowVect(), + [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { + chi_ma[box_no](i, j, k) += chiInc_ma[box_no](i, j, k); + mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); + }); + // Shift outside? + amrex::Gpu::streamSynchronize(); + } + } else { + for (int lev = 0; lev <= finest_level; ++lev) { + auto const& chiInc_ma = chiIncr[lev].const_arrays(); + auto const& chi_ma = advData->chi[lev].arrays(); + auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); + amrex::ParallelFor( + advData->chi[lev], advData->chi[lev].nGrowVect(), + [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( + int box_no, int i, int j, int k) noexcept { chi_ma[box_no](i, j, k) += chiInc_ma[box_no](i, j, k); - } - mac_divu_ma[box_no](i, j, k) += chi_ma[box_no](i, j, k); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); + mac_divu_ma[box_no](i, j, k) += chi_ma[box_no](i, j, k); + }); + // Shift outside? + amrex::Gpu::streamSynchronize(); + } } } - } + if (m_print_chi_convergence) { const amrex::Real max_corr = MLNorm0(GetVecOfConstPtrs(chiIncr)) * m_dt / m_dpdtFactor; @@ -321,7 +347,7 @@ PeleLM::create_constrained_umac_grown( // Use piecewise constant interpolation in time, so create dummy variable for // time - amrex::Real dummy = 0.; + constexpr amrex::Real dummy = 0.; FillPatchTwoLevels( u_mac_fine, amrex::IntVect(a_nGrow), dummy, {u_mac_crse}, {dummy}, {u_mac_fine}, {dummy}, 0, 0, 1, *crse_geom, *fine_geom, cbndyFuncArr, 0, From 99298e533920f27a5db4c43d87fcac688bcaade7 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 24 Aug 2025 22:09:21 +0200 Subject: [PATCH 76/87] fixes --- Source/PeleLMeX_Reactions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/PeleLMeX_Reactions.cpp b/Source/PeleLMeX_Reactions.cpp index e5d0d6c61..fd7e90f5f 100644 --- a/Source/PeleLMeX_Reactions.cpp +++ b/Source/PeleLMeX_Reactions.cpp @@ -469,8 +469,8 @@ PeleLM::getScalarReactForce(const std::unique_ptr& advData) advData->Forcing[lev], [state_o_ma, state_n_ma, extF_ma, dtinv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 extF_rhoH(extF_ma[box_no], RHOH); - amrex::Array4 rhoH_n(state_o_ma[box_no], RHOH); + amrex::Array4 extF_rhoH(extF_ma[box_no], NUM_SPECIES); + amrex::Array4 rhoH_n(state_n_ma[box_no], RHOH); amrex::Array4 rhoH_o(state_o_ma[box_no], RHOH); extF_rhoH(i, j, k) = (rhoH_n(i, j, k) - rhoH_o(i, j, k)) * dtinv; }); From 5e8252fb833e96b034b21a07df3f1446a46195e1 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Sun, 24 Aug 2025 22:11:15 +0200 Subject: [PATCH 77/87] unnecessary capture --- Source/PeleLMeX_Reactions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/PeleLMeX_Reactions.cpp b/Source/PeleLMeX_Reactions.cpp index fd7e90f5f..c4c67aac9 100644 --- a/Source/PeleLMeX_Reactions.cpp +++ b/Source/PeleLMeX_Reactions.cpp @@ -490,7 +490,7 @@ PeleLM::getHeatRelease(const int a_lev, amrex::MultiFab* a_HR) amrex::MultiFab Enth(grids[a_lev], dmap[a_lev], NUM_SPECIES, 0); auto const& enth_ma = Enth.arrays(); amrex::ParallelFor( - *a_HR, [react_ma, state_n_ma, enth_ma, leosparm] AMREX_GPU_DEVICE( + *a_HR, [state_n_ma, enth_ma, leosparm] AMREX_GPU_DEVICE( int box_no, int i, int j, int k) noexcept { amrex::Array4 T(state_n_ma[box_no], TEMP); getHGivenT(i, j, k, T, enth_ma[box_no], leosparm); From 74ee9173539031dafe3c9e7819bd1759bbd2cd63 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Tue, 26 Aug 2025 19:39:11 +0200 Subject: [PATCH 78/87] bump pelephysics --- Source/PeleLMeX_Reactions.cpp | 4 ++-- Submodules/PelePhysics | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/PeleLMeX_Reactions.cpp b/Source/PeleLMeX_Reactions.cpp index c4c67aac9..1e4944e2b 100644 --- a/Source/PeleLMeX_Reactions.cpp +++ b/Source/PeleLMeX_Reactions.cpp @@ -115,8 +115,8 @@ PeleLM::advanceChemistry( bx, NUM_SPECIES, [rhoY_n, extF_rhoY] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { - rhoY_n(i, j, k, n) = c2m::Rho(rhoY_n(i, j, k, n)); // 1.0e3; - extF_rhoY(i, j, k, n) = c2m::Rho(extF_rhoY(i, j, k, n)); // 1.0e3; + rhoY_n(i, j, k, n) = c2m::Rho(rhoY_n(i, j, k, n)); + extF_rhoY(i, j, k, n) = c2m::Rho(extF_rhoY(i, j, k, n)); }); amrex::ParallelFor( bx, [rhoH_n, extF_rhoH] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { diff --git a/Submodules/PelePhysics b/Submodules/PelePhysics index 2dbdf201c..f6ebe5ef9 160000 --- a/Submodules/PelePhysics +++ b/Submodules/PelePhysics @@ -1 +1 @@ -Subproject commit 2dbdf201c20bc6bd91738daf2b28a69f41609e7b +Subproject commit f6ebe5ef904c7a81e297b8d348e27fbb661003cc From e125bc5674f39739038f9fc0050c346e45c64ef5 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 5 Sep 2025 15:06:57 +0100 Subject: [PATCH 79/87] undo fusing --- Source/PeleLMeX_Advection.cpp | 147 +++--- Source/PeleLMeX_Diffusion.cpp | 405 ++++++++-------- Source/PeleLMeX_DiffusionOp.cpp | 268 ++++++----- Source/PeleLMeX_Forces.cpp | 618 ++++++++++++------------- Source/PeleLMeX_Init.cpp | 65 +-- Source/PeleLMeX_Plot.cpp | 102 ++-- Source/PeleLMeX_Projection.cpp | 188 ++++---- Source/PeleLMeX_Reactions.cpp | 216 ++++----- Source/PeleLMeX_Soot.cpp | 36 +- Source/PeleLMeX_Timestep.cpp | 35 +- Source/PeleLMeX_UMac.cpp | 115 ++--- Source/Plasma/PeleLMeX_EFIonDrift.cpp | 61 +-- Source/Plasma/PeleLMeX_EFNLSolve.cpp | 251 +++++----- Source/Plasma/PeleLMeX_EFPoisson.cpp | 30 +- Source/Plasma/PeleLMeX_EFReactions.cpp | 26 +- Source/Plasma/PeleLMeX_EFTimeStep.cpp | 145 +++--- Source/Plasma/PeleLMeX_EFTransport.cpp | 40 +- Source/Plasma/PeleLMeX_EFUtils.cpp | 62 +-- 18 files changed, 1429 insertions(+), 1381 deletions(-) diff --git a/Source/PeleLMeX_Advection.cpp b/Source/PeleLMeX_Advection.cpp index cf3b25690..b04177c79 100644 --- a/Source/PeleLMeX_Advection.cpp +++ b/Source/PeleLMeX_Advection.cpp @@ -242,22 +242,26 @@ PeleLM::updateVelocity(const std::unique_ptr& advData) // Compute provisional new velocity // velForce holds: 1/\rho^{n+1/2} [(gravity+...)^{n+1/2} - \nabla pi^{n} + // 0.5 * divTau^{n}] - auto const& state_old_ma = ldataOld_p->state.const_arrays(); - auto const& adv_aofs_ma = advData->AofS[lev].const_arrays(); - auto const& force_ma = velForces[lev].const_arrays(); - auto const& state_new_ma = ldataNew_p->state.arrays(); - amrex::ParallelFor( - ldataOld_p->state, amrex::IntVect(0), AMREX_SPACEDIM, - [state_old_ma, adv_aofs_ma, force_ma, state_new_ma, - dt_loc = - m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - state_new_ma[box_no](i, j, k, VELX + n) = - state_old_ma[box_no](i, j, k, VELX + n) + - dt_loc * (adv_aofs_ma[box_no](i, j, k, VELX + n) + - force_ma[box_no](i, j, k, n)); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldataOld_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + + amrex::Box const& bx = mfi.tilebox(); + auto const& vel_old = ldataOld_p->state.const_array(mfi, VELX); + auto const& vel_aofs = advData->AofS[lev].const_array(mfi, VELX); + auto const& force = velForces[lev].const_array(mfi); + auto const& vel_new = ldataNew_p->state.array(mfi, VELX); + const amrex::Real dt_loc = m_dt; + amrex::ParallelFor( + bx, AMREX_SPACEDIM, + [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + vel_new(i, j, k, n) = + vel_old(i, j, k, n) + + dt_loc * (vel_aofs(i, j, k, n) + force(i, j, k, n)); + }); + } } } @@ -275,44 +279,40 @@ PeleLM::getScalarAdvForce( // Get t^{n} data pointer auto* ldata_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataR_p = getLevelDataReactPtr(lev); - - auto const& state_ma = ldata_p->state.const_arrays(); - auto const& dn_ma = diffData->Dn[lev].const_arrays(); - auto const& adv_ma = advData->Forcing[lev].arrays(); - auto const& r_ma = ldataR_p->I_R.const_arrays(); - auto const& ext_ma = m_extSource[lev]->arrays(); - - auto const& dn_aux_ma = - (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : dn_ma; - auto const& adv_aux_ma = - (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : adv_ma; - - amrex::ParallelFor( - advData->Forcing[lev], - [state_ma, dn_ma, dn_aux_ma, r_ma, ext_ma, adv_ma, adv_aux_ma, - aux_diffuse_d, leosparm, nAux = m_nAux, dp0dt = m_dp0dt, - is_closed_ch = m_closed_chamber, - do_react = - m_do_react] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rho(state_ma[box_no], DENSITY); - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - amrex::Array4 T(state_ma[box_no], TEMP); - amrex::Array4 dn(dn_ma[box_no], 0); - amrex::Array4 ddn(dn_ma[box_no], NUM_SPECIES + 1); - amrex::Array4 dn_aux(dn_aux_ma[box_no], 0); - amrex::Array4 r(r_ma[box_no], 0); - amrex::Array4 extRhoY(ext_ma[box_no], FIRSTSPEC); - amrex::Array4 extRhoH(ext_ma[box_no], RHOH); - amrex::Array4 fY(adv_ma[box_no], 0); - amrex::Array4 fT(adv_ma[box_no], NUM_SPECIES); - amrex::Array4 fAux(adv_aux_ma[box_no], 0); - buildAdvectionForcing( - i, j, k, rho, rhoY, T, dn, ddn, r, extRhoY, extRhoH, dp0dt, - is_closed_ch, do_react, fY, fT, fAux, dn_aux, aux_diffuse_d, nAux, - leosparm); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(advData->Forcing[lev], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + amrex::FArrayBox DummyFab(bx, 1); + auto const& rho = ldata_p->state.const_array(mfi, DENSITY); + auto const& rhoY = ldata_p->state.const_array(mfi, FIRSTSPEC); + auto const& T = ldata_p->state.const_array(mfi, TEMP); + auto const& dn = diffData->Dn[lev].const_array(mfi, 0); + auto const& ddn = diffData->Dn[lev].const_array(mfi, NUM_SPECIES + 1); + auto const& r = ldataR_p->I_R.const_array(mfi); + auto const& extRhoY = m_extSource[lev]->const_array(mfi, FIRSTSPEC); + auto const& extRhoH = m_extSource[lev]->const_array(mfi, RHOH); + auto const& fY = advData->Forcing[lev].array(mfi, 0); + auto const& fT = advData->Forcing[lev].array(mfi, NUM_SPECIES); + auto const& fAux = (m_nAux > 0) ? advData->Forcing_aux[lev].array(mfi, 0) + : DummyFab.array(); + auto const& dn_aux = (m_nAux > 0) + ? diffData->Dn_aux[lev].const_array(mfi, 0) + : DummyFab.const_array(); + const auto nAux = m_nAux; + const auto dp0dt = m_dp0dt; + const auto is_closed_ch = m_closed_chamber; + const auto do_react = m_do_react; + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + buildAdvectionForcing( + i, j, k, rho, rhoY, T, dn, ddn, r, extRhoY, extRhoH, dp0dt, + is_closed_ch, do_react, fY, fT, fAux, dn_aux, aux_diffuse_d, nAux, + leosparm); + }); + } } // Fill forcing ghost cells if (advData->Forcing[0].nGrow() > 0) { @@ -1126,28 +1126,23 @@ PeleLM::updateScalarComp( auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - auto const& state_old_ma = ldataOld_p->state.const_arrays(); - auto const& adv_aofs_ma = advData->AofS[lev].const_arrays(); - auto const& ext_ma = m_extSource[lev]->const_arrays(); - auto const& state_new_ma = ldataNew_p->state.arrays(); - - amrex::ParallelFor( - ldataOld_p->state, amrex::IntVect(0), ncomp, - [state_old_ma, adv_aofs_ma, ext_ma, state_new_ma, state_comp, - dt = - m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 state_new_arr( - state_new_ma[box_no], state_comp); - amrex::Array4 state_old_arr( - state_old_ma[box_no], state_comp); - amrex::Array4 adv_aofs_arr( - adv_aofs_ma[box_no], state_comp); - amrex::Array4 ext_arr(ext_ma[box_no], state_comp); - state_new_arr(i, j, k, n) = - state_old_arr(i, j, k, n) + - dt * (adv_aofs_arr(i, j, k, n) + ext_arr(i, j, k, n)); - }); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldataNew_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + amrex::Box const& bx = mfi.tilebox(); + auto const& old_arr = ldataOld_p->state.const_array(mfi, state_comp); + auto const& new_arr = ldataNew_p->state.array(mfi, state_comp); + auto const& a_of_s = advData->AofS[lev].const_array(mfi, state_comp); + auto const& ext = m_extSource[lev]->const_array(mfi, state_comp); + const auto dt = m_dt; + amrex::ParallelFor( + bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + new_arr(i, j, k, n) = + old_arr(i, j, k, n) + dt * (a_of_s(i, j, k, n) + ext(i, j, k, n)); + }); + } } - amrex::Gpu::streamSynchronize(); averageDown(AmrNewTime, state_comp, ncomp); } diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 193915c6f..4bd629687 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -693,51 +693,49 @@ PeleLM::addWbarTerm( grids[lev], dmap[lev], 1, nGrow, amrex::MFInfo(), Factory(lev)); } const amrex::Box& domain = geom[lev].Domain(); - - auto const& rho_ma = a_rho[lev]->const_arrays(); - auto const& rhoY_ma = a_spec[lev]->const_arrays(); - auto const& Wbar_ma = Wbar[lev].arrays(); - auto const& gradY_ma = - (have_boundary != 0) ? a_boundary[lev]->const_arrays() : rhoY_ma; - auto const& Wbar_boundary_ma = - (have_boundary != 0) ? Wbar_boundary[lev].arrays() : Wbar_ma; - - amrex::ParallelFor( - Wbar[lev], Wbar[lev].nGrowVect(), - [rho_ma, rhoY_ma, Wbar_ma, gradY_ma, Wbar_boundary_ma, have_boundary, - leosparm, domain, - phys_bc = - m_phys_bc] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - getMwmixGivenRY( - i, j, k, rho_ma[box_no], rhoY_ma[box_no], Wbar_ma[box_no], leosparm); - if (have_boundary != 0) { // need to impose gradWbar on boundary for - // computeGradient - // for dirichlet boundaries, we'll overwrite inhomog neumann ones - // NOTE: for now, this is skipped since wbar disabled for - // isothermal/soret - Wbar_boundary_ma[box_no](i, j, k) = Wbar_ma[box_no](i, j, k); - const int idx[3] = {i, j, k}; - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - const auto bc_lo = phys_bc.lo(idim); - const auto bc_hi = phys_bc.hi(idim); - const bool on_lo = - (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || - bc_lo == BoundaryCondition::BCSlipWallIsotherm) && - (idx[idim] < domain.smallEnd(idim)); - const bool on_hi = - (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || - bc_hi == BoundaryCondition::BCSlipWallIsotherm) && - (idx[idim] > domain.bigEnd(idim)); - - if (on_lo || on_hi) { - getGradMwmixGivengradYMwmix( - i, j, k, gradY_ma[box_no], Wbar_ma[box_no], - Wbar_boundary_ma[box_no], leosparm); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(Wbar[lev], amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& gbx = mfi.growntilebox(); + auto const& rho_arr = a_rho[lev]->const_array(mfi); + auto const& rhoY_arr = a_spec[lev]->const_array(mfi); + auto const& Wbar_arr = Wbar[lev].array(mfi); + auto const& gradY_arr = + (have_boundary != 0) ? a_boundary[lev]->const_array(mfi) : Wbar_arr; + auto const& Wbar_boundary_arr = + (have_boundary != 0) ? Wbar_boundary[lev].array(mfi) : Wbar_arr; + + const auto phys_bc = m_phys_bc; + amrex::ParallelFor( + gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + getMwmixGivenRY(i, j, k, rho_arr, rhoY_arr, Wbar_arr, leosparm); + if (have_boundary != 0) { // need to impose gradWbar on boundary for + // computeGradient + // for dirichlet boundaries, we'll overwrite inhomog neumann ones + // NOTE: for now, this is skipped since wbar disabled for + // isothermal/soret + Wbar_boundary_arr(i, j, k) = Wbar_arr(i, j, k); + int idx[3] = {i, j, k}; + for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + const auto bc_lo = phys_bc.lo(idim); + const auto bc_hi = phys_bc.hi(idim); + bool on_lo = (bc_lo == BoundaryCondition::BCNoSlipWallIsotherm || + bc_lo == BoundaryCondition::BCSlipWallIsotherm) && + (idx[idim] < domain.smallEnd(idim)); + bool on_hi = (bc_hi == BoundaryCondition::BCNoSlipWallIsotherm || + bc_hi == BoundaryCondition::BCSlipWallIsotherm) && + (idx[idim] > domain.bigEnd(idim)); + + if (on_lo || on_hi) { + getGradMwmixGivengradYMwmix( + i, j, k, gradY_arr, Wbar_arr, Wbar_boundary_arr, leosparm); + } } } - } - }); - amrex::Gpu::streamSynchronize(); + }); + } } //------------------------------------------------------------------------ // Compute Wbar gradients and do average down to get gradients consistent @@ -1126,32 +1124,34 @@ PeleLM::differentialDiffusionUpdate( // Get t^{n} data pointer auto* ldata_p = getLevelDataPtr(lev, AmrOldTime); - auto const& state_ma = ldata_p->state.const_arrays(); - auto const& fY_ma = advData->Forcing[lev].arrays(); - - auto const& aux_ma = - (m_nAux > 0) ? ldata_p->auxiliaries.const_arrays() : state_ma; - auto const& fAux_ma = - (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : fY_ma; - - auto dt = m_dt; - amrex::ParallelFor( - advData->Forcing[lev], amrex::IntVect(0), NUM_SPECIES, - [state_ma, fY_ma, - dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - fY_ma[box_no](i, j, k, n) *= dt; - fY_ma[box_no](i, j, k, n) += rhoY(i, j, k, n); - }); - amrex::ParallelFor( - advData->Forcing[lev], amrex::IntVect(0), m_nAux, - [aux_ma, fAux_ma, - dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - fAux_ma[box_no](i, j, k, n) *= dt; - fAux_ma[box_no](i, j, k, n) += aux_ma[box_no](i, j, k, n); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(advData->Forcing[lev], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + amrex::FArrayBox DummyFab(bx, 1); + auto const& rhoY_o = ldata_p->state.const_array(mfi, FIRSTSPEC); + auto const& fY = advData->Forcing[lev].array(mfi, 0); + auto const& aux_o = (m_nAux > 0) + ? ldata_p->auxiliaries.const_array(mfi, 0) + : DummyFab.const_array(); + auto const& fAux = (m_nAux > 0) ? advData->Forcing_aux[lev].array(mfi, 0) + : DummyFab.array(); + const auto dt = m_dt; + const auto nAux = m_nAux; + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + for (int n = 0; n < NUM_SPECIES; n++) { + fY(i, j, k, n) *= dt; + fY(i, j, k, n) += rhoY_o(i, j, k, n); + } + for (int n = 0; n < nAux; n++) { + fAux(i, j, k, n) *= dt; + fAux(i, j, k, n) += aux_o(i, j, k, n); + } + }); + } } //------------------------------------------------------------------------ @@ -1324,71 +1324,51 @@ PeleLM::differentialDiffusionUpdate( for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - - auto const& state_ma = ldata_p->state.arrays(); - auto const& dhat_ma = diffData->Dhat[lev].const_arrays(); - auto const& force_ma = advData->Forcing[lev].const_arrays(); auto dt = m_dt; - if (m_use_wbar != 0 && m_use_soret != 0) { - auto const& dwbar_ma = diffData->Dwbar[lev].const_arrays(); - auto const& dT_ma = diffData->DT[lev].const_arrays(); - amrex::ParallelFor( - ldata_p->state, amrex::IntVect(0), NUM_SPECIES, - [state_ma, dhat_ma, force_ma, dwbar_ma, dT_ma, - dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - rhoY(i, j, k, n) = - force_ma[box_no](i, j, k, n) + - dt * (dhat_ma[box_no](i, j, k, n) - dwbar_ma[box_no](i, j, k, n) - - dT_ma[box_no](i, j, k, n)); - }); - } else if (m_use_wbar != 0) { - auto const& dwbar_ma = diffData->Dwbar[lev].const_arrays(); - amrex::ParallelFor( - ldata_p->state, amrex::IntVect(0), NUM_SPECIES, - [state_ma, dhat_ma, force_ma, dwbar_ma, - dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - rhoY(i, j, k, n) = - force_ma[box_no](i, j, k, n) + - dt * (dhat_ma[box_no](i, j, k, n) - dwbar_ma[box_no](i, j, k, n)); - }); - } else if (m_use_soret != 0) { - auto const& dT_ma = diffData->DT[lev].const_arrays(); - amrex::ParallelFor( - ldata_p->state, amrex::IntVect(0), NUM_SPECIES, - [state_ma, dhat_ma, force_ma, dT_ma, - dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - rhoY(i, j, k, n) = - force_ma[box_no](i, j, k, n) + - dt * (dhat_ma[box_no](i, j, k, n) - dT_ma[box_no](i, j, k, n)); - }); - } else { - amrex::ParallelFor( - ldata_p->state, amrex::IntVect(0), NUM_SPECIES, - [state_ma, dhat_ma, force_ma, - dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - rhoY(i, j, k, n) = - force_ma[box_no](i, j, k, n) + dt * dhat_ma[box_no](i, j, k, n); - }); - } - if (m_nAux > 0) { - auto const& aux_ma = ldata_p->auxiliaries.arrays(); - auto const& dhat_aux_ma = diffData->Dhat_aux[lev].const_arrays(); - auto const& force_aux_ma = advData->Forcing_aux[lev].const_arrays(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + amrex::FArrayBox DummyFab(bx, 1); + auto const& rhoY = ldata_p->state.array(mfi, FIRSTSPEC); + auto const& dhat = diffData->Dhat[lev].const_array(mfi); + auto const& force = advData->Forcing[lev].const_array(mfi, 0); + auto const& dwbar = (m_use_wbar != 0) + ? diffData->Dwbar[lev].const_array(mfi) + : DummyFab.const_array(); + auto const& dT = (m_use_soret != 0) ? diffData->DT[lev].const_array(mfi) + : DummyFab.const_array(); + auto const& aux = + (m_nAux > 0) ? ldata_p->auxiliaries.array(mfi, 0) : DummyFab.array(); + auto const& dhat_aux = (m_nAux > 0) + ? diffData->Dhat_aux[lev].const_array(mfi) + : DummyFab.const_array(); + auto const& force_aux = (m_nAux > 0) + ? advData->Forcing_aux[lev].const_array(mfi, 0) + : DummyFab.const_array(); + const auto nAux = m_nAux; + const auto dt = m_dt; + const auto use_wbar = m_use_wbar; + const auto use_soret = m_use_soret; amrex::ParallelFor( - ldata_p->state, amrex::IntVect(0), m_nAux, - [aux_ma, dhat_aux_ma, force_aux_ma, - dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - aux_ma[box_no](i, j, k, n) = force_aux_ma[box_no](i, j, k, n) + - dt * dhat_aux_ma[box_no](i, j, k, n); + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + for (int n = 0; n < NUM_SPECIES; n++) { + rhoY(i, j, k, n) = force(i, j, k, n) + dt * dhat(i, j, k, n); + if (use_wbar != 0) { + rhoY(i, j, k, n) -= dt * dwbar(i, j, k, n); + } + if (use_soret != 0) { + rhoY(i, j, k, n) -= dt * dT(i, j, k, n); + } + } + for (int n = 0; n < nAux; n++) { + aux(i, j, k, n) = force_aux(i, j, k, n) + dt * dhat_aux(i, j, k, n); + } }); } - // Shift outside? - amrex::Gpu::streamSynchronize(); } // FillPatch species again before going into the enthalpy solve @@ -1574,42 +1554,47 @@ PeleLM::deltaTIter_prepare( auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldataNew_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + // RHS pieces + auto const& rhoH_o = ldataOld_p->state.const_array(mfi, RHOH); + auto const& rhoH_n = ldataNew_p->state.const_array(mfi, RHOH); + auto const& force = advData->Forcing[lev].const_array(mfi, NUM_SPECIES); + auto const& fourier = diffData->Dhat[lev].const_array(mfi, NUM_SPECIES); + auto const& diffDiff = + diffData->Dhat[lev].const_array(mfi, NUM_SPECIES + 1); + auto const& rhs = a_rhs[lev]->array(mfi); + const amrex::Real dtinv = 1.0 / m_dt; + + // Cpmix + auto const& rho = ldataNew_p->state.const_array(mfi, DENSITY); + auto const& rhoY = ldataNew_p->state.const_array(mfi, FIRSTSPEC); + auto const& T = ldataNew_p->state.const_array(mfi, TEMP); + auto const& rhocp = a_rhoCp[lev]->array(mfi); + + // T save + auto const& tsave = a_Tsave[lev]->array(mfi); + const auto dt = m_dt; + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + // Assemble deltaT RHS + rhs(i, j, k) = + dt * ((rhoH_o(i, j, k) - rhoH_n(i, j, k)) * dtinv + force(i, j, k) + +] fourier(i, j, k) + diffDiff(i, j, k)); + + // Get \rho * Cp_{mix} + getCpmixGivenRYT(i, j, k, rho, rhoY, T, rhocp, leosparm); + rhocp(i, j, k) *= rho(i, j, k); + + // Save T + tsave(i, j, k) = T(i, j, k); + }); + } - auto const& state_old_ma = ldataOld_p->state.const_arrays(); - auto const& state_new_ma = ldataNew_p->state.const_arrays(); - auto const& force_ma = advData->Forcing[lev].const_arrays(); - auto const& dhat_ma = diffData->Dhat[lev].const_arrays(); - auto const& rhs_ma = a_rhs[lev]->arrays(); - auto const& rhocp_ma = a_rhoCp[lev]->arrays(); - auto const& tsave_ma = a_Tsave[lev]->arrays(); - - amrex::ParallelFor( - ldataNew_p->state, - [state_old_ma, state_new_ma, force_ma, dhat_ma, rhs_ma, rhocp_ma, - tsave_ma, dtinv, leosparm, - dt = m_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rhoH_o(state_old_ma[box_no], RHOH); - amrex::Array4 rhoH_n(state_new_ma[box_no], RHOH); - amrex::Array4 force(force_ma[box_no], NUM_SPECIES); - amrex::Array4 fourier(dhat_ma[box_no], NUM_SPECIES); - amrex::Array4 diffDiff( - dhat_ma[box_no], NUM_SPECIES + 1); - // Assemble deltaT RHS - rhs_ma[box_no](i, j, k) = - dt * ((rhoH_o(i, j, k) - rhoH_n(i, j, k)) * dtinv + force(i, j, k) + - fourier(i, j, k) + diffDiff(i, j, k)); - - amrex::Array4 rho(state_new_ma[box_no], DENSITY); - amrex::Array4 rhoY(state_new_ma[box_no], FIRSTSPEC); - amrex::Array4 T(state_new_ma[box_no], TEMP); - // Get \rho * Cp_{mix} - getCpmixGivenRYT(i, j, k, rho, rhoY, T, rhocp_ma[box_no], leosparm); - rhocp_ma[box_no](i, j, k) *= rho(i, j, k); - - // Save T - tsave_ma[box_no](i, j, k) = T(i, j, k); - }); - amrex::Gpu::streamSynchronize(); // Set T^{np1} to zero // Include one ghost cell to ensure levelBC at zero for linear solve ldataNew_p->state.setVal(0.0, TEMP, 1, 1); @@ -1737,49 +1722,55 @@ PeleLM::getScalarDiffForce( // Get t^{n} data pointer auto* ldataR_p = getLevelDataReactPtr(lev); - auto const& dn_ma = diffData->Dn[lev].const_arrays(); - auto const& dnp1_ma = diffData->Dnp1[lev].const_arrays(); - auto const& r_ma = ldataR_p->I_R.const_arrays(); - auto const& a_ma = advData->AofS[lev].const_arrays(); - auto const& ext_ma = m_extSource[lev]->const_arrays(); - auto const& f_ma = advData->Forcing[lev].arrays(); - - auto const& dwbar_ma = - (m_use_wbar != 0) ? diffData->Dwbar[lev].const_arrays() : dn_ma; - auto const& dT_ma = - (m_use_soret != 0) ? diffData->DT[lev].const_arrays() : dn_ma; - auto const& f_aux_ma = - (m_nAux > 0) ? advData->Forcing_aux[lev].arrays() : f_ma; - auto const& a_aux_ma = - (m_nAux > 0) ? advData->AofS_aux[lev].const_arrays() : dn_ma; - auto const& dn_aux_ma = - (m_nAux > 0) ? diffData->Dn_aux[lev].const_arrays() : dn_ma; - auto const& dnp1_aux_ma = - (m_nAux > 0) ? diffData->Dnp1_aux[lev].const_arrays() : dn_ma; - - amrex::ParallelFor( - advData->Forcing[lev], - [dn_ma, dnp1_ma, r_ma, a_ma, ext_ma, f_ma, dwbar_ma, dT_ma, f_aux_ma, - a_aux_ma, dn_aux_ma, dnp1_aux_ma, do_react = m_do_react, - use_wbar = m_use_wbar, use_soret = m_use_soret, dp0dt = m_dp0dt, - is_closed_ch = m_closed_chamber, nAux = m_nAux, aux_advect_d, - aux_diffuse_d] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 ddn(dn_ma[box_no], NUM_SPECIES + 1); - amrex::Array4 ddnp1( - dnp1_ma[box_no], NUM_SPECIES + 1); - amrex::Array4 a(a_ma[box_no], FIRSTSPEC); - amrex::Array4 extRhoY(ext_ma[box_no], FIRSTSPEC); - amrex::Array4 extRhoH(ext_ma[box_no], RHOH); - amrex::Array4 fT(f_ma[box_no], NUM_SPECIES); - buildDiffusionForcing( - i, j, k, dn_ma[box_no], ddn, dnp1_ma[box_no], ddnp1, r_ma[box_no], a, - dp0dt, is_closed_ch, do_react, f_ma[box_no], fT, dwbar_ma[box_no], - dT_ma[box_no], extRhoY, extRhoH, use_wbar, use_soret, - f_aux_ma[box_no], a_aux_ma[box_no], dn_aux_ma[box_no], - dnp1_aux_ma[box_no], aux_advect_d, aux_diffuse_d, nAux); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(advData->Forcing[lev], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + amrex::FArrayBox DummyFab(bx, 1); + auto const& dn = diffData->Dn[lev].const_array(mfi, 0); + auto const& ddn = diffData->Dn[lev].const_array(mfi, NUM_SPECIES + 1); + auto const& dnp1k = diffData->Dnp1[lev].const_array(mfi, 0); + auto const& ddnp1k = + diffData->Dnp1[lev].const_array(mfi, NUM_SPECIES + 1); + auto const& r = ldataR_p->I_R.const_array(mfi); + auto const& a = advData->AofS[lev].const_array(mfi, FIRSTSPEC); + auto const& extRhoY = m_extSource[lev]->const_array(mfi, FIRSTSPEC); + auto const& extRhoH = m_extSource[lev]->const_array(mfi, RHOH); + auto const& fY = advData->Forcing[lev].array(mfi, 0); + auto const& fT = advData->Forcing[lev].array(mfi, NUM_SPECIES); + auto const& dwbar = (m_use_wbar != 0) + ? diffData->Dwbar[lev].const_array(mfi, 0) + : DummyFab.const_array(); + auto const& dT = (m_use_soret != 0) + ? diffData->DT[lev].const_array(mfi, 0) + : DummyFab.const_array(); + auto const& fAux = (m_nAux > 0) ? advData->Forcing_aux[lev].array(mfi, 0) + : DummyFab.array(); + auto const& a_aux = (m_nAux > 0) + ? advData->AofS_aux[lev].const_array(mfi, 0) + : DummyFab.const_array(); + auto const& dn_aux = (m_nAux > 0) + ? diffData->Dn_aux[lev].const_array(mfi, 0) + : DummyFab.const_array(); + auto const& dnp1k_aux = (m_nAux > 0) + ? diffData->Dnp1_aux[lev].const_array(mfi, 0) + : DummyFab.const_array(); + const auto do_react = m_do_react; + const auto use_wbar = m_use_wbar; + const auto use_soret = m_use_soret; + const auto dp0dt = m_dp0dt; + const auto is_closed_ch = m_closed_chamber; + const auto nAux = m_nAux; + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + buildDiffusionForcing( + i, j, k, dn, ddn, dnp1k, ddnp1k, r, a, dp0dt, is_closed_ch, + do_react, fY, fT, dwbar, dT, extRhoY, extRhoH, use_wbar, use_soret, + fAux, a_aux, dn_aux, dnp1k_aux, aux_advect_d, aux_diffuse_d, nAux); + }); + } } // Fill forcing ghost cells diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index 9f696257a..cbac2e365 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -146,23 +146,26 @@ DiffusionOp::diffuse_scalar( phi.emplace_back( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), ncomp, 1, amrex::MFInfo(), a_phi[lev]->Factory()); - if (have_density == 0) { - amrex::MultiFab::Copy( - phi[lev], *a_phi[lev], phi_comp, 0, ncomp, phi[lev].nGrowVect()); - } else { - auto const& a_phi_ma = a_phi[lev]->const_arrays(); - auto const& a_rho_ma = a_density[lev]->const_arrays(); - auto const& phi_ma = phi[lev].arrays(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& gbx = mfi.growntilebox(); + auto const& a_phi_arr = a_phi[lev]->const_array(mfi, phi_comp); + auto const& a_rho_arr = + (have_density) != 0 ? a_density[lev]->const_array(mfi) + : a_phi[lev]->const_array( + mfi); // Get dummy amrex::Array4 if no density + auto const& phi_arr = phi[lev].array(mfi); amrex::ParallelFor( - phi[lev], phi[lev].nGrowVect(), ncomp, - [a_phi_ma, a_rho_ma, phi_ma, phi_comp] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 a_phi_arr( - a_phi_ma[box_no], phi_comp); - phi_ma[box_no](i, j, k, n) = - a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); + gbx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + if (have_density != 0) { + phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n) / a_rho_arr(i, j, k); + } else { + phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n); + } }); - amrex::Gpu::streamSynchronize(); } } //---------------------------------------------------------------- @@ -278,24 +281,27 @@ DiffusionOp::diffuse_scalar( // Copy the results of the solve back into a_phi // Times rho{np1,kp1} if needed // Don't touch the ghost cells - if (have_density == 0) { - for (int lev = 0; lev <= finest_level; ++lev) { - amrex::MultiFab::Copy(*a_phi[lev], phi[lev], 0, 0, ncomp, 0); - } - } else { - for (int lev = 0; lev <= finest_level; ++lev) { - auto const& a_phi_ma = a_phi[lev]->arrays(); - auto const& phi_ma = phi[lev].const_arrays(); - auto const& a_rho_ma = a_density[lev]->const_arrays(); + for (int lev = 0; lev <= finest_level; ++lev) { +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& a_phi_arr = a_phi[lev]->array(mfi, phi_comp); + auto const& a_rho_arr = + (have_density) != 0 ? a_density[lev]->const_array(mfi) + : a_phi[lev]->const_array( + mfi); // Get dummy amrex::Array4 if no density + auto const& phi_arr = phi[lev].const_array(mfi); amrex::ParallelFor( - phi[lev], amrex::IntVect(0), ncomp, - [a_phi_ma, a_rho_ma, phi_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - a_phi_ma[box_no](i, j, k, n) = - phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); + bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + if (have_density != 0) { + a_phi_arr(i, j, k, n) = phi_arr(i, j, k, n) * a_rho_arr(i, j, k); + } else { + a_phi_arr(i, j, k, n) = phi_arr(i, j, k, n); + } }); - // Shift outside? - amrex::Gpu::streamSynchronize(); } } } @@ -361,23 +367,26 @@ DiffusionOp::diffuse_scalar( phi.emplace_back( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), ncomp, 1, amrex::MFInfo(), a_phi[lev]->Factory()); - if (have_density == 0) { - amrex::MultiFab::Copy( - phi[lev], *a_phi[lev], phi_comp, 0, ncomp, phi[lev].nGrowVect()); - } else { - auto const& a_phi_ma = a_phi[lev]->const_arrays(); - auto const& a_rho_ma = a_density[lev]->const_arrays(); - auto const& phi_ma = phi[lev].arrays(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& gbx = mfi.growntilebox(); + auto const& a_phi_arr = a_phi[lev]->const_array(mfi, phi_comp); + auto const& a_rho_arr = + (have_density) != 0 ? a_density[lev]->const_array(mfi) + : a_phi[lev]->const_array( + mfi); // Get dummy amrex::Array4 if no density + auto const& phi_arr = phi[lev].array(mfi); amrex::ParallelFor( - phi[lev], phi[lev].nGrowVect(), ncomp, - [a_phi_ma, a_rho_ma, phi_ma, phi_comp] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 a_phi_arr( - a_phi_ma[box_no], phi_comp); - phi_ma[box_no](i, j, k, n) = - a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); + gbx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + if (have_density != 0) { + phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n) / a_rho_arr(i, j, k); + } else { + phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n); + } }); - amrex::Gpu::streamSynchronize(); } } //---------------------------------------------------------------- @@ -487,24 +496,27 @@ DiffusionOp::diffuse_scalar( // Copy the results of the solve back into a_phi // Times rho{np1,kp1} if needed // Don't touch the ghost cells - if (have_density == 0) { - for (int lev = 0; lev <= finest_level; ++lev) { - amrex::MultiFab::Copy(*a_phi[lev], phi[lev], 0, 0, ncomp, 0); - } - } else { - for (int lev = 0; lev <= finest_level; ++lev) { - auto const& a_phi_ma = a_phi[lev]->arrays(); - auto const& phi_ma = phi[lev].const_arrays(); - auto const& a_rho_ma = a_density[lev]->const_arrays(); + for (int lev = 0; lev <= finest_level; ++lev) { +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& a_phi_arr = a_phi[lev]->array(mfi, phi_comp); + auto const& a_rho_arr = + (have_density) != 0 ? a_density[lev]->const_array(mfi) + : a_phi[lev]->const_array( + mfi); // Get dummy amrex::Array4 if no density + auto const& phi_arr = phi[lev].const_array(mfi); amrex::ParallelFor( - phi[lev], amrex::IntVect(0), ncomp, - [a_phi_ma, a_rho_ma, phi_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - a_phi_ma[box_no](i, j, k, n) = - phi_ma[box_no](i, j, k, n) * a_rho_ma[box_no](i, j, k); + bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + if (have_density != 0) { + a_phi_arr(i, j, k, n) = phi_arr(i, j, k, n) * a_rho_arr(i, j, k); + } else { + a_phi_arr(i, j, k, n) = phi_arr(i, j, k, n); + } }); - // Shift outside? - amrex::Gpu::streamSynchronize(); } } } @@ -622,23 +634,26 @@ DiffusionOp::computeDiffFluxes( phi.emplace_back( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), ncomp, 1, amrex::MFInfo(), a_phi[lev]->Factory()); - if (have_density == 0) { - amrex::MultiFab::Copy( - phi[lev], *a_phi[lev], phi_comp, 0, ncomp, phi[lev].nGrowVect()); - } else { - auto const& a_phi_ma = a_phi[lev]->const_arrays(); - auto const& a_rho_ma = a_density[lev]->const_arrays(); - auto const& phi_ma = phi[lev].arrays(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& gbx = mfi.growntilebox(); + auto const& a_phi_arr = a_phi[lev]->const_array(mfi, phi_comp); + auto const& a_rho_arr = + (have_density) != 0 ? a_density[lev]->const_array(mfi) + : a_phi[lev]->const_array( + mfi); // Get dummy amrex::Array4 if no density + auto const& phi_arr = phi[lev].array(mfi); amrex::ParallelFor( - phi[lev], phi[lev].nGrowVect(), ncomp, - [a_phi_ma, a_rho_ma, phi_ma, phi_comp] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 a_phi_arr( - a_phi_ma[box_no], phi_comp); - phi_ma[box_no](i, j, k, n) = - a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); + gbx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + if (have_density != 0) { + phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n) / a_rho_arr(i, j, k); + } else { + phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n); + } }); - amrex::Gpu::streamSynchronize(); } } @@ -760,26 +775,30 @@ DiffusionOp::computeDiffFluxes( amrex::Vector phi; phi.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - phi.emplace_back( + phi[lev].define( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), ncomp, 1, amrex::MFInfo(), a_phi[lev]->Factory()); - if (have_density == 0) { - amrex::MultiFab::Copy( - phi[lev], *a_phi[lev], phi_comp, 0, ncomp, phi[lev].nGrowVect()); - } else { - auto const& a_phi_ma = a_phi[lev]->const_arrays(); - auto const& a_rho_ma = a_density[lev]->const_arrays(); - auto const& phi_ma = phi[lev].arrays(); +#ifdef AMREX_USE_OMP + w #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) + { + const amrex::Box& gbx = mfi.growntilebox(); + auto const& a_phi_arr = a_phi[lev]->const_array(mfi, phi_comp); + auto const& a_rho_arr = + (have_density) != 0 ? a_density[lev]->const_array(mfi) + : a_phi[lev]->const_array( + mfi); // Get dummy amrex::Array4 if no density + auto const& phi_arr = phi[lev].array(mfi); amrex::ParallelFor( - phi[lev], phi[lev].nGrowVect(), ncomp, - [a_phi_ma, a_rho_ma, phi_ma, phi_comp] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 a_phi_arr( - a_phi_ma[box_no], phi_comp); - phi_ma[box_no](i, j, k, n) = - a_phi_arr(i, j, k, n) / a_rho_ma[box_no](i, j, k); + gbx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + if (have_density != 0) { + phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n) / a_rho_arr(i, j, k); + } else { + phi_arr(i, j, k, n) = a_phi_arr(i, j, k, n); + } }); - amrex::Gpu::streamSynchronize(); } } @@ -1182,16 +1201,22 @@ DiffusionTensorOp::compute_divtau( if (have_density != 0) { for (int lev = 0; lev <= finest_level; ++lev) { - auto const& divtau_ma = a_divtau[lev]->arrays(); - auto const& rho_ma = a_density[lev]->const_arrays(); - amrex::ParallelFor( - *a_divtau[lev], amrex::IntVect(0), AMREX_SPACEDIM, - [divtau_ma, rho_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - divtau_ma[box_no](i, j, k, n) /= rho_ma[box_no](i, j, k); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(*a_divtau[lev], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + amrex::Box const& bx = mfi.tilebox(); + auto const& divtau_arr = a_divtau[lev]->array(mfi); + auto const& rho_arr = a_density[lev]->const_array(mfi); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::Real rhoinv = 1.0 / rho_arr(i, j, k); + AMREX_D_TERM(divtau_arr(i, j, k, 0) *= rhoinv; + , divtau_arr(i, j, k, 1) *= rhoinv; + , divtau_arr(i, j, k, 2) *= rhoinv;); + }); + } } } } @@ -1247,26 +1272,29 @@ DiffusionTensorOp::diffuse_velocity( for (int lev = 0; lev <= finest_level; ++lev) { rhs.emplace_back( a_vel[lev]->boxArray(), a_vel[lev]->DistributionMap(), AMREX_SPACEDIM, 0); - auto const& rhs_ma = rhs[lev].arrays(); - auto const& vel_ma = a_vel[lev]->const_arrays(); - if (m_pelelm->m_incompressible == 0) { - auto const& rho_ma = a_density[lev]->const_arrays(); - amrex::ParallelFor( - rhs[lev], amrex::IntVect(0), AMREX_SPACEDIM, - [rhs_ma, vel_ma, rho_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - rhs_ma[box_no](i, j, k, n) = - rho_ma[box_no](i, j, k) * vel_ma[box_no](i, j, k, n); - }); - } else { +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(rhs[lev], amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + amrex::Box const& bx = mfi.tilebox(); + auto const& rhs_a = rhs[lev].array(mfi); + auto const& vel_a = a_vel[lev]->const_array(mfi); + auto const& rho_a = (have_density) != 0 + ? a_density[lev]->const_array(mfi) + : amrex::Array4{}; + const auto rho_incomp = m_pelelm->m_rho; + const auto is_incomp = m_pelelm->m_incompressible; amrex::ParallelFor( - rhs[lev], amrex::IntVect(0), AMREX_SPACEDIM, - [rhs_ma, vel_ma, rho = m_pelelm->m_rho] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - rhs_ma[box_no](i, j, k, n) = rho * vel_ma[box_no](i, j, k, n); + bx, AMREX_SPACEDIM, + [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + if (is_incomp != 0) { + rhs_a(i, j, k, n) = rho_incomp * vel_a(i, j, k, n); + } else { + rhs_a(i, j, k, n) = rho_a(i, j, k) * vel_a(i, j, k, n); + } }); } - amrex::Gpu::streamSynchronize(); } amrex::MLMG mlmg(*m_solve_op); diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 2392d9b68..853c47ca5 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -49,365 +49,359 @@ PeleLM::getVelForces( const amrex::Real time = getTime(lev, a_time); - const int is_incomp = m_incompressible; - const amrex::Real rho_incomp = m_rho; - - const int pseudo_gravity = m_ctrl_pseudoGravity; - const amrex::Real dV_control = m_ctrl_dV; - const auto grav = m_gravity; - const auto gp0 = m_background_gp; - const int ps_dir = m_ctrl_flameDir; - - auto const& state_ma = ldata_p->state.const_arrays(); - auto const& ext_ma = m_extSource[lev]->const_arrays(); - auto const& force_ma = a_velForce->arrays(); - - amrex::ParallelFor( - *a_velForce, - [state_ma, ext_ma, force_ma, grav, gp0, ps_dir, is_incomp, rho_incomp, - pseudo_gravity, - dV_control] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) { - amrex::Array4 vel(state_ma[box_no], VELX); - amrex::Array4 extmom(ext_ma[box_no], VELX); - amrex::Array4 rho(state_ma[box_no], DENSITY); - amrex::Array4 extrho(ext_ma[box_no], DENSITY); - // overwrite if incompressible, just to point to something - if (is_incomp != 0) { - rho = vel; - extrho = extmom; - } - // background gp, pseudo grav, ext sources - makeVelForce( - i, j, k, is_incomp, rho_incomp, pseudo_gravity, ps_dir, grav, gp0, - dV_control, vel, rho, extmom, extrho, force_ma[box_no]); - }); - amrex::Gpu::streamSynchronize(); - - if (add_gradP != 0) { - amrex::MultiFab::Subtract( - *a_velForce, ldataGP_p->gp, 0, 0, AMREX_SPACEDIM, 0); - } - const int has_divTau = static_cast(a_divTau != nullptr); - if (has_divTau != 0) { - amrex::MultiFab::Add(*a_velForce, *a_divTau, 0, 0, AMREX_SPACEDIM, 0); - } + int has_divTau = static_cast(a_divTau != nullptr); -#ifndef PELE_USE_PLASMA - if (m_do_turbulent_forcing) -#endif - { #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif - for (amrex::MFIter mfi(*a_velForce, amrex::TilingIfNotGPU()); mfi.isValid(); - ++mfi) { - const auto& bx = mfi.tilebox(); - amrex::FArrayBox DummyFab(bx, 1); - const auto& rho_arr = (m_incompressible != 0) - ? DummyFab.array() - : ldata_p->state.const_array(mfi, DENSITY); - const auto& force_arr = a_velForce->array(mfi); + for (amrex::MFIter mfi(*a_velForce, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const auto& bx = mfi.tilebox(); + amrex::FArrayBox DummyFab(bx, 1); + const auto& vel_arr = ldata_p->state.const_array(mfi, VELX); + const auto& rho_arr = (m_incompressible) != 0 + ? DummyFab.array() + : ldata_p->state.const_array(mfi, DENSITY); + const auto& rhoY_arr = (m_incompressible) != 0 + ? DummyFab.array() + : ldata_p->state.const_array(mfi, FIRSTSPEC); + const auto& rhoh_arr = (m_incompressible) != 0 + ? DummyFab.array() + : ldata_p->state.const_array(mfi, RHOH); + const auto& temp_arr = (m_incompressible) != 0 + ? DummyFab.array() + : ldata_p->state.const_array(mfi, TEMP); + const auto& extmom_arr = m_extSource[lev]->const_array(mfi, VELX); + const auto& extrho_arr = m_extSource[lev]->const_array(mfi, DENSITY); + const auto& force_arr = a_velForce->array(mfi); + + // Get other forces (gravity, ...) + getVelForces( + lev, bx, time, force_arr, vel_arr, rho_arr, rhoY_arr, rhoh_arr, temp_arr, + extmom_arr, extrho_arr); + #ifdef PELE_USE_PLASMA - const auto& rhoY_arr = (m_incompressible != 0) - ? DummyFab.array() - : ldata_p->state.const_array(mfi, FIRSTSPEC); - const auto& rhoh_arr = (m_incompressible != 0) - ? DummyFab.array() - : ldata_p->state.const_array(mfi, RHOH); - const auto& temp_arr = (m_incompressible != 0) - ? DummyFab.array() - : ldata_p->state.const_array(mfi, TEMP); - const auto& phiV_arr = ldata_p->state.const_array(mfi, PHIV); - const auto& ne_arr = ldata_p->state.const_array(mfi, NE); - addLorentzVelForces(lev, bx, time, force_arr, rhoY_arr, phiV_arr, ne_arr); - if (m_do_turbulent_forcing) + const auto& phiV_arr = ldata_p->state.const_array(mfi, PHIV); + const auto& ne_arr = ldata_p->state.const_array(mfi, NE); + addLorentzVelForces(lev, bx, time, force_arr, rhoY_arr, phiV_arr, ne_arr); #endif - { - // Add forcing terms to maintain turbulence - // note: if m_incompressible == 0 then m_rho is unused by - // addTurbVelForce - turb_forcing.addTurbVelForces( - geom[lev].data(), bx, time, force_arr, rho_arr, is_incomp, - rho_incomp); - } + + // Add forcing terms to maintain turbulence + if (m_do_turbulent_forcing) { + // note: if m_incompressible == false then m_rho is unused by + // addTurbVelForces + turb_forcing.addTurbVelForces( + geom[lev].data(), bx, time, force_arr, rho_arr, m_incompressible, + m_rho); } - } - if (is_incomp != 0) { - a_velForce->mult(1.0 / rho_incomp, 0, AMREX_SPACEDIM, 0); - } else { - amrex::ParallelFor( - *a_velForce, amrex::IntVect(0), AMREX_SPACEDIM, - [force_ma, state_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 rho(state_ma[box_no], DENSITY); - force_ma[box_no](i, j, k, n) /= rho(i, j, k); - }); - amrex::Gpu::streamSynchronize(); + // Add pressure gradient and viscous forces (if req.) and scale by density. + int is_incomp = m_incompressible; + amrex::Real incomp_rho_inv = 1.0 / m_rho; + if ((add_gradP != 0) || (has_divTau != 0)) { + const auto& gp_arr = + (add_gradP) != 0 ? ldataGP_p->gp.const_array(mfi) : DummyFab.array(); + const auto& divTau_arr = + (has_divTau) != 0 ? a_divTau->const_array(mfi) : DummyFab.array(); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + if (is_incomp != 0) { + for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + if (add_gradP != 0) { + force_arr(i, j, k, idim) -= gp_arr(i, j, k, idim); + } + if (has_divTau != 0) { + force_arr(i, j, k, idim) += divTau_arr(i, j, k, idim); + } + force_arr(i, j, k, idim) *= incomp_rho_inv; + } + } else { + for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + if (add_gradP != 0) { + force_arr(i, j, k, idim) -= gp_arr(i, j, k, idim); + } + if (has_divTau != 0) { + force_arr(i, j, k, idim) += divTau_arr(i, j, k, idim); + } + force_arr(i, j, k, idim) /= rho_arr(i, j, k); + } + } + }); + } else { + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + if (is_incomp != 0) { + for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + force_arr(i, j, k, idim) *= incomp_rho_inv; + } + } else { + for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + force_arr(i, j, k, idim) /= rho_arr(i, j, k); + } + } + }); + } } -} -void -PeleLM::addSpark(const TimeStamp a_timestamp) -{ - for (int lev = 0; lev <= finest_level; ++lev) { - for (int n = 0; n < m_n_sparks; ++n) { - // Do the checks first - const amrex::Real time = getTime(lev, a_timestamp); - const bool verb = m_spark_verbose > 1 && lev == 0; - if ( - time < m_spark_time[n] || - time > m_spark_time[n] + m_spark_duration[n]) { + void PeleLM::addSpark(const TimeStamp a_timestamp) + { + for (int lev = 0; lev <= finest_level; ++lev) { + for (int n = 0; n < m_n_sparks; ++n) { + // Do the checks first + const amrex::Real time = getTime(lev, a_timestamp); + const bool verb = m_spark_verbose > 1 && lev == 0; + if ( + time < m_spark_time[n] || + time > m_spark_time[n] + m_spark_duration[n]) { + if (verb) { + amrex::Print() << m_spark[n] << " not active \n"; + } + continue; + } + const amrex::Real* probLo = geom[lev].ProbLo(); + auto const dx = geom[lev].CellSizeArray(); + amrex::IntVect spark_idx; + for (int d = 0; d < AMREX_SPACEDIM; ++d) { + spark_idx[d] = + static_cast((m_spark_location[n][d] - probLo[d]) / dx[d]); + } + const amrex::Box domainBox = geom[lev].Domain(); + // just a check + if (!domainBox.contains(spark_idx)) { + amrex::Warning(m_spark[n] + " not in domain!"); + continue; + } if (verb) { - amrex::Print() << m_spark[n] << " not active \n"; + amrex::Print() << m_spark[n] << " active\n"; } - continue; - } - const amrex::Real* probLo = geom[lev].ProbLo(); - auto const dx = geom[lev].CellSizeArray(); - amrex::IntVect spark_idx; - for (int d = 0; d < AMREX_SPACEDIM; ++d) { - spark_idx[d] = - static_cast((m_spark_location[n][d] - probLo[d]) / dx[d]); - } - const amrex::Box domainBox = geom[lev].Domain(); - // just a check - if (!domainBox.contains(spark_idx)) { - amrex::Warning(m_spark[n] + " not in domain!"); - continue; - } - if (verb) { - amrex::Print() << m_spark[n] << " active\n"; - } - auto const* eosparm = eos_parms.device_parm(); - auto eos = pele::physics::PhysicsType::eos(eosparm); - - auto const& statema = - getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); - auto const& extma = m_extSource[lev]->arrays(); - amrex::ParallelFor( - *m_extSource[lev], - [statema, extma, eos, dx, spark_idx, - spark_duration = m_spark_duration[n], spark_temp = m_spark_temp[n], - spark_radius = m_spark_radius - [n]] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - const amrex::Real dist_to_center = std::sqrt(AMREX_D_TERM( - (i - spark_idx[0]) * (i - spark_idx[0]) * dx[0] * dx[0], - +(j - spark_idx[1]) * (j - spark_idx[1]) * dx[1] * dx[1], - +(k - spark_idx[2]) * (k - spark_idx[2]) * dx[2] * dx[2])); - if (dist_to_center < spark_radius) { - amrex::Real rhoh_src_loc = 0; - const amrex::Real rho = statema[box_no](i, j, k, DENSITY); - amrex::Real Y[NUM_SPECIES]; - for (int ns = 0; ns < NUM_SPECIES; ++ns) { - Y[ns] = statema[box_no](i, j, k, FIRSTSPEC + ns) / rho; + auto const* eosparm = eos_parms.device_parm(); + auto eos = pele::physics::PhysicsType::eos(eosparm); + + auto const& statema = + getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); + auto const& extma = m_extSource[lev]->arrays(); + amrex::ParallelFor( + *m_extSource[lev], + [statema, extma, eos, dx, spark_idx, + spark_duration = m_spark_duration[n], spark_temp = m_spark_temp[n], + spark_radius = m_spark_radius + [n]] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + const amrex::Real dist_to_center = std::sqrt(AMREX_D_TERM( + (i - spark_idx[0]) * (i - spark_idx[0]) * dx[0] * dx[0], + +(j - spark_idx[1]) * (j - spark_idx[1]) * dx[1] * dx[1], + +(k - spark_idx[2]) * (k - spark_idx[2]) * dx[2] * dx[2])); + if (dist_to_center < spark_radius) { + amrex::Real rhoh_src_loc = 0; + const amrex::Real rho = statema[box_no](i, j, k, DENSITY); + amrex::Real Y[NUM_SPECIES]; + for (int ns = 0; ns < NUM_SPECIES; ++ns) { + Y[ns] = statema[box_no](i, j, k, FIRSTSPEC + ns) / rho; + } + eos.TY2H(spark_temp, Y, rhoh_src_loc); + rhoh_src_loc *= rho * 1e-4 / spark_duration; + extma[box_no](i, j, k, RHOH) = rhoh_src_loc; } - eos.TY2H(spark_temp, Y, rhoh_src_loc); - rhoh_src_loc *= rho * 1e-4 / spark_duration; - extma[box_no](i, j, k, RHOH) = rhoh_src_loc; - } - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); + }); + // Shift outside? + amrex::Gpu::streamSynchronize(); + } } } -} -// Manifold model - dissipation rate sources for variances -void -PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) -{ - BL_PROFILE("PeleLM::addScalarVarianceSources"); - // no scalar dissipation sources if not using a manifold model + // Manifold model - dissipation rate sources for variances + void PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) + { + BL_PROFILE("PeleLM::addScalarVarianceSources"); + // no scalar dissipation sources if not using a manifold model #ifndef USE_MANIFOLD_EOS - amrex::ignore_unused(a_timestamp); + amrex::ignore_unused(a_timestamp); #else - if (m_add_variance_sources) { - auto const& leosparm = eos_parms.host_parm(); - - // Determine if we have any scalar variances that need sources added - // Could be moved elsewhere to not do every timestep - int nvariances = 0; - int var_of_scalar = -1; - for (int n = 0; n < MANIFOLD_DIM; ++n) { - if (leosparm.is_variance_of[n] >= 0) { - if (!m_do_les) { - amrex::Abort( - "PeleLM::addScalarVarianceSources(): cannot add a " - "scalar dissipation without an active LES model"); + if (m_add_variance_sources) { + auto const& leosparm = eos_parms.host_parm(); + + // Determine if we have any scalar variances that need sources added + // Could be moved elsewhere to not do every timestep + int nvariances = 0; + int var_of_scalar = -1; + for (int n = 0; n < MANIFOLD_DIM; ++n) { + if (leosparm.is_variance_of[n] >= 0) { + if (!m_do_les) { + amrex::Abort( + "PeleLM::addScalarVarianceSources(): cannot add a " + "scalar dissipation without an active LES model"); + } + nvariances += 1; + var_of_scalar = FIRSTSPEC + leosparm.is_variance_of[n]; } - nvariances += 1; - var_of_scalar = FIRSTSPEC + leosparm.is_variance_of[n]; } - } - if (nvariances > 1) { - amrex::Abort( - "PeleLM::addScalarVarianceSources(): currently we only support " - "manifold models with 0 or 1 variances"); - } else if (nvariances > 0) { - - // Compute scalar gradients (no need to average down here) - constexpr int do_avgDown = 0; - auto bcRecScalar = fetchBCRecArray(var_of_scalar, 1); - constexpr int nGrow = 0; // No need for ghost face on fluxes - amrex::Vector> grad_fc( - finest_level + 1); - for (int lev = 0; lev <= finest_level; ++lev) { - const auto& ba = grids[lev]; - const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - grad_fc[lev][idim].define( - amrex::convert(ba, amrex::IntVect::TheDimensionVector(idim)), - dmap[lev], 1, nGrow, amrex::MFInfo(), factory); - grad_fc[lev][idim].setVal(0.0); // Required? + if (nvariances > 1) { + amrex::Abort( + "PeleLM::addScalarVarianceSources(): currently we only support " + "manifold models with 0 or 1 variances"); + } else if (nvariances > 0) { + + // Compute scalar gradients (no need to average down here) + constexpr int do_avgDown = 0; + auto bcRecScalar = fetchBCRecArray(var_of_scalar, 1); + constexpr int nGrow = 0; // No need for ghost face on fluxes + amrex::Vector> grad_fc( + finest_level + 1); + for (int lev = 0; lev <= finest_level; ++lev) { + const auto& ba = grids[lev]; + const auto& factory = Factory(lev); + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + grad_fc[lev][idim].define( + amrex::convert(ba, amrex::IntVect::TheDimensionVector(idim)), + dmap[lev], 1, nGrow, amrex::MFInfo(), factory); + grad_fc[lev][idim].setVal(0.0); // Required? + } } - } - getDiffusionOp()->computeGradient( - GetVecOfArrOfPtrs(grad_fc), {}, - GetVecOfConstPtrs(getStateVect(a_timestamp)), {}, bcRecScalar[0], - do_avgDown, var_of_scalar); - - constexpr amrex::Real fact = - 0.5 / static_cast(AMREX_SPACEDIM); - const amrex::Real C_chi = m_les_c_chi; - const amrex::Real ScInv = m_Schmidt_inv; - - // Add in Production and Dissipation source terms for subfilter variances - for (int lev = 0; lev <= finest_level; ++lev) { - - auto* ldata_p = getLevelDataPtr(lev, a_timestamp); - - // Require the turbulent viscosity to be pre-computed - // it always is stored at AmrOldTime, so we just use that - // We need cell-centered mu_t but have it at faces - // The simple interpolation below probably isn't valid for EB + getDiffusionOp()->computeGradient( + GetVecOfArrOfPtrs(grad_fc), {}, + GetVecOfConstPtrs(getStateVect(a_timestamp)), {}, bcRecScalar[0], + do_avgDown, var_of_scalar); + + constexpr amrex::Real fact = + 0.5 / static_cast(AMREX_SPACEDIM); + const amrex::Real C_chi = m_les_c_chi; + const amrex::Real ScInv = m_Schmidt_inv; + + // Add in Production and Dissipation source terms for subfilter + // variances + for (int lev = 0; lev <= finest_level; ++lev) { + + auto* ldata_p = getLevelDataPtr(lev, a_timestamp); + + // Require the turbulent viscosity to be pre-computed + // it always is stored at AmrOldTime, so we just use that + // We need cell-centered mu_t but have it at faces + // The simple interpolation below probably isn't valid for EB #ifdef AMREX_USE_EB - amrex::Abort( - "PeleLM::addScalarVarianceSources(): this is not supported with EB"); + amrex::Abort( + "PeleLM::addScalarVarianceSources(): this is not supported with " + "EB"); #endif - for (int n = 0; n < MANIFOLD_DIM; ++n) { - if (leosparm.is_variance_of[n] >= 0) { - - AMREX_D_TERM( - auto const& mut_arr_x = - m_leveldata_old[lev]->visc_turb_fc[0].const_arrays(); - , auto const& mut_arr_y = - m_leveldata_old[lev]->visc_turb_fc[1].const_arrays(); - , auto const& mut_arr_z = - m_leveldata_old[lev]->visc_turb_fc[2].const_arrays();) - AMREX_D_TERM( - auto const& gx = grad_fc[lev][0].const_arrays(); - , auto const& gy = grad_fc[lev][1].const_arrays(); - , auto const& gz = grad_fc[lev][2].const_arrays();) - auto const& extma = m_extSource[lev]->arrays(); - auto const& statema = ldata_p->state.const_arrays(); - - // l_scale will also need modification for EB - const amrex::Real vol = AMREX_D_TERM( - geom[lev].CellSize(0), *geom[lev].CellSize(1), - *geom[lev].CellSize(2)); + for (int n = 0; n < MANIFOLD_DIM; ++n) { + if (leosparm.is_variance_of[n] >= 0) { + + AMREX_D_TERM( + auto const& mut_arr_x = + m_leveldata_old[lev]->visc_turb_fc[0].const_arrays(); + , auto const& mut_arr_y = + m_leveldata_old[lev]->visc_turb_fc[1].const_arrays(); + , auto const& mut_arr_z = + m_leveldata_old[lev]->visc_turb_fc[2].const_arrays();) + AMREX_D_TERM( + auto const& gx = grad_fc[lev][0].const_arrays(); + , auto const& gy = grad_fc[lev][1].const_arrays(); + , auto const& gz = grad_fc[lev][2].const_arrays();) + auto const& extma = m_extSource[lev]->arrays(); + auto const& statema = ldata_p->state.const_arrays(); + + // l_scale will also need modification for EB + const amrex::Real vol = AMREX_D_TERM( + geom[lev].CellSize(0), *geom[lev].CellSize(1), + *geom[lev].CellSize(2)); #if AMREX_SPACEDIM == 2 - const amrex::Real l_scale = std::sqrt(vol); + const amrex::Real l_scale = std::sqrt(vol); #else - const amrex::Real l_scale = std::cbrt(vol); + const amrex::Real l_scale = std::cbrt(vol); #endif - const amrex::Real inv_l_scale2 = 1.0 / (l_scale * l_scale); + const amrex::Real inv_l_scale2 = 1.0 / (l_scale * l_scale); - amrex::ParallelFor( - *m_extSource[lev], [extma, statema, n, C_chi, ScInv, inv_l_scale2, - mut_arr_x, gx, mut_arr_y, gy + amrex::ParallelFor( + *m_extSource[lev], [extma, statema, n, C_chi, ScInv, + inv_l_scale2, mut_arr_x, gx, mut_arr_y, gy #if (AMREX_SPACEDIM == 3) - , - mut_arr_z, gz + , + mut_arr_z, gz #endif - ] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept { - // Subfilter Scalar Dissipation: Linear Relaxation model - // rho chi_sgs = C_chi * mu_t / Delta^2 * Variance - const amrex::Real mu_t = - fact * - (AMREX_D_TERM( - mut_arr_x[bx](i, j, k) + mut_arr_x[bx](i + 1, j, k), - +mut_arr_y[bx](i, j, k) + mut_arr_y[bx](i, j + 1, k), - +mut_arr_z[bx](i, j, k) + mut_arr_z[bx](i, j, k + 1))); - - extma[bx](i, j, k, FIRSTSPEC + n) -= - C_chi * mu_t * inv_l_scale2 * - statema[bx](i, j, k, FIRSTSPEC + n); - - // Production term (w/ Smagorinsky closure for turbulent flux) - // -2 (rho - rho ) d/dx_j - // = 2 *mu_t/Sc_t * d/dx_j * d/dx_j - const amrex::Real mu_grad2 = - fact * - (AMREX_D_TERM( - mut_arr_x[bx](i, j, k) * gx[bx](i, j, k) * gx[bx](i, j, k) + - mut_arr_x[bx](i + 1, j, k) * gx[bx](i + 1, j, k) * - gx[bx](i + 1, j, k), - +mut_arr_y[bx](i, j, k) * gy[bx](i, j, k) * - gy[bx](i, j, k) + - mut_arr_y[bx](i, j + 1, k) * gy[bx](i, j + 1, k) * - gy[bx](i, j + 1, k), - +mut_arr_z[bx](i, j, k) * gz[bx](i, j, k) * - gz[bx](i, j, k) + - mut_arr_z[bx](i, j, k + 1) * gz[bx](i, j, k + 1) * - gz[bx](i, j, k + 1))); - - extma[bx](i, j, k, FIRSTSPEC + n) += 2.0 * ScInv * mu_grad2; - }); - amrex::Gpu::streamSynchronize(); + ] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept { + // Subfilter Scalar Dissipation: Linear Relaxation model + // rho chi_sgs = C_chi * mu_t / Delta^2 * Variance + const amrex::Real mu_t = + fact * + (AMREX_D_TERM( + mut_arr_x[bx](i, j, k) + mut_arr_x[bx](i + 1, j, k), + +mut_arr_y[bx](i, j, k) + mut_arr_y[bx](i, j + 1, k), + +mut_arr_z[bx](i, j, k) + mut_arr_z[bx](i, j, k + 1))); + + extma[bx](i, j, k, FIRSTSPEC + n) -= + C_chi * mu_t * inv_l_scale2 * + statema[bx](i, j, k, FIRSTSPEC + n); + + // Production term (w/ Smagorinsky closure for turbulent flux) + // -2 (rho - rho ) d/dx_j + // = 2 *mu_t/Sc_t * d/dx_j * d/dx_j + const amrex::Real mu_grad2 = + fact * (AMREX_D_TERM( + mut_arr_x[bx](i, j, k) * gx[bx](i, j, k) * + gx[bx](i, j, k) + + mut_arr_x[bx](i + 1, j, k) * + gx[bx](i + 1, j, k) * gx[bx](i + 1, j, k), + +mut_arr_y[bx](i, j, k) * gy[bx](i, j, k) * + gy[bx](i, j, k) + + mut_arr_y[bx](i, j + 1, k) * + gy[bx](i, j + 1, k) * gy[bx](i, j + 1, k), + +mut_arr_z[bx](i, j, k) * gz[bx](i, j, k) * + gz[bx](i, j, k) + + mut_arr_z[bx](i, j, k + 1) * + gz[bx](i, j, k + 1) * gz[bx](i, j, k + 1))); + + extma[bx](i, j, k, FIRSTSPEC + n) += 2.0 * ScInv * mu_grad2; + }); + amrex::Gpu::streamSynchronize(); + } } } } } - } #endif -} + } -// Calculate additional external sources (soot, radiation, user defined, etc.) -void -PeleLM::getExternalSources( - const int is_initIter, - const PeleLM::TimeStamp a_timestamp_old, - const PeleLM::TimeStamp a_timestamp_new) -{ - amrex::ignore_unused(is_initIter); + // Calculate additional external sources (soot, radiation, user defined, etc.) + void PeleLM::getExternalSources( + const int is_initIter, const PeleLM::TimeStamp a_timestamp_old, + const PeleLM::TimeStamp a_timestamp_new) + { + amrex::ignore_unused(is_initIter); - if (m_n_sparks > 0) { - addSpark(a_timestamp_old); - } + if (m_n_sparks > 0) { + addSpark(a_timestamp_old); + } #ifdef PELE_USE_SPRAY - if (is_initIter == 0) { - SprayMKD(m_cur_time, m_dt); - } + if (is_initIter == 0) { + SprayMKD(m_cur_time, m_dt); + } #endif #ifdef PELE_USE_SOOT - if (do_soot_solve) { - computeSootSource(a_timestamp_old, m_dt); - } + if (do_soot_solve) { + computeSootSource(a_timestamp_old, m_dt); + } #endif #ifdef PELE_USE_RADIATION - if (do_rad_solve) { - BL_PROFILE_VAR("PeleLM::advance::rad", PLM_RAD); - computeRadSource(a_timestamp_old); - BL_PROFILE_VAR_STOP(PLM_RAD); - } + if (do_rad_solve) { + BL_PROFILE_VAR("PeleLM::advance::rad", PLM_RAD); + computeRadSource(a_timestamp_old); + BL_PROFILE_VAR_STOP(PLM_RAD); + } #endif - addScalarVarianceSources(a_timestamp_old); + addScalarVarianceSources(a_timestamp_old); - // User defined external sources - if (m_user_defined_ext_sources) { - for (int lev = 0; lev <= finest_level; ++lev) { - auto* ldata_p_old = getLevelDataPtr(lev, a_timestamp_old); - auto* ldata_p_new = getLevelDataPtr(lev, a_timestamp_new); - auto& ext_src = m_extSource[lev]; - ProblemSpecificFunctions::modify_ext_sources( - getTime(lev, a_timestamp_old), m_dt, ldata_p_old->state, - ldata_p_new->state, ext_src, geom[lev].data(), prob_parm_d); + // User defined external sources + if (m_user_defined_ext_sources) { + for (int lev = 0; lev <= finest_level; ++lev) { + auto* ldata_p_old = getLevelDataPtr(lev, a_timestamp_old); + auto* ldata_p_new = getLevelDataPtr(lev, a_timestamp_new); + auto& ext_src = m_extSource[lev]; + ProblemSpecificFunctions::modify_ext_sources( + getTime(lev, a_timestamp_old), m_dt, ldata_p_old->state, + ldata_p_new->state, ext_src, geom[lev].data(), prob_parm_d); + } } } -} diff --git a/Source/PeleLMeX_Init.cpp b/Source/PeleLMeX_Init.cpp index acfd3380d..f9406fc4e 100644 --- a/Source/PeleLMeX_Init.cpp +++ b/Source/PeleLMeX_Init.cpp @@ -149,21 +149,26 @@ PeleLM::MakeNewLevelFromScratch( amrex::MFInfo(), EBFactory(0)); FillSignedDistance(signDist, true); - auto const& sd_cc_ma = m_signedDist0->arrays(); - auto const& sd_nd_ma = signDist.const_arrays(); - amrex::ParallelFor( - *m_signedDist0, m_signedDist0->nGrowVect(), - [sd_cc_ma, - sd_nd_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - sd_cc_ma[box_no](i, j, k) = AMREX_D_TERM( - sd_nd_ma[box_no](i, j, k) + sd_nd_ma[box_no](i + 1, j, k), - +sd_nd_ma[box_no](i, j + 1, k) + sd_nd_ma[box_no](i + 1, j + 1, k), - +sd_nd_ma[box_no](i, j, k + 1) + sd_nd_ma[box_no](i + 1, j, k + 1) + - sd_nd_ma[box_no](i, j + 1, k + 1) + - sd_nd_ma[box_no](i + 1, j + 1, k + 1)); - sd_cc_ma[box_no](i, j, k) *= AMREX_D_PICK(0.5, 0.25, 0.125); - }); - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(*m_signedDist0, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.growntilebox(); + auto const& sd_cc = m_signedDist0->array(mfi); + auto const& sd_nd = signDist.const_array(mfi); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::Real fac = AMREX_D_PICK(0.5, 0.25, 0.125); + sd_cc(i, j, k) = AMREX_D_TERM( + sd_nd(i, j, k) + sd_nd(i + 1, j, k), + +sd_nd(i, j + 1, k) + sd_nd(i + 1, j + 1, k), + +sd_nd(i, j, k + 1) + sd_nd(i + 1, j, k + 1) + + sd_nd(i, j + 1, k + 1) + sd_nd(i + 1, j + 1, k + 1)); + sd_cc(i, j, k) *= fac; + }); + } + m_signedDist0->FillBoundary(geom[0].periodicity()); extendSignedDistance(m_signedDist0.get(), extentFactor); } @@ -352,26 +357,26 @@ PeleLM::initLevelData(const int lev) // Prob/PMF data ProbParm const* lprobparm = prob_parm_d; auto const* lpmfdata = pmf_data.device_parm(); + auto const local_m_incompressible = m_incompressible; - // don't want to use state for dummy in case user overwrites state in aux - amrex::MultiFab dummy_mf(grids[lev], dmap[lev], 1, 0); - - auto const& state_ma = ldata_p->state.arrays(); - auto const& aux_ma = - (m_nAux > 0) ? ldata_p->auxiliaries.arrays() : dummy_mf.arrays(); - - amrex::ParallelFor( - ldata_p->state, - [state_ma, aux_ma, geomdata, lprobparm, lpmfdata, - is_incomp = - m_incompressible] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + amrex::FArrayBox DummyFab(bx, 1); + auto const& state_arr = ldata_p->state.array(mfi); + auto const& aux_arr = + (m_nAux > 0) ? ldata_p->auxiliaries.array(mfi) : DummyFab.array(); + amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { ProblemSpecificFunctions::initdata( - i, j, k, is_incomp, state_ma[box_no], aux_ma[box_no], geomdata, + i, j, k, local_m_incompressible, state_arr, aux_arr, geomdata, *lprobparm, lpmfdata); }); - amrex::Gpu::streamSynchronize(); + } - if (m_incompressible == 0) { + if (local_m_incompressible == 0) { // Initialize thermodynamic pressure setThermoPress(lev, AmrNewTime); if (m_has_divu != 0) { diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index c36e6ce3d..7a9a71065 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -1017,17 +1017,24 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) // Converting units when pltfile is coming from PeleC solution if (pltfileSource == "C") { - amrex::Print() << " Converting CGS to MKS units... \n"; - auto const& state_ma = ldata_p->state.arrays(); - amrex::ParallelFor( - ldata_p->state, - [state_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 vel(state_ma[box_no], VELX); - for (int n = 0; n < AMREX_SPACEDIM; ++n) { - vel(i, j, k, n) *= 0.01; - } - }); - amrex::Gpu::streamSynchronize(); + if (m_verbose > 0) { + amrex::Print() << " Converting CGS to MKS units... \n"; + } +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& vel_arr = ldata_p->state.array(mfi, VELX); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + for (int n = 0; n < AMREX_SPACEDIM; n++) { + amrex::Real vel_mks = vel_arr(i, j, k, n) * 0.01; + vel_arr(i, j, k, n) = vel_mks; + } + }); + } } #ifdef PELE_USE_PLASMA @@ -1045,21 +1052,22 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) SootConst sc; amrex::Real* momV = sc.MomOrderV.data(); amrex::Real* momS = sc.MomOrderS.data(); - auto const& state_ma = ldata_p->state.arrays(); - amrex::Real soot_exp[NUM_SOOT_MOMENTS] = {0.0}; - for (int n = 0; n < NUM_SOOT_MOMENTS; ++n) { - soot_exp[n] = 3. - (3. * momV[n] + 2. * momS[n]); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& soot_arr = ldata_p->state.array(mfi, FIRSTSOOT); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + for (int n = 0; n < NUM_SOOT_MOMENTS; n++) { + amrex::Real soot_exp = 3. - (3. * momV[n] + 2. * momS[n]); + soot_arr(i, j, k, n) *= std::pow(100., soot_exp); + } + soot_arr(i, j, k, NUMSOOTVAR - 1) *= 1.E6; + }); } - amrex::ParallelFor( - ldata_p->state, [state_ma, soot_exp] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - amrex::Array4 soot(state_ma[box_no], FIRSTSOOT); - for (int n = 0; n < NUM_SOOT_MOMENTS; ++n) { - soot(i, j, k, n) *= std::pow(100., soot_exp[n]); - } - soot(i, j, k, NUMSOOTVAR - 1) *= 1.E6; - }); - amrex::Gpu::streamSynchronize(); } } else { SootData* const sd = soot_model->getSootData(); @@ -1087,22 +1095,23 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) // Enforce rho and rhoH consistent with temperature and mixture // The above handles species mapping (to some extent), but nothing enforce // sum of Ys = 1 -> use N2 in the following if N2 is present - auto const& state_ma = ldata_p->state.arrays(); - auto const* leosparm = eos_parms.device_parm(); - const amrex::Real P_cgs = m2c::P(lprobparm->P_mean); - - amrex::ParallelFor( - ldata_p->state, [state_ma, P_cgs, eosparm = leosparm] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& rho_arr = ldata_p->state.array(mfi, DENSITY); + auto const& rhoY_arr = ldata_p->state.array(mfi, FIRSTSPEC); + auto const& rhoH_arr = ldata_p->state.array(mfi, RHOH); + auto const& temp_arr = ldata_p->state.array(mfi, TEMP); + const auto* eosparm = leosparm; + amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { auto eos = pele::physics::PhysicsType::eos(eosparm); - amrex::Array4 rho(state_ma[box_no], DENSITY); - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - amrex::Array4 rhoH(state_ma[box_no], RHOH); - amrex::Array4 temp(state_ma[box_no], TEMP); amrex::Real massfrac[NUM_SPECIES] = {0.0}; amrex::Real sumYs = 0.0; - for (int n = 0; n < NUM_SPECIES; ++n) { - massfrac[n] = rhoY(i, j, k, n); + for (int n = 0; n < NUM_SPECIES; n++) { + massfrac[n] = rhoY_arr(i, j, k, n); #ifdef N2_ID if (n != N2_ID) { sumYs += massfrac[n]; @@ -1112,22 +1121,25 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) #ifdef N2_ID massfrac[N2_ID] = 1.0 - sumYs; #endif + // Get density + amrex::Real P_cgs = lprobparm->P_mean * 10.0; amrex::Real rho_cgs = 0.0; - eos.PYT2R(P_cgs, massfrac, temp(i, j, k), rho_cgs); - rho(i, j, k) = c2m::Rho(rho_cgs); + eos.PYT2R(P_cgs, massfrac, temp_arr(i, j, k), rho_cgs); + rho_arr(i, j, k) = rho_cgs * 1.0e3; // Get enthalpy amrex::Real h_cgs = 0.0; - eos.TY2H(temp(i, j, k), massfrac, h_cgs); - rhoH(i, j, k) = c2m::H(h_cgs) * rho(i, j, k); + eos.TY2H(temp_arr(i, j, k), massfrac, h_cgs); + rhoH_arr(i, j, k) = h_cgs * 1.0e-4 * rho_arr(i, j, k); // Fill rhoYs - for (int n = 0; n < NUM_SPECIES; ++n) { - rhoY(i, j, k, n) = massfrac[n] * rho(i, j, k); + for (int n = 0; n < NUM_SPECIES; n++) { + rhoY_arr(i, j, k, n) = massfrac[n] * rho_arr(i, j, k); } }); - amrex::Gpu::streamSynchronize(); + } + // Initialize thermodynamic pressure setThermoPress(a_lev, AmrNewTime); if (m_has_divu != 0) { diff --git a/Source/PeleLMeX_Projection.cpp b/Source/PeleLMeX_Projection.cpp index 7e84de1f6..fdff051c4 100644 --- a/Source/PeleLMeX_Projection.cpp +++ b/Source/PeleLMeX_Projection.cpp @@ -28,15 +28,19 @@ PeleLM::initialProjection() grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev]); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - auto const& state_ma = ldata_p->state.const_arrays(); - auto const& sigma_ma = sigma[lev]->arrays(); - amrex::ParallelFor( - ldata_p->state, [state_ma, sigma_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - amrex::Array4 rho(state_ma[box_no], DENSITY); - sigma_ma[box_no](i, j, k) = dummy_dt / rho(i, j, k); - }); - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + amrex::Box const& bx = mfi.tilebox(); + auto const& rho_arr = ldata_p->state.const_array(mfi, DENSITY); + auto const& sig_arr = sigma[lev]->array(mfi); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + sig_arr(i, j, k) = dummy_dt / rho_arr(i, j, k); + }); + } #if AMREX_SPACEDIM == 2 if (geom[lev].IsRZ()) { scaleProj_RZ(lev, *sigma[lev]); @@ -152,15 +156,19 @@ PeleLM::initialPressProjection() grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev])); auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - auto const& state_ma = ldata_p->state.const_arrays(); - auto const& sigma_ma = sigma[lev]->arrays(); - amrex::ParallelFor( - ldata_p->state, [state_ma, sigma_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - amrex::Array4 rho(state_ma[box_no], DENSITY); - sigma_ma[box_no](i, j, k) = dummy_dt / rho(i, j, k); - }); - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + amrex::Box const& bx = mfi.tilebox(); + auto const& rho_arr = ldata_p->state.const_array(mfi, DENSITY); + auto const& sig_arr = sigma[lev]->array(mfi); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + sig_arr(i, j, k) = dummy_dt / rho_arr(i, j, k); + }); + } #if AMREX_SPACEDIM == 2 if (geom[lev].IsRZ()) { scaleProj_RZ(lev, *sigma[lev]); @@ -212,15 +220,19 @@ PeleLM::velocityProjection( sigma[lev] = std::make_unique( grids[lev], dmap[lev], 1, nGhost, amrex::MFInfo(), *m_factory[lev]); - auto const& rhoHalf_ma = rhoHalf[lev]->const_arrays(); - auto const& sigma_ma = sigma[lev]->arrays(); - - amrex::ParallelFor( - *rhoHalf[lev], [rhoHalf_ma, sigma_ma, dt = a_dt] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - sigma_ma[box_no](i, j, k) = dt / rhoHalf_ma[box_no](i, j, k); - }); - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(*rhoHalf[lev], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + amrex::Box const& bx = mfi.tilebox(); + auto const& rho_arr = rhoHalf[lev]->const_array(mfi); + auto const& sig_arr = sigma[lev]->array(mfi); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + sig_arr(i, j, k) = a_dt / rho_arr(i, j, k); + }); + } #ifdef AMREX_USE_EB EB_set_covered(*sigma[lev], 0.0); #endif @@ -233,42 +245,37 @@ PeleLM::velocityProjection( } if (incremental == 0) { + amrex::Vector> rhoHalf(finest_level + 1); if (m_incompressible == 0) { - amrex::Vector> rhoHalf = - getDensityVect(a_rhoTime); - for (int lev = 0; lev <= finest_level; ++lev) { - auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); - auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - auto const& state_old_ma = ldataOld_p->state.arrays(); - auto const& gp_new_ma = ldataNew_p->gp.const_arrays(); - auto const& rho_ma = rhoHalf[lev]->const_arrays(); - amrex::ParallelFor( - ldataNew_p->state, amrex::IntVect(0), AMREX_SPACEDIM, - [state_old_ma, gp_new_ma, rho_ma, dt = a_dt] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 vel(state_old_ma[box_no], VELX); - const amrex::Real soverrho = dt / rho_ma[box_no](i, j, k); - vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; - }); - // Shift outside? (w/below) - amrex::Gpu::streamSynchronize(); - } - } else { - for (int lev = 0; lev <= finest_level; ++lev) { - auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); - auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); - auto const& state_old_ma = ldataOld_p->state.arrays(); - auto const& gp_new_ma = ldataNew_p->gp.const_arrays(); - const amrex::Real soverrho = m_dt / m_rho; + rhoHalf = getDensityVect(a_rhoTime); + } + for (int lev = 0; lev <= finest_level; ++lev) { + + auto* ldataOld_p = getLevelDataPtr(lev, AmrOldTime); + auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); + +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldataNew_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + amrex::Box const& bx = mfi.tilebox(); + auto const& vel_arr = ldataNew_p->state.array(mfi, VELX); + auto const& gp_arr = ldataOld_p->gp.const_array(mfi); + auto const& rho_arr = (m_incompressible) != 0 + ? amrex::Array4() + : rhoHalf[lev]->const_array(mfi); + const auto incompressible = m_incompressible; + const auto rho = m_rho; amrex::ParallelFor( - ldataNew_p->state, amrex::IntVect(0), AMREX_SPACEDIM, - [state_old_ma, gp_new_ma, soverrho] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 vel(state_old_ma[box_no], VELX); - vel(i, j, k, n) += gp_new_ma[box_no](i, j, k, n) * soverrho; + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::Real soverrho = + (incompressible) != 0 ? a_dt / rho : a_dt / rho_arr(i, j, k); + AMREX_D_TERM(vel_arr(i, j, k, 0) += gp_arr(i, j, k, 0) * soverrho; + , vel_arr(i, j, k, 1) += gp_arr(i, j, k, 1) * soverrho; + , + vel_arr(i, j, k, 2) += gp_arr(i, j, k, 2) * soverrho); }); - // Shift outside? - amrex::Gpu::streamSynchronize(); } } } @@ -337,21 +344,24 @@ PeleLM::velocityProjection( rhs_cc.emplace_back( grids[lev], dmap[lev], 1, ldataOld_p->divu.nGrow(), amrex::MFInfo(), *m_factory[lev]); - - auto const& divu_o_ma = ldataOld_p->divu.const_arrays(); - auto const& divu_n_ma = ldataNew_p->divu.const_arrays(); - auto const& rhs_ma = rhs_cc[lev].arrays(); - - amrex::ParallelFor( - rhs_cc[lev], rhs_cc[lev].nGrowVect(), - [divu_o_ma, divu_n_ma, - rhs_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - rhs_ma[box_no](i, j, k) = - -(divu_n_ma[box_no](i, j, k) - divu_o_ma[box_no](i, j, k)); - }); - amrex::Gpu::streamSynchronize(); - if (m_closed_chamber != 0) { - rhs_cc[lev].plus(SbarNew - SbarOld, 0, 1, ldataOld_p->divu.nGrow()); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(rhs_cc[lev], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& gbx = mfi.growntilebox(); + const auto& divu_o = ldataOld_p->divu.const_array(mfi); + const auto& divu_n = ldataNew_p->divu.const_array(mfi); + const auto& rhs = rhs_cc[lev].array(mfi); + const auto is_closed_ch = m_closed_chamber; + amrex::ParallelFor( + gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + rhs(i, j, k) = -(divu_n(i, j, k) - divu_o(i, j, k)); + if (is_closed_ch != 0) { + rhs(i, j, k) += + SbarNew - SbarOld; // subtract the mean, but rhs's already - + } + }); } } #ifdef AMREX_USE_EB @@ -556,15 +566,19 @@ PeleLM::scaleProj_RZ( // NOLINT(readability-convert-member-functions-to-static) } const amrex::Real dr = geom[a_lev].CellSize()[0]; auto const& mf_ma = a_mf.arrays(); + const auto ncomp = a_mf.nComp(); amrex::ParallelFor( - a_mf, a_mf.nGrowVect(), a_mf.nComp(), - [mf_ma, dr, - domain] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { + a_mf, a_mf.nGrowVect(), + [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { auto mf = mf_ma[box_no]; if (domain.contains(i, j, k)) { - mf(i, j, k, n) *= (static_cast(i) + 0.5) * dr; + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) *= (static_cast(i) + 0.5) * dr; + } } else { - mf(i, j, k, n) = 0.0; + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) = 0.0; + } } }); amrex::Gpu::streamSynchronize(); @@ -580,15 +594,19 @@ PeleLM:: const amrex::Box& domain = geom[a_lev].Domain(); const amrex::Real dr = geom[a_lev].CellSize()[0]; auto const& mf_ma = a_mf.arrays(); + const auto ncomp = a_mf.nComp(); amrex::ParallelFor( - a_mf, a_mf.nGrowVect(), a_mf.nComp(), - [mf_ma, dr, - domain] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { + a_mf, a_mf.nGrowVect(), + [=] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { auto mf = mf_ma[box_no]; if (domain.contains(i, j, k)) { - mf(i, j, k, n) /= (static_cast(i) + 0.5) * dr; + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) /= (static_cast(i) + 0.5) * dr; + } } else { - mf(i, j, k, n) = 0.0; + for (int n = 0; n < ncomp; ++n) { + mf(i, j, k, n) = 0.0; + } } }); amrex::Gpu::streamSynchronize(); diff --git a/Source/PeleLMeX_Reactions.cpp b/Source/PeleLMeX_Reactions.cpp index 1e4944e2b..3cd8668b3 100644 --- a/Source/PeleLMeX_Reactions.cpp +++ b/Source/PeleLMeX_Reactions.cpp @@ -144,34 +144,35 @@ PeleLM::advanceChemistry( // Set reaction term - auto const& state_o_ma = ldataOld_p->state.const_arrays(); - auto const& state_n_ma = ldataNew_p->state.const_arrays(); - auto const& extF_ma = a_extForcing.const_arrays(); - auto const& rhoYdot_ma = ldataR_p->I_R.arrays(); - const amrex::Real dt_inv = 1.0 / a_dt; - amrex::ParallelFor( - ldataNew_p->state, amrex::IntVect(0), NUM_SPECIES, - [state_o_ma, state_n_ma, extF_ma, rhoYdot_ma, - dt_inv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 rhoY_o(state_o_ma[box_no], FIRSTSPEC); - amrex::Array4 rhoY_n(state_n_ma[box_no], FIRSTSPEC); - rhoYdot_ma[box_no](i, j, k, n) = - -(rhoY_o(i, j, k, n) - rhoY_n(i, j, k, n)) * dt_inv - - extF_ma[box_no](i, j, k, n); - }); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldataNew_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& rhoY_o = ldataOld_p->state.const_array(mfi, FIRSTSPEC); + auto const& rhoY_n = ldataNew_p->state.const_array(mfi, FIRSTSPEC); + auto const& extF_rhoY = a_extForcing.const_array(mfi, 0); + auto const& rhoYdot = ldataR_p->I_R.array(mfi, 0); + amrex::Real dt_inv = 1.0 / a_dt; + amrex::ParallelFor( + bx, NUM_SPECIES, + [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + rhoYdot(i, j, k, n) = + -(rhoY_o(i, j, k, n) - rhoY_n(i, j, k, n)) * dt_inv - + extF_rhoY(i, j, k, n); + }); + #ifdef PELE_USE_PLASMA - amrex::ParallelFor( - ldataNew_p->state, - [state_n_ma, state_o_ma, extF_ma, rhoYdot_ma, - dt_inv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 nE_o(state_o_ma[box_no], NE); - amrex::Array4 nE_n(state_n_ma[box_no], NE); - amrex::Array4 FnE(extF_ma[box_no], NUM_SPECIES + 1); - amrex::Array4 nEdot(rhoYdot_ma[box_no], NUM_SPECIES); + auto const& nE_o = ldataOld_p->state.const_array(mfi, NE); + auto const& nE_n = ldataNew_p->state.const_array(mfi, NE); + auto const& FnE = a_extForcing.const_array(mfi, NUM_SPECIES + 1); + auto const& nEdot = ldataR_p->I_R.array(mfi, NUM_SPECIES); + amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { nEdot(i, j, k) = -(nE_o(i, j, k) - nE_n(i, j, k)) * dt_inv - FnE(i, j, k); }); #endif - amrex::Gpu::streamSynchronize(); + } } // This advanceChemistry works with BoxArrays built such that each box @@ -323,47 +324,49 @@ PeleLM::advanceChemistryBAChem( #endif // Pass from temp state MF to leveldata and set reaction term - auto const& state_tmp_ma = StateTemp.const_arrays(); - auto const& state_o_ma = ldataOld_p->state.const_arrays(); - auto const& state_n_ma = ldataNew_p->state.arrays(); - auto const& extF_ma = a_extForcing.const_arrays(); - auto const& rhoYdot_ma = ldataR_p->I_R.arrays(); - const amrex::Real dt_inv = 1.0 / a_dt; - - amrex::ParallelFor( - ldataNew_p->state, amrex::IntVect(0), NUM_SPECIES, - [state_tmp_ma, state_n_ma, state_o_ma, extF_ma, rhoYdot_ma, - dt_inv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 rhoY_o(state_o_ma[box_no], FIRSTSPEC); - amrex::Array4 rhoY_n(state_n_ma[box_no], FIRSTSPEC); - rhoY_n(i, j, k, n) = state_tmp_ma[box_no](i, j, k, n); - rhoYdot_ma[box_no](i, j, k, n) = - -(rhoY_o(i, j, k, n) - rhoY_n(i, j, k, n)) * dt_inv - - extF_ma[box_no](i, j, k, n); - }); - amrex::ParallelFor( - ldataNew_p->state, [state_tmp_ma, state_n_ma -#ifdef PELE_USE_PLASMA - , - state_o_ma, extF_ma, rhoYdot_ma, nE_tmp_ma, dt_inv +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif - ] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rhoH_n(state_n_ma[box_no], RHOH); - amrex::Array4 temp_n(state_n_ma[box_no], TEMP); - rhoH_n(i, j, k) = state_tmp_ma[box_no](i, j, k, NUM_SPECIES); - temp_n(i, j, k) = state_tmp_ma[box_no](i, j, k, NUM_SPECIES + 1); + for (amrex::MFIter mfi(ldataNew_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& state_arr = StateTemp.const_array(mfi); + auto const& rhoY_o = ldataOld_p->state.const_array(mfi, FIRSTSPEC); + auto const& rhoY_n = ldataNew_p->state.array(mfi, FIRSTSPEC); + auto const& rhoH_n = ldataNew_p->state.array(mfi, RHOH); + auto const& temp_n = ldataNew_p->state.array(mfi, TEMP); + auto const& extF_rhoY = a_extForcing.const_array(mfi, 0); + auto const& rhoYdot = ldataR_p->I_R.array(mfi, 0); + amrex::Real dt_inv = 1.0 / a_dt; + amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + // Pass into leveldata_new + for (int n = 0; n < NUM_SPECIES; n++) { + rhoY_n(i, j, k, n) = state_arr(i, j, k, n); + } + rhoH_n(i, j, k) = state_arr(i, j, k, NUM_SPECIES); + temp_n(i, j, k) = state_arr(i, j, k, NUM_SPECIES + 1); + // Compute I_R + for (int n = 0; n < NUM_SPECIES; n++) { + rhoYdot(i, j, k, n) = + -(rhoY_o(i, j, k, n) - rhoY_n(i, j, k, n)) * dt_inv - + extF_rhoY(i, j, k, n); + } + }); + #ifdef PELE_USE_PLASMA - amrex::Array4 nE_n(state_n_ma[box_no], NE); - amrex::Array4 nE_o(state_o_ma[box_no], NE); - amrex::Array4 FnE(extF_ma[box_no], NUM_SPECIES + 1); - amrex::Array4 nEdot(rhoYdot_ma[box_no], NUM_SPECIES); + auto const& nE_arr = nETemp.const_array(mfi); + auto const& nE_o = ldataOld_p->state.const_array(mfi, NE); + auto const& nE_n = ldataNew_p->state.array(mfi, NE); + auto const& FnE = a_extForcing.const_array(mfi, NUM_SPECIES + 1); + auto const& nEdot = ldataR_p->I_R.array(mfi, NUM_SPECIES); + amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Pass into leveldata_new - nE_n(i, j, k) = nE_tmp_ma[box_no](i, j, k); + nE_n(i, j, k) = nE_arr(i, j, k); // Compute I_R nEdot(i, j, k) = -(nE_o(i, j, k) - nE_n(i, j, k)) * dt_inv - FnE(i, j, k); -#endif }); - amrex::Gpu::streamSynchronize(); +#endif + } } void @@ -449,32 +452,30 @@ PeleLM::getScalarReactForce(const std::unique_ptr& advData) auto* ldataNew_p = getLevelDataPtr(lev, AmrNewTime); auto* ldataR_p = getLevelDataReactPtr(lev); - auto const& state_o_ma = ldataOld_p->state.const_arrays(); - auto const& state_n_ma = ldataNew_p->state.const_arrays(); - auto const& react_ma = ldataR_p->I_R.const_arrays(); - auto const& extF_ma = advData->Forcing[lev].arrays(); - const amrex::Real dtinv = 1.0 / m_dt; - - amrex::ParallelFor( - advData->Forcing[lev], amrex::IntVect(0), NUM_SPECIES, - [state_o_ma, state_n_ma, extF_ma, react_ma, dtinv] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - amrex::Array4 rhoY_n(state_n_ma[box_no], FIRSTSPEC); - amrex::Array4 rhoY_o(state_o_ma[box_no], FIRSTSPEC); - extF_ma[box_no](i, j, k, n) = - (rhoY_n(i, j, k, n) - rhoY_o(i, j, k, n)) * dtinv - - react_ma[box_no](i, j, k, n); - }); - amrex::ParallelFor( - advData->Forcing[lev], - [state_o_ma, state_n_ma, extF_ma, - dtinv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 extF_rhoH(extF_ma[box_no], NUM_SPECIES); - amrex::Array4 rhoH_n(state_n_ma[box_no], RHOH); - amrex::Array4 rhoH_o(state_o_ma[box_no], RHOH); - extF_rhoH(i, j, k) = (rhoH_n(i, j, k) - rhoH_o(i, j, k)) * dtinv; - }); - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(advData->Forcing[lev], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& rhoY_o = ldataOld_p->state.const_array(mfi, FIRSTSPEC); + auto const& rhoH_o = ldataOld_p->state.const_array(mfi, RHOH); + auto const& rhoY_n = ldataNew_p->state.const_array(mfi, FIRSTSPEC); + auto const& rhoH_n = ldataNew_p->state.const_array(mfi, RHOH); + auto const& react = ldataR_p->I_R.const_array(mfi, 0); + auto const& extF_rhoY = advData->Forcing[lev].array(mfi, 0); + auto const& extF_rhoH = advData->Forcing[lev].array(mfi, NUM_SPECIES); + amrex::Real dtinv = 1.0 / m_dt; + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + for (int n = 0; n < NUM_SPECIES; n++) { + extF_rhoY(i, j, k, n) = + (rhoY_n(i, j, k, n) - rhoY_o(i, j, k, n)) * dtinv - + react(i, j, k, n); + } + extF_rhoH(i, j, k) = (rhoH_n(i, j, k) - rhoH_o(i, j, k)) * dtinv; + }); + } } } @@ -483,27 +484,28 @@ PeleLM::getHeatRelease(const int a_lev, amrex::MultiFab* a_HR) { auto* ldataNew_p = getLevelDataPtr(a_lev, AmrNewTime); auto* ldataR_p = getLevelDataReactPtr(a_lev); - auto const* leosparm = eos_parms.device_parm(); - auto const& react_ma = ldataR_p->I_R.const_arrays(); - auto const& state_n_ma = ldataNew_p->state.const_arrays(); - amrex::MultiFab Enth(grids[a_lev], dmap[a_lev], NUM_SPECIES, 0); - auto const& enth_ma = Enth.arrays(); - amrex::ParallelFor( - *a_HR, [state_n_ma, enth_ma, leosparm] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - amrex::Array4 T(state_n_ma[box_no], TEMP); - getHGivenT(i, j, k, T, enth_ma[box_no], leosparm); - }); - amrex::Gpu::streamSynchronize(); - a_HR->setVal(0.0); - auto const& HRR_ma = a_HR->arrays(); - amrex::ParallelFor( - *a_HR, amrex::IntVect(0), NUM_SPECIES, - [react_ma, HRR_ma, enth_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k, int n) noexcept { - HRR_ma[box_no](i, j, k) -= - enth_ma[box_no](i, j, k, n) * react_ma[box_no](i, j, k, n); - }); - amrex::Gpu::streamSynchronize(); + +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + { + for (amrex::MFIter mfi(*a_HR, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + amrex::FArrayBox EnthFab(bx, NUM_SPECIES, amrex::The_Async_Arena()); + auto const& react = ldataR_p->I_R.const_array(mfi, 0); + auto const& T = ldataNew_p->state.const_array(mfi, TEMP); + auto const& Hi = EnthFab.array(); + auto const& HRR = a_HR->array(mfi); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + getHGivenT(i, j, k, T, Hi, leosparm); + HRR(i, j, k) = 0.0; + for (int n = 0; n < NUM_SPECIES; n++) { + HRR(i, j, k) -= Hi(i, j, k, n) * react(i, j, k, n); + } + }); + } + } } diff --git a/Source/PeleLMeX_Soot.cpp b/Source/PeleLMeX_Soot.cpp index ded250cfd..a4636cfb0 100644 --- a/Source/PeleLMeX_Soot.cpp +++ b/Source/PeleLMeX_Soot.cpp @@ -57,22 +57,26 @@ PeleLM::clipSootMoments() SootData* sd = soot_model->getSootData_d(); for (int lev = 0; lev <= finest_level; ++lev) { auto* ldata_p = getLevelDataPtr(lev, AmrNewTime); - auto const& state_ma = ldata_p->state.arrays(); - amrex::ParallelFor( - ldata_p->state, [state_ma, sd] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - amrex::Array4 state_arr(state_ma[box_no], FIRSTSOOT); - amrex::GpuArray moments; - for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; ++mom) { - moments[mom] = state_arr(i, j, k, mom); - } - sd->momConvClipConv(moments.data()); - for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; ++mom) { - state_arr(i, j, k, mom) = moments[mom]; - } - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + amrex::Box const& gbx = mfi.tilebox(); + auto const& state_arr = ldata_p->state.array(mfi, FIRSTSOOT); + SootData* sd = soot_model->getSootData_d(); + amrex::ParallelFor( + gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::GpuArray moments; + for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; mom++) { + moments[mom] = state_arr(i, j, k, mom); + } + sd->momConvClipConv(moments.data()); + for (int mom = 0; mom < NUM_SOOT_MOMENTS + 1; mom++) { + state_arr(i, j, k, mom) = moments[mom]; + } + }); + } } } diff --git a/Source/PeleLMeX_Timestep.cpp b/Source/PeleLMeX_Timestep.cpp index 9a491e113..ecafa68c3 100644 --- a/Source/PeleLMeX_Timestep.cpp +++ b/Source/PeleLMeX_Timestep.cpp @@ -240,21 +240,24 @@ PeleLM::checkDt(const TimeStamp a_time, const amrex::Real a_dt) const amrex::GpuArray dxinv = geom[lev].InvCellSizeArray(); - auto const& state_ma = ldata_p->state.const_arrays(); - auto const& divu_ma = ldata_p->divu.const_arrays(); - - amrex::ParallelFor( - ldata_p->state, - [state_ma, divu_ma, dxinv, a_dt, divu_checkFlag = m_divu_checkFlag, - dtfac = m_divu_dtFactor, - rhoMin = - m_divu_rhoMin] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rho(state_ma[box_no], DENSITY); - amrex::Array4 vel(state_ma[box_no], VELX); - amrex::Array4 divu = divu_ma[box_no]; - check_divu_dt( - i, j, k, divu_checkFlag, dtfac, rhoMin, dxinv, rho, vel, divu, a_dt); - }); - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& rho = ldata_p->state.const_array(mfi, DENSITY); + auto const& vel = ldata_p->state.const_array(mfi, VELX); + auto const& divu = ldata_p->divu.const_array(mfi); + int divu_checkFlag = m_divu_checkFlag; + auto dtfac = m_divu_dtFactor; + auto rhoMin = m_divu_rhoMin; + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + check_divu_dt( + i, j, k, divu_checkFlag, dtfac, rhoMin, dxinv, rho, vel, divu, + a_dt); + }); + } } } diff --git a/Source/PeleLMeX_UMac.cpp b/Source/PeleLMeX_UMac.cpp index 88e9bf5fa..ee16ba1b9 100644 --- a/Source/PeleLMeX_UMac.cpp +++ b/Source/PeleLMeX_UMac.cpp @@ -108,93 +108,46 @@ PeleLM::addChiIncrement( // Add chiIncr to chi and add chi to mac_divu // Both mac_divu and chiIncr have properly filled ghost cells -> work on // grownbox - - if (a_sdcIter == 1) { - switch (m_chi_correction_type) { - case ChiCorrectionType::DivuFirstIter: { - for (int lev = 0; lev <= finest_level; ++lev) { - auto const& chiInc_ma = chiIncr[lev].const_arrays(); - auto const& chi_ma = advData->chi[lev].arrays(); - auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); - amrex::ParallelFor( - advData->chi[lev], advData->chi[lev].nGrowVect(), - [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - chi_ma[box_no](i, j, k) = - chiInc_ma[box_no](i, j, k) + mac_divu_ma[box_no](i, j, k); - mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); - } - break; - } - case ChiCorrectionType::NoDivu: { - for (int lev = 0; lev <= finest_level; ++lev) { - auto const& chiInc_ma = chiIncr[lev].const_arrays(); - auto const& chi_ma = advData->chi[lev].arrays(); - auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); - amrex::ParallelFor( - advData->chi[lev], advData->chi[lev].nGrowVect(), - [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - chi_ma[box_no](i, j, k) = chiInc_ma[box_no](i, j, k); - mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); - } - break; - } - default: { - for (int lev = 0; lev <= finest_level; ++lev) { - auto const& chiInc_ma = chiIncr[lev].const_arrays(); - auto const& chi_ma = advData->chi[lev].arrays(); - auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); + for (int lev = 0; lev <= finest_level; ++lev) { +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(advData->chi[lev], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& gbx = mfi.growntilebox(); + auto const& chiInc_ar = chiIncr[lev].const_array(mfi); + auto const& chi_ar = advData->chi[lev].array(mfi); + auto const& mac_divu_ar = advData->mac_divu[lev].array(mfi); + if (m_chi_correction_type == ChiCorrectionType::DivuFirstIter) { amrex::ParallelFor( - advData->chi[lev], advData->chi[lev].nGrowVect(), - [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - chi_ma[box_no](i, j, k) = chiInc_ma[box_no](i, j, k); - mac_divu_ma[box_no](i, j, k) += chi_ma[box_no](i, j, k); + gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + if (a_sdcIter == 1) { + chi_ar(i, j, k) = chiInc_ar(i, j, k) + mac_divu_ar(i, j, k); + } else { + chi_ar(i, j, k) += chiInc_ar(i, j, k); + } + mac_divu_ar(i, j, k) = chi_ar(i, j, k); }); - // Shift outside? - amrex::Gpu::streamSynchronize(); - } - } - } - } else { - if ( - m_chi_correction_type == ChiCorrectionType::DivuFirstIter || - m_chi_correction_type == ChiCorrectionType::NoDivu) { - for (int lev = 0; lev <= finest_level; ++lev) { - auto const& chiInc_ma = chiIncr[lev].const_arrays(); - auto const& chi_ma = advData->chi[lev].arrays(); - auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); + } else if (m_chi_correction_type == ChiCorrectionType::NoDivu) { amrex::ParallelFor( - advData->chi[lev], advData->chi[lev].nGrowVect(), - [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - chi_ma[box_no](i, j, k) += chiInc_ma[box_no](i, j, k); - mac_divu_ma[box_no](i, j, k) = chi_ma[box_no](i, j, k); + gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + if (a_sdcIter == 1) { + chi_ar(i, j, k) = chiInc_ar(i, j, k); + } else { + chi_ar(i, j, k) += chiInc_ar(i, j, k); + } + mac_divu_ar(i, j, k) = chi_ar(i, j, k); }); - // Shift outside? - amrex::Gpu::streamSynchronize(); - } - } else { - for (int lev = 0; lev <= finest_level; ++lev) { - auto const& chiInc_ma = chiIncr[lev].const_arrays(); - auto const& chi_ma = advData->chi[lev].arrays(); - auto const& mac_divu_ma = advData->mac_divu[lev].arrays(); + } else { // Default: use updated divu every iteration amrex::ParallelFor( - advData->chi[lev], advData->chi[lev].nGrowVect(), - [chi_ma, chiInc_ma, mac_divu_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - chi_ma[box_no](i, j, k) += chiInc_ma[box_no](i, j, k); - mac_divu_ma[box_no](i, j, k) += chi_ma[box_no](i, j, k); + gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + if (a_sdcIter == 1) { + chi_ar(i, j, k) = chiInc_ar(i, j, k); + } else { + chi_ar(i, j, k) += chiInc_ar(i, j, k); + } + mac_divu_ar(i, j, k) += chi_ar(i, j, k); }); - // Shift outside? - amrex::Gpu::streamSynchronize(); } } } diff --git a/Source/Plasma/PeleLMeX_EFIonDrift.cpp b/Source/Plasma/PeleLMeX_EFIonDrift.cpp index ca26ebc10..86e690b68 100644 --- a/Source/Plasma/PeleLMeX_EFIonDrift.cpp +++ b/Source/Plasma/PeleLMeX_EFIonDrift.cpp @@ -59,20 +59,21 @@ PeleLM::ionDriftVelocity(const std::unique_ptr& advData) amrex::MultiFab mobH_cc(grids[lev], dmap[lev], NUM_IONS, 1); - auto const& mob_o_ma = ldataOld_p->mob_cc.const_arrays(); - auto const& mob_n_ma = ldataNew_p->mob_cc.const_arrays(); - auto const& mob_h_ma = mobH_cc.arrays(); - - amrex::ParallelFor( - mobH_cc, mobH_cc.nGrowVect(), - [mob_o_ma, mob_n_ma, - mob_h_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < NUM_IONS; ++n) { - mob_h_ma[box_no](i, j, k, n) = - 0.5 * (mob_o_ma[box_no](i, j, k, n) + mob_n_ma[box_no](i, j, k, n)); - } - }); - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(mobH_cc, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& gbx = mfi.growntilebox(); + const auto& mob_o = ldataOld_p->mob_cc.const_array(mfi); + const auto& mob_n = ldataNew_p->mob_cc.const_array(mfi); + const auto& mob_h = mobH_cc.array(mfi); + amrex::ParallelFor( + gbx, NUM_IONS, + [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + mob_h(i, j, k, n) = 0.5 * (mob_o(i, j, k, n) + mob_n(i, j, k, n)); + }); + } // Get the face centered ions mobility constexpr int doZeroVisc = 0; amrex::Array mobH_ec = @@ -80,21 +81,23 @@ PeleLM::ionDriftVelocity(const std::unique_ptr& advData) // Assemble the ions drift velocity for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - auto const& mob_h_ma = mobH_ec[idim].const_arrays(); - auto const& gp_o_ma = gphiVOld[lev][idim].const_arrays(); - auto const& gp_n_ma = gphiVNew[lev][idim].const_arrays(); - auto const& Ud_Sp_ma = advData->uDrift[lev][idim].arrays(); - amrex::ParallelFor( - mobH_ec[idim], [mob_h_ma, gp_o_ma, gp_n_ma, Ud_Sp_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - for (int n = 0; n < NUM_IONS; ++n) { - Ud_Sp_ma[box_no](i, j, k, n) = - mob_h_ma[box_no](i, j, k, n) * -0.5 * - (gp_o_ma[box_no](i, j, k) + gp_n_ma[box_no](i, j, k)); - } - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(mobH_ec[idim], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box bx = mfi.tilebox(); + const auto& mob_h = mobH_ec[idim].const_array(mfi); + const auto& gp_o = gphiVOld[lev][idim].const_array(mfi); + const auto& gp_n = gphiVNew[lev][idim].const_array(mfi); + const auto& Ud_Sp = advData->uDrift[lev][idim].array(mfi); + amrex::ParallelFor( + bx, NUM_IONS, + [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + Ud_Sp(i, j, k, n) = + mob_h(i, j, k, n) * -0.5 * (gp_o(i, j, k) + gp_n(i, j, k)); + }); + } } } diff --git a/Source/Plasma/PeleLMeX_EFNLSolve.cpp b/Source/Plasma/PeleLMeX_EFNLSolve.cpp index dad8c0c37..851b5775c 100644 --- a/Source/Plasma/PeleLMeX_EFNLSolve.cpp +++ b/Source/Plasma/PeleLMeX_EFNLSolve.cpp @@ -324,40 +324,28 @@ PeleLM::incrementElectronForcing( auto ldataR_p = getLevelDataReactPtr(lev); // Reaction auto ldataNLs_p = getLevelDataNLSolvePtr(lev); // NL data - auto const& state_o_ma = ldata_p->state.const_arrays(); - auto const& nE_n_ma = ldataNLs_p->nlState.const_arrays(); - auto const& I_R_ma = ldataR_p->I_R.const_arrays(); - auto const& F_ma = advData->Forcing[lev].arrays(); - const amrex::Real scaling = nE_scale; - const amrex::Real dtinv = 1.0 / dtsub; - if (a_sstep == 0) { - amrex::ParallelFor( - ldata_p->state, - [state_o_ma, nE_n_ma, I_R_ma, F_ma, scaling, - dtinv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 nE_o(state_o_ma[box_no], NE); - amrex::Array4 I_R_nE(I_R_ma[box_no], NUM_SPECIES); - amrex::Array4 FnE(F_ma[box_no], NUM_SPECIES + 1); - FnE(i, j, k) = - (nE_n_ma[box_no](i, j, k) * scaling - nE_o(i, j, k)) * dtinv - - I_R_nE(i, j, k); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); - } else { +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& nE_o = ldata_p->state.const_array(mfi, NE); + auto const& nE_n = ldataNLs_p->nlState.const_array(mfi); + auto const& I_R_nE = ldataR_p->I_R.const_array(mfi, NUM_SPECIES); + auto const& FnE = advData->Forcing[lev].array(mfi, NUM_SPECIES + 1); + amrex::Real scaling = nE_scale; + amrex::Real dtinv = 1.0 / dtsub; amrex::ParallelFor( - ldata_p->state, - [state_o_ma, nE_n_ma, I_R_ma, F_ma, scaling, - dtinv] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 nE_o(state_o_ma[box_no], NE); - amrex::Array4 I_R_nE(I_R_ma[box_no], NUM_SPECIES); - amrex::Array4 FnE(F_ma[box_no], NUM_SPECIES + 1); - FnE(i, j, k) += - (nE_n_ma[box_no](i, j, k) * scaling - nE_o(i, j, k)) * dtinv - - I_R_nE(i, j, k); + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + if (a_sstep == 0) { + FnE(i, j, k) = (nE_n(i, j, k) * scaling - nE_o(i, j, k)) * dtinv - + I_R_nE(i, j, k); + } else { + FnE(i, j, k) += (nE_n(i, j, k) * scaling - nE_o(i, j, k)) * dtinv - + I_R_nE(i, j, k); + } }); - // Shift outside? - amrex::Gpu::streamSynchronize(); } } } @@ -377,37 +365,36 @@ PeleLM::computeBGcharge( auto ldataR_p = getLevelDataReactPtr(lev); // Reaction auto ldataNLs_p = getLevelDataNLSolvePtr(lev); // NL data - auto const& state_old_ma = ldata_p->state.const_arrays(); - auto const& adv_ma = advData->AofS[lev].const_arrays(); - auto const& dn_ma = diffData->Dn[lev].const_arrays(); - auto const& dnp1_ma = diffData->Dnp1[lev].const_arrays(); - auto const& dhat_ma = diffData->Dhat[lev].const_arrays(); - auto const& rhoYdot_ma = ldataR_p->I_R.const_arrays(); - auto const& charge_ma = ldataNLs_p->backgroundCharge.arrays(); - amrex::ParallelFor( - ldataNLs_p->backgroundCharge, - [state_old_ma, adv_ma, dn_ma, dnp1_ma, dhat_ma, rhoYdot_ma, charge_ma, - dt_int, - zk = zk] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 rhoYold( - state_old_ma[box_no], FIRSTSPEC); - amrex::Array4 adv(adv_ma[box_no], FIRSTSPEC); - charge_ma[box_no](i, j, k) = 0.0; - constexpr amrex::Real factor = 1.0 / elemCharge; - for (int n = 0; n < NUM_SPECIES; ++n) { - amrex::Real rhoYprov = - rhoYold(i, j, k, n) + - dt_int * - (adv(i, j, k, n) + - 0.5 * (dn_ma[box_no](i, j, k, n) - dnp1_ma[box_no](i, j, k, n)) + - dhat_ma[box_no](i, j, k, n) + rhoYdot_ma[box_no](i, j, k, n)); - rhoYprov = amrex::max(rhoYprov, 0.0); - charge_ma[box_no](i, j, k) += zk[n] * rhoYprov; - } - charge_ma[box_no](i, j, k) *= factor; - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi( + ldataNLs_p->backgroundCharge, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& rhoYold = ldata_p->state.const_array(mfi, FIRSTSPEC); + auto const& adv_arr = advData->AofS[lev].const_array(mfi, FIRSTSPEC); + auto const& dn_arr = diffData->Dn[lev].const_array(mfi); + auto const& dnp1_arr = diffData->Dnp1[lev].const_array(mfi); + auto const& dhat_arr = diffData->Dhat[lev].const_array(mfi); + auto const& rhoYdot = ldataR_p->I_R.const_array(mfi); + auto const& charge = ldataNLs_p->backgroundCharge.array(mfi); + amrex::Real factor = 1.0 / elemCharge; + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + charge(i, j, k) = 0.0; + for (int n = 0; n < NUM_SPECIES; n++) { + amrex::Real rhoYprov = + rhoYold(i, j, k, n) + + dt_int * (adv_arr(i, j, k, n) + + 0.5 * (dn_arr(i, j, k, n) - dnp1_arr(i, j, k, n)) + + dhat_arr(i, j, k, n) + rhoYdot(i, j, k, n)); + rhoYprov = amrex::max(rhoYprov, 0.0); + charge(i, j, k) += zk[n] * rhoYprov; + } + charge(i, j, k) *= factor; + }); + } } } @@ -498,36 +485,33 @@ PeleLM::nonLinearResidual( // Init the ghostcells too a_nlresid[lev]->setVal(0.0); - - auto const& I_R_ma = ldataR_p->I_R.const_arrays(); - auto const& lapPhiV_ma = laplacian[lev].const_arrays(); - auto const& ne_diff_ma = diffnE[lev].const_arrays(); - auto const& ne_adv_ma = advnE[lev].const_arrays(); - auto const& ne_curr_ma = nE[lev].const_arrays(); - auto const& state_old_ma = ldataOld_p->state.const_arrays(); - auto const& charge_ma = ldataNLs_p->backgroundCharge.const_arrays(); - auto const& res_ma = a_nlresid[lev]->arrays(); - amrex::ParallelFor( - ldataNLs_p->nlResid, - [I_R_ma, lapPhiV_ma, ne_diff_ma, ne_adv_ma, ne_curr_ma, state_old_ma, - charge_ma, res_ma, - a_dt] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 res_nE(res_ma[box_no], 0); - amrex::Array4 res_phiV(res_ma[box_no], 1); - amrex::Array4 I_R_nE(I_R_ma[box_no], NUM_SPECIES); - amrex::Array4 ne_old(state_old_ma[box_no], NE); - res_nE(i, j, k) = ne_old(i, j, k) - ne_curr_ma[box_no](i, j, k) + - a_dt * (ne_diff_ma[box_no](i, j, k) + - ne_adv_ma[box_no](i, j, k) + I_R_nE(i, j, k)); - constexpr amrex::Real scalLap = eps0 * epsr / elemCharge; - res_phiV(i, j, k) = lapPhiV_ma[box_no](i, j, k) * scalLap - - ne_curr_ma[box_no](i, j, k) + - charge_ma[box_no](i, j, k); - res_nE(i, j, k) *= -1.0; // NLresidual is -RHS - res_phiV(i, j, k) *= -1.0; // NLresidual is -RHS - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldataNLs_p->nlResid, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& I_R_nE = ldataR_p->I_R.const_array(mfi, NUM_SPECIES); + auto const& lapPhiV = laplacian[lev].const_array(mfi); + auto const& ne_diff = diffnE[lev].const_array(mfi); + auto const& ne_adv = advnE[lev].const_array(mfi); + auto const& ne_curr = nE[lev].const_array(mfi); + auto const& ne_old = ldataOld_p->state.const_array(mfi, NE); + auto const& charge = ldataNLs_p->backgroundCharge.const_array(mfi); + auto const& res_nE = a_nlresid[lev]->array(mfi, 0); + auto const& res_phiV = a_nlresid[lev]->array(mfi, 1); + amrex::Real scalLap = eps0 * epsr / elemCharge; + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + res_nE(i, j, k) = + ne_old(i, j, k) - ne_curr(i, j, k) + + a_dt * (ne_diff(i, j, k) + ne_adv(i, j, k) + I_R_nE(i, j, k)); + res_phiV(i, j, k) = + lapPhiV(i, j, k) * scalLap - ne_curr(i, j, k) + charge(i, j, k); + res_nE(i, j, k) *= -1.0; // NLresidual is -RHS + res_phiV(i, j, k) *= -1.0; // NLresidual is -RHS + }); + } } // WriteDebugPlotFile(GetVecOfConstPtrs(a_nlresid),"UnscalednlResid"); @@ -601,23 +585,27 @@ PeleLM::getAdvectionTerm( getDiffusivity(lev, 0, 1, doZeroVisc, bcRecnE, ldata_p->mobE_cc); // Get the electron effective velocity - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - auto const& ueff_ma = ldataNLs_p->uEffnE[idim].arrays(); - auto const& umac_ma = ldataNLs_p->umac[idim].const_arrays(); - auto const& gphi_c_ma = a_gPhiVCur[lev][idim]->const_arrays(); - auto const& gphi_o_ma = ldataNLs_p->gPhiVOld[idim].const_arrays(); - auto const& kappa_e_ma = mobE_ec[idim].const_arrays(); - amrex::ParallelFor( - ldataNLs_p->uEffnE[idim], - [ueff_ma, umac_ma, gphi_c_ma, gphi_o_ma, kappa_e_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - ueff_ma[box_no](i, j, k) = - umac_ma[box_no](i, j, k) - - kappa_e_ma[box_no](i, j, k) * -1.0 * 0.5 * - (gphi_c_ma[box_no](i, j, k) + gphi_o_ma[box_no](i, j, k)); - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); + + // Get the electron effective velocity + for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldataNLs_p->uEffnE[idim], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& ueff = ldataNLs_p->uEffnE[idim].array(mfi); + auto const& umac = ldataNLs_p->umac[idim].const_array(mfi); + auto const& gphi_c = a_gPhiVCur[lev][idim]->const_array(mfi); + auto const& gphi_o = ldataNLs_p->gPhiVOld[idim].const_array(mfi); + auto const& kappa_e = mobE_ec[idim].const_array(mfi); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + ueff(i, j, k) = + umac(i, j, k) - kappa_e(i, j, k) * -1.0 * 0.5 * + (gphi_c(i, j, k) + gphi_o(i, j, k)); + }); + } } } @@ -986,27 +974,28 @@ PeleLM::setUpPrecond( Schur_nEKe.define(grids[lev], dmap[lev], 1, 1); } - auto const& neke_ma = nEKe.arrays(); - auto const& kappaE_ma = ldata_p->mobE_cc.arrays(); - auto const& ne_arr_ma = a_nE[lev]->const_arrays(); - auto const& Schur_ma = - (m_ef_PC_approx == 2) ? Schur_nEKe.arrays() : nEKe.arrays(); - auto const& diffOp_diag_ma = - (m_ef_PC_approx == 2) ? diagDiffOp[lev].arrays() : nEKe.arrays(); - const int do_Schur = (m_ef_PC_approx == 2) ? 1 : 0; - - amrex::ParallelFor( - nEKe, nEKe.nGrowVect(), - [neke_ma, kappaE_ma, ne_arr_ma, Schur_ma, diffOp_diag_ma, a_dt, - do_Schur] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - neke_ma[box_no](i, j, k) = - kappaE_ma[box_no](i, j, k) * ne_arr_ma[box_no](i, j, k); - if (do_Schur == 1) { - Schur_ma[box_no](i, j, k) = -a_dt * 0.5 * neke_ma[box_no](i, j, k) / - diffOp_diag_ma[box_no](i, j, k); - } - }); - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(nEKe, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& gbx = mfi.growntilebox(); + auto const& neke = nEKe.array(mfi); + auto const& kappaE = ldata_p->mobE_cc.array(mfi); + auto const& ne_arr = a_nE[lev]->const_array(mfi); + auto const& Schur = + (m_ef_PC_approx == 2) ? Schur_nEKe.array(mfi) : nEKe.array(mfi); + auto const& diffOp_diag = + (m_ef_PC_approx == 2) ? diagDiffOp[lev].array(mfi) : nEKe.array(mfi); + int do_Schur = (m_ef_PC_approx == 2) ? 1 : 0; + amrex::ParallelFor( + gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + neke(i, j, k) = kappaE(i, j, k) * ne_arr(i, j, k); + if (do_Schur) { + Schur(i, j, k) = -a_dt * 0.5 * neke(i, j, k) / diffOp_diag(i, j, k); + } + }); + } // Upwinded edge neKe values amrex::Array neKe_ec = getUpwindedEdge( diff --git a/Source/Plasma/PeleLMeX_EFPoisson.cpp b/Source/Plasma/PeleLMeX_EFPoisson.cpp index 5da531a04..676fec23e 100644 --- a/Source/Plasma/PeleLMeX_EFPoisson.cpp +++ b/Source/Plasma/PeleLMeX_EFPoisson.cpp @@ -25,18 +25,24 @@ PeleLM::poissonSolveEF(const TimeStamp a_time) auto const& state_ma = ldata_p->state.const_arrays(); auto const& rhs_ma = rhsPoisson[lev]->arrays(); - amrex::ParallelFor( - ldata_p->state, [state_ma, rhs_ma, zk = zk] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - amrex::Array4 nE(state_ma[box_no], NE); - constexpr amrex::Real factor = -1.0; - rhs_ma[box_no](i, j, k) = -nE(i, j, k) * elemCharge * factor; - for (int n = 0; n < NUM_SPECIES; ++n) { - rhs_ma[box_no](i, j, k) += zk[n] * rhoY(i, j, k, n) * factor; - } - }); - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(*rhsPoisson[lev], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& rhoY = ldata_p->state.const_array(mfi, FIRSTSPEC); + auto const& nE = ldata_p->state.const_array(mfi, NE); + auto const& rhs = rhsPoisson[lev]->array(mfi); + amrex::Real factor = -1.0; // / ( eps0 * epsr); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + rhs(i, j, k) = -nE(i, j, k) * elemCharge * factor; + for (int n = 0; n < NUM_SPECIES; n++) { + rhs(i, j, k) += zk[n] * rhoY(i, j, k, n) * factor; + } + }); + } } // Solve for PhiV getDiffusionOp()->diffuse_scalar( diff --git a/Source/Plasma/PeleLMeX_EFReactions.cpp b/Source/Plasma/PeleLMeX_EFReactions.cpp index c45fd09d1..033e9954b 100644 --- a/Source/Plasma/PeleLMeX_EFReactions.cpp +++ b/Source/Plasma/PeleLMeX_EFReactions.cpp @@ -7,19 +7,21 @@ PeleLM::computeInstantaneousReactionRateEF( { auto ldata_p = getLevelDataPtr(lev, a_time); - auto const& state_ma = ldata_p->state.const_arrays(); - auto const& I_R_ma = a_I_R->arrays(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& rhoY = ldata_p->state.const_array(mfi, FIRSTSPEC); + auto const& rhoH = ldata_p->state.const_array(mfi, RHOH); + auto const& nE = ldata_p->state.const_array(mfi, NE); + auto const& T = ldata_p->state.const_array(mfi, TEMP); + auto const& rhoYdot = a_I_R->array(mfi); + auto const& nEdot = a_I_R->array(mfi, NUM_SPECIES); - amrex::ParallelFor( - ldata_p->state, [state_ma, I_R_ma] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - amrex::Array4 rhoH(state_ma[box_no], RHOH); - amrex::Array4 nE(state_ma[box_no], NE); - amrex::Array4 T(state_ma[box_no], TEMP); - amrex::Array4 rhoYdot(I_R_ma[box_no], 0); - amrex::Array4 nEdot(I_R_ma[box_no], NUM_SPECIES); + amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { reactionRateRhoY_EF(i, j, k, rhoY, rhoH, T, nE, rhoYdot, nEdot); }); - amrex::Gpu::streamSynchronize(); + } } diff --git a/Source/Plasma/PeleLMeX_EFTimeStep.cpp b/Source/Plasma/PeleLMeX_EFTimeStep.cpp index 2cbf826bd..d399cc7d0 100644 --- a/Source/Plasma/PeleLMeX_EFTimeStep.cpp +++ b/Source/Plasma/PeleLMeX_EFTimeStep.cpp @@ -23,69 +23,102 @@ PeleLM::estEFIonsDt(const TimeStamp a_time) const auto dxinv = Geom(lev).InvCellSizeArray(); const auto domain = Geom(lev).Domain(); - auto const& state_ma = ldata_p->state.const_arrays(); - auto const& efield_ma = efield_cc.arrays(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& phiV = ldata_p->state.const_array(mfi, PHIV); + auto const& efield = efield_cc.array(mfi, 0); - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - auto bc_lo = bcRecPhiV[0].lo(idim); - auto bc_hi = bcRecPhiV[0].hi(idim); - const amrex::Real factor = -0.5 * dxinv[idim]; + // X + auto bc_lo = bcRecPhiV[0].lo(0); + auto bc_hi = bcRecPhiV[0].hi(0); + amrex::Real factor = -0.5 * dxinv[0]; amrex::ParallelFor( - ldata_p->state, - [bc_lo, bc_hi, efield_ma, state_ma, factor, domain, - idim] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - int idx[3] = {i, j, k}; - amrex::Array4 phiV(state_ma[box_no], PHIV); - const bool on_lo = - ((bc_lo == amrex::BCType::ext_dir) && - idx[idim] <= domain.smallEnd(idim)); - const bool on_hi = - ((bc_hi == amrex::BCType::ext_dir) && - idx[idim] >= domain.bigEnd(idim)); - // use idx for idxp - idx[idim] += 1; - int idxm[3] = {i, j, k}; - idxm[idim] -= 1; - efield_ma[box_no](i, j, k, idim) = - factor * - (phiV(idx[0], idx[1], idx[2]) - phiV(idxm[0], idxm[1], idxm[2])); - if (on_lo) { - efield_ma[box_no](i, j, k, idim) = - factor * (phiV(idx[0], idx[1], idx[2]) + phiV(i, j, k) - - 2.0 * phiV(idxm[0], idxm[1], idxm[2])); - } - if (on_hi) { - efield_ma[box_no](i, j, k, idim) = - factor * (2.0 * phiV(idx[0], idx[1], idx[2]) - phiV(i, j, k) - - phiV(idxm[0], idxm[1], idxm[2])); - } + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bool on_lo = + ((bc_lo == amrex::BCType::ext_dir) && i <= domain.smallEnd(0)); + bool on_hi = + ((bc_hi == amrex::BCType::ext_dir) && i >= domain.bigEnd(0)); + efield(i, j, k, 0) = factor * (phiV(i + 1, j, k) - phiV(i - 1, j, k)); + if (on_lo) + efield(i, j, k, 0) = factor * (phiV(i + 1, j, k) + phiV(i, j, k) - + 2.0 * phiV(i - 1, j, k)); + if (on_hi) + efield(i, j, k, 0) = factor * (2.0 * phiV(i + 1, j, k) - + phiV(i, j, k) - phiV(i - 1, j, k)); + }); + +#if (AMREX_SPACEDIM > 1) + // Y + bc_lo = bcRecPhiV[0].lo(1); + bc_hi = bcRecPhiV[0].hi(1); + factor = -0.5 * dxinv[1]; + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bool on_lo = + ((bc_lo == amrex::BCType::ext_dir) && j <= domain.smallEnd(1)); + bool on_hi = + ((bc_hi == amrex::BCType::ext_dir) && j >= domain.bigEnd(1)); + efield(i, j, k, 1) = factor * (phiV(i, j + 1, k) - phiV(i, j - 1, k)); + if (on_lo) + efield(i, j, k, 1) = factor * (phiV(i, j + 1, k) + phiV(i, j, k) - + 2.0 * phiV(i, j - 1, k)); + if (on_hi) + efield(i, j, k, 1) = factor * (2.0 * phiV(i, j + 1, k) - + phiV(i, j, k) - phiV(i, j - 1, k)); }); - // Shift outside? - amrex::Gpu::streamSynchronize(); - } - auto const& efield_const_ma = efield_cc.const_arrays(); - auto const& mob_cc_ma = ldata_p->mob_cc.const_arrays(); - auto const& uDrMax_ma = driftVelMax_cc.arrays(); +#if (AMREX_SPACEDIM > 2) + // Z + bc_lo = bcRecPhiV[0].lo(2); + bc_hi = bcRecPhiV[0].hi(2); + factor = -0.5 * dxinv[2]; + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + bool on_lo = + ((bc_lo == amrex::BCType::ext_dir) && k <= domain.smallEnd(2)); + bool on_hi = + ((bc_hi == amrex::BCType::ext_dir) && k >= domain.bigEnd(2)); + efield(i, j, k, 2) = factor * (phiV(i, j, k + 1) - phiV(i, j, k - 1)); + if (on_lo) + efield(i, j, k, 2) = factor * (phiV(i, j, k + 1) + phiV(i, j, k) - + 2.0 * phiV(i, j, k - 1)); + if (on_hi) + efield(i, j, k, 2) = factor * (2.0 * phiV(i, j, k + 1) - + phiV(i, j, k) - phiV(i, j, k - 1)); + }); +#endif +#endif + } // Get cell centered max effective velocities across // all dimension/ions - amrex::ParallelFor( - ldata_p->state, - [state_ma, efield_const_ma, mob_cc_ma, - uDrMax_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - amrex::Array4 vel(state_ma[box_no], VELX); - amrex::Real maxVel = 0.0; - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - for (int n = 0; n < NUM_IONS; ++n) { - amrex::Real ueff = - vel(i, j, k, idim) + mob_cc_ma[box_no](i, j, k, n) * - efield_const_ma[box_no](i, j, k, idim); - maxVel = amrex::max(maxVel, std::abs(ueff)); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& vel = ldata_p->state.const_array(mfi, VELX); + auto const& efield = efield_cc.const_array(mfi); + auto const& mob_cc = ldata_p->mob_cc.const_array(mfi); + auto const& uDrMax = driftVelMax_cc.array(mfi); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + amrex::Real maxVel = 0.0; + for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + for (int n = 0; n < NUM_IONS; n++) { + amrex::Real ueff = + vel(i, j, k, idim) + mob_cc(i, j, k, n) * efield(i, j, k, idim); + maxVel = amrex::max(maxVel, std::abs(ueff)); + } } - } - uDrMax_ma[box_no](i, j, k) = maxVel; - }); - amrex::Gpu::streamSynchronize(); + uDrMax(i, j, k) = maxVel; + }); + } + const auto dx = Geom(lev).CellSizeArray(); const amrex::Real cfl_lcl = m_cfl; estdt_lev = amrex::ReduceMin( diff --git a/Source/Plasma/PeleLMeX_EFTransport.cpp b/Source/Plasma/PeleLMeX_EFTransport.cpp index 156273c23..7649cd620 100644 --- a/Source/Plasma/PeleLMeX_EFTransport.cpp +++ b/Source/Plasma/PeleLMeX_EFTransport.cpp @@ -9,25 +9,25 @@ PeleLM::calcEFTransport(const TimeStamp a_time) for (int lev = 0; lev <= finest_level; ++lev) { auto ldata_p = getLevelDataPtr(lev, a_time); auto dxinv = Geom(lev).InvCellSizeArray(); - - auto const& mobE_ma = ldata_p->mobE_cc.arrays(); - auto const& diffE_ma = ldata_p->diffE_cc.arrays(); - auto const& state_ma = ldata_p->state.const_arrays(); - const auto useTab = m_electronKappaTab; - const auto fixedKe = m_fixedKappaE; - - amrex::ParallelFor( - ldata_p->diffE_cc, ldata_p->diffE_cc.nGrowVect(), - [useTab, fixedKe, dxinv, mobE_ma, diffE_ma, - state_ma] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - constexpr amrex::Real factor = PP_RU_MKS / (Na * elemCharge); - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - amrex::Array4 phiV(state_ma[box_no], PHIV); - amrex::Array4 T(state_ma[box_no], TEMP); - getKappaE( - i, j, k, useTab, fixedKe, dxinv, rhoY, phiV, T, mobE_ma[box_no]); - getDiffE(i, j, k, factor, T, mobE_ma[box_no], diffE_ma[box_no]); - }); - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->diffE_cc, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& gbx = mfi.growntilebox(); + auto const& mobE = ldata_p->mobE_cc.array(mfi); + auto const& diffE = ldata_p->diffE_cc.array(mfi); + auto const& rhoY = ldata_p->state.const_array(mfi, FIRSTSPEC); + auto const& phiV = ldata_p->state.const_array(mfi, PHIV); + auto const& T = ldata_p->state.const_array(mfi, TEMP); + amrex::Real factor = PP_RU_MKS / (Na * elemCharge); + const auto useTab = m_electronKappaTab; + const auto fixedKe = m_fixedKappaE; + amrex::ParallelFor( + gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + getKappaE(i, j, k, useTab, fixedKe, dxinv, rhoY, phiV, T, mobE); + getDiffE(i, j, k, factor, T, mobE, diffE); + }); + } } } diff --git a/Source/Plasma/PeleLMeX_EFUtils.cpp b/Source/Plasma/PeleLMeX_EFUtils.cpp index 12a5b25cd..20a5a0a60 100644 --- a/Source/Plasma/PeleLMeX_EFUtils.cpp +++ b/Source/Plasma/PeleLMeX_EFUtils.cpp @@ -210,34 +210,42 @@ PeleLM::initializeElectronNeutral() // Get level data new time pointer auto ldata_p = getLevelDataPtr(lev, AmrNewTime); - auto const& state_ma = ldata_p->state.arrays(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldata_p->state, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& rho = ldata_p->state.array(mfi, DENSITY); + auto const& rhoY = ldata_p->state.array(mfi, FIRSTSPEC); + auto const& rhoH = ldata_p->state.array(mfi, RHOH); + auto const& temp = ldata_p->state.array(mfi, TEMP); + auto const& nE = ldata_p->state.array(mfi, NE); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + initElecNeutral(i, j, k, rho, rhoY, rhoH, temp, nE, *lprobparm); + }); + } - amrex::ParallelFor( - ldata_p->state, [state_ma, lprobparm] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - amrex::Array4 rho(state_ma[box_no], DENSITY); - amrex::Array4 rhoY(state_ma[box_no], FIRSTSPEC); - amrex::Array4 rhoH(state_ma[box_no], RHOH); - amrex::Array4 temp(state_ma[box_no], TEMP); - amrex::Array4 nE(state_ma[box_no], NE); - initElecNeutral(i, j, k, rho, rhoY, rhoH, temp, nE, *lprobparm); - }); - amrex::Gpu::streamSynchronize(); // Convert I_R(Y_nE) into I_R(nE) and set I_R(Y_nE) to zero auto ldataR_p = getLevelDataReactPtr(lev); - auto const& I_R_ma = ldataR_p->I_R.arrays(); - auto eos = pele::physics::PhysicsType::eos(); - amrex::Real invmwt[NUM_SPECIES] = {0.0}; - eos.inv_molecular_weight(invmwt); - amrex::ParallelFor( - ldataR_p->I_R, [I_R_ma, invmwt] AMREX_GPU_DEVICE( - int box_no, int i, int j, int k) noexcept { - amrex::Array4 YnEdot(I_R_ma[box_no], E_ID); - amrex::Array4 nEdot(I_R_ma[box_no], NUM_SPECIES); - nEdot(i, j, k) = YnEdot(i, j, k) * Na * invmwt[E_ID] * 1.0e3; - YnEdot(i, j, k) = 0.0; - }); - amrex::Gpu::streamSynchronize(); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(ldataR_p->I_R, amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box& bx = mfi.tilebox(); + auto const& YnEdot = ldataR_p->I_R.array(mfi, E_ID); + auto const& nEdot = ldataR_p->I_R.array(mfi, NUM_SPECIES); + auto eos = pele::physics::PhysicsType::eos(); + amrex::Real invmwt[NUM_SPECIES] = {0.0}; + eos.inv_molecular_weight(invmwt); + amrex::ParallelFor( + bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + nEdot(i, j, k) = YnEdot(i, j, k) * Na * invmwt[E_ID] * 1.0e3; + YnEdot(i, j, k) = 0.0; + }); + } } } @@ -248,7 +256,9 @@ PeleLM::initializeElectronFromMassFraction() void PeleLM::fillPatchExtrap( - amrex::Real a_time, amrex::Vector const& a_MF, int a_nGrow) + const amrex::Real a_time, + amrex::Vector const& a_MF, + const int a_nGrow) { AMREX_ASSERT(a_MF[0]->nComp() <= m_bcrec_force.size()); const int nComp = a_MF[0]->nComp(); From f8ef618233b0d998ddbb940033482b44ea708850 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 5 Sep 2025 15:18:35 +0100 Subject: [PATCH 80/87] fixes --- Source/PeleLMeX.H | 13 + Source/PeleLMeX_Diffusion.cpp | 4 +- Source/PeleLMeX_Forces.cpp | 479 ++++++++++++++++++---------------- Source/PeleLMeX_K.H | 49 ++++ Source/PeleLMeX_Plot.cpp | 1 + 5 files changed, 321 insertions(+), 225 deletions(-) diff --git a/Source/PeleLMeX.H b/Source/PeleLMeX.H index 4d9a4e424..e0718e168 100644 --- a/Source/PeleLMeX.H +++ b/Source/PeleLMeX.H @@ -850,6 +850,19 @@ public: amrex::MultiFab* a_velForce, const int add_gradP); + void getVelForces( + int lev, + const amrex::Box& bx, + const amrex::Real& a_time, + amrex::Array4 const& force, + amrex::Array4 const& vel, + amrex::Array4 const& rho, + amrex::Array4 const& rhoY, + amrex::Array4 const& rhoh, + amrex::Array4 const& temp, + amrex::Array4 const& extMom, + amrex::Array4 const& extRho); + void addSpark(const PeleLM::TimeStamp a_time); void addScalarVarianceSources(const PeleLM::TimeStamp a_time); diff --git a/Source/PeleLMeX_Diffusion.cpp b/Source/PeleLMeX_Diffusion.cpp index 4bd629687..d5595416c 100644 --- a/Source/PeleLMeX_Diffusion.cpp +++ b/Source/PeleLMeX_Diffusion.cpp @@ -1350,7 +1350,6 @@ PeleLM::differentialDiffusionUpdate( ? advData->Forcing_aux[lev].const_array(mfi, 0) : DummyFab.const_array(); const auto nAux = m_nAux; - const auto dt = m_dt; const auto use_wbar = m_use_wbar; const auto use_soret = m_use_soret; amrex::ParallelFor( @@ -1568,7 +1567,6 @@ PeleLM::deltaTIter_prepare( auto const& diffDiff = diffData->Dhat[lev].const_array(mfi, NUM_SPECIES + 1); auto const& rhs = a_rhs[lev]->array(mfi); - const amrex::Real dtinv = 1.0 / m_dt; // Cpmix auto const& rho = ldataNew_p->state.const_array(mfi, DENSITY); @@ -1584,7 +1582,7 @@ PeleLM::deltaTIter_prepare( // Assemble deltaT RHS rhs(i, j, k) = dt * ((rhoH_o(i, j, k) - rhoH_n(i, j, k)) * dtinv + force(i, j, k) + -] fourier(i, j, k) + diffDiff(i, j, k)); + fourier(i, j, k) + diffDiff(i, j, k)); // Get \rho * Cp_{mix} getCpmixGivenRYT(i, j, k, rho, rhoY, T, rhocp, leosparm); diff --git a/Source/PeleLMeX_Forces.cpp b/Source/PeleLMeX_Forces.cpp index 853c47ca5..9e4cf6910 100644 --- a/Source/PeleLMeX_Forces.cpp +++ b/Source/PeleLMeX_Forces.cpp @@ -142,266 +142,301 @@ PeleLM::getVelForces( }); } } +} - void PeleLM::addSpark(const TimeStamp a_timestamp) - { - for (int lev = 0; lev <= finest_level; ++lev) { - for (int n = 0; n < m_n_sparks; ++n) { - // Do the checks first - const amrex::Real time = getTime(lev, a_timestamp); - const bool verb = m_spark_verbose > 1 && lev == 0; - if ( - time < m_spark_time[n] || - time > m_spark_time[n] + m_spark_duration[n]) { - if (verb) { - amrex::Print() << m_spark[n] << " not active \n"; - } - continue; - } - const amrex::Real* probLo = geom[lev].ProbLo(); - auto const dx = geom[lev].CellSizeArray(); - amrex::IntVect spark_idx; - for (int d = 0; d < AMREX_SPACEDIM; ++d) { - spark_idx[d] = - static_cast((m_spark_location[n][d] - probLo[d]) / dx[d]); - } - const amrex::Box domainBox = geom[lev].Domain(); - // just a check - if (!domainBox.contains(spark_idx)) { - amrex::Warning(m_spark[n] + " not in domain!"); - continue; - } +void +PeleLM::getVelForces( + int lev, + const amrex::Box& bx, + const amrex::Real& a_time, + amrex::Array4 const& force, + amrex::Array4 const& vel, + amrex::Array4 const& rho, + amrex::Array4 const& rhoY, + amrex::Array4 const& rhoh, + amrex::Array4 const& temp, + amrex::Array4 const& extMom, + amrex::Array4 const& extRho) +{ + const auto dx = geom[lev].CellSizeArray(); + const int pseudo_gravity = m_ctrl_pseudoGravity; + const amrex::Real dV_control = m_ctrl_dV; + const int is_incomp = m_incompressible; + const amrex::Real rho_incomp = m_rho; + const auto grav = m_gravity; + const auto gp0 = m_background_gp; + const int ps_dir = m_ctrl_flameDir; + + amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + makeVelForce( + i, j, k, is_incomp, rho_incomp, pseudo_gravity, ps_dir, a_time, grav, gp0, + dV_control, dx, vel, rho, rhoY, rhoh, temp, extMom, extRho, force); + }); +} + +void +PeleLM::addSpark(const TimeStamp a_timestamp) +{ + for (int lev = 0; lev <= finest_level; ++lev) { + for (int n = 0; n < m_n_sparks; ++n) { + // Do the checks first + const amrex::Real time = getTime(lev, a_timestamp); + const bool verb = m_spark_verbose > 1 && lev == 0; + if ( + time < m_spark_time[n] || + time > m_spark_time[n] + m_spark_duration[n]) { if (verb) { - amrex::Print() << m_spark[n] << " active\n"; + amrex::Print() << m_spark[n] << " not active \n"; } - auto const* eosparm = eos_parms.device_parm(); - auto eos = pele::physics::PhysicsType::eos(eosparm); - - auto const& statema = - getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); - auto const& extma = m_extSource[lev]->arrays(); - amrex::ParallelFor( - *m_extSource[lev], - [statema, extma, eos, dx, spark_idx, - spark_duration = m_spark_duration[n], spark_temp = m_spark_temp[n], - spark_radius = m_spark_radius - [n]] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - const amrex::Real dist_to_center = std::sqrt(AMREX_D_TERM( - (i - spark_idx[0]) * (i - spark_idx[0]) * dx[0] * dx[0], - +(j - spark_idx[1]) * (j - spark_idx[1]) * dx[1] * dx[1], - +(k - spark_idx[2]) * (k - spark_idx[2]) * dx[2] * dx[2])); - if (dist_to_center < spark_radius) { - amrex::Real rhoh_src_loc = 0; - const amrex::Real rho = statema[box_no](i, j, k, DENSITY); - amrex::Real Y[NUM_SPECIES]; - for (int ns = 0; ns < NUM_SPECIES; ++ns) { - Y[ns] = statema[box_no](i, j, k, FIRSTSPEC + ns) / rho; - } - eos.TY2H(spark_temp, Y, rhoh_src_loc); - rhoh_src_loc *= rho * 1e-4 / spark_duration; - extma[box_no](i, j, k, RHOH) = rhoh_src_loc; - } - }); - // Shift outside? - amrex::Gpu::streamSynchronize(); + continue; + } + const amrex::Real* probLo = geom[lev].ProbLo(); + auto const dx = geom[lev].CellSizeArray(); + amrex::IntVect spark_idx; + for (int d = 0; d < AMREX_SPACEDIM; ++d) { + spark_idx[d] = + static_cast((m_spark_location[n][d] - probLo[d]) / dx[d]); + } + const amrex::Box domainBox = geom[lev].Domain(); + // just a check + if (!domainBox.contains(spark_idx)) { + amrex::Warning(m_spark[n] + " not in domain!"); + continue; + } + if (verb) { + amrex::Print() << m_spark[n] << " active\n"; } + auto const* eosparm = eos_parms.device_parm(); + auto eos = pele::physics::PhysicsType::eos(eosparm); + + auto const& statema = + getLevelDataPtr(lev, a_timestamp)->state.const_arrays(); + auto const& extma = m_extSource[lev]->arrays(); + amrex::ParallelFor( + *m_extSource[lev], + [statema, extma, eos, dx, spark_idx, + spark_duration = m_spark_duration[n], spark_temp = m_spark_temp[n], + spark_radius = m_spark_radius + [n]] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { + const amrex::Real dist_to_center = std::sqrt(AMREX_D_TERM( + (i - spark_idx[0]) * (i - spark_idx[0]) * dx[0] * dx[0], + +(j - spark_idx[1]) * (j - spark_idx[1]) * dx[1] * dx[1], + +(k - spark_idx[2]) * (k - spark_idx[2]) * dx[2] * dx[2])); + if (dist_to_center < spark_radius) { + amrex::Real rhoh_src_loc = 0; + const amrex::Real rho = statema[box_no](i, j, k, DENSITY); + amrex::Real Y[NUM_SPECIES]; + for (int ns = 0; ns < NUM_SPECIES; ++ns) { + Y[ns] = statema[box_no](i, j, k, FIRSTSPEC + ns) / rho; + } + eos.TY2H(spark_temp, Y, rhoh_src_loc); + rhoh_src_loc *= rho * 1e-4 / spark_duration; + extma[box_no](i, j, k, RHOH) = rhoh_src_loc; + } + }); + // Shift outside? + amrex::Gpu::streamSynchronize(); } } +} - // Manifold model - dissipation rate sources for variances - void PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) - { - BL_PROFILE("PeleLM::addScalarVarianceSources"); - // no scalar dissipation sources if not using a manifold model +// Manifold model - dissipation rate sources for variances +void +PeleLM::addScalarVarianceSources(const TimeStamp a_timestamp) +{ + BL_PROFILE("PeleLM::addScalarVarianceSources"); + // no scalar dissipation sources if not using a manifold model #ifndef USE_MANIFOLD_EOS - amrex::ignore_unused(a_timestamp); + amrex::ignore_unused(a_timestamp); #else - if (m_add_variance_sources) { - auto const& leosparm = eos_parms.host_parm(); - - // Determine if we have any scalar variances that need sources added - // Could be moved elsewhere to not do every timestep - int nvariances = 0; - int var_of_scalar = -1; - for (int n = 0; n < MANIFOLD_DIM; ++n) { - if (leosparm.is_variance_of[n] >= 0) { - if (!m_do_les) { - amrex::Abort( - "PeleLM::addScalarVarianceSources(): cannot add a " - "scalar dissipation without an active LES model"); - } - nvariances += 1; - var_of_scalar = FIRSTSPEC + leosparm.is_variance_of[n]; + if (m_add_variance_sources) { + auto const& leosparm = eos_parms.host_parm(); + + // Determine if we have any scalar variances that need sources added + // Could be moved elsewhere to not do every timestep + int nvariances = 0; + int var_of_scalar = -1; + for (int n = 0; n < MANIFOLD_DIM; ++n) { + if (leosparm.is_variance_of[n] >= 0) { + if (!m_do_les) { + amrex::Abort( + "PeleLM::addScalarVarianceSources(): cannot add a " + "scalar dissipation without an active LES model"); } + nvariances += 1; + var_of_scalar = FIRSTSPEC + leosparm.is_variance_of[n]; } + } - if (nvariances > 1) { - amrex::Abort( - "PeleLM::addScalarVarianceSources(): currently we only support " - "manifold models with 0 or 1 variances"); - } else if (nvariances > 0) { - - // Compute scalar gradients (no need to average down here) - constexpr int do_avgDown = 0; - auto bcRecScalar = fetchBCRecArray(var_of_scalar, 1); - constexpr int nGrow = 0; // No need for ghost face on fluxes - amrex::Vector> grad_fc( - finest_level + 1); - for (int lev = 0; lev <= finest_level; ++lev) { - const auto& ba = grids[lev]; - const auto& factory = Factory(lev); - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - grad_fc[lev][idim].define( - amrex::convert(ba, amrex::IntVect::TheDimensionVector(idim)), - dmap[lev], 1, nGrow, amrex::MFInfo(), factory); - grad_fc[lev][idim].setVal(0.0); // Required? - } + if (nvariances > 1) { + amrex::Abort( + "PeleLM::addScalarVarianceSources(): currently we only support " + "manifold models with 0 or 1 variances"); + } else if (nvariances > 0) { + + // Compute scalar gradients (no need to average down here) + constexpr int do_avgDown = 0; + auto bcRecScalar = fetchBCRecArray(var_of_scalar, 1); + constexpr int nGrow = 0; // No need for ghost face on fluxes + amrex::Vector> grad_fc( + finest_level + 1); + for (int lev = 0; lev <= finest_level; ++lev) { + const auto& ba = grids[lev]; + const auto& factory = Factory(lev); + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { + grad_fc[lev][idim].define( + amrex::convert(ba, amrex::IntVect::TheDimensionVector(idim)), + dmap[lev], 1, nGrow, amrex::MFInfo(), factory); + grad_fc[lev][idim].setVal(0.0); // Required? } - getDiffusionOp()->computeGradient( - GetVecOfArrOfPtrs(grad_fc), {}, - GetVecOfConstPtrs(getStateVect(a_timestamp)), {}, bcRecScalar[0], - do_avgDown, var_of_scalar); - - constexpr amrex::Real fact = - 0.5 / static_cast(AMREX_SPACEDIM); - const amrex::Real C_chi = m_les_c_chi; - const amrex::Real ScInv = m_Schmidt_inv; - - // Add in Production and Dissipation source terms for subfilter - // variances - for (int lev = 0; lev <= finest_level; ++lev) { - - auto* ldata_p = getLevelDataPtr(lev, a_timestamp); - - // Require the turbulent viscosity to be pre-computed - // it always is stored at AmrOldTime, so we just use that - // We need cell-centered mu_t but have it at faces - // The simple interpolation below probably isn't valid for EB + } + getDiffusionOp()->computeGradient( + GetVecOfArrOfPtrs(grad_fc), {}, + GetVecOfConstPtrs(getStateVect(a_timestamp)), {}, bcRecScalar[0], + do_avgDown, var_of_scalar); + + constexpr amrex::Real fact = + 0.5 / static_cast(AMREX_SPACEDIM); + const amrex::Real C_chi = m_les_c_chi; + const amrex::Real ScInv = m_Schmidt_inv; + + // Add in Production and Dissipation source terms for subfilter + // variances + for (int lev = 0; lev <= finest_level; ++lev) { + + auto* ldata_p = getLevelDataPtr(lev, a_timestamp); + + // Require the turbulent viscosity to be pre-computed + // it always is stored at AmrOldTime, so we just use that + // We need cell-centered mu_t but have it at faces + // The simple interpolation below probably isn't valid for EB #ifdef AMREX_USE_EB - amrex::Abort( - "PeleLM::addScalarVarianceSources(): this is not supported with " - "EB"); + amrex::Abort( + "PeleLM::addScalarVarianceSources(): this is not supported with " + "EB"); #endif - for (int n = 0; n < MANIFOLD_DIM; ++n) { - if (leosparm.is_variance_of[n] >= 0) { - - AMREX_D_TERM( - auto const& mut_arr_x = - m_leveldata_old[lev]->visc_turb_fc[0].const_arrays(); - , auto const& mut_arr_y = - m_leveldata_old[lev]->visc_turb_fc[1].const_arrays(); - , auto const& mut_arr_z = - m_leveldata_old[lev]->visc_turb_fc[2].const_arrays();) - AMREX_D_TERM( - auto const& gx = grad_fc[lev][0].const_arrays(); - , auto const& gy = grad_fc[lev][1].const_arrays(); - , auto const& gz = grad_fc[lev][2].const_arrays();) - auto const& extma = m_extSource[lev]->arrays(); - auto const& statema = ldata_p->state.const_arrays(); - - // l_scale will also need modification for EB - const amrex::Real vol = AMREX_D_TERM( - geom[lev].CellSize(0), *geom[lev].CellSize(1), - *geom[lev].CellSize(2)); + for (int n = 0; n < MANIFOLD_DIM; ++n) { + if (leosparm.is_variance_of[n] >= 0) { + + AMREX_D_TERM( + auto const& mut_arr_x = + m_leveldata_old[lev]->visc_turb_fc[0].const_arrays(); + , auto const& mut_arr_y = + m_leveldata_old[lev]->visc_turb_fc[1].const_arrays(); + , auto const& mut_arr_z = + m_leveldata_old[lev]->visc_turb_fc[2].const_arrays();) + AMREX_D_TERM( + auto const& gx = grad_fc[lev][0].const_arrays(); + , auto const& gy = grad_fc[lev][1].const_arrays(); + , auto const& gz = grad_fc[lev][2].const_arrays();) + auto const& extma = m_extSource[lev]->arrays(); + auto const& statema = ldata_p->state.const_arrays(); + + // l_scale will also need modification for EB + const amrex::Real vol = AMREX_D_TERM( + geom[lev].CellSize(0), *geom[lev].CellSize(1), + *geom[lev].CellSize(2)); #if AMREX_SPACEDIM == 2 - const amrex::Real l_scale = std::sqrt(vol); + const amrex::Real l_scale = std::sqrt(vol); #else - const amrex::Real l_scale = std::cbrt(vol); + const amrex::Real l_scale = std::cbrt(vol); #endif - const amrex::Real inv_l_scale2 = 1.0 / (l_scale * l_scale); + const amrex::Real inv_l_scale2 = 1.0 / (l_scale * l_scale); - amrex::ParallelFor( - *m_extSource[lev], [extma, statema, n, C_chi, ScInv, - inv_l_scale2, mut_arr_x, gx, mut_arr_y, gy + amrex::ParallelFor( + *m_extSource[lev], [extma, statema, n, C_chi, ScInv, inv_l_scale2, + mut_arr_x, gx, mut_arr_y, gy #if (AMREX_SPACEDIM == 3) - , - mut_arr_z, gz + , + mut_arr_z, gz #endif - ] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept { - // Subfilter Scalar Dissipation: Linear Relaxation model - // rho chi_sgs = C_chi * mu_t / Delta^2 * Variance - const amrex::Real mu_t = - fact * - (AMREX_D_TERM( - mut_arr_x[bx](i, j, k) + mut_arr_x[bx](i + 1, j, k), - +mut_arr_y[bx](i, j, k) + mut_arr_y[bx](i, j + 1, k), - +mut_arr_z[bx](i, j, k) + mut_arr_z[bx](i, j, k + 1))); - - extma[bx](i, j, k, FIRSTSPEC + n) -= - C_chi * mu_t * inv_l_scale2 * - statema[bx](i, j, k, FIRSTSPEC + n); - - // Production term (w/ Smagorinsky closure for turbulent flux) - // -2 (rho - rho ) d/dx_j - // = 2 *mu_t/Sc_t * d/dx_j * d/dx_j - const amrex::Real mu_grad2 = - fact * (AMREX_D_TERM( - mut_arr_x[bx](i, j, k) * gx[bx](i, j, k) * - gx[bx](i, j, k) + - mut_arr_x[bx](i + 1, j, k) * - gx[bx](i + 1, j, k) * gx[bx](i + 1, j, k), - +mut_arr_y[bx](i, j, k) * gy[bx](i, j, k) * - gy[bx](i, j, k) + - mut_arr_y[bx](i, j + 1, k) * - gy[bx](i, j + 1, k) * gy[bx](i, j + 1, k), - +mut_arr_z[bx](i, j, k) * gz[bx](i, j, k) * - gz[bx](i, j, k) + - mut_arr_z[bx](i, j, k + 1) * - gz[bx](i, j, k + 1) * gz[bx](i, j, k + 1))); - - extma[bx](i, j, k, FIRSTSPEC + n) += 2.0 * ScInv * mu_grad2; - }); - amrex::Gpu::streamSynchronize(); - } + ] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept { + // Subfilter Scalar Dissipation: Linear Relaxation model + // rho chi_sgs = C_chi * mu_t / Delta^2 * Variance + const amrex::Real mu_t = + fact * + (AMREX_D_TERM( + mut_arr_x[bx](i, j, k) + mut_arr_x[bx](i + 1, j, k), + +mut_arr_y[bx](i, j, k) + mut_arr_y[bx](i, j + 1, k), + +mut_arr_z[bx](i, j, k) + mut_arr_z[bx](i, j, k + 1))); + + extma[bx](i, j, k, FIRSTSPEC + n) -= + C_chi * mu_t * inv_l_scale2 * + statema[bx](i, j, k, FIRSTSPEC + n); + + // Production term (w/ Smagorinsky closure for turbulent flux) + // -2 (rho - rho ) d/dx_j + // = 2 *mu_t/Sc_t * d/dx_j * d/dx_j + const amrex::Real mu_grad2 = + fact * + (AMREX_D_TERM( + mut_arr_x[bx](i, j, k) * gx[bx](i, j, k) * gx[bx](i, j, k) + + mut_arr_x[bx](i + 1, j, k) * gx[bx](i + 1, j, k) * + gx[bx](i + 1, j, k), + +mut_arr_y[bx](i, j, k) * gy[bx](i, j, k) * + gy[bx](i, j, k) + + mut_arr_y[bx](i, j + 1, k) * gy[bx](i, j + 1, k) * + gy[bx](i, j + 1, k), + +mut_arr_z[bx](i, j, k) * gz[bx](i, j, k) * + gz[bx](i, j, k) + + mut_arr_z[bx](i, j, k + 1) * gz[bx](i, j, k + 1) * + gz[bx](i, j, k + 1))); + + extma[bx](i, j, k, FIRSTSPEC + n) += 2.0 * ScInv * mu_grad2; + }); + amrex::Gpu::streamSynchronize(); } } } } -#endif } +#endif +} - // Calculate additional external sources (soot, radiation, user defined, etc.) - void PeleLM::getExternalSources( - const int is_initIter, const PeleLM::TimeStamp a_timestamp_old, - const PeleLM::TimeStamp a_timestamp_new) - { - amrex::ignore_unused(is_initIter); +// Calculate additional external sources (soot, radiation, user defined, etc.) +void +PeleLM::getExternalSources( + const int is_initIter, + const PeleLM::TimeStamp a_timestamp_old, + const PeleLM::TimeStamp a_timestamp_new) +{ + amrex::ignore_unused(is_initIter); - if (m_n_sparks > 0) { - addSpark(a_timestamp_old); - } + if (m_n_sparks > 0) { + addSpark(a_timestamp_old); + } #ifdef PELE_USE_SPRAY - if (is_initIter == 0) { - SprayMKD(m_cur_time, m_dt); - } + if (is_initIter == 0) { + SprayMKD(m_cur_time, m_dt); + } #endif #ifdef PELE_USE_SOOT - if (do_soot_solve) { - computeSootSource(a_timestamp_old, m_dt); - } + if (do_soot_solve) { + computeSootSource(a_timestamp_old, m_dt); + } #endif #ifdef PELE_USE_RADIATION - if (do_rad_solve) { - BL_PROFILE_VAR("PeleLM::advance::rad", PLM_RAD); - computeRadSource(a_timestamp_old); - BL_PROFILE_VAR_STOP(PLM_RAD); - } + if (do_rad_solve) { + BL_PROFILE_VAR("PeleLM::advance::rad", PLM_RAD); + computeRadSource(a_timestamp_old); + BL_PROFILE_VAR_STOP(PLM_RAD); + } #endif - addScalarVarianceSources(a_timestamp_old); + addScalarVarianceSources(a_timestamp_old); - // User defined external sources - if (m_user_defined_ext_sources) { - for (int lev = 0; lev <= finest_level; ++lev) { - auto* ldata_p_old = getLevelDataPtr(lev, a_timestamp_old); - auto* ldata_p_new = getLevelDataPtr(lev, a_timestamp_new); - auto& ext_src = m_extSource[lev]; - ProblemSpecificFunctions::modify_ext_sources( - getTime(lev, a_timestamp_old), m_dt, ldata_p_old->state, - ldata_p_new->state, ext_src, geom[lev].data(), prob_parm_d); - } + // User defined external sources + if (m_user_defined_ext_sources) { + for (int lev = 0; lev <= finest_level; ++lev) { + auto* ldata_p_old = getLevelDataPtr(lev, a_timestamp_old); + auto* ldata_p_new = getLevelDataPtr(lev, a_timestamp_new); + auto& ext_src = m_extSource[lev]; + ProblemSpecificFunctions::modify_ext_sources( + getTime(lev, a_timestamp_old), m_dt, ldata_p_old->state, + ldata_p_new->state, ext_src, geom[lev].data(), prob_parm_d); } } +} diff --git a/Source/PeleLMeX_K.H b/Source/PeleLMeX_K.H index 43301ba38..b72455f2b 100644 --- a/Source/PeleLMeX_K.H +++ b/Source/PeleLMeX_K.H @@ -770,6 +770,55 @@ makeVelForce( } } +AMREX_GPU_DEVICE +AMREX_FORCE_INLINE +void +makeVelForce( + int i, + int j, + int k, + int is_incomp, + const amrex::Real& rho_incomp, + int pseudo_gravity, + int pseudo_gravity_dir, + const amrex::Real& /*time*/, + amrex::GpuArray const gravity, + amrex::GpuArray const gp0, + const amrex::Real& dV_control, + amrex::GpuArray const /*dx*/, + amrex::Array4 const& vel, + amrex::Array4 const& rho, + amrex::Array4 const& /*rhoY*/, + amrex::Array4 const& /*rhoh*/, + amrex::Array4 const& /*temp*/, + amrex::Array4 const& extmom, + amrex::Array4 const& extrho, + amrex::Array4 const& force) noexcept +{ + // Switch between incompressible/low-Mach rhos + amrex::Real rho_lcl = 0.0; + if (is_incomp != 0) { + rho_lcl = rho_incomp; + } else { + rho_lcl = rho(i, j, k); + } + + // Gravity and background pressure gradient + for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + force(i, j, k, idim) = -gp0[idim] + gravity[idim] * rho_lcl; + } + + // Pseudo-gravity for active control + if (pseudo_gravity != 0) { + force(i, j, k, pseudo_gravity_dir) += dV_control * rho_lcl; + } + + for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { + force(i, j, k, idim) += + extmom(i, j, k, idim) - vel(i, j, k, idim) * extrho(i, j, k); + } +} + // This kernel returns directly rhoHmix AMREX_GPU_DEVICE AMREX_FORCE_INLINE diff --git a/Source/PeleLMeX_Plot.cpp b/Source/PeleLMeX_Plot.cpp index 7a9a71065..0c704d916 100644 --- a/Source/PeleLMeX_Plot.cpp +++ b/Source/PeleLMeX_Plot.cpp @@ -1084,6 +1084,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile) ldata_p->gp.setVal(0.0); ProbParm const* lprobparm = prob_parm_d; + auto const* leosparm = eos_parms.device_parm(); // If m_do_patch_flow_variables is set as true, call user-defined function to // patch flow variables From 7ca206a224bb7d37ab5ffaa79f80f2f8f515ae42 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 5 Sep 2025 15:20:20 +0100 Subject: [PATCH 81/87] new/old overload --- Source/PeleLMeX_K.H | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/Source/PeleLMeX_K.H b/Source/PeleLMeX_K.H index b72455f2b..6fac1bfe1 100644 --- a/Source/PeleLMeX_K.H +++ b/Source/PeleLMeX_K.H @@ -726,50 +726,6 @@ getHGivenT( } } -AMREX_GPU_DEVICE -AMREX_FORCE_INLINE -void -makeVelForce( - const int i, - const int j, - const int k, - const int is_incomp, - const amrex::Real rho_incomp, - const int pseudo_gravity, - const int pseudo_gravity_dir, - amrex::GpuArray const& gravity, - amrex::GpuArray const& gp0, - const amrex::Real dV_control, - amrex::Array4 const& vel, - amrex::Array4 const& rho, - amrex::Array4 const& extmom, - amrex::Array4 const& extrho, - amrex::Array4 const& force) noexcept -{ - // Switch between incompressible/low-Mach rhos - amrex::Real rho_lcl = 0.0; - if (is_incomp != 0) { - rho_lcl = rho_incomp; - } else { - rho_lcl = rho(i, j, k); - } - - // Gravity and background pressure gradient - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - force(i, j, k, idim) = -gp0[idim] + gravity[idim] * rho_lcl; - } - - // Pseudo-gravity for active control - if (pseudo_gravity != 0) { - force(i, j, k, pseudo_gravity_dir) += dV_control * rho_lcl; - } - - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - force(i, j, k, idim) += - extmom(i, j, k, idim) - vel(i, j, k, idim) * extrho(i, j, k); - } -} - AMREX_GPU_DEVICE AMREX_FORCE_INLINE void From bf2b58f38c155365bb4a4d31281c97d345eb8489 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 5 Sep 2025 15:42:51 +0100 Subject: [PATCH 82/87] typo --- Source/PeleLMeX_DiffusionOp.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/PeleLMeX_DiffusionOp.cpp b/Source/PeleLMeX_DiffusionOp.cpp index cbac2e365..32bf8a9b0 100644 --- a/Source/PeleLMeX_DiffusionOp.cpp +++ b/Source/PeleLMeX_DiffusionOp.cpp @@ -775,15 +775,14 @@ DiffusionOp::computeDiffFluxes( amrex::Vector phi; phi.reserve(finest_level + 1); for (int lev = 0; lev <= finest_level; ++lev) { - phi[lev].define( + phi.emplace_back( a_phi[lev]->boxArray(), a_phi[lev]->DistributionMap(), ncomp, 1, amrex::MFInfo(), a_phi[lev]->Factory()); #ifdef AMREX_USE_OMP - w #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif - for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); - ++mfi) - { + for (amrex::MFIter mfi(phi[lev], amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { const amrex::Box& gbx = mfi.growntilebox(); auto const& a_phi_arr = a_phi[lev]->const_array(mfi, phi_comp); auto const& a_rho_arr = From 97d3d85414d45c6d19acb426173a251b44ff0a68 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 5 Sep 2025 22:20:03 +0100 Subject: [PATCH 83/87] extra --- Source/PeleLMeX_Soot.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/PeleLMeX_Soot.cpp b/Source/PeleLMeX_Soot.cpp index a4636cfb0..52832d130 100644 --- a/Source/PeleLMeX_Soot.cpp +++ b/Source/PeleLMeX_Soot.cpp @@ -64,7 +64,6 @@ PeleLM::clipSootMoments() mfi.isValid(); ++mfi) { amrex::Box const& gbx = mfi.tilebox(); auto const& state_arr = ldata_p->state.array(mfi, FIRSTSOOT); - SootData* sd = soot_model->getSootData_d(); amrex::ParallelFor( gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { amrex::GpuArray moments; From 919722264db5c38d70701d19e5c8791672ed943a Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 5 Sep 2025 22:51:06 +0100 Subject: [PATCH 84/87] more kernel undos and consts --- Source/PeleLMeX_DeriveFunc.cpp | 66 +++++++++++++-------------- Source/PeleLMeX_TransportProp.cpp | 2 + Source/PeleLMeX_Utils.cpp | 23 ++++++---- Source/Plasma/PeleLMeX_EFIonDrift.cpp | 17 +++++-- 4 files changed, 62 insertions(+), 46 deletions(-) diff --git a/Source/PeleLMeX_DeriveFunc.cpp b/Source/PeleLMeX_DeriveFunc.cpp index 3bf7ba605..47d20a475 100644 --- a/Source/PeleLMeX_DeriveFunc.cpp +++ b/Source/PeleLMeX_DeriveFunc.cpp @@ -434,16 +434,16 @@ pelelmex_dermgvort( vort_arr(i, j, k) = std::abs(vx - uy); #elif (AMREX_SPACEDIM == 3) - const amrex::Real vx = 0.5 * (dat_arr(i+1,j,k,1) - dat_arr(i-1,j,k,1)) * idx; - const amrex::Real wx = 0.5 * (dat_arr(i+1,j,k,2) - dat_arr(i-1,j,k,2)) * idx; - - const amrex::Real uy = 0.5 * (dat_arr(i,j+1,k,0) - dat_arr(i,j-1,k,0)) * idy; - const amrex::Real wy = 0.5 * (dat_arr(i,j+1,k,2) - dat_arr(i,j-1,k,2)) * idy; - - const amrex::Real uz = 0.5 * (dat_arr(i,j,k+1,0) - dat_arr(i,j,k-1,0)) * idz; - const amrex::Real vz = 0.5 * (dat_arr(i,j,k+1,1) - dat_arr(i,j,k-1,1)) * idz; - - vort_arr(i,j,k) = std::sqrt((wy-vz)*(wy-vz) + (uz-wx)*(uz-wx) + (vx-uy)*(vx-uy)); + const amrex::Real vx = 0.5 * (dat_arr(i+1,j,k,1) - dat_arr(i-1,j,k,1)) * idx; + const amrex::Real wx = 0.5 * (dat_arr(i+1,j,k,2) - dat_arr(i-1,j,k,2)) * idx; + + const amrex::Real uy = 0.5 * (dat_arr(i,j+1,k,0) - dat_arr(i,j-1,k,0)) * idy; + const amrex::Real wy = 0.5 * (dat_arr(i,j+1,k,2) - dat_arr(i,j-1,k,2)) * idy; + + const amrex::Real uz = 0.5 * (dat_arr(i,j,k+1,0) - dat_arr(i,j,k-1,0)) * idz; + const amrex::Real vz = 0.5 * (dat_arr(i,j,k+1,1) - dat_arr(i,j,k-1,1)) * idz; + + vort_arr(i,j,k) = std::sqrt((wy-vz)*(wy-vz) + (uz-wx)*(uz-wx) + (vx-uy)*(vx-uy)); #endif }); } @@ -612,25 +612,25 @@ pelelmex_dervort( #endif ] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { #if (AMREX_SPACEDIM == 2) - amrex::Real vx = + const amrex::Real vx = 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; - amrex::Real uy = + const amrex::Real uy = 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; vort_arr(i, j, k) = vx - uy; #elif (AMREX_SPACEDIM == 3) - amrex::Real vx = 0.5 * (dat_arr(i+1,j,k,1) - dat_arr(i-1,j,k,1)) * idx; - amrex::Real wx = 0.5 * (dat_arr(i+1,j,k,2) - dat_arr(i-1,j,k,2)) * idx; - - amrex::Real uy = 0.5 * (dat_arr(i,j+1,k,0) - dat_arr(i,j-1,k,0)) * idy; - amrex::Real wy = 0.5 * (dat_arr(i,j+1,k,2) - dat_arr(i,j-1,k,2)) * idy; + const amrex::Real vx = 0.5 * (dat_arr(i+1,j,k,1) - dat_arr(i-1,j,k,1)) * idx; + const amrex::Real wx = 0.5 * (dat_arr(i+1,j,k,2) - dat_arr(i-1,j,k,2)) * idx; - amrex::Real uz = 0.5 * (dat_arr(i,j,k+1,0) - dat_arr(i,j,k-1,0)) * idz; - amrex::Real vz = 0.5 * (dat_arr(i,j,k+1,1) - dat_arr(i,j,k-1,1)) * idz; + const amrex::Real uy = 0.5 * (dat_arr(i,j+1,k,0) - dat_arr(i,j-1,k,0)) * idy; + const amrex::Real wy = 0.5 * (dat_arr(i,j+1,k,2) - dat_arr(i,j-1,k,2)) * idy; - vort_arr(i,j,k,0) = (wy-vz)*(wy-vz); - vort_arr(i,j,k,1) = (uz-wx)*(uz-wx); - vort_arr(i,j,k,2) = (vx-uy)*(vx-uy); + const amrex::Real uz = 0.5 * (dat_arr(i,j,k+1,0) - dat_arr(i,j,k-1,0)) * idz; + const amrex::Real vz = 0.5 * (dat_arr(i,j,k+1,1) - dat_arr(i,j,k-1,1)) * idz; + + vort_arr(i,j,k,0) = (wy-vz)*(wy-vz); + vort_arr(i,j,k,1) = (uz-wx)*(uz-wx); + vort_arr(i,j,k,2) = (vx-uy)*(vx-uy); #endif }); } @@ -1245,26 +1245,26 @@ pelelmex_derenstrophy( l_rho = rho_arr(i, j, k); } #if (AMREX_SPACEDIM == 2) - amrex::Real vx = + const amrex::Real vx = 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; - amrex::Real uy = + const amrex::Real uy = 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; ens_arr(i, j, k) = 0.5 * l_rho * (vx - uy) * (vx - uy); #elif (AMREX_SPACEDIM == 3) - amrex::Real vx = + const amrex::Real vx = 0.5 * (dat_arr(i + 1, j, k, 1) - dat_arr(i - 1, j, k, 1)) * idx; - amrex::Real wx = + const amrex::Real wx = 0.5 * (dat_arr(i + 1, j, k, 2) - dat_arr(i - 1, j, k, 2)) * idx; - amrex::Real uy = + const amrex::Real uy = 0.5 * (dat_arr(i, j + 1, k, 0) - dat_arr(i, j - 1, k, 0)) * idy; - amrex::Real wy = + const amrex::Real wy = 0.5 * (dat_arr(i, j + 1, k, 2) - dat_arr(i, j - 1, k, 2)) * idy; - amrex::Real uz = + const amrex::Real uz = 0.5 * (dat_arr(i, j, k + 1, 0) - dat_arr(i, j, k - 1, 0)) * idz; - amrex::Real vz = + const amrex::Real vz = 0.5 * (dat_arr(i, j, k + 1, 1) - dat_arr(i, j, k - 1, 1)) * idz; ens_arr(i, j, k) = 0.5 * l_rho * @@ -1451,9 +1451,9 @@ pelelmex_derdiffc( if (a_pelelm->m_use_soret == 0) { AMREX_ASSERT(ncomp == NUM_SPECIES); } - bool do_fixed_Le = (a_pelelm->m_fixed_Le != 0); - bool do_fixed_Pr = (a_pelelm->m_fixed_Pr != 0); - bool do_soret = (a_pelelm->m_use_soret != 0); + const bool do_fixed_Le = (a_pelelm->m_fixed_Le != 0); + const bool do_fixed_Pr = (a_pelelm->m_fixed_Pr != 0); + const bool do_soret = (a_pelelm->m_use_soret != 0); amrex::FArrayBox dummies(bx, NUM_SPECIES + 2, amrex::The_Async_Arena()); auto const& rhoY = statefab.const_array(FIRSTSPEC); auto const& T = statefab.array(TEMP); diff --git a/Source/PeleLMeX_TransportProp.cpp b/Source/PeleLMeX_TransportProp.cpp index 1751c02a8..cd91b9ea9 100644 --- a/Source/PeleLMeX_TransportProp.cpp +++ b/Source/PeleLMeX_TransportProp.cpp @@ -303,6 +303,7 @@ PeleLM::calcDiffusivity(const TimeStamp a_time) amrex::Array4(kma[box_no], 0)); #endif }); + // Shift outside/combine with below? amrex::Gpu::streamSynchronize(); // Fill the diff_aux MF with specified Schmidt number @@ -338,6 +339,7 @@ PeleLM::calcDiffusivity(const TimeStamp a_time) amrex::Array4(state_arr[box_no], TEMP), amrex::Array4(cp_arr[box_no]), leosparm); }); + // Combine with the one above? amrex::Gpu::streamSynchronize(); ldata_p->diff_aux_cc.divide(cp_cc, n, 1, ldata_p->diff_cc.nGrow()); } diff --git a/Source/PeleLMeX_Utils.cpp b/Source/PeleLMeX_Utils.cpp index b8717cdd8..7a9d0a79e 100644 --- a/Source/PeleLMeX_Utils.cpp +++ b/Source/PeleLMeX_Utils.cpp @@ -2200,19 +2200,22 @@ PeleLM::extendSignedDistance( const int nGrowFac = flags.nGrow() + 1; // First set the region far away at the max value we need - - auto const& sd_cc_ma = a_signDist->arrays(); const amrex::Real* dx = geomdata.CellSize(); - const amrex::Real sd_cc_fact = nGrowFac * dx[0] * a_extendFactor; - amrex::ParallelFor( - *a_signDist, a_signDist->nGrowVect(), - [sd_cc_ma, maxSignedDist, - sd_cc_fact] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept { - if (sd_cc_ma[box_no](i, j, k) > maxSignedDist - 1e-12) { - sd_cc_ma[box_no](i, j, k) = sd_cc_fact; + +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(*a_signDist, amrex::TilingIfNotGPU()); mfi.isValid(); + ++mfi) { + const amrex::Box& bx = mfi.growntilebox(); + auto const& sd_cc = a_signDist->array(mfi); + amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + if (sd_cc(i, j, k) >= maxSignedDist - 1e-12) { + sd_cc(i, j, k) = nGrowFac * dx[0] * a_extendFactor; } }); - amrex::Gpu::streamSynchronize(); + } + // Iteratively compute the distance function in boxes, propagating across // boxes using ghost cells If needed, increase the number of loop to extend // the reach of the distance function diff --git a/Source/Plasma/PeleLMeX_EFIonDrift.cpp b/Source/Plasma/PeleLMeX_EFIonDrift.cpp index 86e690b68..9385c296a 100644 --- a/Source/Plasma/PeleLMeX_EFIonDrift.cpp +++ b/Source/Plasma/PeleLMeX_EFIonDrift.cpp @@ -174,9 +174,20 @@ PeleLM::ionDriftAddUmac( { // Add umac to the ions drift velocity to get the effective velocity for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - amrex::MultiFab::Add( - advData->uDrift[lev][idim], advData->umac[lev][idim], 0, 0, 1, - advData->umac[lev][idim].nGrowVect()); +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (amrex::MFIter mfi(advData->umac[lev][idim], amrex::TilingIfNotGPU()); + mfi.isValid(); ++mfi) { + const amrex::Box gbx = mfi.growntilebox(); + const auto& umac = advData->umac[lev][idim].const_array(mfi); + const auto& Ud_Sp = advData->uDrift[lev][idim].array(mfi); + amrex::ParallelFor( + gbx, NUM_IONS, + [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept { + Ud_Sp(i, j, k, n) += umac(i, j, k); + }); + } advData->uDrift[lev][idim].FillBoundary(geom[lev].periodicity()); } } From fc450c730dc6a83039946eef52e668e631b14c0a Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 5 Sep 2025 23:32:54 +0100 Subject: [PATCH 85/87] bump pelephysics --- Submodules/PelePhysics | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Submodules/PelePhysics b/Submodules/PelePhysics index f6ebe5ef9..027d59973 160000 --- a/Submodules/PelePhysics +++ b/Submodules/PelePhysics @@ -1 +1 @@ -Subproject commit f6ebe5ef904c7a81e297b8d348e27fbb661003cc +Subproject commit 027d599738d8265db39133692543bdd1a2938b4d From 574082cf143f30a358f3f1f08796c4c3dca83369 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Fri, 5 Sep 2025 23:35:25 +0100 Subject: [PATCH 86/87] old pelephysics --- Submodules/PelePhysics | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Submodules/PelePhysics b/Submodules/PelePhysics index 027d59973..7d6ba7c60 160000 --- a/Submodules/PelePhysics +++ b/Submodules/PelePhysics @@ -1 +1 @@ -Subproject commit 027d599738d8265db39133692543bdd1a2938b4d +Subproject commit 7d6ba7c60d7cf74fc50d6f87d71c0aa34b1484e4 From 39fa4825456ff994b5b32e630a2be9384f807340 Mon Sep 17 00:00:00 2001 From: Thomas Howarth Date: Mon, 8 Sep 2025 11:57:27 +0100 Subject: [PATCH 87/87] eb bfs default tols --- Exec/RegTests/EB_BackwardStepFlame/eb_bfs.inp | 3 +++ Exec/RegTests/EB_BackwardStepFlame/eb_bfs_pp.inp | 4 +++- Tests/CMakeLists.txt | 12 ++---------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Exec/RegTests/EB_BackwardStepFlame/eb_bfs.inp b/Exec/RegTests/EB_BackwardStepFlame/eb_bfs.inp index d9dc7cbe9..0aa340ca3 100644 --- a/Exec/RegTests/EB_BackwardStepFlame/eb_bfs.inp +++ b/Exec/RegTests/EB_BackwardStepFlame/eb_bfs.inp @@ -29,6 +29,9 @@ prob.T_wall = 300 prob.meanFlowMag = 10.0 prob.Y_fuel = 0.0445269 prob.Y_oxid = 0.2226345 +mac_proj.atol = 5e-11 +mac_proj.rtol = 5e-11 +mac_proj.verbose = 2 #---------------------- PeleLM CONTROL --------------------------- peleLM.v = 1 # PeleLMeX verbose peleLM.use_wbar = 1 # Include Wbar term in species diffusion fluxes diff --git a/Exec/RegTests/EB_BackwardStepFlame/eb_bfs_pp.inp b/Exec/RegTests/EB_BackwardStepFlame/eb_bfs_pp.inp index f47cb0cad..a5a8358b9 100644 --- a/Exec/RegTests/EB_BackwardStepFlame/eb_bfs_pp.inp +++ b/Exec/RegTests/EB_BackwardStepFlame/eb_bfs_pp.inp @@ -31,7 +31,9 @@ prob.Y_fuel = 0.0 prob.Y_oxid = 0.23 prob.EBinflow_Yfuel = 0.1 peleLM.EBinflow = 1 - +mac_proj.atol = 5e-11 +mac_proj.rtol = 5e-11 +mac_proj.verbose = 2 #---------------------- PeleLM CONTROL --------------------------- peleLM.v = 1 # PeleLMeX verbose peleLM.use_wbar = 1 # Include Wbar term in species diffusion fluxes diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index dd1c894aa..be94bf8fb 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -96,14 +96,6 @@ function(add_test_r TEST_NAME TEST_EXE_DIR) set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 18000 PROCESSORS ${PELE_NP} WORKING_DIRECTORY "${CURRENT_TEST_BINARY_DIR}/" LABELS "regression" ATTACHED_FILES "${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.log") endfunction(add_test_r) -#Standard regression test with looser tolerances -function(add_test_rtol TEST_NAME TEST_EXE_DIR) - setup_test() - set(RUNTIME_OPTIONS "amr.max_step=10 mac_proj.atol=5e-11 mac_proj.rtol=5e-11 mac_proj.verbose=2 ${RUNTIME_OPTIONS}") - add_test(${TEST_NAME} bash -c "set -o pipefail && ${MPI_COMMANDS} ${CURRENT_TEST_EXE} ${MPIEXEC_POSTFLAGS} ${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.inp ${RUNTIME_OPTIONS} 2>&1 | tee ${TEST_NAME}.log ${SAVE_GOLDS_COMMAND} ${FCOMPARE_COMMAND}") - set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 18000 PROCESSORS ${PELE_NP} WORKING_DIRECTORY "${CURRENT_TEST_BINARY_DIR}/" LABELS "regression" ATTACHED_FILES "${CURRENT_TEST_BINARY_DIR}/${TEST_NAME}.log") -endfunction(add_test_r) - # Regression test with mass conservation verification function(add_test_rv TEST_NAME TEST_EXE_DIR) setup_test() @@ -258,8 +250,8 @@ if(NOT PELE_ENABLE_EB) else() if(PELE_DIM EQUAL 2) add_test_rt(composition-test-${PELE_DIM}d EB_ODEQty) - add_test_rtol(eb_bfs EB_BackwardStepFlame) - add_test_rtol(eb_bfs_pp EB_BackwardStepFlame) + add_test_r(eb_bfs EB_BackwardStepFlame) + add_test_r(eb_bfs_pp EB_BackwardStepFlame) endif() add_test_r(eb-odeqty-${PELE_DIM}d EB_ODEQty) endif()