Skip to content

Commit 7b4466d

Browse files
committed
fixed bug with radiation calculation
1 parent 7a4d5f3 commit 7b4466d

File tree

6 files changed

+67
-26
lines changed

6 files changed

+67
-26
lines changed

demos/ipython_tutorials/10_thz_source.ipynb

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
{
5151
"cell_type": "code",
52-
"execution_count": 1,
52+
"execution_count": 2,
5353
"metadata": {},
5454
"outputs": [
5555
{
@@ -68,7 +68,7 @@
6868
},
6969
{
7070
"cell_type": "code",
71-
"execution_count": 2,
71+
"execution_count": 3,
7272
"metadata": {},
7373
"outputs": [],
7474
"source": [
@@ -143,7 +143,7 @@
143143
},
144144
{
145145
"cell_type": "code",
146-
"execution_count": 3,
146+
"execution_count": 4,
147147
"metadata": {},
148148
"outputs": [
149149
{
@@ -153,7 +153,9 @@
153153
"<Figure size 432x288 with 3 Axes>"
154154
]
155155
},
156-
"metadata": {},
156+
"metadata": {
157+
"needs_background": "light"
158+
},
157159
"output_type": "display_data"
158160
}
159161
],
@@ -174,7 +176,7 @@
174176
},
175177
{
176178
"cell_type": "code",
177-
"execution_count": 4,
179+
"execution_count": 5,
178180
"metadata": {},
179181
"outputs": [
180182
{
@@ -306,7 +308,7 @@
306308
},
307309
{
308310
"cell_type": "code",
309-
"execution_count": 5,
311+
"execution_count": 6,
310312
"metadata": {},
311313
"outputs": [
312314
{
@@ -361,16 +363,16 @@
361363
},
362364
{
363365
"cell_type": "code",
364-
"execution_count": 6,
366+
"execution_count": 7,
365367
"metadata": {},
366368
"outputs": [
367369
{
368370
"data": {
369371
"text/plain": [
370-
"<ocelot.cpbd.magnetic_lattice.MagneticLattice at 0x1c20e9c5f8>"
372+
"<ocelot.cpbd.magnetic_lattice.MagneticLattice at 0x1a2285a400>"
371373
]
372374
},
373-
"execution_count": 6,
375+
"execution_count": 7,
374376
"metadata": {},
375377
"output_type": "execute_result"
376378
}
@@ -397,7 +399,7 @@
397399
},
398400
{
399401
"cell_type": "code",
400-
"execution_count": 7,
402+
"execution_count": 8,
401403
"metadata": {},
402404
"outputs": [
403405
{
@@ -407,7 +409,9 @@
407409
"<Figure size 432x288 with 6 Axes>"
408410
]
409411
},
410-
"metadata": {},
412+
"metadata": {
413+
"needs_background": "light"
414+
},
411415
"output_type": "display_data"
412416
}
413417
],
@@ -430,7 +434,7 @@
430434
},
431435
{
432436
"cell_type": "code",
433-
"execution_count": 8,
437+
"execution_count": 9,
434438
"metadata": {},
435439
"outputs": [
436440
{
@@ -447,7 +451,9 @@
447451
"<Figure size 432x288 with 6 Axes>"
448452
]
449453
},
450-
"metadata": {},
454+
"metadata": {
455+
"needs_background": "light"
456+
},
451457
"output_type": "display_data"
452458
}
453459
],
@@ -460,7 +466,7 @@
460466
},
461467
{
462468
"cell_type": "code",
463-
"execution_count": 9,
469+
"execution_count": 10,
464470
"metadata": {},
465471
"outputs": [
466472
{
@@ -469,7 +475,7 @@
469475
"0.13000000268772674"
470476
]
471477
},
472-
"execution_count": 9,
478+
"execution_count": 10,
473479
"metadata": {},
474480
"output_type": "execute_result"
475481
}
@@ -488,7 +494,7 @@
488494
},
489495
{
490496
"cell_type": "code",
491-
"execution_count": 10,
497+
"execution_count": 11,
492498
"metadata": {},
493499
"outputs": [
494500
{
@@ -544,15 +550,16 @@
544550
},
545551
{
546552
"cell_type": "code",
547-
"execution_count": 11,
553+
"execution_count": 12,
548554
"metadata": {},
549555
"outputs": [
550556
{
551557
"name": "stdout",
552558
"output_type": "stream",
553559
"text": [
554-
"n: 299 / 299\n",
555-
"time exec: 386.6375322341919 s\n"
560+
"n: 299 / 299(54900, 300)\n",
561+
"\n",
562+
"time exec: 396.0704689025879 s\n"
556563
]
557564
},
558565
{
@@ -562,7 +569,9 @@
562569
"<Figure size 432x288 with 1 Axes>"
563570
]
564571
},
565-
"metadata": {},
572+
"metadata": {
573+
"needs_background": "light"
574+
},
566575
"output_type": "display_data"
567576
}
568577
],
@@ -584,7 +593,7 @@
584593
},
585594
{
586595
"cell_type": "code",
587-
"execution_count": 12,
596+
"execution_count": 13,
588597
"metadata": {},
589598
"outputs": [
590599
{
@@ -594,7 +603,9 @@
594603
"<Figure size 432x288 with 6 Axes>"
595604
]
596605
},
597-
"metadata": {},
606+
"metadata": {
607+
"needs_background": "light"
608+
},
598609
"output_type": "display_data"
599610
}
600611
],
@@ -627,7 +638,7 @@
627638
"name": "python",
628639
"nbconvert_exporter": "python",
629640
"pygments_lexer": "ipython3",
630-
"version": "3.6.8"
641+
"version": "3.6.9"
631642
}
632643
},
633644
"nbformat": 4,

ocelot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
general ocelot description
33
"""
44

5-
__version__ = '19.06.0'
5+
__version__ = '19.06.1'
66

77

88
__all__ = ['Twiss', 'twiss', "Beam", "Particle", "get_current", "get_envelope", # beam

ocelot/rad/radiation_py.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def p_array_end(self, p_array):
119119
s_fin += np.trapz(np.sqrt(1 + x1 * x1 + y1 * y1), z, axis=0)
120120
#s_fin += np.sum(dz * np.sqrt(1 + x1 * x1 + y1 * y1), axis=0)
121121

122-
N = int(np.shape(self.U)[1] / 9)
122+
N = int(np.shape(self.U[-1])[0] / 9)
123123

124124
# ref_path is reference path of the particle with zero initial conditions
125125
# in sake of speed and simplicity we assume that ref_path is equal to path of the beam in average

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='ocelot',
13-
version='19.06.0',
13+
version='19.06.1',
1414
description='Accelerator, radiation and x-ray optics simulation framework',
1515
author='ocelot-collab',
1616
author_email='tomin.sergey@gmail.com',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Eph": [7300.0, 7306.0, 7312.0, 7318.0, 7324.0, 7330.0, 7336.0, 7342.0, 7348.0, 7354.0, 7360.0, 7366.0, 7372.0, 7378.0, 7384.0, 7390.0, 7396.0, 7402.0, 7408.0, 7414.0, 7420.0, 7426.0, 7432.0, 7438.0, 7444.0, 7450.0, 7456.0, 7462.0, 7468.0, 7474.0, 7480.0, 7486.0, 7492.0, 7498.0, 7504.0, 7510.0, 7516.0, 7522.0, 7528.0, 7534.0, 7540.0, 7546.0, 7552.0, 7558.0, 7564.0, 7570.0, 7576.0, 7582.0, 7588.0, 7594.0, 7600.0, 7606.0, 7612.0, 7618.0, 7624.0, 7630.0, 7636.0, 7642.0, 7648.0, 7654.0, 7660.0, 7666.0, 7672.0, 7678.0, 7684.0, 7690.0, 7696.0, 7702.0, 7708.0, 7714.0, 7720.0, 7726.0, 7732.0, 7738.0, 7744.0, 7750.0, 7756.0, 7762.0, 7768.0, 7774.0, 7780.0, 7786.0, 7792.0, 7798.0, 7804.0, 7810.0, 7816.0, 7822.0, 7828.0, 7834.0, 7840.0, 7846.0, 7852.0, 7858.0, 7864.0, 7870.0, 7876.0, 7882.0, 7888.0, 7894.0, 7900.0], "Yph": [0.0], "Xph": [0.0], "Total": [4965812.581587954, 2998841.109891502, 11787835.98587464, 298265087.5069799, 2327851.2697966374, 168813936.40602818, 45244899.756761245, 879177650.8295974, 23999499.062793512, 2190286235.7589483, 2191762518.016143, 16014900.911433132, 5750005462.294189, 1474228532.0286827, 2586264443.8323274, 10399971.879080467, 69071295244.82536, 3850185683.0992584, 39447666890.75821, 573685298599.2915, 13987687251944.893, 11080289818.206564, 53633935970.917046, 104857368698.04193, 57936625.190445155, 32350977409.190163, 672801960.7092737, 4262436997.954386, 1329218885.9331353, 13840028295.464958, 2710236574.959064, 517033317.6076588, 7903795050.902946, 758162533.9413148, 38579159.776483044, 18883954.7376785, 5034268491.334858, 12497237.832474848, 1818587755.6996317, 1071122545.8025651, 360668178.25864923, 383656420.17573404, 691923401.4507036, 764550322.23979, 5830474.684086184, 1268372703.3584769, 5851894.944713588, 8718715.393377848, 97249797.3684463, 385275329.4594506, 9703503.466236707, 47352046.12660074, 96113302.44107312, 2481164.519016537, 2733856.545428767, 58035.2476351903, 18355382.199228413, 176214.49061916835, 189438977.9016144, 82766583.656267, 2912812.150833717, 394494046.0360039, 537426383.7755413, 220979210.38309327, 111958030.73756135, 5315500274.103144, 2189482.413896284, 1511863133.2094362, 1602292991.4484494, 10873483857.024893, 237759260.88234735, 26986249345.384884, 70897915321.89253, 1401824837.6016645, 952287750225.2667, 785179052933.6433, 132751413212.94615, 1814895825.9207573, 129290303111.14256, 5845982526.91607, 3784208208.250656, 17969609513.77367, 7164502202.941192, 91796416.70275374, 1664946309.4817839, 13001324868.106226, 1376266.6537445448, 5346216252.01655, 667556382.2308999, 1306075316.770011, 503128599.14706546, 3303495638.7348175, 1325434027.5290344, 71648773.92089504, 2909222335.581498, 106196257.38728566, 2880149.5436927434, 18001008.948414747, 1916829543.569004, 19343347.311283294, 470135364.28821707], "Sigma": [4965812.581587954, 2998841.109891502, 11787835.98587464, 298265087.5069799, 2327851.2697966374, 168813936.40602818, 45244899.756761245, 879177650.8295974, 23999499.062793512, 2190286235.7589483, 2191762518.016143, 16014900.911433132, 5750005462.294189, 1474228532.0286827, 2586264443.8323274, 10399971.879080467, 69071295244.82536, 3850185683.0992584, 39447666890.75821, 573685298599.2915, 13987687251944.893, 11080289818.206564, 53633935970.917046, 104857368698.04193, 57936625.190445155, 32350977409.190163, 672801960.7092737, 4262436997.954386, 1329218885.9331353, 13840028295.464958, 2710236574.959064, 517033317.6076588, 7903795050.902946, 758162533.9413148, 38579159.776483044, 18883954.7376785, 5034268491.334858, 12497237.832474848, 1818587755.6996317, 1071122545.8025651, 360668178.25864923, 383656420.17573404, 691923401.4507036, 764550322.23979, 5830474.684086184, 1268372703.3584769, 5851894.944713588, 8718715.393377848, 97249797.3684463, 385275329.4594506, 9703503.466236707, 47352046.12660074, 96113302.44107312, 2481164.519016537, 2733856.545428767, 58035.2476351903, 18355382.199228413, 176214.49061916835, 189438977.9016144, 82766583.656267, 2912812.150833717, 394494046.0360039, 537426383.7755413, 220979210.38309327, 111958030.73756135, 5315500274.103144, 2189482.413896284, 1511863133.2094362, 1602292991.4484494, 10873483857.024893, 237759260.88234735, 26986249345.384884, 70897915321.89253, 1401824837.6016645, 952287750225.2667, 785179052933.6433, 132751413212.94615, 1814895825.9207573, 129290303111.14256, 5845982526.91607, 3784208208.250656, 17969609513.77367, 7164502202.941192, 91796416.70275374, 1664946309.4817839, 13001324868.106226, 1376266.6537445448, 5346216252.01655, 667556382.2308999, 1306075316.770011, 503128599.14706546, 3303495638.7348175, 1325434027.5290344, 71648773.92089504, 2909222335.581498, 106196257.38728566, 2880149.5436927434, 18001008.948414747, 1916829543.569004, 19343347.311283294, 470135364.28821707], "Pi": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}

unit_tests/sr_test/spectrum/spectrum_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ def test_segments(lattice, screen, beam, update_ref_values=False):
9393
result6 = check_matrix(screen_segm.Pi, screen_whole.Pi , TOL, assert_info=' Pi - ')
9494
assert check_result(result1 + result2 + result3 + result4 + result5 + result6)
9595

96+
97+
def test_calculate_rad_from_lattice(lattice, screen, beam, update_ref_values=False):
98+
"""calculate_radiation fucntion test"""
99+
und = Undulator(Kx=4., nperiods=125, lperiod=0.04, eid="und")
100+
D = Drift(l=0.5, eid="D")
101+
b1 = Hcor(l=0.1, angle=10 * -0.00001, eid="b1")
102+
b2 = Hcor(l=0.2, angle=10 * 0.00002, eid="b2")
103+
b3 = Hcor(l=0.1, angle=10 * -0.00001, eid="b3")
104+
phase_shift = (b1, b2, b3)
105+
cell = (und, D, phase_shift, D, und)
106+
lattice = MagneticLattice(cell)
107+
108+
screen = calculate_radiation(lattice, screen, beam)
109+
110+
if update_ref_values:
111+
return {'Eph': screen.Eph.tolist(), 'Yph': screen.Yph.tolist(), 'Xph': screen.Xph.tolist(),
112+
'Total': screen.Total.tolist(), 'Sigma': screen.Sigma.tolist(), 'Pi': screen.Pi.tolist()}
113+
114+
screen_ref = json_read(REF_RES_DIR + sys._getframe().f_code.co_name + '.json')
115+
116+
result1 = check_matrix(screen.Eph, screen_ref['Eph'], TOL, assert_info=' Eph - ')
117+
result2 = check_matrix(screen.Yph, screen_ref['Yph'], TOL, assert_info=' Yph - ')
118+
result3 = check_matrix(screen.Xph, screen_ref['Xph'], TOL, assert_info=' Xph - ')
119+
result4 = check_matrix(screen.Total, screen_ref['Total'], TOL, assert_info=' Total - ')
120+
result5 = check_matrix(screen.Sigma, screen_ref['Sigma'], TOL, assert_info=' Sigma - ')
121+
result6 = check_matrix(screen.Pi, screen_ref['Pi'], TOL, assert_info=' Pi - ')
122+
assert check_result(result1 + result2 + result3 + result4 + result5 + result6)
123+
96124
def setup_module(module):
97125

98126
f = open(pytest.TEST_RESULTS_FILE, 'a')
@@ -129,6 +157,7 @@ def test_update_ref_values(lattice, screen, beam, cmdopt):
129157
update_functions.append('test_calculate_radiation')
130158
update_functions.append("test_calculate_radiation_endpoles")
131159
update_functions.append('test_segments')
160+
update_functions.append("test_calculate_rad_from_lattice")
132161

133162
if cmdopt in update_functions:
134163
result = eval(cmdopt)(lattice, screen, beam, True)

0 commit comments

Comments
 (0)