ASTR 596 Fall 2025
Instructor: Anna Rosen
Course ethos: Glass-box modeling. Every function is physics-motivated and transparent. This document is your end-to-end reference to sample stellar masses from the Kroupa IMF and positions from a Plummer sphere for star-cluster simulations.
Why these models?¶
Kroupa Initial Mass Function (IMF): Empirical, piecewise power-law description of how many stars form at each mass. It matches the local, near-solar-metallicity stellar population and remains a standard baseline for cluster-scale work.
Plummer model: Simple, analytic, finite-mass, non-singular density profile that approximates bound, relaxed stellar systems. It gives closed-form cumulative mass and an exact inverse-CDF for Monte Carlo sampling of radii.
Learning goals:
Translate physics → probability distributions → samplers.
Build a correct, testable sampler for a broken power law (IMF).
Build a correct, testable sampler for a spherical density profile (Plummer).
2 Canonical Kroupa IMF¶
We use the stellar IMF (counts individual stars, not unresolved systems) with lower and upper mass limits and piecewise power-law slopes. For Project 2 you may use the two-segment form (since for ):
with
Recommended limits:
(hydrogen-burning limit)
(approximate upper stellar mass limit)
2.1 Continuity and Normalization¶
We choose continuity at the break :
with so that .
Let be the expected number of stars. Then
Solve for given (or set such that and then scale to ). For ,
Computing Normalization Constants Analytically¶
To generate exactly stars, compute the normalization constants without numerical integration:
Step 1 - Calculate segment integrals:
For segment 1 ( with slope ):
For segment 2 ( with slope ):
Step 2 - Apply continuity constraint:
With ensuring continuity at :
Step 3 - Compute segment probabilities:
The probability of drawing from each segment:
These probabilities sum to 1 and determine which segment to sample from.
2.2 Inverse-transform sampling within one segment¶
To draw from on with :
Precompute the normalization constant:
Draw from a uniform distribution:
Invert the CDF:
2.3 Piecewise Sampling Algorithm (Two-Segment IMF)¶
Compute segment weights (probabilities) and from the normalized integrals of and .
Draw . If sample from segment 1 using ; else sample from segment 2 using with the inverse formula above.
Numerical guardrails: work in double precision, precompute powers , , and clamp to avoid boundary issues.
3 Plummer Sphere for Spatial Positions¶
3.1 Density and cumulative mass¶
The Plummer density with total mass and scale radius is
The enclosed mass is
Define the CDF for radius: .
3.2 Inverse-transform for the Radius¶
Set with . Solve for :
Draw to avoid infinities.
3.3 Sample angles uniformly on a sphere¶
Draw with and with . Then
3.4 Scale by half-mass radius (user-friendly)¶
If you want a specific half-mass radius :
3.4.1 Typical scales for real star clusters¶
Plummer Scale Parameters for Different Cluster Types
Cluster Type | Scale Radius (a) | Half-mass Radius | Examples |
|---|---|---|---|
Ultra-compact clusters | 0.1-0.3 pc | 0.08-0.23 pc | Super star clusters, nuclear clusters |
Young massive clusters | 0.3-1 pc | 0.23-0.8 pc | Arches, Westerlund 1 |
Open clusters | 0.5-3 pc | 0.4-2.3 pc | Pleiades, Hyades |
Globular clusters | 1-5 pc | 0.8-4 pc | Milky Way globulars |
OB associations (sparse) | 5-20 pc | 4-15 pc | Extended stellar associations |
For computational simulations with N ≤ 200 particles: Use much smaller scales to represent a cluster core:
Testing (N ≤ 50): AU ≈ 0.0005 pc
Production runs (N = 100-200): AU ≈ 0.005 pc
Full cluster (N > 1000): pc (requires advanced algorithms or long runtimes)
3.5 Re-centering¶
After sampling stars with positions and masses , subtract the mass-weighted center of mass so that
3.6 Virial Equilibrium Velocities¶
For a Plummer sphere in virial equilibrium, assign velocities by drawing each component independently from a Gaussian distribution with radius-dependent (1D) velocity dispersion:
where is the total mass and is the Plummer scale radius.
Implementation:
For each particle at radius :
Calculate using the formula above
Draw
Draw
Draw
Validation check: The 3D velocity dispersion should satisfy:
After assigning velocities, subtract the mass-weighted center-of-mass velocity to ensure .
This initialization produces a system with virial ratio (equilibrium). If your initial , check your velocity assignment.
4 Putting It All Together - Initial Conditions Sampler Blueprint¶
Inputs: , (or ), .
Outputs: arrays of stellar masses , positions , and initial velocities .
4.1 If is given¶
Precompute segment probabilities .
For each star: choose segment → draw via inverse-CDF.
Draw → compute → .
Recentre to the mass-weighted COM.
Draw velocities from Gaussian with → .
Avoid rescaling all masses post-hoc (it distorts the IMF).
5) Validation & Diagnostics (Required)¶
5.1 IMF checks¶
Segment counts: fraction below/above matches analytic expectations within sampling error.
Slope recovery: fit a line to log-binned in each segment; slopes .
Mean mass: compare sample mean to the analytic mean
computed analytically using the closed-form integrals for each power-law segment
5.2 Plummer checks¶
CDF check: verify that raised to 3 matches . Equivalently, verify that
is uniform.
Shell counts: number density in spherical shells: .
Half-mass radius: compute and compare to target.
6) Common pitfalls (and fixes)¶
Forgetting normalization of piecewise segments. Fix: compute normalized integrals for segment weights.
Uniform in instead of a power law in . Fix: use inverse-CDF for , not uniform in unless .
Segment weighting error. Fix: compute normalized segment probabilities from integrals, not from slopes or widths.
Angular sampling bias. Fix: sample , .
Radius divergence at . Fix: clamp away from 0 and 1.
Rescaling masses to hit . Fix: prefer stop-at-or-above or reject-last; document choice.
Forgetting Center-of-Mass (COM) recentering. Fix: subtract mass-weighted COM from positions.
7) Energy and Virial Diagnostics for N-body Systems¶
7.1 Energy Components¶
For an N-body gravitational system, monitor these quantities throughout your simulation:
Kinetic Energy (sum over all particles):
where for star .
Gravitational Potential Energy (sum over unique pairs):
Critical: Count each pair only once using , not which would double-count.
Total Energy:
7.2 The Virial Theorem¶
For a self-gravitating system in equilibrium, the time-averaged kinetic and potential energies satisfy:
Define the Virial Ratio:
Physical Interpretation:
: System in virial equilibrium (bound and stable)
: System out of equilibrium (will evolve)
: System is “super-virial” (will expand)
: System is “sub-virial” (will contract)
7.3 Using Energy Conservation for Debugging¶
Monitor all three components (, , ) separately:
If drifts but is stable → potential energy calculation error
If drifts but is stable → kinetic energy or velocity update error
If both drift proportionally → force calculation or integration scheme error
Sudden jumps → likely self-force bug or sign error
Expected Conservation by Method:
Euler/RK2/RK4: will drift (non-symplectic)
Leapfrog: conserved to machine precision (~10-15)
The virial ratio should remain < 0.01 for a properly initialized cluster.
8) Optional Project Extension Ideas¶
Metallicity or density dependence: allow low-mass slopes () and/or the high-mass slope to vary with environmental parameters.
Mass segregation: sample positions conditionally on mass, e.g. with .
Velocities: draw from the Plummer distribution function to start near virial equilibrium, or rescale drawn velocities to a desired virial ratio.
9) Quick-reference formulas¶
IMF inverse within [a,b], :
Plummer radius inverse:
Half-mass scaling: . Continuity constant: .
Code Verification Checklist¶
Before you perform production runs.
Verified slopes from a log-histogram of sampled masses.
CDF test for Plummer radii passes (uniformity of ).
Sample half-mass radius matches target within sampling error.
Documented choice for mass-budget handling (stop-at-or-above vs reject-last).
Code has named constants, units on plots, and asserts for numerical guards.
End of guide.