Coder Social home page Coder Social logo

dtamayo / reboundx Goto Github PK

View Code? Open in Web Editor NEW
79.0 15.0 59.0 13.58 MB

A library for adding additional forces to the REBOUND N-body integration package

License: GNU General Public License v3.0

C 11.41% Makefile 0.09% Python 3.05% Jupyter Notebook 85.43% Dockerfile 0.01%

reboundx's Introduction

https://img.shields.io/badge/REBOUNDx-v4.2.2-green.svg?style=flat https://travis-ci.org/dtamayo/reboundx.svg?branch=master https://coveralls.io/repos/dtamayo/reboundx/badge.svg?branch=master&service=github https://img.shields.io/badge/license-GPL-green.svg?style=flat https://readthedocs.org/projects/pip/badge/?version=latest https://img.shields.io/badge/arXiv-1908.05634-green.svg?style=flat https://img.shields.io/badge/launch-binder-ff69b4.svg?style=flat

Welcome to REBOUNDx (eXtras)

REBOUNDx allows you to easily incorporate additional physics into your REBOUND simulations. The main code is written in C, and we provide a convenient Python wrapper. For an overview of the technical details and some practical recommendations, see Tamayo, Rein, Shi and Hernandez 2019. The paper publication lines up with REBOUNDx version 3.0.0.

Documentation

For a list of supported effects, and descriptions of the parameters that need to be set for each effect, see the documentation at https://reboundx.readthedocs.io. You can also find installation instructions and a quickstart guide there.

Attribution

We have tried to structure the documentation in a way that makes it easy to credit the various people who have contributed to any given effect. Please see the Attribution section at https://reboundx.readthedocs.io for direct links to ADS.

Changelog

https://github.com/dtamayo/reboundx/blob/main/changelog.md

reboundx's People

Contributors

acpetit avatar alekseygenerozov avatar aryaakmal avatar bearsy0 avatar dangcpham avatar dtamayo avatar findus23 avatar gabrielepichierri avatar hannorein avatar kaltrinak avatar malidib avatar meldonization avatar michaelkmpoon avatar nofe4108 avatar sabaronett avatar tigerchenlu98 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reboundx's Issues

Custom Effects and Parameters

Hi Dan,

I have a question about designing/implementing custom effects; especially in regards to potentially "shared" parameters.

Section 6.2 (Adding Parameters) says:

You cannot use particle parameter names that are in use by other effects, so search first for the name you are planning to add.

What does this mean for the multiple Speed of Light (C) values that your GR and Radiation forces are using. For example, if I were to add both GR and the Radiation Forces effects to a simulation, would you have to assign the C parameter for each force separately?

I have potentially three overlapping forces which I want to include in my simulations all of which would reference a particles spin period and obliquity. The software development side of me want's to define each of my forces separately so that other users (or even myself) can pick and choose what forces to include etc...

I might find it more convenient to throw the three forces into one function however if it means simplifying the referencing of parameters.

How difficult would it be for separate forces to share particle parameters?

Thanks by the way for the very thoughtful documentation on adding new forces!

Best,

-Robert

REBx not playing well with REBOUND Version 3.17

Hi Dan,

Following a conversation with @hannorein, I upgraded my local Rebound project to version 3.17. During my next build of Rebx (trying to better diagnose #62) I encountered a build error.

I found that in steppers.c that many functions that were previously defined in rebound.h such as reb_integrator_ias15_reset had been moved to either integrator_ias15.h or integrator_whfast.h. These changes to the rebound.h file occurred during the documentation updates in the commit by @hannorein titled:

'The documentation is now using MkDocs and the Material theme.'

For the C build, I was able to solve these errors imply by including these files at the top of steppers.c. When I continued however to build the local pip installation (i.e. pip install -e .) the build broke with a fatal file not found error, where the newly included files integrator_ias15.h and integrator_whfast.h where causing the issue. I guess this is solvable with an updated include path for the compilation, but I am not that experienced yet with such flags.

I believe that this issue should be present for any user who has upgraded to REBOUND v3.17

Let me know how I can help,

-Robert

Python QuickStart Guide

I just needed a quick example to see if REBOUNDx is working, so I looked at the quick start guide. I'm probably just a bit slow, but it took me way too long to remember that I need to add rebx.add_operator(mm) if I want to have the modify_mass module actually do anything. Am I missing something or should we add that line to the quick start guide?

python 3.5/3.6/3.7 librebound.cpython-36m-x86_64-linux-gnu.so import error

I'm having issues with import reboundx giving OSError: librebound.cpython-35m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory on Linux within a python virtualenv. The commands I'm using are:

virtualenv -p python3 venv
source venv/bin/activate
pip install rebound reboundx
(then start a python session in the virtualenv)
python

import rebound
import reboundx

When I run import reboundx I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data_local/zyrxvo/venv/lib/python3.5/site-packages/reboundx/__init__.py", line 13, in <module>
    clibreboundx = cdll.LoadLibrary(pymodulespath + '/../libreboundx' + suffix)
  File "/usr/lib/python3.5/ctypes/__init__.py", line 425, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python3.5/ctypes/__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: librebound.cpython-35m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory

This example uses Python/3.5.3, but I also get the same issue with Python/3.6 and Python/3.7. It might seem obvious that the errors are different for each version of python giving librebound.cpython-35m-x86_64-linux-gnu.so, librebound.cpython-36m-x86_64-linux-gnu.so, and librebound.cpython-37m-x86_64-linux-gnu.so but I've included copies of all 3 just incase it comes up with a Google search result for those who don't know.

The issue does not appear when the same commands are used in macOS (10.14.6). There was a similar issue brought up before (#26) that was closed April 2018. The previous solution was,

In case anyone runs into similar problems like me... upgrade rebound (not reboundx) to 3.5.13 appears to solve the problem.

However, this solution is outdated.

After digging around, it seems to work if reboundx is installed from a git repo. So if I use a local copy of reboundx and first update it with git pull origin master to git-hash fc75c72e43a27f7a54a98a4c7e5f314182341e88 (Fri Aug 16 11:44:19) and I install it using pip install -e . then everything seems to work.

Even so, this does not always work if a local git repo of rebound is also installed using pip install -e ., but it does always seem to work if rebound is installed with pip install rebound. When installed using pip install rebound the rebound git-hash is 1d360a4bbe951b7826dc4654cd1a820259571fb2 (Thu Aug 15 10:01:27 2019). But the newest git-hash in rebound is currently 74addbcedc64a44541f2e2a0c38ba3bd52c064e4 (Fri Aug 16 09:41:21), so maybe this is a rebound issue and not a reboundx issue. But the error is given on import reboundx so I'm submitting it here.

"OSError: librebound.cpython-37m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory" when importing reboundx on Google Colab

Hello,
I have been trying to use rebound and reboundx in a Google Colab notebook, but I keep getting the following error:

import reboundx

OSError                                   Traceback (most recent call last)

[<ipython-input-5-44515272dadb>](https://localhost:8080/#) in <module>
----> 1 import reboundx

2 frames

[/usr/local/lib/python3.7/dist-packages/reboundx/__init__.py](https://localhost:8080/#) in <module>
     11 pymodulespath = os.path.dirname(__file__)
     12 from ctypes import *
---> 13 clibreboundx = cdll.LoadLibrary(pymodulespath + '/../libreboundx' + suffix)
     14 
     15 # Version

[/usr/lib/python3.7/ctypes/__init__.py](https://localhost:8080/#) in LoadLibrary(self, name)
    440 
    441     def LoadLibrary(self, name):
--> 442         return self._dlltype(name)
    443 
    444 cdll = LibraryLoader(CDLL)

[/usr/lib/python3.7/ctypes/__init__.py](https://localhost:8080/#) in __init__(self, name, mode, handle, use_errno, use_last_error)
    362 
    363         if handle is None:
--> 364             self._handle = _dlopen(self._name, mode)
    365         else:
    366             self._handle = handle

OSError: librebound.cpython-37m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory

I could share an example notebook if it helps, but the only other thing I've done is run pip install rebound reboundx. Is there any workaround, or is the library incompatible with Google Colab?

gr_source flag not working

Hi,

When adding General Relativity effects using "gr", it says in the documentation that the "gr_source" flag can be applied to a specific particle in the simulation to indicate that the effects should be applied using that particle as the source. It also seems that this effect should be able to be applied using multiple particles as sources. My use case is that I have multiple particles where GR is significant but too many particles to run "gr_full" without significant slowing. Looking in the gr.c file, it seems that the source is hardcoded to be the particle with index 0. Was this a functionality that got removed for some reason?

MPI

I've reimplemented the MPI stuff in REBOUND. I'll plan to merge the mph branch into the master branch some time soon. I'm letting you know because I had to add one variable to the reb_simulation struct and it will break REBOUNDx.

Setting beta via sim.particles[i].beta does not work?

I'm following this example to set the beta by

sim.particles[0].beta = 0.1

But if I try to print sim.particles[0].beta, I get the error of "'Particle' object has no attribute 'beta'".

If I follow this example instead and set beta by, e.g. ps["p1"].params["beta"] = 0.1, then all works as expected.

Why does the first way not work -- did I miss something there?

Adding custom operator and force without overwriting

Hello. I am trying to incorporate both GR and my custom operator. Although I am adding the force and operator through REBOUNDx (as instructed in Custom_Effects.ipynb), the results indicate that the first function is still overwritten. Is there a problem with how I am calling the functions? Thanks!

if gr == True:
    rebx = reboundx.Extras(sim)
    gr = rebx.load_force("gr")
    gr.force_type = "pos"
    rebx.add_force(gr)
    gr.params["c"] = constants.C  

if tides == True:
    rebx = reboundx.Extras(sim)
    mod = rebx.load_operator("modify_orbits_direct2")
    mod.operator_type = "updater"
    rebx.add_operator(mod)
    tau = 5e4
    ps[1].params["tau_e"] = tau

REBOUNDx error: Force 'type_I_migration' not found in REBOUNDx library.

Hello,

I am having issues with implementing Type I Migration. I downloaded the ipython example and tried running it without any modifications and it showed me the following error

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-7-10ea43c03dd8> in <module>
      1 rebx = reboundx.Extras(sim)
----> 2 mig = rebx.load_force("type_I_migration")
      3 rebx.add_force(mig)
      4 
      5 mig.params["tIm_scale_height_1"] = 0.03

/usr/local/Cellar/jupyterlab/3.0.1/libexec/lib/python3.9/site-packages/reboundx/extras.py in load_force(self, name)
     81         clibreboundx.rebx_load_force.restype = POINTER(Force)
     82         ptr = clibreboundx.rebx_load_force(byref(self), c_char_p(name.encode('ascii')))
---> 83         self.process_messages()
     84         return ptr.contents
     85 

/usr/local/Cellar/jupyterlab/3.0.1/libexec/lib/python3.9/site-packages/reboundx/extras.py in process_messages(self)
    205     def process_messages(self):
    206         try:
--> 207             self._sim.contents.process_messages()
    208         except ValueError: # _sim is NULL
    209             raise AttributeError("REBOUNDx Error: The Simulation instance REBOUNDx was attached to no longer exists. This can happen if the Simulation instance goes out of scope or otherwise gets garbage collected.")

/usr/local/Cellar/jupyterlab/3.0.1/libexec/lib/python3.9/site-packages/rebound/simulation.py in process_messages(self)
    703                 warnings.warn(msg[1:], RuntimeWarning)
    704             elif msg[0]=='e':
--> 705                 raise RuntimeError(msg[1:])
    706 
    707 

RuntimeError: REBOUNDx error: Force 'type_I_migration' not found in REBOUNDx library.

I already tried uninstalling reboundx and installing it again with pip.

Thanks in advance

Question about documentation

I was wondering about the following statement in section 6.1 docs: "Note that we should specifically update the passed particles array (NOT sim->particles)."

What exactly is the issue with doing this? Would updating sim->particles also be an issue for new effects?

I know this is not an issue per se, so apologies if this is not the right forum.

Thank you!

Aleksey

Makefiles

Is there a reason why I cannot compile the library from the main directory? Right now I need to go to examples/ to type make. If I type make in the main directory, it calls make clean.

implement machine independent math functions?

Several effects need math functions (trig functions, pow, log) that are not platform independent in the C99 standard. It would be nice to implement machine independent functions even if they're slower than the standard functions so that we can rely on REBOUNDx also being machine independent. Here's a starting point

https://github.com/sunsided/libfixmath

though at least some of the functions are meant for computer graphics and are low accuracy

Change parameter (beta, mass) during integration run

As a user, I like to change certain values during the course of the integration, using feedback from the integration. Consider a light sail in form of a reflective sphere which may change its reflectivity (the beta value). When it gets closer to the star, it increases reflectivity, and vice versa. If beta can be adjusted during the run, depending on the distance between two objects, interesting trajectories can be simulated.

One may take this further and also modify parameters such as the mass of a body. This is already possible using a given (set once and forget) function, as shown in the example "ModifyMass.ipynb". However, it appears not to be possible to change mass or luminosity depending on external conditions.

tides forces

Hi all,

I have resumed and old project about tides forces. I coded the equations for a reboundx module but I have a doubt in the last part, after compute the tides forces.
The point is that the final particle acceleration is given by:

acelaration

Where F^{T} are the tides forces and F^{GR} and F^{R} are not considered in this case. So, please ignore them.
As one can notice, the main problem is that every planet acceleration depends on the forces of the others planets in the problem. So, when I coded the module (following the examples and the guide)
I have something like that:


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "reboundx.h"

static void rebx_calculate_tides_forces(struct reb_simulation* const sim, const double K2s, const double K2sDt, const double Ss_z, const double Rs, const int source_index){
    struct reb_particle* const particles = sim->particles;
    struct reb_particle* const source = &particles[source_index];
    const double G = sim->G;
     
    
    const int _N_real = sim->N - sim->N_var;

    for (int i=0;i<_N_real;i++){
        
        const double* K2p = rebx_get_param_check(&particles[i], "K2p", REBX_TYPE_DOUBLE);
        if(K2p == NULL) continue; // only particles with K2p set feel tidal forces
        
        const double* K2pDt = rebx_get_param_check(&particles[i], "K2pDt", REBX_TYPE_DOUBLE);
        if(K2pDt == NULL) continue; // 
        
        const double* Sp_z = rebx_get_param_check(&particles[i], "Sp_z", REBX_TYPE_DOUBLE);
        if(Sp_z == NULL) continue; // 
        
        const double* Rp = rebx_get_param_check(&particles[i], "Rp", REBX_TYPE_DOUBLE);
        if(Rp == NULL) continue; // 
 
        const struct reb_particle p = particles[i]; 

Then, I computed the forces for every i-planet inside the for loop. I don't copy here all the equations involved to avoid the mesh. At the end, we have:

	double F_x = (F_tr+(Ptop+Ptos)*(v_dot_er/rps)) * er_x + Ptop*(Sp_cross_er_x - (1./rps_2)*triple_product_x) + Ptos*(Ss_cross_er_x-(1./rps_2)*triple_product_x);
	double F_y = (F_tr+(Ptop+Ptos)*(v_dot_er/rps)) * er_y + Ptop*(Sp_cross_er_y - (1./rps_2)*triple_product_y) + Ptos*(Ss_cross_er_y-(1./rps_2)*triple_product_y);
	double F_z = (F_tr+(Ptop+Ptos)*(v_dot_er/rps)) * er_z + Ptop*(Sp_cross_er_z - (1./rps_2)*triple_product_z) + Ptos*(Ss_cross_er_z-(1./rps_2)*triple_product_z);
	
	// Compute the accelaration 
	
	F_x *= reduced_mass;
	F_y *= reduced_mass;
	F_z *= reduced_mass;

        particles[i].ax += F_x;
        particles[i].ay += F_y;
        particles[i].az += F_z;
	
	
	}
	
}

void rebx_tides_forces(struct reb_simulation* const sim, struct rebx_effect* const tides_forces){ 
    double* K2s = rebx_get_param_check(tides_forces, "K2s", REBX_TYPE_DOUBLE);
    if (K2s == NULL){
        reb_error(sim, "Need to set potential love number of the star (K2s) in tides_forces effect.\n");
    }
    double* K2sDt = rebx_get_param_check(tides_forces, "K2sDt", REBX_TYPE_DOUBLE);
    if (K2sDt == NULL){
        reb_error(sim, "Need to set potential love number times constant time lag of the star (K2sDt) in tides_forces effect.\n");
    }
    double* Ss_z = rebx_get_param_check(tides_forces, "Ss_z", REBX_TYPE_DOUBLE);
    if (Ss_z == NULL){
        reb_error(sim, "Need to set the Spin in Z direction of the star (Ss_z) in tides_forces effect.\n");
    }
    double* Rs = rebx_get_param_check(tides_forces, "Rs", REBX_TYPE_DOUBLE);
    if (Rs == NULL){
        reb_error(sim, "Need to set the radio of the star (Rs) in tides_forces effect.\n");
    }
    const int N_real = sim->N - sim->N_var;
    struct reb_particle* const particles = sim->particles;
    int source_found=0;
    for (int i=0; i<N_real; i++){
        if (rebx_get_param_check(&particles[i], "Star", REBX_TYPE_INT) != NULL){
            source_found = 1;
            rebx_calculate_tides_forces(sim, *K2s, *K2sDt, *Ss_z, *Rs, i);
        }
    }
    if (!source_found){
        rebx_calculate_tides_forces(sim, *K2s, *K2sDt, *Ss_z, *Rs, 0);    // default source to index 0 if "radiation_source" not found on any particle
    }
}



However, with this formulation, I computed for i-planet the tidal forces and its acceleration, but without taken into account the forces corresponding to others planets. So, basically I'm computing only the
first term in the right hand of the equation showed at the beginning, and it is missing the second term.

Any suggestion about how to include this missing part?

Sorry in advance if it's not very clear the problem I have. I will be glad to re-explain if necessary.

Thank you very much =)

reboundx install failed on my Macbook

Background

When I try to install reboundx, I get the traceback shown below. It shouldn't matter, but I'm running python from a virtualenv.

My system info:

$ sysctl -n machdep.cpu.brand_string
Apple M1 Pro
$
$ uname -a
Darwin WS-T604GF3GK0.tld 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000 x86_64
$
$ python -V
Python 3.9.14
$
$ which python
/Users/mike.pennington/py_venv/py3_9/bin/python
$

Traceback from pip install -U spock:

$
WS-T604GF3GK0 mike.pennington$ pip install -U reboundx
Collecting reboundx
  Using cached reboundx-3.7.1.tar.gz (5.3 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  ร— python setup.py egg_info did not run successfully.
  โ”‚ exit code: 1
  โ•ฐโ”€> [11 lines of output]
      fatal: not a git repository (or any of the parent directories): .git
      /Users/mike.pennington/py_venv/py3_9/lib/python3.9/site-packages/setuptools/installer.py:27: SetuptoolsDeprec
        warnings.warn(
      running egg_info
      creating /private/var/folders/st/rhqxlbh534q5bv8200h1pykw0000gq/T/pip-pip-egg-info-ds20p1mw/reboundx.egg-info
      writing /private/var/folders/st/rhqxlbh534q5bv8200h1pykw0000gq/T/pip-pip-egg-info-ds20p1mw/reboundx.egg-info/PKG-INFO
      writing dependency_links to /private/var/folders/st/rhqxlbh534q5bv8200h1pykw0000gq/T/pip-pip-egg-info-ds20p1mw/reboundx.egg-info/dependency_links.txt
      writing requirements to /private/var/folders/st/rhqxlbh534q5bv8200h1pykw0000gq/T/pip-pip-egg-info-ds20p1mw/reboundx.egg-info/requires.txt
      writing top-level names to /private/var/folders/st/rhqxlbh534q5bv8200h1pykw0000gq/T/pip-pip-egg-info-ds20p1mw/reboundx.egg-info/top_level.txt
      writing manifest file '/private/var/folders/st/rhqxlbh534q5bv8200h1pykw0000gq/T/pip-pip-egg-info-ds20p1mw/reboundx.egg-info/SOURCES.txt'
      error: dlopen(/private/var/folders/st/rhqxlbh534q5bv8200h1pykw0000gq/T/pip-install-hym1d65q/reboundx_0959fc94734d4b83af22664e17f6199e/.eggs/rebound-3.20.0-py3.9-macosx-12-arm64.egg/rebound/../librebound.cpython-39-darwin.so, 0x0006): tried: '/private/var/folders/st/rhqxlbh534q5bv8200h1pykw0000gq/T/pip-install-hym1d65q/reboundx_0959fc94734d4b83af22664e17f6199e/.eggs/rebound-3.20.0-py3.9-macosx-12-arm64.egg/rebound/../librebound.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), '/private/var/folders/st/rhqxlbh534q5bv8200h1pykw0000gq/T/pip-install-hym1d65q/reboundx_0959fc94734d4b83af22664e17f6199e/.eggs/rebound-3.20.0-py3.9-macosx-12-arm64.egg/librebound.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

ร— Encountered error while generating package metadata.
โ•ฐโ”€> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Citation?

We have a manuscript that uses reboundx in their analysis. Presently they mention the software by name along with a github URL. This makes it very hard to track its use in systems like google scholar or NASA ADS.

We would like to know if you have a preferred citation for this code; specifically, a citation that can be put into the list of references for it.

thanks in advance,

gus muench
data scientist, ApJ/AJ

Confusing function name in "type_I_migration.c"

Hi,

in the file "type_I_migration.c", that implements type I migration, what is called the semi-major axis damping timescale is
probably meant to be the migration timescale, which isn't the same. This can be a source of confusion and it might be a good idea to use a different naming convention (e.g. migration timescale, as in Cresswell&Nelson2008).

Issue regarding modifying the mass

Hi all, I got a bug which intrigued me for several days. I was trying to write and implement two new effects, one is migration and the other one is mass accretion. The migration was implemented as a velocity dependent force, and the mass accretion depended on mass, position of the particle and time as well. It looked like each of them worked well as designed on its own, however, when I tried to combine them together, the integration always quit in the middle and gave a warning message: "Warning! At least 10 predictor corrector loops in IAS15 did not converge..." I checked the orbital output and found out the orbit started to be very unstable after some time. To separate the issue I replace the mass accretion differential with some simple function that only depends on time, namely the logistic function, and it works fine even when combining with the migration effect. Can you give any suggestion about the reason for this problem? Thank you very much.

[Question]:Transition guide for HNBody users: How to implement Earth-Moon quadrupole attraction?

Hi,
first: many thanks for making such nice open-source tools (both Rebound + ReboundX),

I am not an astronomer, but user of a different package (HNBody) so far, mainly doing
long-term solar system integrations.

I would like to migrate to an open-source package for reproducibility and ease of hacking, and
managed to follow the examples etc., to approximate HNBody's setup (e.g. including postNewtonian GR
corrections and sun J2 corrections) ...

HNBody has a some drivers that implements either an Earth-Moon sub integration (ems), or a simpler "lunar" driver, but I am not sure how to translate that into one of the Rebound(X) J2/J4 examples, which seem to be related. Do you have any suggestions?

A separate question about HNBody vs Rebound: I think HNBody implements Kahan Summation in the integration steps, claiming reduced round-off by several orders of magnitude. I looked at the Rebound code and it seems everything is coded in terms of doubles --- would this make a big difference or is this addressed by other means?

Many thanks!

rebx_calculate_energy

There is a convenience function defined on the python side which is msising from c:

rebx.calculate_energy()

Acceleration Output as 0 when integrating with REBOUNDx

I have found once adding an additional force effect with REBOUNDx, after integrating the accelerations are output to be 0.

For example, this correctly outputs an acceleration before integrating with the additional force, but outputs 0.0 for the accelerations after adding the force and integrating. (Base code from this tutorial https://github.com/dtamayo/reboundx/blob/master/ipython_examples/GeneralRelativity.ipynb)

import rebound
sim = rebound.Simulation()
sim.add(m=1., hash="star") # Sun
sim.add(m=1.66013e-07,a=0.387098,e=0.205630, hash="planet") # Mercury-like
sim.move_to_com() # Moves to the center of momentum frame
ps = sim.particles

print("Initial acceleration in x direction should be 0:  ", ps[1].ax)
sim.integrate(10.)
print("Acceleration in x direction after first integration should not be 0:  ", ps[1].ax)
print("pomega = %.16f"%sim.particles[1].pomega)

import reboundx
rebx = reboundx.Extras(sim)
gr = rebx.add("gr")

from reboundx import constants
gr.params["c"] = constants.C

ps["star"].params["gr_source"] = 1

print("Acceleration in x direction after adding gr should not be 0:  ", ps[1].ax)

deltat = 100.
E0 = rebx.gr_hamiltonian(sim, gr)
sim.integrate(sim.t + deltat)
Ef = rebx.gr_hamiltonian(sim, gr)
print("Acceleration in x direction after adding gr and integrating should not be 0 but will be:  ", ps[1].ax)

print("pomega = %.16f"%sim.particles[1].pomega)
juliancentury = 628.33195 # in yr/2pi
arcsec = 4.8481368e-06 # in rad
print("Rate of change of pomega = %.4f [arcsec / Julian century]"% (sim.particles[1].pomega/deltat*juliancentury/arcsec))
print("Relative error on the relativistic Hamiltonian = {0}".format(abs(Ef-E0)/abs(E0)))

How would one get the acceleration info of the particles post integration?

Thanks!

Best,
Kaisa

Error messages

Right now the reboundx error messages will only appear after the simulation is finished. If it's a long running simulation, that could be a problem. It would be nice to terminate the rebound simulation immediately if there is a serious reboundx error. Example:

sim = ...
rebx = reboundx.Extras(sim)
gr = rebx.add("gr_potential")
# gr.params["c"] = constants.C # without this line an error occurs
sim.integrate(1e9) # simulation runs for a long time, error appears at end

Problem in installing REBOUND X

Hi all,
I recently upgraded to a Mac system , I was using REBOUND and REBOUND X in my previous Linux machine. Now, in this new Mac machine I was able to install Rebound successfully and it's running ,but I am somehow not being able to install Rebound X , It always gives me an error message and then terminate the installation whenever I try to install it using "pip install reboundx" . I have attached two Screenshots of the same . Also to just let you know , I have tried this in both my Global as well as Virtual environment , but still Rebound X is not getting installed.
Previously , I had a conversation with @hannorein , and he suggested me to post the issue here in the forum.
I would be really thankful to you all if you can help me out with this.

Screenshot 2021-06-23 at 12 12 58 PM

Screenshot 2021-06-23 at 12 13 15 PM

Error Not being thrown when it should

Hi Dan,

I made my first simple force, but the example script didn't seem to actually be connecting to the force code.

I had used the radiation forces code as my template, so I went into the radiation forces (circumplanetary) example file to make sure it was running correctly.

I knew something was off when I saw that p1 and p2 had the same eccentricity values at each time step. Even stranger, is that I went into file and commented out the setting of the speed of light parameter, saved and recompiled, and the output was identical. Not to mention that Rebx should have thrown an error when it tried to integrate without the parameter being set!

(I tested this radiation forces bug in main as well to make sure it wasn't something I introduced in my new branch...)

Any idea what could be going on. Does rad_forces_circumplanetary work correctly for you in C?

Best,
-Robert

librebound.cpython-39-x86_64-linux-gnu.so import error

Hi, it seems like this issue comes up every few years or so (#26, #39) , so I guess it's my turn. I have a custom version of rebound and a custom version of reboundx.

After modifying the source code, I reinstalled rebound and then reboundx (using pip install -e . in their respective directories). This occured without any error. Importing rebound separately worked without any issues too. However, when I tried to import reboundx, I encountered the following error:

>>> import reboundx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/g/Documents/pwds/reboundx/reboundx/__init__.py", line 13, in <module>
    clibreboundx = cdll.LoadLibrary(pymodulespath + '/../libreboundx' + suffix)
  File "/home/dang/anaconda3/envs/planets/lib/python3.9/ctypes/__init__.py", line 460, in LoadLibrary
    return self._dlltype(name)
  File "/home/dang/anaconda3/envs/planets/lib/python3.9/ctypes/__init__.py", line 382, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: librebound.cpython-39-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory

I also tried to use python setup.py install in both directories to install, but the same issue occurred. I'm not quite sure what could have went wrong and it seems like the previous issues' solutions don't apply here. Thanks for your help!

Dang

Migration problem

Hello! I am currently having trouble in python modifying the tau_a values for many particles at the same time. I figured out that whenever I alter the tau_a value for 10 or more particles then I get the following warning:

RuntimeWarning: At least 10 predictor corrector loops in IAS15 did not converge. This is typically an indication of the timestep being too large.

. If this happens the integration seems to completely shut down no matter how small the timestep is set. Also, when this warning is thrown the adaptive time stepping does not work. Everything only works if I modify 9 or less, but I need to be able to do this for thousands of particles if possible?

Unphysical energy flips with GR?

I have noticed that with GR turned on, orbits can unphysically flip from positive to negative semimajor axis. A simple example showing this behavior can be found at the following link: https://gist.github.com/alekseygenerozov/927f3df70202d7e76b16d4cbe71a1980

I also see a warning message about lack of convergence in gr.c, so perhaps I should not be surprised with unphysical results, but I was wondering if you had some thoughts about avoiding this issue?

Thank you,

Aleksey

Installing reboundx on fresh Mac Big Sur fails

Dear reboundx creators,
I recently installed rebound on a fresh Mac Big Sur without problems. But, when attempting to install reboundx, the following error appears (in addition to other warnings):
$ pip3 install reboundx
...
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DLIBREBOUNDX -Isrc -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/rebound -c src/output.c -o build/temp.macosx-10.9-x86_64-3.9/src/output.o -fstrict-aliasing -O3 -std=c99 -fPIC -Wpointer-arith -DREBXGITHASH=d17670bfad6727c43ce0b74326a1d3d8d61069cd
src/output.c:217:13: error: implicit declaration of function 'rebx_len' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
int N = rebx_len(list);
^
...
Another installation on a fresh Ubuntu 20 run without problems. Hence, I wonder if it could be because a too strict mac-gcc behavior? Could be fixed in an easy way, without going deep under the hood?. Thanks in advance anyhow for your very interesting packages.

REBOUNDx trouble with satellites

I'm attempting to get REBOUNDx to apply a direct force to a simple 3-body system.
And I'm not understanding something basic.

particle0 is the Sun
particle1 is Earth at 1AU
particle2 is the Moon at 60-Earth radii from particle1

I'm using the IAS15 integrator with a constant time step dt = 1e-3 years,
which is ~1% the lunar orbital period.


I'm using the following to tell REBOUNDx to change the Moon's
elements computed with respect to the Earth.

mod.params["coordinates"] = reboundx.coordinates["PARTICLE"]
ps[2].params["primary"] = 1 (is this right??)

Then I'm setting the tau_a parameter for the Moon
and integrate for 100 years.

ps[2].params["tau_a"] = 1000. #some number to get some decay after a century
print(ps[2].calculate_orbit(primary=ps[1]).a) #elements before integration
sim.integrate(100)
print(ps[2].calculate_orbit(primary=ps[1]).a) #elements after integration

But comparing the two prints shows that nothing happens (i.e., the
force that gives rise to "tau_a" = 1000 is
not applied) unlessโ€‹ I change the above statement to

ps[1].params["tau_a"] = 1000.


It seems that tau_a must be set for Earth to get the
Moon's orbit to change.

This doesn't seem right.

Darren Williams

modify_mass module error

Hi all,

I'm interested to use the Reboundx module "modify_mass".
Just to check if works in my computer I copied the ipython example and run:

import rebound
import reboundx
import numpy as np
sim = rebound.Simulation()
sim.G = 4*np.pi**2 # use units of AU, yrs and solar masses

M0 = 1. # initial mass of star
sim.add(m=M0)
sim.add(a=1.)
sim.add(a=2.)
sim.add(a=3.)
sim.move_to_com()
ps = sim.particles

rebx = reboundx.Extras(sim)
mass_effect = rebx.add("modify_mass")

ps[0].params["tau_mass"] = -1.e4

Nout = 1000
mass = np.zeros(Nout)
times = np.linspace(0., 1.e4, Nout)

for i, time in enumerate(times):
    sim.integrate(time)
    mass[i] = sim.particles[0].m

unfortunately I obtain a strange error, and I am bit lost =(

here is the error:


Traceback (most recent call last):
  File "mas.py", line 18, in <module>
    ps[0].params["tau_mass"] = -1.e4
  File "/home/mileva/reboundx/reboundx/__init__.py", line 35, in params
    params = Params(self)
  File "/home/mileva/reboundx/reboundx/params.py", line 13, in __init__
    raise AttributeError("Need to attach reboundx.Extras instance to simulation before setting particle params.")
AttributeError: Need to attach reboundx.Extras instance to simulation before setting particle params.
*** glibc detected *** python: double free or corruption (out): 0x00007f89ce9cddd0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7da26)[0x7f89d00a0a26]
/usr/local/lib/python2.7/dist-packages/rebound/../librebound.so(reb_integrator_whfasthelio_reset+0x47)[0x7f89cf2c5eb7]
/usr/local/lib/python2.7/dist-packages/rebound/../librebound.so(reb_free_pointers+0xc3)[0x7f89cf2bc633]
/usr/lib/python2.7/lib-dynload/_ctypes.so(ffi_call_unix64+0x4c)[0x7f89cf51eea4]
/usr/lib/python2.7/lib-dynload/_ctypes.so(ffi_call+0x1e5)[0x7f89cf51e8c5]
/usr/lib/python2.7/lib-dynload/_ctypes.so(_ctypes_callproc+0x4d2)[0x7f89cf50f2c2]
/usr/lib/python2.7/lib-dynload/_ctypes.so(+0xbaa2)[0x7f89cf50faa2]
python(PyObject_Call+0x36)[0x4e9f36]
python(PyEval_EvalFrameEx+0x86a)[0x49846a]
python(PyEval_EvalCodeEx+0x1a0)[0x49f1c0]
python[0x4a8960]
python(PyObject_Call+0x36)[0x4e9f36]
python[0x4ec11a]
python(PyObject_Call+0x36)[0x4e9f36]
python(PyEval_CallObjectWithKeywords+0x36)[0x4ea396]
python[0x460bb5]
python[0x460f6e]
python[0x57cbd5]
python(PyDict_SetItem+0x49)[0x4faf79]
python(_PyModule_Clear+0x149)[0x561619]
python(PyImport_Cleanup+0x4bd)[0x507d8d]
python(Py_Finalize+0x12f)[0x4aedff]
python(Py_Main+0x3ce)[0x4aa72e]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f89d00447ed]
python[0x41b9b1]
======= Memory map: ========
00400000-00671000 r-xp 00000000 08:11 5901780                            /usr/bin/python2.7
00870000-00871000 r--p 00270000 08:11 5901780                            /usr/bin/python2.7
00871000-008da000 rw-p 00271000 08:11 5901780                            /usr/bin/python2.7
008da000-008ec000 rw-p 00000000 00:00 0 
020a7000-02cb8000 rw-p 00000000 00:00 0                                  [heap]
7f89cb60d000-7f89cb6ef000 r-xp 00000000 08:11 5906044                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f89cb6ef000-7f89cb8ee000 ---p 000e2000 08:11 5906044                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f89cb8ee000-7f89cb8f6000 r--p 000e1000 08:11 5906044                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f89cb8f6000-7f89cb8f8000 rw-p 000e9000 08:11 5906044                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f89cb8f8000-7f89cb90d000 rw-p 00000000 00:00 0 
7f89cb90d000-7f89cba2e000 r-xp 00000000 08:11 5898405                    /usr/lib/x86_64-linux-gnu/libapt-pkg.so.4.12.0
7f89cba2e000-7f89cbc2e000 ---p 00121000 08:11 5898405                    /usr/lib/x86_64-linux-gnu/libapt-pkg.so.4.12.0
7f89cbc2e000-7f89cbc32000 r--p 00121000 08:11 5898405                    /usr/lib/x86_64-linux-gnu/libapt-pkg.so.4.12.0
7f89cbc32000-7f89cbc33000 rw-p 00125000 08:11 5898405                    /usr/lib/x86_64-linux-gnu/libapt-pkg.so.4.12.0
7f89cbc33000-7f89cbc34000 rw-p 00000000 00:00 0 
7f89cbc34000-7f89cbc7e000 r-xp 00000000 08:11 6030924                    /usr/lib/python2.7/dist-packages/apt_pkg.so
7f89cbc7e000-7f89cbe7e000 ---p 0004a000 08:11 6030924                    /usr/lib/python2.7/dist-packages/apt_pkg.so
7f89cbe7e000-7f89cbe80000 r--p 0004a000 08:11 6030924                    /usr/lib/python2.7/dist-packages/apt_pkg.so
7f89cbe80000-7f89cbe89000 rw-p 0004c000 08:11 6030924                    /usr/lib/python2.7/dist-packages/apt_pkg.so
7f89cbe89000-7f89cbeb0000 r-xp 00000000 08:11 3673679                    /lib/x86_64-linux-gnu/libexpat.so.1.5.2
7f89cbeb0000-7f89cc0b0000 ---p 00027000 08:11 3673679                    /lib/x86_64-linux-gnu/libexpat.so.1.5.2
7f89cc0b0000-7f89cc0b2000 r--p 00027000 08:11 3673679                    /lib/x86_64-linux-gnu/libexpat.so.1.5.2
7f89cc0b2000-7f89cc0b3000 rw-p 00029000 08:11 3673679                    /lib/x86_64-linux-gnu/libexpat.so.1.5.2
7f89cc0b3000-7f89cc0c1000 r-xp 00000000 08:11 6034455                    /usr/lib/python2.7/lib-dynload/pyexpat.so
7f89cc0c1000-7f89cc2c0000 ---p 0000e000 08:11 6034455                    /usr/lib/python2.7/lib-dynload/pyexpat.so
7f89cc2c0000-7f89cc2c1000 r--p 0000d000 08:11 6034455                    /usr/lib/python2.7/lib-dynload/pyexpat.so
7f89cc2c1000-7f89cc2c3000 rw-p 0000e000 08:11 6034455                    /usr/lib/python2.7/lib-dynload/pyexpat.so
7f89cc2c3000-7f89cc348000 r-xp 00000000 08:11 6305700                    /usr/local/lib/python2.7/dist-packages/numpy/random/mtrand.so
7f89cc348000-7f89cc547000 ---p 00085000 08:11 6305700                    /usr/local/lib/python2.7/dist-packages/numpy/random/mtrand.so
7f89cc547000-7f89cc548000 r--p 00084000 08:11 6305700                    /usr/local/lib/python2.7/dist-packages/numpy/random/mtrand.so
7f89cc548000-7f89cc567000 rw-p 00085000 08:11 6305700                    /usr/local/lib/python2.7/dist-packages/numpy/random/mtrand.so
7f89cc567000-7f89cc568000 rw-p 00000000 00:00 0 
7f89cc568000-7f89cc571000 r-xp 00000000 08:11 6305710                    /usr/local/lib/python2.7/dist-packages/numpy/fft/fftpack_lite.so
7f89cc571000-7f89cc770000 ---p 00009000 08:11 6305710                    /usr/local/lib/python2.7/dist-packages/numpy/fft/fftpack_lite.so
7f89cc770000-7f89cc771000 r--p 00008000 08:11 6305710                    /usr/local/lib/python2.7/dist-packages/numpy/fft/fftpack_lite.so
7f89cc771000-7f89cc772000 rw-p 00009000 08:11 6305710                    /usr/local/lib/python2.7/dist-packages/numpy/fft/fftpack_lite.so
7f89cc772000-7f89cc773000 r-xp 00000000 08:11 6034429                    /usr/lib/python2.7/lib-dynload/future_builtins.so
7f89cc773000-7f89cc972000 ---p 00001000 08:11 6034429                    /usr/lib/python2.7/lib-dynload/future_builtins.so
7f89cc972000-7f89cc973000 r--p 00000000 08:11 6034429                    /usr/lib/python2.7/lib-dynload/future_builtins.so
7f89cc973000-7f89cc974000 rw-p 00001000 08:11 6034429                    /usr/lib/python2.7/lib-dynload/future_builtins.so
7f89cc974000-7f89cc993000 r-xp 00000000 08:11 6034447                    /usr/lib/python2.7/lib-dynload/_io.so
7f89cc993000-7f89ccb92000 ---p 0001f000 08:11 6034447                    /usr/lib/python2.7/lib-dynload/_io.so
7f89ccb92000-7f89ccb93000 r--p 0001e000 08:11 6034447                    /usr/lib/python2.7/lib-dynload/_io.so
7f89ccb93000-7f89ccb9c000 rw-p 0001f000 08:11 6034447                    /usr/lib/python2.7/lib-dynload/_io.so
7f89ccb9c000-7f89ccbbf000 r-xp 00000000 08:11 6307744                    /usr/local/lib/python2.7/dist-packages/numpy/linalg/_umath_linalg.so
7f89ccbbf000-7f89ccdbe000 ---p 00023000 08:11 6307744                    /usr/local/lib/python2.7/dist-packages/numpy/linalg/_umath_linalg.so
7f89ccdbe000-7f89ccdbf000 r--p 00022000 08:11 6307744                    /usr/local/lib/python2.7/dist-packages/numpy/linalg/_umath_linalg.so
7f89ccdbf000-7f89ccdc0000 rw-p 00023000 08:11 6307744                    /usr/local/lib/python2.7/dist-packages/numpy/linalg/_umath_linalg.so
7f89ccdc0000-7f89ccdf5000 r-xp 00000000 08:11 5905988                    /usr/lib/x86_64-linux-gnu/libquadmath.so.0.0.0
7f89ccdf5000-7f89ccff4000 ---p 00035000 08:11 5905988                    /usr/lib/x86_64-linux-gnu/libquadmath.so.0.0.0
7f89ccff4000-7f89ccff5000 r--p 00034000 08:11 5905988                    /usr/lib/x86_64-linux-gnu/libquadmath.so.0.0.0
7f89ccff5000-7f89ccff6000 rw-p 00035000 08:11 5905988                    /usr/lib/x86_64-linux-gnu/libquadmath.so.0.0.0
7f89ccff6000-7f89cd10a000 r-xp 00000000 08:11 5909188                    /usr/lib/x86_64-linux-gnu/libgfortran.so.3.0.0
7f89cd10a000-7f89cd30a000 ---p 00114000 08:11 5909188                    /usr/lib/x86_64-linux-gnu/libgfortran.so.3.0.0
7f89cd30a000-7f89cd30b000 r--p 00114000 08:11 5909188                    /usr/lib/x86_64-linux-gnu/libgfortran.so.3.0.0
7f89cd30b000-7f89cd30d000 rw-p 00115000 08:11 5909188                    /usr/lib/x86_64-linux-gnu/libgfortran.so.3.0.0
7f89cd30d000-7f89cd3a6000 r-xp 00000000 08:11 7344892                    /usr/lib/libblas/libblas.so.3gf.0
7f89cd3a6000-7f89cd5a5000 ---p 00099000 08:11 7344892                    /usr/lib/libblas/libblas.so.3gf.0
7f89cd5a5000-7f89cd5a6000 r--p 00098000 08:11 7344892                    /usr/lib/libblas/libblas.so.3gf.0
7f89cd5a6000-7f89cd5a7000 rw-p 00099000 08:11 7344892                    /usr/lib/libblas/libblas.so.3gf.0
7f89cd5a7000-7f89cde8c000 r-xp 00000000 08:11 7344908                    /usr/lib/lapack/liblapack.so.3gf.0
7f89cde8c000-7f89ce08b000 ---p 008e5000 08:11 7344908                    /usr/lib/lapack/liblapack.so.3gf.0
7f89ce08b000-7f89ce08c000 r--p 008e4000 08:11 7344908                    /usr/lib/lapack/liblapack.so.3gf.0
7f89ce08c000-7f89ce090000 rw-p 008e5000 08:11 7344908                    /usr/lib/lapack/liblapack.so.3gf.0
7f89ce090000-7f89ce19d000 rw-p 00000000 00:00 0 
7f89ce19d000-7f89ce1a0000 r-xp 00000000 08:11 6307743                    /usr/local/lib/python2.7/dist-packages/numpy/linalg/lapack_lite.so
7f89ce1a0000-7f89ce39f000 ---p 00003000 08:11 6307743                    /usr/local/lib/python2.7/dist-packages/numpy/linalg/lapack_lite.so
7f89ce39f000-7f89ce3a0000 r--p 00002000 08:11 6307743                    /usr/local/lib/python2.7/dist-packages/numpy/linalg/lapack_lite.so
7f89ce3a0000-7f89ce3a1000 rw-p 00003000 08:11 6307743                    /usr/local/lib/python2.7/dist-packages/numpy/linalg/lapack_lite.so
7f89ce3a1000-7f89ce43f000 r-xp 00000000 08:11 6307712                    /usr/local/lib/python2.7/dist-packages/numpy/core/umath.so
7f89ce43f000-7f89ce63f000 ---p 0009e000 08:11 6307712                    /usr/local/lib/python2.7/dist-packages/numpy/core/umath.so
7f89ce63f000-7f89ce640000 r--p 0009e000 08:11 6307712                    /usr/local/lib/python2.7/dist-packages/numpy/core/umath.so
7f89ce640000-7f89ce646000 rw-p 0009f000 08:11 6307712                    /usr/local/lib/python2.7/dist-packages/numpy/core/umath.so
7f89ce646000-7f89ce648000 rw-p 00000000 00:00 0 
7f89ce648000-7f89ce7a6000 r-xp 00000000 08:11 6307713                    /usr/local/lib/python2.7/dist-packages/numpy/core/multiarray.so
7f89ce7a6000-7f89ce9a6000 ---p 0015e000 08:11 6307713                    /usr/local/lib/python2.7/dist-packages/numpy/core/multiarray.soAbortado (`core' generado)

Any suggestion about what I'm doing wrong?

thanks in advance to all!

all the best,

Mileva

How to compute compute new paramter for each particle

Hi everyone,

I was trying to code a module to compute a external force exerted in each particle in the simulation.
Following the examples is straightforward. However, once the force is computed and the
new acceleration is given:

p->ax += fyork_x
p->ay += fyork_y
p->az += fyork_z

I would like to store, for each particle a new parameter,f_di,which is given by the force computed previously times velocity, so something like:

f_di = fyork_x*dvx+fyork_y*dvy+fyork_z*dvx

any suggestion about how can I do that?

thank you very much!

version

Change so you can print rebound.version like in REBOUND

setup.py usage of site-packages causes error on Debian-derived Linux distributions

Debian (and derived distros like Ubuntu) adopted a policy of installing manually built python packages in dist-packages instead of site-packages. This causes an issue at line 42-43 of setup.py:

reboundx/setup.py

Lines 42 to 43 in 2b49863

# get site-packages dir to add to paths in case reb & rebx installed simul in tmp dir
rebdirsp = [p for p in sys.path if p.endswith('site-packages')][0]+'/'

This throws a fatal IndexError as the list of matches is empty.

Maybe there's a portable way of picking up from the environment what the site-packages equivalent is, as opposed to just patching this the crude way and checking for both site-packages and dist-packages.

Reference to the Debian policy:
https://wiki.debian.org/Python

python 3.6 librebound.cpython-36m-x86_64-linux-gnu.so import error

import reboundx gives me OSError: librebound.cpython-36m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory unless I do it under the python3.6/site-packages directory. Anyone has this error? I almost suspect I missed something obvious...

python 3.6.5
rebound 3.5.12, reboundx 2.18.1 installed via pip

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-58-227e1b4154d8> in <module>()
      7  
      8 
----> 9 import reboundx
     10 rebx = reboundx.Extras(sim)
     11 rf = rebx.add("radiation_forces")

~/anaconda3/lib/python3.6/site-packages/reboundx/__init__.py in <module>()
     11 pymodulespath = os.path.dirname(__file__)
     12 from ctypes import *
---> 13 clibreboundx = cdll.LoadLibrary(pymodulespath + '/../libreboundx' + suffix)
     14 
     15 # Version

~/anaconda3/lib/python3.6/ctypes/__init__.py in LoadLibrary(self, name)
    424 
    425     def LoadLibrary(self, name):
--> 426         return self._dlltype(name)
    427 
    428 cdll = LibraryLoader(CDLL)

~/anaconda3/lib/python3.6/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    346 
    347         if handle is None:
--> 348             self._handle = _dlopen(self._name, mode)
    349         else:
    350             self._handle = handle

OSError: librebound.cpython-36m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory

Custom operator on eccentricity and semimajor axis

Hello,
I am trying to add tidal dissipation as a custom operator, which would update the eccentricity, and semimajor axis as e += dedt * dt and a += dadt * dt.
I use Equations (1) and (2) from Jackson et al. (2008), ApJ, 678, 1396. Here is my code

sim = rebound.Simulation()
sim.units = ('yr', 'AU', 'Msun')
sim.integrator = 'whfast'
sim.add(m=1.0)
sim.add(m=constants.Mjup/constants.Msun, a=a0 / constants.AU, e=e0)
sim.move_to_com()
ps = sim.particles

def dissipation(reb_sim, rebx_operator, dt):
        sim = reb_sim.contents
        dissip = rebx_operator.contents
        ps = sim.particles

        Rp = 1.0
        Qp = 1e4
        Rs = 1.0
        Qs = 1e6

        e1 = (63.0/4.0) * (constants.GG * (ps[0].m*constants.Msun)**3)**0.5 * ((Rp*constants.Rjup)**5 / (Qp * ps[1].m*constants.Mjup))
        e2 = (171.0/16.0) * (constants.GG / (ps[0].m*constants.Msun))**0.5 * ((Rs*constants.Rsun)**5 * ps[1].m*constants.Mjup / Qs)
        de_dt = -(e1 + e2) * (ps[1].a*constants.AU)**(-13.0/2.0) * e

        a1 = (63.0/2.0) * (constants.GG * (ps[0].m*constants.Msun)**3)**0.5 * ((Rp*constants.Rjup)**5 / (Qp * ps[1].m*constants.Mjup))
        a2 = (9.0/2.0) * (constants.GG / (ps[0].m*constants.Msun))**0.5 * ((Rs*constants.Rsun)**5 * ps[1].m*constants.Mjup / Qs)
        da_dt = -(a1*ps[1].e**2 + a2) * (ps[1].a*constants.AU)**(-11.0/2.0)

        #ps[1].e += de_dt * dt
        #ps[1].a += (da_dt * dt) / constants.AU

rebx = reboundx.Extras(sim)
myop = rebx.create_operator("dissipation")
myop.operator_type = "updater"
myop.step_function = dissipation
rebx.add_operator(myop)

But when I integrate using sim.integrate(), I get the following error:

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 315, in 'calling callback function'
  File "test.py", line 143, in dissipation
    ps[1].a += (da_dt * dt) / constants.AU
AttributeError: can't set attribute

Is it impossible to update the eccentricity and semimajor axis ?

Thanks a lot !

Attribution Error: sim.particles[1].e

Hi Dan,

I'm writing a tidal evolution code where I replace the line sim.particles[1].m += Mdot*dt from Custom_Effects.ipynb with an analogous sim.particles[1].e += edot*dt (where edot is a constant or could depend on current eccentricity). The program will not let me update eccentricity: I get the error message "AttributeError: can't set attribute." Any suggestions?

Thank you,
Luis

trouble modifying orbital elements directly

Hello,

I am trying to give a test particle a kick in semi-major axis every orbital period by rewriting the "modify_orbits_direct.c" file. However, although I receive no errors when compiling, the compiling stops and the following appears on the terminal:

'./libreboundx.so: undefined reference to "reb_transformations_inertial_to_jacobi_posvel"
./libreboundx.so: undefined reference to "reb_transformations_jacobi_to_inertial_acc"
./libreboundx.so: undefined reference to "reb_transformations_inertial_to_jacobi_posvelacc"
collect2: error: ld returned 1 exit status
Makefile:6: recipe for target 'all' failed
make: *** [all] Error 1 '

I have attached my version of "modify_orbits_direct.c" and a simulation file called "add_forces_test.c" so that you can see the code I am trying to implement. I think I am not accessing the particles orbital elements in the correct manner?? Thank you for any help you can give!!

modify_orbits_direct

add_forces_test

Adding custom force

Hello!

I am using REBOUNDx to (1) add additional forces on a massless planet in a 2-body system and (2) track the planet's eccentricity as a function of time. As per the latest version of Custom_Effects.ipynb, I use rebx.add_force(myforce) to call my Python-based orbital evolution function. This function is a line-by-line translation of some Mercury subroutine MFO_USER.FOR (which was motivated by the appendix in Wolff et al. 2012). It forces additional acceleration and velocity terms with an arbitrarily assigned (cosine) function of e-dot and updates the terms via lines like ps[1].ax += ax and ps[1].vx += vx. I then compare REBOUND's results to Mercury's and to the corresponding eccentricity model.

My issue is that REBOUND does not agree with the model, whereas Mercury does, despite the implementation of similar code structures. See figure below. My suspicion is that the issue is rooted in the user-defined velocities ps[1].vx += vx, since the results look much better (albeit not perfect) when I turn the velocities off (i.e., do not update them).

I would like to get a better sense of what REBOUND is doing with these velocities. Where in the source code can I find the velocity calculations?

Thank you,
Luis

orbital_evolution

Scatter Particles Without Discontinuous Jumps in Position

Hello,

I am trying to subject particles in my simulation to an artificial scattering force that will change a bodies semi-major axis and eccentricity. However, it seems the method I am using is causing discontinuous jumps in the positions of the particles I am trying to scatter. I am using a modified version of your source file, "modify_orbits_direct.c". Is there any way to scatter the particles without these jumps in position?

Here is my code:

/**
 * @file    modify_orbits_direct.c
 * @brief   Update orbital element every 100 orbital periods as described by interactions w/ Neptune
 * @author  Dan Tamayo <[email protected]>
 * 
 * @section     LICENSE
 * Copyright (c) 2015 Dan Tamayo, Hanno Rein
 *
 * This file is part of reboundx.
 *
 * reboundx is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * reboundx is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with rebound.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <omp.h>
#include "rebound.h"
#include "reboundx.h"

static struct reb_particle rebx_calculate_modify_orbits_direct(struct reb_simulation* const sim, struct rebx_effect* const effect, struct reb_particle* p, struct reb_particle* primary, const double dt){
	int err=0;
	struct reb_orbit o = reb_tools_particle_to_orbit_err(sim->G, *p, *primary, &err);
	double time = sim->t;

	if(err){        // mass of primary was 0 or p = primary.  Return same particle without doing anything.
		return *p;
	}
	
	// define perihelion and change in semi-major axis
	double q0 = o.a*(1-o.e);
	double d_a = 0.02*(1.0/o.a);

	// every 100 orbital periods (for a specific particle), give a particle a kick in semi-major axis	
	if (reb_output_check(sim,100.0*2.0*M_PI*pow(o.a,3.0/2.0))){
		if ( o.a > 0 ){
			// if perihelion small enough, give particle a kick
			if ( q0 <= 0.35){
				// determine randomly whether to scatter particle inward or outward
				double flip = reb_random_uniform(1,10);
				// change semi-major axis
				if (flip > 5){
					o.a += d_a;
				}
				else {
					o.a -= d_a;
				}
				// change eccentricity
				double d_e = (1.0-(q0/o.a)) - o.e;
				o.e += d_e;
			}
		}
	}

	return reb_tools_orbit_to_particle(sim->G, *primary, p->m, o.a, o.e, o.inc, o.Omega, o.omega, o.f);
}

void rebx_modify_orbits_direct(struct reb_simulation* const sim, struct rebx_effect* const effect, const double dt, enum rebx_timing timing){
	const int* const ptr = rebx_get_param_check(effect, "coordinates", REBX_TYPE_INT);
	enum REBX_COORDINATES coordinates = REBX_COORDINATES_JACOBI;
	if (ptr != NULL){
		coordinates = *ptr;
	}
	const int back_reactions_inclusive = 1;
	const char* reference_name = "primary";
	rebxtools_com_ptm(sim, effect, coordinates, back_reactions_inclusive, reference_name, rebx_calculate_modify_orbits_direct, dt);
}

safe_mode

It seems that REBOUNDx overwrites the safe_mode flag in whfast. This leads to a significant slowdown in simulations where I add a GR potential and use symplectic correctors. For example:

import rebound
import reboundx
from rebound.data import add_outer_solar_system

sim = rebound.Simulation()
add_outer_solar_system(sim)
sim.integrator = "whfast"
sim.ri_whfast.corrector = 7
sim.ri_whfast.safe_mode = 0

rebx = reboundx.Extras(sim)
gr = rebx.add("gr_potential")
gr.params['c'] = constants.C

sim.integrate(100)

I should probably remember this, but is this by design or a bug?

python 2.7 OSError: librebound.so

Hello,

I have problems importing reboundx, related to previous closed issues. I installed separately rebound (3.10.2) and then reboundx (3.0.4), using pip. On my local machine, everything works just fine with Python 2.7.

However, when I upload all the packages on a cluster, I get the following error messages (still Python 2.7):

import reboundx
File "../Py_Libraries/reboundx/__init__.py", line 13, in <module>
clibreboundx = cdll.LoadLibrary(pymodulepath+"/libreboundx"+suffix)
File "/usr/lib/python2.7/ctypes/__init__.py", line 444, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 366, in __init__
self._handle = _dlopen(self._name, mode)
OSError: librebound.so: cannot open shared object file: No such file or directory

Any idea ?

Thanks a lot !

How to get the radius of a particle when particle mass decreasing using tau_mass

Hi! I am making a code for my research which requires the sun lose its mass over time. I have used tau_mass to make the sun lose its mass at a certain rate. Now, since the mass have changed, radius and density of the sun should also change. I am wondering if how can I get the radius of the sun (particle) and its density also over period of time. I am confused since I am new to python and reboundx. Thanks for your favorable respose this will help me a lot!

Regards,
Kelvin

Segmentation Error while 3 more particles are included

Hi there. I have recently used your REBOUNDx package for the simulation, however it ended up with a issue which confused me. I tried to add the effect "modify_mass" to all the five particles, and though it could be compiled successfully, I received "segmentation error" message every time I ran the program. I also found out that the code worked well if I just included 3 or less particles, including the central star. Do you have any suggestions on the possible cause? I am using the C-version for both Rebound and Rebounds. Cheers.

modify mass C equation

Hi all,

I'm using the external module modify_mass.c in REBOUNDx. What I want is to implement another kind of mass loss instead of the e-folding. Thus, I went to the src code in order to learn how implement this change. However, I don't understand very well the following part of the code:

if (tau_mass != NULL){
   	    p->m += p->m*dt/(*tau_mass);

I know that is equivalent in python to:


M0=initial mass
M = M0*np.e**(times/tau_mass)

However, I don't understand where is implemented the exponential in the original C code.
What is dt in that equation?

I know that my problem here is that I'm bad C code person....yet =)

Thanks in advance for the help!

Best,

Mileva

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.