Пример #1
0
 def test_wradMat_M(self):
     rd.UtiDelAll()
     ksi = [.019, .06]
     M = [0,0,1.5]
     a = wrd.wrad_mat.wradMatLin(ksi,M)
     
     assert a.M ==  [0,0,1.5]
Пример #2
0
 def test_wradMat_exists(self):
     rd.UtiDelAll()
     ksi = [.019, .06]
     M = [0,0,1.5]
     a = wrd.wrad_mat.wradMatLin(ksi,M)
     
     assert a.radobj == 1
Пример #3
0
    def test_radia_simple_magnet(self):
        
        rad.UtiDelAll()
        magnet   = rad.ObjRecMag([0,0,0], [1,1,1], [0,1,0])
        observed = np.array(rad.Fld(magnet, 'b', [1,2,3]), dtype=np.float32)

        expected = np.array([0.0006504201540729257, -0.00021819974895862903, 0.0019537852236147252], dtype=np.float32)

        self.assertTrue(np.allclose(observed, expected))
Пример #4
0
    def build_model(self):
        """Build a Radia or Opera model with the current result set."""
        length = self.length_spinbox.value()
        if self.build_button.text() == 'Radia':
            rad.UtiDelAll()
            item = self.listview.selectedItems()[0]
            # build magnet geometry
            magnet = rad.ObjCnt([rad.ObjThckPgn(0, length, pg[2:].reshape((4, 2)).tolist(), "z", list(pg[:2]) + [0, ])
                                 for pg in self.state['results'][tuple(item.text().split(', '))]])
            rad.MatApl(magnet, rad.MatStd('NdFeB', next(c for c in self.controls if c.switch == 'Br').control.value()))

            # plot geometry in 3d
            ax = self.plot3d.axes
            ax.cla()
            ax.set_axis_off()
            polygons = rad.ObjDrwVTK(magnet)['polygons']
            vertices = np.array(polygons['vertices']).reshape((-1, 3))  # [x, y, z, x, y, z] -> [[x, y, z], [x, y, z]]
            [set_lim(vertices.min(), vertices.max()) for set_lim in (ax.set_xlim3d, ax.set_ylim3d, ax.set_zlim3d)]
            vertices = np.split(vertices, np.cumsum(polygons['lengths'])[:-1])  # split to find each face
            ax.add_collection3d(Poly3DCollection(vertices, linewidths=0.1, edgecolors='black',
                                                 facecolors=self.get_colour(), alpha=0.2))

            # add arrows
            magnetisation = np.array(rad.ObjM(magnet)).reshape((-1, 6)).T  # reshape to [x, y, z, mx, my, mz]
            for end in (-1, 1):  # one at each end of the block, not in the middle
                magnetisation[2] = end * length / 2
                ax.quiver(*magnetisation, color='black', lw=1, pivot='middle')

            self.tab_control.setCurrentIndex(2)  # switch to '3d' tab

            # solve the model
            try:
                rad.Solve(magnet, 0.00001, 10000)  # precision and number of iterations
            except RuntimeError:
                self.statusBar().showMessage('Radia solve error')

            # get results
            dx = 0.1
            multipoles = [mpole_names.index(c.label) for c in self.controls if c.label.endswith('pole') and c.get_arg()]
            i = multipoles[-1]
            xs = np.linspace(-dx, dx, 4)
            fit_field = np.polyfit(xs / 1000, [rad.Fld(magnet, 'by', [x, 0, 0]) for x in xs], i)
            fit_int = np.polyfit(xs / 1000,
                                 [rad.FldInt(magnet, 'inf', 'iby', [x, 0, -1], [x, 0, 1]) * 0.001 for x in xs], i)
            text = ''
            for j, (l, c, ic, u, iu) in enumerate(
                    zip(mpole_names, fit_field[::-1], fit_int[::-1], units[1:], units[:-1])):
                if j in multipoles:
                    f = factorial(j)  # 1 for dip, quad; 2 for sext; 6 for oct
                    text += f'{l} field = {c * f:.3g} {u}, integral = {ic * f:.3g} {iu}, length = {ic / c:.3g} m\n'
            ax.text2D(1, 1, text, transform=ax.transAxes, va='top', ha='right', fontdict={'size': 8})
            self.plot3d.canvas.draw()
Пример #5
0
    def create_radia_object(
            self,
            magnetization_dict=None,
            horizontal_pos_err_dict=None,
            vertical_pos_err_dict=None):
        _rad.UtiDelAll()
        self._cassettes = {}

        if magnetization_dict is None:
            magnetization_dict = {}

        if horizontal_pos_err_dict is None:
            horizontal_pos_err_dict = {}

        if vertical_pos_err_dict is None:
            vertical_pos_err_dict = {}

        name = 'cs'
        cs = _cassettes.PMCassette(
            upper_cassette=True, name=name,
            init_radia_object=False, **self.cassette_properties)
        cs.create_radia_object(
            magnetization_list=magnetization_dict.get(name),
            horizontal_pos_err=horizontal_pos_err_dict.get(name),
            vertical_pos_err=vertical_pos_err_dict.get(name))
        cs.shift([0, -self._gap/2, 0])
        cs.rotate([0, 0, 0], [0, 0, 1], _np.pi)
        self._cassettes[name] = cs

        name = 'ci'
        ci = _cassettes.PMCassette(
            upper_cassette=False, name=name,
            init_radia_object=False, **self.cassette_properties)
        ci.create_radia_object(
            magnetization_list=magnetization_dict.get(name),
            horizontal_pos_err=horizontal_pos_err_dict.get(name),
            vertical_pos_err=vertical_pos_err_dict.get(name))
        ci.shift([0, -self._gap/2, 0])
        self._cassettes[name] = ci

        self._radia_object = _rad.ObjCnt(
            [c.radia_object for c in [cs, ci]])
Пример #6
0
 def reset_geom(self, g_name):
     self.remove_geom(g_name)
     return radia.UtiDelAll()
Пример #7
0
def reset():
    return radia.UtiDelAll()
Пример #8
0
import socket

from mpi4py import MPI
comm = MPI.COMM_WORLD

comm.Barrier()

if comm.rank == 0:
    print(
        f'{comm.rank:04d} of {comm.size:04d} : Test Radia on each process...')

comm.Barrier()

print(f'{comm.rank:04d} of {comm.size:04d} : Radia version: {rad.UtiVer()}')

rad.UtiDelAll()
magnet = rad.ObjRecMag([0, 0, 0], [1, 1, 1], [0, 1, 0])
observed = np.array(rad.Fld(magnet, 'b', [1, 2, 3]), dtype=np.float32)
expected = np.array(
    [0.0006504201540729257, -0.00021819974895862903, 0.0019537852236147252],
    dtype=np.float32)

print(
    f'{comm.rank:04d} of {comm.size:04d} : Radia success: {np.allclose(observed, expected)}'
)

comm.Barrier()

if comm.rank == 0:
    print(
        f'{comm.rank:04d} of {comm.size:04d} : Test communication on each process...'
Пример #9
0
 def setUp(self):
     rd.UtiDelAll()
     #ATHENA_II Parameters
     AII = ma.model_hyper_parameters(applePeriods=3, Mova=0.0)
Пример #10
0
 def testawradO(self):
     rd.UtiDelAll()
     c2 = wrd.wradObjThckPgn(0.0,5.0,[[-5.0,-5.0],[-5.0,5.0],[5.0,5.0],[5.0,-5.0]])
     assert c2.radobj == 1
Пример #11
0
 def testsimple(self):
     rd.UtiDelAll()
     cl = wr.wradClaExtr()
     assert cl.cont1 == 1
Пример #12
0
    def __init__(self,
                 model_parameters=parameters.model_parameters(),
                 fmagnet=ms.appleMagnet):

        rd.UtiDelAll()
        self.cont = wrd.wradObjCnt([])

        self.model_parameters = model_parameters
        mp = self.model_parameters

        if mp.shiftmode == 'circular':
            shiftmodesign = 1
        elif mp.shiftmode == 'linear':
            shiftmodesign = -1
        else:
            shiftmodesign = 0

        self.rownames = ['q1', 'q2', 'q3', 'q4']
        self.allarraytabs = np.array([
            ha.MagnetRow(
                self.rownames[0], ha.HalbachArray(model_parameters, fmagnet),
                ha.HalbachTermination_APPLE(model_parameters, fmagnet))
            for _ in range(4)
        ])

        for r in range(4):
            self.allarraytabs[r] = ha.MagnetRow(
                self.rownames[r],
                ha.HalbachArray(model_parameters, fmagnet),
                ha.HalbachTermination_APPLE(model_parameters, fmagnet),
                beam=int((r // 2)),
                quadrant=int(self.rownames[r][1]) - 1,
                row=r)

        ##### Functional Magnets #####

        ### Q1 ###

        self.allarraytabs[0].cont.wradTranslate([
            -(mp.nominal_fmagnet_dimensions[2] + mp.rowtorowgap) / 2.0, 0.0,
            -(mp.nominal_fmagnet_dimensions[0] + mp.gap) / 2.0
        ])
        self.allarraytabs[0].cont.wradFieldInvert()
        self.allarraytabs[0].cont.wradRotate([0, 0, 0], [0, 1, 0], np.pi)
        self.allarraytabs[0].cont.wradReflect([0, 0, 0], [1, 0, 0])

        ### Q2 ###
        self.allarraytabs[1].cont.wradTranslate([
            -(mp.nominal_fmagnet_dimensions[2] + mp.rowtorowgap) / 2.0,
            mp.rowshift, -(mp.nominal_fmagnet_dimensions[0] + mp.gap) / 2.0
        ])
        self.allarraytabs[1].cont.wradFieldInvert()
        self.allarraytabs[1].cont.wradRotate([0, 0, 0], [0, 1, 0], np.pi)

        ### Q3 ###
        self.allarraytabs[2].cont.wradTranslate([
            -(mp.nominal_fmagnet_dimensions[2] + mp.rowtorowgap) / 2.0,
            mp.rowshift * shiftmodesign,
            -(mp.nominal_fmagnet_dimensions[0] + mp.gap) / 2.0
        ])

        ### Q4 ###
        self.allarraytabs[3].cont.wradTranslate([
            -(mp.nominal_fmagnet_dimensions[2] + mp.rowtorowgap) / 2.0, 0.0,
            -(mp.nominal_fmagnet_dimensions[0] + mp.gap) / 2.0
        ])
        self.allarraytabs[3].cont.wradReflect([0, 0, 0], [1, 0, 0])

        for row in range(len(self.allarraytabs)):
            self.cont.wradObjAddToCnt([self.allarraytabs[row].cont])
Пример #13
0
    def __init__(self,
                 model_parameters=parameters.model_parameters(),
                 fmagnet=ms.appleMagnet,
                 cmagnet=ms.compMagnet,
                 Hcmagnet=ms.HcompMagnet,
                 Vcmagnet=ms.VcompMagnet):
        rd.UtiDelAll()
        self.cont = wrd.wradObjCnt([])

        self.model_parameters = model_parameters
        mp = self.model_parameters

        if mp.shiftmode == 'circular':
            shiftmodesign = 1
        elif mp.shiftmode == 'linear':
            shiftmodesign = -1
        else:
            shiftmodesign = 0

        self.rownames = [
            'q1', 'q2', 'q3', 'q4', 'c1v', 'c1h', 'c2v', 'c2h', 'c3v', 'c3h',
            'c4v', 'c4h'
        ]
        self.allarraytabs = np.array([
            ha.MagnetRow(
                self.rownames[0], ha.HalbachArray(model_parameters, fmagnet),
                ha.HalbachTermination_APPLE(model_parameters, fmagnet))
            for _ in range(12)
        ])

        for r in range(4):
            self.allarraytabs[r] = ha.MagnetRow(
                self.rownames[r],
                ha.HalbachArray(model_parameters, fmagnet),
                ha.HalbachTermination_APPLE(model_parameters, fmagnet),
                beam=int((r // 2)),
                quadrant=int(self.rownames[r][1]) - 1,
                row=r)
        for r in range(4, 12, 2):
            if r < 8:
                be = 0

            else:
                be = 1

            self.allarraytabs[r] = ha.MagnetRow(
                self.rownames[r],
                ha.HalbachArray(model_parameters, Vcmagnet),
                ha.HalbachTermination_APPLE(model_parameters, Vcmagnet),
                beam=be,
                quadrant=int(self.rownames[r][1]) - 1,
                row=r)
        for r in range(5, 12, 2):
            if r < 8:
                be = 0

            else:
                be = 1

            self.allarraytabs[r] = ha.MagnetRow(
                self.rownames[r],
                ha.HalbachArray(model_parameters, Hcmagnet),
                ha.HalbachTermination_APPLE(model_parameters, Hcmagnet),
                beam=be,
                quadrant=int(self.rownames[r][1]) - 1,
                row=r)

        ##### Functional Magnets #####

        ### Q1 ###

        self.allarraytabs[0].cont.wradTranslate([
            -(mp.nominal_fmagnet_dimensions[2] + mp.rowtorowgap) / 2.0, 0.0,
            -(mp.nominal_fmagnet_dimensions[0] + mp.gap) / 2.0
        ])
        self.allarraytabs[0].cont.wradFieldInvert()
        self.allarraytabs[0].cont.wradRotate([0, 0, 0], [0, 1, 0], np.pi)
        self.allarraytabs[0].cont.wradReflect([0, 0, 0], [1, 0, 0])

        ### Q2 ###
        self.allarraytabs[1].cont.wradTranslate([
            -(mp.nominal_fmagnet_dimensions[2] + mp.rowtorowgap) / 2.0,
            mp.rowshift, -(mp.nominal_fmagnet_dimensions[0] + mp.gap) / 2.0
        ])
        self.allarraytabs[1].cont.wradFieldInvert()
        self.allarraytabs[1].cont.wradRotate([0, 0, 0], [0, 1, 0], np.pi)

        ### Q3 ###
        self.allarraytabs[2].cont.wradTranslate([
            -(mp.nominal_fmagnet_dimensions[2] + mp.rowtorowgap) / 2.0,
            mp.rowshift * shiftmodesign,
            -(mp.nominal_fmagnet_dimensions[0] + mp.gap) / 2.0
        ])

        ### Q4 ###
        self.allarraytabs[3].cont.wradTranslate([
            -(mp.nominal_fmagnet_dimensions[2] + mp.rowtorowgap) / 2.0, 0.0,
            -(mp.nominal_fmagnet_dimensions[0] + mp.gap) / 2.0
        ])
        self.allarraytabs[3].cont.wradReflect([0, 0, 0], [1, 0, 0])

        ##### Compensation Magnets #####

        ### C1h ###
        self.allarraytabs[5].cont.wradTranslate([
            -(mp.nominal_hcmagnet_dimensions[2] + mp.rowtorowgap + 2 *
              (mp.nominal_fmagnet_dimensions[0] + mp.compappleseparation)) /
            2.0, 0.0, -(mp.nominal_hcmagnet_dimensions[0] + mp.gap) / 2.0
        ])
        self.allarraytabs[5].cont.wradReflect([0, 0, 0], [0, 0, 1])

        ### C2h ###

        self.allarraytabs[7].cont.wradTranslate([
            -(mp.nominal_hcmagnet_dimensions[2] + mp.rowtorowgap + 2 *
              (mp.nominal_fmagnet_dimensions[0] + mp.compappleseparation)) /
            2.0, mp.rowshift,
            -(mp.nominal_hcmagnet_dimensions[0] + mp.gap) / 2.0
        ])
        self.allarraytabs[7].cont.wradFieldInvert()
        self.allarraytabs[7].cont.wradRotate([0, 0, 0], [0, 1, 0], np.pi)

        ### C3h ###
        self.allarraytabs[9].cont.wradTranslate([
            -(mp.nominal_hcmagnet_dimensions[2] + mp.rowtorowgap + 2 *
              (mp.nominal_fmagnet_dimensions[0] + mp.compappleseparation)) /
            2.0, mp.rowshift * shiftmodesign,
            -(mp.nominal_hcmagnet_dimensions[0] + mp.gap) / 2.0
        ])

        ### C4h ###
        self.allarraytabs[11].cont.wradTranslate([
            -(mp.nominal_hcmagnet_dimensions[2] + mp.rowtorowgap + 2 *
              (mp.nominal_fmagnet_dimensions[0] + mp.compappleseparation)) /
            2.0, 0.0, -(mp.nominal_hcmagnet_dimensions[0] + mp.gap) / 2.0
        ])
        self.allarraytabs[11].cont.wradFieldInvert()
        self.allarraytabs[11].cont.wradReflect([0, 0, 0], [1, 0, 0])

        ### C1v ###
        self.allarraytabs[4].cont.wradFieldRotate([0, 0, 0], [0, 1, 0],
                                                  np.pi / 2)
        self.allarraytabs[4].cont.wradFieldInvert()
        self.allarraytabs[4].cont.wradRotate([0, 0, 0], [0, 1, 0], np.pi / 2)
        self.allarraytabs[4].cont.wradReflect([0, 0, 0], [0, 0, 1])
        self.allarraytabs[4].cont.wradTranslate([
            -(mp.nominal_vcmagnet_dimensions[0] + mp.rowtorowgap) / 2.0, 0.0,
            (mp.nominal_vcmagnet_dimensions[2] + mp.gap + 2 *
             (mp.nominal_fmagnet_dimensions[2] + mp.compappleseparation)) / 2.0
        ])
        ###feildrotatedebugtest###
        #        axisq1 = [[10,-20,10],[10,20,10]]
        #        rd.Solve(self.allarraytabs[0].cont.objectlist[0].objectlist[0].radobj,0.001,1000)
        #        q1m = np.array(rd.FldLst(self.allarraytabs[0].cont.objectlist[0].objectlist[0].radobj,'mxmymz',axisq1[0],axisq1[1],101,'arg',-20))
        #        plt.plot(q1m[:,0],q1m[:,3])

        #        axisc1v = [[4,-20,30],[4,20,30]]
        #        rd.Solve(self.allarraytabs[4].cont.objectlist[0].objectlist[0].radobj,0.001,1000)
        #        c1vm = np.array(rd.FldLst(self.allarraytabs[4].cont.objectlist[0].objectlist[0].radobj,'mxmymz',axisc1v[0],axisc1v[1],101,'arg',-20))
        #        plt.plot(c1vm[:,0],c1vm[:,3])

        #        print(1)

        ### C2v ###

        self.allarraytabs[6].cont.wradFieldRotate([0, 0, 0], [0, 1, 0],
                                                  np.pi / 2)
        #self.allarraytabs[4].cont.wradFieldInvert()
        self.allarraytabs[6].cont.wradRotate([0, 0, 0], [0, 1, 0], -np.pi / 2)
        self.allarraytabs[6].cont.wradTranslate([
            (mp.nominal_vcmagnet_dimensions[0] + mp.rowtorowgap) / 2.0,
            mp.rowshift,
            (mp.nominal_vcmagnet_dimensions[2] + mp.gap + 2 *
             (mp.nominal_fmagnet_dimensions[2] + mp.compappleseparation)) / 2.0
        ])

        ### C3v ###
        self.allarraytabs[8].cont.wradFieldRotate([0, 0, 0], [0, 1, 0],
                                                  np.pi / 2)
        #self.allarraytabs[10].cont.wradFieldInvert()
        self.allarraytabs[8].cont.wradRotate([0, 0, 0], [0, 1, 0], np.pi / 2)
        self.allarraytabs[8].cont.wradTranslate([
            -(mp.nominal_vcmagnet_dimensions[0] + mp.rowtorowgap) / 2.0,
            mp.rowshift * shiftmodesign,
            -(mp.nominal_vcmagnet_dimensions[2] + mp.gap + 2 *
              (mp.nominal_fmagnet_dimensions[2] + mp.compappleseparation)) /
            2.0
        ])

        ### C4v ###
        self.allarraytabs[10].cont.wradFieldRotate([0, 0, 0], [0, 1, 0],
                                                   np.pi / 2)
        self.allarraytabs[10].cont.wradFieldInvert()
        self.allarraytabs[10].cont.wradRotate([0, 0, 0], [0, 1, 0], -np.pi / 2)
        self.allarraytabs[10].cont.wradTranslate([
            (mp.nominal_vcmagnet_dimensions[0] + mp.rowtorowgap) / 2.0, 0.0,
            (mp.nominal_vcmagnet_dimensions[2] + mp.gap + 2 *
             (mp.nominal_fmagnet_dimensions[2] + mp.compappleseparation)) / 2.0
        ])
        self.allarraytabs[10].cont.wradReflect([0, 0, 0], [0, 0, 1])

        for row in range(len(self.allarraytabs)):
            self.cont.wradObjAddToCnt([self.allarraytabs[row].cont])

        print('my compensated APPLE calculated at a gap of {}mm'.format(
            mp.gap))
        '''
Пример #14
0
    def create_radia_object(
            self,
            magnetization_dict=None,
            horizontal_pos_err_dict=None,
            vertical_pos_err_dict=None):
        _rad.UtiDelAll()
        self._cassettes = {}

        if magnetization_dict is None:
            magnetization_dict = {}

        if horizontal_pos_err_dict is None:
            horizontal_pos_err_dict = {}

        if vertical_pos_err_dict is None:
            vertical_pos_err_dict = {}

        if _utils.depth(self._block_shape) != 3:
            self._block_shape = [self._block_shape]

        mirror_block_shape = [
            [(-1)*pts[0], pts[1]] for shp in self._block_shape for pts in shp]

        name = 'cse'
        cse = _cassettes.PMCassette(
            block_shape=mirror_block_shape,
            upper_cassette=True, name=name,
            init_radia_object=False, **self.cassette_properties)
        cse.create_radia_object(
            magnetization_list=magnetization_dict.get(name),
            horizontal_pos_err=horizontal_pos_err_dict.get(name),
            vertical_pos_err=vertical_pos_err_dict.get(name))
        cse.shift([0, -self._gap/2, 0])
        cse.rotate([0, 0, 0], [0, 0, 1], _np.pi)
        self._cassettes[name] = cse

        name = 'csd'
        csd = _cassettes.PMCassette(
            block_shape=self._block_shape,
            upper_cassette=True, name=name,
            init_radia_object=False, **self.cassette_properties)
        csd.create_radia_object(
            magnetization_list=magnetization_dict.get(name),
            horizontal_pos_err=horizontal_pos_err_dict.get(name),
            vertical_pos_err=vertical_pos_err_dict.get(name))
        csd.shift([0, -self._gap/2, 0])
        csd.rotate([0, 0, 0], [0, 0, 1], _np.pi)
        self._cassettes[name] = csd

        name = 'cie'
        cie = _cassettes.PMCassette(
            block_shape=self._block_shape,
            upper_cassette=False, name=name,
            init_radia_object=False, **self.cassette_properties)
        cie.create_radia_object(
            magnetization_list=magnetization_dict.get(name),
            horizontal_pos_err=horizontal_pos_err_dict.get(name),
            vertical_pos_err=vertical_pos_err_dict.get(name))
        cie.shift([0, -self._gap/2, 0])
        self._cassettes[name] = cie

        name = 'cid'
        cid = _cassettes.PMCassette(
            block_shape=mirror_block_shape,
            upper_cassette=False, name=name,
            init_radia_object=False, **self.cassette_properties)
        cid.create_radia_object(
            magnetization_list=magnetization_dict.get(name),
            horizontal_pos_err=horizontal_pos_err_dict.get(name),
            vertical_pos_err=vertical_pos_err_dict.get(name))
        cid.shift([0, -self._gap/2, 0])
        self._cassettes[name] = cid

        self._radia_object = _rad.ObjCnt(
            [c.radia_object for c in [csd, cse, cid, cie]])
Пример #15
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
Пример #16
0
 def setUp(self):
     rd.UtiDelAll()
     #ATHENA_II Parameters
     AII = am.model_hyper_parameters(applePeriods = 3, Mova = 10.0)
     self.tc = am.appleUpperBeam(AII) #tc test_container