From a02434ac09285d05b781b88285126d2238d870d7 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 22 Jun 2021 01:13:22 +0200 Subject: Laser: warnin antenna of a box; Allow zero amplitude (#1989) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add check of laser antenna position * implement axel suggestions * disable laser if antenna is out the box * fix bug * Update Source/Particles/LaserParticleContainer.cpp * implement neil's solution * remove unnecessary include * fix initial status of m_enabled * adding back a check * add back check * add back check * removed unnecessary comment Co-authored-by: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com> --- Source/Particles/LaserParticleContainer.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'Source/Particles/LaserParticleContainer.cpp') diff --git a/Source/Particles/LaserParticleContainer.cpp b/Source/Particles/LaserParticleContainer.cpp index c17dd11b7..4eb2e59f0 100644 --- a/Source/Particles/LaserParticleContainer.cpp +++ b/Source/Particles/LaserParticleContainer.cpp @@ -71,6 +71,7 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, if (m_e_max == amrex::Real(0.)){ amrex::Print() << m_laser_name << " with zero amplitude disabled.\n"; + m_enabled = false; return; // Disable laser if amplitude is 0 } @@ -164,8 +165,8 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, //Init laser profile - AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_e_max > 0., - "Laser amplitude (e_max) must be positive."); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_e_max >= 0., + "Laser amplitude (e_max) must be >= 0."); AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_wavelength > 0., "Laser wavelength must be positive."); @@ -184,13 +185,13 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, void LaserParticleContainer::ContinuousInjection (const RealBox& injection_box) { + if (!m_enabled) return; + // Input parameter injection_box contains small box where injection // should occur. // So far, LaserParticleContainer::laser_injection_box contains the // outdated full problem domain at t=0. - if (m_e_max == amrex::Real(0.)) return; // Disable laser if amplitude is 0 - // Convert updated_position to Real* to use RealBox::contains(). #if (AMREX_SPACEDIM == 3) const Real* p_pos = m_updated_position.dataPtr(); @@ -214,7 +215,7 @@ LaserParticleContainer::ContinuousInjection (const RealBox& injection_box) void LaserParticleContainer::UpdateContinuousInjectionPosition (Real dt) { - if (m_e_max == amrex::Real(0.)) return; // Disable laser if amplitude is 0 + if (!m_enabled) return; int dir = WarpX::moving_window_dir; if (do_continuous_injection and (WarpX::gamma_boost > 1)){ @@ -236,15 +237,22 @@ LaserParticleContainer::UpdateContinuousInjectionPosition (Real dt) void LaserParticleContainer::InitData () { + if (!m_enabled) return; + // Call InitData on max level to inject one laser particle per // finest cell. InitData(maxLevel()); + + if(!do_continuous_injection && (TotalNumberOfParticles() == 0)){ + amrex::Print() << "WARNING: laser antenna is completely out of the simulation box !!!\n"; + m_enabled = false; // Disable laser if antenna is completely out of the simulation box + } } void LaserParticleContainer::InitData (int lev) { - if (m_e_max == amrex::Real(0.)) return; // Disable laser if amplitude is 0 + if (!m_enabled) return; // spacing of laser particles in the laser plane. // has to be done after geometry is set up. @@ -423,7 +431,7 @@ LaserParticleContainer::Evolve (int lev, WARPX_PROFILE("LaserParticleContainer::Evolve()"); WARPX_PROFILE_VAR_NS("LaserParticleContainer::Evolve::ParticlePush", blp_pp); - if (m_e_max == amrex::Real(0.)) return; // Disable laser if amplitude is 0 + if (!m_enabled) return; Real t_lab = t; if (WarpX::gamma_boost > 1) { @@ -550,7 +558,8 @@ LaserParticleContainer::Evolve (int lev, void LaserParticleContainer::PostRestart () { - if (m_e_max == amrex::Real(0.)) return; // Disable laser if amplitude is 0 + if (!m_enabled) return; + Real Sx, Sy; const int lev = finestLevel(); ComputeSpacing(lev, Sx, Sy); -- cgit v1.2.3