From ddb2585a55edcedd0ca613f4288f34d71edda8b2 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Tue, 7 May 2019 11:48:48 -0700 Subject: continuous injection working + comments --- Source/Laser/LaserParticleContainer.cpp | 134 +++++++++++++------------------- 1 file changed, 54 insertions(+), 80 deletions(-) (limited to 'Source/Laser/LaserParticleContainer.cpp') diff --git a/Source/Laser/LaserParticleContainer.cpp b/Source/Laser/LaserParticleContainer.cpp index 8499455de..a7fe9042d 100644 --- a/Source/Laser/LaserParticleContainer.cpp +++ b/Source/Laser/LaserParticleContainer.cpp @@ -149,42 +149,42 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, u_Y = {0., 1., 0.}; #endif - laser_prob_domain = Geometry::ProbDomain(); + laser_injection_box= Geometry::ProbDomain(); { Vector lo, hi; if (pp.queryarr("prob_lo", lo)) { - laser_prob_domain.setLo(lo); + laser_injection_box.setLo(lo); } if (pp.queryarr("prob_hi", hi)) { - laser_prob_domain.setHi(hi); + laser_injection_box.setHi(hi); } } if (do_continuous_injection){ // If laser antenna initially outside of the box, store its theoretical // position in z_antenna_th, and set done_injecting to 0. - z_antenna_th = position[2]; - const Real prob_lo_z = laser_prob_domain.lo()[AMREX_SPACEDIM-1]; - const Real prob_hi_z = laser_prob_domain.hi()[AMREX_SPACEDIM-1]; - if ( z_antenna_thprob_hi_z ){ + updated_position = position; + // Convert updated position to Real* to use RealBox.contains() +#if (AMREX_SPACEDIM == 3) + const Real* p_pos = updated_position.dataPtr(); +#else + const Real p_pos[2] = {updated_position[0], updated_position[2]}; +#endif + if ( not laser_injection_box.contains(p_pos) ){ done_injecting = 0; } - // Sanity checks: do_continuous_injection can be used only if the - // laser, the moving window and the boost are all in z direction. + + // Sanity checks + std::Vector windir(3, 0.0); +#if (AMREX_SPACEDIM==2) + windir[2*dir] = 1.0; +#else + windir[dir] = 1.0; +#endif AMREX_ALWAYS_ASSERT_WITH_MESSAGE( - (nvec[0]-0)*(nvec[0]-0) + - (nvec[1]-0)*(nvec[1]-0) + - (nvec[2]-1)*(nvec[2]-1) < 1.e-12, - "do_continous_injection for laser particle only works if " + - "laser.direction = 0 0 1 (laser along z). TODO: all directions."); - AMREX_ALWAYS_ASSERT_WITH_MESSAGE( - WarpX::moving_window_dir == AMREX_SPACEDIM-1, - "do_continous_injection for laser particle only works if " + - "moving window along z. TODO: all directions."); - AMREX_ALWAYS_ASSERT_WITH_MESSAGE( - maxLevel() == 0, - "do_continous_injection for laser particle only works if " + - "max level = 0."); + (nvec[0]-windir[0]) + (nvec[1]-windor[1]) + (nvec[2]-windor[2]) + < 1.e-12, "do_continous_injection for laser particle only works" + + " if moving window direction and laser propagation direction are the same"); if ( WarpX::gamma_boost>1 ){ AMREX_ALWAYS_ASSERT_WITH_MESSAGE( (WarpX::boost_direction[0]-0)*(WarpX::boost_direction[0]-0) + @@ -197,86 +197,60 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, } /* \brief Check if laser particles enter the box, and inject if necessary. - * \param dt: time step (assume no MR for now) - * \param prob_domain: a RealBox that contains current simulation boundaries. - * This function checks if the laser antenna should be injected at this - * iteration. If so, it injects it and set done_injecting to 1. + * \param injection_box: a RealBox where particles should be injected. */ void -LaserParticleContainer::ContinuousInjection (Real dt, const RealBox& prob_domain) +LaserParticleContainer::ContinuousInjection (const RealBox& injection_box) { - Print()<<" --- In LaserParticleContainer::ContinuousInjection"<=prob_lo_z && z_antenna_th 1)){ - // In boosted-frame simulations, the plasma has moved since the last + // In boosted-frame simulations, the antenna has moved since the last // call to this function, and injection position needs to be updated - z_antenna_th -= WarpX::beta_boost * #if ( AMREX_SPACEDIM == 3 ) + updated_position[dir] -= WarpX::beta_boost * WarpX::boost_direction[dir] * PhysConst::c * dt; #elif ( AMREX_SPACEDIM == 2 ) - // In 2D, dir=0 corresponds to x and dir=1 corresponds to z - // This needs to be converted in order to index `boost_direction` - // which has 3 components, for both 2D and 3D simulations. + // In 2D, dir=0 corresponds to x and dir=1 corresponds to z + // This needs to be converted in order to index `boost_direction` + // which has 3 components, for both 2D and 3D simulations. + updated_position[2*dir] -= WarpX::beta_boost * WarpX::boost_direction[2*dir] * PhysConst::c * dt; #endif } - - /* - if (WarpX::do_plasma_injection and (WarpX::gamma_boost > 1){ - z_antenna_th -= PhysConst::c * WarpX::beta_boost * dt; - } - */ } - - - - - - - - - - - - - - - void LaserParticleContainer::InitData () { @@ -294,9 +268,9 @@ LaserParticleContainer::InitData (int lev) // LaserParticleContainer::position contains the initial position of the // laser antenna. In the boosted frame, the antenna is moving. - // Update its position. + // Update its position with updated_position. if (do_continuous_injection){ - position[2] = z_antenna_th; + position = updated_position; } auto Transform = [&](int i, int j) -> Vector{ @@ -334,8 +308,8 @@ LaserParticleContainer::InitData (int lev) plane_hi[1] = std::max(plane_hi[1], j); }; - const Real* prob_lo = laser_prob_domain.lo(); - const Real* prob_hi = laser_prob_domain.hi(); + const Real* prob_lo = laser_injection_box.lo(); + const Real* prob_hi = laser_injection_box.hi(); #if (AMREX_SPACEDIM == 3) compute_min_max(prob_lo[0], prob_lo[1], prob_lo[2]); compute_min_max(prob_hi[0], prob_lo[1], prob_lo[2]); @@ -396,7 +370,7 @@ LaserParticleContainer::InitData (int lev) #else const Real x[2] = {pos[0], pos[2]}; #endif - if (laser_prob_domain.contains(x)) + if (laser_injection_box.contains(x)) { for (int k = 0; k<2; ++k) { particle_x.push_back(pos[0]); -- cgit v1.2.3