-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release_merge' of https://github.com/like2000/PyHEADTAIL
Conflicts: cobra_functions/__init__.py cobra_functions/stats.pyx impedances/__init__.py monitors/__init__.py solvers/__init__.py trackers/__init__.py
- Loading branch information
Showing
113 changed files
with
12,240 additions
and
372,251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ scripts/ | |
#* | ||
.project | ||
.pydevproject | ||
*.h5 | ||
*.h5part | ||
.ipynb_checkpoints |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from ._version import __version__ | ||
from general.element import Element, Printing | ||
from particles.slicing import clean_slices | ||
# print ' ' | ||
# print ' ;Cfttttt11111111tttt1f0f. ' | ||
# print ' ,GttttfG0GGG00000GGG0G0G0G0G0G0Ct1t1fG: ' | ||
# print ' ,GtttLG000GGGGGGGGGGG00GGGGGGGGGGGGGG0GGG0GCtttLt ' | ||
# print ' .CtttC0G00GGGGGGGGGGG00t1t1GGGGGGGGGGGGGGGGGG0GG0G00Gtttt ' | ||
# print ' G1tf000GGGGGGGGGG000811tGG0GL0GGGGGGGGGGGGGGGGGGGGGGGGGGGGG11C ' | ||
# print ' GtttGG0G00GGGGGGGGG08t1GGG0;;0G000GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGtt: ' | ||
# print ' 01tGG00GGGGGGGGGGGG0tt000ft::::GGG00GGGGGGGGGGGGGGGGGGG0GGG0G0000000GftG ' | ||
# print ' L1tLf. 8ttGGGGGGGGGGGGGG00GtGG8fft:::::;0GG@0GGGGGGGGGGGGG00G088888888888GttfLLLt1C ' | ||
# print ' CtG0G0GG8888t.G1tGGGGGGGGGGGGGGG0fGG0ffff;:::::::0G08GGGGGGGGGGGG888888888888f ' | ||
# print ' .tt0GGGGG0888Ctf0GGGGGGGGGGGG0G0000GGGG0Gt;:;:::;0GG88GGGGG8808888888888C ' | ||
# print ' C1GGGGGG0G01t00GGGGGGGGGGGGG00000000GGGGGGGG;::;GGG80GGGGGGGG0Lt1t@@i ' | ||
# print ' 1tGGGGG0811G00GGGGGGGGGGGGGGGG0880G0GGGGGG0G0;L0G08GGGGGGGGGGG0GGG1ttf ' | ||
# print ' t1t0GG08t1G0GGGGGGGGGGGGG0GtLGGGG0GLtGGGGGGGGG8G08GGGGGGGGGGGGGGGGG00tttf ' | ||
# print ' 0tCGG8tt00GGGGGGGGG0G0CtG0GG0GGG000GGt00GGGG000GGGGGGGGGGGGGGGGGGGGGG0G1tG ' | ||
# print ' 0G0G81G0GGGGGGGGGG0Gf00GG8888@8@80GGG0CGGG0GGGGGGGGGGGGGGGGGGGGGGGGGG000ttL ' | ||
# print ' C11GG080GGGGGGGG00t0GG08@111: .i1t80GG08GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGt1C ' | ||
# print ' f0@tGGGGGGGGGGG00C0GG88i1 1GG0G0GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG0GGttC ' | ||
# print ' G88ffG0GGGGGG0G0GGG0811. .0GG08GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG0Gt1L ' | ||
# print ' C .C .0G1800GGGGGG0G00f0811 .0G00GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG0G11i ' | ||
# print ' L 1 Lt 11GGGGGGG000ft81: .8; 0G0GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG0GG001t0 ' | ||
# print ' L: .C 1 f t 8CG00GGGG0G181, 0G00 00G0GG0GGGGGGGGGGGGGGGGGGGGGGGG0GGGGGGGGGGGGtt8 ' | ||
# print ' f. . .;iC .. C .tGLG0GGGGt01. 0, Gi 0GGGGGGGGGGGGGGGGGGG0GGGGGGGGGGGGGGGGGGGGGGGGtt8 ' | ||
# print ' CL0t .G1111 : G 1 08t8L0000t11: 00@8L t0GGGGGGGGGGGGGGGGGGG80GGGGGGGGGGGGGGGGGGGGGGGG11L ' | ||
# print ' 1 C1 i f , :,0C10G0Ltf: :C8@1 :00GGGGGGGGGGGGGGGGGGGGG8888880000GGGGGGGGGGGGGGCtt. ' | ||
# print ' ,1G:C111. .1 i i i 0@80ttt10i G111 fGGG0GGGGGGGGGGGGGGGGGGGGG8888888888GGG0GGGGGGGGGGtt0 ' | ||
# print ' ; tL1 01 ; Gf C 00. LG1 f f;;:::;;:8GGGGGGGGGGGGGGG0GGGt888888888880GGGGGGGG00Gtt. ' | ||
# print ' i1i C1 i111 . C8@G i0,G;::;C1 .t;:;:;::::::0GGGG00GGGGGGGGGGG0G11 .G8@8888880GGGGGGGGGL1G ' | ||
# print ' L111tt1111. 1; 1111. . @888@@888:;:;;:;;;0. :t::::;: :::::8GG88GGGGG0GGGGGGGGGC1, 8888@8800GGGGGG1t ' | ||
# print ' 8 C1 f L11i ;. 1. ;.:;:::::::::::::::::::::;; ;;:::10G880GGGGGGGGGGGGGG0GL1 ,88888G0GGG0f1. ' | ||
# print ' G .i, .1 G ,1110f L.::::::::::::::::::::;. i.L;;:;LG88888G0GGGGGGGGGGGGGG0tf ,88880GGGGt; ' | ||
# print ' t111111; :11 f11L G .1.::::::::::::;CC;:;:;:::;;C88888888880GGGGGGGGGGGGG0G1G 0@8000G1t ' | ||
# print ' L1Cf011. ;11 .11G t1.L ,L,.::::::;:::::;:::C@888888888888888G000GGGGGGGGGGt1 f880GtL ' | ||
# print ' .G111111111. .1t. 111.. .:LG8888@88088@0tfL@G t88888888880GGGGGGGGG0GCti CC0tL ' | ||
# print ' ;L111111110. .1C i :..::;ft888888888ffffffftt8. 08888880GGGGGGGGGGGtG tti ' | ||
# print ' G11i,,,,. 0 :L..;:::::;ffC88888888fffi::::::..C; C88888GGG0GGGG0GtC f. ' | ||
# print ' .Gf11111. :Cff.C ,tftL.,;:::::::::;f888888888881:;:::::::..i. 888800GGGGGG01L ' | ||
# print ' i1111111111ffft;:.....::ft..:::::::::::::0G000GGGG8888880f;;;::::.. 88880GGGGGGtf ' | ||
# print ' .. iffff;:::::::;ttC.::::::::::::::0GGGG0GC888888800t G::::;.G @88GGGGGGtf ' | ||
# print ' . G::::::;1: L.;:;:::::::::::GG0G0Gf888888 Gi10::::;:. .;@8GGGGGtC ' | ||
# print ' ,.:::::::::::::;0GG1 L888 1L fG:;:::::. 880GGG1C ' | ||
# print ' .,:::::::::::;80i...... 1G tf;:::.; 880001. ' | ||
# print ' :.:::::::::::t. . GftftC,G G0Gtt ' | ||
# print ' :.:;::::::;i , Ct11G LC1i ' | ||
# print ' 1:::::::1001 C . tf ' | ||
# print ' ' | ||
print ('PyHEADTAIL v' + __version__ + '\n\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__version__ = "1.0.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .. import __version__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
""" | ||
@author Kevin Li, Michael Schenk | ||
@date 31. January 2014 | ||
@brief Collection of cython functions to calculate statistics | ||
of bunch and slice_set data. | ||
@copyright CERN | ||
""" | ||
import numpy as np | ||
cimport numpy as np | ||
cimport libc.math as cmath | ||
|
||
cimport cython.boundscheck | ||
cimport cython.cdivision | ||
|
||
|
||
@cython.boundscheck(False) | ||
cpdef double mean(double[::1] u): | ||
""" Cython function to calculate the mean value of dataset u. """ | ||
cdef double mean_u = 0 | ||
cdef unsigned int n = u.shape[0] | ||
|
||
cdef unsigned int i | ||
for i in xrange(n): | ||
mean_u += u[i] | ||
if n: | ||
mean_u /= n | ||
|
||
return mean_u | ||
|
||
@cython.boundscheck(False) | ||
cpdef double std(double[::1] u): | ||
""" Cython function to calculate the standard deviation of | ||
dataset u. """ | ||
cdef double mean_u = mean(u) | ||
cdef double std_u = 0 | ||
cdef double du = 0 | ||
|
||
cdef unsigned int n = u.shape[0] | ||
cdef unsigned int i | ||
for i in xrange(n): | ||
du = u[i] - mean_u | ||
std_u += du * du | ||
if n: | ||
std_u /= n | ||
|
||
return cmath.sqrt(std_u) | ||
|
||
@cython.boundscheck(False) | ||
cpdef double emittance(double[::1] u, double[::1] up): | ||
""" Cython function to calculate the emittance of datasets | ||
u and up, i.e. a coordinate-momentum pair. To calculate the | ||
emittance, one needs the mean values of quantities u and | ||
up. """ | ||
cdef double mean_u = mean(u) | ||
cdef double mean_up = mean(up) | ||
|
||
cdef double u2 = 0 | ||
cdef double up2 = 0 | ||
cdef double uup = 0 | ||
cdef double du = 0 | ||
cdef double dup = 0 | ||
|
||
cdef unsigned int n = u.shape[0] | ||
cdef unsigned int i | ||
for i in xrange(n): | ||
du = u[i] - mean_u | ||
dup = up[i] - mean_up | ||
|
||
u2 += du * du | ||
up2 += dup * dup | ||
uup += du * dup | ||
if n: | ||
u2 /= n | ||
up2 /= n | ||
uup /= n | ||
|
||
return cmath.sqrt(u2*up2 - uup*uup) | ||
|
||
|
||
''' | ||
Cython statistics functions for an instance of a SliceSet class. | ||
''' | ||
|
||
@cython.boundscheck(False) | ||
@cython.cdivision(True) | ||
cpdef count_macroparticles_per_slice(int[::1] slice_index_of_particle, | ||
int[::1] particles_within_cuts, | ||
int[::1] n_macroparticles): | ||
""" Cython function to count the number of macroparticles in | ||
each slice. """ | ||
cdef unsigned int n_particles_within_cuts = particles_within_cuts.shape[0] | ||
cdef unsigned int s_idx, i | ||
|
||
for i in xrange(n_particles_within_cuts): | ||
s_idx = slice_index_of_particle[particles_within_cuts[i]] | ||
n_macroparticles[s_idx] += 1 | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.cdivision(True) | ||
cpdef sort_particle_indices_by_slice(int[::1] slice_index_of_particle, | ||
int[::1] particles_within_cuts, | ||
int[::1] slice_positions, | ||
int[::1] particle_indices_by_slice): | ||
""" Iterate once through all the particles within the slicing | ||
region and assign their position in the bunch.z array to the | ||
respective slice they are in. | ||
This is to provide a method to the user that allows to see | ||
which particles are in a specific slice (see | ||
particle_indices_of_slice in SliceSet class). """ | ||
cdef unsigned int n_part_in_cuts = particles_within_cuts.shape[0] | ||
cdef unsigned int n_slices = slice_positions.shape[0] - 1 | ||
|
||
cdef unsigned int[::1] pos_ctr = np.zeros(n_slices, dtype=np.uint32) | ||
cdef unsigned int i, p_idx, s_idx | ||
cdef unsigned int pos | ||
|
||
for i in xrange(n_part_in_cuts): | ||
p_idx = particles_within_cuts[i] | ||
s_idx = slice_index_of_particle[p_idx] | ||
|
||
pos = slice_positions[s_idx] + pos_ctr[s_idx] | ||
particle_indices_by_slice[pos] = p_idx | ||
pos_ctr[s_idx] += 1 | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.cdivision(True) | ||
cpdef mean_per_slice(int[::1] slice_index_of_particle, | ||
int[::1] particles_within_cuts, | ||
int[::1] n_macroparticles, | ||
double[::1] u, double[::1] mean_u): | ||
""" Iterate once through all the particles within the | ||
slicing region and calculate simultaneously the mean | ||
value of quantity u for each slice separately. """ | ||
cdef unsigned int n_part_in_cuts = particles_within_cuts.shape[0] | ||
cdef unsigned int n_slices = mean_u.shape[0] | ||
cdef unsigned int p_idx, s_idx, i | ||
|
||
for i in xrange(n_part_in_cuts): | ||
p_idx = particles_within_cuts[i] | ||
s_idx = slice_index_of_particle[p_idx] | ||
mean_u[s_idx] += u[p_idx] | ||
|
||
for i in xrange(n_slices): | ||
if n_macroparticles[i]: | ||
mean_u[i] /= n_macroparticles[i] | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.cdivision(True) | ||
cpdef std_per_slice(int[::1] slice_index_of_particle, | ||
int[::1] particles_within_cuts, | ||
int[::1] n_macroparticles, | ||
double[::1] u, double[::1] std_u): | ||
""" Iterate once through all the particles within the | ||
slicing region and calculate simultaneously the | ||
standard deviation of quantity u for each slice | ||
separately. """ | ||
cdef unsigned int n_part_in_cuts = particles_within_cuts.shape[0] | ||
cdef unsigned int n_slices = std_u.shape[0] | ||
cdef unsigned int p_idx, s_idx, i | ||
cdef double du | ||
|
||
cdef double[::1] mean_u = np.zeros(n_slices, dtype=np.double) | ||
mean_per_slice(slice_index_of_particle, particles_within_cuts, | ||
n_macroparticles, u, mean_u) | ||
|
||
for i in xrange(n_part_in_cuts): | ||
p_idx = particles_within_cuts[i] | ||
s_idx = slice_index_of_particle[p_idx] | ||
|
||
du = u[p_idx] - mean_u[s_idx] | ||
std_u[s_idx] += du * du | ||
|
||
for i in xrange(n_slices): | ||
if n_macroparticles[i]: | ||
std_u[i] /= n_macroparticles[i] | ||
|
||
std_u[i] = cmath.sqrt(std_u[i]) | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.cdivision(True) | ||
cpdef emittance_per_slice(int[::1] slice_index_of_particle, | ||
int[::1] particles_within_cuts, | ||
int[::1] n_macroparticles, | ||
double[::1] u, double[::1] up, double[::1] epsn_u): | ||
""" Iterate once through all the particles within the | ||
slicing region and calculate simultaneously the emittance | ||
of quantities u and up, i.e. a coordinate-momentum pair, | ||
for each slice separately. To calculate the emittance per | ||
slice, one needs the mean values of quantities u and up | ||
for each slice. """ | ||
cdef unsigned int n_part_in_cuts = particles_within_cuts.shape[0] | ||
cdef unsigned int n_slices = epsn_u.shape[0] | ||
cdef unsigned int p_idx, s_idx, i | ||
|
||
# Determine mean values of u and up for each slice. | ||
cdef double[::1] mean_u = np.zeros(n_slices, dtype=np.double) | ||
cdef double[::1] mean_up = np.zeros(n_slices, dtype=np.double) | ||
mean_per_slice(slice_index_of_particle, particles_within_cuts, | ||
n_macroparticles, u, mean_u) | ||
mean_per_slice(slice_index_of_particle, particles_within_cuts, | ||
n_macroparticles, up, mean_up) | ||
|
||
cdef double du, dup | ||
cdef double[::1] u2 = np.zeros(n_slices, dtype=np.double) | ||
cdef double[::1] up2 = np.zeros(n_slices, dtype=np.double) | ||
cdef double[::1] uup = np.zeros(n_slices, dtype=np.double) | ||
|
||
for i in xrange(n_part_in_cuts): | ||
p_idx = particles_within_cuts[i] | ||
s_idx = slice_index_of_particle[p_idx] | ||
|
||
du = u[p_idx] - mean_u[s_idx] | ||
dup = up[p_idx] - mean_up[s_idx] | ||
|
||
u2[s_idx] += du * du | ||
up2[s_idx] += dup * dup | ||
uup[s_idx] += du * dup | ||
|
||
for i in xrange(n_slices): | ||
if n_macroparticles[i]: | ||
u2[i] /= n_macroparticles[i] | ||
up2[i] /= n_macroparticles[i] | ||
uup[i] /= n_macroparticles[i] | ||
|
||
epsn_u[i] = cmath.sqrt(u2[i]*up2[i] - uup[i]*uup[i]) |
Oops, something went wrong.