Skip to content

Commit

Permalink
fixed bug with radiation calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-tomin committed Aug 21, 2019
1 parent 7a4d5f3 commit 7b4466d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 26 deletions.
57 changes: 34 additions & 23 deletions demos/ipython_tutorials/10_thz_source.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -68,7 +68,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -143,7 +143,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -153,7 +153,9 @@
"<Figure size 432x288 with 3 Axes>"
]
},
"metadata": {},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
Expand All @@ -174,7 +176,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -306,7 +308,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -361,16 +363,16 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<ocelot.cpbd.magnetic_lattice.MagneticLattice at 0x1c20e9c5f8>"
"<ocelot.cpbd.magnetic_lattice.MagneticLattice at 0x1a2285a400>"
]
},
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -397,7 +399,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand All @@ -407,7 +409,9 @@
"<Figure size 432x288 with 6 Axes>"
]
},
"metadata": {},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
Expand All @@ -430,7 +434,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand All @@ -447,7 +451,9 @@
"<Figure size 432x288 with 6 Axes>"
]
},
"metadata": {},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
Expand All @@ -460,7 +466,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand All @@ -469,7 +475,7 @@
"0.13000000268772674"
]
},
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -488,7 +494,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -544,15 +550,16 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"n: 299 / 299\n",
"time exec: 386.6375322341919 s\n"
"n: 299 / 299(54900, 300)\n",
"\n",
"time exec: 396.0704689025879 s\n"
]
},
{
Expand All @@ -562,7 +569,9 @@
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
Expand All @@ -584,7 +593,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -594,7 +603,9 @@
"<Figure size 432x288 with 6 Axes>"
]
},
"metadata": {},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
Expand Down Expand Up @@ -627,7 +638,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.6.9"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion ocelot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
general ocelot description
"""

__version__ = '19.06.0'
__version__ = '19.06.1'


__all__ = ['Twiss', 'twiss', "Beam", "Particle", "get_current", "get_envelope", # beam
Expand Down
2 changes: 1 addition & 1 deletion ocelot/rad/radiation_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def p_array_end(self, p_array):
s_fin += np.trapz(np.sqrt(1 + x1 * x1 + y1 * y1), z, axis=0)
#s_fin += np.sum(dz * np.sqrt(1 + x1 * x1 + y1 * y1), axis=0)

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

# ref_path is reference path of the particle with zero initial conditions
# in sake of speed and simplicity we assume that ref_path is equal to path of the beam in average
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='ocelot',
version='19.06.0',
version='19.06.1',
description='Accelerator, radiation and x-ray optics simulation framework',
author='ocelot-collab',
author_email='tomin.sergey@gmail.com',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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]}
29 changes: 29 additions & 0 deletions unit_tests/sr_test/spectrum/spectrum_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,34 @@ def test_segments(lattice, screen, beam, update_ref_values=False):
result6 = check_matrix(screen_segm.Pi, screen_whole.Pi , TOL, assert_info=' Pi - ')
assert check_result(result1 + result2 + result3 + result4 + result5 + result6)


def test_calculate_rad_from_lattice(lattice, screen, beam, update_ref_values=False):
"""calculate_radiation fucntion test"""
und = Undulator(Kx=4., nperiods=125, lperiod=0.04, eid="und")
D = Drift(l=0.5, eid="D")
b1 = Hcor(l=0.1, angle=10 * -0.00001, eid="b1")
b2 = Hcor(l=0.2, angle=10 * 0.00002, eid="b2")
b3 = Hcor(l=0.1, angle=10 * -0.00001, eid="b3")
phase_shift = (b1, b2, b3)
cell = (und, D, phase_shift, D, und)
lattice = MagneticLattice(cell)

screen = calculate_radiation(lattice, screen, beam)

if update_ref_values:
return {'Eph': screen.Eph.tolist(), 'Yph': screen.Yph.tolist(), 'Xph': screen.Xph.tolist(),
'Total': screen.Total.tolist(), 'Sigma': screen.Sigma.tolist(), 'Pi': screen.Pi.tolist()}

screen_ref = json_read(REF_RES_DIR + sys._getframe().f_code.co_name + '.json')

result1 = check_matrix(screen.Eph, screen_ref['Eph'], TOL, assert_info=' Eph - ')
result2 = check_matrix(screen.Yph, screen_ref['Yph'], TOL, assert_info=' Yph - ')
result3 = check_matrix(screen.Xph, screen_ref['Xph'], TOL, assert_info=' Xph - ')
result4 = check_matrix(screen.Total, screen_ref['Total'], TOL, assert_info=' Total - ')
result5 = check_matrix(screen.Sigma, screen_ref['Sigma'], TOL, assert_info=' Sigma - ')
result6 = check_matrix(screen.Pi, screen_ref['Pi'], TOL, assert_info=' Pi - ')
assert check_result(result1 + result2 + result3 + result4 + result5 + result6)

def setup_module(module):

f = open(pytest.TEST_RESULTS_FILE, 'a')
Expand Down Expand Up @@ -129,6 +157,7 @@ def test_update_ref_values(lattice, screen, beam, cmdopt):
update_functions.append('test_calculate_radiation')
update_functions.append("test_calculate_radiation_endpoles")
update_functions.append('test_segments')
update_functions.append("test_calculate_rad_from_lattice")

if cmdopt in update_functions:
result = eval(cmdopt)(lattice, screen, beam, True)
Expand Down

0 comments on commit 7b4466d

Please sign in to comment.