fixed bug in moddump_flyby where secondary's orbit was not being set properly#852
fixed bug in moddump_flyby where secondary's orbit was not being set properly#852ahermosillo wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesFlyby sink translation
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces translation logic for the secondary sink particle relative to the primary sink particle in src/utils/moddump_addflyby.f90. Feedback suggests initializing xyzmh_ptmass_in and vxyz_ptmass_in to zero to avoid copying uninitialized garbage values, and simplifying the velocity translation into a single assignment.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| nptmass_in = 0 | ||
| call set_orbit(orbit,m1,m2,hacc1,accr2,xyzmh_ptmass_in,vxyz_ptmass_in,& | ||
| nptmass_in,(id==master),ierr) |
There was a problem hiding this comment.
The local array xyzmh_ptmass_in is declared but not initialized. Since set_orbit only populates specific elements (like position, mass, and accretion radius), other properties of the sink particle (such as spin, etc.) will contain uninitialized garbage values. When copying xyzmh_ptmass_in(:,2) to xyzmh_ptmass(:,nptmass), these garbage values are copied into the active sink particle array. Initializing xyzmh_ptmass_in (and vxyz_ptmass_in for safety) to zero before calling set_orbit prevents this correctness issue.
xyzmh_ptmass_in = 0.
vxyz_ptmass_in = 0.
nptmass_in = 0
call set_orbit(orbit,m1,m2,hacc1,accr2,xyzmh_ptmass_in,vxyz_ptmass_in,&
nptmass_in,(id==master),ierr)
| vxyz_ptmass(:,nptmass) = vxyz_ptmass_in(:,2) | ||
|
|
||
| vxyz_ptmass(:,nptmass) = vxyz_ptmass(:,nptmass) & | ||
| + vxyz_ptmass(:,1) & | ||
| - vxyz_ptmass_in(:,1) |
There was a problem hiding this comment.
The velocity translation can be simplified into a single assignment. Since vxyz_ptmass only contains the 3 velocity components (unlike xyzmh_ptmass which contains other properties that need to be copied first), there is no need to assign vxyz_ptmass_in(:,2) first and then add the offset in a separate statement. Combining them is cleaner and more efficient.
vxyz_ptmass(:,nptmass) = vxyz_ptmass_in(:,2) &
+ vxyz_ptmass(:,1) &
- vxyz_ptmass_in(:,1)
Description:
Components modified:
Type of change:
Testing:
I calculated the secondary's orbital elements using the xyzvxyz data from a dump file, and I confirmed this was the same as the orbital parameters I input in flyby.moddump. I tested this for bound and unbound case.
Did you run the bots? no
Did you update relevant documentation in the docs directory? no
Did you add comments such that the purpose of the code is understandable? yes
Is there a unit test that could be added for this feature/bug? yes
If so, please describe what a unit test might check:
We can test that running this moddump will add a star at the correct orbit for all of the 4 options (bound, unbound, orbit reconstructor, observed dx dy).
Related issues: #851
Summary by CodeRabbit