"Then, is it possible to avoid using pure FiniteElement
in NDSolve
?" Sadly the answer seems to be no, at least now, because adding Method -> {MethodOfLines, TemporalVariable -> t}
causes tvic
warningWell, which seems to indicate NDSolve
is having difficulty in noticing the system can actually be discretized to a DAE system of t
. Stillfor this specific toy problem, if we discretizedifferentiate the system outside offirst 2 equations in NDSolvet
(I'll use pdetoode
for the task)direction and add proper initial condition, it's possible:
γθθ[R_, t_] := 4
tend = 1;
bleft = 1/10; bright = 1;
With[{r = r[R, t], TRR = TRR[R, t], γRR = γRR[R, t], γθθ = γθθ[R, t]},
eqns = {r D[r, R] == γRR γθθ R,
r^4 R γθθ D[TRR, R] == 2 γRR (r^4 - R^4 γθθ^4),
D[γRR, t] == 0};
bc = {r == 0.1 /. R -> bleft, TRR == 0 /. R -> bright};
ic = γRR == 3 /. t -> 0;];
Block[{γRR}, γRR[R_, t_] := 3;
solinitlst =
NDSolveValue[{eqns // Most, bc}, {r[R, t], TRR[R, t]}, {R, 0.1bleft, 1bright}]];
icadd = {r[R, 0], TRR[R, 0]} == solinitlst // Thread;solinitlst;
tendsollst = 1;NDSolveValue[{D[eqns points// =Most, 100;
gridt], =eqns Array[#// &Last, pointsbc, {bleftic, brighticadd}]; difforder = 2;
(* Definition of pdetoode isn't included in this post,
please find it in the link above.{r, *)
ptoofunc = pdetoode[{r, TRR, γRR}[R, t], {t, grid0, difforder];
ode =tend}, {D[{Rest@ptoofunc@eqns[[1]]R, Most@ptoofunc@eqns[[2]]}bleft, t]bright}, ptoofunc@eqns[[3]]};
odebc = bc // ptoofunc;
odeicMethod =-> {ic // ptoofunc, icadd[[1]] // ptoofunc // Rest"MethodOfLines", icadd[[2]] // ptoofunc // Most};
var = Outer[#@#2 &, {r, TRR, γRR}, grid];
sollst"SpatialDiscretization" =-> NDSolveValue[{ode, odebc, odeic}"TensorProductGrid", var,"MaxPoints" {t,-> 050, tend}];
{solr, solTRR, solγRR} = rebuild[#, grid, 2] &"MinPoints" /@-> sollst;
Plot[{solr50, solTRR,"DifferenceOrder" solγRR-> 2}[R}];
Plot[sollst[R, tend] // Through // Evaluate, {R, bleft, bright}]
NDSolve
will manage to find an accurate enough result:
TheNotice this approach is excessivemay fail for this toy examplemore complicated problem, but can be useful forbecause the DAE solver NDSolve
is not that strong. Here is an example of more complicated problem.
#Remark
Without the D[…, t]
in definition of ode
, the program will still find a solution, but it's not that accurate, maybe because NDSolve
can handle differential equation involving derivative of t
better.
solinitlst
is necessary, probably because the DAE solver can't find accurate enough initial conditions automatically in this case.