Skip to content
Snippets Groups Projects
Commit 6593babf authored by Vadim Gubaidulin's avatar Vadim Gubaidulin
Browse files

Added a test to check the tune shifts from FBT are correct.

parent 93934fb5
No related branches found
1 merge request!32FBT
import h5py as hp
import numpy as np import numpy as np
import pytest import pytest
from nafflib import get_tune
from utility_test_growth_rate import get_growth_beam from utility_test_growth_rate import get_growth_beam
from mbtrack2 import ( from mbtrack2 import (
...@@ -40,10 +42,10 @@ class TestFBTPhys: ...@@ -40,10 +42,10 @@ class TestFBTPhys:
track_alive=False, track_alive=False,
mpi=False) mpi=False)
damping_time = [50, 100] damping_time = [50, 100]
growth_rate = 1 / (damping_time[1] * demo_ring.T0) phase_diff = [-45, -45]
fbt = TransverseExponentialDamper(ring, fbt = TransverseExponentialDamper(ring,
damping_time=damping_time, damping_time=damping_time,
phase_diff=[-90, -90]) phase_diff=phase_diff)
save_every = 1 save_every = 1
bbmon = BeamMonitor(h=ring.h, bbmon = BeamMonitor(h=ring.h,
...@@ -62,6 +64,8 @@ class TestFBTPhys: ...@@ -62,6 +64,8 @@ class TestFBTPhys:
bbmon.close() bbmon.close()
growth_rate = (1 / (damping_time[1] * demo_ring.T0) *
np.cos(np.deg2rad(phase_diff[1])))
path = name + '.hdf5' path = name + '.hdf5'
gr, gr_std = get_growth_beam(ring, path, 1e3, 2e3) gr, gr_std = get_growth_beam(ring, path, 1e3, 2e3)
rel_error = np.abs(growth_rate - gr) * 100 / growth_rate rel_error = np.abs(growth_rate - gr) * 100 / growth_rate
...@@ -69,6 +73,17 @@ class TestFBTPhys: ...@@ -69,6 +73,17 @@ class TestFBTPhys:
print(f"Relative error: {rel_error} % (std: {rel_error_std} %)") print(f"Relative error: {rel_error} % (std: {rel_error_std} %)")
assert rel_error < 5 assert rel_error < 5
with hp.File(name + '.hdf5', 'r') as f:
x = f['Beam']['mean'][0, 0, :]
t = get_tune(x)
np.testing.assert_allclose(
(np.abs(t) - (demo_ring.tune[0] - int(demo_ring.tune[0]))),
np.abs(
np.sin(np.deg2rad(phase_diff[0])) /
(2 * np.pi * damping_time[0])),
rtol=5e-2)
def test_firdamper_growth_rate_chroma0(self, demo_ring, tmp_path): def test_firdamper_growth_rate_chroma0(self, demo_ring, tmp_path):
ring = demo_ring ring = demo_ring
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment