ptclu = consts.c*np.sqrt(ptclGamma**2 - 1.) x = [np.array([1., 0., 0.])] v = [np.array([0., ptclu, 0.])] fields = constEM() efield = [fields.getEField(x)] bfield = [fields.getBField(x)] expectedX = np.array([1.00000000e+00, 2.99777763e+00, 1.51624746e-16]) expectedU = np.array([3.51764015e-02, 3.02775541e+10, 3.06281988e-06]) tol = 1.e-8 # Sequence tests the implementation of drift-kick-drift 2nd order # integrator scheme. This makes sure x and v are synchronous in time at # the end of the simulation # half move forward x = pusher.halfmove(v, x, 1) # full accelerate and move u = pusher.accelerate(v, efield, bfield) x = pusher.move(v, x) # half move backward x = pusher.halfmove(v, x, -1) failed = False xerror = x[0] - expectedX uerror = u[0] - expectedU metricX = np.dot(xerror, xerror)/np.dot(expectedX, expectedX) metricV = np.dot(uerror, uerror)/np.dot(expectedU, expectedU) print 'BorisVay pusher test error:' print 'Xerror =', metricX print 'Verror =', metricV
# Create a relativistic particle with 1 mm-mrad "emittance" in the # transverse gradient direction gamma0 = 100. v0 = consts.c * (1. - 1/gamma0**2) pos = np.array([[0., 0.0025, 0.]]) vel = np.array([[0., -0.0025/consts.c, gamma0*v0]]) # Set up the length of the simulation undulatorPeriods = 10 undulatorLength = undulatorPeriods*lambda_w nsteps = int(undulatorLength/(consts.c * dt)) t = 0. # Initial half-move pos = pusher.halfmove(vel, pos, +1) t += 0.5*dt gamma = np.sqrt(np.dot(vel[0], vel[0])/consts.c**2 + 1) x = [] x.append(pos[0][0]) y = [] y.append(pos[0][1]) z = [] z.append(pos[0][2]) vx = [] vx.append(vel[0][0]/(gamma*consts.c)) vy = [] vy.append(vel[0][1]/(gamma*consts.c)) vz = [] vz.append(vel[0][2]/(gamma*consts.c))
uDir = 1.4*np.pi uDir2 = 0.1*np.pi v0 = [np.array([uMag * np.cos(uDir) * np.sin(uDir2), uMag * np.sin(uDir) * np.sin(uDir2), uMag * np.cos(uDir2)])] x0 = [np.zeros(3)] x.append(x0[0][0]) y.append(x0[0][1]) z.append(x0[0][2]) gammaArray = [] gamma = np.sqrt(np.dot(v0[0], v0[0])/consts.c**2 + 1) gammaArray.append(gamma) x0 = pusher.halfmove(v0, x0, +1) for idx in range(10000): v0 = pusher.accelerate(v0, E, B) x0 = pusher.move(v0, x0) x.append(x0[0][0]) y.append(x0[0][1]) z.append(x0[0][2]) gamma = np.sqrt(np.dot(v0[0], v0[0])/consts.c**2 + 1) gammaArray.append(gamma) x0 = pusher.halfmove(v0, x0, -1) fig = plt.figure() ax = fig.add_subplot(111, projection='3d')