9
$\begingroup$

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}]

enter image description here

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}]

enter image description here

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?

$\endgroup$
  • 3
    $\begingroup$ The PDE becomes singular where y[x, t] vanishes. $\endgroup$ – bbgodfrey Dec 10 '19 at 22:58
  • $\begingroup$ @bbgodfrey Thanks for your response! Maybe, you can tell me how can I avoid this singularity? $\endgroup$ – Oiale Dec 11 '19 at 9:53
  • 4
    $\begingroup$ Since you're trying to understand method of lines, it's better to use some well-known problem for testing. Constructing PDE casually can easily lead to unsolvable problem, and your 2nd example is the case. $\endgroup$ – xzczd Dec 15 '19 at 1:57
  • $\begingroup$ @Oiale Thank you for accepting my answer and for bounties. $\endgroup$ – user2320292 Dec 24 '19 at 7:19
3
+50
$\begingroup$

The modified equation, boundary conditions (BCs) and the initial condition (IC) are not consistent. To see this, let's consider the equation at $x=0$ (or at $x=\pi$): $$0 = \left[ \partial_x^2 U(t,x) + a^2 \partial_x U(t,x) \right]_{x = 0}, \quad (1)$$ because $U(t,0) = 0$ and $\cos(U(t,0)) = 1$ (I use $a^2$ instead of 25). Eq.(1) provides a relation between the 1st and 2nd derivatives at $x = 0$. This relation should be satisfied for any $t$, including $t = 0$. Surely, function $\sin(x)$ in the IC does not satisfy Eq.(1).
One can modify the BCs and IC to make the problem consistent. For example, $$ U(t,0) = \delta, \quad U(t,\pi) = \delta, \quad U(0,x) = \sin(x) +\delta,$$ where $\delta > 0$. Also, taking smaller $a$ might help. For example, taking $\delta = 0.01$ and $a = 2$ works fine.
A general advice: It is not a good practice to write a governing equation (and the BCs and ICs) "by hand", using just imagination or intuition. It is much better to derive this equation from "first principles", using laws of physics or other disciplines.
(Minor comment: There is a misprint in your NDSolve command, {x,0,1} should be changed to {x,0,Pi}).

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.