Beispiel #1
0
def _apply_clone(g_id, xform):
    # start with 'identity'
    xf = radia.TrfTrsl([0, 0, 0])
    for clone_xform in xform.transforms:
        cxf = PKDict(clone_xform)
        if cxf.model == 'translateClone':
            txf = radia.TrfTrsl(_split_comma_field(cxf.distance, 'float'))
            xf = radia.TrfCmbL(xf, txf)
        if cxf.model == 'rotateClone':
            rxf = radia.TrfRot(_split_comma_field(cxf.center, 'float'),
                               _split_comma_field(cxf.axis, 'float'),
                               numpy.pi * float(cxf.angle) / 180.)
            xf = radia.TrfCmbL(xf, rxf)
    if xform.alternateFields != '0':
        xf = radia.TrfCmbL(xf, radia.TrfInv())
    radia.TrfMlt(g_id, xf, xform.numCopies + 1)
Beispiel #2
0
    def wradTranslate(self, translation_vector):
        '''trying to write a translation function'''

        #translate vertices
        for i in range(len(self.vertices)):
            self.vertices[i] = self.vertices[i] + translation_vector

        #translate radia object
        tran = rd.TrfTrsl(translation_vector)
        rd.TrfOrnt(self.radobj, tran)
Beispiel #3
0
def _apply_clone(g_id, xform):
    xform = PKDict(xform)
    # start with 'identity'
    xf = radia.TrfTrsl([0, 0, 0])
    for clone_xform in xform.transforms:
        cxf = PKDict(clone_xform)
        if cxf.model == 'translateClone':
            txf = radia.TrfTrsl(
                sirepo.util.split_comma_delimited_string(cxf.distance, float)
            )
            xf = radia.TrfCmbL(xf, txf)
        if cxf.model == 'rotateClone':
            rxf = radia.TrfRot(
                sirepo.util.split_comma_delimited_string(cxf.center, float),
                sirepo.util.split_comma_delimited_string(cxf.axis, float),
                numpy.pi * float(cxf.angle) / 180.
            )
            xf = radia.TrfCmbL(xf, rxf)
    if xform.alternateFields != '0':
        xf = radia.TrfCmbL(xf, radia.TrfInv())
    radia.TrfMlt(g_id, xf, xform.numCopies + 1)
Beispiel #4
0
def _apply_translation(g_id, xform):
    radia.TrfOrnt(g_id,
                  radia.TrfTrsl(_split_comma_field(xform.distance, 'float')))
 def shift(self, value):
     """Shift radia object."""
     if self._radia_object is not None:
         self._radia_object = _rad.TrfOrnt(self._radia_object,
                                           _rad.TrfTrsl(value))
Beispiel #6
0
def _apply_translation(g_id, xform):
    xform = PKDict(xform)
    radia.TrfOrnt(
        g_id,
        radia.TrfTrsl(sirepo.util.split_comma_delimited_string(xform.distance, float))
    )
Beispiel #7
0
def _clone_with_translation(g_id, num_copies, distance, alternate_fields):
    xf = radia.TrfTrsl(distance)
    if alternate_fields:
        xf = radia.TrfCmbL(xf, radia.TrfInv())
    radia.TrfMlt(g_id, xf, num_copies + 1)
Beispiel #8
0
#mag01sbd = rad.ObjDivMagPln(mag01, [[2,0.5],[3,0.2],[4,0.1]], [1,0.4,0.1], [0.4,1,0.2], [0,0,1], 'Frame->Lab')
mag01sbd = rad.ObjDivMagPln(mag01, [[2,0.5],[3,0.2],[4,0.1]])
#rad.ObjDrwOpenGL(mag01sbd)

#mag00sbd = rad.ObjDivMag(mag00, [[2,0.5],[3,0.2],[4,0.1]], 'cyl', [[2.5,4,0],[0,0,1],[8,0,0],3], 'Frame->Lab')
#mag00sbd = rad.ObjDivMagCyl(mag00, [[2,0.5],[3,0.2],[4,0.1]], [2.5,4,0], [0,0,1], [8,0,0], 3, 'Frame->Lab')

print('Volume of 3D object:', rad.ObjGeoVol(mag01sbd))
print('Geom. Limits of 3D object:', rad.ObjGeoLim(mag01sbd))

#rad.ObjDrwOpenGL(mag01)

trf01 = rad.TrfPlSym([0,10,0], [0,1,0])
trf02 = rad.TrfRot([0,10,0], [0,0,1], 1.)
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)

matNdFeB = rad.MatStd('NdFeB')
M = rad.MatMvsH(matNdFeB, 'M', [0,0,0])
print('NdFeB material index:', matNdFeB, ' Magnetization:', M)

matLin01 = rad.MatLin([0.1,0.2],1.1)
matLin02 = rad.MatLin([0.1,0.2],[0,0,1.1])
Beispiel #9
0
 def shift(self, value):
     self._radia_object = _rad.TrfOrnt(
         self._radia_object, _rad.TrfTrsl(value))
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
 def shift(self, value):
     """Shift the radia object."""
     if self._radia_object is not None:
         self._radia_object = _rad.TrfOrnt(self._radia_object,
                                           _rad.TrfTrsl(value))
         self._longitudinal_position += value[2]