xfields 0.22.2__tar.gz → 0.23.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xfields-0.23.0/.gitignore +13 -0
- {xfields-0.22.2 → xfields-0.23.0}/PKG-INFO +1 -1
- xfields-0.23.0/contributors_and_credits.txt +16 -0
- xfields-0.23.0/examples/000_sphere/.gitignore +1 -0
- xfields-0.23.0/examples/000_sphere/000_sphere_xfields3D.py +167 -0
- xfields-0.23.0/examples/000_sphere/001_sphere_xfields2p5D.py +170 -0
- xfields-0.23.0/examples/001_spacecharge/000_spacecharge_example.py +152 -0
- xfields-0.23.0/examples/001_spacecharge/001_shared_fieldmap.py +152 -0
- xfields-0.23.0/examples/001_spacecharge/002_spacecharge_with_losses.py +33 -0
- xfields-0.23.0/examples/002_beambeam/000_beambeam.py +191 -0
- xfields-0.23.0/examples/002_beambeam/001_beambeam3d.py +165 -0
- xfields-0.23.0/examples/002_beambeam/002_beambeam3d_old_interface.py +136 -0
- xfields-0.23.0/examples/002_beambeam/003_beambeam3d_strongstrong_track.py +188 -0
- xfields-0.23.0/examples/002_beambeam/004_beambeam2d_strongstrong_pyheadtail.py +215 -0
- xfields-0.23.0/examples/002_beambeam/005_beambeam6d_strongstrong_pipeline.py +201 -0
- xfields-0.23.0/examples/002_beambeam/006_beambeam6d_strongstrong_pipeline_MPI2Procs.py +221 -0
- xfields-0.23.0/examples/002_beambeam/007_beambeam3d_beamstrahlung.py +381 -0
- xfields-0.23.0/examples/002_beambeam/008_beambeam6d_collective_beamstrahlung.py +392 -0
- xfields-0.23.0/examples/002_beambeam/009_constant_charge_slicing.py +46 -0
- xfields-0.23.0/examples/002_beambeam/010_beambeam2d_strongstrong_pipeline.py +167 -0
- xfields-0.23.0/examples/002_beambeam/010_beambeam2d_weakstrong.py +115 -0
- xfields-0.23.0/examples/002_beambeam/011a_inspect_kick_vs_zeta_hirata.py +98 -0
- xfields-0.23.0/examples/002_beambeam/011b_lhc_one_bb.py +65 -0
- xfields-0.23.0/examples/002_beambeam/011c_dev_pic.py +313 -0
- xfields-0.23.0/examples/002_beambeam/011d_pic_pipeline.py +152 -0
- xfields-0.23.0/examples/002_beambeam/011e_multiple_kicks_multiple_turns.py +232 -0
- xfields-0.23.0/examples/002_beambeam/011g_pic_pipeline_gpu.py +164 -0
- xfields-0.23.0/examples/003_electronlens/electronlens_interpolated_ideal.py +88 -0
- xfields-0.23.0/examples/004_fadeeva/000_check_fadeeva.py +139 -0
- xfields-0.23.0/examples/005_ibs/000_growth_rates_no_vdisp.py +119 -0
- xfields-0.23.0/examples/005_ibs/001_growth_rates_with_vdisp.py +76 -0
- xfields-0.23.0/examples/005_ibs/002_growth_rates_conventions.py +79 -0
- xfields-0.23.0/examples/005_ibs/003_tracking_with_kicks.py +66 -0
- xfields-0.23.0/examples/005_ibs/004_tracking_with_kicks_tbt_emittances.py +94 -0
- xfields-0.23.0/examples/longitudinal_kick_in_spacecharge/000_gaussian_3d.py +140 -0
- xfields-0.23.0/examples/longitudinal_kick_in_spacecharge/001_dev_spacecharge.py +96 -0
- xfields-0.23.0/examples/longitudinal_kick_in_spacecharge/002_sps_ion.py +124 -0
- xfields-0.23.0/examples/longitudinal_kick_in_spacecharge/003_sps_ion_with_builtin_z_kick.py +118 -0
- xfields-0.23.0/examples/longitudinal_kick_in_spacecharge/004_qgaussian_derivative.py +63 -0
- xfields-0.23.0/examples/longitudinal_kick_in_spacecharge/sps_ion_2021.json +1 -0
- xfields-0.23.0/examples/slicer/000_dev.py +876 -0
- xfields-0.23.0/examples/slicer/001_slicer_operations.py +29 -0
- xfields-0.23.0/examples/slicer/002a_example_slicer.py +142 -0
- xfields-0.23.0/examples/slicer/002b_example_slicer_gpu.py +145 -0
- xfields-0.23.0/examples/slicer/003_multilog.py +22 -0
- xfields-0.23.0/examples/slicer/004_log_moments.py +151 -0
- xfields-0.23.0/examples/slicer/005a_moment_profile.py +75 -0
- xfields-0.23.0/examples/slicer/005b_moment_profile_gpu.py +89 -0
- xfields-0.23.0/examples/slicer/005c_moment_profile_from_wake.py +53 -0
- xfields-0.23.0/examples/slicer/005d_moment_profile_from_wake_gpu.py +59 -0
- xfields-0.23.0/mktest +1 -0
- xfields-0.23.0/release.sh +20 -0
- xfields-0.23.0/requirements.txt +2 -0
- xfields-0.23.0/test_data/HLLHC_wake.dat +2801 -0
- xfields-0.23.0/test_data/pyecloud_pinch/Pinch_creation/.gitignore +4 -0
- xfields-0.23.0/test_data/pyecloud_pinch/Pinch_creation/000_buildup.py +4 -0
- xfields-0.23.0/test_data/pyecloud_pinch/Pinch_creation/001_pinch.py +131 -0
- xfields-0.23.0/test_data/pyecloud_pinch/Pinch_creation/beam.beam +33 -0
- xfields-0.23.0/test_data/pyecloud_pinch/Pinch_creation/filemanager.py +54 -0
- xfields-0.23.0/test_data/pyecloud_pinch/Pinch_creation/machine_parameters.input +51 -0
- xfields-0.23.0/test_data/pyecloud_pinch/Pinch_creation/secondary_emission_parameters.input +16 -0
- xfields-0.23.0/test_data/pyecloud_pinch/Pinch_creation/simulation_parameters.input +81 -0
- xfields-0.23.0/test_data/pyecloud_pinch/README.md +35 -0
- xfields-0.23.0/test_data/pyecloud_pinch/eclouds.json +5838 -0
- xfields-0.23.0/test_data/pyecloud_pinch/refined_Pinch_MTI1.0_MLI1.0_DTO2.0_DLO1.0.h5 +0 -0
- xfields-0.23.0/test_data/test_beamstrahlung/README.txt +3 -0
- xfields-0.23.0/test_data/test_beamstrahlung/test_beamstrahlung_guineapig_ttbar2_beamstrahlung_photon_hist.txt +9 -0
- xfields-0.23.0/tests/ibs_conftest.py +168 -0
- xfields-0.23.0/tests/pytest_onebyone.sh +7 -0
- xfields-0.23.0/tests/test_alpha_pi_setter.py +158 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_beamstrahlung.py +3 -0
- xfields-0.23.0/tests/test_beamstrahlung_pic.py +229 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_ibs_growth_rates.py +133 -32
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_iptocp_strongstrong.py +4 -1
- xfields-0.23.0/update_cprght_statement.py +48 -0
- xfields-0.23.0/xfields/_version.py +1 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/beambeam3d.py +112 -11
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/beambeam3dpic.py +62 -2
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/beambeam_src/beambeam3d.h +1 -2
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/beambeam_src/beambeampic_methods.h +38 -2
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/temp_slicer.py +5 -2
- {xfields-0.22.2 → xfields-0.23.0}/xfields/headers/beamstrahlung_spectrum.h +1 -4
- xfields-0.23.0/xfields/headers/beamstrahlung_spectrum_pic.h +168 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/headers/bhabha_spectrum.h +0 -2
- {xfields-0.22.2 → xfields-0.23.0}/xfields/ibs/__init__.py +3 -2
- {xfields-0.22.2 → xfields-0.23.0}/xfields/ibs/_analytical.py +277 -96
- {xfields-0.22.2 → xfields-0.23.0}/xfields/ibs/_api.py +28 -34
- {xfields-0.22.2 → xfields-0.23.0}/xfields/ibs/_formulary.py +8 -4
- {xfields-0.22.2 → xfields-0.23.0}/xfields/ibs/_kicks.py +35 -22
- {xfields-0.22.2 → xfields-0.23.0}/xfields.egg-info/PKG-INFO +1 -1
- {xfields-0.22.2 → xfields-0.23.0}/xfields.egg-info/SOURCES.txt +72 -0
- xfields-0.22.2/xfields/_version.py +0 -1
- {xfields-0.22.2 → xfields-0.23.0}/LICENSE +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/MANIFEST.in +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/README.md +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/pyproject.toml +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/setup.cfg +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/setup.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_beambeam2d.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_beambeam3d_part1.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_beambeam3d_part2.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_beambeam_pic.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_beambeamstrongstrong2d.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_beambeamstrongstrong2d_pi.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_beambeamstrongstrong3d.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_beambeamstrongstrong3d_pi.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_bhabha.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_cerrf.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_compressed_profile_interp_result.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_constant_charge_slicing.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_electroncloud.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_electronlens_interpolated.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_element_with_slicer_filling_scheme.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_ibs_kicks.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_lumi.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_mean_std.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_profiles.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_slicer.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_spacecharge.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/tests/test_temp_slicer.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/__init__.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/__init__.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/beambeam2d.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/beambeam_src/beambeam.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/beambeam_src/beambeam2d.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/beambeam_src/beambeam3d_methods_for_strongstrong.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/beambeam_src/beambeam3d_ref_frame_changes.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/beambeam_src/beambeam3d_transport_sigmas.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/electroncloud.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/electroncloud_src/electroncloud.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/electronlens_interpolated.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/electronlens_src/electronlens_interpolated.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/element_with_slicer.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/spacecharge.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/spacecharge_src/spacecharge3d.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/spacecharge_src/spacechargebigaussian.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/waketracker/__init__.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/waketracker/convolution.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/beam_elements/waketracker/waketracker.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/config_tools/__init__.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/config_tools/beambeam_config_tools/__init__.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/config_tools/beambeam_config_tools/_madpoint.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/config_tools/beambeam_config_tools/config_tools.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/config_tools/beambeam_config_tools/orbit_dependent_configuration_tools.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/config_tools/electroncloud_config_tools.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/config_tools/spacecharge_config_tools.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/__init__.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/bigaussian.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/bigaussian_src/bigaussian.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/bigaussian_src/bigaussian_fieldmap.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/bigaussian_src/compute_gx_gy.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/bigaussian_src/faddeeva.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/bigaussian_src/faddeeva_cernlib.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/bigaussian_src/faddeeva_mit.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/interpolated.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/interpolated_src/central_diff.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/interpolated_src/charge_deposition.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/interpolated_src/cubic_interpolators.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/interpolated_src/linear_interpolators.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/interpolated_src/tricubic_coefficients.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/fieldmaps/tricubicinterpolated.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/general.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/headers/compressed_profile.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/headers/compute_slice_moments.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/headers/constants.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/headers/particle_states.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/headers/power_n.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/headers/sincos.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/longitudinal_profiles/__init__.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/longitudinal_profiles/coasting.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/longitudinal_profiles/qgaussian.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/longitudinal_profiles/qgaussian_src/qgaussian.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/slicers/__init__.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/slicers/compressed_profile.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/slicers/slicers_src/uniform_bin_slicer.h +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/slicers/uniform.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/solvers/__init__.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/solvers/base.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/solvers/fftsolvers.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/test_support/__init__.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields/test_support/temp_makepart.py +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields.egg-info/dependency_links.txt +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields.egg-info/requires.txt +0 -0
- {xfields-0.22.2 → xfields-0.23.0}/xfields.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
The following people contributed to the development of this package:
|
|
2
|
+
|
|
3
|
+
CERN contributors:
|
|
4
|
+
- H. Bartosik
|
|
5
|
+
- X. Buffat
|
|
6
|
+
- R. De Maria
|
|
7
|
+
- L. Giacomel
|
|
8
|
+
- G. Iadarola
|
|
9
|
+
- P. Kicsiny
|
|
10
|
+
- S. Lopaciuk
|
|
11
|
+
- K. Paraschou
|
|
12
|
+
- M. Schwinzerl
|
|
13
|
+
- F. Soubelet
|
|
14
|
+
- E. Waagaard
|
|
15
|
+
|
|
16
|
+
The Particle In Cell implementation is largely based on the PyPIC package (https://github.com/pycomplete/pypic)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
picsphere.pkl
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# copyright ################################# #
|
|
2
|
+
# This file is part of the Xfields Package. #
|
|
3
|
+
# Copyright (c) CERN, 2021. #
|
|
4
|
+
# ########################################### #
|
|
5
|
+
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
from numpy.random import rand
|
|
10
|
+
from scipy.constants import epsilon_0
|
|
11
|
+
from numpy import pi
|
|
12
|
+
|
|
13
|
+
from xobjects import ContextCpu, ContextCupy, ContextPyopencl
|
|
14
|
+
from xfields import TriLinearInterpolatedFieldMap
|
|
15
|
+
|
|
16
|
+
context = ContextCpu()
|
|
17
|
+
context = ContextCupy(default_block_size=256)
|
|
18
|
+
#context = ContextPyopencl()
|
|
19
|
+
|
|
20
|
+
print(repr(context))
|
|
21
|
+
|
|
22
|
+
import matplotlib.pyplot as plt
|
|
23
|
+
plt.close('all')
|
|
24
|
+
|
|
25
|
+
center_xyz = np.array([0.1, 0.2, -0.3])
|
|
26
|
+
radius = .5
|
|
27
|
+
n_part_cube = 10000000
|
|
28
|
+
|
|
29
|
+
x_cube = radius*(2. * rand(n_part_cube) - 1.) + center_xyz[0]
|
|
30
|
+
y_cube = radius*(2. * rand(n_part_cube) - 1.) + center_xyz[1]
|
|
31
|
+
z_cube = radius*(2. * rand(n_part_cube) - 1.) + center_xyz[2]
|
|
32
|
+
|
|
33
|
+
mask_sphere = ((x_cube - center_xyz[0])**2
|
|
34
|
+
+ (y_cube - center_xyz[1])**2
|
|
35
|
+
+ (z_cube - center_xyz[2])**2) < radius**2
|
|
36
|
+
x = x_cube[mask_sphere]
|
|
37
|
+
y = y_cube[mask_sphere]
|
|
38
|
+
z = z_cube[mask_sphere]
|
|
39
|
+
pweights = 1. + 0*x
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# PIC
|
|
43
|
+
x_lim = (-1.1, 1.)
|
|
44
|
+
y_lim = (-1.2, 1.)
|
|
45
|
+
z_lim = (-1.3, 1.)
|
|
46
|
+
|
|
47
|
+
nx = 128
|
|
48
|
+
ny = 128
|
|
49
|
+
nz = 200
|
|
50
|
+
|
|
51
|
+
theta_test = 70. * np.pi/360
|
|
52
|
+
phi_test = 300 * np.pi/360.
|
|
53
|
+
r_test = 2.5*radius*np.linspace(-1, 1., 1000)
|
|
54
|
+
|
|
55
|
+
x0_test = r_test * np.sin(theta_test) * np.cos(phi_test)
|
|
56
|
+
y0_test = r_test * np.sin(theta_test) * np.sin(phi_test)
|
|
57
|
+
z0_test = r_test * np.cos(theta_test)
|
|
58
|
+
|
|
59
|
+
x_test = center_xyz[0] + x0_test
|
|
60
|
+
y_test = center_xyz[1] + y0_test
|
|
61
|
+
z_test = center_xyz[2] + z0_test
|
|
62
|
+
|
|
63
|
+
# Moving particles and test coordinates to GPU (if needed)
|
|
64
|
+
np2platf = context.nparray_to_context_array
|
|
65
|
+
x_dev = np2platf(x)
|
|
66
|
+
y_dev = np2platf(y)
|
|
67
|
+
z_dev = np2platf(z)
|
|
68
|
+
pweights_dev = np2platf(pweights)
|
|
69
|
+
x_test_dev = np2platf(x_test)
|
|
70
|
+
y_test_dev = np2platf(y_test)
|
|
71
|
+
z_test_dev = np2platf(z_test)
|
|
72
|
+
|
|
73
|
+
###############
|
|
74
|
+
# Actual test #
|
|
75
|
+
###############
|
|
76
|
+
|
|
77
|
+
# Build fieldmap object
|
|
78
|
+
fmap = TriLinearInterpolatedFieldMap(
|
|
79
|
+
_context=context,
|
|
80
|
+
x_range=x_lim, nx=nx,
|
|
81
|
+
y_range=y_lim, ny=ny,
|
|
82
|
+
z_range=z_lim, nz=nz,
|
|
83
|
+
solver='FFTSolver3D')
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# Compute potential
|
|
87
|
+
n_rep = 4
|
|
88
|
+
for _ in range(n_rep):
|
|
89
|
+
t1 = time.time()
|
|
90
|
+
fmap.update_from_particles(x_p=x_dev, y_p=y_dev, z_p=z_dev,
|
|
91
|
+
ncharges_p=pweights_dev, q0_coulomb=1.)
|
|
92
|
+
|
|
93
|
+
# Check on the x axis
|
|
94
|
+
(rho_test_dev, phi_test_dev, dx_test_dev, dy_test_dev,
|
|
95
|
+
dz_test_dev) = fmap.get_values_at_points(
|
|
96
|
+
x=x_test_dev, y=y_test_dev, z=z_test_dev)
|
|
97
|
+
context.synchronize()
|
|
98
|
+
t2 = time.time()
|
|
99
|
+
print(f'Time: {t2-t1:.2e}')
|
|
100
|
+
|
|
101
|
+
# Copy back for plotting
|
|
102
|
+
platf2np = context.nparray_from_context_array
|
|
103
|
+
rho_test = platf2np(rho_test_dev)
|
|
104
|
+
phi_test = platf2np(phi_test_dev)
|
|
105
|
+
dx_test = platf2np(dx_test_dev)
|
|
106
|
+
dy_test = platf2np(dy_test_dev)
|
|
107
|
+
dz_test = platf2np(dz_test_dev)
|
|
108
|
+
|
|
109
|
+
# pickle for other tests
|
|
110
|
+
import pickle
|
|
111
|
+
# with open('picsphere.pkl', 'wb') as fid:
|
|
112
|
+
# pickle.dump({
|
|
113
|
+
# 'fmap': fmap,
|
|
114
|
+
# 'x_test': x_test,
|
|
115
|
+
# 'y_test': y_test,
|
|
116
|
+
# 'z_test': z_test,
|
|
117
|
+
# }, fid)
|
|
118
|
+
|
|
119
|
+
####################
|
|
120
|
+
# Plots and checks #
|
|
121
|
+
####################
|
|
122
|
+
|
|
123
|
+
ex_test = -dx_test
|
|
124
|
+
ey_test = -dy_test
|
|
125
|
+
ez_test = -dz_test
|
|
126
|
+
|
|
127
|
+
plt.figure(100)
|
|
128
|
+
plt.plot(r_test, rho_test)
|
|
129
|
+
plt.axhline(y=len(x)/(4/3*np.pi*radius**3))
|
|
130
|
+
|
|
131
|
+
plt.figure(101)
|
|
132
|
+
plt.plot(r_test, phi_test)
|
|
133
|
+
|
|
134
|
+
e_ref = len(x)/(4*pi*epsilon_0) * (
|
|
135
|
+
r_test/radius**3*(np.abs(r_test)<radius)
|
|
136
|
+
+ np.sign(r_test)/r_test**2*(np.abs(r_test)>=radius))
|
|
137
|
+
plt.figure(102)
|
|
138
|
+
plt.plot(r_test, ex_test*x0_test/r_test
|
|
139
|
+
+ ey_test*y0_test/r_test + ez_test*z0_test/r_test)
|
|
140
|
+
plt.plot(r_test, e_ref)
|
|
141
|
+
plt.grid(True)
|
|
142
|
+
|
|
143
|
+
# Check integral
|
|
144
|
+
int_rho = np.sum(platf2np(fmap.rho))*fmap.dx*fmap.dy*fmap.dz
|
|
145
|
+
assert np.isclose(int_rho, len(x))
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
fig1 = plt.figure(1)
|
|
149
|
+
ax1 = fig1.add_subplot(111)
|
|
150
|
+
ax1.pcolormesh(fmap.x_grid, fmap.y_grid,
|
|
151
|
+
np.sum(platf2np(fmap.rho), axis=2).T, shading='gouraud')
|
|
152
|
+
ax1.set_aspect('equal')
|
|
153
|
+
ax1.add_patch(plt.Circle((center_xyz[0], center_xyz[1]), radius,
|
|
154
|
+
color='w', fill=False))
|
|
155
|
+
ax1.set_xlabel('x')
|
|
156
|
+
ax1.set_ylabel('y')
|
|
157
|
+
|
|
158
|
+
fig2 = plt.figure(2)
|
|
159
|
+
ax2 = fig2.add_subplot(111)
|
|
160
|
+
ax2.pcolormesh(fmap.y_grid, fmap.z_grid,
|
|
161
|
+
np.sum(platf2np(fmap.rho), axis=0).T, shading='gouraud')
|
|
162
|
+
ax2.set_aspect('equal')
|
|
163
|
+
ax2.add_patch(plt.Circle((center_xyz[1], center_xyz[2]), radius,
|
|
164
|
+
color='w', fill=False))
|
|
165
|
+
ax2.set_xlabel('y')
|
|
166
|
+
ax2.set_ylabel('z')
|
|
167
|
+
plt.show()
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# copyright ################################# #
|
|
2
|
+
# This file is part of the Xfields Package. #
|
|
3
|
+
# Copyright (c) CERN, 2021. #
|
|
4
|
+
# ########################################### #
|
|
5
|
+
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
from numpy.random import rand
|
|
10
|
+
from scipy.constants import epsilon_0
|
|
11
|
+
from numpy import pi
|
|
12
|
+
|
|
13
|
+
from xobjects import ContextCpu, ContextCupy, ContextPyopencl
|
|
14
|
+
from xfields import TriLinearInterpolatedFieldMap
|
|
15
|
+
|
|
16
|
+
context = ContextCpu()
|
|
17
|
+
#context = ContextCupy(default_block_size=256)
|
|
18
|
+
#context = ContextPyopencl()
|
|
19
|
+
|
|
20
|
+
print(repr(context))
|
|
21
|
+
|
|
22
|
+
import matplotlib.pyplot as plt
|
|
23
|
+
plt.close('all')
|
|
24
|
+
|
|
25
|
+
center_xyz = np.array([0.1, 0.2, -0.3])
|
|
26
|
+
radius = .5
|
|
27
|
+
n_part_cube = 10000000
|
|
28
|
+
|
|
29
|
+
x_cube = radius*(2. * rand(n_part_cube) - 1.) + center_xyz[0]
|
|
30
|
+
y_cube = radius*(2. * rand(n_part_cube) - 1.) + center_xyz[1]
|
|
31
|
+
z_cube = radius*(2. * rand(n_part_cube) - 1.) + center_xyz[2]
|
|
32
|
+
|
|
33
|
+
mask_sphere = ((x_cube - center_xyz[0])**2
|
|
34
|
+
+ (y_cube - center_xyz[1])**2
|
|
35
|
+
+ (z_cube - center_xyz[2])**2) < radius**2
|
|
36
|
+
x = x_cube[mask_sphere]
|
|
37
|
+
y = y_cube[mask_sphere]
|
|
38
|
+
z = z_cube[mask_sphere]
|
|
39
|
+
pweights = 1. + 0*x
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# PIC
|
|
43
|
+
x_lim = (-1.1, 1.)
|
|
44
|
+
y_lim = (-1.2, 1.)
|
|
45
|
+
z_lim = (-1.3, 1.)
|
|
46
|
+
|
|
47
|
+
nx = 256
|
|
48
|
+
ny = 256
|
|
49
|
+
nz = 50
|
|
50
|
+
|
|
51
|
+
theta_test = 70. * np.pi/360
|
|
52
|
+
r_test = 2.5*radius*np.linspace(-1, 1., 1000)
|
|
53
|
+
z_test = 0.4
|
|
54
|
+
|
|
55
|
+
x0_test = r_test * np.cos(theta_test)
|
|
56
|
+
y0_test = r_test * np.sin(theta_test)
|
|
57
|
+
z0_test = z_test + 0*r_test
|
|
58
|
+
|
|
59
|
+
x_test = center_xyz[0] + x0_test
|
|
60
|
+
y_test = center_xyz[1] + y0_test
|
|
61
|
+
z_test = center_xyz[2] + z0_test
|
|
62
|
+
|
|
63
|
+
# Moving particles and test coordinates to GPU (if needed)
|
|
64
|
+
np2platf = context.nparray_to_context_array
|
|
65
|
+
x_dev = np2platf(x)
|
|
66
|
+
y_dev = np2platf(y)
|
|
67
|
+
z_dev = np2platf(z)
|
|
68
|
+
pweights_dev = np2platf(pweights)
|
|
69
|
+
x_test_dev = np2platf(x_test)
|
|
70
|
+
y_test_dev = np2platf(y_test)
|
|
71
|
+
z_test_dev = np2platf(z_test)
|
|
72
|
+
|
|
73
|
+
###############
|
|
74
|
+
# Actual test #
|
|
75
|
+
###############
|
|
76
|
+
|
|
77
|
+
# Build fieldmap object
|
|
78
|
+
fmap = TriLinearInterpolatedFieldMap(
|
|
79
|
+
_context=context,
|
|
80
|
+
x_range=x_lim, nx=nx,
|
|
81
|
+
y_range=y_lim, ny=ny, z_range=z_lim, nz=nz,
|
|
82
|
+
solver='FFTSolver2p5D')
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# Compute potential
|
|
86
|
+
n_rep = 10
|
|
87
|
+
for _ in range(n_rep):
|
|
88
|
+
t1 = time.time()
|
|
89
|
+
fmap.update_from_particles(x_p=x_dev, y_p=y_dev, z_p=z_dev,
|
|
90
|
+
ncharges_p=pweights_dev, q0_coulomb=1.)
|
|
91
|
+
|
|
92
|
+
# Check on the x axis
|
|
93
|
+
(rho_test_dev, phi_test_dev, dx_test_dev, dy_test_dev,
|
|
94
|
+
dz_test_dev) = fmap.get_values_at_points(
|
|
95
|
+
x=x_test_dev, y=y_test_dev, z=z_test_dev)
|
|
96
|
+
context.synchronize()
|
|
97
|
+
t2 = time.time()
|
|
98
|
+
print(f'Time: {t2-t1:.2e}')
|
|
99
|
+
|
|
100
|
+
# Copy back for plotting
|
|
101
|
+
platf2np = context.nparray_from_context_array
|
|
102
|
+
rho_test = platf2np(rho_test_dev)
|
|
103
|
+
phi_test = platf2np(phi_test_dev)
|
|
104
|
+
dx_test = platf2np(dx_test_dev)
|
|
105
|
+
dy_test = platf2np(dy_test_dev)
|
|
106
|
+
dz_test = platf2np(dz_test_dev)
|
|
107
|
+
|
|
108
|
+
# pickle for other tests
|
|
109
|
+
import pickle
|
|
110
|
+
# with open('picsphere.pkl', 'wb') as fid:
|
|
111
|
+
# pickle.dump({
|
|
112
|
+
# 'fmap': fmap,
|
|
113
|
+
# 'x_test': x_test,
|
|
114
|
+
# 'y_test': y_test,
|
|
115
|
+
# 'z_test': z_test,
|
|
116
|
+
# }, fid)
|
|
117
|
+
|
|
118
|
+
####################
|
|
119
|
+
# Plots and checks #
|
|
120
|
+
####################
|
|
121
|
+
|
|
122
|
+
ex_test = -dx_test
|
|
123
|
+
ey_test = -dy_test
|
|
124
|
+
ez_test = -dz_test
|
|
125
|
+
|
|
126
|
+
plt.figure(100)
|
|
127
|
+
plt.plot(r_test, rho_test)
|
|
128
|
+
plt.axhline(y=len(x)/(4/3*np.pi*radius**3))
|
|
129
|
+
|
|
130
|
+
plt.figure(101)
|
|
131
|
+
plt.plot(r_test, phi_test)
|
|
132
|
+
|
|
133
|
+
assert z0_test[0]<radius
|
|
134
|
+
r_loc = np.sqrt(radius**2 - z0_test[0]**2)
|
|
135
|
+
rho_ref = len(x)/(4/3*pi*radius**3)
|
|
136
|
+
lam_loc = rho_ref*pi*r_loc**2
|
|
137
|
+
e_ref = rho_ref/(epsilon_0) * (
|
|
138
|
+
r_test/2*(np.abs(r_test)<r_loc)
|
|
139
|
+
+ r_loc**2/r_test/2*(np.abs(r_test)>=r_loc))
|
|
140
|
+
plt.figure(102)
|
|
141
|
+
plt.plot(r_test, ex_test*x0_test/r_test
|
|
142
|
+
+ ey_test*y0_test/r_test)
|
|
143
|
+
plt.plot(r_test, e_ref)
|
|
144
|
+
plt.grid(True)
|
|
145
|
+
|
|
146
|
+
# Check integral
|
|
147
|
+
int_rho = np.sum(platf2np(fmap.rho))*fmap.dx*fmap.dy*fmap.dz
|
|
148
|
+
assert np.isclose(int_rho, len(x))
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
fig1 = plt.figure(1)
|
|
152
|
+
ax1 = fig1.add_subplot(111)
|
|
153
|
+
ax1.pcolormesh(fmap.x_grid, fmap.y_grid,
|
|
154
|
+
np.sum(platf2np(fmap.rho), axis=2).T, shading='gouraud')
|
|
155
|
+
ax1.set_aspect('equal')
|
|
156
|
+
ax1.add_patch(plt.Circle((center_xyz[0], center_xyz[1]), radius,
|
|
157
|
+
color='w', fill=False))
|
|
158
|
+
ax1.set_xlabel('x')
|
|
159
|
+
ax1.set_ylabel('y')
|
|
160
|
+
|
|
161
|
+
fig2 = plt.figure(2)
|
|
162
|
+
ax2 = fig2.add_subplot(111)
|
|
163
|
+
ax2.pcolormesh(fmap.y_grid, fmap.z_grid,
|
|
164
|
+
np.sum(platf2np(fmap.rho), axis=0).T, shading='gouraud')
|
|
165
|
+
ax2.set_aspect('equal')
|
|
166
|
+
ax2.add_patch(plt.Circle((center_xyz[1], center_xyz[2]), radius,
|
|
167
|
+
color='w', fill=False))
|
|
168
|
+
ax2.set_xlabel('y')
|
|
169
|
+
ax2.set_ylabel('z')
|
|
170
|
+
plt.show()
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# copyright ################################# #
|
|
2
|
+
# This file is part of the Xfields Package. #
|
|
3
|
+
# Copyright (c) CERN, 2021. #
|
|
4
|
+
# ########################################### #
|
|
5
|
+
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
from xobjects import ContextCpu, ContextCupy, ContextPyopencl
|
|
11
|
+
import xtrack as xt
|
|
12
|
+
import xpart as xp
|
|
13
|
+
|
|
14
|
+
###################
|
|
15
|
+
# Choose context #
|
|
16
|
+
###################
|
|
17
|
+
|
|
18
|
+
context = ContextCpu(omp_num_threads=0) # no omp
|
|
19
|
+
#context = ContextCpu(omp_num_threads=48) # omp
|
|
20
|
+
#context = ContextCupy(default_block_size=256)
|
|
21
|
+
#context = ContextPyopencl('0.0')
|
|
22
|
+
|
|
23
|
+
print(repr(context))
|
|
24
|
+
|
|
25
|
+
#################################
|
|
26
|
+
# Generate particles and probes #
|
|
27
|
+
#################################
|
|
28
|
+
|
|
29
|
+
n_macroparticles = int(1e6)
|
|
30
|
+
bunch_intensity = 2.5e11
|
|
31
|
+
sigma_x = 3e-3
|
|
32
|
+
sigma_y = 2e-3
|
|
33
|
+
sigma_z = 30e-2
|
|
34
|
+
p0c = 25.92e9
|
|
35
|
+
mass = xp.pmass
|
|
36
|
+
theta_probes = 30 * np.pi/180
|
|
37
|
+
r_max_probes = 2e-2
|
|
38
|
+
z_probes = 1.2*sigma_z
|
|
39
|
+
n_probes = 1000
|
|
40
|
+
|
|
41
|
+
from xfields.test_support.temp_makepart import generate_particles_object
|
|
42
|
+
(particles_dtk, r_probes, x_probes,
|
|
43
|
+
y_probes, z_probes) = generate_particles_object(
|
|
44
|
+
n_macroparticles,
|
|
45
|
+
bunch_intensity,
|
|
46
|
+
sigma_x,
|
|
47
|
+
sigma_y,
|
|
48
|
+
sigma_z,
|
|
49
|
+
p0c,
|
|
50
|
+
mass,
|
|
51
|
+
n_probes,
|
|
52
|
+
r_max_probes,
|
|
53
|
+
z_probes,
|
|
54
|
+
theta_probes)
|
|
55
|
+
particles = xp.Particles(
|
|
56
|
+
_context=context, **particles_dtk.to_dict())
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
######################
|
|
60
|
+
# Space charge (PIC) #
|
|
61
|
+
######################
|
|
62
|
+
|
|
63
|
+
x_lim = 5.*sigma_x
|
|
64
|
+
y_lim = 5.*sigma_y
|
|
65
|
+
z_lim = 5.*sigma_z
|
|
66
|
+
|
|
67
|
+
from xfields import SpaceCharge3D
|
|
68
|
+
spcharge = SpaceCharge3D(
|
|
69
|
+
_context=context,
|
|
70
|
+
length=1, update_on_track=True, apply_z_kick=False,
|
|
71
|
+
x_range=(-x_lim, x_lim),
|
|
72
|
+
y_range=(-y_lim, y_lim),
|
|
73
|
+
z_range=(-z_lim, z_lim),
|
|
74
|
+
nx=256, ny=256, nz=100,
|
|
75
|
+
# solver='FFTSolver2p5D',
|
|
76
|
+
solver='FFTSolver2p5DAveraged',
|
|
77
|
+
gamma0=particles_dtk.gamma0[0])
|
|
78
|
+
|
|
79
|
+
spcharge.track(particles)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
#############################
|
|
83
|
+
# Compare against ducktrack #
|
|
84
|
+
#############################
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
p2np = context.nparray_from_context_array
|
|
88
|
+
|
|
89
|
+
from ducktrack import SCQGaussProfile, TestParticles
|
|
90
|
+
scdtk = SCQGaussProfile(
|
|
91
|
+
number_of_particles = bunch_intensity,
|
|
92
|
+
bunchlength_rms=sigma_z,
|
|
93
|
+
sigma_x=sigma_x,
|
|
94
|
+
sigma_y=sigma_y,
|
|
95
|
+
length=spcharge.length,
|
|
96
|
+
x_co=0.,
|
|
97
|
+
y_co=0.)
|
|
98
|
+
|
|
99
|
+
p_dtk = TestParticles(p0c=p0c,
|
|
100
|
+
mass=mass,
|
|
101
|
+
x=x_probes.copy(),
|
|
102
|
+
y=y_probes.copy(),
|
|
103
|
+
zeta=z_probes.copy())
|
|
104
|
+
|
|
105
|
+
scdtk.track(p_dtk)
|
|
106
|
+
|
|
107
|
+
mask_inside_grid = ((np.abs(x_probes)<0.9*x_lim) &
|
|
108
|
+
(np.abs(y_probes)<0.9*y_lim))
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
import matplotlib.pyplot as plt
|
|
112
|
+
plt.close('all')
|
|
113
|
+
plt.figure(1)
|
|
114
|
+
plt.subplot(211)
|
|
115
|
+
plt.plot(r_probes, p_dtk.px, color='red')
|
|
116
|
+
plt.plot(r_probes, p2np(particles.px[:n_probes]), color='blue',
|
|
117
|
+
linestyle='--')
|
|
118
|
+
plt.subplot(212)
|
|
119
|
+
plt.plot(r_probes, p_dtk.py, color='red')
|
|
120
|
+
plt.plot(r_probes, p2np(particles.py[:n_probes]), color='blue',
|
|
121
|
+
linestyle='--')
|
|
122
|
+
|
|
123
|
+
plt.figure(2)
|
|
124
|
+
plt.subplot(111)
|
|
125
|
+
tr_profile = spcharge.fieldmap.rho.sum(axis=0)
|
|
126
|
+
for ii in range(tr_profile.shape[1]):
|
|
127
|
+
tr_profile[:,ii] = tr_profile[:,ii]/tr_profile[:,ii].max()
|
|
128
|
+
tr_profile = context.nparray_from_context_array(tr_profile)
|
|
129
|
+
plt.plot(tr_profile)
|
|
130
|
+
|
|
131
|
+
###########
|
|
132
|
+
# Time it #
|
|
133
|
+
###########
|
|
134
|
+
|
|
135
|
+
n_rep = 5
|
|
136
|
+
|
|
137
|
+
for _ in range(n_rep):
|
|
138
|
+
t1 = time.time()
|
|
139
|
+
spcharge.track(particles)
|
|
140
|
+
context.synchronize()
|
|
141
|
+
t2 = time.time()
|
|
142
|
+
print(f'Time (full PIC): {(t2-t1)*1e3:.2f} ms')
|
|
143
|
+
|
|
144
|
+
spcharge.update_on_track = False
|
|
145
|
+
for _ in range(n_rep):
|
|
146
|
+
t1 = time.time()
|
|
147
|
+
spcharge.track(particles)
|
|
148
|
+
context.synchronize()
|
|
149
|
+
t2 = time.time()
|
|
150
|
+
print(f'Time (interp only): {(t2-t1)*1e3:.2f} ms')
|
|
151
|
+
|
|
152
|
+
plt.show()
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# copyright ################################# #
|
|
2
|
+
# This file is part of the Xfields Package. #
|
|
3
|
+
# Copyright (c) CERN, 2021. #
|
|
4
|
+
# ########################################### #
|
|
5
|
+
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
from xline.particles import Particles
|
|
11
|
+
from xobjects import ContextCpu, ContextCupy, ContextPyopencl
|
|
12
|
+
import xtrack as xt
|
|
13
|
+
|
|
14
|
+
###################
|
|
15
|
+
# Choose context #
|
|
16
|
+
###################
|
|
17
|
+
|
|
18
|
+
#context = ContextCpu(omp_num_threads=0) # no omp
|
|
19
|
+
context = ContextCpu(omp_num_threads=1) # omp
|
|
20
|
+
#context = ContextCpu(omp_num_threads=48) # omp
|
|
21
|
+
context = ContextCupy(default_block_size=256)
|
|
22
|
+
#context = ContextPyopencl('0.0')
|
|
23
|
+
|
|
24
|
+
print(repr(context))
|
|
25
|
+
|
|
26
|
+
#################################
|
|
27
|
+
# Generate particles and probes #
|
|
28
|
+
#################################
|
|
29
|
+
|
|
30
|
+
n_macroparticles = int(1e6)
|
|
31
|
+
bunch_intensity = 2.5e11
|
|
32
|
+
sigma_x = 3e-3
|
|
33
|
+
sigma_y = 2e-3
|
|
34
|
+
sigma_z = 30e-2
|
|
35
|
+
p0c = 25.92e9
|
|
36
|
+
mass = Particles.pmass
|
|
37
|
+
theta_probes = 30 * np.pi/180
|
|
38
|
+
r_max_probes = 2e-2
|
|
39
|
+
z_probes = 1.2*sigma_z
|
|
40
|
+
n_probes = 1000
|
|
41
|
+
|
|
42
|
+
from xfields.test_support.temp_makepart import generate_particles_object
|
|
43
|
+
(particles_pyst, r_probes, x_probes,
|
|
44
|
+
y_probes, z_probes) = generate_particles_object(
|
|
45
|
+
n_macroparticles,
|
|
46
|
+
bunch_intensity,
|
|
47
|
+
sigma_x,
|
|
48
|
+
sigma_y,
|
|
49
|
+
sigma_z,
|
|
50
|
+
p0c,
|
|
51
|
+
mass,
|
|
52
|
+
n_probes,
|
|
53
|
+
r_max_probes,
|
|
54
|
+
z_probes,
|
|
55
|
+
theta_probes)
|
|
56
|
+
particles = xt.Particles(
|
|
57
|
+
_context=context, **particles_pyst.to_dict())
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
######################
|
|
61
|
+
# Space charge (PIC) #
|
|
62
|
+
######################
|
|
63
|
+
|
|
64
|
+
x_lim = 5.*sigma_x
|
|
65
|
+
y_lim = 5.*sigma_y
|
|
66
|
+
z_lim = 5.*sigma_z
|
|
67
|
+
|
|
68
|
+
from xfields import SpaceCharge3D
|
|
69
|
+
spcharge_parent = SpaceCharge3D(
|
|
70
|
+
_context=context,
|
|
71
|
+
length=1, update_on_track=True, apply_z_kick=False,
|
|
72
|
+
x_range=(-x_lim, x_lim),
|
|
73
|
+
y_range=(-y_lim, y_lim),
|
|
74
|
+
z_range=(-z_lim, z_lim),
|
|
75
|
+
nx=256, ny=256, nz=100,
|
|
76
|
+
solver='FFTSolver2p5D',
|
|
77
|
+
gamma0=particles_pyst.gamma0)
|
|
78
|
+
|
|
79
|
+
spcharge= SpaceCharge3D(
|
|
80
|
+
_buffer=spcharge_parent._buffer,
|
|
81
|
+
length=1, update_on_track=True, apply_z_kick=False,
|
|
82
|
+
fieldmap=spcharge_parent.fieldmap)
|
|
83
|
+
|
|
84
|
+
spcharge.fieldmap.rho[0,0,0] = 100.
|
|
85
|
+
assert np.isclose(spcharge_parent.fieldmap.rho[0,0,0], 100.)
|
|
86
|
+
|
|
87
|
+
spcharge.track(particles)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
#########################
|
|
91
|
+
# Compare against xline #
|
|
92
|
+
#########################
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
p2np = context.nparray_from_context_array
|
|
96
|
+
|
|
97
|
+
from xline.elements import SCQGaussProfile
|
|
98
|
+
scpyst = SCQGaussProfile(
|
|
99
|
+
number_of_particles = bunch_intensity,
|
|
100
|
+
bunchlength_rms=sigma_z,
|
|
101
|
+
sigma_x=sigma_x,
|
|
102
|
+
sigma_y=sigma_y,
|
|
103
|
+
length=spcharge.length,
|
|
104
|
+
x_co=0.,
|
|
105
|
+
y_co=0.)
|
|
106
|
+
|
|
107
|
+
p_pyst = Particles(p0c=p0c,
|
|
108
|
+
mass=mass,
|
|
109
|
+
x=x_probes.copy(),
|
|
110
|
+
y=y_probes.copy(),
|
|
111
|
+
zeta=z_probes.copy())
|
|
112
|
+
|
|
113
|
+
scpyst.track(p_pyst)
|
|
114
|
+
|
|
115
|
+
mask_inside_grid = ((np.abs(x_probes)<0.9*x_lim) &
|
|
116
|
+
(np.abs(y_probes)<0.9*y_lim))
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
import matplotlib.pyplot as plt
|
|
120
|
+
plt.close('all')
|
|
121
|
+
plt.figure()
|
|
122
|
+
plt.subplot(211)
|
|
123
|
+
plt.plot(r_probes, p_pyst.px, color='red')
|
|
124
|
+
plt.plot(r_probes, p2np(particles.px[:n_probes]), color='blue',
|
|
125
|
+
linestyle='--')
|
|
126
|
+
plt.subplot(212)
|
|
127
|
+
plt.plot(r_probes, p_pyst.py, color='red')
|
|
128
|
+
plt.plot(r_probes, p2np(particles.py[:n_probes]), color='blue',
|
|
129
|
+
linestyle='--')
|
|
130
|
+
|
|
131
|
+
###########
|
|
132
|
+
# Time it #
|
|
133
|
+
###########
|
|
134
|
+
|
|
135
|
+
n_rep = 5
|
|
136
|
+
|
|
137
|
+
for _ in range(n_rep):
|
|
138
|
+
t1 = time.time()
|
|
139
|
+
spcharge.track(particles)
|
|
140
|
+
context.synchronize()
|
|
141
|
+
t2 = time.time()
|
|
142
|
+
print(f'Time (full PIC): {(t2-t1)*1e3:.2f} ms')
|
|
143
|
+
|
|
144
|
+
spcharge.update_on_track = False
|
|
145
|
+
for _ in range(n_rep):
|
|
146
|
+
t1 = time.time()
|
|
147
|
+
spcharge.track(particles)
|
|
148
|
+
context.synchronize()
|
|
149
|
+
t2 = time.time()
|
|
150
|
+
print(f'Time (interp only): {(t2-t1)*1e3:.2f} ms')
|
|
151
|
+
|
|
152
|
+
plt.show()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from scipy.constants import e as qe
|
|
3
|
+
|
|
4
|
+
import xfields as xf
|
|
5
|
+
import xpart as xp
|
|
6
|
+
|
|
7
|
+
sc = xf.SpaceCharge3D(
|
|
8
|
+
x_range=(-0.01, 0.01),
|
|
9
|
+
y_range=(-0.01, 0.01),
|
|
10
|
+
z_range=(-1, 1),
|
|
11
|
+
nx=128,
|
|
12
|
+
ny=128,
|
|
13
|
+
nz=128,
|
|
14
|
+
solver='FFTSolver2p5D'
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
particles = xp.Particles(
|
|
18
|
+
x=[0.002, 0.003, 0.004],
|
|
19
|
+
y=[0.002, 0.003, 0.004],
|
|
20
|
+
zeta=[-0.5, 0., 0.05],
|
|
21
|
+
mass0=xp.PROTON_MASS_EV,
|
|
22
|
+
p0c=1e9,
|
|
23
|
+
weight=[1., 1., 1.])
|
|
24
|
+
|
|
25
|
+
particles.state = np.array([1, 1, -20])
|
|
26
|
+
|
|
27
|
+
sc.track(particles)
|
|
28
|
+
|
|
29
|
+
dx = sc.fieldmap.dx
|
|
30
|
+
dy = sc.fieldmap.dy
|
|
31
|
+
dz = sc.fieldmap.dz
|
|
32
|
+
|
|
33
|
+
charges = np.sum(sc.fieldmap.rho[:]) * dx * dy * dz / qe
|