To illustrate the problem, I will give an example that differs from the one proposed by Riku. But in this case, numerical instability is better seen. The result is similar to erosion. Perhaps geologists will like this.
b = {1, HeavisideTheta[x - y]}; L = 4; reg =
DiscretizeRegion[Rectangle[{-L, -L}, {L, L}], MaxCellMeasure -> .01];
eq = D[u[t, x, y], t] + Div[b*u[t, x, y], {x, y}] == 0;
ic = u[0, x, y] == Exp[-x^2 - y^2];
bc = {u[t, L, y] == 0, u[t, -L, y] == 0, u[t, x, L] == 0,
u[t, x, -L] == 0};
sol = NDSolveValue[{eq, ic, bc}, u, {x, y} \[Element] reg, {t, 0, 1}];
Table[Plot3D[sol[t, x, y], {x, y} \[Element] reg, Mesh -> None,
PlotRange -> All, PlotLabel -> Row[{"t = ", t}],
AxesLabel -> {"x", "y", ""}], {t, 0, 1, .1}]
This code has a message
NDSolveValue::femcscd: The PDE is convection dominated and the result may not be stable. Adding artificial diffusion may help
This is confirmed by the data shown in Figure 1. Use the Sobolev vector field, as suggested by Riku. The following code has no messages, but the solution of the problem shown in Fig. 2 demonstrates similar erosion, as in Fig. 1.
b = {0, HeavisideTheta[x - y]}; L = 4; reg =
DiscretizeRegion[Rectangle[{-L, -L}, {L, L}], MaxCellMeasure -> .01];
eq = D[u[t, x, y], t] + Div[b*u[t, x, y], {x, y}] == 0;
ic = u[0, x, y] == Exp[-x^2 - y^2];
bc = {u[t, L, y] == 0, u[t, -L, y] == 0, u[t, x, L] == 0,
u[t, x, -L] == 0};
sol = NDSolveValue[{eq, ic, bc}, u, {x, y} \[Element] reg, {t, 0, 1}];
Table[Plot3D[sol[t, x, y], {x, y} \[Element] reg, Mesh -> None,
PlotRange -> All, PlotLabel -> Row[{"t = ", t}],
AxesLabel -> {"x", "y", ""}], {t, 0, 1, .1}]
Finally, we use the initial data, as suggested by Riku. The following code has no messages, and the solution shown in Figure 3 has no features.
b = {0, HeavisideTheta[x - y]}; L = 4; reg =
DiscretizeRegion[Rectangle[{-L, -L}, {L, L}], MaxCellMeasure -> .01];
eq = D[u[t, x, y], t] + Div[b*u[t, x, y], {x, y}] == 0;
ic = u[0, x, y] == 1;
bc = {u[t, L, y] == 1, u[t, -L, y] == 1, u[t, x, L] == 1,
u[t, x, -L] == 1};
sol = NDSolveValue[{eq, ic, bc}, u, {x, y} \[Element] reg, {t, 0, 1}];
Table[Plot3D[sol[t, x, y], {x, y} \[Element] reg, Mesh -> None,
PlotRange -> All, PlotLabel -> Row[{"t = ", t}],
AxesLabel -> {"x", "y", ""}], {t, 0, 1, .1}]
I add a numerical example for the solution that Vsevolod A. proposed. Equation has the form
$$u_t+\nabla .(u\vec {b})=0$$ with $b=(1,\sigma (x-y) )$ and $\sigma (s)=$2*HeavisideTheta[s]-1
.
b = {1, 2*(-1/2 + HeavisideTheta[x - y])}; L = 4; reg =
DiscretizeRegion[Rectangle[{-L, -L}, {L, L}], MaxCellMeasure -> .01];
eq = D[u[t, x, y], t] + Div[b*u[t, x, y], {x, y}] == 0;
ic = u[0, x, y] == Exp[-x^2 - y^2];
bc = {u[t, L, y] == 0, u[t, -L, y] == 0, u[t, x, L] == 0,
u[t, x, -L] == 0};
sol = NDSolveValue[{eq, ic, bc}, u, {x, y} \[Element] reg, {t, 0, 1}];
Here we see numerical instability. Now we have to study how this instability arises from the solution in the form of the ODE system. First, we consider how the solution changes as k
changes in approximate expression $\sigma =\frac {k(x-y)}{\sqrt {1+k^2(x-y)^2}}$
plot[p_] :=
Block[{q = p}, b = {1, q*(x - y)/Sqrt[1 + (q*(x - y))^2]}; L = 4;
reg = DiscretizeRegion[Rectangle[{-L, -L}, {L, L}],
MaxCellMeasure -> .01];
eq = D[u[t, x, y], t] + Div[b*u[t, x, y], {x, y}] == 0;
ic = u[0, x, y] == Exp[-x^2 - y^2];
bc = {u[t, L, y] == 0, u[t, -L, y] == 0, u[t, x, L] == 0,
u[t, x, -L] == 0};
sol = NDSolveValue[{eq, ic, bc},
u, {x, y} \[Element] reg, {t, 0, 1}, Method -> {
"PDEDiscretization" -> {"MethodOfLines",
"SpatialDiscretization" -> {"FiniteElement",
"MeshOptions" -> {"MaxCellMeasure" -> 0.01}}}}];
Plot3D[sol[1, x, y], {x, y} \[Element] reg, Mesh -> None,
PlotRange -> All, PlotLabel -> Row[{"k = ", p}],
AxesLabel -> {"x", "y", ""}]] // Quiet
Table[plot[k], {k, 1, 11, 2}]
Here are the results for t = 1
and different k