# 想知道为什么加法会失败？ptr是什么属性？

``````class adjustnbody:
def __init__(self,N:ti.f32,mass:ti.f32,dimension:ti.f32):
self.PI = ti.atan2(1,1)*4
self.G = ti.field(ti.f32,shape=())

self.dim = dimension
self.n = N
self.mass = mass
self.pos = ti.Vector.field(self.dim,ti.f32,self.n)
self.vel = ti.Vector.field(self.dim,ti.f32,self.n)
self.force = ti.Vector.field(self.dim,ti.f32,self.n)
self.color = ti.Vector.field(3,ti.f32,self.n)
if self.dim == 2:
self.offset = ti.Vector([np.random.uniform(),np.random.uniform()])
self.expand = ti.Vector([1,1])
self.originvel = ti.Vector([0,0])
elif self.dim == 3:
self.offset = ti.Vector([np.random.uniform(),np.random.uniform(),np.random.uniform()])
self.expand = ti.Vector([1,1,1])
self.originvel = ti.Vector([0,0,0])
@ti.kernel
def initial(self,center:ti.template(),expand_size:ti.f32,init_vel:ti.f32):

for i in range(self.n):
if self.n == 1:
self.pos[i] = center
for j in ti.static(range(self.dim)):
self.vel[i][j] = 0
else:
#off, ovel = self.xvcalcu(self.dim,init_vel,expand_size)
self.offset += -self.expand*expand_size*0.5
self.originvel[0] = -self.offset[1]
self.originvel[1] = self.offset[0]
self.originvel *= init_vel
self.pos[i] = center+self.offset
self.vel[i] = self.originvel
``````

1 Like

1 Like

`self.offset = ti.Vector.field(2, ti.f32, ())`

`self.offset[None] += -self.expand*expand_size*0.5`