def calc_field_integrals(radia_object, zmin, zmax, znpts, x=0, y=0):
    posz, bx, by, bz = _np.transpose(
        _rad.FldLst(radia_object, "b", [x, y, zmin], [x, y, zmax], znpts,
                    "arg", zmin))

    posz_m = _np.array(posz) / 1000
    ibx = _integrate.cumtrapz(bx, posz_m, initial=0)
    iby = _integrate.cumtrapz(by, posz_m, initial=0)
    ibz = _integrate.cumtrapz(bz, posz_m, initial=0)
    iibx = _integrate.cumtrapz(ibx, posz_m)
    iiby = _integrate.cumtrapz(iby, posz_m)
    iibz = _integrate.cumtrapz(ibz, posz_m)

    return _np.array([ibx, iby, ibz]), _np.array([iibx, iiby, iibz])
def get_field_amplitude(radia_object,
                        field,
                        period_length,
                        nr_periods,
                        x=0,
                        y=0,
                        method='sine'):
    if radia_object is None:
        return None

    if method not in ('sine', 'hilbert'):
        raise ValueError('Invalid value for method argument.')

    if nr_periods > 1:
        zmin = -period_length * (nr_periods - 1) / 2
        zmax = period_length * (nr_periods - 1) / 2
        zpts = 101 * (nr_periods - 1)
    else:
        zmin = -period_length / 2
        zmax = period_length / 2
        zpts = 101

    z, b = _np.transpose(
        _rad.FldLst(radia_object, field, [x, y, zmin], [x, y, zmax], zpts,
                    "arg", zmin))
    bamp_init = _np.max(_np.abs(b))

    if method == 'sine':
        p = _optimize.curve_fit(_utils.fit_cosine,
                                z,
                                b,
                                p0=[bamp_init, 2 * _np.pi / period_length,
                                    0])[0]
        bamp = p[0]
    elif method == 'hilbert':
        bhilbert = _hilbert(b)
        bamp = _np.mean(_np.abs(bhilbert))

    return bamp
Exemple #3
0
 def calculate_B_field(self, axis = 'default'):
     #define axis
     if axis == 'default':
         limit = self.model.model_parameters.periodlength
         axis = [[0,-limit,0],[0,limit,0]]
     self.axis = axis
     #solve for the fieldlist
     tempb = rd.FldLst(self.model.cont.radobj,'bxbybz',axis[0],axis[1],int(1+self.model.model_parameters.pointsperperiod*2),'arg',axis[0][1])
     
     #absolutely temporary streamplot example
     #self.model.cont.wradStreamPlot(corner1 = np.array([-10,-10,0]), corner2 = np.array([10,10,0]), fields = 'bxbz')
     
 #make that list a numpy array
     self.bfield = np.array(tempb)
     
     self.bmax = np.array([np.max(np.abs(self.bfield[:,1])),np.max(np.abs(self.bfield[:,2])),np.max(np.abs(self.bfield[:,3]))])
     self.beff = np.linalg.norm(self.bmax)
     
     self.solved_attributes.append('bfield')
     self.solved_attributes.append('bmax')
     self.solved_attributes.append('beff')
     '''solve for B field for central 2 periods or minimum distance
Exemple #4
0
    #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])

    #make that list a numpy array
    bbn = np.array(bb)

    #plot the calculated field
    plt.plot(bbn[:, 0], bbn[:, 1:4])
    plt.legend(['bx', 'by', 'bz'])

    #show it
    #    plt.show()

    #list of things to show (max 4)
    quads = ['q1', 'q2', 'q3', 'q4']
    #calculate the field on a line due to each element of list
Exemple #5
0
    print(b.objectlist)

    #rd.ObjDrwOpenGL(a.radobj)
    #rd.ObjDrwOpenGL(b.radobj)

    #######PLOT SOMETHING#######################
    tmpob = f
    tmpob.wradSolve(0.001, 1000)

    z = 0
    x1 = -15
    x2 = 0
    ymax = 400
    nump = 2001

    Bz1 = rd.FldLst(tmpob.radobj, 'bz', [x1, -ymax, z], [x1, ymax, z], nump,
                    'arg', 0)
    Bz2 = rd.FldLst(tmpob.radobj, 'bz', [x2, -ymax, z], [x2, ymax, z], nump,
                    'arg', 0)

    Bx1 = rd.FldLst(tmpob.radobj, 'bx', [x1, -ymax, z], [x1, ymax, z], nump,
                    'arg', 0)
    Bx2 = rd.FldLst(tmpob.radobj, 'bx', [x2, -ymax, z], [x2, ymax, z], nump,
                    'arg', 0)

    Bz1 = np.array(Bz1)
    Bz2 = np.array(Bz2)

    Bx1 = np.array(Bx1)
    Bx2 = np.array(Bx2)

    #set up plot
    print('Interaction Matrix : ', size, 'X', size, 'or',
          round(size * size * 4 / 1000000, 3), 'MB')
    print('Gradient = ', round(Bz, 4), 'T/m')
    print('Int. Quad. @ 1 mm = ', round(Iz, 5), 'T')
    print('Delta Int. Quad. @ 10 mm = ', round(100 * (Iz1 / Iz - 1), 2), '%')

    #Display the Geometry
    rad.ObjDrwOpenGL(g)

    #Magnetic Field Plots
    z = 0
    x1 = 0
    x2 = 30
    ymax = 40
    np = 20
    Bz1 = rad.FldLst(g, 'bz', [x1, 0, z], [x1, ymax, z], np, 'arg', 0)
    Bz2 = rad.FldLst(g, 'bz', [x2, 0, z], [x2, ymax, z], np, 'arg', 0)
    uti_plot1d_m([Bz1, Bz2],
                 labels=[
                     'Y', 'Vertical Magnetic Field',
                     'Vertical Magnetic Field vs. Vertical Position'
                 ],
                 units=['mm', 'T'],
                 styles=['-b.', '--r.'],
                 legend=['X = {} mm'.format(x1), 'X = {} mm'.format(x2)])

    #Magnetic Field Integral Plots
    z = 0
    ymin = 0.001
    ymax = 10
    npy = 20