python中的while循环语句的数组循环_在while循环中附加数组

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值