diff options
Diffstat (limited to 'Source/Initialization/WarpXInitData.cpp')
-rw-r--r-- | Source/Initialization/WarpXInitData.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 892172745..98533ea33 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -92,6 +92,7 @@ WarpX::InitData () ScaleEdges(); ScaleAreas(); #endif + ComputeMaxStep(); ComputePMLFactors(); @@ -267,6 +268,74 @@ WarpX::ComputePMLFactors () } void +WarpX::ComputeMaxStep () +{ + if (do_compute_max_step_from_zmax) { + computeMaxStepBoostAccelerator(geom[0]); + } + + // Make max_step and stop_time self-consistent, assuming constant dt. + + // If max_step is the limiting condition, decrease stop_time consistently + if (stop_time > t_new[0] + dt[0]*(max_step - istep[0]) ) { + stop_time = t_new[0] + dt[0]*(max_step - istep[0]); + } + // If stop_time is the limiting condition instead, decrease max_step consistently + else { + // The static_cast should not overflow since stop_time is the limiting condition here + max_step = static_cast<int>(istep[0] + std::ceil( (stop_time-t_new[0])/dt[0] )); + } +} + +/* \brief computes max_step for wakefield simulation in boosted frame. + * \param geom: Geometry object that contains simulation domain. + * + * max_step is set so that the simulation stop when the lower corner of the + * simulation box passes input parameter zmax_plasma_to_compute_max_step. + */ +void +WarpX::computeMaxStepBoostAccelerator(const amrex::Geometry& a_geom){ + // Sanity checks: can use zmax_plasma_to_compute_max_step only if + // the moving window and the boost are all in z direction. + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( + WarpX::moving_window_dir == AMREX_SPACEDIM-1, + "Can use zmax_plasma_to_compute_max_step only if " + + "moving window along z. TODO: all directions."); + if (gamma_boost > 1){ + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( + (WarpX::boost_direction[0]-0)*(WarpX::boost_direction[0]-0) + + (WarpX::boost_direction[1]-0)*(WarpX::boost_direction[1]-0) + + (WarpX::boost_direction[2]-1)*(WarpX::boost_direction[2]-1) < 1.e-12, + "Can use zmax_plasma_to_compute_max_step in boosted frame only if " + + "warpx.boost_direction = z. TODO: all directions."); + } + + // Lower end of the simulation domain. All quantities are given in boosted + // frame except zmax_plasma_to_compute_max_step. + const Real zmin_domain_boost = a_geom.ProbLo(AMREX_SPACEDIM-1); + // End of the plasma: Transform input argument + // zmax_plasma_to_compute_max_step to boosted frame. + const Real len_plasma_boost = zmax_plasma_to_compute_max_step/gamma_boost; + // Plasma velocity + const Real v_plasma_boost = -beta_boost * PhysConst::c; + // Get time at which the lower end of the simulation domain passes the + // upper end of the plasma (in the z direction). + const Real interaction_time_boost = (len_plasma_boost-zmin_domain_boost)/ + (moving_window_v-v_plasma_boost); + // Divide by dt, and update value of max_step. + int computed_max_step; + if (do_subcycling){ + computed_max_step = static_cast<int>(interaction_time_boost/dt[0]); + } else { + computed_max_step = + static_cast<int>(interaction_time_boost/dt[maxLevel()]); + } + max_step = computed_max_step; + Print()<<"max_step computed in computeMaxStepBoostAccelerator: " + <<computed_max_step<<std::endl; +} + +void WarpX::InitNCICorrector () { if (WarpX::use_fdtd_nci_corr) |