# Plotting a differential equation with boundary conditions

I have a problem with numerical calculation and plotting of differential equation. Now I set a complicated region to set a boundary condition:

square1 = Rectangle[{-7.3, .5}, {7.3, 1.5}];
square2 = Rectangle[{-7.5, .7}, {7.5, 1.3}];
circle1 = Disk[{-7.3, .7}, .2];
circle2 = Disk[{-7.3, 1.3}, .2];
circle3 = Disk[{7.3, .7}, .2];
circle4 = Disk[{7.3, 1.3}, .2];
plate1 = RegionUnion[square1, square2, circle1, circle2, circle3,
circle4];

square3 = Rectangle[{-7.3, -1.5}, {7.3, -.5}];
square4 = Rectangle[{-7.5, -1.3}, {7.5, -.7}];
circle5 = Disk[{-7.3, -1.3}, .2];
circle6 = Disk[{-7.3, -.7}, .2];
circle7 = Disk[{7.3, -1.3}, .2];
circle8 = Disk[{7.3, -.7}, .2];
plate2 = RegionUnion[square3, square4, circle5, circle6, circle7,
circle8];

area = Rectangle[{-15, -2}, {15, 2}];
region = RegionDifference[area, RegionUnion[plate1, plate2]];
regionplot =
RegionPlot[region, PlotTheme -> "Monochrome",
PlotRange -> {{-15, 15}, {-2, 2}}, AspectRatio -> Automatic]


and selected area is shown in white area by regionplot

Then, I apply this region as a boundary condition, and try NDsolve

bc = {DirichletCondition[u[x, y] == 1, {x, y} \[Element] plate1],
DirichletCondition[u[x, y] == -1, {x, y} \[Element] plate2]};
sol = NDSolveValue[{\!$$\*SubsuperscriptBox[\(\[Del]$$, $${x, y}$$, $$2$$]$$u[x, y]$$\) == 0,
bc}, u, {x, -15, 15}, {y, -2, 2}]
DensityPlot[sol[x, y], {x, -15, 15}, {y, -2, 2},
PlotLegends -> Automatic]


When I run this code, below error messages are shown:

    NDSolveValue::bcnop: No places were found on the boundary where {x,y}\[Element]BooleanRegion[#1||#2||#3||#4||#5||#6&,{Rectangle[{-7.3,0.5},{7.3,1.5}],Rectangle[{-7.5,0.7},{7.5,1.3}],Disk[{-7.3,0.7},0.2],Disk[{-7.3,1.3},0.2],Disk[{7.3,0.7},0.2],Disk[{7.3,1.3},0.2]}] was True, so DirichletCondition[u==1,{x,y}\[Element]BooleanRegion[#1||#2||#3||#4||#5||#6&,{Rectangle[{-7.3,0.5},{7.3,1.5}],Rectangle[{-7.5,0.7},{7.5,1.3}],Disk[{-7.3,0.7},0.2],Disk[{-7.3,1.3},0.2],Disk[{7.3,0.7},0.2],Disk[{7.3,1.3},0.2]}]] will effectively be ignored.
NDSolveValue::bcnop: No places were found on the boundary where {x,y}\[Element]BooleanRegion[#1||#2||#3||#4||#5||#6&,{Rectangle[{-7.3,-1.5},{7.3,-0.5}],Rectangle[{-7.5,-1.3},{7.5,-0.7}],Disk[{-7.3,-1.3},0.2],Disk[{-7.3,-0.7},0.2],Disk[{7.3,-1.3},0.2],Disk[{7.3,-0.7},0.2]}] was True, so DirichletCondition[u==-1,{x,y}\[Element]BooleanRegion[#1||#2||#3||#4||#5||#6&,{Rectangle[{-7.3,-1.5},{7.3,-0.5}],Rectangle[{-7.5,-1.3},{7.5,-0.7}],Disk[{-7.3,-1.3},0.2],Disk[{-7.3,-0.7},0.2],Disk[{7.3,-1.3},0.2],Disk[{7.3,-0.7},0.2]}]] will effectively be ignored.


I don't know the reason why this boundary conditions are not working. Is there any idea how my code will work?

There are two issues with your approach. First, you'd need to specify the region to NDSolve and second the way you specify the predicate for the boundary conditions is not idea since there will be numerical error in finding what is part of the boundary and what not.

Here is a way to do it. We generate and visualize a mesh:

Needs["NDSolveFEM"]
mesh = ToElementMesh[region, RegionBounds[region],
"MaxCellMeasure" -> 0.1];
mesh["Wireframe"]


For the boundary condition we can simply use a small bounding box around the boundaries. You can make use of RegionBounds to find those. Then we have:

bc = {
DirichletCondition[
u[x, y] == 1, (-7.6 <= x <= 7.6) && (0.4 <= y <= 1.6)],
DirichletCondition[
u[x, y] == -1, (-7.6 <= x <= 7.6) && (-1.6 <= y <= -0.4)]
};


Note that I made the boxes just a little larger to guarantee that they overlap with the region. We can then solve and visualize:

 sol = NDSolveValue[{Laplacian[u[x, y], {x, y}] == 0, bc}, u,
Element[{x, y}, mesh]];
DensityPlot[sol[x, y], Element[{x, y}, mesh], PlotRange -> Automatic,
AspectRatio -> Automatic]


You may find the ref pages of ToElementMesh, ToBoundaryMesh and the ElementMesh Generation tutorial useful. In the tutorial you may find the section on markers useful.