Coder Social home page Coder Social logo

modify mass C equation about reboundx HOT 5 CLOSED

dtamayo avatar dtamayo commented on August 28, 2024
modify mass C equation

from reboundx.

Comments (5)

dtamayo avatar dtamayo commented on August 28, 2024

from reboundx.

MilevaE avatar MilevaE commented on August 28, 2024

Hi Dan,

thanks you very much for the explanation!, now it's clear =)

Cheers,

Mileva

from reboundx.

MilevaE avatar MilevaE commented on August 28, 2024

Hi again,

sorry for re-open when was already closed =(

As I mentioned, I'm learning about how to implement my own effects. Just for learn, I try to implement a linear mass loss/growth, based in the e-folding code already available. I followed all the steps, which I think that are ok. Everything compile correctly. However, when I call from my python code, the integration never starts =(

This is the C code for the effect (copy from modify_mass.c and change a couple of things):

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

void rebx_modify_mass_linear(struct reb_simulation* const sim, struct rebx_effect* const effect, const double dt, enum rebx_timing timing){
    const int _N_real = sim->N - sim->N_var;
	for(int i=0; i<_N_real; i++){
		struct reb_particle* const p = &sim->particles[i];
        const double* const M_dot = rebx_get_param_check(p, "M_dot", REBX_TYPE_DOUBLE);
        const double* const initial_mass = rebx_get_param_check(p, "initial_mass", REBX_TYPE_DOUBLE);
        if (M_dot != NULL){
		    p->m += *initial_mass + (*M_dot*dt);
        }
	}
    reb_move_to_com(sim);
} 




I have defined M_dot in units of M_sun/year, i.e., the rate of mass loss. And Mo the initial mass of
the star in M_sun. So, what I think is doing is:

m = Mo + M_dot*dt

Thus, in principle, just a linear (and simple) equation.

From python, I call doing:

Mo = 3.04
rebx = reboundx.Extras(sim)
mass_effect_linear = rebx.add("modify_mass_linear")

ps[0].params["M_dot"] = -1.e-5
ps[0].params["initial_mass"] = Mo

Nout = 1e5
mass = np.zeros(Nout)
years=1e5
times = np.linspace(0., years, Nout)
time_step = np.zeros((0,Nout))
semimayor = np.zeros((2,Nout))
ecc = np.zeros((2,Nout))
sim.integrator = "ias15"
#sim.integrator = "whfast"


for i, timex in enumerate(times):
    sim.integrate(timex)
    mass[i] = sim.particles[0].m
    semimayor[0][i] = sim.particles[1].a
    semimayor[1][i] = sim.particles[2].a
    ecc[0][i] = sim.particles[1].e
    ecc[1][i] = sim.particles[2].e
    time_step = np.append(time_step,sim.dt)
    print i

So, any advice what I'm doing wrong and why the integration never starts.. :/

Thanks a lot for the help!

Cheers,

Mileva

from reboundx.

dtamayo avatar dtamayo commented on August 28, 2024

Hi Mileva,

what do you mean it doesn't start? What error do you get in the notebook and/or in the terminal from which you launched the notebook?

Also, I know it's just a test, but I think your equation updating the masses will always update to the same value assuming a constant timestep. I think you want p->m += M_dotdt;

from reboundx.

MilevaE avatar MilevaE commented on August 28, 2024

Hi Dan,

yes, with your advice works perfect. Thanks!

When I said "the integration never starts" I mean, that, as you can see in the code:

for i, timex in enumerate(times):
    sim.integrate(timex)
    mass[i] = sim.particles[0].m
    semimayor[0][i] = sim.particles[1].a
    semimayor[1][i] = sim.particles[2].a
    ecc[0][i] = sim.particles[1].e
    ecc[1][i] = sim.particles[2].e
    time_step = np.append(time_step,sim.dt)
    print i

I inserted a "print i" at the end, in order to follow what is going on. However, in this case, never start to count, doesn't print anything. With your correction yes, it prints =)

Thanks!

Best,

Mileva

from reboundx.

Related Issues (20)

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.