Example #1
0
def exact_slice(slices, xg_in, yg_in, zg_in, xg_out, yg_out, z_out):
    slices_array = np.empty([len(xg_in), len(yg_in), len(zg_in)])
    for i in range(len(zg_in) - 1):
        slices_array[:, :, i] = slices[i]

    tinterp = ti.Tricubic_Interpolation(A=slices_array,
                                        x0=xg_in[0],
                                        y0=yg_in[0],
                                        z0=zg_in[0],
                                        dx=xg_in[1] - xg_in[0],
                                        dy=yg_in[1] - yg_in[0],
                                        dz=zg_in[1] - zg_in[0])

    the_slice = np.empty([len(xg_out), len(yg_out), 8])
    for ii, x_out in enumerate(xg_out):
        for jj, y_out in enumerate(yg_out):
            the_slice[ii, jj, 0] = tinterp.val(x_out, y_out, z_out)
            the_slice[ii, jj, 1] = tinterp.ddx(x_out, y_out, z_out)
            the_slice[ii, jj, 2] = tinterp.ddy(x_out, y_out, z_out)
            the_slice[ii, jj, 3] = tinterp.ddz(x_out, y_out, z_out)
            the_slice[ii, jj, 4] = tinterp.ddxdy(x_out, y_out, z_out)
            the_slice[ii, jj, 5] = tinterp.ddxdz(x_out, y_out, z_out)
            the_slice[ii, jj, 6] = tinterp.ddydz(x_out, y_out, z_out)
            the_slice[ii, jj, 7] = tinterp.ddxdydz(x_out, y_out, z_out)
    return the_slice
Example #2
0
    def __init__(self,fname, scale=1., method='Exact'):
        ob = h5py.File(fname)
        xg = ob['xg'][()]
        yg = ob['yg'][()]
        zg = ob['zg'][()]
        phi = scale*ob['phi'][()]
        
        #ob = mfm_e.myloadmat(fname)
        #xg = ob['xg']
        #yg = ob['yg']
        #zg = ob['zg']
        #phi = scale*ob['phi'].transpose(1,2,0)
        
        print('ecloud:')
        print('\t xg: %f'%xg[-1])
        print('\t yg: %f'%yg[-1])
        print('\t zg: %f'%zg[-1])
        print('\t dx: %f'%(xg[1]-xg[0]))
        print('\t dy: %f'%(yg[1]-yg[0]))
        print('\t dz: %f'%(zg[1]-zg[0]))
        self.TI = ti.Tricubic_Interpolation(A=phi, x0=xg[0], y0=yg[0], z0=zg[0],
                                       dx=xg[1]-xg[0], dy=yg[1]-yg[0], dz=zg[1]-zg[0], method = method)

        #dipolar kicks
        xkick, ykick, zkick = self.TI.kick(0.,0.,0.)
        self.px0 = xkick
        self.py0 = ykick
        self.delta0 = zkick
nx = 5
ny = 7
nz = 9
A = np.random.rand(nx, ny, nz, 8) * 1.0e-3
dx = 0.001
dy = 0.002
dz = 0.003
x0 = -(nx // 2) * dx
y0 = -(ny // 2) * dy
z0 = -(nz // 2) * dz

TI = cTI.Tricubic_Interpolation(A=A,
                                dx=dx,
                                dy=dy,
                                dz=dz,
                                x0=x0,
                                y0=y0,
                                z0=z0,
                                method="Exact")

test_x = x0 + TI.ix_bound_up * dx * np.random.rand(n_part)
test_y = y0 + TI.iy_bound_up * dy * np.random.rand(n_part)
test_z = z0 + TI.iz_bound_up * dz * np.random.rand(n_part)

# for x,y,z in zip(test_x,test_y,test_z):
#    print(x,y,z)
#    TI.val(x,y,z)

for i_part in range(n_part):
    part = pysixtrack.Particles()
    part.x = test_x[i_part]
Example #4
0
ez = np.empty([Nx, Ny, Nz, 8])

for kk in range(Nz):
    phi[:, :, kk, :] = kfm.h5_to_dict(pinch,
                                      group='slices/slice%d' % kk)['phi']
    ex[:, :, kk, :] = kfm.h5_to_dict(epinch,
                                     group='slices/ex_slice%d' % kk)['ex']
    ey[:, :, kk, :] = kfm.h5_to_dict(epinch,
                                     group='slices/ey_slice%d' % kk)['ey']
    ez[:, :, kk, :] = kfm.h5_to_dict(epinch,
                                     group='slices/ez_slice%d' % kk)['ez']

TI = ti.Tricubic_Interpolation(A=phi,
                               x0=x0,
                               y0=y0,
                               z0=z0,
                               dx=dx,
                               dy=dy,
                               dz=dz,
                               method='Exact')
TIex = ti.Tricubic_Interpolation(A=ex,
                                 x0=x0,
                                 y0=y0,
                                 z0=z0,
                                 dx=dx,
                                 dy=dy,
                                 dz=dz,
                                 method='Exact')
TIey = ti.Tricubic_Interpolation(A=ey,
                                 x0=x0,
                                 y0=y0,
                                 z0=z0,
                                   pic_in,
                                   fname,
                                   k + 3,
                                   dz,
                                   n_slices,
                                   symmetric_slice_2D=symmetric2D)
 else:
     slices[3, :, :] = get_slice(pic_out,
                                 pic_in,
                                 fname,
                                 k + 3,
                                 symmetric_slice_2D=symmetric2D)
 tinterp = ti.Tricubic_Interpolation(A=slices,
                                     x0=z0_in,
                                     y0=x0_in,
                                     z0=y0_in,
                                     dx=dz,
                                     dy=dx_in,
                                     dz=dy_in)
 if do_kicks:
     tinterp_dx = ti.Tricubic_Interpolation(A=ex_slices,
                                            x0=z0_in,
                                            y0=x0_in,
                                            z0=y0_in,
                                            dx=dz,
                                            dy=dx_in,
                                            dz=dy_in)
     tinterp_dy = ti.Tricubic_Interpolation(A=ey_slices,
                                            x0=z0_in,
                                            y0=x0_in,
                                            z0=y0_in,