Maybe tutorial/NDSolveStateData
can help. It lets you allow NDSolve
to keep track of all the information the OP is asking about.
The first step is to call NDSolve`ProcessEquation
instead of NDSolve
; the same arguments may be given, but note that an interval of integration is optional. Since the OP did not include a value for Tdrive
, I left it out. I also gave dummy values to the other parameters. An NDSolve`StateData
data structure is returned.
DriveMotion = {r'[t] == Sin[γ[t]] v[t],
v'[t] == -Sin[γ[t]] μ/r[t]^2 + Aion, γ'[t] == Cos[γ[t]]/r[t] (v[t] - μ/(v[t] r[t])),
ϕ'[t] == Cos[γ[t]]/r[t] v[t]};
Init1 = {r[0] == Rinit,
v[0] == Vcirc, γ[0] == 0, ϕ[0] == 0};
Block[{Rinit = 1, Vcirc = 1, Aion = 1, μ = 1},
{state} =
NDSolve`ProcessEquations[{DriveMotion, Init1},
{r, v, γ, ϕ}, {t}, MaxSteps -> 5000000,
Method -> "Automatic"]
]
(* {NDSolve`StateData["<" 0. ">"]} *)
To integrate up to t == 2
, we call NDSolve`Iterate
on the state
with the stopping time.
NDSolve`Iterate[state, 2]
It alters the state
. We can get the values of the state variables by calling NDSolve`ProcessSolutions
with the argument "Forward"
(use "Backward"
if the value t == 2
is before the time of the initial condition in Init1
).
NDSolve`ProcessSolutions[state, "Forward"]
(*
{r[2.] -> 3.19208, Derivative[1][r][2.] -> 2.43266,
v[2.] -> 2.6337, Derivative[1][v][2.] -> 0.90935,
γ[2.] -> 1.17754, Derivative[1][γ][2.] -> 0.301888,
ϕ[2.] -> 1.85649, Derivative[1][ϕ][2.] -> 0.316168}
*)
Now we can continue to integrate, say up to t == 4
:
NDSolve`Iterate[state, 4]
To get the complete solution, we can use NDSolve`ProcessSolutions
with no extra argument:
sol = NDSolve`ProcessSolutions[state]

The variables used are stored in state
and you can get at the pieces without having to type each one out:
vars = state@"Variables"
(* {t, {}, {r, v, γ, ϕ},
{Derivative[1][r], Derivative[1][v], Derivative[1][γ], Derivative[1][ϕ]},
{}, {}, {}, {}} *)
One can extract the dependent variables:
funcs = NDSolve`SolutionDataComponent[vars, "DependentVariables"]
(* {r, v, γ, ϕ} *)
Apply the solution function to the time t == 2.
and compare with the values where we stopped the integration above.
Through[funcs[2.]] /. sol
(* {3.19208, 2.6337, 1.17754, 1.85649} *)
More arguments and options are described in the tutorial linked at the beginning.
Addendum -- Reinitialization
Another glance at the OP's question makes me think that the OP might be interested in reinitializing the ODE at t == 0
with the values of the state variables obtained at t == 2
. In the OP's example, which is autonomous, it makes no difference whether we start over at t == 0
and continue for another 2
or continue to t == 4
as above. If the coefficients depended on t
, then it would make a difference. In either case, one can start over with the last state as the initial state as follows.
Suppose therefore we have just completed the step NDSolve`Iterate[state, 2]
above and that funcs
is a list of the dependent variables as above. One can use NDSolve`Reinitialize
with new initial conditions to get a newstate
data structure.
{newstate} = NDSolve`Reinitialize[state,
Through[funcs[0]] == Through[funcs[2.]] /. NDSolve`ProcessSolutions[state, "Forward"]];
Now we compare advancing the newstate
from t == 0
to 2
and the old state
from t == 2
to 4
.
NDSolve`Iterate[newstate, 2.]
NDSolve`Iterate[state, 4.]
Compare values:
NDSolve`ProcessSolutions[state, "Forward"]
NDSolve`ProcessSolutions[newstate, "Forward"]
(*
{r[4.`] -> 10.195149962394567`, Derivative[1][r][4.`] -> 4.532956349402`,
v[4.`] -> 4.567362769921008`, Derivative[1][v][4.`] -> 0.9904516398189146`,
γ[4.`] -> 1.4479746578634392`, Derivative[1][γ][4.`] -> 0.054627031974180444`,
ϕ[4.`] -> 2.1329726485832348`, Derivative[1][ϕ][4.`] -> 0.05488509738922278`}
{r[2.`] -> 10.195149985177293`, Derivative[1][r][2.`] -> 4.5329563552874`,
v[2.`] -> 4.567362772976815`, Derivative[1][v][2.`] -> 0.9904516398569216`,
γ[2.`] -> 1.4479746616356868`, Derivative[1][γ][2.`] -> 0.054627029636341445`,
ϕ[2.`] -> 2.1329726759733605`, Derivative[1][ϕ][2.`] -> 0.05488509503939425`}
*)
A note on funcs
I usually make my own list of funcs
at the very beginning: At some point you type the list {r, v, γ, ϕ}
of functions to be solved for. Why not store it in a variable for later use?
MapIndexed[#1 == Trajectory1EOD[#2[[1]]] &, State /. t -> 0]
$\endgroup$NDSolve`StateData
? $\endgroup$