dtamayo / reboundx

A library for adding additional forces to the REBOUND N-body integration package
GNU General Public License v3.0
80 stars 61 forks source link

Segmentation Error while 3 more particles are included #23

Closed 884woods closed 6 years ago

884woods commented 6 years ago

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.

dtamayo commented 6 years ago

I'm happy to look into it. Could you post the code you used and the reboundx version you are using?

On Oct c18, 2017, at 6:52 AM, 884woods notifications@github.com wrote:

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? Cheers.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

dtamayo commented 6 years ago

Even better, could you post the output from

print(reboundx.githash)

if you’re in python, or

printf(“%s\n”, rebx_githash_str);

if you’re in C?

And same for REBOUND (rebound.githash or reb_githash_str).

Thanks

On Oct 18, 2017, at 7:35 AM, Daniel Tamayo tamayo.daniel@gmail.com wrote:

I'm happy to look into it. Could you post the code you used and the reboundx version you are using?

On Oct c18, 2017, at 6:52 AM, 884woods <notifications@github.com mailto:notifications@github.com> wrote:

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? Cheers.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dtamayo/reboundx/issues/23, or mute the thread https://github.com/notifications/unsubscribe-auth/ADQAlx2wnCiVm2UJaATVOEdc3n1ll_2Xks5stdhygaJpZM4P9hWz.

884woods commented 6 years ago

Thank you . Attached is the code. Please have a review. code.txt

884woods commented 6 years ago

The hash is "2f9286947d97ced2b1a5e56156b9aa9890a5922b"

dtamayo commented 6 years ago

I can reproduce what you're getting. I couldn't find an immediate fix, and have an important interview Monday morning, but will work on this right afterwards. I noticed (I have the semi major axes seared in my mind) that you're working on HL Tau. In case you find it useful, here's a (Python) file we used for doing a lot of the things that I think you're doing for this Paper: https://arxiv.org/abs/1703.09132 Script: https://github.com/CSimbulan/HLTau/blob/master/Main/hltau.py.

It might have just been test code, but one thing I noticed is that you have something like an exponentially decaying disk, but those values for tau_e will not continuously update according to e^(-sim.t/t_dispersal), it's just getting set at the beginning (to 1 when t = 0). You would need to add that to the heartbeat function in C, or put it in a loop of calls to integrate like we do in the above Python script.

884woods commented 6 years ago

Many thanks for your reviewing. I will have a look at your reference and continue refining my codes. Please keep me posted if you have any new discoveries, either via this thread or by updating your code on github.

dtamayo commented 6 years ago

The problem is with

 struct reb_particle star;
 star.m = 1.e8; 
 star.r = Rs;
 reb_add(sim,star);

You need to make sure that everything's initialized to 0, and pointers to NULL. The seg fault was coming from accessing bad memory because star.ap was not NULL. With the above you're not even guaranteed that the velocity and position of the star will be 0, though some of the time they will be, which will lead to strange behavior that changes from run to run. The right way to declare and initialize the particle is

struct reb_particle star = {0};

A couple other things:

I would not recommend changing ri_ias15.epsilon. That can give you spurious results and the change in performance is not that great.

If you want eccentricity damping to be relative to the star, you need to set the 'primary' param to particles[0] after setting coordinates to PARTICLE. Unless you have something particular in mind though, I think the right thing to use is Jacobi coordinates, which is the default, so you could simply remove the coordinates stuff and it will do that.

You need to set the tau_e's to a negative number, otherwise you'll get exponential increases in the eccentricities!

Hope that helps