Exemple #1
0
 def test4(self):
     print "Test 2: set, get time"
     instance = SPHRayInterface(**default_options)
     self.assertEqual(0, instance.set_sphray_data_directory(instance.data_directory))
     self.assertEquals(0, instance.set_sphray_output_directory(instance.output_directory))        
     self.assertEqual(0, instance.initialize_code())
     self.assertEqual(0, instance.commit_parameters())
     
     input_file = os.path.join(os.path.dirname(__file__), "test_sphray_data_4K")
     mass, hsml, x, y, z, rho, xe, u = self.read_gas_file(input_file)
     number_of_gas_particles = len(x)
     indices, errors = instance.new_gas_particle(mass, hsml, x, y, z, rho, xe, u)
     self.assertEqual(errors, [0]*number_of_gas_particles)
     self.assertEqual(indices, range(1,number_of_gas_particles+1))
     
     input_file = os.path.join(os.path.dirname(__file__), "test_sphray_data_sources_001.1")
     L, xs, ys, zs, spctype = self.read_src_file(input_file)
     number_of_src_particles = len(xs)
     s_indices, errors = instance.new_src_particle(L, xs, ys, zs, spctype)
     self.assertEqual(errors, [0]*number_of_src_particles)
     self.assertEqual(s_indices, range(number_of_gas_particles+1,number_of_src_particles+number_of_gas_particles+1))
    
     self.assertEqual(0, instance.commit_particles())
     
     time,err= instance.get_time()
     self.assertEqual(0,err)
     self.assertEqual(0.,time)
     err= instance.set_time(123.)
     self.assertEqual(-1,err)   # because we don't know whether it is safe yet
     time,err= instance.get_time()
     instance.stop()
     self.assertEqual(0,err)
     self.assertEqual(123.,time)
Exemple #2
0
 def test1(self):
     print "Test 1: initialization"
     
     instance = SPHRayInterface(**default_options)
     self.assertEqual(0, instance.initialize_code())
     self.assertEquals(0, instance.set_sphray_data_directory(instance.data_directory))        
     self.assertEquals(0, instance.set_sphray_output_directory(instance.output_directory))        
     self.assertEqual(0, instance.commit_parameters())
     self.assertEqual(0, instance.cleanup_code())
     instance.stop()
Exemple #3
0
    def test2(self):
        print("Test 2: add, commit_particles")
        instance = SPHRayInterface(**default_options)
        self.assertEqual(
            0, instance.set_sphray_data_directory(instance.data_directory))
        self.assertEqual(
            0, instance.set_sphray_output_directory(instance.output_directory))
        self.assertEqual(0, instance.initialize_code())
        self.assertEqual(0, instance.commit_parameters())

        input_file = os.path.join(os.path.dirname(__file__),
                                  "test_sphray_data_4K")
        mass, hsml, x, y, z, rho, xe, u = self.read_gas_file(input_file)
        number_of_gas_particles = len(x)
        indices, errors = instance.new_gas_particle(mass, hsml, x, y, z, rho,
                                                    xe, u)
        self.assertEqual(errors, [0] * number_of_gas_particles)
        self.assertEqual(indices, list(range(1, number_of_gas_particles + 1)))

        input_file = os.path.join(os.path.dirname(__file__),
                                  "test_sphray_data_sources_001.1")
        L, xs, ys, zs, spctype = self.read_src_file(input_file)
        number_of_src_particles = len(xs)
        s_indices, errors = instance.new_src_particle(L, xs, ys, zs, spctype)
        self.assertEqual(errors, [0] * number_of_src_particles)
        self.assertEqual(
            s_indices,
            list(
                range(number_of_gas_particles + 1,
                      number_of_src_particles + number_of_gas_particles + 1)))

        self.assertEqual(0, instance.commit_particles())
        mass2, hsml2, x2, y2, z2, rho2, xe2, u2, error = instance.get_state_gas(
            indices)
        self.assertAlmostEqual((mass - mass2), numpy.zeros_like(x), 7)
        self.assertAlmostEqual((hsml - hsml2), numpy.zeros_like(x), 7)
        self.assertAlmostEqual((x - x2) / 13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((y - y2) / 13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((z - z2) / 13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((rho - rho2), numpy.zeros_like(x), 7)
        #        self.assertAlmostEqual((xe-xe2), numpy.zeros_like(x), 7)
        self.assertAlmostEqual((u - u2), numpy.zeros_like(x), 7)

        L2, xs2, ys2, zs2, spctype2, error = instance.get_state_src(s_indices)
        self.assertAlmostEqual((L - L2), numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((xs - xs2) / 13200., numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((ys - ys2) / 13200., numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((zs - zs2) / 13200., numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((spctype - spctype2), numpy.zeros_like(xs), 7)

        self.assertEqual(0, instance.cleanup_code())
        instance.stop()
Exemple #4
0
    def test2(self):
        print "Test 2: add, commit_particles"
        instance = SPHRayInterface(**default_options)
        self.assertEqual(0, instance.set_sphray_data_directory(instance.data_directory))
        self.assertEquals(0, instance.set_sphray_output_directory(instance.output_directory))        
        self.assertEqual(0, instance.initialize_code())
        self.assertEqual(0, instance.commit_parameters())
        
        input_file = os.path.join(os.path.dirname(__file__), "test_sphray_data_4K")
        mass, hsml, x, y, z, rho, xe, u = self.read_gas_file(input_file)
        number_of_gas_particles = len(x)
        indices, errors = instance.new_gas_particle(mass, hsml, x, y, z, rho, xe, u)
        self.assertEqual(errors, [0]*number_of_gas_particles)
        self.assertEqual(indices, range(1,number_of_gas_particles+1))
        
        input_file = os.path.join(os.path.dirname(__file__), "test_sphray_data_sources_001.1")
        L, xs, ys, zs, spctype = self.read_src_file(input_file)
        number_of_src_particles = len(xs)
        s_indices, errors = instance.new_src_particle(L, xs, ys, zs, spctype)
        self.assertEqual(errors, [0]*number_of_src_particles)
        self.assertEqual(s_indices, range(number_of_gas_particles+1,number_of_src_particles+number_of_gas_particles+1))
       
        self.assertEqual(0, instance.commit_particles())
        mass2, hsml2, x2, y2, z2, rho2, xe2, u2 , error = instance.get_state_gas(indices)
        self.assertAlmostEqual((mass-mass2), numpy.zeros_like(x), 7)
        self.assertAlmostEqual((hsml-hsml2), numpy.zeros_like(x), 7)
        self.assertAlmostEqual((x-x2)/13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((y-y2)/13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((z-z2)/13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((rho-rho2), numpy.zeros_like(x), 7)
#        self.assertAlmostEqual((xe-xe2), numpy.zeros_like(x), 7)
        self.assertAlmostEqual((u-u2), numpy.zeros_like(x), 7)

        L2, xs2, ys2, zs2, spctype2 , error = instance.get_state_src(s_indices)
        self.assertAlmostEqual((L-L2), numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((xs-xs2)/13200., numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((ys-ys2)/13200., numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((zs-zs2)/13200., numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((spctype-spctype2), numpy.zeros_like(xs), 7)

        self.assertEqual(0, instance.cleanup_code())
        instance.stop()
Exemple #5
0
    def test6(self):
        print "Test 3: add, commit_particles, setters, remove with velocity"
        instance = SPHRayInterface(**default_options)
        self.assertEqual(0, instance.set_sphray_data_directory(instance.data_directory))
        self.assertEquals(0, instance.set_sphray_output_directory(instance.output_directory))        
        self.assertEqual(0, instance.initialize_code())
        self.assertEqual(0, instance.commit_parameters())
        
        input_file = os.path.join(os.path.dirname(__file__), "test_sphray_data_4K")
        mass, hsml, x, y, z, rho, xe, u,vx,vy,vz = self.read_gas_file_vel(input_file)
        number_of_gas_particles = len(x)
        indices, errors = instance.new_gas_particle(mass, hsml, x, y, z, rho, xe, u,vx,vy,vz)
        self.assertEqual(errors, [0]*number_of_gas_particles)
        self.assertEqual(indices, range(1,number_of_gas_particles+1))
        
        input_file = os.path.join(os.path.dirname(__file__), "test_sphray_data_sources_001.1")
        L, xs, ys, zs, spctype = self.read_src_file(input_file)
        number_of_src_particles = len(xs)
        s_indices, errors = instance.new_src_particle(L, xs, ys, zs, spctype)
        self.assertEqual(errors, [0]*number_of_src_particles)
        self.assertEqual(s_indices, range(number_of_gas_particles+1,number_of_src_particles+number_of_gas_particles+1))
       
        self.assertEqual(0, instance.commit_particles())
        mass2, hsml2, x2, y2, z2, rho2, xe2, u2 , error = instance.get_state_gas(indices)
        vx2,vy2,vz2,error=instance.get_vel_gas(indices)
        self.assertAlmostEqual((mass-mass2), numpy.zeros_like(x), 7)
        self.assertAlmostEqual((hsml-hsml2), numpy.zeros_like(x), 7)
        self.assertAlmostEqual((x-x2)/13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((y-y2)/13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((z-z2)/13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((vx-vx2)/13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((vy-vy2)/13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((vz-vz2)/13200., numpy.zeros_like(x), 7)
        self.assertAlmostEqual((rho-rho2), numpy.zeros_like(x), 7)
#        self.assertAlmostEqual((xe-xe2), numpy.zeros_like(x), 7)
        self.assertAlmostEqual((u-u2), numpy.zeros_like(x), 7)

        L2, xs2, ys2, zs2, spctype2 , error = instance.get_state_src(s_indices)
        self.assertAlmostEqual((L-L2), numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((xs-xs2)/13200., numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((ys-ys2)/13200., numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((zs-zs2)/13200., numpy.zeros_like(xs), 7)
        self.assertAlmostEqual((spctype-spctype2), numpy.zeros_like(xs), 7)

        error=instance.set_state_gas(100,1.,2.,3.,4.,5.,6.,7.,8.)
        self.assertEqual(0, error)
        error=instance.set_vel_gas(100,9.,10.,11.)
        self.assertEqual(0, error)
        error=instance.set_state_gas(10000,1.,2.,3.,4.,5.,6.,7.,8.)
        self.assertEqual(-1, error)
 
        m,h,x,y,z,rho,xe,u,error=instance.get_state_gas(100)
        vx,vy,vz,error=instance.get_vel_gas(100)
        self.assertEqual(0, error)
        self.assertAlmostEqual(m, 1., 7)
        self.assertAlmostEqual(h, 2., 7)
        self.assertAlmostEqual(x, 3., 7)
        self.assertAlmostEqual(y, 4., 7)
        self.assertAlmostEqual(z, 5., 7)
        self.assertAlmostEqual(rho, 6., 7)
#        self.assertAlmostEqual(xe, 7., 7)
        self.assertAlmostEqual(u, 8., 7)
        self.assertAlmostEqual(vx, 9., 7)
        self.assertAlmostEqual(vy, 10., 7)
        self.assertAlmostEqual(vz, 11., 7)

        error=instance.remove_gas_particle(100)
        self.assertEqual(0, error)
        error=instance.remove_gas_particle(100)
        self.assertEqual(-4, error)


        error=instance.set_state_src(4097,1.,2.,3.,4.,5.)
        self.assertEqual(0, error)
        error=instance.set_state_src(10000,1.,2.,3.,4.,5.)
        self.assertEqual(-1, error)
 
        L,x,y,z,s,error=instance.get_state_src(4097)
        self.assertEqual(0, error)
        self.assertAlmostEqual(L, 1., 7)
        self.assertAlmostEqual(x, 2., 7)
        self.assertAlmostEqual(y, 3., 7)
        self.assertAlmostEqual(z, 4., 7)
        self.assertAlmostEqual(s, 5., 7)

        error=instance.remove_src_particle(4097)
        self.assertEqual(0, error)
        error=instance.remove_src_particle(4097)
        self.assertEqual(-4, error)

        instance.recommit_particles()
        error=instance.remove_gas_particle(100)
        self.assertEqual(-1, error)        
        error=instance.remove_gas_particle(4097)
        self.assertEqual(-1, error)


        self.assertEqual(0, instance.cleanup_code())
        instance.stop()