示例#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 main(N=1000, Lstar=100| units.LSun, boxsize=10| units.parsec, 
         rho=1.0| (units.amu/units.cm**3), t_end=0.1|units.Myr, n_steps=10):

    ionization_fraction = 0.0
    internal_energy = (9. |units.kms)**2

    source=Particles(1)
    source.position = (0, 0, 0) |units.parsec
    source.flux = Lstar/(20. | units.eV)
    source.luminosity = Lstar/(20. | units.eV)
    source.rho = rho
    source.xion = ionization_fraction
    source.u = internal_energy

    converter=nbody_system.nbody_to_si(1|units.MSun, boxsize)
    ism = ProtoPlanetaryDisk(N, convert_nbody=converter, 
                                densitypower=1.5, 
                                Rmin=0.1, 
                                Rmax=1,
                                q_out=1.0,
                                discfraction=1.0).result
    ism = ism.select(lambda r: r.length()<0.5*boxsize,["position"])
    gamma=5./3.
    mu=1.| units.amu
    Tinit = 10000|units.K
    ism.u = 1/(gamma-1)*constants.kB * Tinit/mu
    ism.rho = rho
    ism.flux = 0. | units.s**-1
    ism.xion = ionization_fraction 
    ism.h_smooth = 0 | units.AU

    rad = SimpleXSplitSet(redirect="none")
#    rad = SimpleX()
#    rad = SPHRay()
    rad.parameters.box_size=1.001*boxsize    
    rad.parameters.timestep=0.001 | units.Myr

    rad.src_particles.add_particle(source)
    rad.gas_particles.add_particles(ism)

    channel_to_local_gas = rad.gas_particles.new_channel_to(ism)
    write_set_to_file(ism, "rad.hdf5", 'hdf5')

    time = 0.0 | t_end.unit
    dt = t_end/float(n_steps)
    while time<t_end:
        time += dt
        rad.evolve_model(time)
        channel_to_local_gas.copy_attributes(["xion",])
        write_set_to_file(ism, "rad.hdf5", 'hdf5')

        print "Time=", time
        print "min ionization:", rad.gas_particles.xion.min()
        print "average Xion:", rad.gas_particles.xion.mean()
        print "max ionization:", rad.gas_particles.xion.max()
    rad.stop()
示例#3
0
 def test1(self):
     print "Test 1: initialization"
     instance = SimpleXSplitSet(**default_options)
     instance.initialize_code()
     instance.commit_parameters()
     instance.cleanup_code()
     instance.stop()
示例#4
0
def irradiate_disk_with_bump(Mstar=10 | units.MSun,
                             tstar=20 | units.Myr,
                             Ndisk=100,
                             Mdisk=0.9 | units.MSun,
                             Rmin=1.0 | units.AU,
                             Rmax=100.0 | units.AU,
                             Mbump=0.1 | units.MSun,
                             Rbump=10.0 | units.AU,
                             abump=10 | units.AU,
                             t_end=10 | units.yr,
                             n_steps=10):
    dt = t_end / float(n_steps)

    stellar = SeBa()
    stellar.particles.add_particle(Particle(mass=Mstar))
    stellar.evolve_model(tstar)

    source = Particles(1)
    source.mass = stellar.particles[0].mass
    source.position = (0, 0, 0) | units.AU
    source.velocity = (0, 0, 0) | units.kms
    source.luminosity = stellar.particles[0].luminosity / (20. | units.eV)
    source.temperature = stellar.particles[0].temperature
    Teff = stellar.particles[0].temperature
    source.flux = source.luminosity
    source.rho = 1.0 | (units.g / units.cm**3)
    source.xion = 0.0  #ionization_fraction
    source.u = (9. | units.kms)**2  #internal_energy
    stellar.stop()

    ism = new_disk_with_bump(source[0].mass, Ndisk, Mdisk, Rmin, Rmax, Mbump,
                             Rbump, abump)
    ism.flux = 0 | units.s**-1
    ism.xion = 0.0  #ionization_fraction

    hydro = Gadget2(nbody_system.nbody_to_si(Mdisk, Rmax))
    hydro.gas_particles.add_particles(ism)
    hydro.dm_particles.add_particles(source)
    hydro.evolve_model(1 | units.day)
    hydro.gas_particles.new_channel_to(ism).copy()
    hydro.stop()

    rad = SimpleXSplitSet(redirect="none", numer_of_workers=4)
    rad.parameters.box_size = 2.01 * Rmax
    rad.parameters.timestep = 0.1 * dt
    rad.set_source_Teff(Teff)
    rad.src_particles.add_particle(source)
    rad.gas_particles.add_particles(ism)

    rad_to_framework = rad.gas_particles.new_channel_to(ism)
    particles = ParticlesSuperset([source, ism])
    write_set_to_file(particles, "rad.hdf5", 'hdf5')

    while rad.model_time < t_end:
        rad.evolve_model(rad.model_time + dt)
        rad_to_framework.copy_attributes(["x", "y", "z", "xion"])
        write_set_to_file(particles, "rad.hdf5", 'hdf5')
        print "Time=", rad.model_time, "Ionization (min, mean, max):", ism.xion.min(
        ), ism.xion.mean(), ism.xion.max()
    rad.stop()
示例#5
0
def irradiate_disk_with_bump(Mstar = 10|units.MSun, tstar = 20|units.Myr,
                             Ndisk=100, Mdisk=0.9|units.MSun,
                             Rmin=1.0|units.AU, Rmax=100.0|units.AU,
                             Mbump=0.1|units.MSun, Rbump=10.0|units.AU,
                             abump=10|units.AU,
                             t_end=10|units.yr, n_steps=10,
                             filename = None, image_id=1):
    dt = t_end/float(n_steps)

    stellar = SeBa()
    stellar.particles.add_particle(Particle(mass=Mstar))
    stellar.evolve_model(tstar)

    source=Particles(1)
    source.mass = stellar.particles[0].mass
    source.position = (0, 0, 0) |units.AU
    source.velocity = (0, 0, 0) |units.kms
    source.luminosity = stellar.particles[0].luminosity/(20. | units.eV)
    source.temperature = stellar.particles[0].temperature
    Teff = stellar.particles[0].temperature
    source.flux = source.luminosity
    source.rho = 1.0|(units.g/units.cm**3)
    source.xion = 0.0 #ionization_fraction
    source.u = (9. |units.kms)**2 #internal_energy
    stellar.stop()

    ism = new_disk_with_bump(source[0].mass, Ndisk, Mdisk, Rmin, Rmax,
                             Mbump, Rbump, abump)
    ism.flux = 0 | units.s**-1
    ism.xion = 0.0 #ionization_fraction

    hydro = Gadget2(nbody_system.nbody_to_si(Mdisk, Rmax))
    hydro.gas_particles.add_particles(ism)
    hydro.dm_particles.add_particles(source)
    hydro.evolve_model(1|units.day)
    hydro.gas_particles.new_channel_to(ism).copy()
    hydro.stop()
    
    rad = SimpleXSplitSet(redirect="none",numer_of_workers=4)
    rad.parameters.box_size=2.01*Rmax
    rad.parameters.timestep=0.1*dt
    rad.set_source_Teff(Teff)
    rad.src_particles.add_particle(source)
    rad.gas_particles.add_particles(ism)

    rad_to_framework = rad.gas_particles.new_channel_to(ism)
    particles = ParticlesSuperset([source, ism])
    write_set_to_file(particles, "rad.hdf5", 'hdf5')

    while rad.model_time<t_end:
        rad.evolve_model(rad.model_time + dt)
        rad_to_framework.copy_attributes(["x","y", "z", "xion"])
        write_set_to_file(particles, "rad.hdf5", 'hdf5')
        print "Time=", rad.model_time, "Ionization (min, mean, max):", ism.xion.min(), ism.xion.mean(), ism.xion.max()
    rad.stop()
示例#6
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)
示例#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 test5(self):
     print("Test 4: default parameters")
     instance = SimpleXSplitSet(**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)
     for x in param:
         setattr(instance.parameters, x, param[x])
     for x in param:
         self.assertEqual(getattr(instance.parameters, x), param[x])
示例#9
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()
示例#10
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()
示例#11
0
def main(N=1000,
         Lstar=100 | units.LSun,
         boxsize=10 | units.parsec,
         rho=1.0 | (units.amu / units.cm**3),
         t_end=0.1 | units.Myr,
         n_steps=10):

    ionization_fraction = 0.0
    internal_energy = (9. | units.kms)**2

    source = Particles(1)
    source.position = (0, 0, 0) | units.parsec
    source.flux = Lstar / (20. | units.eV)
    source.luminosity = Lstar / (20. | units.eV)
    source.rho = rho
    source.xion = ionization_fraction
    source.u = internal_energy

    converter = nbody_system.nbody_to_si(1 | units.MSun, boxsize)
    ism = ProtoPlanetaryDisk(N,
                             convert_nbody=converter,
                             densitypower=1.5,
                             Rmin=0.1,
                             Rmax=1,
                             q_out=1.0,
                             discfraction=1.0).result
    ism = ism.select(lambda r: r.length() < 0.5 * boxsize, ["position"])
    gamma = 5. / 3.
    mu = 1. | units.amu
    Tinit = 10000 | units.K
    ism.u = 1 / (gamma - 1) * constants.kB * Tinit / mu
    ism.rho = rho
    ism.flux = 0. | units.s**-1
    ism.xion = ionization_fraction
    ism.h_smooth = 0 | units.AU

    rad = SimpleXSplitSet(redirect="none")
    #    rad = SimpleX()
    #    rad = SPHRay()
    rad.parameters.box_size = 1.001 * boxsize
    rad.parameters.timestep = 0.001 | units.Myr

    rad.src_particles.add_particle(source)
    rad.gas_particles.add_particles(ism)

    channel_to_local_gas = rad.gas_particles.new_channel_to(ism)
    write_set_to_file(ism, "rad.hdf5", 'hdf5')

    time = 0.0 | t_end.unit
    dt = t_end / float(n_steps)
    while time < t_end:
        time += dt
        rad.evolve_model(time)
        channel_to_local_gas.copy_attributes([
            "xion",
        ])
        write_set_to_file(ism, "rad.hdf5", 'hdf5')

        print("Time=", time)
        print("min ionization:", rad.gas_particles.xion.min())
        print("average Xion:", rad.gas_particles.xion.mean())
        print("max ionization:", rad.gas_particles.xion.max())
    rad.stop()
示例#12
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()
示例#13
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()
示例#14
0
def _irradiate_disk_with_pump(Mstar = 10|units.MSun,
         tstar = 20|units.Myr,
         Ndisk=100, Mdisk=0.9|units.MSun, 
         Rmin=1.0|units.AU, Rmax=100.0|units.AU, 
         Mbump=0.1|units.MSun,Rbump=10.0|units.AU, abump=10|units.AU,
         t_end=10|units.yr, n_steps=10, filename = None, image_id=1):
    model_time = 0.0 | t_end.unit
    dt = t_end/float(n_steps)

    ionization_fraction = 0.0
    internal_energy = (9. |units.kms)**2

    stellar = SeBa()
    stellar.particles.add_particle(Particle(mass=Mstar))
    stellar.evolve_model(tstar)

    print "L=", stellar.particles[0].luminosity.in_(units.LSun), stellar.particles[0].temperature

    source=Particles(1)
    source.mass = stellar.particles[0].mass
    source.position = (0, 0, 0) |units.AU
    source.velocity = (0, 0, 0) |units.kms
    source.luminosity = stellar.particles[0].luminosity/(20. | units.eV)
    source.temperature = stellar.particles[0].temperature
    Teff = stellar.particles[0].temperature
    source.flux = source.luminosity
    source.rho = 1.0|(units.g/units.cm**3)
    source.xion = ionization_fraction
    source.u = internal_energy
    stellar.stop()

    Mstar = source[0].mass
    if filename ==None:
        ism = new_disk_with_bump(Mstar = Mstar,
                                 Ndisk=Ndisk, Mdisk=Mdisk,
                                 Rmin=Rmin, Rmax=Rmax,
                                 Mbump=Mbump, Rbump=Rbump,
                                 abump=abump)
    else:
        ism = read_disk_with_bump(image_id=image_id, filename=filename)#, Rmax=Rmax)
    ism = ism.select(lambda r: r.length()<1.0*Rmax,["position"])
    ism.flux = 0 | units.s**-1
    ism.xion = ionization_fraction 

    if filename ==None:
        converter=nbody_system.nbody_to_si(Mdisk, Rmax)
        hydro = Gadget2(converter)
        hydro.gas_particles.add_particles(ism)
        hydro.dm_particles.add_particles(source)
        hydro.evolve_model(1|units.day)
        hydro.gas_particles.new_channel_to(ism).copy()
        hydro.stop()
    
    rad = SimpleXSplitSet(redirect="none",numer_of_workers=4)
    rad.parameters.number_of_freq_bins=5
    rad.parameters.thermal_evolution_flag=1
    rad.parameters.blackbody_spectrum_flag=1
    rad.parameters.metal_cooling_flag=0
    rad.parameters.box_size=2.01*Rmax
    if isinstance(rad, SPHRay):
        ism.h_smooth = 0.1 | (units.RSun)

    else:
        rad.parameters.timestep=0.1*dt
        rad.set_source_Teff(Teff)

    rad.src_particles.add_particle(source)
    rad.gas_particles.add_particles(ism)

    channel_from_rad_to_framework = rad.gas_particles.new_channel_to(ism)

    particles = ParticlesSuperset([source, ism])
    write_set_to_file(particles, "rad.hdf5", 'hdf5')

    tCPU = time()
    while model_time<t_end:
        model_time += dt

        rad.evolve_model(model_time)
        channel_from_rad_to_framework.copy_attributes(["x","y", "z", "xion"])
        write_set_to_file(particles, "rad.hdf5", 'hdf5')

        print "Date:"+str(localtime()[2])+"."+str(localtime()[1])+"."+str(localtime()[1]), "at", str(localtime()[3])+"h", str(localtime()[4])+"m"
        print "Time=", model_time, "dt_CPU=", time()-tCPU
        print "min ionization:", ism.xion.min()
        print "average Xion:", ism.xion.mean()
        print "max ionization:", ism.xion.max()
        tCPU = time()

    rad.stop()