I am trying to numerically solve the following PDE
pde =
With[{d = .25, \[Rho] = .5, M = 10, T = 2,
L = 10, \[Alpha] = 0.2},
{
D[n[x, t], {t, 1}] ==
Piecewise[
Table[{(1 - x^2/(3 d (M T - i T)))*
n[x, t]* g / Sqrt[3 d (M T - i T)] ,
i T < t < i T + \[Alpha] T && -\[Sqrt](3 d*(M T - i T)) <
x < \[Sqrt](3 d*(M T - i T)) }, {i, 0, M - 1}]
]
+
Piecewise[
Table[{d * D[n[x, t], {x, 2}] - \[Rho] * n[x, t],
i T + \[Alpha] T < t < (i + 1) T}, {i, 0, M - 1}]
],
n[x, 0] == InitialCondition,
(D[n[x, t], x] /. x -> -L) == (D[n[x, t], x] /. x -> L) == 0
}
];
However, when I try to get the solution through
sln = With[{M = 10, L=10},
ParametricNDSolveValue[
pde /. InitialCondition -> 0.5 (*uniform*),
n, {x, -L, L}, {t, 0, M T}, {g},
AccuracyGoal -> 20, PrecisionGoal -> 10]
];
and then write, for example, sln[.5][0,5]
, MMA v13.2 gives an error NDSolve::ibcinc
stating the initial and boundary conditions are inconsistent, but it also produces a result. Could someone help me figure out what's happening?
I want to keep g
as a parameter to then be able to manipulate the plots by varying it, say
Manipulate[Plot[{sln[g][0, t]}, {t, 0, 10}, PlotRange -> All],{g, 0.1, 10}]
However, in that case MMA throws out the error and then stops the evaluation.
PS: The reason I have added PrecisionGoal
is that without it, at longer times the solution seems to have a lot of numerical error. For example, after removing PrecisionGoal
and AccuracyGoal
, MMA solves the pde with no error, but when I look at
Plot[{sln[.1][x, 14]}, {x, -10, 10}, PlotRange -> All]
, the plot does not make sense to me.
PrecisionGoal
there is no error, but the final results/plots don't make sense. However I got things to work withAccuracyGoal -> 15, PrecisionGoal -> 10
. This seems like an accident, since with a different initial conditionn[x,0] = Sin[ Pi x /(2L)]^2
the error persists even with these accuracy and precision goals. $\endgroup$