Example #1
0
 def test1(self):
     print("Test 1: initialization")
     instance = SimpleX(**default_options)
     instance.initialize_code()
     instance.commit_parameters()
     instance.cleanup_code()
     instance.stop()
Example #2
0
    def test12(self):
        N = 1000
        Lstar=100|units.LSun
        boxsize=10|units.parsec
        rho=1.0 | (units.amu/units.cm**3)
        t_end=0.01 |units.Myr
        internal_energy = (9. |units.kms)**2

        source=Particle()
        source.position = (0, 0, 0) |units.parsec
        source.flux = Lstar/(20. | units.eV)
        source.rho = rho
        source.xion = 0.0
        source.u = internal_energy

        ism = ism_cube(N, boxsize/2., rho, internal_energy).result
        ism.rho = rho
        ism.flux = 0. | units.s**-1
        ism.xion = source.xion

        radiative = SimpleX()
        radiative.parameters.box_size=1.001*boxsize    
        radiative.parameters.timestep=0.001 | units.Myr

        radiative.particles.add_particle(source)
        radiative.particles.add_particles(ism)

        radiative.evolve_model(t_end)
        self.assertAlmostRelativeEquals( 0.0750819123073, radiative.particles.xion.mean(), 1)
        radiative.stop()
Example #3
0
 def test1(self):
     print "Test 1: initialization"
     instance = SimpleX(**default_options)
     instance.initialize_code()
     instance.commit_parameters()
     instance.cleanup_code()
     instance.stop()
Example #4
0
 def test11(self):
     print "Test 11: add test"
     instance = SimpleX(number_of_workers=1)
     
     input_file = os.path.join(os.path.dirname(__file__), "test_simplex_data.txt")
     particles = particles_from_input_file(input_file)
     N=len(particles)
     toadd=particles[0:10].copy()
     particles=particles[10:].copy()
     instance.particles.add_particles(particles)
     instance.commit_particles()
     instance.particles.add_particles(toadd)
     self.assertEqual( len(instance.particles), N)
Example #5
0
 def test11(self):
     print "Test 11: add test"
     instance = SimpleX(number_of_workers=1)
     
     input_file = os.path.join(os.path.dirname(__file__), "test_simplex_data.txt")
     particles = particles_from_input_file(input_file)
     N=len(particles)
     toadd=particles[0:10].copy()
     particles=particles[10:].copy()
     instance.particles.add_particles(particles)
     instance.commit_particles()
     instance.particles.add_particles(toadd)
     self.assertEqual( len(instance.particles), N)
Example #6
0
 def test8(self):
     print "Test 8: two step evolve"
     instance = SimpleX(**default_options)
     
     input_file = os.path.join(os.path.dirname(__file__), "test_simplex_data.txt")
     particles = particles_from_input_file(input_file)
     instance.particles.add_particles(particles)
     self.assertAlmostEqual(instance.particles.xion.mean(), 0.0)
     instance.evolve_model(0.25 | units.Myr)
     instance.evolve_model(0.5 | units.Myr)
     self.assertEqual( instance.particles.flux.max().value_in(1.e48* units.s**-1), 5)
     self.assertAlmostRelativeEqual(instance.particles.xion.mean(),0.00084660917243,3)
     instance.cleanup_code()
     instance.stop()
Example #7
0
 def test6(self):
     print "Test 2: print parameters,data directory"
     instance = SimpleX(**default_options)
     print instance.parameters
     
     instance.parameters.simplex_data_directory="some/dir"
     self.assertEqual(instance.parameters.simplex_data_directory, "some/dir")
Example #8
0
 def test8(self):
     print "Test 8: two step evolve"
     instance = SimpleX(**default_options)
     
     input_file = os.path.join(os.path.dirname(__file__), "test_simplex_data.txt")
     particles = particles_from_input_file(input_file)
     instance.particles.add_particles(particles)
     self.assertAlmostEqual(instance.particles.xion.mean(), 0.0)
     instance.evolve_model(0.25 | units.Myr)
     instance.evolve_model(0.5 | units.Myr)
     self.assertEqual( instance.particles.flux.max().value_in(1.e48* units.s**-1), 5)
     self.assertAlmostRelativeEqual(instance.particles.xion.mean(),0.00084660917243,3)
     instance.cleanup_code()
     instance.stop()
Example #9
0
 def test7(self):
     print "Test 7: two step evolve"
     instance = SimpleX(**default_options)
     instance.parameters.recombination_radiation_flag=1
     
     input_file = os.path.join(os.path.dirname(__file__), "test_simplex_data.txt")
     particles = particles_from_input_file(input_file)
     instance.particles.add_particles(particles)
     self.assertAlmostEqual(instance.particles.xion.mean(), 0.0)
     instance.evolve_model(0.25 | units.Myr)
     flux_before=instance.particles.flux.sum()
     instance.particles.flux=particles.flux
     flux_after=instance.particles.flux.sum()
     self.assertEqual(flux_before,flux_after)
     instance.evolve_model(0.5 | units.Myr)
     self.assertAlmostRelativeEqual(instance.particles.xion.mean(),0.00084660917243,3)
     self.assertEqual( instance.particles.flux.max().value_in(1.e48* units.s**-1), 5)
     instance.cleanup_code()
     instance.stop()
Example #10
0
    def test12(self):
        N = 1000
        Lstar = 100 | units.LSun
        boxsize = 10 | units.parsec
        rho = 1.0 | (units.amu / units.cm**3)
        t_end = 0.01 | units.Myr
        internal_energy = (9. | units.kms)**2

        source = Particle()
        source.position = (0, 0, 0) | units.parsec
        source.flux = Lstar / (20. | units.eV)
        source.rho = rho
        source.xion = 0.0
        source.u = internal_energy

        ism = ism_cube(N, boxsize / 2., rho, internal_energy).result
        ism.rho = rho
        ism.flux = 0. | units.s**-1
        ism.xion = source.xion

        radiative = SimpleX()
        radiative.parameters.box_size = 1.001 * boxsize
        radiative.parameters.timestep = 0.001 | units.Myr

        radiative.particles.add_particle(source)
        radiative.particles.add_particles(ism)

        radiative.evolve_model(t_end)
        self.assertAlmostRelativeEquals(0.0750819123073,
                                        radiative.particles.xion.mean(), 1)
        radiative.stop()
Example #11
0
 def test7(self):
     print "Test 7: two step evolve"
     instance = SimpleX(**default_options)
     instance.parameters.recombination_radiation_flag=1
     
     input_file = os.path.join(os.path.dirname(__file__), "test_simplex_data.txt")
     particles = particles_from_input_file(input_file)
     instance.particles.add_particles(particles)
     self.assertAlmostEqual(instance.particles.xion.mean(), 0.0)
     instance.evolve_model(0.25 | units.Myr)
     flux_before=instance.particles.flux.sum()
     instance.particles.flux=particles.flux
     flux_after=instance.particles.flux.sum()
     self.assertEqual(flux_before,flux_after)
     instance.evolve_model(0.5 | units.Myr)
     self.assertAlmostRelativeEqual(instance.particles.xion.mean(),0.00084660917243,3)
     self.assertEqual( instance.particles.flux.max().value_in(1.e48* units.s**-1), 5)
     instance.cleanup_code()
     instance.stop()
Example #12
0
    def test4(self):
        print "Test 4: default parameters"
        instance = SimpleX(**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)    
Example #13
0
    def test4(self):
        print("Test 4: default parameters")
        instance = SimpleX(**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)
Example #14
0
 def test5(self):
     print("Test 4: default parameters")
     instance = SimpleX(**default_options)
     param = dict(timestep=0.1 | units.Myr,
                  source_effective_T=2.e5 | units.K,
                  hilbert_order=3,
                  number_of_freq_bins=4,
                  thermal_evolution_flag=1,
                  blackbody_spectrum_flag=1,
                  box_size=32100 | units.parsec,
                  metal_cooling_flag=1,
                  collisional_ionization_flag=1,
                  simplex_data_directory='.')
     for x in param:
         setattr(instance.parameters, x, param[x])
     for x in param:
         self.assertEqual(getattr(instance.parameters, x), param[x])
Example #15
0
def iliev_test_5(N=10000, Ns=10, L=15. | units.kpc, dt=None):
    """
    prepare iliev test and return SPH and simplex interfaces
    """
    gas, sources = iliev_test_5_ic(N, Ns, L)

    conv = nbody_system.nbody_to_si(1.0e9 | units.MSun, 1.0 | units.kpc)

    sph = Fi(conv, use_gl=False, mode='periodic', redirection='none')
    sph.initialize_code()

    sph.parameters.use_hydro_flag = True
    sph.parameters.radiation_flag = False
    sph.parameters.self_gravity_flag = False
    sph.parameters.gamma = 1
    sph.parameters.isothermal_flag = True
    sph.parameters.integrate_entropy_flag = False
    sph.parameters.timestep = dt
    sph.parameters.verbosity = 0
    sph.parameters.pboxsize = 2 * L
    sph.commit_parameters()
    sph.gas_particles.add_particles(gas)
    sph.commit_particles()

    #  sph.start_viewer()

    rad = SimpleX(number_of_workers=1, redirection='none')
    rad.initialize_code()

    rad.parameters.box_size = 2 * L
    rad.parameters.hilbert_order = 0

    rad.commit_parameters()

    gas.add_particles(sources)
    rad.particles.add_particles(gas)
    rad.commit_particles()

    return sph, rad
Example #16
0
def iliev_test_5( N=10000,
                  Ns=10,
                  L=15. | units.kpc,
                  dt=None):
  """
  prepare iliev test and return SPH and simplex interfaces
  """  
  gas,sources=iliev_test_5_ic(N,Ns,L)                


  conv=nbody_system.nbody_to_si(1.0e9 | units.MSun, 1.0 | units.kpc)
     
  sph=Fi(conv,use_gl=False,mode='periodic',redirection='none')   
  sph.initialize_code()

  sph.parameters.use_hydro_flag=True
  sph.parameters.radiation_flag=False
  sph.parameters.self_gravity_flag=False
  sph.parameters.gamma=1
  sph.parameters.isothermal_flag=True
  sph.parameters.integrate_entropy_flag=False
  sph.parameters.timestep=dt  
  sph.parameters.verbosity=0
  sph.parameters.pboxsize=2*L
  sph.commit_parameters()
  sph.gas_particles.add_particles(gas)
  sph.commit_particles()

#  sph.start_viewer()
         
  rad=SimpleX(number_of_workers = 1,redirection='none')
  rad.initialize_code()

  rad.parameters.box_size=2*L
  rad.parameters.hilbert_order=0

  rad.commit_parameters()

  gas.add_particles(sources)
  rad.particles.add_particles(gas)
  rad.commit_particles()
                  
  return sph,rad                  
Example #17
0
converter = nbody_system.nbody_to_si(Mcloud, Rcloud)
gas_particles = molecular_cloud(targetN=N,
                                convert_nbody=converter,
                                base_grid=body_centered_grid_unit_cube).result

gas_particles.x += np.random.normal(size=len(gas_particles)) * sigma
gas_particles.y += np.random.normal(size=len(gas_particles)) * sigma
gas_particles.z += np.random.normal(size=len(gas_particles)) * sigma

gas_particles.flux = 0. | units.s**-1
gas_particles.u = (Tcloud * constants.kB) / (1.008 * constants.u)
gas_particles.rho = Mcloud / (4. / 3. * np.pi * Rcloud**3)

gas_particles.xion = 0.

radiative = SimpleX(redirection='none', number_of_workers=8)

radiative.parameters.blackbody_spectrum_flag = True
radiative.parameters.thermal_evolution_flag = True
radiative.parameters.box_size = box_size
radiative.parameters.timestep = 1. | 1e3 * units.yr

radiative.particles.add_particles(gas_particles)

radiative.commit_particles()

start = time.time()

radiative.evolve_model(0.05 | units.Myr)

end = time.time()
Example #18
0
    def test3(self):
        print("Test 3: evolve")
        instance = SimpleX(**default_options)
        instance.initialize_code()
        instance.commit_parameters()

        input_file = os.path.join(os.path.dirname(__file__),
                                  "test_simplex_data.txt")
        particles = particles_from_input_file(input_file)
        particles.du_dt = particles.u / (10 | units.Myr)
        instance.particles.add_particles(particles)
        #        instance.particles.du_dt=particles.du_dt
        #        instance.commit_particles()
        instance.particles.du_dt = particles.du_dt
        self.assertAlmostEqual(instance.particles.xion.mean(), 0.0)
        self.assertAlmostEqual(
            instance.particles.du_dt.mean().in_(units.cm**2 / units.s**3),
            particles.du_dt.mean().in_(units.cm**2 / units.s**3))
        instance.evolve_model(0.5 | units.Myr)
        self.assertAlmostEqual(
            instance.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.particles.xion.mean(),
                               0.000845247683257)
        instance.cleanup_code()
        instance.stop()
Example #19
0
    def test2(self):
        print("Test 2: commit_particles, getters and setters")
        instance = SimpleX(**default_options)
        instance.initialize_code()
        instance.commit_parameters()

        input_file = os.path.join(os.path.dirname(__file__),
                                  "test_simplex_data.txt")
        particles = particles_from_input_file(input_file)
        instance.particles.add_particles(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()
Example #20
0
    def test2(self):
        print "Test 2: commit_particles, getters and setters"
        instance = SimpleX(**default_options)
        instance.initialize_code()
        instance.commit_parameters()
        
        input_file = os.path.join(os.path.dirname(__file__), "test_simplex_data.txt")
        particles = particles_from_input_file(input_file)
        instance.particles.add_particles(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()
Example #21
0
    def test3(self):
        print "Test 3: evolve"
        instance = SimpleX(**default_options)
        instance.initialize_code()
        instance.commit_parameters()
        
        input_file = os.path.join(os.path.dirname(__file__), "test_simplex_data.txt")
        particles = particles_from_input_file(input_file)
        particles.du_dt = particles.u/(10|units.Myr)
        instance.particles.add_particles(particles)
#        instance.particles.du_dt=particles.du_dt
#        instance.commit_particles()
        instance.particles.du_dt=particles.du_dt
        self.assertAlmostEqual(instance.particles.xion.mean(), 0.0)
        self.assertAlmostEqual(instance.particles.du_dt.mean().in_(units.cm**2/units.s**3),particles.du_dt.mean().in_(units.cm**2/units.s**3))
        instance.evolve_model(0.5 | units.Myr)
        self.assertAlmostEqual(instance.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.particles.xion.mean(), 0.000845247683257)
        instance.cleanup_code()
        instance.stop()