From cc429657fc4414539b4fb42da947b831e94448a4 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 16 Feb 2022 16:12:10 -0800 Subject: [PATCH] Provide `t_min` and `t_max` for flux injection (#2842) * Implement injection orthogal to plane * Generalize momentum distribution for flux injection * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks" This reverts commit b0cd1891771a4c49c14abb7cb9df7374cee4458c. * Revert "Generalize momentum distribution for flux injection" This reverts commit 0a22b1d8fa68a3a5705d8f4824f757b6dee497f0. * Rotate momentum initialization * Correct flux number when the direction is normal to plane * Update distribution of particles within a cell * Clean-up injection code * Add more documentation * Add more comments * Handle 1D case * Only do the rotation for Gaussian flux profile * Fix compilation error * Correct compilation for GPU * Start adding automated test * Correct sign of velocity * Update to add continuous injection * Finalize test * Correct processing of flux_normal_axis * Add checksum * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix bug * Update script * Implement maximum injection time * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add parameter tmin * Make parameter optional ; update documentation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- Docs/source/usage/parameters.rst | 2 ++ .../Checksum/benchmarks_json/FluxInjection.json | 2 +- Source/Evolve/WarpXEvolve.cpp | 2 +- Source/Initialization/PlasmaInjector.H | 2 ++ Source/Initialization/PlasmaInjector.cpp | 2 ++ Source/Particles/MultiParticleContainer.H | 2 +- Source/Particles/MultiParticleContainer.cpp | 4 ++-- Source/Particles/PhysicalParticleContainer.H | 2 +- Source/Particles/PhysicalParticleContainer.cpp | 12 +++++++++--- Source/Particles/WarpXParticleContainer.H | 2 +- 10 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index 92bb030caa9..9365bd35ff6 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -613,6 +613,8 @@ Particle initialization ``.flux_normal_axis`` (`x`, `y`, or `z` for 3D, `x` or `z` for 2D, or `r` or `z` for RZ) ``.flux_direction`` (`-1` or `+1`, direction of flux relative to the plane) ``.num_particles_per_cell`` (`double`) + ``.flux_tmin`` (`double`, Optional time at which the flux will be turned on. Ignored when negative.) + ``.flux_tmax`` (`double`, Optional time at which the flux will be turned off. Ignored when negative.) * ``none``: Do not inject macro-particles (for example, in a simulation that starts with neutral, ionizable atoms, one may want to create the electrons species -- where ionized electrons can be stored later on -- without injecting electron macro-particles). diff --git a/Regression/Checksum/benchmarks_json/FluxInjection.json b/Regression/Checksum/benchmarks_json/FluxInjection.json index 56718d77283..b3645168f29 100644 --- a/Regression/Checksum/benchmarks_json/FluxInjection.json +++ b/Regression/Checksum/benchmarks_json/FluxInjection.json @@ -13,4 +13,4 @@ "lev=0": { "Bz": 2.20886367779576e-47 } -} \ No newline at end of file +} diff --git a/Source/Evolve/WarpXEvolve.cpp b/Source/Evolve/WarpXEvolve.cpp index 87aef375b52..383fc05fc2e 100644 --- a/Source/Evolve/WarpXEvolve.cpp +++ b/Source/Evolve/WarpXEvolve.cpp @@ -259,7 +259,7 @@ WarpX::Evolve (int numsteps) // We might need to move j because we are going to make a plotfile. int num_moved = MoveWindow(step+1, move_j); - mypc->ContinuousFluxInjection(dt[0]); + mypc->ContinuousFluxInjection(cur_time, dt[0]); mypc->ApplyBoundaryConditions(); diff --git a/Source/Initialization/PlasmaInjector.H b/Source/Initialization/PlasmaInjector.H index 0b53b49ee63..d97f7325062 100644 --- a/Source/Initialization/PlasmaInjector.H +++ b/Source/Initialization/PlasmaInjector.H @@ -107,6 +107,8 @@ public: bool surface_flux = false; // inject from a surface amrex::Real surface_flux_pos; // surface location + amrex::Real flux_tmin = -1.; // Time after which we start injecting particles + amrex::Real flux_tmax = -1.; // Time after which we stop injecting particles // Flux normal axis represents the direction in which to emit particles // When compiled in Cartesian geometry, 0 = x, 1 = y, 2 = z // When compiled in cylindrical geometry, 0 = radial, 1 = azimuthal, 2 = z diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp index 6026f28a6f5..233b4efc666 100644 --- a/Source/Initialization/PlasmaInjector.cpp +++ b/Source/Initialization/PlasmaInjector.cpp @@ -260,6 +260,8 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) } #endif getWithParser(pp_species_name, "surface_flux_pos", surface_flux_pos); + queryWithParser(pp_species_name, "flux_tmin", flux_tmin); + queryWithParser(pp_species_name, "flux_tmax", flux_tmax); std::string flux_normal_axis_string; pp_species_name.get("flux_normal_axis", flux_normal_axis_string); flux_normal_axis = -1; diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 00fb5e8f5bd..2a8aec1403d 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -285,7 +285,7 @@ public: int doContinuousInjection() const; // Inject particles from a surface during the simulation - void ContinuousFluxInjection(amrex::Real dt) const; + void ContinuousFluxInjection(amrex::Real t, amrex::Real dt) const; std::vector GetSpeciesNames() const { return species_names; } diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 4a5b2ebd868..973cfb8bf48 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -765,10 +765,10 @@ MultiParticleContainer::doContinuousInjection () const * calls virtual function ContinuousFluxInjection. */ void -MultiParticleContainer::ContinuousFluxInjection (amrex::Real dt) const +MultiParticleContainer::ContinuousFluxInjection (amrex::Real t, amrex::Real dt) const { for (auto& pc : allcontainers){ - pc->ContinuousFluxInjection(dt); + pc->ContinuousFluxInjection(t, dt); } } diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index a6a5729e73c..3f3d2d83bd9 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -363,7 +363,7 @@ protected: void ContinuousInjection (const amrex::RealBox& injection_box) override; // Continuously inject a flux of particles from a defined surface - void ContinuousFluxInjection (const amrex::Real dt) override; + void ContinuousFluxInjection (const amrex::Real t, const amrex::Real dt) override; //This function return true if the PhysicalParticleContainer contains electrons //or positrons, false otherwise diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 27d94a5f16d..1ee12b76954 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -2518,10 +2518,16 @@ PhysicalParticleContainer::ContinuousInjection (const RealBox& injection_box) /* \brief Inject a flux of particles during the simulation */ void -PhysicalParticleContainer::ContinuousFluxInjection (amrex::Real dt) +PhysicalParticleContainer::ContinuousFluxInjection (amrex::Real t, amrex::Real dt) { - if (plasma_injector->surface_flux) { - AddPlasmaFlux(dt); + if (plasma_injector->surface_flux){ + // Check the optional parameters for start and stop of injection + if ( ((plasma_injector->flux_tmin<0) || (t>=plasma_injector->flux_tmin)) && + ((plasma_injector->flux_tmax<0) || (t< plasma_injector->flux_tmax)) ){ + + AddPlasmaFlux(dt); + + } } } diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 8f098b49b31..0f5b147efa1 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -245,7 +245,7 @@ public: virtual void UpdateContinuousInjectionPosition(amrex::Real /*dt*/) {} // Inject a continuous flux of particles from a defined plane - virtual void ContinuousFluxInjection(amrex::Real /*dt*/) {} + virtual void ContinuousFluxInjection(amrex::Real /*t*/, amrex::Real /*dt*/) {} /// /// This returns the total charge for all the particles in this ParticleContainer.