Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I always wondered if I could start NDSolve from an intermediate time step.

What I mean is, in the code sample below, if I were to run my solution from tmin=0 to tmax=2 and then I realize that my solution hasn't converged yet, could I just change my tmin to 2 and then proceed with a larger tmax (in this case the solution coverges [attains steady state in this example] at tmax=5).

This is because very often I solve 4th order Nonlinear PDEs with NDSolve, some of which take over 70-80 minutes to complete (as I run them for long times of a million time steps or so) and then I realize that the solution hasn't converged yet. So can I just, as in my presumed working example, change my tmin to my tmax from the previous run and change my tmax to a larger run?

tmin = 0;
tmax = 5;
sol = NDSolve[{D[u[t, x], t] == D[u[t, x], x, x], u[0, x] == 0, 
    u[t, 0] == Sin[t], u[t, 5] == 0}, u, {t, tmin, tmax}, {x, 0, 5}];
Plot3D[Evaluate[u[t, x] /. sol], {t, tmin, tmax}, {x, 0, 5}, 
 PlotRange -> All]
share|improve this question
    
By "converged" you mean "reached a steady state"? Regardless, you might use the old solution to give initial and boundary values for starting anew. –  Daniel Lichtblau May 14 '12 at 23:31
    
@DanielLichtblau Yes, steady state. –  drN May 15 '12 at 0:25
add comment

2 Answers 2

up vote 7 down vote accepted

You could integrate up to some intermediate time, tintermediate, and then feed the result as initial conditions to the solver to propagate from tintermediate to tmax, like so:

tmin = 0;
tintermediate = 2;
tmax = 5;
sol = NDSolve[{D[u[t, x], t] == D[u[t, x], x, x], u[0, x] == 0, 
    u[t, 0] == Sin[t], u[t, 5] == 0}, 
   u, {t, tmin, tintermediate}, {x, 0, 5}];
sol2 = NDSolve[{D[u[t, x], t] == D[u[t, x], x, x],
    u[tintermediate, x] \[Equal] First@(u[tintermediate, x] /. sol), 
    u[t, 0] == Sin[t], u[t, 5] == 0}, 
   u, {t, tintermediate, tmax}, {x, 0, 5}];
share|improve this answer
    
Thanks! Just so that I understand this right sol2 is the solution from t=2 to t=5...? –  drN May 15 '12 at 0:31
    
Yes, that is what it is –  acl May 15 '12 at 0:32
    
Ok. Thanks! I actually just learned the use of @! –  drN May 15 '12 at 0:36
    
ah yes. glad to be of help! –  acl May 15 '12 at 0:45
add comment

As it turns out, the designers of NDSolve[] have precisely anticipated this sort of use; this is where you can use the NDSolve`StateData framework.

To use acl's example:

(* prepare PDE *)
state = First[NDSolve`ProcessEquations[{D[u[t, x], t] == D[u[t, x], x, x], 
 u[0, x] == 0, u[t, 0] == Sin[t], u[t, 5] == 0}, u, t, {x, 0, 5}]];


(* go up to t = 2 *)
NDSolve`Iterate[state, {0, 2}]
NDSolve`ProcessSolutions[state, "Forward"]

(* go up to t = 5 *)
NDSolve`Iterate[state, 5];
NDSolve`ProcessSolutions[state, "Forward"]

See the docs for more details.

share|improve this answer
    
good point, +1! –  acl May 15 '12 at 0:46
    
Awesome! I'll look into the documentation. This is quite nifty! (Not taking anything away from the previous answerer :)) –  drN May 15 '12 at 12:16
    
Why am I not able to plot the solution u[t,x] with Plot3D[ Evaluate[u[t, x]], {t, 2, 5}, {x, 0, 5} ] OR Plot3D[ u[t, x]/.sol, {t, 2, 5}, {x, 0, 5} ] where sol= NDSolve`ProcessSolutions[state, "Forward"] –  drN May 22 '12 at 14:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.