예제 #1
0
    def test_insert_in_modelflame(self):
        latfile = self.testfile
        fm = ModelFlame(latfile)
        r0,s0 = fm.run(to_element=6)
        econf_before_insertion = fm.get_element(index=5)[0]
        total_before_insertion = len(fm.machine)

        new_econf = {'index':5, 'properties':{'name':'test_drift', 'type':'drift', 'L':0.05588}}
        fm.insert_element(econf=new_econf)
        total_after_insertion = len(fm._mach_ins)
        test_econf = fm.get_element(index=5)[0]
        self.assertEqual(test_econf['index'], new_econf['index'])
        self.assertEqual(test_econf['properties']['name'], new_econf['properties']['name'])
        self.assertEqual(test_econf['properties']['type'], new_econf['properties']['type'])
        self.assertEqual(test_econf['properties']['L'], new_econf['properties']['L'])
        self.assertEqual(total_before_insertion+1, total_after_insertion)

        test_econf2 = fm.get_element(index=6)[0]
        self.assertEqual(test_econf2['index'], 6)
        self.assertEqual(test_econf2['properties']['name'], econf_before_insertion['properties']['name'])
        self.assertEqual(test_econf2['properties']['type'], econf_before_insertion['properties']['type'])

        r1,s1 = fm.run(to_element=6)

        compare_mstates(self, s0, s1)
예제 #2
0
    def test_generate_source(self):
        latfile = self.testfile
        fm = ModelFlame(latfile)
        ms = fm.bmstate
        sconf = generate_source(ms)
        sconf0 = fm.get_element(type='source')[0]
        compare_source_element(self, sconf, sconf0)

        r0, s0 = fm.run(monitor=range(len(fm.machine)))
        fm.configure(sconf)
        r, s = fm.run(monitor=range(len(fm.machine)))
        compare_mstates(self, s, s0)

        rs0 = [ts for (ti,ts) in r0]
        rs = [ts for (ti,ts) in r]
        for (is1, is2) in zip(rs0, rs):
            compare_mstates(self, is1, is2)
예제 #3
0
    def test_configure(self):
        latfile = self.testfile
        with open(latfile, 'rb') as f:
            m0 = Machine(f)
        s0 = m0.allocState({})
        e_cor_idx = 10
        m0.reconfigure(10, {'theta_x': 0.005})
        r0 = m0.propagate(s0, 0, len(m0), range(len(m0)))

        fm = ModelFlame(latfile)
        e = fm.get_element(index=10)[0]
        e['properties']['theta_x'] = 0.005
        fm.configure(e)
        r, s = fm.run(monitor=range(len(m0)))

        rs0 = [ts for (ti,ts) in r0]
        rs = [ts for (ti,ts) in r]
        for (is1, is2) in zip(rs0, rs):
            compare_mstates(self, is1, is2)
예제 #4
0
from math import sqrt

from flame import Machine

from flame_utils import generate_latfile
from flame_utils import BeamState
from flame_utils import ModelFlame

import logging
logging.getLogger('flame.machine').disabled = True

import ray

latfile = 'fitSolscan_20180430.lat'
fm = ModelFlame(latfile)
sols = fm.get_element(type='solenoid')
r, s = fm.run(monitor=-1)
refbg = s.bg[0]
refbg
[
    s.moment0_rms[0], s.moment0_rms[2],
    s.moment1[0, 2, 0] / s.moment0_rms[0] / s.moment0_rms[2]
]


def get_m1_mat(emitx, betax, alphax, emity, betay, alphay, cxy, cxyp, cyxp,
               cxpyp):
    emitx = emitx / 1e6
    emity = emity / 1e6
    m1_mat = np.eye(4)
    gammax = (1 + alphax * alphax) / betax