Пример #1
0
    def wradFieldRotate(self, pivot_origin, pivot_vector, rot_magnitude):
        '''trying to write a rotation function
            # u' = quq*
            #u is point
            #q is quaternion representation of rotation angle ( sin (th/2)i, sin(th/2)j, sin (th/2)k, cos (th/2))'''
        q = R.from_quat([
            pivot_vector[0] * np.sin(rot_magnitude / 2.0),
            pivot_vector[1] * np.sin(rot_magnitude / 2.0),
            pivot_vector[2] * np.sin(rot_magnitude / 2.0),
            np.cos(rot_magnitude / 2.0)
        ])

        #rotate magnetisation vector
        self.magnetisation = q.apply(self.magnetisation)
        self.material.M = self.magnetisation.tolist()

        self.material = wrdm.wradMatLin(self.material.ksi, self.material.M)
        rd.MatApl(self.radobj, self.material.radobj)

        # rotate colour
        q = R.from_quat([
            pivot_vector[0] * np.sin(rot_magnitude / 2.0),
            pivot_vector[1] * np.sin(rot_magnitude / 2.0),
            pivot_vector[2] * np.sin(rot_magnitude / 2.0),
            np.cos(rot_magnitude / 2.0),
        ])

        tmpcol = [(4 * x - 2) for x in self.colour]

        tmpcol = q.apply(tmpcol)

        self.colour = [(2 + x) / 4.0 for x in tmpcol]
        rd.ObjDrwAtr(self.radobj, self.colour, self.linethickness)
Пример #2
0
def appleArray(parameter_class, loc_offset, halbach_direction=-1):
    a = wrd.wradObjCnt([])

    loc_offset[1] += -((parameter_class.appleMagnets - 1) / 2.0) * (
        parameter_class.mainmagthick + parameter_class.shim)
    M = []
    mat = []
    for i in range(4):
        #M.append([halbach_direction * np.sin(i*np.pi/2.0)*parameter_class.M*np.sin(2*np.pi*parameter_class.Mova/360.0),halbach_direction * np.sin(i*np.pi/2.0)*parameter_class.M * np.cos(2*np.pi*parameter_class.Mova/360.0), np.cos(i*np.pi/2.0)*parameter_class.M])
        M.append([
            np.cos(i * np.pi / 2.0) * parameter_class.M *
            np.sin(2 * np.pi * parameter_class.Mova / 360.0),
            halbach_direction * np.sin(i * np.pi / 2.0) * parameter_class.M,
            np.cos(i * np.pi / 2.0) * parameter_class.M *
            np.cos(2 * np.pi * parameter_class.Mova / 360.0)
        ])

        mat.append(wrdm.wradMatLin(parameter_class.ksi, M[i]))

    for x in range(-int((parameter_class.appleMagnets - 1) / 2),
                   int(1 + (parameter_class.appleMagnets - 1) /
                       2)):  #0,parameter_class.appleMagnets

        mag = ms.appleMagnet(parameter_class, loc_offset)
        loc_offset[1] += parameter_class.mainmagthick + parameter_class.shim
        magcol = [(2 + y) / 4.0 for y in M[(x) % 4]]
        mag.wradObjDrwAtr(magcol, 2)  # [x / myInt for x in myList]
        mag.wradObjDivMag([2, 3, 1])
        a.wradObjAddToCnt([mag])

    return a
Пример #3
0
def compVArray(parameter_class, loc_offset, halbach_direction=-1):
    a = wrd.wradObjCnt([])

    loc_offset[1] = -((parameter_class.appleMagnets - 1) / 2.0) * (
        parameter_class.mainmagthick + parameter_class.shim)
    M = []
    mat = []
    for i in range(4):
        #M.append([np.sin(i*np.pi/2.0)*parameter_class.M*np.sin(2*np.pi*parameter_class.Mova/360.0),np.sin(i*np.pi/2.0)*parameter_class.M * np.cos(2*np.pi*parameter_class.Mova/360.0),halbach_direction * np.cos(i*np.pi/2.0)*parameter_class.M])
        M.append([
            -halbach_direction * np.cos(i * np.pi / 2.0) * parameter_class.M *
            np.cos(2 * np.pi * parameter_class.Mova / 360.0),
            halbach_direction * np.sin(i * np.pi / 2.0) * parameter_class.M,
            np.cos(i * np.pi / 2.0) * parameter_class.M *
            np.sin(2 * np.pi * parameter_class.Mova / 360.0)
        ])
        mat.append(wrdm.wradMatLin(parameter_class.ksi, M[i]))

    for x in range(0, parameter_class.appleMagnets):

        mag = compMagnet(parameter_class, loc_offset[1], mat[x % 4],
                         loc_offset)
        loc_offset[1] += parameter_class.mainmagthick + parameter_class.shim
        magcol = [(2 + y) / 4.0 for y in M[x % 4]]
        mag.wradObjDrwAtr(magcol, 2)  # [x / myInt for x in myList]
        mag.wradObjDivMag([2, 3, 1])
        a.wradObjAddToCnt([mag])

    a.wradRotate([0, 0, 0], [0, 1, 0], np.pi / 2.0)

    return a
Пример #4
0
    def __init__(self, **kwargs):
        #general
        prop_defaults = {
            "origin": np.zeros(
                3
            ),  #set the origin of the device. Default is array([0., 0., 0.])

            ######  Undulator Parameters  ######
            "applePeriods": 3,  # Number of Periods of the APPLE Undulator
            "minimumgap": 2,  # Gap used in calculation in mm
            "rowtorowgap":
            0.5,  # for APPLE devices the distance between functional rows on the same jaw
            "shim":
            0.05,  # The gap between each magnet in a row / magnet array.
            "compappleseparation":
            15.0,  # The gap between functional magnets and compenation magnets
            "periodlength": 15,  # The period length of the undulator
            "circlin":
            1,  # Polarisation mode of the undulator -1 is circ (parallel), 1 is linear (antiparallel)
            "shift": 0,  # distance of row shift in mm
            "halbach_direction":
            1,  # a value to determine the sense of magnet rotation along the axis. 1 = Field BELOW array. -1 Field ABOVE array 

            #####  Magnet Shape  #####
            "mainmagdimension":
            30,  # The primary magnet dimension for the functional magnets [mm]
            "clampcut": 5,  # The size of the square removed for clamping [mm]
            "direction":
            'y',  # The direction of extrusion - along the direction of travel of the electrons. Dimensions propogate in the order [z,y,x]

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

            # "compmagdimensions" : [15.0,self.mainmagthick,30.0] # dimensions of the compensation magnets [mm]

            #####  Magnet Material #####
            "ksi": [.019, .06],  # Permeability - anisotropic
            "M": 1.21 * 1.344,  # Block Remanence [T]
            "Mova":
            0.0  # Off Vertical Angle of Vertical type magnet blocks [degrees]
        }

        for (prop, default) in prop_defaults.items():
            setattr(self, prop, kwargs.get(prop, default))

        ###Derived Attributes###

        #Undulator
        self.appleMagnets = int(self.applePeriods * 4 + 1)

        #magnet shape
        self.mainmagthick = (self.periodlength - 4 * self.shim) / 4.0

        #compensation magnets
        self.compmagdimensions = [15.0, self.mainmagthick, 30.0]

        #magnetmaterial
        self.magnet_material = wrdm.wradMatLin(self.ksi, [0, 0, self.M])
Пример #5
0
 def __init__(self, model_hyper_parameters = parameters.model_parameters(), magnet = ms.appleMagnet):
     self.cont = wrd.wradObjCnt([])
         
     loc_offset = [0,0,0]
     
     loc_offset[1] = -(((model_hyper_parameters.totalmagnets-1)/2.0) * 
                       (model_hyper_parameters.nominal_fmagnet_dimensions[1] + 
                        model_hyper_parameters.shim) + 
                       model_hyper_parameters.nominal_fmagnet_dimensions[1]/2.0 + 2 *model_hyper_parameters.shim +
                       model_hyper_parameters.end_magnet_thickness[0] * 2.5 +
                       model_hyper_parameters.end_separation
                       )
     M = []
     mat = []
     
     for i in range(model_hyper_parameters.magnets_per_period):
         #M.append([halbach_direction * np.sin(i*np.pi/2.0)*model_hyper_parameters.M*np.sin(2*np.pi*model_hyper_parameters.Mova/360.0),halbach_direction * np.sin(i*np.pi/2.0)*model_hyper_parameters.M * np.cos(2*np.pi*model_hyper_parameters.Mova/360.0), np.cos(i*np.pi/2.0)*model_hyper_parameters.M])
         M.append([np.cos(i*2*np.pi/model_hyper_parameters.magnets_per_period)*model_hyper_parameters.M*np.sin(2*np.pi*model_hyper_parameters.Mova/360.0),
                   -1 * np.sin(i*2*np.pi/model_hyper_parameters.magnets_per_period)*model_hyper_parameters.M, 
                   np.cos(i*2*np.pi/model_hyper_parameters.magnets_per_period)*model_hyper_parameters.M * np.cos(2*np.pi*model_hyper_parameters.Mova/360.0)])
         
         mat.append(wrdm.wradMatLin(model_hyper_parameters.ksi,M[i]))
     
     Mus = -int((model_hyper_parameters.totalmagnets-1)/2)#1st full magnet Upstream in row
     Mds = int((model_hyper_parameters.totalmagnets-1)/2)#1st full magnet Downstreamin row
     
     mag1 = magnet(model_hyper_parameters, loc_offset,mat[(Mus-3)%model_hyper_parameters.magnets_per_period], magnet_thickness = model_hyper_parameters.end_magnet_thickness[0]) 
     loc_offset[1] += model_hyper_parameters.end_magnet_thickness[0] + model_hyper_parameters.end_separation
     
     mag2 = magnet(model_hyper_parameters, loc_offset,mat[(Mus-2)%model_hyper_parameters.magnets_per_period], magnet_thickness = model_hyper_parameters.end_magnet_thickness[0]) 
     
     loc_offset[1] += model_hyper_parameters.end_magnet_thickness[0] + model_hyper_parameters.shim
     
     mag3 = magnet(model_hyper_parameters, loc_offset,mat[(Mus-1)%model_hyper_parameters.magnets_per_period], magnet_thickness = model_hyper_parameters.end_magnet_thickness[0]) 
     
     
     loc_offset[1] = (((model_hyper_parameters.totalmagnets-1)/2.0) * 
                       (model_hyper_parameters.nominal_fmagnet_dimensions[1] + 
                        model_hyper_parameters.shim) + 
                       model_hyper_parameters.nominal_fmagnet_dimensions[1]/2.0 + 
                       model_hyper_parameters.shim +
                       model_hyper_parameters.end_magnet_thickness[0]/2.0
                       )
     
     mag4 = magnet(model_hyper_parameters, loc_offset,mat[(Mds+1)%model_hyper_parameters.magnets_per_period], magnet_thickness = model_hyper_parameters.end_magnet_thickness[0]) 
     loc_offset[1] += model_hyper_parameters.end_magnet_thickness[0] + model_hyper_parameters.shim
     
     mag5 = magnet(model_hyper_parameters, loc_offset,mat[(Mds+2)%model_hyper_parameters.magnets_per_period], magnet_thickness = model_hyper_parameters.end_magnet_thickness[0]) 
     loc_offset[1] += model_hyper_parameters.end_magnet_thickness[0] + model_hyper_parameters.end_separation
     
     mag6 = magnet(model_hyper_parameters, loc_offset,mat[(Mds+3)%model_hyper_parameters.magnets_per_period], magnet_thickness = model_hyper_parameters.end_magnet_thickness[0]) 
     
     
     self.cont.wradObjAddToCnt([mag1.cont, mag2.cont, mag3.cont, mag4.cont, mag5.cont, mag6.cont])
Пример #6
0
 def __init__(self, model_hyper_parameters = parameters.model_parameters(), magnet = ms.appleMagnet):
     '''
     Constructor
     '''
     #def appleArray(model_hyper_parameters, loc_offset, halbach_direction = -1):
     self.cont = wrd.wradObjCnt([])
     
     loc_offset = [0,0,0]
     
     loc_offset[1] = -((model_hyper_parameters.totalmagnets-1)/2.0) * (model_hyper_parameters.nominal_fmagnet_dimensions[1] + model_hyper_parameters.shim)
     M = []
     mat = []
     for i in range(model_hyper_parameters.magnets_per_period):
         #M.append([halbach_direction * np.sin(i*np.pi/2.0)*model_hyper_parameters.M*np.sin(2*np.pi*model_hyper_parameters.Mova/360.0),halbach_direction * np.sin(i*np.pi/2.0)*model_hyper_parameters.M * np.cos(2*np.pi*model_hyper_parameters.Mova/360.0), np.cos(i*np.pi/2.0)*model_hyper_parameters.M])
         M.append([np.cos(i*2*np.pi/model_hyper_parameters.magnets_per_period)*model_hyper_parameters.M*np.sin(2*np.pi*model_hyper_parameters.Mova/360.0),-1 * np.sin(i*2*np.pi/model_hyper_parameters.magnets_per_period)*model_hyper_parameters.M, np.cos(i*2*np.pi/model_hyper_parameters.magnets_per_period)*model_hyper_parameters.M * np.cos(2*np.pi*model_hyper_parameters.Mova/360.0)])
         
         mat.append(wrdm.wradMatLin(model_hyper_parameters.ksi,M[i]))
     
     for x in range(-int((model_hyper_parameters.totalmagnets-1)/2),int(1+(model_hyper_parameters.totalmagnets-1)/2)):#0,model_hyper_parameters.appleMagnets
         
         mag = magnet(model_hyper_parameters, loc_offset,mat[(x)%model_hyper_parameters.magnets_per_period]) 
         loc_offset[1] += model_hyper_parameters.nominal_fmagnet_dimensions[1] + model_hyper_parameters.shim
         self.cont.wradObjAddToCnt([mag.cont])
Пример #7
0

if __name__ == '__main__':

    #my parameter list
    '''    origin = np.zeros(3)
    mainmagthick = 5
    mainmagdimension = 30
    clamput = 5
    direction = 'y'
    '''
    #ATHENA_II Parameters
    AII = parameters.model_hyper_parameters()

    #magnet Material [Bx,By,Bz]
    mat1 = wrdm.wradMatLin(AII.ksi, [0, 0, AII.M])

    #my magnet model

    a = ms.appleMagnet(AII)
    magcol = [(2 + x) / 4.0 for x in [0, AII.M, 0]]
    a.cont.wradObjDrwAtr(magcol, 2)
    a.cont.wradObjDivMag([3, 2, 1])

    a1 = ms.compMagnet(AII, [0, 0, 0])
    a1.cont.wradObjDrwAtr(magcol, 2)
    a1.cont.wradObjDivMag([3, 2, 1])

    #    rd.ObjDrwOpenGL(a.radobj)
    #    rd.ObjDrwOpenGL(a1.radobj)
Пример #8
0
 def __init__(self, **kwargs):
     #h5py string type
     h5str = h5.special_dtype(vlen=str) 
     #general
     
     prop_defaults = {
         "origin": np.zeros(3), #set the origin of the device. Default is array([0., 0., 0.])
         "coordinate_names" :np.array(['X','S','Z'], dtype = h5str),
         "pointsperperiod" : 20,
         "block_subdivision" : [2,3,1],
         
         ######  Undulator Parameters  ######
         
         "type" : "Compensated_APPLE",
         "beams" : 2,
         "quadrants" : 4,
         "rows_per_quadrant" : 3,
         "rows" : 12, 
         "periods" : 3, # Number of Periods of the APPLE Undulator
         "minimumgap" : 2, # Minimum designed gap in mm
         "gap" : 5, #Default Gap to calculate at
         "shim" : 0.1, # The gap between each magnet in a row / magnet array.
         "periodlength" : 15, # The period length of the undulator
         "halbach_direction" : 1,  # a value to determine the sense of magnet rotation along the axis. 1 = Field BELOW array. -1 Field ABOVE array 
         "magnets_per_period" : 4, # This number is almost exclusively 4 in undulator Halbach arrays. But it doesn't *have* to be.
         
         #####  APPLE Undulator Parameters  #####
         "rowtorowgap": 0.5, # for APPLE devices the distance between functional rows on the same jaw
         "shiftmode" : 'circular', # Polarisation mode of the undulator ; 'circular' (parallel) or 'linear' (antiparallel)
         "rowshift" : 0, # distance of row shift in mm
         "jawshift" : 0, #distance of jawshift in mm
         "end_separation" : 2.5, #separation of end magnet in usual APPLE end constellation
         
         #####  Compensated APPLE Undulator Parameters  #####
         "compappleseparation" : 15.0, # The gap between functional magnets and compenation magnets
         
         #####  Magnet Shape  #####
         
         "square_magnet" : False,
         "nominal_fmagnet_dimensions" : [30.0,0.0,30.0], # The nominal maximal magnet dimension for the functional magnets [mm]
         "apple_clampcut" : 5.0, # The size of the square removed for clamping an APPLE magnet [mm]
         "magnet_chamfer" : [5.0,0.0,5.0], # Dimensions of chamfer for a rectangular magnet (to make it octagonal) [mm]
         "direction" : 'y', # The direction of extrusion - along the direction of travel of the electrons. Dimensions propogate in the order [z,y,x]
     
         #####  Compensation Magnets #####
         
         "nominal_cmagnet_dimensions" : [15.0,0.0,30.0], # dimensions of the compensation magnets [mm]
         "comp_magnet_chamfer" : [5.0,0.0,5.0],
         "nominal_hcmagnet_dimensions" : [15.0,0.0,30.0], # dimensions of the compensation magnets [mm]
         "hcomp_magnet_chamfer" : [5.0,0.0,5.0],
         "nominal_vcmagnet_dimensions" : [15.0,0.0,30.0], # dimensions of the compensation magnets [mm]
         "vcomp_magnet_chamfer" : [5.0,0.0,5.0],
         
         #####  Magnet Material #####
         
         "ksi" : [.019, .06], # Permeability - anisotropic
         "M" : 1.21*1.344, # Block Remanence [T]
         "Mova" : 0.0 # Off Vertical Angle of Vertical type magnet blocks [degrees]
         
         
     }
     
     for (prop, default) in prop_defaults.items():
         setattr(self, prop, kwargs.get(prop, default))
     
     ###Derived Attributes###
     
     #Undulator
     self.totalmagnets = int(self.periods*self.magnets_per_period + 1);
     
     #magnet thicknesses
     self.nominal_fmagnet_dimensions[1] = (self.periodlength-self.magnets_per_period * self.shim) / self.magnets_per_period
     self.nominal_cmagnet_dimensions[1] = self.nominal_fmagnet_dimensions[1]
     self.nominal_hcmagnet_dimensions[1] = self.nominal_fmagnet_dimensions[1]
     self.nominal_vcmagnet_dimensions[1] = self.nominal_fmagnet_dimensions[1]
     
     
     #square magnet dimensions
     if self.square_magnet is not False:
         self.nominal_fmagnet_dimensions[0] = self.square_magnet
         self.nominal_fmagnet_dimensions[2] = self.square_magnet
         self.nominal_cmagnet_dimensions[0] = self.square_magnet/2.0
         self.nominal_cmagnet_dimensions[2] = self.square_magnet+self.comp_magnet_chamfer[2]
                 
     #end_magnet_thicknesses
     self.end_magnet_thickness = [(self.periodlength / 8.0) - self.shim]
     
     
     
     #magnetmaterial
     self.magnet_material = wrdm.wradMatLin(self.ksi,[0,0,self.M])
     
     #core undulator parameters
     if self.type == 'Compensated_APPLE':
         self.magnet_rows = 12