Skip to content

Commit

Permalink
DataFrame: Add Test
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Nov 20, 2023
1 parent e4cd215 commit c499992
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/python/test_dataframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python3
#
# Copyright 2022-2023 The ImpactX Community
#
# Authors: Axel Huebl
# License: BSD-3-Clause-LBNL
#
# -*- coding: utf-8 -*-

from impactx import ImpactX, RefPart, distribution, elements


def test_df_pandas():
"""
This tests using ImpactX and Pandas Dataframes
"""
sim = ImpactX()

sim.particle_shape = 2
sim.slice_step_diagnostics = True
sim.init_grids()

# init particle beam
kin_energy_MeV = 2.0e3
bunch_charge_C = 1.0e-9
npart = 10000

# reference particle
pc = sim.particle_container()
ref = pc.ref_particle()
ref.set_charge_qe(-1.0).set_mass_MeV(0.510998950).set_kin_energy_MeV(kin_energy_MeV)

# particle bunch
distr = distribution.Waterbag(
sigmaX=3.9984884770e-5,
sigmaY=3.9984884770e-5,
sigmaT=1.0e-3,
sigmaPx=2.6623538760e-5,
sigmaPy=2.6623538760e-5,
sigmaPt=2.0e-3,
muxpx=-0.846574929020762,
muypy=0.846574929020762,
mutpt=0.0,
)
sim.add_particles(bunch_charge_C, distr, npart)

assert pc.TotalNumberOfParticles() == npart

# init accelerator lattice
fodo = [
elements.Drift(0.25),
elements.Quad(1.0, 1.0),
elements.Drift(0.5),
elements.Quad(1.0, -1.0),
elements.Drift(0.25),
]
sim.lattice.extend(fodo)

# simulate
sim.evolve()

# compare number of global particles
assert npart == len(pc.to_df(local=False))


if __name__ == "__main__":
test_df_pandas()

0 comments on commit c499992

Please sign in to comment.