def new_gas_to_star_interaction_codes_bhtree(self, gas_code):
        def new_bhtree():
            result = BHTree(self.converter)
            result.parameters.epsilon_squared = self.star_epsilon**2
            return result

        return [bridge.CalculateFieldForCodes(new_bhtree, [gas_code])]\
    def new_gas_to_star_interaction_codes_octgrav(self, gas_code):
        def new_octgrav():
            result = Octgrav(self.converter)
            result.parameters.epsilon_squared = self.gas_epsilon**2
            return result

        return [bridge.CalculateFieldForCodes(new_octgrav, [gas_code])]
Beispiel #3
0
 def create_codes(self):
     self.star_code = self.new_star_code_hermite()
     self.gas_code = self.new_gas_code_gadget()
     
     def new_code_to_calculate_gravity_of_gas_particles():
         result = BHTree(self.converter)
         return result
         
     calculate_gravity_code=bridge.CalculateFieldForCodes(
         new_code_to_calculate_gravity_of_gas_particles,  # the code that calculates the acceleration field
         input_codes = [self.gas_code] # the codes to calculate the acceleration field of
     )
     self.gas_to_star_codes = [calculate_gravity_code]
     self.star_to_gas_codes = [self.star_code]
Beispiel #4
0
def run_mc(N=5000, Mcloud=10000. | units.MSun, Rcloud=1. | units.parsec):

    conv = nbody_system.nbody_to_si(Mcloud, Rcloud)

    interaction_timestep = 0.01 | units.Myr
    time_end = 0.36 | units.Myr

    parts = molecular_cloud(targetN=N,
                            convert_nbody=conv,
                            base_grid=body_centered_grid_unit_cube).result

    sph = Fi(conv)

    # need to turn off self gravity, the bridge will calculate this
    sph.parameters.self_gravity_flag = False

    # some typical Fi flags (just for reference, most are default values)
    sph.parameters.use_hydro_flag = True
    sph.parameters.isothermal_flag = True
    sph.parameters.integrate_entropy_flag = False
    sph.parameters.gamma = 1
    sph.parameters.verbosity = 0

    # setting the hydro timestep is important
    # the sph code will take 2 timesteps every interaction timestep
    sph.parameters.timestep = interaction_timestep / 2

    sph.gas_particles.add_particles(parts)

    def new_code_to_calculate_gravity_of_gas_particles():
        result = BHTree(conv)
        return result

    calculate_gravity_code = bridge.CalculateFieldForCodes(
        new_code_to_calculate_gravity_of_gas_particles,  # the code that calculates the acceleration field
        input_codes=[sph]  # the codes to calculate the acceleration field of
    )

    bridged_system = bridge.Bridge()
    bridged_system.timestep = interaction_timestep

    bridged_system.add_system(
        sph,  # the code to move the particles of
        [calculate_gravity_code
         ]  # the codes that provide the acceleration field
    )

    fig = pyplot.figure(figsize=(12, 12))

    ncolumn = 2
    nrow = 2
    nplot = ncolumn * nrow

    grid_size = 3 | units.parsec
    extent = (grid_size * (-0.5, 0.5, -0.5, 0.5)).value_in(units.parsec)

    if nplot > 1:
        plot_timestep = time_end / (nplot - 1)
    else:
        plot_timestep = time_end

    for i in range(nplot):
        ttarget = i * plot_timestep
        print("evolving to time:", ttarget.as_quantity_in(units.Myr))
        bridged_system.evolve_model(ttarget)

        rho = make_map(sph, N=200, grid_size=grid_size)
        subplot = fig.add_subplot(ncolumn, nrow, i + 1)
        subplot.imshow(numpy.log10(1.e-5 +
                                   rho.value_in(units.amu / units.cm**3)),
                       extent=extent,
                       vmin=1,
                       vmax=5)
        subplot.set_title(ttarget.as_quantity_in(units.Myr))

    sph.stop()
    pyplot.show()