# Dirichlet condition from user-defined polygon

I would like to specify a Dirichlet condition from a polyhedron defined by a set of points.

    DirichletCondition[u[x, y, z] == 5, RegionRegionProperty[RegionBoundary[object], {x, y, z}, "FastDescription"][[1]][[2]]]


However, this part

    RegionRegionProperty[RegionBoundary[object], {x, y, z},
"FastDescription"][[1]][[2]]]


doesn't work given the oddly shaped polygon given by RegionBoundary[object]. I haven't been able to find out much about RegionProperty or find out where I can find alternatives to "FastDescription".

Here is how I define object:

center = {39, 19, 0};
objcoords = {{0.35744634112855245,
19.49760834744405}, {10.42305798361631,
19.4864491327628}, {12.243503729806417,
18.29241316186902}, {16.364505056976796,
18.11755617591872}, {18.196197885680288,
22.372731682760513}, {15.189009198663676,
24.589812823211748}, {0.2100041188046311, 24.861851631504276}, {0,
24.86}, {-61.5, 24.86}, {-61.5, 15.86}, {-5, 15.86}};
objcoords[[;; , 1]] = objcoords[[;; , 1]] - center[[1]];
objcoords[[;; , 2]] = objcoords[[;; , 2]] - center[[2]];
(*create 3D polygon from the coordinates*)
objTop =
Table[{objcoords[[i, 1]], objcoords[[i, 2]], 1}, {i, 1,
Length[objcoords]}];
objBottom =
Table[{objcoords[[i, 1]], objcoords[[i, 2]], -1}, {i, 1,
Length[objcoords]}];
object = ConvexHullRegion[Join[objTop, objBottom]]


Please could someone help me get a Dirichlet condition from a user-defined polyhedron/polygon?

• It is not clear what do you try to solve. Is object to be a region for your numerical solution? Mar 6, 2022 at 7:28
• Thanks for your question. object is an electrode in a wider space in which I need to find the potential due to the electrode being near by. That is why I need to set a boundary condition on object. Mar 6, 2022 at 8:45
• What is the region (wider space?) to solve this problem? Could you upload equation and boundary condition in mathematical notation? Mar 6, 2022 at 9:13
• bc = { DirichletCondition[u[x, y, z] == Vobj, RegionRegionProperty[RegionBoundary[object], {x, y, z}, "FastDescription"][[1]][[2]]] }; Mar 6, 2022 at 10:29
• eq = Laplacian[u[x, y, z], {x, y, z}] == 0; U = NDSolveValue[{eq, bc}, u, {x, y, z} [Element] mesh]; Mar 6, 2022 at 10:29

This is solution with zero boundary condition on the air boundary

center = {39, 19, 0};
objcoords = {{0.35744634112855245,
19.49760834744405}, {10.42305798361631,
19.4864491327628}, {12.243503729806417,
18.29241316186902}, {16.364505056976796,
18.11755617591872}, {18.196197885680288,
22.372731682760513}, {15.189009198663676,
24.589812823211748}, {0.2100041188046311, 24.861851631504276}, {0,
24.86}, {-61.5, 24.86}, {-61.5, 15.86}, {-5, 15.86}};
objcoords[[;; , 1]] = objcoords[[;; , 1]] - center[[1]];
objcoords[[;; , 2]] = objcoords[[;; , 2]] - center[[2]];
(*create 3D polygon from the coordinates*)
objTop = Table[{objcoords[[i, 1]], objcoords[[i, 2]], 1}, {i, 1,
Length[objcoords]}];
objBottom =
Table[{objcoords[[i, 1]], objcoords[[i, 2]], -1}, {i, 1,
Length[objcoords]}];
object = ConvexHullRegion[Join[objTop, objBottom]]

Needs["NDSolveFEM"]

xair = yair = zair = 70; air =
Cuboid[{-xair, -yair, -zair}, {xair, yair, zair}]; reg =
RegionDifference[air, object]; mesh =
ToElementMesh[reg,
MeshRefinementFunction ->
Function[{vertices, area},
area > 0.1 (0.1 + 10 Norm[Mean[vertices]])]];
xmax = Max[objcoords[[All, 1]]]; ymm = MinMax[objcoords[[All, 2]]]

bc = {DirichletCondition[
u[x, y, z] == 5, -xair <= x <= xmax && -1 <= z <= 1 &&
ymm[[1]] <= y <= ymm[[2]]],
DirichletCondition[u[x, y, z] == 0, True]}; eq =
Laplacian[u[x, y, z], {x, y, z}] == 0; U =
NDSolveValue[{eq, bc}, u, Element[{x, y, z}, mesh]]


Visualization

{ContourPlot[U[x, y, 0], {x, -xair, xair}, {y, -yair, yair},
ColorFunction -> Hue, PlotRange -> All, PlotPoints -> 50,
PlotLegends -> Automatic, Contours -> 20, FrameLabel -> Automatic],
ContourPlot[U[x, 0, z], {x, -xair, xair}, {z, -zair, zair},
ColorFunction -> Hue, PlotRange -> All, PlotPoints -> 50,
PlotLegends -> Automatic, Contours -> 20, FrameLabel -> Automatic]}


• This is it! Thank you so very much!! Mar 6, 2022 at 15:23
• So it looks like the exact locations of the edges of the object don't matter so much in the Dirichlet condition then? For example, x < xmax suffices Mar 6, 2022 at 15:25
• Yes, with DirichletCondition[ u[x, y, z] == 5, -xair <= x <= xmax && -1 <= z <= 1 && ymm[[1]] <= y <= ymm[[2]]] Mathematica FEM automatically computed all cells on the surface of object included in the mesh`. Mar 6, 2022 at 16:14
• I see, thank you. Mar 6, 2022 at 16:19
• @ECrane You are welcome! Mar 6, 2022 at 16:46