-
Notifications
You must be signed in to change notification settings - Fork 10
Fix accel func #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix accel func #124
Conversation
|
I wanted to test this code yesterday, but I had to fix a compatibility issue of my code with the latest version of pynbody... I'm running a final test with a larger acceleration tomorrow, but I think the result will be similarly consistent. |
|
Thanks @The9Cat! Teng @M1ssing-N0, those tests worked already with the previous version, try to do the test where you put the Sgr potential at some fixed position (-X_sgr, 0,0) from the origin and integrate the orbit of a particle at rest at (0,0,0) see if it now moves towards Sgr in the negative x-direction... |
|
Also checked that one. The particle is pulled towards Sgr correctly. I noticed that the particle may still fly away freely if the potential has a large acceleration. The acceleration is very large though, 1e5 km/s/Gyr. Is that a reasonable behavior for the code? |
|
The code is simply using time-centered leap frog to solve the equations of motion given the force. So orbits should not be erratic unless the gravitational field itself is very rough Since you have a fixed potential, I recommend checking energy conservation for your orbit using the evaluation operator. E.g. if your basis instance is |
|
I've exposed the center in pyEXP, such that along with the time of a coefficient structure, we can also inspect (and set!) the center. I was getting frustrated building an example that I couldn't quickly get the center. On being I have a draft version that also duplicates the |
|
The initial design intentionally makes the center immutable. That is, the center is set when the coefficients are created and remains a fixed attribute. So explicitly That may be too restrictive and I'm fine with a more flexible API. After all, one can modify coefficient values for various purposes. Perhaps having |
|
I think that's a fine compromise -- mainly I want some way to get and set the centre in pyEXP.
|
|
Looks good to me. On your two points:
|
The particle escaped the potential soon after the simulation starts (positive total energy) and the gravity from the potential become negligible, so I think the behavior is indeed reasonable. I'm excited about the new member functions. The getter function is important for testing and the setter function can be particularly useful when working on a model with multiple components like the Milky Way. Plus |
|
Thanks, @M1ssing-N0 and @The9Cat for good naming suggestions. I've now
Last question: should |
|
For convenience, I think it's fine to have |
|
Good idea. Okay, they are exposed I think if we're all happy we can go ahead and merge this. |
|
These changes look fine to me. Do you have a MWE for |
|
I'm working on a MWE -- will have it set up soon and link here. The last commit sets an explicit zero center if the user doesn't pass anything (rather than being implicitly 0,0,0). This isn't ideal, I think, as the different structures could have a different number of dimensions, but having three zeros seems safest. The center needs to be set for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Thought we were doing that somewhere already, but no...
Yes, should be a 3d center. I think the design assumes a three-vector even if the system is 2d.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the acceleration function by propagating the expansion center to the force evaluation. Key changes include updating the Python bindings in pyEXP/CoefWrappers.cc, initializing and managing the center data in expui/CoefStruct.H, and applying the center offset in the field evaluations in expui/BiorthBasis.cc.
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pyEXP/CoefWrappers.cc | Updated bindings: changed time to readonly and added center access and mutators with accompanying docstrings. |
| expui/CoefStruct.H | Initialized the center vector and added getter and setter functions for center and time. |
| expui/BiorthBasis.cc | Adjusted acceleration evaluation to subtract the expansion center from field coordinates. |
| expui/BasisFactory.H | Exposed the basis expansion center through a new getter. |
Files not reviewed (1)
- CMakeLists.txt: Language not supported
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
This is a draft fix for the expansion center behavior described by @chervs in
IntegrateOrbits()Details
I put in all the infrastructure in
pyEXPfor propagating the expansion center to theAccelFuncbasis evaluation but then didn't use it for providing translated coordinates for the force evaluation.This PR is a fix for that.
@M1ssing-N0 : Would you compile this branch and try your failing example? Thanks.