Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[small] Inject Particles from openPMD in RZ #1113

Merged
merged 63 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f02d842
Added description of singleparticle particle injection style
LDAmorim Apr 4, 2020
a6901c1
Revert "Added description of singleparticle particle injection style"
LDAmorim Apr 6, 2020
2a5adb2
Merge remote-tracking branch 'upstream/master'
LDAmorim Apr 8, 2020
6c47279
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim Apr 20, 2020
24a131b
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim Apr 22, 2020
2c243e1
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim Apr 23, 2020
bbfbcf2
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim Apr 27, 2020
06a7810
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim Apr 27, 2020
2180838
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim Apr 28, 2020
374671e
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim Apr 30, 2020
75af55e
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim May 12, 2020
e15473d
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim May 13, 2020
2ed1c93
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim May 14, 2020
0d0d346
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim May 22, 2020
b84453a
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim Jun 1, 2020
6bc431a
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX
LDAmorim Jun 12, 2020
85f1730
Tried to inject particles only in simulation Box
LDAmorim Jun 12, 2020
52edd94
Added Todo for multiple levels of mesh refinement
LDAmorim Jun 12, 2020
564a6f0
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX into opmd…
LDAmorim Jun 15, 2020
756faf3
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX into opmd…
LDAmorim Jun 15, 2020
8a404c9
Merge remote-tracking branch 'upstream/master' into opmd_periodic
LDAmorim Jun 16, 2020
adc7dff
Explain todo better
LDAmorim Jun 16, 2020
662b5de
Added x and y_shifts and replaced cascading ifs by bools and continue
LDAmorim Jun 16, 2020
8e5f9a1
Replaced cascading ifs by bools and continue
LDAmorim Jun 16, 2020
8226b87
Replaced TODO by FIXME as reviewer suggested
LDAmorim Jun 16, 2020
0be9125
Made the insidebounds function use box limits as defaults
LDAmorim Jun 17, 2020
eb3155a
Fixed identation issue
LDAmorim Jun 17, 2020
e853fd0
Fixed identation issue
LDAmorim Jun 17, 2020
e1f3b86
Fixed identation issue
LDAmorim Jun 17, 2020
adba576
Added to Docs the default for xmin,xmax and other dirs
LDAmorim Jun 17, 2020
6f1f0f9
Fix missing y and z dirs
LDAmorim Jun 17, 2020
7d49b3e
Merge branch 'master' of https://github.com/ECP-WarpX/WarpX into opmd…
LDAmorim Jun 17, 2020
c8eb2ed
Update Source/Initialization/PlasmaInjector.cpp
LDAmorim Jun 17, 2020
829b70f
Fixed PlasmaInjector limits with periodic condition
LDAmorim Jun 17, 2020
2327c64
Removed check if 3D because now ylims are +/-inf
LDAmorim Jun 17, 2020
dafbff6
Restored if to check for y velocity also in 2D/RZ
LDAmorim Jun 17, 2020
cfcc502
Fixed Docs to recent changes
LDAmorim Jun 17, 2020
35ad432
Update Source/Initialization/PlasmaInjector.cpp
LDAmorim Jun 17, 2020
30e9658
Fix extra bracket
LDAmorim Jun 17, 2020
fc7f091
Added information about RZ geometry for openPMD external file
LDAmorim Jun 18, 2020
b744209
Fix to issue without periodic boundaries
LDAmorim Jun 18, 2020
382a29e
Added variable rz_take_absolute, to allow to inject x<0 particles in RZ
LDAmorim Jun 18, 2020
55bfb67
Fix to declaration of addplasmafromfile rz_take_absolute
LDAmorim Jun 18, 2020
a7aab79
Fix to declaration of addplasmafromfile rz_take_absolute
LDAmorim Jun 18, 2020
87e138d
Fixed documentation to include rz_take_absolute option
LDAmorim Jun 18, 2020
a65a510
Fixed documentation to include rz_take_absolute option
LDAmorim Jun 18, 2020
085d51f
Fix merging conflict
LDAmorim Jun 18, 2020
23c26ce
Final fix to xmax=inf in RZ
LDAmorim Jun 18, 2020
7f3a059
Merge branch 'development' of https://github.com/ECP-WarpX/WarpX into…
LDAmorim Jun 18, 2020
1b08dc7
In RZ particles are injected in x,y,z
LDAmorim Jun 19, 2020
40d1ba3
Fixed remaining rz_take_absolute
LDAmorim Jun 19, 2020
66291d6
Fixed merging conflicts
LDAmorim Jun 22, 2020
3e53699
Merge remote-tracking branch 'upstream/development' into opmd_rz
LDAmorim Jun 22, 2020
6ccfd0d
Merge remote-tracking branch 'upstream/development' into opmd_rz
LDAmorim Jun 22, 2020
9a425b8
Converted (x,y,z) to (r,0,z)
LDAmorim Jun 23, 2020
e6ab381
Merge remote-tracking branch 'upstream/development' into opmd_rz
LDAmorim Jun 23, 2020
a3ac3fe
Fixed bounds limits (r,z) but injection is in 3D
LDAmorim Jun 23, 2020
2d66cc6
Re-fix to insideBounds()
LDAmorim Jun 23, 2020
8a9c675
AMReX assert of periodic in RZ
LDAmorim Jun 23, 2020
47bd24c
Removed Assert -> went to PR 1115 by @dpgrote
LDAmorim Jun 23, 2020
4abbe66
Fixed issues pointed out by reviewer @dpgrote
LDAmorim Jun 23, 2020
82d346d
Undo changes for future PR
LDAmorim Jun 23, 2020
3cb10ed
Undo changes for future PR
LDAmorim Jun 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Docs/source/running_cpp/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ Particle initialization
``<species_name>.z_shift`` (`double`) optional (default is no shift) when set this value will be added to the longitudinal, ``z``, position of the particles.
The external file must include the species ``openPMD::Record``s labeled ``position`` and ``momentum`` (`double` arrays), with dimensionality and units set via ``openPMD::setUnitDimension`` and ``setUnitSI``.
If the external file also contains ``openPMD::Records``s for ``mass`` and ``charge`` (constant `double` scalars) then the species will use these, unless overwritten in the input file (see ``<species_name>.mass``, ```<species_name>.charge`` or ```<species_name>.species_type``).
The ``external_file`` option is currently implemented for 2D and 3D geometries, with record components ``x``, ``z`` and ``y`` for 3D.
The ``external_file`` option is currently implemented for 2D, 3D and RZ geometries, with record components in the cartesian coordinates ``(x,y,z)`` for 3D and RZ, and ``(x,z)`` for 2D.
For more information on the `openPMD format <https://github.com/openPMD>`__ and how to build WarpX with it, please visit :doc:`../building/openpmd`.

* ``<species_name>.num_particles_per_cell_each_dim`` (`3 integers in 3D and RZ, 2 integers in 2D`)
Expand Down
10 changes: 3 additions & 7 deletions Source/Initialization/PlasmaInjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,16 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
parseDensity(pp);
parseMomentum(pp);
} else if (part_pos_s == "external_file") {
#ifdef WARPX_DIM_RZ
amrex::Abort("The option of reading particle data from an external "
"file has not been implemented nor tested in RZ geometry");
#endif
pp.query("q_tot", q_tot); // optional
#ifndef WARPX_USE_OPENPMD
amrex::Abort("WarpX has to be compiled with USE_OPENPMD=TRUE to be able"
" to read the external openPMD file with species data");
#endif
external_file = true;
std::string str_injection_file;
pp.get("injection_file", str_injection_file);
// optional parameters
pp.query("q_tot", q_tot);
pp.query("z_shift",z_shift);

#ifdef WARPX_USE_OPENPMD
if (ParallelDescriptor::IOProcessor()) {
Expand Down Expand Up @@ -327,8 +325,6 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name)
double const mass_unit = ps["mass"][openPMD::RecordComponent::SCALAR].unitSI();
mass = p_m * mass_unit;
}

pp.query("z_shift",z_shift);
} // IOProcessor

// Broadcast charge and mass to non-IO processors
Expand Down
11 changes: 10 additions & 1 deletion Source/Particles/PhysicalParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ public:
// Inject particles in Box 'part_box'
virtual void AddParticles (int lev);

/**
* Create new macroparticles for this species, with a fixed
* number of particles per cell (in the cells of `part_realbox`).
* The new particles are only created inside the intersection of `part_realbox`
* with the local grid for the current proc.
* @param[in] lev the index of the refinement level
* @param[in] part_realbox the box in which new particles should be created
* (this box should correspond to an integer number of cells in each direction,
* but its boundaries need not be aligned with the actual cells of the simulation)
*/
void AddPlasma (int lev, amrex::RealBox part_realbox = amrex::RealBox());

void MapParticletoBoostedFrame (amrex::Real& x, amrex::Real& y, amrex::Real& z, std::array<amrex::Real, 3>& u);
Expand All @@ -185,7 +195,6 @@ public:
const amrex::Real q_tot, long npart, const int do_symmetrize);

/** Load a particle beam from an external file
*
* @param[in] q_tot total charge of the particle species to be initialized
*/
void AddPlasmaFromFile (amrex::ParticleReal q_tot,
Expand Down
20 changes: 5 additions & 15 deletions Source/Particles/PhysicalParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ PhysicalParticleContainer::AddGaussianBeam (
npart /= 4;
}
for (long i = 0; i < npart; ++i) {
#if (defined WARPX_DIM_3D) || (WARPX_DIM_RZ)
#if (defined WARPX_DIM_3D) || (defined WARPX_DIM_RZ)
const Real weight = q_tot/(npart*charge);
const Real x = distx(mt);
const Real y = disty(mt);
Expand Down Expand Up @@ -328,7 +328,7 @@ PhysicalParticleContainer::AddPlasmaFromFile(ParticleReal q_tot,
double const momentum_unit_x = ps["momentum"]["x"].unitSI();
std::shared_ptr<ParticleReal> ptr_uz = ps["momentum"]["z"].loadChunk<ParticleReal>();
double const momentum_unit_z = ps["momentum"]["z"].unitSI();
# ifdef WARPX_DIM_3D
# ifndef WARPX_DIM_XZ
std::shared_ptr<ParticleReal> ptr_y = ps["position"]["y"].loadChunk<ParticleReal>();
double const position_unit_y = ps["position"]["y"].unitSI();
# endif
Expand Down Expand Up @@ -361,10 +361,10 @@ PhysicalParticleContainer::AddPlasmaFromFile(ParticleReal q_tot,
for (auto i = decltype(npart){0}; i<npart; ++i){
ParticleReal const x = ptr_x.get()[i]*position_unit_x;
ParticleReal const z = ptr_z.get()[i]*position_unit_z+z_shift;
# ifndef WARPX_DIM_3D
ParticleReal const y = 0.0_prt;
# else
# if (defined WARPX_DIM_3D) || (defined WARPX_DIM_RZ)
ParticleReal const y = ptr_y.get()[i]*position_unit_y;
# else
ParticleReal const y = 0.0_prt;
# endif
if (plasma_injector->insideBounds(x, y, z)) {
ParticleReal const ux = ptr_ux.get()[i]*momentum_unit_x/PhysConst::m_e;
Expand Down Expand Up @@ -464,16 +464,6 @@ PhysicalParticleContainer::AddParticles (int lev)
}
}

/**
* Create new macroparticles for this species, with a fixed
* number of particles per cell (in the cells of `part_realbox`).
* The new particles are only created inside the intersection of `part_realbox`
* with the local grid for the current proc.
* @param lev the index of the refinement level
* @param part_realbox the box in which new particles should be created
* (this box should correspond to an integer number of cells in each direction,
* but its boundaries need not be aligned with the actual cells of the simulation)
*/
void
PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox)
{
Expand Down
8 changes: 7 additions & 1 deletion Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,17 @@ WarpX::ReadParameters ()

// Only needs to be set with WARPX_DIM_RZ, otherwise defaults to 1
pp.query("n_rz_azimuthal_modes", n_rz_azimuthal_modes);
#if (defined WARPX_DIM_RZ) && (defined WARPX_USE_PSATD)
#if (defined WARPX_DIM_RZ)
AMREX_ALWAYS_ASSERT_WITH_MESSAGE( Geom(0).isPeriodic(0) == 0, "In RZ,"
" the boundary condition in r can not"
" be periodic.\nPlease change "
" `geometry.is_periodic` in the input");
#if (defined WARPX_USE_PSATD)
// Force do_nodal=true (that is, not staggered) and
// use same shape factors in all directions, for gathering
do_nodal = true;
l_lower_order_in_v = false;
#endif
#endif
}

Expand Down