From 97755d1c2e04e5b8c3295182eaff472c73cf8a53 Mon Sep 17 00:00:00 2001 From: "L. Diana Amorim" Date: Mon, 22 Jun 2020 09:21:59 -0700 Subject: [PATCH] AddPlasmaFromFile fix for periodic boundaries (#1089) * Added description of singleparticle particle injection style * Revert "Added description of singleparticle particle injection style" This reverts commit f02d842c935311458024da6e661950742de24f63. * 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 --- Docs/source/running_cpp/parameters.rst | 7 +++++ Source/Initialization/PlasmaInjector.cpp | 26 ++++++++++++++++++- .../Particles/PhysicalParticleContainer.cpp | 6 ++--- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index 31835e29aa1..214ad8fe9fe 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -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. +* ``.xmin,ymin,zmin`` (`float`) optional (default unlimited) + When ``.xmin`` and ``.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]]``. + +* ``.xmax,ymax,zmax`` (`float`) optional (default unlimited) + * ``.injection_style`` (`string`) Determines how the particles will be injected in the simulation. The options are: diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp index 3de1ab35290..9ba96b1856e 100644 --- a/Source/Initialization/PlasmaInjector.cpp +++ b/Source/Initialization/PlasmaInjector.cpp @@ -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::lowest(); ymin = std::numeric_limits::lowest(); zmin = std::numeric_limits::lowest(); @@ -88,6 +88,30 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) ymax = std::numeric_limits::max(); zmax = std::numeric_limits::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); diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index e0a46f43a9b..a0016d43667 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -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();