Here is how to obtain the "$n$-th approximating function of CantorStaircase
.
ClearAll[f];
f[0] = x \[Function] x;
f[n_Integer?Positive] := f[n] = x \[Function] Evaluate[PiecewiseExpand[
Piecewise[{
{0, x <= 0},
{1/2 f[n - 1][3 x], 0 <= x <= 1/3},
{1/2, 1/3 <= x <= 2/3},
{1/2 + 1/2 f[n - 1][3 x - 2], 2/3 <= x <= 1},
{1, 1 <= x}
}]]];
Dislcaimer: As nonlinear FEM is involved in the following, this will work only with _Mathematica_ version 12 or later.
Next step is to solve the PDE numerically. This is a hyperbolic PDE of firsts order which is notorious for its shocks. So we use some diffusion to obtain a stable numerical scheme (so ϵ
converging to 0
, we will obtain the viscousity sol). The second, very important trick is to general a spacial discretization that has the nondifferentiable points of the initial conditions contained in its vertex list.
Needs["NDSolve`FEM`"]
sign = 1;
ϵ = 0.0001;
T = 1;
n = 5;
nElements = 10 3^n;
Ω = ToElementMesh[
"Coordinates" -> Partition[Subdivide[-1., 2., nElements], 1],
"MeshElements" -> {LineElement[Partition[Range[nElements + 1], 2, 1]]},
"MeshOrder" -> 1
];
sol = NDSolveValue[
{
D[u[t, x], t] - ϵ D[u[t, x], x, x] + D[u[t, x]^2/2, x] == 0,
u[0, x] == sign f[n][x]
},
u, {t, 0, T}, x ∈ Ω
];
Plot3D[sol[t, x], {x, -1/2, 3/2}, {t, 0, T},
AxesLabel -> {"x", "t"},
PlotRange -> sign {-0.1, 1.1},
NormalsFunction -> None,
PlotPoints -> {200, 200},
ViewPoint -> {- sign 1.3, -2.4, 2.}
]

We can nicely see the rarefaction waves. Shock waves can only be observed after setting sign
to a negative value; here is the plot for sign = -1
:

NDSolve
with the first few iterates of the piecewise-linear functions that converge to the Cantor staircase function. In the (for me) best imaginable universe, the solutions might converge in a very weak sense to your desired solution so that you might get an impression of how it looks like. $\endgroup$NDSolve
working for other initial conditions, post your code here so people don't have to reinvent the wheel. $\endgroup$FEMDocumentation/tutorial/NonlinearFiniteElementVerificationTests#\ 1129285755
$\endgroup$