Skip to content

fixed bug in moddump_flyby where secondary's orbit was not being set properly#852

Open
ahermosillo wants to merge 1 commit into
danieljprice:mainfrom
ahermosillo:master
Open

fixed bug in moddump_flyby where secondary's orbit was not being set properly#852
ahermosillo wants to merge 1 commit into
danieljprice:mainfrom
ahermosillo:master

Conversation

@ahermosillo

@ahermosillo ahermosillo commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description:

Components modified:

  • Setup (src/setup)
  • Main code (src/main)
  • Moddump utilities (src/utils/moddump)
  • Analysis utilities (src/utils/analysis)
  • Test suite (src/tests)
  • Documentation (docs/)
  • Build/CI (build/ or github actions)

Type of change:

  • Bug fix
  • Physics improvements
  • Better initial conditions
  • Performance improvements
  • Documentation update
  • Better testing
  • Code cleanup / refactor
  • Other (please describe)

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

  • Bug Fixes
    • Corrected flyby sink placement when modifying dumps.
    • Flyby positions and velocities are now translated relative to the current primary sink, preserving the intended relative motion.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7f0a3593-3db8-4591-bb0b-e29d9194d603

📥 Commits

Reviewing files that changed from the base of the PR and between 6a853b3 and f3ebe66.

📒 Files selected for processing (1)
  • src/utils/moddump_addflyby.f90

📝 Walkthrough

Walkthrough

modify_dump now inserts the flyby secondary with position and velocity translated by the difference between the current and input primary sink states, while retaining the sink-count increment and capacity check.

Changes

Flyby sink translation

Layer / File(s) Summary
Translate inserted flyby state
src/utils/moddump_addflyby.f90
modify_dump increments nptmass, checks array capacity, initializes the secondary from input state, and shifts its position and velocity relative to the current primary sink.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the change: it describes fixing the flyby secondary orbit placement relative to the primary.
Description check ✅ Passed The description follows the template and covers the change, component, type, testing, bots, docs, comments, unit-test idea, and related issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 80 to 82
nptmass_in = 0
call set_orbit(orbit,m1,m2,hacc1,accr2,xyzmh_ptmass_in,vxyz_ptmass_in,&
nptmass_in,(id==master),ierr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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)

Comment on lines +96 to +100
vxyz_ptmass(:,nptmass) = vxyz_ptmass_in(:,2)

vxyz_ptmass(:,nptmass) = vxyz_ptmass(:,nptmass) &
+ vxyz_ptmass(:,1) &
- vxyz_ptmass_in(:,1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant