Skip to content

Commit ed52596

Browse files
committed
fixed bug in Tupan interface where values passed to ParticleSystem where ndarrays of dim 0 instead of floats
1 parent 20bb7f5 commit ed52596

1 file changed

Lines changed: 35 additions & 26 deletions

File tree

src/amuse_tupan/interface.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
2+
from amuse.datamodel.particles import Particle, Particles
33
from amuse.community import *
44
from amuse.community.interface.gd import GravitationalDynamicsInterface
55
from amuse.community.interface.gd import GravitationalDynamics
@@ -38,7 +38,7 @@ def __init__(self):
3838
self.integrator_method = "sia21h.dkd"
3939
self.pn_order = 0
4040
self.clight = None
41-
self.particles = []
41+
self.particles = Particles()
4242
self.particles_initialized = False
4343

4444
def initialize_code(self):
@@ -60,43 +60,52 @@ def commit_parameters(self):
6060
return 0
6161

6262
def commit_particles(self):
63-
num = len(self.particles)
64-
ps = ParticleSystem(nstars=num)
63+
ps = ParticleSystem(nstars=len(self.particles))
6564
for (i, p) in enumerate(self.particles):
6665
ps.id[i] = i
6766
ps.mass[i] = p.mass
6867
ps.radius[i] = p.radius # XXX: 'radius' is not yet used in Tupan.
6968
ps.eps2[i] = self.eps2/2
70-
ps.rx[i] = p.rx
71-
ps.ry[i] = p.ry
72-
ps.rz[i] = p.rz
69+
ps.rx[i] = p.x
70+
ps.ry[i] = p.y
71+
ps.rz[i] = p.z
7372
ps.vx[i] = p.vx
7473
ps.vy[i] = p.vy
7574
ps.vz[i] = p.vz
76-
self.integrator = Integrator(self.eta,
77-
self.time_begin,
78-
ps,
79-
method=self.integrator_method,
80-
pn_order=self.pn_order,
81-
clight=self.clight)
75+
76+
self.integrator = Integrator(
77+
self.eta,
78+
self.time_begin,
79+
ps,
80+
method=self.integrator_method,
81+
pn_order=self.pn_order,
82+
clight=self.clight
83+
)
8284
return 0
8385

8486
def synchronize_model(self):
8587
return 0
8688

87-
def new_particle(self, index_of_the_particle,
88-
mass, radius, x, y, z, vx, vy, vz):
89-
ps = ParticleSystem(nstars=1)
90-
ps.mass[0] = mass
91-
ps.radius[0] = radius
92-
ps.rx[0] = x
93-
ps.ry[0] = y
94-
ps.rz[0] = z
95-
ps.vx[0] = vx
96-
ps.vy[0] = vy
97-
ps.vz[0] = vz
98-
self.particles.append(ps)
99-
index_of_the_particle.value = len(self.particles)-1
89+
def new_particle(
90+
self,
91+
index_of_the_particle,
92+
mass,
93+
radius,
94+
x, y, z,
95+
vx, vy, vz,
96+
):
97+
ps = Particle()
98+
ps.mass = mass
99+
ps.radius = radius
100+
ps.x = x
101+
ps.y = y
102+
ps.z = z
103+
ps.vx = vx
104+
ps.vy = vy
105+
ps.vz = vz
106+
index_of_the_particle.value = len(self.particles)
107+
self.particles.add_particle(ps)
108+
100109
return 0
101110

102111
def set_state(self, index_of_the_particle,

0 commit comments

Comments
 (0)