Replacing HeavisideTheta
with Piecewise
makes it work. it could be a limitation of NDSolve. I do not know.
ClearAll["Global`*"];
k=5;
α=3*π/4
η=0;
pde=Laplacian[u[r,θ],{r,θ},"Polar"]==k^2*u[r,θ];
bc=u[1,θ]==1-(1-η)*Piecewise[{{0,θ<α},{1,True}}]
sol=NDSolveValue[{pde,bc},u,{r,0,1},{θ,0,Pi}]
ContourPlot[sol[Sqrt[x^2 + y^2], ArcTan[x, y]], {x, -1, 1}, {y, 0, 1},
Contours -> 20, ColorFunction -> "Pastel", AspectRatio -> Automatic,
PlotLegends -> Automatic]
Note that HeavisideTheta
can be written using Piecewise
Plot[1 - (1 - η)* HeavisideTheta[θ - α], {θ, -4, 4}]
Plot[1 - (1 - η)* Piecewise[{{0, θ < α}, {1, True}}], {θ, -4, 4}]
How to remove the black dots that appears on the boundary of the
semicircle?
Just add more PlotPoints
:
ContourPlot[sol[Sqrt[x^2 + y^2], ArcTan[x, y]], {x, -1, 1}, {y, 0, 1},
Contours -> 20, ColorFunction -> "Pastel", AspectRatio -> Automatic,
PlotLegends -> Automatic, PerformanceGoal -> "Quality",
PlotPoints -> 75]
This below shows the problem more clearly
ClearAll["Global`*"];
k = 5;
α = 3*π/4;
η = 0;
pde = Laplacian[u[r, θ], {r, θ}, "Polar"] == 0;
bc = u[1, θ] == 1 - (1 - η)*HeavisideTheta[θ - α];
sol = DSolveValue[{pde, bc}, u[r, θ], {r, θ}]
Now we do the same thing, but using NDSolve
instead of DSovle
and get an error
ClearAll["Global`*"];
k = 5;
α = 3*π/4;
η = 0;
pde = Laplacian[u[r, θ], {r, θ}, "Polar"] == 0;
bc = u[1, θ] == 1 - (1 - η)*HeavisideTheta[θ - α];
sol = NDSolveValue[{pde, bc}, u[r, θ], {r, 0, 1}, {θ, 0, Pi}]
Changing to Piecewise
fixes the above.
Maybe this is a bug or could be a feature.