I am solving a set of coupled partial differential equations (some variation of a 1 dimensional compressible fluid flow). I want to solve the equations (NDSolve, this works fine) but then continue solving with different boundary conditions. I am trying to use NDSolve`Reinitialize for this but it gives me an error.
Current code: I first have someFunction
as boundary condition. Then I want to solve the system, and continue with NEWFUNCTION
as boundary condition.
(* rhostart, vstart, estart are defined previously *)
boundaryconditions = (
rho[0, z] == rhostart[z]
&& v[0, z] == vstart[z]
&& e[0, z] == estart[z]
&& ...
&& e[t, 0] == someFunction[t]
&& ...);
statedata = First[NDSolve`ProcessEquations[
{eq1, eq2, eq3, boundaryconditions},
{rho, v, e}, {t, 0, tmax}, {z, 0, zmax}
]]
(* I call Iterate in a loop to check if the result is sufficiently stable (I omitted that code here) *)
NDSolve`Iterate[statedata, curTime]
(* When stable, I process the result *)
solution = NDSolve`ProcessSolutions[statedata]
rhostart[z_] := Evaluate[rho[curTime,z] /. solution];
estart[z_] := Evaluate[e[curTime,z] /. solution];
vstart[z_] := Evaluate[v[curTime,z] /. solution];
(* I compute a few things using the result, omitted here *)
(* Now I want to change a boundary condition by changing e[t,0] *)
newboundaryconditions = (
rho[0, z] == rhostart[z]
&& v[0, z] == vstart[z]
&& e[0, z] == estart[z]
&& ...
&& e[t, 0] == NEWFUNCTION[t]
&& ...);
NDSolve`Reinitialize[statedata, {newboundaryconditions}];
This gives me the following error:
NDSolve`Reinitialize::ndsv: Cannot find starting value for the variable v.
More details: One of my boundary conditions involves setting a variable at x=0 to a certain value. I then let the system evolve in time untill it reaches a steady state. Subsequently I want to compute a few values and then change this boundary condition to a different value and let the system evolve again in time starting from where it left off untill it reaches a sufficiently steady state again.
Important: I could change the original boundary condition function someFunction
to incorporate all changes at long time intervals. However I do not want to keep the full solution of NDSolve in memory all the time (it already reaches 6 GB quickly) so I think it is neccesary to restart the NDSolve process each time.
If anything is unclear or if more information is needed please let me know.
f[0, x] == 0
tof[0, x] == 1
, thenNDSolve
won't be able to reconcile the discontinuity. $\endgroup$someFunction[t]
interpolates from value A to B over time. The solution starts withe[0,0] = A
and at the end of NDSolve, the solution hase[tfinal, 0] = B
. The new boundary conditionNEWFUNCTION
is similar but interpolates from B to C, so it should be consistent. $\endgroup$rhostart
,vstart
andestart
objects since they are InterpolatingFunction objects so maybe I need to define them likerhostart[x_?NumericQ]:=...
or something. I tried with and without usingEvaluate
but no luck so far. $\endgroup$Set
instead ofSetDelayed
(e.g.vstart[z_] = v[curTime,z] /. solution
). Also, maybe try saving a copy ofstatedata
before iterating the solution, and using that in theReinitialize
. $\endgroup$NDSolve Reinitialize
with the original boundary conditions as second argument, it gives the same error. I should have checked this before. The problem is probably not caused by the way I set the Interpolating function objects and so on. Why would it fail when I call Reinitialize with the same boundary conditions as in the original call? $\endgroup$