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

[WIP] Laser Injection #1201

Open
wants to merge 101 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
56158d6
new prefactor for calculation of width_p for momentum in linear
EyaDammak Jan 17, 2025
9725208
Update PlasmaParticleContainer.cpp
EyaDammak Jan 17, 2025
089343f
style
EyaDammak Jan 17, 2025
a3ff984
Update PlasmaParticleContainer.cpp
EyaDammak Jan 17, 2025
8436c64
Update PlasmaParticleContainer.H
EyaDammak Jan 17, 2025
b523447
style
EyaDammak Jan 17, 2025
c50df2d
style
EyaDammak Jan 17, 2025
37b39af
Update PlasmaParticleContainer.cpp
EyaDammak Jan 17, 2025
af196e8
Update laser_ionization.1Rank.json
EyaDammak Jan 19, 2025
78cd9de
Update PlasmaParticleContainerInit.cpp
EyaDammak Jan 20, 2025
7a725a3
Update PlasmaParticleContainer.cpp
EyaDammak Jan 22, 2025
8dc706b
Update PlasmaParticleContainer.cpp
EyaDammak Jan 23, 2025
7f8b5b3
squelette
EyaDammak Jan 23, 2025
fb67cde
Merge branch 'injection' of https://github.com/EyaDammak/hipace into …
EyaDammak Jan 23, 2025
0e45cd7
fisrt kernel: counting + make invalid
EyaDammak Jan 23, 2025
000a659
simplification
EyaDammak Jan 24, 2025
8644ef7
update MultiPlasma.H
EyaDammak Jan 24, 2025
a9adc38
update Hipace.cpp
EyaDammak Jan 24, 2025
0e395a5
num_electrons was not defined
EyaDammak Jan 24, 2025
fd15bc9
return issue
EyaDammak Jan 24, 2025
14f2385
resizing the beam particle container
EyaDammak Jan 24, 2025
5199d62
syntax
EyaDammak Jan 24, 2025
189bc16
update resizing
EyaDammak Jan 24, 2025
92c9f2a
update
EyaDammak Jan 24, 2025
c25a23a
update
EyaDammak Jan 24, 2025
ddf3148
include more
EyaDammak Jan 24, 2025
acac290
adding beam defining
EyaDammak Jan 24, 2025
f55078f
includes missing
EyaDammak Jan 24, 2025
9205322
update hiapce.cpp
EyaDammak Jan 24, 2025
418d6f3
update hiapce.cpp for include
EyaDammak Jan 24, 2025
8089c15
update hipace.cpp
EyaDammak Jan 24, 2025
c6e0998
missing a variable for beams
EyaDammak Jan 24, 2025
259e62f
fixing small issue
EyaDammak Jan 24, 2025
9156aa6
update plasmaparticlecontainer
EyaDammak Jan 24, 2025
e1e2c1d
Update PlasmaParticleContainer.cpp
EyaDammak Jan 24, 2025
3dd3910
update ppc
EyaDammak Jan 29, 2025
dfc0e06
Merge branch 'injection' of https://github.com/EyaDammak/hipace into …
EyaDammak Jan 29, 2025
390b341
update ppc
EyaDammak Jan 29, 2025
1dfd87c
Update PlasmaParticleContainer.cpp
EyaDammak Jan 29, 2025
d75777f
update reduce function
EyaDammak Jan 29, 2025
0eba01f
Merge branch 'injection' of https://github.com/EyaDammak/hipace into …
EyaDammak Jan 29, 2025
694891c
update ppc
EyaDammak Jan 29, 2025
804645d
update
EyaDammak Jan 29, 2025
4cd31f2
update ppc
EyaDammak Jan 29, 2025
40e554c
update ppc
EyaDammak Jan 30, 2025
38ccfde
update ppc
EyaDammak Jan 30, 2025
a1e14e0
ppc
EyaDammak Jan 30, 2025
007d434
ppc, trying something
EyaDammak Jan 30, 2025
2e869da
update MultiPlasma
EyaDammak Jan 30, 2025
093677b
Update PlasmaParticleContainer.cpp
EyaDammak Jan 31, 2025
caae128
adding the beam.can_laser_injection
EyaDammak Jan 31, 2025
365ff2b
make public the m_product_name
EyaDammak Jan 31, 2025
96d9879
forgot to save
EyaDammak Jan 31, 2025
eea15e7
updates
EyaDammak Jan 31, 2025
042f8fb
adding islice variable
EyaDammak Jan 31, 2025
75421f0
ppc
EyaDammak Jan 31, 2025
068460e
m_can_laser_injection in plasmaparticlecontainer
EyaDammak Jan 31, 2025
52b4946
moving all the m_product and so on in the plasma container
EyaDammak Jan 31, 2025
748f345
modifications
EyaDammak Jan 31, 2025
b0083e8
update MultiBeam.cpp
EyaDammak Jan 31, 2025
60e5301
hello
EyaDammak Jan 31, 2025
2793b7c
style
EyaDammak Feb 2, 2025
67a172a
Update PlasmaParticleContainer.H
EyaDammak Feb 12, 2025
28eaad7
Update PlasmaParticleContainer.cpp
EyaDammak Feb 12, 2025
e2dbff3
Update MultiPlasma.cpp
EyaDammak Feb 14, 2025
eb5a235
Update parameters.rst
EyaDammak Feb 14, 2025
093a17b
Update BeamParticleContainer.cpp
EyaDammak Feb 14, 2025
d44c240
Update PlasmaParticleContainer.cpp
EyaDammak Feb 14, 2025
a07c5f9
Update MultiPlasma.cpp
EyaDammak Feb 14, 2025
cfb2436
Update PlasmaParticleContainer.cpp
EyaDammak Feb 14, 2025
5d0eeab
Merge branch 'development' into injection
EyaDammak Feb 14, 2025
a5285e5
Merge branch 'Hi-PACE:development' into injection
EyaDammak Feb 18, 2025
39a1eed
Update PlasmaParticleContainerInit.cpp
EyaDammak Feb 18, 2025
d638b06
Update PlasmaParticleContainer.cpp
EyaDammak Feb 19, 2025
db37f78
Update PlasmaParticleContainer.cpp
EyaDammak Feb 19, 2025
06d8bba
Update PlasmaParticleContainer.cpp
EyaDammak Feb 21, 2025
fd9c525
Update MultiPlasma.cpp
EyaDammak Feb 21, 2025
332ce5e
update ppc.cpp
EyaDammak Feb 21, 2025
a5435e8
update ppc.cpp
EyaDammak Feb 21, 2025
4a27702
Update PlasmaParticleContainer.cpp
EyaDammak Feb 21, 2025
f00732d
Update PlasmaParticleContainer.cpp
EyaDammak Feb 21, 2025
d8d966f
Merge branch 'Hi-PACE:development' into injection
EyaDammak Feb 24, 2025
c08636e
update pcc.cpp
EyaDammak Feb 24, 2025
3a78493
update pcc.cpp
EyaDammak Feb 24, 2025
0c693cd
update pcc.cpp
EyaDammak Feb 24, 2025
b412517
ppc.cpp
EyaDammak Feb 24, 2025
f7f5b21
MultiPlasma update
EyaDammak Feb 24, 2025
06473f3
update MultiPlasma.cpp
EyaDammak Feb 24, 2025
f243dca
multiplasma
EyaDammak Feb 24, 2025
d06b8b5
MultiPlasma.cpp
EyaDammak Feb 24, 2025
d3c7e19
multiplasma
EyaDammak Feb 24, 2025
94fd2e4
multiplasma
EyaDammak Feb 25, 2025
7a7e8e4
Update MultiPlasma.H
EyaDammak Feb 25, 2025
4de3834
style
EyaDammak Feb 25, 2025
966a640
Update PlasmaParticleContainer.H
EyaDammak Feb 25, 2025
503e04f
Update parameters.rst
EyaDammak Feb 25, 2025
d8bef27
Update PlasmaParticleContainerInit.cpp
EyaDammak Feb 25, 2025
98a926f
Merge branch 'Hi-PACE:development' into injection
EyaDammak Feb 25, 2025
e7534cd
Update PlasmaParticleContainer.cpp
EyaDammak Feb 25, 2025
677dc6f
style
EyaDammak Feb 25, 2025
e2ed4fa
Update MultiPlasma.cpp
EyaDammak Feb 25, 2025
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
7 changes: 7 additions & 0 deletions docs/source/run/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,13 @@ which are valid only for certain beam types, are introduced further below under
The ideal index type is different for beam push and beam deposition so some experimentation
may be required to find the overall fastest setting for a specific simulation.

* ``<plasma name>.can_laser_injection`` (`bool`) optional (default `0`)
Whether the laser injection is unabled. Can also be set to 1 by specifying ``<plasma name>.injection_product``.

* ``<plasma name>.injection_product`` (`string`) optional (default "")
Name of the beam species that contains the new electrons that are produced
when this plasma gets ionized. Only needed if this plasma is ionizable and the laser injection is unabled.

Option: ``fixed_weight_pdf``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
4 changes: 4 additions & 0 deletions src/Hipace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "particles/pusher/GetAndSetPosition.H"
#include "mg_solver/HpMultiGrid.H"
#include "fields/fft_poisson_solver/fft/AnyFFT.H"
#include "particles/beam/MultiBeam.H"

#include <AMReX_ParmParse.H>
#include <AMReX_IntVect.H>
Expand Down Expand Up @@ -698,6 +699,9 @@ Hipace::SolveOneSlice (int islice, int step)
// plasma laser ionization
m_multi_plasma.DoLaserIonization(islice, m_multi_laser.GetLaserGeom(), m_multi_laser);

// injection
m_multi_plasma.DoLaserInjection(m_multi_beam, getDiagBeamNames(), m_multi_laser.GetLaserGeom(), m_multi_laser, islice);

// Push plasma particles
for (int lev=0; lev<current_N_level; ++lev) {
m_multi_plasma.AdvanceParticles(m_fields, m_3D_geom, false, lev, current_N_level);
Expand Down
2 changes: 1 addition & 1 deletion src/particles/beam/BeamParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private:
amrex::IntVect m_reorder_idx_type = {0, 0, 0};

// fixed_ppc:

private:
amrex::IntVect m_ppc {1, 1, 1}; /**< Number of particles per cell in each direction */
amrex::RealVect m_position_mean {0., 0., 0.}; /**< mean position of the beam */
amrex::Real m_min_density {0.}; /**< minimum density at which beam particles are generated */
Expand Down
12 changes: 12 additions & 0 deletions src/particles/plasma/MultiPlasma.H
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "PlasmaParticleContainer.H"
#include "fields/Fields.H"
#include "particles/collisions/CoulombCollision.H"
#include "particles/beam/MultiBeam.H"

class MultiPlasma
{
Expand Down Expand Up @@ -109,6 +110,17 @@ public:
void DoLaserIonization (const int islice, const amrex::Geometry& laser_geom,
const MultiLaser& laser);

/** Do the transfer of ionized plasma particles to beam particles
*
* \param[in] beams MultiBeam object containing all beams
* \param[in] beamnames Vector of strings representing the names of the beams
* \param[in] laser_geom Geometry of the laser used for ionization
* \param[in] laser MultiLaser object containing the laser details
* \param[in] islice Slice index corresponding to the current simulation slice
*/
void DoLaserInjection (MultiBeam& beams, const amrex::Vector< std::string > beamnames, const amrex::Geometry& laser_geom,
const MultiLaser& laser, const int islice);

/** \brief whether any plasma species uses a neutralizing background, e.g. no ion motion */
bool AnySpeciesNeutralizeBackground () const;

Expand Down
23 changes: 23 additions & 0 deletions src/particles/plasma/MultiPlasma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* License: BSD-3-Clause-LBNL
*/
#include "MultiPlasma.H"
#include "particles/beam/MultiBeam.H"
#include "particles/deposition/PlasmaDepositCurrent.H"
#include "particles/deposition/ExplicitDeposition.H"
#include "particles/pusher/PlasmaParticleAdvance.H"
Expand Down Expand Up @@ -57,7 +58,19 @@ MultiPlasma::InitData (amrex::Vector<amrex::BoxArray> slice_ba,
plasma.InitIonizationModule(gm[0],
Hipace::m_background_density_SI); // geometry only for dz
}

MultiBeam multi_beam;
if(plasma.m_can_laser_injection) {
for (int i=0; i<m_names.size(); ++i) {
if(m_names[i] == plasma.m_product_beam_name) {
plasma.m_product_beam_pc = &multi_beam.m_all_beams[i];
}
}
//AMREX_ALWAYS_ASSERT_WITH_MESSAGE(plasma.m_product_beam_pc != nullptr,
// "Must specify a valid product beam for laser injection using ionization_product");
}
}

}

amrex::Real
Expand Down Expand Up @@ -138,6 +151,16 @@ MultiPlasma::DoLaserIonization (
}
}

void
MultiPlasma::DoLaserInjection (
MultiBeam& beams, const amrex::Vector< std::string > beamnames, const amrex::Geometry& laser_geom,
const MultiLaser& laser, const int islice)
{
for (auto& plasma : m_all_plasmas) {
plasma.PlasmaToBeam(beams, beamnames, laser_geom,laser, islice);
}
}

bool
MultiPlasma::AnySpeciesNeutralizeBackground () const
{
Expand Down
19 changes: 18 additions & 1 deletion src/particles/plasma/PlasmaParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <AMReX_AmrParticles.H>
#include <AMReX_Particles.H>
#include <AMReX_AmrCore.H>
#include "particles/beam/MultiBeam.H"
#include "particles/beam/BeamParticleContainer.H"
#include <map>

/** \brief Map names and indices for plasma particles attributes (SoA data) */
Expand Down Expand Up @@ -113,6 +115,18 @@ public:
const MultiLaser& laser,
const amrex::Real background_density_SI);

/** Do the transfer of particles from the plasma container to the beam container
*
* \param[in] beams MultiBeam object containing all beams
* \param[in] beamnames Vector of strings representing the names of the beams
* \param[in] laser_geom Geometry of the laser used for ionization
* \param[in] laser MultiLaser object containing the laser details
* \param[in] islice Slice index corresponding to the current simulation slice
*/
void PlasmaToBeam (MultiBeam& beams, const amrex::Vector< std::string > beamnames, const amrex::Geometry& laser_geom,
const MultiLaser& laser, const int islice
);

/** Reorder particles to speed-up current deposition
* \param[in] islice zeta slice index
*/
Expand Down Expand Up @@ -215,8 +229,11 @@ public:
amrex::Gpu::DeviceVector<amrex::Real> m_laser_adk_prefactor;
/** to calculate laser ionization momentum width for linear polarization */
amrex::Gpu::DeviceVector<amrex::Real> m_laser_dp_prefactor;
/** to calculate laser ionization momentum width at the second order for linear polarization */
amrex::Gpu::DeviceVector<amrex::Real> m_laser_dp_second_prefactor;
// laser injection:
bool m_can_laser_injection = false; /**< whether laser injection is unabled */
std::string m_product_beam_name = ""; /**< name of Injection product beam */
BeamParticleContainer* m_product_beam_pc = nullptr; /**< Injection product beam */

// plasma sorting/reordering:

Expand Down
82 changes: 81 additions & 1 deletion src/particles/plasma/PlasmaParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "particles/pusher/BeamParticleAdvance.H"
#include "particles/particles_utils/FieldGather.H"
#include "particles/pusher/GetAndSetPosition.H"
#include "particles/beam/BeamParticleContainer.H"
#include "particles/beam/MultiBeam.H"

#include <cmath>
#include <fstream>
#include <sstream>
Expand Down Expand Up @@ -78,6 +81,8 @@ PlasmaParticleContainer::ReadParameters ()
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_init_ion_lev >= 0,
"The initial ion level must be specified");
}
m_can_laser_injection = pp.contains("injection_product");
queryWithParser(pp, "can_laser_injection", m_can_laser_injection);
queryWithParserAlt(pp, "neutralize_background", m_neutralize_background, pp_alt);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!m_can_ionize || !m_neutralize_background,
"Cannot use neutralize_background when ionization is turned on");
Expand All @@ -91,6 +96,7 @@ PlasmaParticleContainer::ReadParameters ()
m_charge *= m_init_ion_lev;
}
queryWithParser(pp, "ionization_product", m_product_name);
queryWithParser(pp, "injection_product", m_product_beam_name);

std::string density_func_str = "0.";
DeprecatedInput(m_name, "density", "density(x,y,z)");
Expand Down Expand Up @@ -426,7 +432,6 @@ IonizationModule (const int lev,
const long pid = amrex::Gpu::Atomic::Add( p_ip_elec, 1u ); // ensures thread-safe access when incrementing `p_ip_elec`
const long pidx = pid + old_size;

// Copy ion data to new electron
// Set the ionized electron ID to 2 (valid/invalid) for the ionized electrons
amrex::ParticleIDWrapper{idcpu_elec[pidx]} = 2;
amrex::ParticleCPUWrapper{idcpu_elec[pidx]} = lev; // current level
Expand Down Expand Up @@ -730,6 +735,81 @@ LaserIonization (const int islice,
}
}

void
PlasmaParticleContainer::
PlasmaToBeam (MultiBeam& beams, const amrex::Vector< std::string > beamnames, const amrex::Geometry& laser_geom,
const MultiLaser& laser, const int islice)
{
if (!m_can_laser_ionize || !laser.UseLaser(islice) || !m_can_laser_injection) return;
HIPACE_PROFILE("PlasmaParticleContainer::PlasmaToBeam()");

amrex::Gpu::DeviceScalar<uint32_t> num_new_beam_part(0);
uint32_t* AMREX_RESTRICT p_num_new_beam_part = num_new_beam_part.dataPtr();

// Loop over plasma particle boxes
for (PlasmaParticleIterator pti(*this); pti.isValid(); ++pti)
{
// Loading the data from the plasma containers
const auto ptd_plasma = pti.GetParticleTile().getParticleTileData();

amrex::Long const num_particles = pti.numParticles();

amrex::ReduceOps<amrex::ReduceOpSum> reduce_op;
amrex::ReduceData<uint64_t> reduce_data(reduce_op);
using ReduceTuple = typename decltype(reduce_data)::Type;

// This kernel calculates the number of ionized electrons in the plasma container and make them invalid
reduce_op.eval(
num_particles, reduce_data,
[=] AMREX_GPU_DEVICE (int ip) -> ReduceTuple
{
if (ptd_plasma.id(ip) != 2) // whether the plasma particle is from ionization
{
ptd_plasma.id(ip).make_invalid(); // make the particle invalid in the plasma container
return {1};
} else {
return {0};
}
});

auto [sum_new_beam_part] = reduce_data.value();

amrex::Gpu::Atomic::Add(p_num_new_beam_part, static_cast<uint32_t>(sum_new_beam_part));

auto& beam_elec = m_product_beam_pc;

// Resize the beam container
auto& beam_soa = beam_elec->getBeamSlice(WhichBeamSlice::This).GetStructOfArrays();
auto old_size = beam_soa.size();
auto new_size = old_size + num_new_beam_part.dataValue();
beam_soa.resize(new_size);

auto ptd_beam = beam_elec->getBeamSlice(WhichBeamSlice::This).getParticleTileData();

// This kernel does the transfer of the ionized electrons from the plasma container
// to the beam container
amrex::Gpu::DeviceScalar<uint32_t> ip_elec(0);
uint32_t * AMREX_RESTRICT p_ip_elec = ip_elec.dataPtr();
amrex::ParallelFor(num_particles,
[=] AMREX_GPU_DEVICE (int ip) {
if (ptd_plasma.id(ip) != 2){
const long pid_beam = amrex::Gpu::Atomic::Add(p_ip_elec, 1u);
const long pidx_beam = pid_beam + old_size;
ptd_beam.rdata(BeamIdx::x)[pidx_beam] = ptd_plasma.pos(0, ip);
ptd_beam.rdata(BeamIdx::y)[pidx_beam] = ptd_plasma.pos(1, ip);
ptd_beam.rdata(BeamIdx::z)[pidx_beam] = ptd_plasma.pos(2, ip);
ptd_beam.rdata(BeamIdx::ux)[pidx_beam] = ptd_plasma.rdata(PlasmaIdx::ux)[ip];
ptd_beam.rdata(BeamIdx::uy)[pidx_beam] = ptd_plasma.rdata(PlasmaIdx::uy)[ip];
amrex::Real ux = ptd_plasma.rdata(PlasmaIdx::ux)[ip];
amrex::Real uy = ptd_plasma.rdata(PlasmaIdx::uy)[ip];
amrex::Real psi = ptd_plasma.rdata(PlasmaIdx::psi)[ip];
ptd_beam.rdata(BeamIdx::uz)[pidx_beam] = (1+ux*ux+uy*uy-psi*psi)/(2.*psi);
ptd_beam.rdata(BeamIdx::w)[pidx_beam] = ptd_plasma.rdata(PlasmaIdx::w)[ip];
}
});
}
}

void
PlasmaParticleContainer::InSituComputeDiags (int islice)
{
Expand Down
Loading