Exemple #1
0
def _new_galactics_model(halo_number_of_particles,
                         unit_system_converter=None,
                         do_scale=False,
                         verbose=False,
                         **keyword_arguments):

    code = keyword_arguments.pop("code")
    instance = code(unit_converter=unit_system_converter)
    instance.parameters.halo_number_of_particles = halo_number_of_particles
    for (key, value) in keyword_arguments.iteritems():
        setattr(instance.parameters, key, value)

    if verbose:
        print "adopted galaxy model parameters:"
        print instance.parameters

    instance.generate_particles()
    result = instance.particles.copy()

    if hasattr(instance, "gas_particles") and len(instance.gas_particles) > 0:
        resultgas = instance.gas_particles.copy()
    else:
        resultgas = Particles()

    instance.stop()

    if len(resultgas) > 0:
        allpart = ParticlesSuperset([result, resultgas])
    else:
        allpart = result
    allpart.move_to_center()

    # do_scale *is* possible for case with unit converter
    # note that in case of scaling the output galaxy parameters may be very different from the model
    # parameters input
    if do_scale:
        print "Warning: do_scale for a large galactics model may be very slow"
        if verbose:
            print "Warning: do_scale typically changes the galaxy scale parameters quite a lot from the input parameters"
        if len(resultgas) > 0:
            # this is fixable
            raise Exception(
                "scaling of galaxy models with gas currently not possible")
        allpart.scale_to_standard(convert_nbody=unit_system_converter)

    if not unit_system_converter is None:
        result = ParticlesWithUnitsConverted(
            result, unit_system_converter.as_converter_from_si_to_generic())
        result = result.copy()
        if len(resultgas) > 0:
            resultgas = ParticlesWithUnitsConverted(
                resultgas,
                unit_system_converter.as_converter_from_si_to_generic())
            resultgas = resultgas.copy()

    if len(resultgas) > 0:
        # resultincludes the gas particles (but not under the same keys)
        return resultgas, result
    else:
        return result
def _new_galactics_model(halo_number_of_particles, unit_system_converter=None, do_scale=False, verbose=False, **keyword_arguments):

    code=keyword_arguments.pop("code")
    instance = code(unit_converter=unit_system_converter, redirection="none" if verbose else "null")
    instance.parameters.halo_number_of_particles = halo_number_of_particles
    for (key, value) in keyword_arguments.iteritems():
        setattr(instance.parameters, key, value)
    
    if verbose:
        print "adopted galaxy model parameters:"
        print instance.parameters
    
    instance.generate_particles()
    result = instance.particles.copy()
    
    if hasattr(instance,"gas_particles") and len(instance.gas_particles)>0:
        resultgas=instance.gas_particles.copy()
    else:
        resultgas=Particles()
    
    instance.stop()

    if len(resultgas)>0:
        allpart=ParticlesSuperset([result, resultgas])
    else:
        allpart=result
    allpart.move_to_center()

    # do_scale *is* possible for case with unit converter
    # note that in case of scaling the output galaxy parameters may be very different from the model 
    # parameters input
    if do_scale:
        print "Warning: do_scale for a large galactics model may be very slow"
        if verbose:
            print "Warning: do_scale typically changes the galaxy scale parameters quite a lot from the input parameters"
        if len(resultgas)>0:
            # this is fixable
            raise Exception("scaling of galaxy models with gas currently not possible")        
        allpart.scale_to_standard(convert_nbody=unit_system_converter)

    if not unit_system_converter is None:
        result = ParticlesWithUnitsConverted(result, unit_system_converter.as_converter_from_si_to_generic())
        result = result.copy()
        if len(resultgas)>0:
            resultgas = ParticlesWithUnitsConverted(resultgas, unit_system_converter.as_converter_from_si_to_generic())
            resultgas = resultgas.copy()

    if len(resultgas)>0:
      # resultincludes the gas particles (but not under the same keys)
      return resultgas, result
    else:
      return result
Exemple #3
0
def _new_galactics_model(halo_number_of_particles, unit_system_converter=None, do_scale=False, **keyword_arguments):
    instance = GalactICs(unit_converter=unit_system_converter)
    instance.parameters.halo_number_of_particles = halo_number_of_particles
    for (key, value) in keyword_arguments.iteritems():
        setattr(instance.parameters, key, value)
    
    instance.generate_particles()
    result = instance.particles.copy()
    instance.stop()
    
    result.move_to_center()
    if do_scale:
        result.scale_to_standard(convert_nbody=unit_system_converter)
    
    if not unit_system_converter is None:
        result = ParticlesWithUnitsConverted(result, unit_system_converter.as_converter_from_si_to_generic())
        result = result.copy()
    return result
Exemple #4
0
def new_halogen_model(number_of_particles,
                      convert_nbody=None,
                      do_scale=False,
                      redirection='null',
                      **keyword_arguments):
    """
    Create an alpha-beta-gamma-model using Halogen with the given number of 
    particles. Returns a set of equal-mass particles self-consistently sampled 
    from the spherically symmetric density distribution defined by the alpha, 
    beta, and gamma parameters. The model is centered around the origin. 
    Positions and velocities are optionally scaled such that the kinetic and 
    potential energies are 0.25 and -0.5 in nbody-units, respectively.
    
    The alpha, beta, and gamma parameters are (of course) required, but all 
    other Halogen parameters can be used too, e.g. 
    new_halogen_model(..., black_hole_mass = 1.0e6 | units.MSun)
    will set halogen.parameters.black_hole_mass to this value. See 
    help(Halogen().parameters) for an overview of the Halogen parameters.

    :argument number_of_particles: Number of particles to generate in the model
    :argument convert_nbody:  When given will convert the resulting set to SI units
    :argument do_scale: scale the result to exact nbody units (M=1, K=0.25, U=-0.5)
    :argument alpha: alpha parameter in density profile (see amuse/community/halogen/src/doc for details)
    :argument beta:  beta parameter in density profile (see amuse/community/halogen/src/doc for details)
    :argument gamma: gamma parameter in density profile (see amuse/community/halogen/src/doc for details)
    """
    instance = Halogen(unit_converter=convert_nbody, redirection=redirection)
    instance.parameters.number_of_particles = number_of_particles
    for (key, value) in keyword_arguments.items():
        setattr(instance.parameters, key, value)

    instance.generate_particles()
    result = instance.particles.copy()
    instance.stop()

    result.move_to_center()
    if do_scale:
        result.scale_to_standard()

    if not convert_nbody is None:
        result = ParticlesWithUnitsConverted(
            result, convert_nbody.as_converter_from_si_to_generic())
        result = result.copy()
    return result
Exemple #5
0
def new_halogen_model(number_of_particles, convert_nbody = None, do_scale = False, 
        redirection = 'null', **keyword_arguments):
    """
    Create an alpha-beta-gamma-model using Halogen with the given number of 
    particles. Returns a set of equal-mass particles self-consistently sampled 
    from the spherically symmetric density distribution defined by the alpha, 
    beta, and gamma parameters. The model is centered around the origin. 
    Positions and velocities are optionally scaled such that the kinetic and 
    potential energies are 0.25 and -0.5 in nbody-units, respectively.
    
    The alpha, beta, and gamma parameters are (of course) required, but all 
    other Halogen parameters can be used too, e.g. 
    new_halogen_model(..., black_hole_mass = 1.0e6 | units.MSun)
    will set halogen.parameters.black_hole_mass to this value. See 
    help(Halogen().parameters) for an overview of the Halogen parameters.

    :argument number_of_particles: Number of particles to generate in the model
    :argument convert_nbody:  When given will convert the resulting set to SI units
    :argument do_scale: scale the result to exact nbody units (M=1, K=0.25, U=-0.5)
    :argument alpha: alpha parameter in density profile (see amuse/community/halogen/src/doc for details)
    :argument beta:  beta parameter in density profile (see amuse/community/halogen/src/doc for details)
    :argument gamma: gamma parameter in density profile (see amuse/community/halogen/src/doc for details)
    """
    instance = Halogen(unit_converter=convert_nbody, redirection=redirection)
    instance.parameters.number_of_particles = number_of_particles
    for (key, value) in keyword_arguments.iteritems():
        setattr(instance.parameters, key, value)
    
    instance.generate_particles()
    result = instance.particles.copy()
    instance.stop()
    
    result.move_to_center()
    if do_scale:
        result.scale_to_standard()
    
    if not convert_nbody is None:
        result = ParticlesWithUnitsConverted(result, convert_nbody.as_converter_from_si_to_generic())
        result = result.copy()
    return result