1

For $(t,z)\in[0,1]\times[-1,0]$

zmin = -1; tmax = 1;

and some fields $w(t,z)$ and $y(t,z)$

n = 100; h = -zmin/(n-1);
W[t_] = Table[w[i][t], {i, n}]; 
Y[t_] = Table[y[i][t], {i, n}];

let there be the following PDE's system $$\partial_tw=\partial_zy+w\partial_zw$$ $$\partial_ty=\partial_zw+w\partial_zy$$

For the implementation of the Method of Lines derivatives $\partial_zw$ and $\partial_zy$ are numerically approximated as

Wz[t_] = Join[{(w[2][t] - w[1][t])/h}, 
Table[(w[i + 1][t] - w[i - 1][t])/(2h), {i, 2, n - 1}], {(
w[n][t] - w[n - 1][t])/h}];

and

Yz[t_] = Join[{(y[2][t] - y[1][t])/h}, 
Table[(y[i + 1][t] - y[i - 1][t])/(2h), {i, 2, n - 1}], {(
y[n][t] - y[n - 1][t])/h}];

Notice that the above derivative formulas change for $i=1$ (i.e. $z=-1$) and $i=100$ (i.e. $z=0$). This is a way to handle the fact that numerical integration for $z$ is confined in $[-1,0]$ and does not imply any boundary condition.

Then the above PDE's system can be written as

wall[t_] = Yz[t] + W[t]*Wz[t];
eqw = Thread[
D[W[t], t] == wall[t] - PadLeft[{ wall[t][[n]]}, n]];
eqy = Thread[D[Y[t], t] == Wz[t] + W[t]*Yz[t]]; 

The only boundary condition that is implied by the above equations is that $$w(t,0)=0$$ and this is the reason for the cumbersome statement of the dynamical equation for $w$ ( further explanation: press ctrl+F and type "here is the answer for point 3").

The boundary condition is accompanied by the following initial conditions

w0[z_] = -0.01*Sin[z*Pi]^2;
y0[z_] = 1;
initw = Thread[W[0] == Table[w0[zmin + (i-1)*h], {i, n}]];
inity = Thread[Y[0] == Table[y0[zmin + (i-1)*h], {i, n}]];

and then NDSolve is called to implement the method of lines

lines = NDSolveValue[{eqw, eqy, initw, inity}, {W[t], Y[t]}, {t, 0, 
tmax}];

So there arise the following questions:

  1. Except $w(t,0)=0$ is there any other boundary condition implicit in the finite difference equations? If it does then which? If it doesn't then why does the code run? The problem seems underdetermined.

  2. Can one call the Method of Lines as internal routine so as to increase the accuracy of the above code?

I am working on these but would appreciate any help.

dkstack
  • 103
  • 6
  • h = -zmin/n should be h = -zmin/(n-1). 2. /h, {i, 2, n - 1}] should be /(2h), {i, 2, n - 1}]. 3. What's the meaning of PadLeft[{ wall[t][[n]]}, n]? If you think this will impose $w(t,0)=0$, you're wrong.
  • – xzczd Dec 23 '18 at 12:37
  • I believe that boundary conditions are needed for both w and y. I am unaware of any way to call Method of Lines as internal routine, but you could use NDSolve directly to solve the coupled PDEs. – bbgodfrey Dec 23 '18 at 13:36
  • @xzczd here is the answer for point 3. PadLeft[{ wall[t][[n]]}, n] creates a list with n elements all of which is zero except the nth one that equals wall[t][[n]] . As a result the subtraction results in a list of n elements the first n-1 equal to Yz[t] + W[t]*Wz[t] and the last one equal to zero. This means that $\partial_tw(t,0)=0$ and results in $w(t,0)=w(0,0)=\sin(0)^2=0$. – dkstack Dec 23 '18 at 13:36
  • @xzczd I edited my question according to point 2. – dkstack Dec 23 '18 at 13:47
  • @bbgodfrey boundary condition about y concerns its value or could be stated in terms of its z-derivative? Also can you see why the code runs I mean if there is an implicit boundary condition in my code? – dkstack Dec 23 '18 at 13:50
  • @xzczd concerning point 1. the choice h=-zmin/n results in a $z$-grid of $n$ points the $i=1$ point being $z=zmin+h$ and the $i=n$ point being $z=0$. So spatial integration is done for $z\in[-1+h,0]$ and not $[-1,0]$. I think this is not essential to the question but I will fix the code as soon as possible. – dkstack Dec 23 '18 at 14:02
  • Oh… as to point3, you're right, I forgot about the i.c., but I think it's better to explain this a bit in the question. @bbgodfrey Have you read this post?: https://scicomp.stackexchange.com/q/28033/5331 – xzczd Dec 23 '18 at 14:20
  • @xzczd what do you think of point 1.? I mean is there any difference between h = -zmin/n and h = -zmin/(n-1) other than adding $h$ to the left end of $[-1,0]$? – dkstack Dec 23 '18 at 14:25
  • There won't be any obvious difference when the grid is dense enough, of course. But it's just better to avoid this inaccuracy. – xzczd Dec 23 '18 at 14:48
  • @xzczd I think it is ok now, what do you think? – dkstack Dec 23 '18 at 15:48
  • @xzczd Thanks for the link, which I had not seen. – bbgodfrey Dec 23 '18 at 16:07