When using mass taper keep the planet on the desired orbit
In the present version of the code the planet is set initially at aphelium (X=a(1+e),Y=0) with velocity:
\dot Y = \sqrt{(G(M_*+M_p)/a)} \sqrt{(1-e^2)}/(1+e);
\dot X =0
The initial velocity depends on the planet mass and when we apply a masstaper we set the initial velocity corresponding to the initial mass value so we do not keep the planet on the desired orbit
Discussion and solution from keybase:
@gpichier Here's the formula if you are interested. In a heliocentric frame with the (x,y) plane being the orbital plane and the x axis in the direction of the pericentre, the position and velocities of a planet are given in terms of the orbital elements as
X=a(cosE -e)
Y=a\sqrt{1-e^2}sinE;
\dot{X}=-(n a)/(1-e cosE) sinE;
\dot{Y}=(n a \sqrt{1-e^2})/(1-e cosE) cosE
where E is the eccentric anomaly (there are also formuas using the true anomaly if it's easier that way - if the coordinate system is not aligned with the planet's orbit, one just needs a couple of rotations). Then when one increases the mass of the planet one could just say: take the same orbital elements from the previous step, increase E by a Keplerian step over dt (however it won't be a uniform increase in E because it's not the mean anomaly), and use these formulas to calculate the new positions and velocities that correspond to the needed (constant) orbital elements. For example putting e=0 in the formulas, the position and velocities would always maintain a circular orbit. However this would also fix the semi-major axis, and maybe one would like the planet to be migrating at the same time it is changing it's mass. In this case one could use the torque felt by the planet. calculate the da/dt provided by the disc, and apply it over the integration step dt.
@crida In your formula, the planet mass is only present inside
n = \sqrt{G(M_*+M_p)/a^3}
right ? Then, all one needs to do is to adapt
\dot{X} \,, \dot{Y}
by multiplying them by
[1+\dot{M_p}/(M_*+M_p)]
(because
\dot{n} = n*\dot{M_p}/(M_*+M_p)
if I'm not mistaken).