def draw(radia_object):
    if radia_object is None:
        return False

    _rad.ObjDrwAtr(radia_object, [0, 0.5, 1], 0.001)
    _rad.ObjDrwOpenGL(radia_object)
    return True
Beispiel #2
0
        allSlicePgns.append([slicePgn, z])
        z += dz
    allSlicePgns.append([[[0., 0.]], _r])
    return rad.ObjMltExtPgn(allSlicePgns, _M)


#*********************************Entry point
if __name__ == "__main__":

    #Build the Geometry
    aSpherMag = SphericalVolume(1, 15, 15, [1, 0, 0])
    #Apply Color to it
    rad.ObjDrwAtr(aSpherMag, [0, 0.5, 0.8])

    #Display the Geometry in 3D Viewer
    rad.ObjDrwOpenGL(aSpherMag)

    #Calculate Magnetic Field
    print('Field in the Center = ', rad.Fld(aSpherMag, 'b', [0, 0, 0]))

    #Horizontal Field vs Longitudinal Position
    yMin = -0.99
    yMax = 0.99
    ny = 301
    yStep = (yMax - yMin) / (ny - 1)
    BxVsY = rad.Fld(aSpherMag, 'bx',
                    [[0, yMin + i * yStep, 0] for i in range(ny)])

    #Plot the Results
    uti_plot1d(
        BxVsY, [yMin, yMax, ny],
Beispiel #3
0
        rad.FldInt(g, 'inf', 'ibz', [xMin + ix * xStep, -300., zc],
                   [xMin + ix * xStep, 300., zc]) for ix in range(nx)
    ]

    return BzVsY, [yMin, yMax, ny], IBzVsX, [xMin, xMax, nx]


#*********************************Entry point
if __name__ == "__main__":

    #Build the Geometry
    g = BuildGeometry()
    print('SCW Geometry Index:', g)

    #Display the Geometry in 3D Viewer
    rad.ObjDrwOpenGL(g)

    #Calculate Magnetic Field
    BzVsY, MeshY, IBzVsX, MeshX = CalcField(g)

    print('Field in Center:', BzVsY[0], 'T')
    print('Field Integral in Center:', IBzVsX[0], 'T.mm')

    #Plot the Results
    uti_plot.uti_plot1d(
        BzVsY, MeshY,
        ['Longitudinal Position [mm]', 'Bz [T]', 'Vertical Magnetic Field'])
    uti_plot.uti_plot1d(IBzVsX, MeshX, [
        'Horizontal Position [mm]', 'Integral of Bz [T.mm]',
        'Vertical Magnetic Field Integral'
    ])
Beispiel #4
0
    #ll = per/2 - lp[1]
    ll = 0.5 * per - lp[1]

    #Magnet Parameters
    lm = [65, ll, 45]
    nm = [1, 3, 1]
    cm = [0, 1, 1]

    #Magnetic Materials
    mp, mm = Materials()

    #Build the Structure
    und, pole, magnet = Und(lp, mp, np, cp, lm, mm, nm, cm, gap, gapOffset,
                            numPer)
    #Show the Structure in 3D Viewer
    rad.ObjDrwOpenGL(und)

    #Solve the Magnetization Problem
    t0 = time.time()
    res = rad.Solve(und, 0.0003, 1000)
    print('Solved for Magnetization in', round(time.time() - t0, 2), 's')
    print('Relaxation Results:', res)
    print('Peak Magnetic Field:', round(rad.Fld(und, 'bz', [0, 0, 0]), 5), 'T')

    #Calculate Magnetic Field
    BzVsY, MeshY = CalcField(und, per, numPer)

    #Extracting Characteristics of Magnetic Materials
    MeshH_Pole = [-0.002, 0.002, 201]
    M_Pole = GetMagnMaterCompMvsH(MeshH_Pole, pole, 'x', 'x')
    MeshH_Mag = [-1, 1, 201]
                           _lp=lp,
                           _ch_p=chPole,
                           _np=np,
                           _np_tip=npTip,
                           _mp=mp,
                           _cp=cp,
                           _lm=lm,
                           _ch_m_xz=chMagXZ,
                           _ch_m_yz=chMagYZ,
                           _ch_m_yz_r=chMagYZrat,
                           _nm=nm,
                           _mm=mm,
                           _cm=cm)

    #Display the Geometry
    if (rank <= 0): rad.ObjDrwOpenGL(grp)

    #Construct Interaction Matrix
    t0 = time.time()
    IM = rad.RlxPre(grp)
    if (rank <= 0):
        print('Interaction Matrix was set up in:', round(time.time() - t0, 2),
              's')

    #Perform the Relaxation
    t0 = time.time()
    res = rad.RlxAuto(IM, 0.001, 5000)
    if (rank <= 0):
        print('Relaxation took:', round(time.time() - t0, 2), 's')
        print('Relaxation Results:', res)
Beispiel #6
0
if __name__ == '__main__':

    test_hyper_params = parameters.model_parameters(
        Mova=0,
        periods=8,
        periodlength=65,
        nominal_fmagnet_dimensions=[30.0, 0.0, 30.0],
        M=1.3,
        #nominal_cmagnet_dimensions = [10.0,0.0,15.0],
        nominal_vcmagnet_dimensions=[7.5, 0.0, 12.5],
        nominal_hcmagnet_dimensions=[7.5, 0.0, 15.0],
        compappleseparation=15,
        apple_clampcut=5.0,
        comp_magnet_chamfer=[3.0, 0.0, 3.0],
        magnets_per_period=4,
        gap=10,
        rowshift=0,
        shiftmode='circular',
        rowtorowgap=1.0,
    )
    id_10eV = id.compensatedAPPLEv2(test_hyper_params)
    #
    case1 = af.CaseSolution(id_10eV)
    case1.calculate_B_field()
    print(case1.bmax)
    rd.ObjDrwOpenGL(id_10eV.cont.radobj)
    plt.plot(case1.bfield[:, 0], case1.bfield[:, 1], case1.bfield[:, 3])
    plt.show()
    print(1)
Beispiel #7
0
        periods=10,
        periodlength=15,
        block_subdivision=[1, 1, 1],
        nominal_fmagnet_dimensions=[15.0, 0.0, 15.0],
        nominal_cmagnet_dimensions=[10.0, 0.0, 7.5],
        compappleseparation=7.5,
        apple_clampcut=3.0,
        comp_magnet_chamfer=[3.0, 0.0, 3.0],
        magnets_per_period=4,
        gap=2,
        rowshift=0,
        shiftmode='circular')
    a = compensatedAPPLEv2(testparams)

    #draw object
    rd.ObjDrwOpenGL(a.cont.radobj)

    #solve object
    a.cont.wradSolve()

    #calculate field at a point
    aa = rd.Fld(a.cont.radobj, 'bxbybz', [0, 0, 10])

    #define line start and end points
    linestart = [0, -60, 0]
    lineend = [0, 60, 0]

    #calculate field on a line
    bb = rd.FldLst(a.cont.radobj, 'bxbybz', linestart, lineend,
                   int(1 + (lineend[1] - linestart[1]) / 0.1), 'arg',
                   linestart[1])
Beispiel #8
0
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'))

magDpl = rad.ObjDpl(mag, 'FreeSym->False')
Beispiel #9
0
    e = appleComplete(AII)

    f = compensatedAppleComplete(AII)

    #comp upper beam
    #    f = compUpperBeam(AII)

    #    rd.ObjDrwOpenGL(f.radobj)
    #comp lower beam

    #rota = rd.TrfRot([0,0,0],[1,1,1],np.pi/7.0)
    #    rd.ObjDrwOpenGL(c.radobj)
    #    rd.ObjDrwOpenGL(d.radobj)
    #    rd.ObjDrwOpenGL(e.radobj)
    rd.ObjDrwOpenGL(f.radobj)
    #EXAMPLES OF TRANSFORMATIONS
    #b.wradRotate([0,0,0],[1,0,0],np.pi)

    #b.wradTranslate([10,20,30])

    #b.wradReflect([0,0,0], [4,1,1])

    #Lower APPLE BEAM

    #my apple model
    print(AII.origin)
    print(b.objectlist)

    #rd.ObjDrwOpenGL(a.radobj)
    #rd.ObjDrwOpenGL(b.radobj)
Beispiel #10
0
    def build(self):
        """Create a quadrupole with the given geometry."""
        if self.solve_state < SolveState.SHAPES:
            self.define_shapes()

        rad.UtiDelAll()
        origin = [0, 0, 0]
        nx = [1, 0, 0]
        ny = [0, 1, 0]
        nz = [0, 0, 1]

        tip_mesh = round(self.min_mesh)
        pole_mesh = round(self.min_mesh * self.pole_mult)
        yoke_mesh = round(self.min_mesh * self.yoke_mult)

        length = self.length

        # Subdivide the pole tip cylindrically. The axis is where the edge of the tapered pole meets the Y-axis.
        points = rotate45(self.tip_points)
        x2, y2 = points[-2]  # top right of pole
        x3, y3 = points[-3]  # bottom right of pole
        m = (y2 - y3) / (x2 - x3)
        c = y2 - m * x2
        pole_tip = rad.ObjThckPgn(length / 2, length, points, "z")
        # Slice off the chamfer (note the indexing at the end here - selects the pole not the cut-off piece)
        pole_tip = rad.ObjCutMag(pole_tip, [length - self.chamfer, 0, self.r], [1, 0, -1])[0]
        n_div = max(1, round(math.sqrt((x2 - x3) ** 2 + (y2 - y3) ** 2) / pole_mesh))
        # We have to specify the q values here (second element of each sublist in the subdivision argument)
        # otherwise weird things happen
        mesh = [[n_div, 4], [tip_mesh / 3, 1], [tip_mesh, 1]]
        div_opts = 'Frame->Lab;kxkykz->Size'
        # rad.ObjDivMag(pole_tip, [[tip_mesh, 1], [tip_mesh, 1], [tip_mesh, 3]], div_opts)
        rad.ObjDivMag(pole_tip, mesh, "cyl", [[[0, c, 0], nz], nx, 1], div_opts)
        rad.TrfOrnt(pole_tip, rad.TrfRot(origin, nz, -math.pi / 4))

        pole = rad.ObjThckPgn(length / 2, length, rotate45(self.pole_points), "z")
        rad.ObjDivMag(pole, [pole_mesh, ] * 3, div_opts)
        rad.TrfOrnt(pole, rad.TrfRot(origin, nz, -math.pi / 4))

        # Need to split yoke since Radia can't build concave blocks
        points = rotate45(self.yoke_points[:2] + self.yoke_points[-2:])
        # yoke1 is the part that joins the pole to the yoke
        # Subdivide this cylindrically since the flux goes around a corner here
        # The axis is the second point (x1, y1)
        x1, y1 = points[1]
        yoke1 = rad.ObjThckPgn(length / 2, length, points, "z")
        cyl_div = [[[x1, y1, 0], nz], [self.width, self.width, 0], 1]
        # The first (kr) argument, corresponding to radial subdivision,
        # in rad.ObjDivMag cuts by number not size even though kxkykz->Size is specified.
        # So we have to fudge this. It seems to require a larger number to give the right number of subdivisions.
        n_div = max(1, round(2 * self.width / yoke_mesh))
        rad.ObjDivMag(yoke1, [n_div, yoke_mesh, yoke_mesh], "cyl", cyl_div, div_opts)
        rad.TrfOrnt(yoke1, rad.TrfRot(origin, nz, -math.pi / 4))

        # For the second part of the yoke, we use cylindrical subdivision again. But the axis is not on the corner;
        # instead we calculate the point where the two lines converge (xc, yc).
        points = self.yoke_points[1:3] + self.yoke_points[-3:-1]
        x0, y0 = points[0]
        x1, y1 = points[1]
        x2, y2 = points[2]
        x3, y3 = points[3]
        m1 = (y3 - y0) / (x3 - x0)
        m2 = (y2 - y1) / (x2 - x1)
        c1 = y0 - m1 * x0
        c2 = y1 - m2 * x1
        xc = (c2 - c1) / (m1 - m2)
        yc = m1 * xc + c1
        yoke2 = rad.ObjThckPgn(length / 2, length, points, 'z')
        cyl_div = [[[xc, yc, 0], nz], [x3 - xc, y3 - yc, 0], 1]
        n_div = max(1, round(0.7 * n_div))  # this is a bit of a fudge
        rad.ObjDivMag(yoke2, [n_div, yoke_mesh, yoke_mesh], "cyl", cyl_div, div_opts)

        yoke3 = rad.ObjThckPgn(length / 2, length, self.yoke_points[2:6], "z")
        rad.ObjDivMag(yoke3, [yoke_mesh, ] * 3, div_opts)

        steel = rad.ObjCnt([pole_tip, pole, yoke1, yoke2, yoke3])
        rad.ObjDrwAtr(steel, [0, 0, 1], 0.001)  # blue steel
        rad.TrfOrnt(steel, rad.TrfRot(origin, ny, -math.pi / 2))
        rad.ObjDrwOpenGL(steel)
        rad.TrfOrnt(steel, rad.TrfRot(origin, ny, math.pi / 2))
        # rad.TrfMlt(steel, rad.TrfPlSym([0, 0, 0], [1, -1, 0]), 2)  # reflect along X=Y line to create a quadrant
        rad.TrfZerPerp(steel, origin, [1, -1, 0])
        rad.TrfZerPerp(steel, origin, nz)
        steel_material = rad.MatSatIsoFrm([2000, 2], [0.1, 2], [0.1, 2])
        steel_material = rad.MatStd('Steel42')
        steel_material = rad.MatSatIsoFrm([959.703184, 1.41019852], [33.9916543, 0.5389669], [1.39161186, 0.64144324])
        rad.MatApl(steel, steel_material)

        coil = rad.ObjRaceTrk(origin, [5, 5 + self.coil_width],
                              [self.coil_x * 2 - self.r, length * 2], self.coil_height, 4, self.current_density)
        rad.TrfOrnt(coil, rad.TrfRot(origin, nx, -math.pi / 2))
        rad.TrfOrnt(coil, rad.TrfTrsl([0, self.r + self.taper_height + self.coil_height / 2, 0]))
        rad.TrfOrnt(coil, rad.TrfRot(origin, nz, -math.pi / 4))
        rad.ObjDrwAtr(coil, [1, 0, 0], 0.001)  # red coil
        quad = rad.ObjCnt([steel, coil])

        rad.TrfZerPara(quad, origin, nx)
        rad.TrfZerPara(quad, origin, ny)

        # rad.ObjDrwOpenGL(quad)
        self.radia_object = quad
        self.solve_state = SolveState.BUILT
Beispiel #11
0
trf03 = rad.TrfTrsl([30,10,0])
trf04 = rad.TrfInv()
trf05 = rad.TrfCmbL(trf01, trf04)
trf06 = rad.TrfCmbR(trf01, trf04)

#rad.TrfMlt(mag01, trf03, 3)
rad.TrfOrnt(mag01, trf06)

#rad.ObjDrwOpenGL(mag01)

dmp = rad.UtiDmp([mag01, trf02], 'bin')
#print(dmp)

elemsRest = rad.UtiDmpPrs(dmp)
print('Indexes of restored elements:', elemsRest)
rad.ObjDrwOpenGL(elemsRest[0])

print(rad.UtiDmp(elemsRest[0], 'asc'))
print(rad.UtiDmp(elemsRest[1], 'asc'))

#rad.UtiDel(elemsRest[0])
#print(rad.UtiDmp(elemsRest[0], 'asc'))

print(rad.UtiDmp(trf03, 'asc'))
rad.UtiDelAll()
print(rad.UtiDmp(trf03, 'asc'))


#cutMag = rad.ObjCutMag(mag, [0,0,50], [0,0,1], "Frame->Lab")
#print('Obj. indexes after magnet cut:', cutMag)
Beispiel #12
0
        self.name = name

    
if __name__ == '__main__':
    mymodelparams = parameters.model_parameters(magnets_per_period = 6, periods = 1)
    
    a = HalbachArray(mymodelparams)
    b = HalbachTermination_APPLE(mymodelparams)
    
    c = MagnetRow(a,b)
    
    a.cont.wradSolve(0.001, 1000)
    
    print('{}{}'.format(a.cont.radobj,b))
#    rd.ObjDrwOpenGL(a.cont.radobj)
    rd.ObjDrwOpenGL(b.cont.radobj)
    rd.ObjDrwOpenGL(c.cont.radobj)
    
    
    
    z = 17.5; x1 = 15.25; x2 = 0; ymax = 400; nump = 2001
    
    Bz1 = rd.FldLst(a.cont.radobj, 'bz', [x1,-ymax,z], [x1,ymax,z], nump, 'arg', 0)
    Bz2 = rd.FldLst(a.cont.radobj, 'bz', [x2,-ymax,z], [x2,ymax,z], nump, 'arg',0 )
    
    Bx1 = rd.FldLst(a.cont.radobj, 'bx', [x1,-ymax,z], [x1,ymax,z], nump, 'arg', 0)
    Bx2 = rd.FldLst(a.cont.radobj, 'bx', [x2,-ymax,z], [x2,ymax,z], nump, 'arg',0 )
    
    Bz1 = np.array(Bz1)
    Bz2 = np.array(Bz2)
    n1 = [nx, 3, 2]  #pole faces
    n2 = [nx, 2, 2]  #small vertical arm
    n3 = [nx, 2, 2]
    n4 = [nx, 2, 2]  #horizontal arm
    n5 = [nx, 2, 2]
    n6 = [nx, 2, 2]  #inside the coil

    #Build the geometry
    t0 = time()
    rad.UtiDelAll()
    ironmat = rad.MatSatIsoFrm([20000, 2], [0.1, 2], [0.1, 2])
    t = Geom(1)
    size = rad.ObjDegFre(t)

    #Display the geometry
    rad.ObjDrwOpenGL(t)

    #Solve the geometry
    t1 = time()
    res = rad.Solve(t, 0.0001, 1500)
    t2 = time()

    #Print the results
    b0 = rad.Fld(t, 'Bz', [0, 0, 0])
    bampere = (-4 * pi * current / gap) / 10000
    r = b0 / bampere

    print(
        'Solving results for the segmentation by elliptical cylinders in the corners:'
    )
    print('Mag_Max  H_Max  N_Iter =', round(res[1], 5), 'T ', round(res[2], 5),