defevolve_particles(pp_all,pv_all,m_all,dt):"""
Evolve particles in time via leap-frog integrator scheme.
Parameters
----------
pp_all : np.ndarray
2-D array containing (x, y, z) positions for all particles.
Shape is (N, 3) where N is the number of particles.
pv_all : np.ndarray
2-D array containing (x, y, z) velocities for all particles.
Shape is (N, 3) where N is the number of particles.
m_all : np.ndarray
1-D array containing masses for all particles, length N, where
N is the number of particles.
dt : float
Evolve system for time dt.
Returns
-------
Updated particle positions and particle velocities, each being a 2-D
array with shape (N, 3), where N is the number of particles.
"""# Make copies of position/velocity arrays that we can modify in-place.pp=pp_all.copy()pv=pv_all.copy()N=len(m_all)# Number of particles in systemdims=pp_all.shape[-1]# Dimensionality of problem# Compute net force vectors on all particlesforces=netGravForces(m_all,pp_all)# Leap-frog method takes two half-steps (first dimension of acc array)acc=np.zeros([2,N,dims])# Leap-frog integrator takes two half-stepsstep=0whilestep<2:# Loop over particles, compute acceleration,# update positions and velocitiesforkinxrange(N):# Rec-calculate acceleration at each half-stepacc[step,k]=forces[k]/m_all[k]# Update position on first half-step, velocity on secondifstep==0:pp[k,:]=pp[k]+pv[k]*dt+0.5*acc[0,k]*dt**2else:pv[k,:]=pv[k]+0.5*(acc[0,k]+acc[1,k])*dt
step+=1returnpp,pv