Skip to content

Commit be1fd99

Browse files
committed
Added tests for the lhcquad and lhcdipole fields
1 parent d8647ba commit be1fd99

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

01_element/lhcdipole.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
d1: drift, l=1*m, aper1=3*cm;
2+
b1: sbend, magnetGeometryType="lhcleft", l=1*m, aper1=3*cm, angle=-0.5;
3+
d2: drift, l=1*m, aper1=3*cm;
4+
5+
l0 : line = (d1,b1,d2);
6+
7+
use, period=l0;
8+
9+
sample, all;
10+
11+
beam, particle="proton",
12+
energy=7*TeV,
13+
X0={{ X0 }}*cm,
14+
Y0={{ Y0 }}*cm;
15+
16+
sampler: samplerplacement, z=5*m, aper1=5*m, aper2=5*m, shape="rectangular", partID={2212};

01_element/lhcquadrupole.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
d1: drift, l=1*m, aper1=3*cm;
2+
q1: quadrupole, magnetGeometryType="lhcleft", l=1*m, aper1=3*cm, k1=1;
3+
d2: drift, l=1*m, aper1=3*cm;
4+
5+
l0 : line = (d1,q1,d2);
6+
7+
use, period=l0;
8+
9+
sample, all;
10+
11+
beam, particle="proton",
12+
energy=7*TeV,
13+
X0={{ X0 }}*cm,
14+
Y0={{ Y0 }}*cm;
15+
16+
sampler: samplerplacement, z=5*m, aper1=5*m, aper2=5*m, shape="rectangular", partID={2212};

01_element/test_lhcdipole.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pytest
2+
import pybdsim
3+
import os
4+
5+
def test() :
6+
7+
os.chdir(os.path.dirname(__file__))
8+
9+
base_name = "lhcdipole"
10+
template_name = base_name+".tpl"
11+
gmad_name = base_name+".gmad"
12+
root_name = base_name+".root"
13+
14+
# check field in primary aperture,
15+
# secondary aperture and outside of the secondary aperture (yoke)
16+
listX0 = [0,19.4,19.4]
17+
listY0 = [0,0,4]
18+
listAssert = [1.9062219,-0.1165236,-0.1521038]
19+
20+
for i in range(len(listAssert)):
21+
22+
X0,Y0,assertion = listX0[i],listY0[i],listAssert[i]
23+
24+
data = {
25+
'X0': str(X0),
26+
'Y0': str(Y0),
27+
}
28+
29+
pybdsim.Run.RenderGmadJinjaTemplate(template_name,gmad_name,data)
30+
pybdsim.Run.Bdsim(gmad_name,base_name,ngenerate=1,seed=1)
31+
32+
d = pybdsim.DataPandas.BDSIMOutput(root_name)
33+
s = d.get_sampler("sampler.")
34+
35+
assert(s['x'][0] == pytest.approx(assertion))

01_element/test_lhcquadrupole.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pytest
2+
import pybdsim
3+
import os
4+
5+
def test() :
6+
7+
os.chdir(os.path.dirname(__file__))
8+
9+
base_name = "lhcquadrupole"
10+
template_name = base_name+".tpl"
11+
gmad_name = base_name+".gmad"
12+
root_name = base_name+".root"
13+
14+
# check field along diagonal in primary aperture,
15+
# secondary aperture and outside of the secondary aperture (yoke)
16+
listX0 = [1,20.4,23.4]
17+
listY0 = [1,1,4]
18+
listAssert = [-0.0198441,0.1741561,0.2050054]
19+
20+
for i in range(len(listAssert)):
21+
22+
X0,Y0,assertion = listX0[i],listY0[i],listAssert[i]
23+
24+
data = {
25+
'X0': str(X0),
26+
'Y0': str(Y0),
27+
}
28+
29+
pybdsim.Run.RenderGmadJinjaTemplate(template_name,gmad_name,data)
30+
pybdsim.Run.Bdsim(gmad_name,base_name,ngenerate=1,seed=1)
31+
32+
d = pybdsim.DataPandas.BDSIMOutput(root_name)
33+
s = d.get_sampler("sampler.")
34+
35+
assert(s['x'][0] == pytest.approx(assertion))

0 commit comments

Comments
 (0)