Skip to content

Commit

Permalink
Python: Deposit Charge (#612)
Browse files Browse the repository at this point in the history
Add a Python function `ImpactX.deposit_charge()` that deposits the
current particle beam into x,y,z `rho`, independent of space charge
logic and not applying any kicks to the beam.

Useful for debugging and experimenting with new algorithms.
  • Loading branch information
ax3l authored May 14, 2024
1 parent 22edb97 commit 8734507
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/python/ImpactX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "pyImpactX.H"

#include <ImpactX.H>
#include <particles/transformation/CoordinateTransformation.H>

#include <AMReX.H>
#include <AMReX_ParmParse.H>
Expand Down Expand Up @@ -360,6 +361,32 @@ void init_ImpactX (py::module& m)
"``0`` for silent, higher is more verbose. Default is ``1``."
)

.def("deposit_charge",
[](ImpactX & ix) {
// transform from x',y',t to x,y,z
transformation::CoordinateTransformation(
*(ix.amr_data)->m_particle_container,
CoordSystem::t);

// Note: The following operation assume that
// the particles are in x, y, z coordinates.

// Resize the mesh, based on `m_particle_container` extent
ix.ResizeMesh();

// Redistribute particles in the new mesh in x, y, z
ix.amr_data->m_particle_container->Redistribute();

// charge deposition
ix.amr_data->m_particle_container->DepositCharge(ix.amr_data->m_rho, ix.amr_data->refRatio());

// transform from x,y,z to x',y',t
transformation::CoordinateTransformation(*(ix.amr_data)->m_particle_container,
CoordSystem::s);
},
"Deposit charge in x,y,z."
)

.def("finalize", &ImpactX::finalize,
"Deallocate all contexts and data."
)
Expand Down
3 changes: 2 additions & 1 deletion tests/python/test_charge_deposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_charge_deposition(save_png=True):

sim.n_cell = [16, 24, 32]
sim.load_inputs_file(basepath + "/examples/fodo/input_fodo.in")
sim.space_charge = True
sim.slice_step_diagnostics = False

# Future:
Expand All @@ -41,6 +40,8 @@ def test_charge_deposition(save_png=True):

sim.evolve()

sim.deposit_charge()

rho = sim.rho(lev=0)
rs = rho.sum_unique(comp=0, local=False)

Expand Down

0 comments on commit 8734507

Please sign in to comment.