def test2D(potential, field): potAccept2D = np.zeros((NX_2D + 1, NY_2D + 1)) fieldAccept2D = np.zeros((NX_2D + 1, NY_2D + 1, 2)) for i, j in np.ndindex(potAccept2D.shape): potAccept2D[i, j] = potential(X0_2D + DX_2D * i, Y0_2D + DY_2D * j) fieldAccept2D[i, j] = field(X0_2D + DX_2D * i, Y0_2D + DY_2D * j) test(esSolve.potentialToElectricField(potAccept2D, [DX_2D, DY_2D]), fieldAccept2D)
def test1D(potential, field): potAccept1D = np.zeros(NX_1D + 1) fieldAccept1D = np.zeros((NX_1D + 1, 1)) for i in range(NX_1D + 1): potAccept1D[i] = potential(X0_1D + DX_1D * i) fieldAccept1D[i] = field(X0_1D + DX_1D * i) test(esSolve.potentialToElectricField(potAccept1D, [DX_1D]), fieldAccept1D)
def test2D(potential,field): potAccept2D = np.zeros((NX_2D+1,NY_2D+1)) fieldAccept2D = np.zeros((NX_2D+1,NY_2D+1,2)) for i,j in np.ndindex(potAccept2D.shape): potAccept2D[i,j] = potential(X0_2D+DX_2D*i,Y0_2D+DY_2D*j) fieldAccept2D[i,j] = field( X0_2D+DX_2D*i,Y0_2D+DY_2D*j) test(esSolve.potentialToElectricField(potAccept2D,[DX_2D,DY_2D]), fieldAccept2D)
def test1D(potential,field): potAccept1D = np.zeros(NX_1D+1) fieldAccept1D = np.zeros((NX_1D+1,1)) for i in range(NX_1D+1): potAccept1D[i] = potential(X0_1D+DX_1D*i) fieldAccept1D[i] = field( X0_1D+DX_1D*i) test(esSolve.potentialToElectricField(potAccept1D,[DX_1D]), fieldAccept1D)
def test3D(potential,field): potAccept3D = np.zeros((NX_3D+1,NY_3D+1,NZ_3D+1)) fieldAccept3D = np.zeros((NX_3D+1,NY_3D+1,NZ_3D+1,3)) for i,j,k in np.ndindex(potAccept3D.shape): # consider using np.fromfunction here potAccept3D[i,j,k] = potential(X0_3D+DX_3D*i,Y0_3D+DY_3D*j,Z0_3D+DZ_3D*k) fieldAccept3D[i,j,k] = field( X0_3D+DX_3D*i,Y0_3D+DY_3D*j,Z0_3D+DZ_3D*k) test(esSolve.potentialToElectricField(potAccept3D,[DX_3D,DY_3D,DZ_3D]), fieldAccept3D)
def test3D(potential, field): potAccept3D = np.zeros((NX_3D + 1, NY_3D + 1, NZ_3D + 1)) fieldAccept3D = np.zeros((NX_3D + 1, NY_3D + 1, NZ_3D + 1, 3)) for i, j, k in np.ndindex(potAccept3D.shape): # consider using np.fromfunction here potAccept3D[i, j, k] = potential(X0_3D + DX_3D * i, Y0_3D + DY_3D * j, Z0_3D + DZ_3D * k) fieldAccept3D[i, j, k] = field(X0_3D + DX_3D * i, Y0_3D + DY_3D * j, Z0_3D + DZ_3D * k) test( esSolve.potentialToElectricField(potAccept3D, [DX_3D, DY_3D, DZ_3D]), fieldAccept3D)
VN_NR, "gaussSeidel", relTol=0.0, absTol=1.0e-3 * (deltaV_NR), useCython=False) pot1D_R = esSolve.laplace1D(NX, DX, V0, VN_R, "gaussSeidel", relTol=0.0, absTol=1.0e-3 * (deltaV_R), useCython=False) # Compute E = - grad V on grid electricFieldOnGrid_NR = esSolve.potentialToElectricField(pot1D_NR, [DX]) electricFieldOnGrid_R = esSolve.potentialToElectricField(pot1D_R, [DX]) positions_NR = [electron_NR.position[0]] velocities_NR = [electron_NR.velocity[0]] positions_R_Rpush = [electron_R_Rpush.position[0]] velocities_R_Rpush = [electron_R_Rpush.velocity[0]] positions_R_NRpush = [electron_R_NRpush.position[0]] velocities_R_NRpush = [electron_R_NRpush.velocity[0]] for step in xrange(steps + 1): # Compute E at particle position electricFieldAtPoint_NR = esSolve.electricFieldAtPoint( electricFieldOnGrid_NR, [DX], [X0], electron_NR.position) electricFieldAtPoint_R_Rpush = esSolve.electricFieldAtPoint( electricFieldOnGrid_R, [DX], [X0], electron_R_Rpush.position)
electron_R_Rpush = particle(mass,charge,[X0_particle],[V0_particle]) electron_R_NRpush = particle(mass,charge,[X0_particle],[V0_particle]) # Time steps T_NR = 0.99*pow(-2.0*mass*pow(LX,2.0)/(charge*deltaV_NR),0.5) T_R = 0.99*pow(-2.0*mass*pow(LX,2.0)/(charge*deltaV_R),0.5) steps = 100 DT_NR = T_NR/steps DT_R = T_R/steps # Solve for potential pot1D_NR = esSolve.laplace1D(NX,DX,V0,VN_NR,"gaussSeidel",relTol=0.0,absTol=1.0e-3*(deltaV_NR),useCython=False) pot1D_R = esSolve.laplace1D(NX,DX,V0,VN_R,"gaussSeidel",relTol=0.0,absTol=1.0e-3*(deltaV_R),useCython=False) # Compute E = - grad V on grid electricFieldOnGrid_NR = esSolve.potentialToElectricField(pot1D_NR,[DX]) electricFieldOnGrid_R = esSolve.potentialToElectricField(pot1D_R,[DX]) positions_NR = [electron_NR.position[0]] velocities_NR = [electron_NR.velocity[0]] positions_R_Rpush = [electron_R_Rpush.position[0]] velocities_R_Rpush = [electron_R_Rpush.velocity[0]] positions_R_NRpush = [electron_R_NRpush.position[0]] velocities_R_NRpush = [electron_R_NRpush.velocity[0]] for step in xrange(steps+1): # Compute E at particle position electricFieldAtPoint_NR = esSolve.electricFieldAtPoint(electricFieldOnGrid_NR,[DX],[X0],electron_NR.position) electricFieldAtPoint_R_Rpush = esSolve.electricFieldAtPoint(electricFieldOnGrid_R,[DX],[X0],electron_R_Rpush.position) electricFieldAtPoint_R_NRpush = esSolve.electricFieldAtPoint(electricFieldOnGrid_R,[DX],[X0],electron_R_NRpush.position)