From f22d6cb818b24d51941062ee7ddf182b5c5fd465 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Fri, 3 May 2019 16:34:31 -0700 Subject: first implementation for laser continuous injection --- Source/Particles/MultiParticleContainer.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index a4df1f83a..6c0bd7ca9 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -414,3 +414,17 @@ MultiParticleContainer } } } + +void +MultiParticleContainer::ContinuousInjection(Real dt, const RealBox& prob_domain) const +{ +// Print()<<"prob_lo "<do_continuous_injection) + { + pc->ContinuousInjection(dt, prob_domain); + } + } +}; -- cgit v1.2.3 From 5f074622fce90b063fce76a1d0d466e9f33b07e0 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Fri, 3 May 2019 16:58:56 -0700 Subject: some cleaning. Works without boosted frame. --- Source/Evolve/WarpXEvolveEM.cpp | 1 - Source/Laser/LaserParticleContainer.cpp | 41 ----------------------------- Source/Particles/MultiParticleContainer.H | 2 -- Source/Particles/MultiParticleContainer.cpp | 4 +-- Source/Particles/WarpXParticleContainer.cpp | 9 ------- 5 files changed, 1 insertion(+), 56 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index 8ce39683f..65e813b33 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -88,7 +88,6 @@ WarpX::EvolveEM (int numsteps) UpdateAuxilaryData(); } -// mypc->ContinuousInjection(dt[0], geom[0].ProbLo(), geom[0].ProbHi()); mypc->ContinuousInjection(dt[0], geom[0].ProbDomain()); if (do_subcycling == 0 || finest_level == 0) { diff --git a/Source/Laser/LaserParticleContainer.cpp b/Source/Laser/LaserParticleContainer.cpp index b7c893169..c5d056f32 100644 --- a/Source/Laser/LaserParticleContainer.cpp +++ b/Source/Laser/LaserParticleContainer.cpp @@ -162,12 +162,10 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, if (do_continuous_injection){ z_antenna_th = position[2]; - Print()<<"z_antenna_th "<prob_hi_z ){ done_injecting = 0; - Print()<<"z_antenna_th>prob_lo_z && z_antenna_th1){ z_antenna_th -= PhysConst::c * WarpX::beta_boost * dt; } - Print()<<"LaserParticleContainer::ContinuousInjection"<prob_lo_z && z_antenna_thprob_lo_z && z_antenna_thprob_lo_z && z_antenna_th0){ - Print()<<"particle_z.dataPtr() "< 1) { // Convert time from the boosted to the lab-frame @@ -425,10 +387,8 @@ LaserParticleContainer::Evolve (int lev, Cuda::ManagedDeviceVector plane_Xp, plane_Yp, amplitude_E; - Print()<<"before for loop "< prob_lo, -// amrex::Vector prob_hi) const; // // Parameters for the Cherenkov corrector in the FDTD solver. diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 6c0bd7ca9..2539359f9 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -418,8 +418,6 @@ MultiParticleContainer void MultiParticleContainer::ContinuousInjection(Real dt, const RealBox& prob_domain) const { -// Print()<<"prob_lo "<do_continuous_injection) @@ -427,4 +425,4 @@ MultiParticleContainer::ContinuousInjection(Real dt, const RealBox& prob_domain) pc->ContinuousInjection(dt, prob_domain); } } -}; +} diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 45f0793f0..2edd3c636 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -178,12 +178,6 @@ WarpXParticleContainer::AddNParticles (int lev, BL_ASSERT(nattr == 1); const Real* weight = attr; - Print()<< "in WarpXParticleContainer::AddNParticles"< prob_lo, -// amrex::Vector prob_hi) {} /// /// This returns the total charge for all the particles in this ParticleContainer. @@ -253,6 +258,10 @@ protected: static int do_not_push; + // Whether to allow particles outside of the simulation domain to be + // initialized when they enter the domain. + // This is currently required because continuous injection does not + // support all features allowed by direct injection. int do_continuous_injection = 0; int done_injecting = 1; -- cgit v1.2.3 From 38b802c0ba0d47fd179a2b384e8867248de078e9 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Tue, 7 May 2019 08:35:22 -0700 Subject: consistent continuous injection for PhysicalParticle and LaserParticle --- Source/Evolve/WarpXEvolveEM.cpp | 2 +- Source/Laser/LaserParticleContainer.H | 1 + Source/Laser/LaserParticleContainer.cpp | 6 +++++- Source/Particles/MultiParticleContainer.cpp | 4 +++- Source/Particles/PhysicalParticleContainer.H | 7 +++++-- Source/Particles/PhysicalParticleContainer.cpp | 19 ++++++++++++++++--- Source/Particles/WarpXParticleContainer.H | 2 +- Source/Utils/WarpXMovingWindow.cpp | 6 ++++++ Source/WarpX.cpp | 13 ++++++++----- 9 files changed, 46 insertions(+), 14 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index 4a3ea092d..7fe47d261 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -90,7 +90,7 @@ WarpX::EvolveEM (int numsteps) // Performs continuous injection of all WarpXParticleContainer // in mypc. - mypc->ContinuousInjection(dt[0], geom[0].ProbDomain()); + // mypc->ContinuousInjection(dt[0], geom[0].ProbDomain()); if (do_subcycling == 0 || finest_level == 0) { OneStep_nosub(cur_time); diff --git a/Source/Laser/LaserParticleContainer.H b/Source/Laser/LaserParticleContainer.H index 2e40ca5be..4c7de4c81 100644 --- a/Source/Laser/LaserParticleContainer.H +++ b/Source/Laser/LaserParticleContainer.H @@ -88,6 +88,7 @@ private: // Theoretical position of the antenna. Used if do_continuous_injection=1. // Track the position of the antenna until it enters the simulation domain. amrex::Real z_antenna_th; + int done_injecting=1; void ComputeSpacing (int lev, amrex::Real& Sx, amrex::Real& Sy) const; void ComputeWeightMobility (amrex::Real Sx, amrex::Real Sy); diff --git a/Source/Laser/LaserParticleContainer.cpp b/Source/Laser/LaserParticleContainer.cpp index d28bd75e5..569d99c97 100644 --- a/Source/Laser/LaserParticleContainer.cpp +++ b/Source/Laser/LaserParticleContainer.cpp @@ -205,6 +205,8 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, void LaserParticleContainer::ContinuousInjection (Real dt, const RealBox& prob_domain) { + Print()<<" --- In LaserParticleContainer::ContinuousInjection"<1){ z_antenna_th -= PhysConst::c * WarpX::beta_boost * dt; @@ -222,7 +224,9 @@ LaserParticleContainer::ContinuousInjection (Real dt, const RealBox& prob_domain // Get domain boundaries in the z direction const Real prob_lo_z = prob_domain.lo()[AMREX_SPACEDIM-1]; const Real prob_hi_z = prob_domain.hi()[AMREX_SPACEDIM-1]; - if ( z_antenna_th>prob_lo_z && z_antenna_th=prob_lo_z && z_antenna_thdo_continuous_injection "<do_continuous_injection<do_continuous_injection) { + Print()<<"i "<do_continuous_injection "<do_continuous_injection<ContinuousInjection(dt, prob_domain); } } diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index 362683879..253aa58cd 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -101,8 +101,9 @@ public: const amrex::Real t_lab, const amrex::Real dt, DiagnosticParticles& diagnostic_particles) final; - bool injected = false; - + // bool injected = false; + // int do_continuous_injection = false; + protected: std::string species_name; @@ -122,6 +123,8 @@ protected: int GetRefineFac(const amrex::Real x, const amrex::Real y, const amrex::Real z); std::unique_ptr m_refined_injection_mask = nullptr; + void ContinuousInjection(amrex::Real dt, const amrex::RealBox& prob_domain) override; + }; #endif diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 17e6d98d9..c28aacd28 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -24,7 +24,8 @@ NumParticlesToAdd(const Box& overlap_box, const RealBox& overlap_realbox, for (IntVect iv = overlap_box.smallEnd(); iv <= overlap_box.bigEnd(); overlap_box.next(iv)) { int fac; - if (injected) { + // if (injected) { + if (do_continuous_injection) { #if ( AMREX_SPACEDIM == 3 ) Real x = overlap_corner[0] + (iv[0] + 0.5)*dx[0]; Real y = overlap_corner[1] + (iv[1] + 0.5)*dx[1]; @@ -81,6 +82,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp pp.query("do_backward_propagation", do_backward_propagation); pp.query("do_splitting", do_splitting); pp.query("split_type", split_type); + pp.query("do_continuous_injection", do_continuous_injection); } PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core) @@ -361,7 +363,9 @@ PhysicalParticleContainer::AddPlasmaCPU (int lev, RealBox part_realbox) for (IntVect iv = overlap_box.smallEnd(); iv <= overlap_box.bigEnd(); overlap_box.next(iv)) { int fac; - if (injected) { + // if (injected) { + if (do_continuous_injection) { + Print()<<"in AddPlasmaCPU if do_continuous_injection"< local_rho; amrex::Vector local_jx; diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index 05e171f22..5b84a1eb0 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -163,13 +163,19 @@ WarpX::MoveWindow (bool move_j) particleBox.setHi( dir, current_injection_position ); } // Perform the injection of new particles in particleBox + // Performs continuous injection of all WarpXParticleContainer + // in mypc. + if (particleBox.ok() and (current_injection_position != new_injection_position)){ + mypc->ContinuousInjection(dt[0], particleBox); + /* for (int i = 0; i < num_injected_species; ++i) { int ispecies = injected_plasma_species[i]; WarpXParticleContainer& pc = mypc->GetParticleContainer(ispecies); auto& ppc = dynamic_cast(pc); ppc.AddPlasma(lev, particleBox); } + */ // Update the injection position current_injection_position = new_injection_position; } diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 47ead98df..645e92161 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -146,14 +146,17 @@ WarpX::WarpX () // Particle Container mypc = std::unique_ptr (new MultiParticleContainer(this)); + /* if (do_plasma_injection) { for (int i = 0; i < num_injected_species; ++i) { int ispecies = injected_plasma_species[i]; WarpXParticleContainer& pc = mypc->GetParticleContainer(ispecies); auto& ppc = dynamic_cast(pc); - ppc.injected = true; + // ppc.injected = true; + ppc.do_continuous_injection = 1; } } + */ Efield_aux.resize(nlevs_max); Bfield_aux.resize(nlevs_max); @@ -302,10 +305,10 @@ WarpX::ReadParameters () pp.query("do_plasma_injection", do_plasma_injection); if (do_plasma_injection) { - pp.get("num_injected_species", num_injected_species); - injected_plasma_species.resize(num_injected_species); - pp.getarr("injected_plasma_species", injected_plasma_species, - 0, num_injected_species); + // pp.get("num_injected_species", num_injected_species); + // injected_plasma_species.resize(num_injected_species); + // pp.getarr("injected_plasma_species", injected_plasma_species, + // 0, num_injected_species); if (moving_window_v >= 0){ // Inject particles continuously from the right end of the box current_injection_position = geom[0].ProbHi(moving_window_dir); -- cgit v1.2.3 From 6bdafd570c25fde71d2ce93ecea6fbd803f8cf2c Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Tue, 7 May 2019 09:32:47 -0700 Subject: laser and plasma cont injection combined and working with MW and boost in z --- Source/Laser/LaserParticleContainer.H | 1 + Source/Laser/LaserParticleContainer.cpp | 46 ++++++++++++++++++++++++++--- Source/Particles/MultiParticleContainer.H | 4 ++- Source/Particles/MultiParticleContainer.cpp | 24 +++++++++++++++ Source/Particles/WarpXParticleContainer.H | 1 + Source/Utils/WarpXMovingWindow.cpp | 4 ++- 6 files changed, 74 insertions(+), 6 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Laser/LaserParticleContainer.H b/Source/Laser/LaserParticleContainer.H index 4c7de4c81..bb36f4795 100644 --- a/Source/Laser/LaserParticleContainer.H +++ b/Source/Laser/LaserParticleContainer.H @@ -96,6 +96,7 @@ private: // Inject the laser antenna during the simulation, if it started // outside of the simulation domain and enters it. void ContinuousInjection(amrex::Real dt, const amrex::RealBox& prob_domain) override; + void UpdateContinuousInjectionPosition(amrex::Real dt) override; }; #endif diff --git a/Source/Laser/LaserParticleContainer.cpp b/Source/Laser/LaserParticleContainer.cpp index 569d99c97..8499455de 100644 --- a/Source/Laser/LaserParticleContainer.cpp +++ b/Source/Laser/LaserParticleContainer.cpp @@ -207,10 +207,6 @@ LaserParticleContainer::ContinuousInjection (Real dt, const RealBox& prob_domain { Print()<<" --- In LaserParticleContainer::ContinuousInjection"<1){ - z_antenna_th -= PhysConst::c * WarpX::beta_boost * dt; - } // If laser antenna particles have not been injected yet, // check if they should be injected at this iteration. If // so, inject them and set done_injecting to 0 (false). @@ -239,6 +235,48 @@ LaserParticleContainer::ContinuousInjection (Real dt, const RealBox& prob_domain } } +void +LaserParticleContainer::UpdateContinuousInjectionPosition(Real dt) +{ + int dir = WarpX::moving_window_dir; + // update position of the antenna (outside of the box) + // Continuously inject plasma in new cells (by default only on level 0) + if (do_continuous_injection and (WarpX::gamma_boost > 1)){ + // In boosted-frame simulations, the plasma 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 ) + 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. + 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 () { diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index c6bc6d768..f48daf9bb 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -172,7 +172,9 @@ public: void ContinuousInjection(amrex::Real dt, const amrex::RealBox& prob_domain) const; - + + void UpdateContinuousInjectionPosition(amrex::Real dt) const; + // // Parameters for the Cherenkov corrector in the FDTD solver. // Both stencils are calculated ar runtime. diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 1ce0c5390..9810a168f 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -434,3 +434,27 @@ MultiParticleContainer::ContinuousInjection(Real dt, const RealBox& prob_domain) } } } + +void +MultiParticleContainer::UpdateContinuousInjectionPosition(Real dt) const +{ + for (int i=0; ido_continuous_injection "<do_continuous_injection<do_continuous_injection) + { + Print()<<"i "<do_continuous_injection "<do_continuous_injection<UpdateContinuousInjectionPosition(dt); + } + } + /* + for (int i=nspecies; i(pc); + // auto& pc = allcontainers[i]; + // auto& lpc = dynamic_cast(pc); + lpc.UpdateContinuousInjectionPosition(dt); + } + */ +} diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 62f3570ad..51238907d 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -193,6 +193,7 @@ public: // RigidInjectedParticleContainer: not implemented. virtual void ContinuousInjection(amrex::Real dt, const amrex::RealBox& prob_domain) {} + virtual void UpdateContinuousInjectionPosition(amrex::Real dt) {} /// /// This returns the total charge for all the particles in this ParticleContainer. diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index 5b84a1eb0..2ba1d2f59 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -33,8 +33,10 @@ WarpX::MoveWindow (bool move_j) // and of the plasma injection moving_window_x += moving_window_v * dt[0]; int dir = moving_window_dir; - UpdatePlasmaInjectionPosition( dt[0] ); + UpdatePlasmaInjectionPosition( dt[0] ); + mypc->UpdateContinuousInjectionPosition( dt[0] ); + // compute the number of cells to shift on the base level Real new_lo[AMREX_SPACEDIM]; Real new_hi[AMREX_SPACEDIM]; -- cgit v1.2.3 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/Evolve/WarpXEvolveEM.cpp | 4 - Source/Laser/LaserParticleContainer.H | 8 +- Source/Laser/LaserParticleContainer.cpp | 134 ++++++++++--------------- Source/Particles/MultiParticleContainer.H | 8 +- Source/Particles/MultiParticleContainer.cpp | 32 ++---- Source/Particles/PhysicalParticleContainer.H | 6 +- Source/Particles/PhysicalParticleContainer.cpp | 13 ++- Source/Particles/WarpXParticleContainer.H | 7 +- Source/Utils/WarpXMovingWindow.cpp | 29 +++--- Source/WarpX.cpp | 12 --- 10 files changed, 98 insertions(+), 155 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index 7fe47d261..e98561be1 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -88,10 +88,6 @@ WarpX::EvolveEM (int numsteps) UpdateAuxilaryData(); } - // Performs continuous injection of all WarpXParticleContainer - // in mypc. - // mypc->ContinuousInjection(dt[0], geom[0].ProbDomain()); - if (do_subcycling == 0 || finest_level == 0) { OneStep_nosub(cur_time); } else if (do_subcycling == 1 && finest_level == 1) { diff --git a/Source/Laser/LaserParticleContainer.H b/Source/Laser/LaserParticleContainer.H index bb36f4795..ccd48f3b5 100644 --- a/Source/Laser/LaserParticleContainer.H +++ b/Source/Laser/LaserParticleContainer.H @@ -84,10 +84,11 @@ private: std::string field_function; // laser particle domain - amrex::RealBox laser_prob_domain; + amrex::RealBox laser_injection_box; // Theoretical position of the antenna. Used if do_continuous_injection=1. // Track the position of the antenna until it enters the simulation domain. - amrex::Real z_antenna_th; + amrex::Vector updated_position; + // Avoid injecting the antenna several times. int done_injecting=1; void ComputeSpacing (int lev, amrex::Real& Sx, amrex::Real& Sy) const; @@ -95,7 +96,8 @@ private: void InitData (int lev); // Inject the laser antenna during the simulation, if it started // outside of the simulation domain and enters it. - void ContinuousInjection(amrex::Real dt, const amrex::RealBox& prob_domain) override; + void ContinuousInjection(const amrex::RealBox& injection_box) override; + // Update position of the antenna void UpdateContinuousInjectionPosition(amrex::Real dt) override; }; 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]); diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index f48daf9bb..49a79231c 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -170,9 +170,11 @@ public: const amrex::Real t_boost, const amrex::Real t_lab, const amrex::Real dt, amrex::Vector& parts) const; - void ContinuousInjection(amrex::Real dt, - const amrex::RealBox& prob_domain) const; - + // Inject particles during the simulation (for particles entering the + // simulation domain after some iterations, due to flowing plasma and/or + // moving window). + void ContinuousInjection(const amrex::RealBox& injection_box) const; + // Update injection position for continuously-injected species. void UpdateContinuousInjectionPosition(amrex::Real dt) const; // diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 9810a168f..a5f695c69 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -416,45 +416,33 @@ MultiParticleContainer } /* \brief Continuous injection for particles initially outside of the domain. - * \param dt: timestep (so far, this only works without MR) - * \param prob_domain: current boundaries of the full domain. + * \param injection_box: Domain where new particles should be injected. * Loop over all WarpXParticleContainer in MultiParticleContainer and * calls virtual function ContinuousInjection. */ void -MultiParticleContainer::ContinuousInjection(Real dt, const RealBox& prob_domain) const +MultiParticleContainer::ContinuousInjection(const RealBox& injection_box) const { for (int i=0; ido_continuous_injection "<do_continuous_injection<do_continuous_injection) - { - Print()<<"i "<do_continuous_injection "<do_continuous_injection<ContinuousInjection(dt, prob_domain); + if (pc->do_continuous_injection){ + pc->ContinuousInjection(injection_box); } } } +/* \brief Update position of continuous injection parameters. + * \param dt: simulation time step (level 0) + * All classes inherited from WarpXParticleContainer do not have + * a position to update (PhysicalParticleContainer does not do anything). + */ void MultiParticleContainer::UpdateContinuousInjectionPosition(Real dt) const { for (int i=0; ido_continuous_injection "<do_continuous_injection<do_continuous_injection) - { - Print()<<"i "<do_continuous_injection "<do_continuous_injection<do_continuous_injection){ pc->UpdateContinuousInjectionPosition(dt); } } - /* - for (int i=nspecies; i(pc); - // auto& pc = allcontainers[i]; - // auto& lpc = dynamic_cast(pc); - lpc.UpdateContinuousInjectionPosition(dt); - } - */ } diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index 253aa58cd..4f365768b 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -101,9 +101,6 @@ public: const amrex::Real t_lab, const amrex::Real dt, DiagnosticParticles& diagnostic_particles) final; - // bool injected = false; - // int do_continuous_injection = false; - protected: std::string species_name; @@ -123,7 +120,8 @@ protected: int GetRefineFac(const amrex::Real x, const amrex::Real y, const amrex::Real z); std::unique_ptr m_refined_injection_mask = nullptr; - void ContinuousInjection(amrex::Real dt, const amrex::RealBox& prob_domain) override; + // Inject particles during the whole simulation + void ContinuousInjection(const amrex::RealBox& injection_box) override; }; diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index c28aacd28..2fa39d87d 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -24,7 +24,6 @@ NumParticlesToAdd(const Box& overlap_box, const RealBox& overlap_realbox, for (IntVect iv = overlap_box.smallEnd(); iv <= overlap_box.bigEnd(); overlap_box.next(iv)) { int fac; - // if (injected) { if (do_continuous_injection) { #if ( AMREX_SPACEDIM == 3 ) Real x = overlap_corner[0] + (iv[0] + 0.5)*dx[0]; @@ -363,9 +362,7 @@ PhysicalParticleContainer::AddPlasmaCPU (int lev, RealBox part_realbox) for (IntVect iv = overlap_box.smallEnd(); iv <= overlap_box.bigEnd(); overlap_box.next(iv)) { int fac; - // if (injected) { if (do_continuous_injection) { - Print()<<"in AddPlasmaCPU if do_continuous_injection"< local_rho; amrex::Vector local_jx; diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index 2ba1d2f59..38bde5e92 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -34,9 +34,16 @@ WarpX::MoveWindow (bool move_j) moving_window_x += moving_window_v * dt[0]; int dir = moving_window_dir; + // Update warpx.current_injection_position + // PhysicalParticleContainer uses this injection position UpdatePlasmaInjectionPosition( dt[0] ); - mypc->UpdateContinuousInjectionPosition( dt[0] ); - + if (WarpX::do_plasma_injection){ + // Update injection position for WarpXParticleContainer in mypc. + // Nothing to do for PhysicalParticleContainers + // For LaserParticleContainer, need to update the antenna position. + mypc->UpdateContinuousInjectionPosition( dt[0] ); + } + // compute the number of cells to shift on the base level Real new_lo[AMREX_SPACEDIM]; Real new_hi[AMREX_SPACEDIM]; @@ -164,21 +171,11 @@ WarpX::MoveWindow (bool move_j) particleBox.setLo( dir, new_injection_position ); particleBox.setHi( dir, current_injection_position ); } - // Perform the injection of new particles in particleBox - // Performs continuous injection of all WarpXParticleContainer - // in mypc. - + if (particleBox.ok() and (current_injection_position != new_injection_position)){ - mypc->ContinuousInjection(dt[0], particleBox); - /* - for (int i = 0; i < num_injected_species; ++i) { - int ispecies = injected_plasma_species[i]; - WarpXParticleContainer& pc = mypc->GetParticleContainer(ispecies); - auto& ppc = dynamic_cast(pc); - ppc.AddPlasma(lev, particleBox); - } - */ - // Update the injection position + // Performs continuous injection of all WarpXParticleContainer + // in mypc. + mypc->ContinuousInjection(particleBox); current_injection_position = new_injection_position; } } diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 645e92161..bea91f1ba 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -146,18 +146,6 @@ WarpX::WarpX () // Particle Container mypc = std::unique_ptr (new MultiParticleContainer(this)); - /* - if (do_plasma_injection) { - for (int i = 0; i < num_injected_species; ++i) { - int ispecies = injected_plasma_species[i]; - WarpXParticleContainer& pc = mypc->GetParticleContainer(ispecies); - auto& ppc = dynamic_cast(pc); - // ppc.injected = true; - ppc.do_continuous_injection = 1; - } - } - */ - Efield_aux.resize(nlevs_max); Bfield_aux.resize(nlevs_max); -- cgit v1.2.3 From 2ddaf2f8270247b847041da886adefb4f96714c1 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Tue, 7 May 2019 12:56:03 -0700 Subject: remove do_plasma_injection and cleaning --- Source/Laser/LaserParticleContainer.cpp | 5 +++-- Source/Particles/MultiParticleContainer.H | 1 + Source/Particles/MultiParticleContainer.cpp | 13 +++++++++++++ Source/Utils/WarpXMovingWindow.cpp | 6 +++--- Source/WarpX.H | 3 ++- Source/WarpX.cpp | 25 ++++++++++--------------- Tools/Visualization.ipynb | 10 +++++----- 7 files changed, 37 insertions(+), 26 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Laser/LaserParticleContainer.cpp b/Source/Laser/LaserParticleContainer.cpp index a7fe9042d..3bbd7a039 100644 --- a/Source/Laser/LaserParticleContainer.cpp +++ b/Source/Laser/LaserParticleContainer.cpp @@ -175,14 +175,15 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, } // Sanity checks - std::Vector windir(3, 0.0); + int dir = WarpX::moving_window_dir; + 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]-windir[0]) + (nvec[1]-windor[1]) + (nvec[2]-windor[2]) + (nvec[0]-windir[0]) + (nvec[1]-windir[1]) + (nvec[2]-windir[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 ){ diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 49a79231c..0c5e49c04 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -176,6 +176,7 @@ public: void ContinuousInjection(const amrex::RealBox& injection_box) const; // Update injection position for continuously-injected species. void UpdateContinuousInjectionPosition(amrex::Real dt) const; + int doContinuousInjection() const; // // Parameters for the Cherenkov corrector in the FDTD solver. diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index a5f695c69..440906348 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -446,3 +446,16 @@ MultiParticleContainer::UpdateContinuousInjectionPosition(Real dt) const } } } + +int +MultiParticleContainer::doContinuousInjection() const +{ + int warpx_do_continuous_injection = 0; + for (int i=0; ido_continuous_injection){ + warpx_do_continuous_injection = 1; + } + } + return warpx_do_continuous_injection; +} diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index 38bde5e92..18d89951d 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -9,7 +9,7 @@ WarpX::UpdatePlasmaInjectionPosition (Real dt) { int dir = moving_window_dir; // Continuously inject plasma in new cells (by default only on level 0) - if (WarpX::do_plasma_injection and (WarpX::gamma_boost > 1)){ + if (WarpX::warpx_do_continuous_injection and (WarpX::gamma_boost > 1)){ // In boosted-frame simulations, the plasma has moved since the last // call to this function, and injection position needs to be updated current_injection_position -= WarpX::beta_boost * @@ -37,7 +37,7 @@ WarpX::MoveWindow (bool move_j) // Update warpx.current_injection_position // PhysicalParticleContainer uses this injection position UpdatePlasmaInjectionPosition( dt[0] ); - if (WarpX::do_plasma_injection){ + if (WarpX::warpx_do_continuous_injection){ // Update injection position for WarpXParticleContainer in mypc. // Nothing to do for PhysicalParticleContainers // For LaserParticleContainer, need to update the antenna position. @@ -143,7 +143,7 @@ WarpX::MoveWindow (bool move_j) } // Continuously inject plasma in new cells (by default only on level 0) - if (WarpX::do_plasma_injection) { + if (WarpX::warpx_do_continuous_injection) { const int lev = 0; diff --git a/Source/WarpX.H b/Source/WarpX.H index 9e9776117..710b2a7e7 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -476,7 +476,8 @@ private: amrex::Real current_injection_position = 0; // Plasma injection parameters - int do_plasma_injection = 0; + // int do_plasma_injection = 0; + int warpx_do_continuous_injection = 0; int num_injected_species = -1; amrex::Vector injected_plasma_species; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index bea91f1ba..a3a24897a 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -145,6 +145,16 @@ WarpX::WarpX () // Particle Container mypc = std::unique_ptr (new MultiParticleContainer(this)); + warpx_do_continuous_injection = mypc->doContinuousInjection(); + if (warpx_do_continuous_injection){ + if (moving_window_v >= 0){ + // Inject particles continuously from the right end of the box + current_injection_position = geom[0].ProbHi(moving_window_dir); + } else { + // Inject particles continuously from the left end of the box + current_injection_position = geom[0].ProbLo(moving_window_dir); + } + } Efield_aux.resize(nlevs_max); Bfield_aux.resize(nlevs_max); @@ -291,21 +301,6 @@ WarpX::ReadParameters () moving_window_v *= PhysConst::c; } - pp.query("do_plasma_injection", do_plasma_injection); - if (do_plasma_injection) { - // pp.get("num_injected_species", num_injected_species); - // injected_plasma_species.resize(num_injected_species); - // pp.getarr("injected_plasma_species", injected_plasma_species, - // 0, num_injected_species); - if (moving_window_v >= 0){ - // Inject particles continuously from the right end of the box - current_injection_position = geom[0].ProbHi(moving_window_dir); - } else { - // Inject particles continuously from the left end of the box - current_injection_position = geom[0].ProbLo(moving_window_dir); - } - } - pp.query("do_boosted_frame_diagnostic", do_boosted_frame_diagnostic); if (do_boosted_frame_diagnostic) { diff --git a/Tools/Visualization.ipynb b/Tools/Visualization.ipynb index f5946a3de..5ac03f931 100644 --- a/Tools/Visualization.ipynb +++ b/Tools/Visualization.ipynb @@ -991,21 +991,21 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.14" + "pygments_lexer": "ipython3", + "version": "3.7.1" }, "widgets": { "state": { -- cgit v1.2.3