Пример #1
0
def Und(lp, mp, np, cp, lm, mm, nm, cm, gap, gapOffset, numPer):

    zer = [0, 0, 0]
    Grp = rad.ObjCnt([])

    #Principal Poles and Magnets
    #y = lp[1]/4;
    y = 0.25 * lp[1]

    #Pole = rad.ObjFullMag([lp[0]/4,y,-lp[2]/2-gap/2], [lp[0]/2,lp[1]/2,lp[2]], zer, np, Grp, mp, cp)
    Pole = rad.ObjFullMag([0.25 * lp[0], y, -0.5 * (lp[2] + gap)],
                          [0.5 * lp[0], 0.5 * lp[1], lp[2]], zer, np, Grp, mp,
                          cp)
    #y += lp[1]/4;
    y += 0.25 * lp[1]

    mDir = -1
    for i in range(0, numPer):
        initM = [0, mDir, 0]
        mDir *= -1
        #y += lm[1]/2
        y += 0.5 * lm[1]

        #Magnet = rad.ObjFullMag([lm[0]/4,y,-lm[2]/2-gap/2-gapOffset], [lm[0]/2,lm[1],lm[2]], initM, nm, Grp, mm, cm)
        Magnet = rad.ObjFullMag(
            [0.25 * lm[0], y, -0.5 * (lm[2] + gap) - gapOffset],
            [0.5 * lm[0], lm[1], lm[2]], initM, nm, Grp, mm, cm)
        #y += (lm[1] + lp[1])/2
        y += 0.5 * (lm[1] + lp[1])

        #Pole = rad.ObjFullMag([lp[0]/4,y,-lp[2]/2-gap/2], [lp[0]/2,lp[1],lp[2]], zer, np, Grp, mp, cp)
        Pole = rad.ObjFullMag([0.25 * lp[0], y, -0.5 * (lp[2] + gap)],
                              [0.5 * lp[0], lp[1], lp[2]], zer, np, Grp, mp,
                              cp)
        #y += lp[1]/2
        y += 0.5 * lp[1]

    initM = [0, mDir, 0]
    #y += lm[1]/4;
    y += 0.25 * lm[1]

    #Magnet = rad.ObjFullMag([lm[0]/4,y,-lm[2]/2-gap/2-gapOffset], [lm[0]/2,lm[1]/2,lm[2]], initM, nm, Grp, mm, cm)
    Magnet = rad.ObjFullMag(
        [0.25 * lm[0], y, -0.5 * (lm[2] + gap) - gapOffset],
        [0.5 * lm[0], 0.5 * lm[1], lm[2]], initM, nm, Grp, mm, cm)

    #Mirrors
    rad.TrfZerPerp(Grp, [0, 0, 0], [1, 0, 0])
    rad.TrfZerPara(Grp, zer, [0, 0, 1])
    rad.TrfZerPerp(Grp, zer, [0, 1, 0])

    return Grp, Pole, Magnet
Пример #2
0
def Und(lp, mp, np, cp, lm, mm, nm, cm, gap, gapOffset, numPer):

    zer = [0, 0, 0]
    Grp = rad.ObjCnt([])

    #Principal Poles and Magnets
    y = lp[1] / 4
    Pole = rad.ObjFullMag([lp[0] / 4, y, -lp[2] / 2 - gap / 2],
                          [lp[0] / 2, lp[1] / 2, lp[2]], zer, np, Grp, mp, cp)
    y += lp[1] / 4

    mDir = -1
    for i in range(0, numPer):
        initM = [0, mDir, 0]
        mDir *= -1
        y += lm[1] / 2
        Magnet = rad.ObjFullMag(
            [lm[0] / 4, y, -lm[2] / 2 - gap / 2 - gapOffset],
            [lm[0] / 2, lm[1], lm[2]], initM, nm, Grp, mm, cm)
        y += (lm[1] + lp[1]) / 2
        Pole = rad.ObjFullMag([lp[0] / 4, y, -lp[2] / 2 - gap / 2],
                              [lp[0] / 2, lp[1], lp[2]], zer, np, Grp, mp, cp)
        y += lp[1] / 2

    initM = [0, mDir, 0]
    y += lm[1] / 4
    Magnet = rad.ObjFullMag([lm[0] / 4, y, -lm[2] / 2 - gap / 2 - gapOffset],
                            [lm[0] / 2, lm[1] / 2, lm[2]], initM, nm, Grp, mm,
                            cm)

    #Mirrors
    rad.TrfZerPerp(Grp, [0, 0, 0], [1, 0, 0])
    rad.TrfZerPara(Grp, zer, [0, 0, 1])
    rad.TrfZerPerp(Grp, zer, [0, 1, 0])

    return Grp, Pole, Magnet
Пример #3
0
def HybridUndCenPart(_gap,
                     _gap_ofst,
                     _nper,
                     _air,
                     _lp,
                     _ch_p,
                     _np,
                     _np_tip,
                     _mp,
                     _cp,
                     _lm,
                     _ch_m_xz,
                     _ch_m_yz,
                     _ch_m_yz_r,
                     _nm,
                     _mm,
                     _cm,
                     _use_ex_sym=False):
    zer = [0, 0, 0]
    grp = rad.ObjCnt([])

    y = _lp[1] / 4
    initM = [0, -1, 0]

    pole = rad.ObjFullMag([_lp[0] / 4, y, -_lp[2] / 2 - _gap / 2 - _ch_p],
                          [_lp[0] / 2, _lp[1] / 2, _lp[2]], zer,
                          [_np[0], int(_np[1] / 2 + 0.5), _np[2]], grp, _mp,
                          _cp)

    if (_ch_p > 0.):  # Pole Tip
        poleTip = rad.ObjThckPgn(
            _lp[0] / 4, _lp[0] / 2,
            [[y - _lp[1] / 4, -_gap / 2 - _ch_p], [y - _lp[1] / 4, -_gap / 2],
             [y + _lp[1] / 4 - _ch_p, -_gap / 2],
             [y + _lp[1] / 4, -_gap / 2 - _ch_p]], zer)
        rad.ObjDivMag(
            poleTip,
            [_np_tip[0], int(_np_tip[1] / 2 + 0.5), _np_tip[2]])
        rad.MatApl(poleTip, _mp)
        rad.ObjDrwAtr(poleTip, _cp)
        rad.ObjAddToCnt(grp, [poleTip])

    y += _lp[1] / 4 + _air + _lm[1] / 2

    for i in range(_nper):
        magnet = rad.ObjThckPgn(
            _lm[0] / 4, _lm[0] / 2,
            [[y + _lm[1] / 2 - _ch_m_yz_r * _ch_m_yz, -_gap / 2 - _gap_ofst],
             [y + _lm[1] / 2, -_gap / 2 - _gap_ofst - _ch_m_yz],
             [y + _lm[1] / 2, -_gap / 2 - _gap_ofst - _lm[2] + _ch_m_yz],
             [
                 y + _lm[1] / 2 - _ch_m_yz_r * _ch_m_yz,
                 -_gap / 2 - _gap_ofst - _lm[2]
             ],
             [
                 y - _lm[1] / 2 + _ch_m_yz_r * _ch_m_yz,
                 -_gap / 2 - _gap_ofst - _lm[2]
             ], [y - _lm[1] / 2, -_gap / 2 - _gap_ofst - _lm[2] + _ch_m_yz],
             [y - _lm[1] / 2, -_gap / 2 - _gap_ofst - _ch_m_yz],
             [y - _lm[1] / 2 + _ch_m_yz_r * _ch_m_yz, -_gap / 2 - _gap_ofst]],
            initM)
        # Cuting Magnet Corners
        magnet = rad.ObjCutMag(
            magnet, [_lm[0] / 2 - _ch_m_xz, 0, -_gap / 2 - _gap_ofst],
            [1, 0, 1])[0]
        magnet = rad.ObjCutMag(
            magnet, [_lm[0] / 2 - _ch_m_xz, 0, -_gap / 2 - _gap_ofst - _lm[2]],
            [1, 0, -1])[0]

        rad.ObjDivMag(magnet, _nm)
        rad.MatApl(magnet, _mm)
        rad.ObjDrwAtr(magnet, _cm)
        rad.ObjAddToCnt(grp, [magnet])

        initM[1] *= -1
        y += _lm[1] / 2 + _lp[1] / 2 + _air

        if (i < _nper - 1):
            pole = rad.ObjFullMag(
                [_lp[0] / 4, y, -_lp[2] / 2 - _gap / 2 - _ch_p],
                [_lp[0] / 2, _lp[1], _lp[2]], zer, _np, grp, _mp, _cp)

            if (_ch_p > 0.):  # Pole Tip
                poleTip = rad.ObjThckPgn(_lp[0] / 4, _lp[0] / 2,
                                         [[y - _lp[1] / 2, -_gap / 2 - _ch_p],
                                          [y - _lp[1] / 2 + _ch_p, -_gap / 2],
                                          [y + _lp[1] / 2 - _ch_p, -_gap / 2],
                                          [y + _lp[1] / 2, -_gap / 2 - _ch_p]],
                                         zer)
                rad.ObjDivMag(poleTip, _np_tip)
                rad.MatApl(poleTip, _mp)
                rad.ObjDrwAtr(poleTip, _cp)
                rad.ObjAddToCnt(grp, [poleTip])

            y += _lm[1] / 2 + _lp[1] / 2 + _air

    y -= _lp[1] / 4
    pole = rad.ObjFullMag([_lp[0] / 4, y, -_lp[2] / 2 - _gap / 2 - _ch_p],
                          [_lp[0] / 2, _lp[1] / 2, _lp[2]], zer,
                          [_np[0], int(_np[1] / 2 + 0.5), _np[2]], grp, _mp,
                          _cp)
    if (_ch_p > 0.):  # Pole Tip
        poleTip = rad.ObjThckPgn(
            _lp[0] / 4, _lp[0] / 2,
            [[y - _lp[1] / 4, -_gap / 2 - _ch_p],
             [y - _lp[1] / 4 + _ch_p, -_gap / 2], [y + _lp[1] / 4, -_gap / 2],
             [y + _lp[1] / 4, -_gap / 2 - _ch_p]], zer)
        rad.ObjDivMag(
            poleTip,
            [_np_tip[0], int(_np_tip[1] / 2 + 0.5), _np_tip[2]])
        rad.MatApl(poleTip, _mp)
        rad.ObjDrwAtr(poleTip, _cp)
        rad.ObjAddToCnt(grp, [poleTip])

    # Symmetries
    if (
            _use_ex_sym
    ):  # Some "non-physical" mirroring (applicable for calculation of central field only)
        y += _lp[1] / 4
        rad.TrfZerPerp(grp, [0, y, 0], [0, 1, 0])  # Mirror left-right
        rad.TrfZerPerp(grp, [0, 2 * y, 0], [0, 1, 0])

    #     #"Physical" symmetries (applicable also for calculation of total structure with terminations)
    #     rad.TrfZerPerp(grp, zer, [0,1,0]) #Mirror left-right
    #     #Mirror front-back
    #     rad.TrfZerPerp(grp, zer, [1,0,0])
    #     #Mirror top-bottom
    #     rad.TrfZerPara(grp, zer, [0,0,1])

    return grp
Пример #4
0
magBkg = rad.ObjBckg([1,2,3])

mag = rad.ObjCnt([mag00, mag01, mag02, mag03, mag04, mag05, mag06, mag07, mag08, mag09])
print('Container Content:', rad.ObjCntStuf(mag))
print('Container Size:', rad.ObjCntSize(mag))

rad.ObjAddToCnt(mag, [mag10, mag11])
cnt02 = rad.ObjCnt([mag00, mag])

mat = rad.MatLin([1.01, 1.2], [0, 0, 1.3])
#mat = rad.MatStd('NdFeB', 1.2)
rad.MatApl(mag01, mat)
print('Magn. Material index:', mat, ' appled to object:', mag01)

mag00a = rad.ObjFullMag([10,0,40],[12,18,5],[0,0,1],[2,2,2],cnt02,mat,[0.5,0,0])

rad.ObjDrwOpenGL(cnt02)

data_cnt = rad.ObjDrwVTK(cnt02)
print(data_cnt)


objAfterCut = rad.ObjCutMag(mag00a,[10,0,40],[1,1,1]) #,'Frame->Lab')
print('Indexes of objects after cutting:', objAfterCut)
#rad.ObjDrwOpenGL(objAfterCut[0])

print(rad.UtiDmp(mag01, 'asc'))
print(rad.UtiDmp(mat, 'asc'))
#print(rad.UtiDmp(107, 'asc'))
Пример #5
0
    def undulator(
            pole_lengths, pole_props, pole_segs, block_lengths, block_props,
            block_segs, gap_height, gap_offset, num_periods
    ):
        """
        create hybrid undulator magnet
        arguments:
          pole_lengths = [lpx, lpy, lpz] = dimensions of the iron poles (mm)
          pole_props = magnetic properties of the iron poles (M-H curve)
          pole_segs = segmentation of the iron poles
          block_lengths = [lmx, lmy, lmz] = dimensions of the magnet blocks (mm)
          block_props = magnetic properties of the magnet blocks (remanent magnetization)
          block_segs = segmentation of the magnet blocks
          gap_height = undulator gap (mm)
          gap_offset = vertical offset of the magnet blocks w/rt the poles (mm)
          numPer = number of full periods of the undulator magnetic field
        return: Radia representations of
          undulator group, poles, permanent magnets
        """
        zero = [0, 0, 0]

        # colors
        c_pole = [1, 0, 1]
        c_block = [0, 1, 1]

        # full magnet will be assembled into this Radia group
        grp = radia.ObjCnt([])

        # principal poles and magnet blocks in octant(+,+,–)
        # -- half pole
        y = pole_lengths[1] / 4
        pole = radia.ObjFullMag(
            [pole_lengths[0] / 4, y, -pole_lengths[2] / 2 - gap_height / 2],
            [pole_lengths[0] / 2, pole_lengths[1] / 2, pole_lengths[2]],
            zero, pole_segs, grp, pole_props, c_pole
        )
        y += pole_lengths[1] / 4

        # -- magnet and pole pairs
        m_dir = -1
        for i in range(num_periods):
            init_m = [0, m_dir, 0]
            m_dir *= -1
            y += block_lengths[1] / 2
            magnet = radia.ObjFullMag(
                [
                    block_lengths[0] / 4,
                    y,
                    -block_lengths[2] / 2 - gap_height / 2 - gap_offset
                ],
                [
                    block_lengths[0] / 2, block_lengths[1], block_lengths[2]
                ],
                init_m, block_segs, grp, block_props, c_block
            )
            y += (block_lengths[1] + pole_lengths[1]) / 2
            pole = radia.ObjFullMag(
                [pole_lengths[0] / 4, y, -pole_lengths[2] / 2 - gap_height / 2],
                [pole_lengths[0] / 2, pole_lengths[1], pole_lengths[2]],
                zero, pole_segs, grp, pole_props, c_pole
            )
            y += pole_lengths[1] / 2

        # -- end magnet block
        init_m = [0, m_dir, 0]
        y += block_lengths[1] / 4
        magnet = radia.ObjFullMag(
            [
                block_lengths[0] / 4,
                y,
                -block_lengths[2] / 2 - gap_height / 2 - gap_offset
            ],
            [
                block_lengths[0] / 2, block_lengths[1] / 2, block_lengths[2]
            ],
            init_m, block_segs, grp, block_props, c_block)

        # use mirror symmetry to define the full undulator
        radia.TrfZerPerp(grp, zero, [1, 0, 0])  # reflect in the (y,z) plane
        radia.TrfZerPara(grp, zero, [0, 0, 1])  # reflect in the (x,y) plane
        radia.TrfZerPerp(grp, zero, [0, 1, 0])  # reflect in the (z,x) plane

        return grp, pole, magnet
Пример #6
0
def hybrid_undulator(lpx, lpy, lpz, pole_properties, pole_segmentation, pole_color,
                     lmx, lmz, magnet_properties, magnet_segmentation, magnet_color,
                     gap, offset, period, period_number):
    """
    create hybrid undulator magnet
    arguments:
      pole_dimensions = [lpx, lpy, lpz] = dimensions of the iron poles / mm
      pole_properties = magnetic properties of the iron poles (M-H curve)
      pole_separation = segmentation of the iron poles
      pole_color = [r,g,b] = color for the iron poles
      magnet_dimensions = [lmx, lmy, lmz] = dimensions of the magnet blocks / mm
      magnet_properties = magnetic properties of the magnet blocks (remanent magnetization)
      magnet_segmentation = segmentation of the magnet blocks
      magnet_color = [r,g,b] = color for the magnet blocks
      gap = undulator gap / mm
      offset = vertical offset / mm of the magnet blocks w/rt the poles
      period = length of one undulator period / mm
      period_number = number of full periods of the undulator magnetic field
    return: Radia representations of
      undulator group, poles, permanent magnets
    """
    pole_dimensions = [lpx, lpy, lpz]
    lmy = period / 2. - pole_dimensions[1]
    magnet_dimensions = [lmx, lmy, lmz]
    zer = [0, 0, 0]
    # full magnet will be assembled into this Radia group
    grp = rad.ObjCnt([])
    # principal poles and magnet blocks in octant(+,+,–)
    # -- half pole
    y = pole_dimensions[1] / 4
    pole = rad.ObjFullMag([pole_dimensions[0] / 4, y, -pole_dimensions[2] / 2 - gap / 2],
                          [pole_dimensions[0] / 2, pole_dimensions[1] / 2, pole_dimensions[2]],
                          zer, pole_segmentation, grp, pole_properties, pole_color)
    y += pole_dimensions[1] / 4
    # -- magnet and pole pairs
    magnetization_dir = -1
    for i in range(0, period_number):
        init_magnetization = [0, magnetization_dir, 0]
        magnetization_dir *= -1
        y += magnet_dimensions[1] / 2
        magnet = rad.ObjFullMag([magnet_dimensions[0] / 4, y, -magnet_dimensions[2] / 2 - gap / 2 - offset],
                                [magnet_dimensions[0] / 2, magnet_dimensions[1], magnet_dimensions[2]],
                                init_magnetization, magnet_segmentation, grp, magnet_properties, magnet_color)
        y += (magnet_dimensions[1] + pole_dimensions[1]) / 2
        pole = rad.ObjFullMag([pole_dimensions[0] / 4, y, -pole_dimensions[2] / 2 - gap / 2],
                              [pole_dimensions[0] / 2, pole_dimensions[1], pole_dimensions[2]],
                              zer, pole_segmentation, grp, pole_properties, pole_color)
        y += pole_dimensions[1] / 2
    # -- end magnet block
    init_magnetization = [0, magnetization_dir, 0]
    y += magnet_dimensions[1] / 4
    magnet = rad.ObjFullMag([magnet_dimensions[0] / 4, y, -magnet_dimensions[2] / 2 - gap / 2 - offset],
                            [magnet_dimensions[0] / 2, magnet_dimensions[1] / 2, magnet_dimensions[2]],
                            init_magnetization, magnet_segmentation, grp, magnet_properties, magnet_color)
    # use mirror symmetry to define the full undulator
    rad.TrfZerPerp(grp, zer, [1, 0, 0])  # reflect in the (y,z) plane
    rad.TrfZerPara(grp, zer, [0, 0, 1])  # reflect in the (x,y) plane
    rad.TrfZerPerp(grp, zer, [0, 1, 0])  # reflect in the (z,x) plane


    return grp, pole, magnet