-
Notifications
You must be signed in to change notification settings - Fork 192
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
Use PostNewtonian.jl for initial orbital parameters #6224
Open
nilsvu
wants to merge
4
commits into
sxs-collaboration:develop
Choose a base branch
from
nilsvu:pn_initial_orbital_params
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+122
−59
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,43 @@ | |
logger = logging.getLogger(__name__) | ||
|
||
|
||
# The following two functions are modernized versions of those in SpEC's | ||
# `ZeroEccParamsFromPN.py`. They use higher PN orders (whichever are implemented | ||
# in the PostNewtonian module), are much faster, and avoid spurious output from | ||
# old Fortran code (LSODA) that was used in SpEC's `ZeroEccParamsFromPN.py`. | ||
# They are consistent with SpEC up to 2.5 PN order, as tested by Mike Boyle (see | ||
# https://github.com/moble/PostNewtonian.jl/issues/41). | ||
# | ||
# Since these functions use Julia through Python bindings, they will download | ||
# Julia and precompile the packages on first use, which may take a few minutes | ||
# (see https://moble.github.io/PostNewtonian.jl/dev/interface/python/). | ||
|
||
|
||
def omega_and_adot(r, q, chiA, chiB): | ||
from sxs.julia import PostNewtonian | ||
|
||
pn = PostNewtonian.BBH( | ||
np.array( | ||
[1.0 / (1.0 + q), q / (1.0 + q), *chiA, *chiB, 1, 0, 0, 0, 1, 0] | ||
) | ||
) | ||
pn.state[12] = PostNewtonian.separation_inverse(r, pn) | ||
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why replace? Please add some docs |
||
return PostNewtonian.Omega(pn), PostNewtonian.separation_dot(pn) / r | ||
|
||
|
||
def num_orbits_and_time_to_merger(q, chiA0, chiB0, omega0): | ||
from sxs.julia import PNWaveform | ||
|
||
pn_waveform = PNWaveform( | ||
M1=1.0 / (1.0 + q), | ||
M2=q / (1.0 + q), | ||
chi1=chiA0, | ||
chi2=chiB0, | ||
Omega_i=omega0, | ||
) | ||
return 0.5 * pn_waveform.orbital_phase[-1] / np.pi, pn_waveform.time[-1] | ||
|
||
|
||
def initial_orbital_parameters( | ||
mass_ratio: float, | ||
dimensionless_spin_a: Sequence[float], | ||
|
@@ -76,8 +113,8 @@ def initial_orbital_parameters( | |
) | ||
return separation, orbital_angular_velocity, radial_expansion_velocity | ||
|
||
# The functions from SpEC currently work only for zero eccentricity. We will | ||
# need to generalize this for eccentric orbits. | ||
# The functions from the PostNewtonian module currently work only for zero | ||
# eccentricity. We will need to generalize this for eccentric orbits. | ||
assert eccentricity == 0.0, ( | ||
"Initial orbital parameters can currently only be computed for zero" | ||
" eccentricity." | ||
|
@@ -97,25 +134,13 @@ def initial_orbital_parameters( | |
" 'time_to_merger'." | ||
) | ||
|
||
# Import functions from SpEC until we have ported them over. These functions | ||
# call old Fortran code (LSODA) through scipy.integrate.odeint, which leads | ||
# to lots of noise in stdout. When porting these functions, we should | ||
# modernize them to use scipy.integrate.solve_ivp. | ||
try: | ||
from ZeroEccParamsFromPN import nOrbitsAndTotalTime, omegaAndAdot | ||
except ImportError: | ||
raise ImportError( | ||
"Importing from SpEC failed. Make sure you have pointed " | ||
"'-D SPEC_ROOT' to a SpEC installation when configuring the build " | ||
"with CMake." | ||
) | ||
|
||
# Find an omega0 that gives the right number of orbits or time to merger | ||
if num_orbits is not None or time_to_merger is not None: | ||
logger.info("Finding orbital angular velocity...") | ||
opt_result = minimize( | ||
lambda x: ( | ||
abs( | ||
nOrbitsAndTotalTime( | ||
num_orbits_and_time_to_merger( | ||
q=mass_ratio, | ||
chiA0=dimensionless_spin_a, | ||
chiB0=dimensionless_spin_b, | ||
|
@@ -140,14 +165,14 @@ def initial_orbital_parameters( | |
|
||
# Find the separation that gives the desired orbital angular velocity | ||
if orbital_angular_velocity is not None: | ||
logger.info("Finding separation...") | ||
opt_result = minimize( | ||
lambda x: abs( | ||
omegaAndAdot( | ||
omega_and_adot( | ||
r=x[0], | ||
q=mass_ratio, | ||
chiA=dimensionless_spin_a, | ||
chiB=dimensionless_spin_b, | ||
rPrime0=1.0, # Choice also made in SpEC | ||
)[0] | ||
- orbital_angular_velocity | ||
), | ||
|
@@ -163,12 +188,11 @@ def initial_orbital_parameters( | |
logger.debug(f"Found initial separation: {separation}") | ||
|
||
# Find the radial expansion velocity | ||
new_orbital_angular_velocity, radial_expansion_velocity = omegaAndAdot( | ||
new_orbital_angular_velocity, radial_expansion_velocity = omega_and_adot( | ||
r=separation, | ||
q=mass_ratio, | ||
chiA=dimensionless_spin_a, | ||
chiB=dimensionless_spin_b, | ||
rPrime0=1.0, # Choice also made in SpEC | ||
) | ||
if orbital_angular_velocity is None: | ||
orbital_angular_velocity = new_orbital_angular_velocity | ||
|
@@ -181,7 +205,7 @@ def initial_orbital_parameters( | |
) | ||
|
||
# Estimate number of orbits and time to merger | ||
num_orbits, time_to_merger = nOrbitsAndTotalTime( | ||
num_orbits, time_to_merger = num_orbits_and_time_to_merger( | ||
q=mass_ratio, | ||
chiA0=dimensionless_spin_a, | ||
chiB0=dimensionless_spin_b, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ spectre_add_python_bindings_test( | |
None | ||
TIMEOUT 60) | ||
|
||
if (SpEC_FOUND) | ||
# Disable this test if using jemalloc as a shared library, because Julia | ||
# doesn't like the 'LD_PRELOAD' trick to load jemalloc for Pybindings. | ||
if (NOT "${JEMALLOC_LIB_TYPE}" STREQUAL SHARED) | ||
Comment on lines
+12
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the source code work in the CLI if we are using JEMALLOC? |
||
spectre_add_python_bindings_test( | ||
"support.Pipelines.EccentricityControl.InitialOrbitalParameters" | ||
Test_InitialOrbitalParameters.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
Please add a note what these magic 1s and 0s are. I believe they are the following, but the docs/code of the julia implementation don't match so I'm unsure...
1 = v (velocity???)
0, 0, 0, 1 = rotor (quaternion??)
0 = phi