pisces.extensions.simulation.core.initial_conditions.InitialConditions.compute_center_of_mass_velocity#
- InitialConditions.compute_center_of_mass_velocity(models: str | list[str] = 'all', masses: dict[str, unyt_quantity] | None = None)[source]#
Compute the mass-weighted center-of-mass (COM) velocity for one or more models in the initial conditions.
The COM velocity is:
\[\mathbf{V}_{\mathrm{COM}} = \frac{\sum_i m_i \mathbf{v}_i}{\sum_i m_i}\]where
m_i
is the total mass of modeli
andv_i
is its velocity vector.- Mass values are obtained in the following order:
If
masses
is provided, use those values (must map model name → scalar mass).Otherwise, attempt to read
total_mass
from the model’s metadata.
- Parameters:
models (
str
orlist
ofstr
, optional) – Which models to include in the COM velocity calculation. If"all"
, all models inmodels
are used. If a single model name is given, it will be treated as a list of one.masses (
dict
ofstr
,unyt_quantity
, optional) – Optional mapping from model name to its total mass. Overridestotal_mass
in metadata if provided.
- Returns:
The COM velocity vector with shape
(ndim,)
and units of velocity.- Return type:
- Raises:
KeyError – If any specified model name is not found in the initial conditions.
ValueError – If a required mass is missing from both
masses
and the model metadata.