Skip to content

Commit

Permalink
AddPlasmaFromFile fix for periodic boundaries (#1089)
Browse files Browse the repository at this point in the history
* Added description of singleparticle particle injection style

* Revert "Added description of singleparticle particle injection style"

This reverts commit f02d842.

* Tried to inject particles only in simulation Box

* Added Todo for multiple levels of mesh refinement

* Explain todo better

* Added x and y_shifts and replaced cascading ifs by bools and continue

* Replaced cascading ifs by bools and continue

* Replaced TODO by FIXME as reviewer suggested

* Made the insidebounds function use box limits as defaults

* Fixed identation issue

* Fixed identation issue

* Fixed identation issue

* Added to Docs the default for xmin,xmax and other dirs

* Fix missing y and z dirs

* Update Source/Initialization/PlasmaInjector.cpp

* Fixed PlasmaInjector limits with periodic condition

* Removed check if 3D because now ylims are +/-inf

* Restored if to check for y velocity also in 2D/RZ

* Fixed Docs to recent changes

* Update Source/Initialization/PlasmaInjector.cpp

* Fix extra bracket

* Tiny bool cleanup

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
  • Loading branch information
LDAmorim and ax3l authored Jun 22, 2020
1 parent 9f7fc11 commit 97755d1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Docs/source/running_cpp/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ Particle initialization
The mass of one `physical` particle of this species.
If ``species_type`` is specified, the mass will be set to the physical value and ``mass`` is optional.

* ``<species_name>.xmin,ymin,zmin`` (`float`) optional (default unlimited)
When ``<species_name>.xmin`` and ``<species_name>.xmax`` (see below) are set, they delimit the region within which particles are injected.
The same is applicable in the other directions.
If periodic boundary conditions are used in direction ``i``, then the default (i.e. if the range is not specified) range will be the simulation box, ``[geometry.prob_hi[i], geometry.prob_lo[i]]``.

* ``<species_name>.xmax,ymax,zmax`` (`float`) optional (default unlimited)

* ``<species_name>.injection_style`` (`string`)
Determines how the particles will be injected in the simulation.
The options are:
Expand Down
26 changes: 25 additions & 1 deletion Source/Initialization/PlasmaInjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
pp.query("radially_weighted", radially_weighted);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(radially_weighted, "ERROR: Only radially_weighted=true is supported");

// parse plasma boundaries
// Unlimited boundaries
xmin = std::numeric_limits<amrex::Real>::lowest();
ymin = std::numeric_limits<amrex::Real>::lowest();
zmin = std::numeric_limits<amrex::Real>::lowest();
Expand All @@ -88,6 +88,30 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
ymax = std::numeric_limits<amrex::Real>::max();
zmax = std::numeric_limits<amrex::Real>::max();

// NOTE: When periodic boundaries are used, default injection range is set to mother grid dimensions.
const Geometry& geom = WarpX::GetInstance().Geom(0);
if( geom.isPeriodic(0) ) {
xmin = geom.ProbLo(0);
xmax = geom.ProbHi(0);
}

if( geom.isPeriodic(1) ) {
# ifndef WARPX_DIM_3D
zmin = geom.ProbLo(1);
zmax = geom.ProbHi(1);
# else
ymin = geom.ProbLo(1);
ymax = geom.ProbHi(1);
# endif
}

# ifdef WARPX_DIM_3D
if( geom.isPeriodic(2) ) {
zmin = geom.ProbLo(2);
zmax = geom.ProbHi(2);
}
# endif

pp.query("xmin", xmin);
pp.query("ymin", ymin);
pp.query("zmin", zmin);
Expand Down
6 changes: 3 additions & 3 deletions Source/Particles/PhysicalParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ PhysicalParticleContainer::AddPlasmaFromFile(ParticleReal q_tot,
uy = ptr_uy.get()[i]*momentum_unit_y/PhysConst::m_e;
}
CheckAndAddParticle(x, y, z, { ux, uy, uz}, weight,
particle_x, particle_y, particle_z,
particle_ux, particle_uy, particle_uz,
particle_w);
particle_x, particle_y, particle_z,
particle_ux, particle_uy, particle_uz,
particle_w);
}
}
auto const np = particle_z.size();
Expand Down

0 comments on commit 97755d1

Please sign in to comment.