Skip to main content
added 25 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

Notice this approach maywill probably fail forin more complicated problemcases, because the DAE solver NDSolve is not that strong. In those cases, advanced technique is needed, Herehere is an example of more complicated problem.

Notice this approach may fail for more complicated problem, because the DAE solver NDSolve is not that strong. Here is an example of more complicated problem.

Notice this approach will probably fail in more complicated cases, because the DAE solver NDSolve is not that strong. In those cases, advanced technique is needed, here is an example.

add a simpler solution instead.
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

"Then, is it possible to avoid using pure FiniteElementin 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:

enter image description here

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

  1. 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.

  2. solinitlst is necessary, probably because the DAE solver can't find accurate enough initial conditions automatically in this case.

"Then, is it possible to avoid using pure FiniteElementin NDSolve?" Sadly the answer seems to be no, at least now, because adding Method -> {MethodOfLines, TemporalVariable -> t} causes tvic warning, which seems to indicate NDSolve is having difficulty in noticing the system can actually be discretized to a DAE system of t. Still, if we discretize the system outside of NDSolve (I'll use pdetoode for the task):

γθθ[R_, t_] := 4
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.1, 1}]];

icadd = {r[R, 0], TRR[R, 0]} == solinitlst // Thread;
    
tend = 1; points = 100;
grid = Array[# &, points, {bleft, bright}]; difforder = 2;
(* Definition of pdetoode isn't included in this post,
   please find it in the link above. *)
ptoofunc = pdetoode[{r, TRR, γRR}[R, t], t, grid, difforder];

ode = {D[{Rest@ptoofunc@eqns[[1]], Most@ptoofunc@eqns[[2]]}, t], ptoofunc@eqns[[3]]};
odebc = bc // ptoofunc;
odeic = {ic // ptoofunc, icadd[[1]] // ptoofunc // Rest, icadd[[2]] // ptoofunc // Most};

var = Outer[#@#2 &, {r, TRR, γRR}, grid];
sollst = NDSolveValue[{ode, odebc, odeic}, var, {t, 0, tend}];

{solr, solTRR, solγRR} = rebuild[#, grid, 2] & /@ sollst;

Plot[{solr, solTRR, solγRR}[R, tend] // Through // Evaluate, {R, bleft, bright}]

NDSolve will manage to find an accurate enough result:

enter image description here

The approach is excessive for this toy example, but can be useful for more complicated problem.

#Remark

  1. 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.

  2. solinitlst is necessary, probably because the DAE solver can't find accurate enough initial conditions automatically in this case.

"Then, is it possible to avoid using pure FiniteElementin NDSolve?" Well, for this specific toy problem, if we differentiate the first 2 equations in t 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, bleft, bright}]];

icadd = {r[R, 0], TRR[R, 0]} == solinitlst;

sollst = NDSolveValue[{D[eqns // Most, t], eqns // Last, bc, ic, icadd}, {r, 
    TRR, γRR}, {t, 0, tend}, {R, bleft, bright}, 
   Method -> {"MethodOfLines", 
     "SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> 50, 
       "MinPoints" -> 50, "DifferenceOrder" -> 2}}];

Plot[sollst[R, tend] // Through // Evaluate, {R, bleft, bright}]

enter image description here

Notice this approach may fail for more complicated problem, because the DAE solver NDSolve is not that strong. Here is an example of more complicated problem.

added 2 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

"Then, is it possible to avoid using pure FiniteElementin NDSolve?" Sadly the answer seems to be no, at least now, because adding Method -> {MethodOfLines, TemporalVariable -> t} causes tvic warning, which seems to indicate NDSolve is having difficulty to noticein noticing the system can actually be discretized to a DAE system of t. Still, if we discretize the system outside of NDSolve (I'll use pdetoode for the task):

"Then, is it possible to avoid using pure FiniteElement?" Sadly the answer seems to be no, at least now, because adding Method -> {MethodOfLines, TemporalVariable -> t} causes tvic warning, which seems to indicate NDSolve is having difficulty to notice the system can actually be discretized to a DAE system of t. Still, if we discretize the system outside of NDSolve (I'll use pdetoode for the task):

"Then, is it possible to avoid using pure FiniteElementin NDSolve?" Sadly the answer seems to be no, at least now, because adding Method -> {MethodOfLines, TemporalVariable -> t} causes tvic warning, which seems to indicate NDSolve is having difficulty in noticing the system can actually be discretized to a DAE system of t. Still, if we discretize the system outside of NDSolve (I'll use pdetoode for the task):

added 2323 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading
added 18 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading