Skip to content

Commit ad35267

Browse files
authored
Merge pull request #26 from xsuite/release0.2.3
Release 0.2.3
2 parents b270fc6 + 015178c commit ad35267

File tree

11 files changed

+128
-78
lines changed

11 files changed

+128
-78
lines changed

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "xcoll"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
description = "Xsuite collimation package"
55
homepage = "https://github.com/xsuite/xcoll"
66
repository = "https://github.com/xsuite/xcoll"
@@ -25,7 +25,6 @@ xdeps = ">=0.1.1"
2525
xpart = ">=0.15.0"
2626
xtrack = ">=0.36.5"
2727
xfields = ">=0.12.1"
28-
xcoll = ">=0.2.1"
2928

3029
[tool.poetry.dev-dependencies]
3130
pytest = ">=7.3"

tests/test_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from xcoll import __version__
22

33
def test_version():
4-
assert __version__ == '0.2.2'
4+
assert __version__ == '0.2.3'
55

xcoll/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from .general import _pkg_root
22

33
from .beam_elements import BaseCollimator, BlackAbsorber, EverestCollimator, EverestCrystal
4-
from .scattering_routines.everest import materials
5-
from .scattering_routines.everest.materials import GeneralMaterial, Material, CrystalMaterial
4+
from .scattering_routines.everest import materials, Material, CrystalMaterial
65
from .manager import CollimatorManager
76
from .colldb import CollimatorDatabase, load_SixTrack_colldb
87

9-
__version__ = '0.2.2'
8+
__version__ = '0.2.3'

xcoll/beam_elements/collimators_src/everest_collimator.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
#include <math.h>
99
#include <stdio.h>
1010

11+
/*gpufun*/
12+
void EverestCollimator_set_material(EverestCollimatorData el, LocalParticle* part0){
13+
MaterialData material = EverestCollimatorData_getp__material(el);
14+
RandomRutherfordData rng = EverestCollimatorData_getp_rutherford_rng(el);
15+
RandomRutherford_set_by_xcoll_material(rng, (GeneralMaterialData) material);
16+
}
1117

1218
/*gpufun*/
1319
void EverestCollimator_track_local_particle(EverestCollimatorData el, LocalParticle* part0) {
@@ -19,7 +25,6 @@ void EverestCollimator_track_local_particle(EverestCollimatorData el, LocalParti
1925

2026
MaterialData material = EverestCollimatorData_getp__material(el);
2127
RandomRutherfordData rng = EverestCollimatorData_getp_rutherford_rng(el);
22-
RandomRutherford_set_by_xcoll_material(rng, (GeneralMaterialData) material);
2328

2429
// Collimator properties
2530
double const length = EverestCollimatorData_get_active_length(el);
@@ -48,10 +53,10 @@ void EverestCollimator_track_local_particle(EverestCollimatorData el, LocalParti
4853
} else {
4954
// Check collimator initialisation
5055
int8_t is_tracking = assert_tracking(part, XC_ERR_INVALID_TRACK);
51-
int8_t rng_set = assert_rng_set(part, RNG_ERR_SEEDS_NOT_SET);
52-
int8_t ruth_set = assert_rutherford_set(rng, part, RNG_ERR_RUTH_NOT_SET);
56+
int8_t rng_is_set = assert_rng_set(part, RNG_ERR_SEEDS_NOT_SET);
57+
int8_t ruth_is_set = assert_rutherford_set(rng, part, RNG_ERR_RUTH_NOT_SET);
5358

54-
if (is_tracking && rng_set && ruth_set) {
59+
if (is_tracking && rng_is_set && ruth_is_set) {
5560
// Drift inactive front
5661
Drift_single_particle(part, inactive_front);
5762

xcoll/beam_elements/collimators_src/everest_crystal.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
#include <stdio.h>
1010

1111

12+
13+
/*gpufun*/
14+
void EverestCrystal_set_material(EverestCrystalData el, LocalParticle* part0){
15+
CrystalMaterialData material = EverestCrystalData_getp__material(el);
16+
RandomRutherfordData rng = EverestCrystalData_getp_rutherford_rng(el);
17+
RandomRutherford_set_by_xcoll_material(rng, (GeneralMaterialData) material);
18+
}
19+
1220
/*gpufun*/
1321
void EverestCrystal_track_local_particle(EverestCrystalData el, LocalParticle* part0) {
1422
int8_t active = EverestCrystalData_get_active(el);
@@ -19,7 +27,6 @@ void EverestCrystal_track_local_particle(EverestCrystalData el, LocalParticle* p
1927

2028
CrystalMaterialData material = EverestCrystalData_getp__material(el);
2129
RandomRutherfordData rng = EverestCrystalData_getp_rutherford_rng(el);
22-
RandomRutherford_set_by_xcoll_material(rng, (GeneralMaterialData) material);
2330

2431
// Crystal properties
2532
double length = EverestCrystalData_get_active_length(el);
@@ -60,6 +67,13 @@ void EverestCrystal_track_local_particle(EverestCrystalData el, LocalParticle* p
6067
double const cry_orient = EverestCrystalData_get__orient(el);
6168
double const cry_miscut = EverestCrystalData_get_miscut(el);
6269

70+
// Impact table
71+
CollimatorImpactsData record = EverestCrystalData_getp_internal_record(el, part0);
72+
RecordIndex record_index = NULL;
73+
if (record){
74+
record_index = CollimatorImpactsData_getp__index(record);
75+
}
76+
6377
//start_per_particle_block (part0->part)
6478
if (!active){
6579
// Drift full length
@@ -68,10 +82,10 @@ void EverestCrystal_track_local_particle(EverestCrystalData el, LocalParticle* p
6882
} else {
6983
// Check collimator initialisation
7084
int8_t is_tracking = assert_tracking(part, XC_ERR_INVALID_TRACK);
71-
int8_t rng_set = assert_rng_set(part, RNG_ERR_SEEDS_NOT_SET);
72-
int8_t ruth_set = assert_rutherford_set(rng, part, RNG_ERR_RUTH_NOT_SET);
85+
int8_t rng_is_set = assert_rng_set(part, RNG_ERR_SEEDS_NOT_SET);
86+
int8_t ruth_is_set = assert_rutherford_set(rng, part, RNG_ERR_RUTH_NOT_SET);
7387

74-
if (is_tracking && rng_set && ruth_set) {
88+
if (is_tracking && rng_is_set && ruth_is_set) {
7589
// Drift inactive front
7690
Drift_single_particle(part, inactive_front);
7791

@@ -83,7 +97,7 @@ void EverestCrystal_track_local_particle(EverestCrystalData el, LocalParticle* p
8397

8498
scatter_cry(part, length, material, rng, cos_zL, sin_zL, c_aperture, c_offset,
8599
side, cry_tilt, cry_rcurv, cry_bend, cry_alayer, cry_xmax, cry_ymax, cry_orient,
86-
cry_miscut);
100+
cry_miscut, record, record_index);
87101

88102
// Return from closed orbit
89103
LocalParticle_add_to_x(part, co_x);

xcoll/beam_elements/everest_collimator.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import xtrack as xt
99

1010
from .base_collimator import BaseCollimator, InvalidCollimator
11-
from ..scattering_routines.everest import Material, CrystalMaterial, EverestEngine
11+
from ..scattering_routines.everest import GeneralMaterial, Material, CrystalMaterial, EverestEngine
1212
from ..general import _pkg_root
1313

1414

@@ -20,6 +20,8 @@
2020
# only activated around the track command. Furthermore, because of 'iscollective = False' we need to specify
2121
# get_backtrack_element. We want it nicer..
2222

23+
# TODO: _per_particle_kernels should be a normal kernel (such that we don't need to pass a dummy Particles() )
24+
2325
class EverestCollimator(BaseCollimator):
2426
_xofields = { **BaseCollimator._xofields,
2527
'_material': Material,
@@ -41,6 +43,13 @@ class EverestCollimator(BaseCollimator):
4143
_pkg_root.joinpath('beam_elements','collimators_src','everest_collimator.h')
4244
]
4345

46+
_per_particle_kernels = {
47+
'_EverestCollimator_set_material': xo.Kernel(
48+
c_name='EverestCollimator_set_material',
49+
args=[]
50+
)
51+
}
52+
4453

4554
def __init__(self, **kwargs):
4655
if '_xobject' not in kwargs:
@@ -54,8 +63,8 @@ def __init__(self, **kwargs):
5463
kwargs.setdefault('rutherford_rng', xt.RandomRutherford())
5564
kwargs.setdefault('_tracking', True)
5665
super().__init__(**kwargs)
57-
# if '_xobject' not in kwargs:
58-
# self.random_generator.set_rutherford_by_xcoll_material(self.material)
66+
if '_xobject' not in kwargs:
67+
self._EverestCollimator_set_material(xp.Particles())
5968

6069
@property
6170
def material(self):
@@ -67,7 +76,7 @@ def material(self, material):
6776
if not isinstance('material', dict) or material['__class__'] != "Material":
6877
raise ValueError("Invalid material!")
6978
self._material = material
70-
# self.random_generator.set_rutherford_by_xcoll_material(material)
79+
self._EverestCollimator_set_material(xp.Particles())
7180

7281
def get_backtrack_element(self, _context=None, _buffer=None, _offset=None):
7382
# TODO: this should be an InvalidCollimator
@@ -103,6 +112,13 @@ class EverestCrystal(BaseCollimator):
103112
_pkg_root.joinpath('beam_elements','collimators_src','everest_crystal.h')
104113
]
105114

115+
_per_particle_kernels = {
116+
'_EverestCrystal_set_material': xo.Kernel(
117+
c_name='EverestCrystal_set_material',
118+
args=[]
119+
)
120+
}
121+
106122

107123
def __init__(self, **kwargs):
108124
if '_xobject' not in kwargs:
@@ -122,8 +138,8 @@ def __init__(self, **kwargs):
122138
kwargs.setdefault('rutherford_rng', xt.RandomRutherford())
123139
kwargs.setdefault('_tracking', True)
124140
super().__init__(**kwargs)
125-
# if '_xobject' not in kwargs:
126-
# self.random_generator.set_rutherford_by_xcoll_material(self.material)
141+
if '_xobject' not in kwargs:
142+
self._EverestCrystal_set_material(xp.Particles())
127143

128144
@property
129145
def lattice(self):
@@ -148,7 +164,7 @@ def material(self, material):
148164
if not isinstance(material, dict) or material['__class__'] != "CrystalMaterial":
149165
raise ValueError("Invalid material!")
150166
self._material = material
151-
# self.random_generator.set_rutherford_by_xcoll_material(material)
167+
self._EverestCrystal_set_material(xp.Particles())
152168

153169
def get_backtrack_element(self, _context=None, _buffer=None, _offset=None):
154170
# TODO: this should be an InvalidCollimator
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from .materials import Material, CrystalMaterial
1+
from .materials import GeneralMaterial, Material, CrystalMaterial
22
from .everest import EverestEngine

0 commit comments

Comments
 (0)