I have code to solve the 2D wave equation on a given region with an initial condition that is sinusoidal in one part of the region and 0 elsewhere. Here is an example on a rectangular region that works just fine, with plot shown at t=0:
weq = Laplacian[u[x, y, t], {x, y}] == D[u[x, y, t], {t, 2}];
bc = {u[x, 2 Pi, t] == 0, u[x, 0, t] == 0, u[0, y, t] == 0,
u[Pi, y, t] == 0};
ic = {u[x, y, 0] ==
If[0 <= x <= Pi && 0 <= y <= Pi, Sin[m x] Sin[n y], 0],
Derivative[0, 0, 1][u][x, y, 0] == 0};
nsol2 = Quiet[NDSolve[{weq, bc, ic} /. {m -> 2, n -> 2},
u, {x, 0, Pi}, {y, 0, 2 Pi}, {t, 0, 5}]];
ListAnimate[
Table[Plot3D[u[x, y, t] /. nsol2, {x, 0, \[Pi]}, {y, 0, 2 \[Pi]},
AxesLabel -> Automatic,
PlotRange -> {{0, \[Pi]}, {0, 2 \[Pi]}, {-1, 1}},
BoxRatios -> {1, 2, 0.5}], {t, 0, 5, 0.5}]]
I want to keep the same initial condition ic
that is sinusoidal in the [{0,0},{Pi,Pi}] rectangle and zero elsewhere, but with a curved guide as a Dirichlet boundary instead of the rectangular boundary used above.
bc2 = DirichletCondition[u[x, y, t] == 0, True]
tube = Region[
RegionUnion[Rectangle[{0, 0}, {Pi, Pi}],
Rectangle[{2 Pi, -2 Pi}, {3 Pi, -Pi}],
Region[Annulus[{Pi, -Pi}, {Pi, 2 Pi}, {0, Pi/2}]]]]
benttubesol =
Quiet[NDSolve[{weq, bc2, ic} /. {m -> 2, n -> 2},
u, {x, y} \[Element] tube, {t, 0, 15}]]
ListAnimate[
Table[Plot3D[u[x, y, t] /. benttubesol, {x, y} \[Element] tube,
AxesLabel -> Automatic,
PlotRange -> {{0, 3 \[Pi]}, {-2 Pi, \[Pi]}, {-1, 1}},
BoxRatios -> {1, 1, 0.5}], {t, 0, 15, 1}]]
The [{0,0},{Pi,Pi}] rectangle is mysteriously absent from the 3DPlot, although the part of the tube that does appear evolves correctly in time (the above is after some time has passed). Why could this be? I think it's related to the if function in ic
, but I don't know what I could change to fix it.
ListAnimate[ Table[Plot3D[ u[x, y, t] /. benttubesol, {x, -1, 3 \[Pi]}, {y, -2 \[Pi], \[Pi]}, AxesLabel -> Automatic, PlotRange -> {{-1, 3 \[Pi]}, {-2 Pi, \[Pi]}, {-1, 1}}, BoxRatios -> {1, 1, 1}], {t, 0, 15, 1}]]
$\endgroup$