Skip to content

Commit 2ddef4a

Browse files
committed
The Python subclass of C++ Bunch class has been added. Users can add pure Python methods to this subclass to extend functionality of the C++ Bunch. Please avoid overloading of the C++ methods of the Bunch class.
1 parent 7671a02 commit 2ddef4a

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

py/orbit/bunch/Bunch.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
This is a pure Python subclass of the C++ Bunch class from orbit.core.bunch.
3+
Users can extend the C++ Bunch with pure Python methods.
4+
"""
5+
6+
import sys
7+
8+
from orbit.core.bunch import Bunch as cppBunch
9+
10+
class Bunch(cppBunch):
11+
def __init__(self):
12+
cppBunch.__init__(self)
13+
14+
def getNumpyVersion(self):
15+
import numpy as np
16+
return np.__version__
17+
18+
if __name__ == '__main__':
19+
from orbit.py_linac.lattice import Drift
20+
21+
py_bunch = Bunch()
22+
eKin = 1.4
23+
py_bunch.getSyncParticle().kinEnergy(eKin)
24+
25+
x = 1.0; y = 2.0; z = 3.0
26+
xp = -1.0; yp = -2.0; zp = -3.0
27+
py_bunch.addParticle(x*1.e-3,xp*1.e-3,y*1.e-3,yp*1.e-3,z*1.e-3,zp*1.e-3)
28+
29+
print ("============== Initial coordinates =============")
30+
py_bunch.dumpBunch()
31+
32+
drift = Drift("drift")
33+
drift.setLength(1.0)
34+
drift.trackBunch(py_bunch)
35+
print ("============== New coordinates =================")
36+
py_bunch.dumpBunch()
37+
38+
print ("Stop.")
39+
sys.exit(0)

py/orbit/bunch/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .Bunch import Bunch
2+
3+
__all__ = []
4+
__all__.append("Bunch")

py/orbit/bunch/meson.build

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
py_sources = files([
2+
'Bunch.py',
3+
'__init__.py'
4+
])
5+
6+
python.install_sources(
7+
py_sources,
8+
subdir: 'orbit/bunch',
9+
# pure: true,
10+
)

py/orbit/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
subdir('bumps')
3+
subdir('bunch')
34
subdir('core')
45
subdir('matching')
56
subdir('time_dep')

0 commit comments

Comments
 (0)