I'm trying to master the method of lines for solving nonlinear PDEs. Currently, I've faced the PDE, that I'm not able to solve.
Firstly, I have started with this equation:
$$\partial_t U(t,x) =\partial^2_x U(t,x) + 25\cdot \cos^2 (U(t,x))\cdot\partial_x U(t,x)$$
With initial condition:
$$U(0,x) = \sin(x)$$
And boundary conditions:
$$U(t,0) = 0, U(t,\pi) = 0$$
And I can successfully solve it by the following code:
(*initialize grid params*)\[Rho]max = \[Pi]; tmax = 1;
n = 100; dh = \[Rho]max/(n + 1);
(*list of time functions and derivatives*)
U[t_] = Join[{0}, Table[u[i][t], {i, 1, n}], {0}];
Uhh[t_] = ListCorrelate[{1, -2, 1}/dh^2, U[t]];
Uh[t_] = ListCorrelate[{-3, 4, -1}/(2*dh), U[t]];
(*PDE*)
eqU = Thread[
D[U[t], t][[2 ;; -2]] ==
Uhh[t] + 25*(Cos[U[t]][[2 ;; -2]])^2*Uh[t]];
(*IC*)
initU = Thread[U[0][[2 ;; -2]] == Table[Sin[dh*i], {i, 1, n}]];
(*call solver*)
lines = NDSolveValue[{eqU, initU}, {U[t][[2 ;; -2]]}, {t, 0, tmax}];
(*plot the result*)
Utab = Table[i dh, {i, 0, n + 1}][[2 ;; -2]];
ParametricPlot3D[Evaluate@Thread[{Utab, t, lines[[1]]}], {t, 0, 0.05},
PlotRange -> All, AxesLabel -> {"z", "t", "U"},
BoxRatios -> {2, 2, 1}, ImageSize -> Large,
LabelStyle -> {Black, Bold, Medium}]
The same plot can be produced by NDSolve:
nsol = NDSolve[{D[y[x, t], t] ==
D[D[y[x, t], x], x] + 25*(Cos[y[x, t]])^2*D[y[x, t], x], y[x, 0] == Sin[x], y[0, t] == 0, y[\[Pi], t] == 0}, y[x, t], {x, 0, 1}, {t, 0, 0.05}]
Plot3D[nsol[[1, 1, 2]], {x, 0, \[Pi]}, {t, 0, 0.05}]
After that I've decided to make problem more complex, I changed the equation this way:
$$ U(t,x) \partial_t U(t,x) =\partial^2_x U(t,x) + 25\cdot \cos^2 (U(t,x))\cdot\partial_x U(t,x) $$
i.e add $U(t,x)$ to the LHS of the equation.
Thereafter, I couldn't solve this equation by code written above.
Execution is stopped by error:
NDSolveValue::ndsz: At t == 0.000026446140667429057`, step size is effectively zero; singularity or stiff system suspected.
Can somebody give me a piece of advice how to solve this problem? Is it just property of such equation (presence of singularity) that not allow me to use method of lines here? How can I avoid the error, if it is possible at all?
y[x, t]
vanishes. $\endgroup$