Fixed in 12.1
I was looking at examples of solving problems in electromagnetism and ran across this question, which was a great example of just that. However, looking at the Dirichlet condition, both answers define the boundary of the rectangle explicitly:
DirichletCondition[u[x, y] == 100.,
x == 40 && 40 <= y <= 60 ||
x == 60 && 40 <= y <= 60 ||
40 <= x <= 60 && y == 40 ||
40 <= x <= 60 && y == 60]
I thought to use Mathematica region capabilities to achieve the same result, and did this:
RegionBoundary @ Rectangle[{40, 40}, {60, 60}]
Much simpler and should be equivalent. But when I tried to solve the equation (same setup as in the linked question) it resulted in an error:
sol =
NDSolveValue[
{Laplacian[V[x, y], {x, y}] == 0,
DirichletCondition[
V[x, y] == 100, {x, y} ∈ RegionBoundary @ Rectangle[{40, 40}, {60, 60}]],
V[x, 0] == V[x, 100] == V[0, y] == V[100, y] == 0},
V,
{x, y} ∈
RegionDifference[Rectangle[{0, 0}, {100, 100}],
Rectangle[{40, 40}, {60, 60}]]]
No places were found on the boundary where {x,y}∈Line[{{40,40},{60,40},{60,60},{40,60},{40,40}}] was True, so DirichletCondition[V==100,{x,y}∈Line[{{40,40},{60,40},{60,60},{40,60},{40,40}}]] will effectively be ignored.
This doesn't make any sense, so I dug a little deeper. Calling RegionMember
on my constructed region (FullSimplify
to clean it up) gives
(x | y) ∈ Reals &&
((40 <= y <= 60 && (x == 40 || x == 60)) || (40 <= x <= 60 && (y == 40 || y == 60)))
But, if I remove the first condition
(x | y) ∈ Reals
and just copy-paste the rest in, it works (as expected, since it's the same as the explicit one given in the beginning). Just to be clear, this works:
sol =
NDSolveValue[
{Laplacian[V[x, y], {x, y}] == 0,
DirichletCondition[
V[x, y] == 100,
((40 <= y <= 60 && (x == 40 || x == 60)) || (40 <= x <=60 && (y == 40 || y == 60)))],
V[x, 0] == V[x, 100] == V[0, y] == V[100, y] == 0},
V,
{x, y} ∈
RegionDifference[
Rectangle[{0, 0}, {100, 100}],
Rectangle[{40, 40}, {60, 60}]]]
Thus the culprit seems to be this little bit:
(x | y) ∈ Reals
My question is: why? Both $x$ and $y$ are real numbers, so to me that little bit should only be extraneous, saying what's implied by the other conditions. Clearly this is not the case.