Skip to content
Snippets Groups Projects
Commit eff9c02d authored by Alexis GAMELIN's avatar Alexis GAMELIN
Browse files

Add LongitudinalAperture and fix other apperture classes

parent 6186e11f
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,9 @@ from mbtrack2.tracking.optics import Optics, PhyisicalModel ...@@ -14,7 +14,9 @@ from mbtrack2.tracking.optics import Optics, PhyisicalModel
from mbtrack2.tracking.element import (Element, LongitudinalMap, from mbtrack2.tracking.element import (Element, LongitudinalMap,
TransverseMap, SynchrotronRadiation, TransverseMap, SynchrotronRadiation,
SkewQuadrupole) SkewQuadrupole)
from mbtrack2.tracking.aperture import (CircularAperture, ElipticalAperture, from mbtrack2.tracking.aperture import (CircularAperture,
RectangularAperture) ElipticalAperture,
RectangularAperture,
LongitudinalAperture)
from mbtrack2.tracking.wakepotential import WakePotential from mbtrack2.tracking.wakepotential import WakePotential
...@@ -16,13 +16,11 @@ class CircularAperture(Element): ...@@ -16,13 +16,11 @@ class CircularAperture(Element):
Parameters Parameters
---------- ----------
ring : Synchrotron object
radius : float radius : float
radius of the circle in [m] radius of the circle in [m]
""" """
def __init__(self, ring, radius): def __init__(self, radius):
self.ring = ring
self.radius = radius self.radius = radius
self.radius_squared = radius**2 self.radius_squared = radius**2
...@@ -37,8 +35,8 @@ class CircularAperture(Element): ...@@ -37,8 +35,8 @@ class CircularAperture(Element):
---------- ----------
bunch : Bunch or Beam object bunch : Bunch or Beam object
""" """
alive = bunch.particles["x"]**2 + bunch.particles["y"]**2 > self.radius_squared alive = bunch.particles["x"]**2 + bunch.particles["y"]**2 < self.radius_squared
bunch.alive[alive] = False bunch.alive[~alive] = False
class ElipticalAperture(Element): class ElipticalAperture(Element):
""" """
...@@ -47,15 +45,13 @@ class ElipticalAperture(Element): ...@@ -47,15 +45,13 @@ class ElipticalAperture(Element):
Parameters Parameters
---------- ----------
ring : Synchrotron object
X_radius : float X_radius : float
horizontal radius of the elipse in [m] horizontal radius of the elipse in [m]
Y_radius : float Y_radius : float
vertical radius of the elipse in [m] vertical radius of the elipse in [m]
""" """
def __init__(self, ring, X_radius, Y_radius): def __init__(self, X_radius, Y_radius):
self.ring = ring
self.X_radius = X_radius self.X_radius = X_radius
self.X_radius_squared = X_radius**2 self.X_radius_squared = X_radius**2
self.Y_radius = Y_radius self.Y_radius = Y_radius
...@@ -73,8 +69,8 @@ class ElipticalAperture(Element): ...@@ -73,8 +69,8 @@ class ElipticalAperture(Element):
bunch : Bunch or Beam object bunch : Bunch or Beam object
""" """
alive = (bunch.particles["x"]**2/self.X_radius_squared + alive = (bunch.particles["x"]**2/self.X_radius_squared +
bunch.particles["y"]**2/self.Y_radius_squared > 1) bunch.particles["y"]**2/self.Y_radius_squared < 1)
bunch.alive[alive] = False bunch.alive[~alive] = False
class RectangularAperture(Element): class RectangularAperture(Element):
""" """
...@@ -83,7 +79,6 @@ class RectangularAperture(Element): ...@@ -83,7 +79,6 @@ class RectangularAperture(Element):
Parameters Parameters
---------- ----------
ring : Synchrotron object
X_right : float X_right : float
right horizontal aperture of the rectangle in [m] right horizontal aperture of the rectangle in [m]
Y_top : float Y_top : float
...@@ -94,8 +89,7 @@ class RectangularAperture(Element): ...@@ -94,8 +89,7 @@ class RectangularAperture(Element):
bottom vertical aperture of the rectangle in [m] bottom vertical aperture of the rectangle in [m]
""" """
def __init__(self, ring, X_right, Y_top, X_left=None, Y_bottom=None): def __init__(self, X_right, Y_top, X_left=None, Y_bottom=None):
self.ring = ring
self.X_right = X_right self.X_right = X_right
self.X_left = X_left self.X_left = X_left
self.Y_top = Y_top self.Y_top = Y_top
...@@ -127,4 +121,42 @@ class RectangularAperture(Element): ...@@ -127,4 +121,42 @@ class RectangularAperture(Element):
(bunch.particles["y"] > self.Y_bottom)) (bunch.particles["y"] > self.Y_bottom))
alive = alive_X & alive_Y alive = alive_X & alive_Y
bunch.alive[alive] = False bunch.alive[~alive] = False
\ No newline at end of file
class LongitudinalAperture(Element):
"""
Longitudinal aperture element. The particles which are outside of the
longitudinal bounds are 'lost' and not used in the tracking any more.
Parameters
----------
ring : Synchrotron object
tau_up : float
Upper longitudinal bound in [s].
tau_low : float, optional
Lower longitudinal bound in [s].
"""
def __init__(self, tau_up, tau_low=None):
self.tau_up = tau_up
if tau_low is None:
self.tau_low = tau_up*-1
else:
self.tau_low = tau_low
@Element.parallel
def track(self, bunch):
"""
Tracking method for the element.
No bunch to bunch interaction, so written for Bunch objects and
@Element.parallel is used to handle Beam objects.
Parameters
----------
bunch : Bunch or Beam object
"""
alive = ((bunch.particles["tau"] < self.tau_up) &
(bunch.particles["tau"] > self.tau_low))
bunch.alive[~alive] = False
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment