From bc70d383d3589a88f11cb3fcfb2e714d0d7e0bd8 Mon Sep 17 00:00:00 2001 From: jbb Date: Thu, 23 May 2024 11:56:47 -0700 Subject: [PATCH] tryign to average down after reflux --- exec/dean_kow/multilevel/inputs_bug1 | 8 ++++---- src_deankow/multilevel/AmrCoreAdv.cpp | 13 +++++++++++-- src_deankow/multilevel/ParticleData.H | 16 ++++++++++++++-- src_deankow/multilevel/mykernel.H | 1 + 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/exec/dean_kow/multilevel/inputs_bug1 b/exec/dean_kow/multilevel/inputs_bug1 index dba196d6..550af4aa 100644 --- a/exec/dean_kow/multilevel/inputs_bug1 +++ b/exec/dean_kow/multilevel/inputs_bug1 @@ -3,7 +3,7 @@ # whichever comes first # ***************************************************************** max_step = 2500 -max_step = 5 +max_step = 50 seed = 1024 @@ -36,11 +36,11 @@ amr.v = 1 # verbosity in Amr # Resolution and refinement # ***************************************************************** -amr.n_cell = 256 256 amr.n_cell = 32 32 +amr.n_cell = 256 256 amr.max_grid_size_x = 256 256 amr.max_grid_size_y = 256 256 -amr.max_grid_size_x = 64 64 +amr.max_grid_size_x = 64 64 amr.max_grid_size_y = 64 64 amr.max_level = 1 @@ -62,7 +62,7 @@ amr.blocking_factor_x = 8 amr.blocking_factor_y = 8 amr.blocking_factor_z = 8 -amr.regrid_int = 2 # how often to regrid +amr.regrid_int = 10 # how often to regrid # ***************************************************************** # Time step control diff --git a/src_deankow/multilevel/AmrCoreAdv.cpp b/src_deankow/multilevel/AmrCoreAdv.cpp index 45ddea8d..22936d93 100644 --- a/src_deankow/multilevel/AmrCoreAdv.cpp +++ b/src_deankow/multilevel/AmrCoreAdv.cpp @@ -146,7 +146,9 @@ AmrCoreAdv::Evolve () Real sum_phi_new = phi_new[0].sum(); amrex::Print() << "Coarse STEP " << step+1 << " ends." << " TIME = " << cur_time - << " DT = " << dt[0] << " Sum(Phi) = " << sum_phi_old << " " << sum_phi_new << std::endl; + << " DT = " << dt[0] << " Sum(Phi) = " << std::setw(24) << std::setprecision(16) + << std::scientific << sum_phi_old << " " << std::setw(2l) << std::setprecision(16) + << std::scientific << sum_phi_new << std::endl; // sync up time for (lev = 0; lev <= finest_level; ++lev) { @@ -292,7 +294,7 @@ AmrCoreAdv::RemakeLevel (int lev, Real time, const BoxArray& ba, #ifdef AMREX_PARTICLES if (lev == 1) { - particleData.regrid_particles(grown_fba, old_fine_ba, phi_new[1]); + particleData.regrid_particles(grown_fba, ba, old_fine_ba, phi_new[1]); } #endif } @@ -629,6 +631,13 @@ AmrCoreAdv::timeStepNoSubcycling (Real time, int iteration) if (istep[0] % regrid_int == 0) { regrid(0, time); + + AverageDown(); + + Real sum_phi_reg = phi_new[0].sum(); + amrex::Print() << " Sum(Phi) new after regrid = " << std::setw(24) << std::setprecision(16) << std::scientific << sum_phi_reg << std::endl; + sum_phi_reg = phi_old[0].sum(); + amrex::Print() << " Sum(Phi) old after regrid = " << std::setw(24) << std::setprecision(16) << std::scientific << sum_phi_reg << std::endl; } } diff --git a/src_deankow/multilevel/ParticleData.H b/src_deankow/multilevel/ParticleData.H index acc0524e..c965d926 100644 --- a/src_deankow/multilevel/ParticleData.H +++ b/src_deankow/multilevel/ParticleData.H @@ -93,14 +93,26 @@ struct ParticleData { } } - void regrid_particles(const amrex::BoxArray& new_fine_ba, const amrex::BoxArray& old_fine_ba, amrex::MultiFab& phi_fine) + void regrid_particles(const amrex::BoxArray& new_fine_ba, const amrex::BoxArray& new_ungrown_ba, const amrex::BoxArray& old_fine_ba, amrex::MultiFab& phi_fine) { amrex::DistributionMapping new_dm { new_fine_ba, amrex::ParallelDescriptor::NProcs() }; stochastic_particles->SetParticleDistributionMap(1, new_dm); - stochastic_particles->SetParticleBoxArray(1, new_fine_ba); + stochastic_particles->SetParticleBoxArray(1, new_ungrown_ba); stochastic_particles->Redistribute(); stochastic_particles->RemoveParticlesAtLevel(0); stochastic_particles->AddParticles(phi_fine, old_fine_ba); + phi_fine.setVal(0.0); + const int lev = 1; + const auto dx = stochastic_particles->Geom(lev).CellSizeArray(); + +#if (AMREX_SPACEDIM == 2) + const amrex::Real cell_vol = dx[0]*dx[1]; +#else + const amrex::Real cell_vol = dx[0]*dx[1]*dx[2]; +#endif + stochastic_particles->Increment(phi_fine, lev); + phi_fine.mult(1./cell_vol); + stochastic_particles->SetParticleBoxArray(1, new_fine_ba); } void Checkpoint (const std::string& filename) const diff --git a/src_deankow/multilevel/mykernel.H b/src_deankow/multilevel/mykernel.H index 7c131cc5..50231904 100644 --- a/src_deankow/multilevel/mykernel.H +++ b/src_deankow/multilevel/mykernel.H @@ -69,6 +69,7 @@ void init_phi (int i, int j, int k, Real x = prob_lo[0] + (i+Real(0.5)) * dx[0] - xcent; Real y = prob_lo[1] + (j+Real(0.5)) * dx[1] - ycent; Real r2 = (x*x + y*y); + r2 = 4.*(x-y)*(x-y)+ .25*(x+y)*(x+y); #if (AMREX_SPACEDIM == 3) Real zcent = Real(0.75); Real z = prob_lo[2] + (k+Real(0.5)) * dx[2] - zcent;