syllabus example code: hydro_minimal.pyΒΆ

[source code]

   Minimalistic routine for running a hydrodynamics solver
from amuse.lab import *
from import store

def main(N=100, Mtot=1|units.MSun, Rvir=1|units.RSun, t_end=1|units.Myr):
    converter=nbody_system.nbody_to_si(Mtot, Rvir)
    gas = new_plummer_gas_model(N, convert_nbody=converter)
    gas.vx = 100 | units.kms

    hydro = Gadget2(converter)
    Etot_init = hydro.kinetic_energy + hydro.potential_energy + hydro.thermal_energy

    Ekin = hydro.kinetic_energy
    Epot = hydro.potential_energy
    Eth = hydro.thermal_energy
    Etot = Ekin + Epot + Eth
    print "T=", hydro.get_time(), "M=", hydro.gas_particles.mass.sum(),
    print "E= ", Etot, "Q= ", (Ekin+Eth)/Epot, "dE=", (Etot_init-Etot)/Etot
    print "pos-vel=", hydro.gas_particles.center_of_mass(), hydro.gas_particles.center_of_mass_velocity()


def new_option_parser():
    from amuse.units.optparse import OptionParser
    result = OptionParser()
    result.add_option("-N", dest="N", type="int",default = 100,
                      help="number of stars [10]")
    result.add_option("-t", unit=units.Myr,
                      dest="t_end", type="float", default = 1|units.Myr,
                      help="end time of the simulation [%default]")
    result.add_option("-M", unit=units.MSun,
                      dest="Mtot", type="float", default = 1|units.MSun,
                      help="Mass of molcular cloud [%default]")
    result.add_option("-R", unit=units.RSun,
                      dest="Rvir", type="float", default = 1|units.RSun,
                      help="Radius of cloud [%default]")
    return result

if __name__ in ('__main__', '__plot__'):
    o, arguments  = new_option_parser().parse_args()

Keywords: python, amuse, astrophysics, matplotlib, pylab, example, codex (see how-to-search-examples)

This Page