当前位置: 首页>>代码示例>>Python>>正文


Python Hermite.get_potential_at_point方法代码示例

本文整理汇总了Python中amuse.community.hermite0.interface.Hermite.get_potential_at_point方法的典型用法代码示例。如果您正苦于以下问题:Python Hermite.get_potential_at_point方法的具体用法?Python Hermite.get_potential_at_point怎么用?Python Hermite.get_potential_at_point使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在amuse.community.hermite0.interface.Hermite的用法示例。


在下文中一共展示了Hermite.get_potential_at_point方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test16

# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import get_potential_at_point [as 别名]
 def test16(self):
     particles = new_plummer_model(200)
     particles.scale_to_standard()
     instance = Hermite()
     instance.initialize_code()
     instance.parameters.epsilon_squared = 0.00000 | nbody_system.length**2
     instance.particles.add_particles(particles)
     
     x = numpy.arange(-1,1,0.1) | nbody_system.length
     zero = numpy.zeros(len(x)) | nbody_system.length
     potential0 =  instance.get_potential_at_point(zero, x , zero, zero)
     instance.stop()
     for n in (2, 3, 4):
         
         instance = Hermite(number_of_workers = n)
         instance.initialize_code()
         instance.parameters.epsilon_squared = 0.00000 | nbody_system.length**2
         instance.particles.add_particles(particles)
         potential =  instance.get_potential_at_point(zero, x , zero, zero)
     
         self.assertAlmostRelativeEquals(potential0, potential, 8)
         instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:24,代码来源:test_hermite.py

示例2: test14

# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import get_potential_at_point [as 别名]
    def test14(self):
        instance = Hermite()
        instance.initialize_code()
        instance.parameters.epsilon_squared = 0.00001 | nbody_system.length**2
        
        particles = datamodel.Particles(2)
        particles.mass = [1.0, 1.0] | nbody_system.mass
        particles.radius =  [0.0001, 0.0001] | nbody_system.length
        particles.position = [[0.0,0.0,0.0], [2.0,0.0,0.0]] | nbody_system.length
        particles.velocity = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] | nbody_system.speed
        instance.particles.add_particles(particles)
        
        zero = 0.0 | nbody_system.length
        fx, fy, fz = instance.get_gravity_at_point(zero, 1.0 | nbody_system.length, zero, zero)
        self.assertAlmostEqual(fx, 0.0 | nbody_system.acceleration, 6)
        self.assertAlmostEqual(fy, 0.0 | nbody_system.acceleration, 6)
        self.assertAlmostEqual(fz, 0.0 | nbody_system.acceleration, 6)

        for x in (0.25, 0.5, 0.75):
            x0 = x | nbody_system.length
            x1 = (2.0 - x) | nbody_system.length
            potential0 = instance.get_potential_at_point(zero, x0, zero, zero)
            potential1 = instance.get_potential_at_point(zero, x1, zero, zero)
            fx0, fy0, fz0 = instance.get_gravity_at_point(zero, x0, zero, zero)
            fx1, fy1, fz1 = instance.get_gravity_at_point(zero, x1, zero, zero)
            
            self.assertAlmostEqual(fy0, 0.0 | nbody_system.acceleration, 6)
            self.assertAlmostEqual(fz0, 0.0 | nbody_system.acceleration, 6)
            self.assertAlmostEqual(fy1, 0.0 | nbody_system.acceleration, 6)
            self.assertAlmostEqual(fz1, 0.0 | nbody_system.acceleration, 6)
            
            self.assertAlmostEqual(fx0, -1.0 * fx1, 5)
            fx = (-1.0 / (x0**2) + 1.0 / (x1**2)) * (1.0 | nbody_system.length ** 3 / nbody_system.time ** 2)
            self.assertAlmostEqual(fx, fx0, 2)
            self.assertAlmostEqual(potential0, potential1, 5)
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:38,代码来源:test_hermite.py

示例3: hydro_grid_in_potential_well

# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import get_potential_at_point [as 别名]
def hydro_grid_in_potential_well(mass=1 | units.MSun, length=100 | units.AU):
    converter = nbody_system.nbody_to_si(mass, length)

    # calculate density in field based on solar wind
    # gives a very low number
    molar_mass_hydrogen_proton = 1 | units.g / units.mol
    density_hydrogen_in_stellar_wind = 10 | 1 / units.cm**3
    particles_per_mol = 6.022e23 | 1 / units.mol
    density_hydrogen_in_stellar_wind_in_moles = (
            density_hydrogen_in_stellar_wind
            / particles_per_mol
            )
    density_gas = 100 * (
            density_hydrogen_in_stellar_wind_in_moles
            * molar_mass_hydrogen_proton
            ).as_quantity_in(units.MSun / units.AU**3)

    # override with higher number for plotting
    density_gas = 1e-3 | units.MSun / units.AU**3

    instance = Athena(converter)
    instance.initialize_code()
    instance.parameters.nx = 50
    instance.parameters.ny = 50
    instance.parameters.nz = 1
    instance.parameters.length_x = length
    instance.parameters.length_y = length
    instance.parameters.length_z = length
    instance.parameters.x_boundary_conditions = ("periodic", "periodic")
    instance.parameters.y_boundary_conditions = ("periodic", "periodic")
    instance.parameters.z_boundary_conditions = ("outflow", "outflow")

    # instance.stopping_conditions.number_of_steps_detection.enable()

    instance.set_has_external_gravitational_potential(1)

    instance.commit_parameters()

    grid_in_memory = instance.grid.copy()
    grid_in_memory.rho = density_gas
    pressure = 1 | units.Pa

    grid_in_memory.energy = pressure / (instance.parameters.gamma - 1)
    channel = grid_in_memory.new_channel_to(instance.grid)
    channel.copy()

    instance.initialize_grid()
    particle = Particle(
        mass=mass,
        position=length * [0.5, 0.5, 0.5],
        velocity=[0.0, 0.0, 0.0] | units.kms
    )

    gravity = Hermite(converter)
    dx = (grid_in_memory.x[1][0][0] - grid_in_memory.x[0]
          [0][0]).as_quantity_in(units.AU)
    gravity.parameters.epsilon_squared = dx**2
    gravity.particles.add_particle(particle)

    potential = gravity.get_potential_at_point(
        0 * instance.potential_grid.x.flatten(),
        instance.potential_grid.x.flatten(),
        instance.potential_grid.y.flatten(),
        instance.potential_grid.z.flatten()
    )

    potential = potential.reshape(instance.potential_grid.x.shape)
    instance.potential_grid.potential = potential

    instance.evolve_model(100 | units.yr)
    print(instance.get_timestep().value_in(units.yr))
    value_to_plot = instance.grid.rho[:, :, 0].value_in(
        units.MSun / units.AU**3)
    # value_to_plot = potential[...,...,0].value_in(potential.unit)
    plot_grid(value_to_plot)
开发者ID:amusecode,项目名称:amuse,代码行数:77,代码来源:grid_potential.py


注:本文中的amuse.community.hermite0.interface.Hermite.get_potential_at_point方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。