示例#1
0
 def test1(self):
     print("Test 1: initialization")
     instance = SimpleXSplitSet(**default_options)
     instance.initialize_code()
     instance.commit_parameters()
     instance.cleanup_code()
     instance.stop()
示例#2
0
    def test3(self):
        print("Test 3: evolve")
        instance = SimpleXSplitSet(**default_options)
        instance.initialize_code()
        instance.commit_parameters()

        input_file = os.path.join(os.path.dirname(__file__),
                                  "test_simplex_data.txt")
        particles, src_particles = splitset_from_input_file(input_file)
        instance.src_particles.add_particles(src_particles)
        particles.du_dt = particles.u / (10 | units.Myr)
        instance.gas_particles.add_particles(particles)

        self.assertAlmostEqual(instance.gas_particles.xion.mean(), 0.0)
        self.assertAlmostEqual(
            instance.gas_particles.du_dt.mean().in_(units.cm**2 / units.s**3),
            particles.du_dt.mean().in_(units.cm**2 / units.s**3))
        self.assertEqual(instance.get_name_of_current_state(), 'EDIT')
        instance.evolve_model(0.5 | units.Myr)
        self.assertEqual(instance.get_name_of_current_state(), 'RUN')
        self.assertAlmostEqual(
            instance.gas_particles.du_dt.mean().in_(units.cm**2 / units.s**3),
            particles.du_dt.mean().in_(units.cm**2 / units.s**3))
        self.assertAlmostEqual(instance.gas_particles.xion.mean(),
                               0.000845247683257)
        instance.gas_particles.remove_particles(particles[0:4])
        # this is what we would like....
        #        self.assertEquals(instance.get_name_of_current_state(), 'UPDATE')
        #        instance.recommit_particles()
        instance.evolve_model(0.75 | units.Myr)
        self.assertEqual(len(instance.particles), len(particles) - 4)
        instance.cleanup_code()
        instance.stop()
示例#3
0
    def test3(self):
        print "Test 3: evolve"
        instance = SimpleXSplitSet(**default_options)
        instance.initialize_code()
        instance.commit_parameters()
        
        input_file = os.path.join(os.path.dirname(__file__), "test_simplex_data.txt")
        particles,src_particles = splitset_from_input_file(input_file)
        instance.src_particles.add_particles(src_particles)
        particles.du_dt = particles.u/(10|units.Myr)
        instance.gas_particles.add_particles(particles)

        self.assertAlmostEqual(instance.gas_particles.xion.mean(), 0.0)
        self.assertAlmostEqual(instance.gas_particles.du_dt.mean().in_(units.cm**2/units.s**3),particles.du_dt.mean().in_(units.cm**2/units.s**3))
        self.assertEquals(instance.get_name_of_current_state(), 'EDIT')
        instance.evolve_model(0.5 | units.Myr)
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        self.assertAlmostEqual(instance.gas_particles.du_dt.mean().in_(units.cm**2/units.s**3),particles.du_dt.mean().in_(units.cm**2/units.s**3))
        self.assertAlmostEqual(instance.gas_particles.xion.mean(), 0.000845247683257)
        instance.gas_particles.remove_particles(particles[0:4])
# this is what we would like....
#        self.assertEquals(instance.get_name_of_current_state(), 'UPDATE')
#        instance.recommit_particles()
        instance.evolve_model(0.75 | units.Myr)
        self.assertEqual(len(instance.particles), len(particles)-4)
        instance.cleanup_code()
        instance.stop()
示例#4
0
 def test1(self):
     print "Test 1: initialization"
     instance = SimpleXSplitSet(**default_options)
     instance.initialize_code()
     instance.commit_parameters()
     instance.cleanup_code()
     instance.stop()
示例#5
0
    def test2(self):
        print "Test 2: commit_particles, getters and setters"
        instance = SimpleXSplitSet(**default_options)
        instance.initialize_code()
        instance.commit_parameters()
        
        input_file = os.path.join(os.path.dirname(__file__), "test_simplex_data.txt")
        particles,src_particles = splitset_from_input_file(input_file)
        instance.gas_particles.add_particles(particles)
        instance.src_particles.add_particles(src_particles)
        instance.commit_particles()
#        for attribute in ['position', 'rho', 'flux', 'xion']:
#            self.assertAlmostEqual(13200.*getattr(particles, attribute),
#                                   13200.*getattr(instance.particles, attribute), 5)
#            setattr(instance.particles, attribute, getattr(particles, attribute)/2.0)
#            self.assertAlmostEqual(13200.*getattr(particles, attribute)/2.0,
#                                   13200.*getattr(instance.particles, attribute), 5)
        instance.cleanup_code()
        instance.stop()
示例#6
0
    def test2(self):
        print "Test 2: commit_particles, getters and setters"
        instance = SimpleXSplitSet(**default_options)
        instance.initialize_code()
        instance.commit_parameters()
        
        input_file = os.path.join(os.path.dirname(__file__), "test_simplex_data.txt")
        particles,src_particles = splitset_from_input_file(input_file)
        instance.gas_particles.add_particles(particles)
        instance.src_particles.add_particles(src_particles)
        instance.commit_particles()
#        for attribute in ['position', 'rho', 'flux', 'xion']:
#            self.assertAlmostEqual(13200.*getattr(particles, attribute),
#                                   13200.*getattr(instance.particles, attribute), 5)
#            setattr(instance.particles, attribute, getattr(particles, attribute)/2.0)
#            self.assertAlmostEqual(13200.*getattr(particles, attribute)/2.0,
#                                   13200.*getattr(instance.particles, attribute), 5)
        instance.cleanup_code()
        instance.stop()
示例#7
0
    def test4(self):
        print("Test 4: default parameters")
        instance = SimpleXSplitSet(**default_options)

        default = dict(timestep=0.05 | units.Myr,
                       source_effective_T=1.e5 | units.K,
                       hilbert_order=1,
                       number_of_freq_bins=1,
                       thermal_evolution_flag=0,
                       blackbody_spectrum_flag=0,
                       box_size=13200 | units.parsec,
                       metal_cooling_flag=0,
                       collisional_ionization_flag=0)
        for x in default:
            self.assertEqual(getattr(instance.parameters, x), default[x])
        instance.commit_parameters()
        for x in default:
            self.assertEqual(getattr(instance.parameters, x), default[x])

        tnow = instance.model_time
        self.assertEqual(tnow, 0. | units.Myr)
        instance.model_time = 321. | units.Myr
        tnow = instance.model_time
        self.assertEqual(tnow, 321. | units.Myr)
示例#8
0
    def test4(self):
        print "Test 4: default parameters"
        instance = SimpleXSplitSet(**default_options)

        default=dict( timestep= 0.05| units.Myr, 
                  source_effective_T=  1.e5 | units.K,
                  hilbert_order= 1,
                  number_of_freq_bins= 1,
                  thermal_evolution_flag = 0,
                  blackbody_spectrum_flag = 0,
                  box_size=13200 | units.parsec,
                  metal_cooling_flag=0,
                  collisional_ionization_flag=0)
        for x in default:
            self.assertEqual(getattr(instance.parameters,x), default[x])
        instance.commit_parameters()
        for x in default:
            self.assertEqual(getattr(instance.parameters,x), default[x])

        tnow=instance.model_time
        self.assertEqual(tnow, 0. | units.Myr)    
        instance.model_time=321. | units.Myr
        tnow=instance.model_time
        self.assertEqual(tnow, 321. | units.Myr)