コード例 #1
0
def driftTest():
    rl = lc.getReferenceLattice()

    vals = np.zeros((6, 1, 3, 100))
    n = np.zeros((1, 100))

    n[0, :] = [0.1 * x for x in range(100)]
    for j in range(100):
        rl = lc.getReferenceLattice()
        rl.addMarkerDef('IP1')
        rl.addElement(name='IP1', pos=j * 0.1)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1,
                                         trk_element=('IP1', 'ip1'))

        loadValues(vals, 0, j, diff, mad, six2mad)

    return n, vals
コード例 #2
0
def testMatrix():
    rl = lc.getReferenceLattice()
    kick = np.zeros(6)
    rm = np.eye(6)

    vals = np.zeros((6, 6, 3, 100))
    n = np.zeros((6, 100))

    for k in range(6):
        n[k, :] = [0.0001 * (x + 1) for x in range(100)]

    for i in range(6):
        for j in range(100):
            kick = np.zeros(6)
            kick[i] = (j + 1) * 0.0001

            rl.addMatrixDef(name='trkstrt', L=0.0, KICK=kick, RM=rm)
            rl.addElement(name='trkstrt', pos=0)
            rl_s = rl.getLatticeDefinition()

            diff, mad, six2mad = csm.compare('element_test',
                                             nbr_turns,
                                             energy_GeV,
                                             init_coords,
                                             0,
                                             rl_s,
                                             norm='',
                                             verbose=1,
                                             all_files=1)

            loadValues(vals, i, j, diff, mad, six2mad)
    return n, vals
コード例 #3
0
def testKicker():
    rl = lc.getReferenceLattice()

    vals = np.zeros((6, 3, 3, 100))
    n = np.zeros((3, 100))

    n[0, :] = [0.0003 * (x + 1) for x in range(100)]
    for j in range(100):
        rl.addKickerDef(name='trkstrt',
                        HKICK=0.0003 * (j + 1),
                        VKICK=0,
                        L=0,
                        TILT=0)
        rl.addElement(name='trkstrt', pos=0.01)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 0, j, diff, mad, six2mad)

    n[1, :] = [0.0003 * (x + 1) for x in range(100)]
    for j in range(100):
        rl.addKickerDef(name='trkstrt',
                        HKICK=0,
                        VKICK=0.0003 * (j + 1),
                        L=0,
                        TILT=0)
        rl.addElement(name='trkstrt', pos=0.01)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 1, j, diff, mad, six2mad)

    n[2, :] = [np.pi * x / 50 for x in range(100)]
    for j in range(100):
        rl.addKickerDef(name='trkstrt',
                        HKICK=0.003,
                        VKICK=0,
                        L=0,
                        TILT=np.pi * j / 50)
        rl.addElement(name='trkstrt', pos=0.01)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 2, j, diff, mad, six2mad)

    return n, vals
コード例 #4
0
def testSolenoid():
    rl = lc.getReferenceLattice()

    vals = np.zeros((6, 3, 3, 100))
    n = np.zeros((3, 100))

    n[0, :] = [0.1 * x for x in range(100)]
    for j in range(100):

        rl.addSolenoidDef(name='trkstrt', KS=j * 0.1, KSI=0.000001, L=0.0)
        rl.addElement(name='trkstrt', pos=0.0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 0, j, diff, mad, six2mad)

    n[1, :] = [0.01 * x for x in range(100)]
    for j in range(100):
        rl.addSolenoidDef(name='trkstrt', KS=0.000001, KSI=j * 0.01, L=0.0)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 1, j, diff, mad, six2mad)

    n[2, :] = [0.005 * x for x in range(100)]
    for j in range(100):
        rl.addSolenoidDef(name='trkstrt', KS=j * 0.005, KSI=j * 0.005, L=0.0)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 2, j, diff, mad, six2mad)
    return n, vals
コード例 #5
0
def testRFCavity():
    rl = lc.getReferenceLattice()

    vals = np.zeros((6, 3, 3, 100))
    n = np.zeros((3, 100))

    n[0, :] = range(1, 101)
    for j in range(100):

        rl.addRFCavityDef(name='trkstrt',
                          VOLT=j + 1,
                          LAG=0.25,
                          L=0,
                          HARMON=100,
                          FREQ=0)
        rl.addElement(name='trkstrt', pos=0.0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 0, j, diff, mad, six2mad)

    n[1, :] = [0.01 * x for x in range(100)]
    for j in range(100):
        rl.addRFCavityDef(name='trkstrt',
                          VOLT=100,
                          LAG=0.01 * j,
                          L=0,
                          HARMON=100,
                          FREQ=0)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 1, j, diff, mad, six2mad)

    n[2, :] = range(1, 101)
    for j in range(100):
        rl.addRFCavityDef(name='trkstrt',
                          VOLT=100,
                          LAG=0.25,
                          L=0,
                          HARMON=j + 1,
                          FREQ=0)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 2, j, diff, mad, six2mad)

    return n, vals
コード例 #6
0
def testMultipole(orde):
    rl = lc.getReferenceLattice()

    vals = np.zeros((6, 4, 3, 100))
    n = np.zeros((4, 100))

    n[0, :] = [0.001 * x for x in range(1, 101)]
    for j in range(100):
        rl.addMultipoleDef(name='trkstrt',
                           order=orde,
                           KN=(j + 1) * 0.0008,
                           KS=0,
                           TILT=0,
                           THICK=False)
        rl.addElement(name='trkstrt', pos=0.0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 0, j, diff, mad, six2mad)

    n[1, :] = [0.001 * x for x in range(1, 101)]
    for j in range(100):
        rl.addMultipoleDef(name='trkstrt',
                           order=orde,
                           KN=0,
                           KS=(j + 1) * 0.0008,
                           TILT=0,
                           THICK=False)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 1, j, diff, mad, six2mad)

    n[2, :] = [np.pi * 0.02 * x for x in range(100)]
    for j in range(100):
        rl.addMultipoleDef(name='trkstrt',
                           order=orde,
                           KN=0.008,
                           KS=0,
                           TILT=str(0.02 * j) + '*PI',
                           THICK=False)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 2, j, diff, mad, six2mad)

    n[3, :] = [np.pi * 0.02 * x for x in range(100)]
    for j in range(100):
        rl.addMultipoleDef(name='trkstrt',
                           order=orde,
                           KN=0,
                           KS=0.008,
                           TILT=str(0.02 * j) + '*pi',
                           THICK=False)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1)

        loadValues(vals, 3, j, diff, mad, six2mad)

    return n, vals
コード例 #7
0
def testRFMultipole(orde):
    symb = ('', 'd', 'q', 's', 'o')
    rl = lc.getReferenceLattice()

    vals = np.zeros((6, 7, 3, 100))
    n = np.zeros((7, 100))

    n[0, :] = [0.0002 * x for x in range(1, 101)]
    for j in range(100):
        rl.addRFMultipoleDef(name='trkstrt',
                             order=orde,
                             VOLT=0,
                             LAG=0.25,
                             HARMON=0,
                             FREQ=200,
                             TILT=0,
                             KN=0.0002 * (j + 1),
                             KS=0.0,
                             PN=0.0,
                             PS=0.0)
        rl.addElement(name='trkstrt', pos=0.0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1,
                                         trk_element=('trkstrt',
                                                      'trkstrt' + symb[orde]))

        loadValues(vals, 0, j, diff, mad, six2mad)

    n[1, :] = [0.0002 * x for x in range(1, 101)]
    for j in range(100):
        rl.addRFMultipoleDef(name='trkstrt',
                             order=orde,
                             VOLT=0,
                             LAG=0.25,
                             HARMON=0,
                             FREQ=200,
                             TILT=0,
                             KN=0.0,
                             KS=0.0002 * (j + 1),
                             PN=0.0,
                             PS=0.0)
        rl.addElement(name='trkstrt', pos=0.0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1,
                                         trk_element=('trkstrt', 'trkstrt' +
                                                      symb[orde] + 's'))

        loadValues(vals, 1, j, diff, mad, six2mad)

    n[2, :] = [2 * (x + 1) for x in range(100)]
    for j in range(100):
        rl.addRFMultipoleDef(name='trkstrt',
                             order=orde,
                             VOLT=0,
                             LAG=0.25,
                             HARMON=0,
                             FREQ=2 * (j + 1),
                             TILT=0,
                             KN=0.02,
                             KS=0.0,
                             PN=0.0,
                             PS=0.0)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1,
                                         trk_element=('trkstrt',
                                                      'trkstrt' + symb[orde]))

        loadValues(vals, 2, j, diff, mad, six2mad)

    n[3, :] = [x * 0.01 for x in range(100)]
    for j in range(100):
        rl.addRFMultipoleDef(name='trkstrt',
                             order=orde,
                             VOLT=0,
                             LAG=0.25,
                             HARMON=0,
                             FREQ=200,
                             TILT=0,
                             KN=0.02,
                             KS=0.0,
                             PN=0.01 * j,
                             PS=0.0)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1,
                                         trk_element=('trkstrt',
                                                      'trkstrt' + symb[orde]))

        loadValues(vals, 3, j, diff, mad, six2mad)

    n[4, :] = [np.pi * x / 50 for x in range(100)]
    for j in range(100):
        rl.addRFMultipoleDef(name='trkstrt',
                             order=orde,
                             VOLT=0,
                             LAG=0.25,
                             HARMON=0,
                             FREQ=200,
                             TILT=np.pi * j / 50,
                             KN=0.02,
                             KS=0.0,
                             PN=0.0,
                             PS=0.0)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1,
                                         trk_element=('trkstrt',
                                                      'trkstrt' + symb[orde]))

        loadValues(vals, 4, j, diff, mad, six2mad)

    n[5, :] = [np.pi * x / 50 for x in range(100)]
    for j in range(100):
        rl.addRFMultipoleDef(name='trkstrt',
                             order=orde,
                             VOLT=0,
                             LAG=0.25,
                             HARMON=0,
                             FREQ=200,
                             TILT=np.pi * j / 50,
                             KN=0.0,
                             KS=0.02,
                             PN=0.0,
                             PS=0.0)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1,
                                         trk_element=('trkstrt', 'trkstrt' +
                                                      symb[orde] + 's'))

        loadValues(vals, 5, j, diff, mad, six2mad)

    n[6, :] = [0.02 * x for x in range(100)]
    for j in range(100):
        rl.addRFMultipoleDef(name='trkstrt',
                             order=orde,
                             VOLT=0.02 * j,
                             LAG=0.25,
                             HARMON=0,
                             FREQ=200,
                             TILT=0,
                             KN=0.02,
                             KS=0.0,
                             PN=0.0,
                             PS=0.0)
        rl.addElement(name='trkstrt', pos=0)
        rl_s = rl.getLatticeDefinition()

        diff, mad, six2mad = csm.compare('element_test',
                                         nbr_turns,
                                         energy_GeV,
                                         init_coords,
                                         0,
                                         rl_s,
                                         norm='',
                                         verbose=1,
                                         all_files=1,
                                         trk_element=('trkstrt',
                                                      'trkstrt' + symb[orde]))

        loadValues(vals, 6, j, diff, mad, six2mad)

    return n, vals
コード例 #8
0
#          the difference between them respectively
#        - The 4th dimension of vals is for each parameter value
#
# Examples:
#           - vals(1,2,0,5) corresponds to the PX value in MAD-X for the third test case in which the parameter
#             value is n(2,5)
#           - vals(4,0,2,7) corresponds to the difference in T value between MAD-X and MAD-X-transformed SixTrack for
#             the first test case in which the parameter value is n(0,7)
#           - vals(2,1,1,1) corresponds to the Y value in MAD-X-transformed SixTrack for the second test case in which
#             the parameter value is n(1,1)
#

nbr_turns = 1
energy_GeV = 5
init_coords = (0.001, 0.002, 0.003, 0.004, 0.005, 0.01)
rl = lc.getReferenceLattice()
path = os.getcwd()


def loadValues(vals, i, j, diff, mad, six2mad):
    for col_idx in range(6):
        vals[col_idx, i, 0, j] = mad.iloc[0, 2 + col_idx]
        vals[col_idx, i, 1, j] = six2mad.iloc[0, col_idx]
        vals[col_idx, i, 2, j] = diff.iloc[0, col_idx]


def testMultipole(orde):
    rl = lc.getReferenceLattice()

    vals = np.zeros((6, 4, 3, 100))
    n = np.zeros((4, 100))