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:
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.
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.
h = -zmin/n
should beh = -zmin/(n-1)
. 2./h, {i, 2, n - 1}]
should be/(2h), {i, 2, n - 1}]
. 3. What's the meaning ofPadLeft[{ wall[t][[n]]}, n]
? If you think this will impose $w(t,0)=0$, you're wrong. $\endgroup$w
andy
. 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. $\endgroup$PadLeft[{ wall[t][[n]]}, n]
creates a list with n elements all of which is zero except the nth one that equalswall[t][[n]]
. As a result the subtraction results in a list of n elements the first n-1 equal toYz[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$. $\endgroup$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? $\endgroup$