Skip to content

Commit

Permalink
Provide t_min and t_max for flux injection (#2842)
Browse files Browse the repository at this point in the history
* 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 b0cd189.

* Revert "Generalize momentum distribution for flux injection"

This reverts commit 0a22b1d.

* 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>
  • Loading branch information
RemiLehe and pre-commit-ci[bot] authored Feb 17, 2022
1 parent 278f3cd commit cc42965
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Docs/source/usage/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ Particle initialization
``<species_name>.flux_normal_axis`` (`x`, `y`, or `z` for 3D, `x` or `z` for 2D, or `r` or `z` for RZ)
``<species_name>.flux_direction`` (`-1` or `+1`, direction of flux relative to the plane)
``<species_name>.num_particles_per_cell`` (`double`)
``<species_name>.flux_tmin`` (`double`, Optional time at which the flux will be turned on. Ignored when negative.)
``<species_name>.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).

Expand Down
2 changes: 1 addition & 1 deletion Regression/Checksum/benchmarks_json/FluxInjection.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"lev=0": {
"Bz": 2.20886367779576e-47
}
}
}
2 changes: 1 addition & 1 deletion Source/Evolve/WarpXEvolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions Source/Initialization/PlasmaInjector.H
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Source/Initialization/PlasmaInjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/Particles/MultiParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> GetSpeciesNames() const { return species_names; }

Expand Down
4 changes: 2 additions & 2 deletions Source/Particles/MultiParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Particles/PhysicalParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions Source/Particles/PhysicalParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Particles/WarpXParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cc42965

Please sign in to comment.