如何随机分布 N 个质量,使它们遵循 Python 中的 Plummer 密度分布 [英] How to randomly distribute N masses, such that they follow a Plummer density distribution in Python

查看:43
本文介绍了如何随机分布 N 个质量,使它们遵循 Python 中的 Plummer 密度分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Python 中工作.我有 N 颗恒星,每颗恒星质量为 M_0.我想将这些星星随机分布在半径 R 的体积中,使得密度分布遵循 另请参阅此内容,了解如何根据 Plummer 分布函数自洽地分配速度.

我在这里描述的方法可以在Aarseth 等.阿尔.1974年

I am working in Python. I have N stars, each of one solar mass M_0. I want to randomly distribute these stars in a volume of radius R, such that the density distribution follows a Plummer model, given by this formular:

I understand that M is the total cluster mass, in this case M=NM_0, but am unsure as to how I would code for this mass distribution.

解决方案

In what follows I'm going to assume that you are using numpy in python imported as

import numpy as np

The easiest way to do this is to work in spherical polar coordinates (r,θ,φ)

  • x = r sin(θ) cos(φ)
  • y = r sin(θ) sin(φ)
  • z = r cos(θ)

You then need a way of selecting each of these in turn.

The angular coordinates are easiest so we can start with those. Here we want to pick the angles θ and φ so that they are uniformly distributed on the surface of a sphere.

The Azimuthal Angle (φ)

As there is no additional factors in the area element this can just be chosen uniformly in the range [0,2π)

phi = np.random.uniform(0, 2*np.pi)

The Polar Angle (θ)

Here we need to chose this so that sin(θ)dθ is uniform note that we can write sin(θ)dθ = d(cos(θ)) so in other words for each value of θ that we pick cos(θ) needs to be equally likely. If we sample cos(θ) between [-1,1) then this will give the correct distribution of values of θ

theta = np.arccos( np.random.uniform(-1,1) )

The Radius (r)

Now we have a way of distributing points randomly on the surface of a sphere we now need a way of knowing how the radii are distributed.

For this we need the cumulative mass distribution

which is the amount of mass enclosed at a radius r from the center of the Plummer sphere.

When we create a new star, and place it at radius r, that star will see an amount of mass m(r) of the cluster at positions closer to the center than its own position, and therefore an amount of mass M − m(r) at positions further from the center.

In other words, it will see a fraction m(r)/M of the total mass inside its radial position. Now that fraction could be anything between 0 and 1. It will be 0 if the particle is placed exactly in the center, and it will approach 1 if the particle is placed very far away, reaching 1 when the particle is placed at infinity.

The ranking of each particle, in terms of the enclosed mass, is random and uniform in the mass fraction. In other words, m(r)/M will be a random value between 0 and 1, with each value equally likely.

To get an expression for the radius we thus need to invert m(r) to give us r(m) the radius where a fraction m of the mass will reside

Thus if we pick m uniform in [0,1) we can then use that equation to convert that into the correct radius.

r = a / np.sqrt( np.random.uniform(0, 1)**(-2.0 / 3.0) - 1)

Once your have those coordinates you can use the expressions I gave above to convert them back into cartesians.

That'll do it for one star, I'll leave it to you to figure out how to efficiently do it for n in python.

References

I've based this answer pretty heavily on The Art of Computational Science also see this for how to assign velocities self consistantly from the Plummer distribution function.

The method I've described here can be found in the appendix of Aarseth et. al. 1974

这篇关于如何随机分布 N 个质量,使它们遵循 Python 中的 Plummer 密度分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆