Skip to content

Commit

Permalink
Merge pull request #965 from rieder/fix/whitespace
Browse files Browse the repository at this point in the history
Fix code style (only) in tests
Applied with `autopep8 --select W293,E251,E111,E114,E117,E201,E202,E203,E211,E221,E222,E225,E227,E228,E231,E251,E261,E262,E265,E271,E272,E30,E502,E701,E703,E711,E714,W291,W292,W293,W391`
  • Loading branch information
rieder committed Jul 6, 2023
2 parents 93b833c + 9691393 commit 8332261
Show file tree
Hide file tree
Showing 163 changed files with 21,236 additions and 22,372 deletions.
6 changes: 3 additions & 3 deletions src/amuse/test/suite/codes_tests/gd_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ def test7(self):
# if they are implemented for the code, otherwise will call
# get_state multiple times
# todo, fi fails, need to check with inti
#self.assertAlmostRelativeEqual(instance.particles[-1].mass, new_particles[0].mass)
#self.assertAlmostRelativeEqual(instance.particles[-1].velocity, new_particles[0].velocity)
#self.assertAlmostRelativeEqual(instance.particles[-1].position, new_particles[0].position)
# self.assertAlmostRelativeEqual(instance.particles[-1].mass, new_particles[0].mass)
# self.assertAlmostRelativeEqual(instance.particles[-1].velocity, new_particles[0].velocity)
# self.assertAlmostRelativeEqual(instance.particles[-1].position, new_particles[0].position)
instance.particles.synchronize_to(particles)
self.assertEqual(len(particles), 99)
self.assertEqual(particles[-1], new_particles[0])
Expand Down
1 change: 0 additions & 1 deletion src/amuse/test/suite/codes_tests/legacy_support.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

156 changes: 76 additions & 80 deletions src/amuse/test/suite/codes_tests/test_aarsethzare.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,103 +22,103 @@ class TestAarsethZareInterface(TestWithMPI):
def test0(self):
instance = AarsethZareInterface()
instance.stop()

def test1(self):

instance = AarsethZareInterface()
time, x, y, z, vx, vy, vz, error = instance.evolve_triple(
[0,0,0],
[1,1,1],
[0, 0, 0],
[1, 1, 1],
[-10, 0, 10],
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0],
[1.0,1.0,1.0]
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[1.0, 1.0, 1.0]
)

print(time, x, y, z, vx, vy, vz, error)
self.assertEqual(error, 0)
self.assertAlmostRelativeEquals(y, [0,0,0])
self.assertAlmostRelativeEquals(z, [0,0,0])
self.assertAlmostRelativeEquals(y, [0, 0, 0])
self.assertAlmostRelativeEquals(z, [0, 0, 0])
self.assertAlmostRelativeEquals(x[-1], -x[0], 10)
self.assertAlmostRelativeEquals(x[1], 0, 10)
self.assertAlmostRelativeEquals(vx[-1], -vx[0], 10)
self.assertAlmostRelativeEquals(vx[1], 0, 10)
self.assertAlmostRelativeEquals(vy, [0,0,0])
self.assertAlmostRelativeEquals(vz, [0,0,0])


self.assertAlmostRelativeEquals(vy, [0, 0, 0])
self.assertAlmostRelativeEquals(vz, [0, 0, 0])

def test2(self):

instance = AarsethZareInterface()
time, x, y, z, vx, vy, vz, error = instance.evolve_triple(
[0,0],
[1,1],
[0, 0],
[1, 1],
[-10, 0],
[0,0],
[0,0],
[0,0],
[0,0],
[0,0],
[0, 0],
[0, 0],
[0, 0],
[0, 0],
[0, 0],
[1.0]
)

self.assertEqual(error, -1)


class TestAarsethZare(TestWithMPI):
def new_system_of_sun_and_earth_and_moon(self):
stars = datamodel.Stars(3)
sun = stars[0]
sun.mass = units.MSun(1.0)
sun.position = units.m(numpy.array((0.0,0.0,0.0)))
sun.velocity = units.ms(numpy.array((0.0,0.0,0.0)))
sun.position = units.m(numpy.array((0.0, 0.0, 0.0)))
sun.velocity = units.ms(numpy.array((0.0, 0.0, 0.0)))
sun.radius = units.RSun(1.0)

earth = stars[1]
earth.mass = units.kg(5.9736e24)
earth.radius = units.km(6371)
earth.position = units.km(numpy.array((149.5e6,0.0,0.0)))
earth.velocity = units.ms(numpy.array((0.0,29800,0.0)))
earth.radius = units.km(6371)
earth.position = units.km(numpy.array((149.5e6, 0.0, 0.0)))
earth.velocity = units.ms(numpy.array((0.0, 29800, 0.0)))

moon = stars[2]
moon.mass = units.kg(7.3477e22 )
moon.radius = units.km(1737.10)
moon.position = units.km(numpy.array((149.5e6 + 384399.0 ,0.0,0.0)))
moon.velocity = ([0.0,1.022,0] | units.km/units.s) + earth.velocity
moon.mass = units.kg(7.3477e22)
moon.radius = units.km(1737.10)
moon.position = units.km(numpy.array((149.5e6 + 384399.0, 0.0, 0.0)))
moon.velocity = ([0.0, 1.022, 0] | units.km/units.s) + earth.velocity
return stars

def test0(self):
instance = AarsethZare()
instance.stop()

def test1(self):
instance = AarsethZare()
time, x, y, z, vx, vy, vz = instance.evolve_triple(
[0,0,0] | nbody_system.time,
[1,1,1] | nbody_system.mass,
[0, 0, 0] | nbody_system.time,
[1, 1, 1] | nbody_system.mass,
[-10, 0, 10] | nbody_system.length,
[0,0,0] | nbody_system.length,
[0,0,0] | nbody_system.length,
[0,0,0] | nbody_system.speed,
[0,0,0] | nbody_system.speed,
[0,0,0] | nbody_system.speed,
[1.0,1.0,1.0]| nbody_system.time
[0, 0, 0] | nbody_system.length,
[0, 0, 0] | nbody_system.length,
[0, 0, 0] | nbody_system.speed,
[0, 0, 0] | nbody_system.speed,
[0, 0, 0] | nbody_system.speed,
[1.0, 1.0, 1.0] | nbody_system.time
)
self.assertAlmostRelativeEquals(y, [0,0,0] | nbody_system.length)
self.assertAlmostRelativeEquals(z, [0,0,0] | nbody_system.length )
self.assertAlmostRelativeEquals(x[-1], -x[0], 10 )
self.assertAlmostRelativeEquals(x[1], 0 | nbody_system.length , 10)

self.assertAlmostRelativeEquals(y, [0, 0, 0] | nbody_system.length)
self.assertAlmostRelativeEquals(z, [0, 0, 0] | nbody_system.length)
self.assertAlmostRelativeEquals(x[-1], -x[0], 10)
self.assertAlmostRelativeEquals(x[1], 0 | nbody_system.length, 10)
self.assertAlmostRelativeEquals(vx[-1], -vx[0], 10)
self.assertAlmostRelativeEquals(vx[1], 0 | nbody_system.speed, 10)
self.assertAlmostRelativeEquals(vy, [0,0,0] | nbody_system.speed)
self.assertAlmostRelativeEquals(vz, [0,0,0] | nbody_system.speed)
self.assertAlmostRelativeEquals(vy, [0, 0, 0] | nbody_system.speed)
self.assertAlmostRelativeEquals(vz, [0, 0, 0] | nbody_system.speed)

def test2(self):
instance = AarsethZare()

particles = datamodel.Particles(3)
particles.mass = 1.0 | nbody_system.mass
particles.position = [
Expand All @@ -127,49 +127,45 @@ def test2(self):
[10.0, 0.0, 0.0],
] | nbody_system.length
particles.velocity = [0.0, 0.0, 0.0] | nbody_system.speed

instance.particles.add_particles(particles)
instance.evolve_model(1.0 | nbody_system.time)


self.assertAlmostRelativeEquals(instance.particles.y, [0,0,0] | nbody_system.length)
self.assertAlmostRelativeEquals(instance.particles.z, [0,0,0] | nbody_system.length )
self.assertAlmostRelativeEquals(instance.particles.x[-1], -instance.particles.x[0], 10 )
self.assertAlmostRelativeEquals(instance.particles.x[1], 0 | nbody_system.length , 10)

self.assertAlmostRelativeEquals(instance.particles.y, [0, 0, 0] | nbody_system.length)
self.assertAlmostRelativeEquals(instance.particles.z, [0, 0, 0] | nbody_system.length)
self.assertAlmostRelativeEquals(instance.particles.x[-1], -instance.particles.x[0], 10)
self.assertAlmostRelativeEquals(instance.particles.x[1], 0 | nbody_system.length, 10)
self.assertAlmostRelativeEquals(instance.particles.vx[-1], -instance.particles.vx[0], 10)
self.assertAlmostRelativeEquals(instance.particles.vx[1], 0 | nbody_system.speed, 10)
self.assertAlmostRelativeEquals(instance.particles.vy, [0,0,0] | nbody_system.speed)
self.assertAlmostRelativeEquals(instance.particles.vz, [0,0,0] | nbody_system.speed)



self.assertAlmostRelativeEquals(instance.particles.vy, [0, 0, 0] | nbody_system.speed)
self.assertAlmostRelativeEquals(instance.particles.vz, [0, 0, 0] | nbody_system.speed)

def test3(self):
instance = AarsethZare(nbody_system.nbody_to_si(1.0 | units.yr, 1.0 | units.MSun))

particles = self.new_system_of_sun_and_earth_and_moon()
instance.particles.add_particles(particles)

earth = instance.particles[1]

position_at_start = earth.position[0]

instance.evolve_model(365.0 | units.day)

position_after_full_rotation = earth.position[0]

self.assertAlmostRelativeEquals(position_at_start, position_after_full_rotation, 4)

instance.evolve_model(1.5 | units.yr)

position_after_half_a_rotation = earth.position[0]

self.assertAlmostRelativeEquals(-position_at_start, position_after_half_a_rotation, 2)

instance.evolve_model(1.75 | units.yr)

position_after_quarter_a_rotation = earth.position[1]

self.assertAlmostRelativeEquals(position_at_start, position_after_quarter_a_rotation, 2)

instance.stop()

0 comments on commit 8332261

Please sign in to comment.