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)) gammaArray = [] gammaArray.append(gamma) for idx in range(nsteps): E = myplanarundulator.evaluateEField(pos, t) B = myplanarundulator.evaluateBField(pos, t) vel = pusher.accelerate(vel, E, B) pos = pusher.move(vel, pos) gamma = np.sqrt(np.dot(vel[0], vel[0])/consts.c**2 + 1) x.append(pos[0][0]) vx.append(vel[0][0]/(gamma*consts.c)) y.append(pos[0][1]) vy.append(vel[0][1]/(gamma*consts.c)) z.append(pos[0][2]) vz.append(vel[0][2]/(gamma*consts.c)) gammaArray.append(gamma) t += dt # Backwards half-move pos = pusher.halfmove(vel, pos, -1) t -= 0.5*dt
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') ax.plot(x, y, z, linewidth=2) ax.plot(x, y, zs=min(z), zdir='z', alpha=0.25, c='k') ax.plot(x, z, zs=min(y), zdir='y', alpha=0.25, c='k')
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 if metricX > tol:
pusher = RbBorisVay(charge, mass, dt) gammavx = [] gammavxIdeal=[] tArray = [] v0 = [np.array([0., 0., 0.])] x0 = [np.zeros(3)] t = 0. x0 = pusher.halfmove(v0, x0, +1) t += 0.5*dt for idx in range(1000): Eomt = E*np.cos(omega*t) v0 = pusher.accelerate(v0, Eomt, B) x0 = pusher.move(v0, x0) gammavx.append(v0[0][0]) gammavxIdeal.append((E0*charge/(mass*omega))*(np.sin(omega*t))) tArray.append(t) t += dt x0 = pusher.halfmove(v0, x0, -1) t -= dt plt.plot(tArray, gammavx, c='r', label='computed') plt.plot(tArray, gammavxIdeal, c='b', label='theoretical') plt.legend() plt.xlabel(r'$t$ [sec]') plt.ylabel(r'$\gamma v_x$ [m/s]')