0
두 가지 종의 입자 충돌을 모델링했습니다. 각 클래스를 정의하기 위해 클래스를 사용하고 입자 위치와 속도를 유지하는 배열 클래스를 사용하고 있습니다.Python 클래스에 정의 된 배열의 원소 교환하기
class Particle(object):
def __init__(self,num):
self.x=numpy.zeros((num,1)) #Position
self.v=numpy.zeros((num,3)) #Velocity
class Species(object):
def __init__(self):
self.mass=[]
self.spwt=[]
self.np=[]
self.np_alloc=[]
self.part=[]
종은 :
충돌 제가
클래스 같이 별도의 파일에 정의 된 종 (B)의 입자의 속도와 종 (A)의 입자의 속도를 바꿀 필요가 발생
주 파일에 작성 :#variables to hold species
A = struct.Species()
B = struct.Species()
#set species data
A.mass = 1
A.np = 0
A.spwt=spwt
A.np_alloc = num
A.part = struct.Particle(A.np_alloc)
B.mass = 1
B.np = 0
B.spwt=spwt
B.np_alloc = int(cloud_den/spwt/cloud_len)
B.part = struct.Particle(B.np_alloc)
을 그리고 난 입자 속도를 교환 할 때
,451,515,print A.part.v[p1]
print B.part.v[p2]
A.part.v[p1],B.part.v[p2]=B.part.v[p2],A.part.v[p1]
print A.part.v[p1]
print B.part.v[p2]
출력은 다음과 같습니다
[ 1000. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]