BUG: Always use the coordinate system normal for computing angular momentum components for particles #4872
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
The current code for computing angular momentum components for particle fields based on their positions and velocities has an incorrect assumption. That is, if there is a
normal
field parameter (such as in the case of disk objects), that this is the normal vector that should be considered in the computation of the angular momentum. If there is no normal parameter, the normal vector is assumed to be [0,0,1]. This normal vector along with the center position is used to compute the components of position and velocity for the computation of the angular momentum vector.The problem with using the
normal
vector from the field parameter (if it exists) is that it involves rotating the coordinate system to one other than the default cartesian coordinate system from the dataset, but in fact the latter is the coordinate system that we want the vector components in, so we do not want to rotate. The solution is to assume that normal is always [0,0,1] for Cartesian coordinate systems.FWIW, the computation of the gas angular momentum in
yt/fields/angular_momentum.py
does not use the normal vector at all and thus this change brings the calculation of the angular momentum for both particles and gas into agreement with each other.PR Checklist