I am trying to import a .obj file to be used in a static electric field simulation. I am able to successfully run the simulation with certain other aperture geometries (see here: < https://www.dropbox.com/s/dds8rm3odg2m7gu/largeAp.obj?dl=0 >), but not this aperture geometry: < https://www.dropbox.com/s/jajk5y3b1xtej8w/squareAp_large.obj?dl=0 >
The errors spit out are: ToElementMesh::femtemcns: Cannot set region holes. and NDSolveValue::femtemcns: Cannot set region holes.
which I assume are due to same problem.
Here is the simulation code. What could be the problem? I tried adjusting mesh resoltuion, etc., but may have done it improperly.
Best,
Clear["Global`*"];
Needs["NDSolve`FEM`"]
R = Import["C:...squareAp_large.obj"];
RegionDimension[R];
M = BoundaryMeshRegion[MeshCoordinates[R], MeshCells[R, 2]];
RegionDimension[M];
Volume[M];
r = RegionDifference[
RegionDifference[
RegionDifference[Cuboid[{0, 0, -0.5}, {2, 2, 0.5}], M],
Cuboid[{0, 0, 0.4}, {2, 2, 0.5}]],
Cuboid[{0, 0, -0.5}, {2, 2, -0.4}]]
ToElementMesh[r]["Wireframe"]
pol = -1;
V0 = 4000;
sol = NDSolveValue[{Laplacian[V[x, y, z], {x, y, z}] == 0,
DirichletCondition[
V[x, y, z] == -pol*
V0/2, (0.4 <= z <= 0.5) && (0 <= y <= 2) && (0 <= x <= 2)],
DirichletCondition[
V[x, y, z] ==
pol*V0/2, (0.0071 <= z <= 0.0072) && (0 <= y <= 2) && (0 <= x <=
2)], DirichletCondition[
V[x, y, z] ==
0, (0 <= z <= 0.0070) && (0 <= y <= 2) && (0 <= x <= 2)],
DirichletCondition[
V[x, y, z] ==
0, (-0.5 <= z <= -0.4) && (0 <= y <= 2) && (0 <= x <= 2)]},
V, {x, y, z} \[Element] r]
plotXZ = ContourPlot[sol[x, 0.75, z], {x, 0, 2}, {z, -0.4, 0.1},
ContourShading -> Automatic, ColorFunction -> "Rainbow",
Contours -> 100]
plotYZ = ContourPlot[sol[0.75, y, z], {y, 0, 2}, {z, -0.4, 0.1},
ContourShading -> Automatic, ColorFunction -> "Rainbow",
Contours -> 100]
plotXY = ContourPlot[sol[x, y, -0.05], {x, 0.5, 1.5}, {y, 0.5, 1.5},
ColorFunction -> "Rainbow", Contours -> 50, PlotLegends -> Automatic]
SliceContourPlot3D[sol[x, y, z],
"CenterPlanes", {x, 0.5, 1}, {y, 0.5, 1}, {z, 0, -0.1},
ColorFunction -> "Rainbow", Contours -> 200];
DensityPlot3D[
sol[x, y, z], {x, 0.5, 1}, {y, 0.5, 1}, {z, -0.4, -0.00001},
PlotTheme -> "Detailed", ColorFunction -> "Rainbow",
PerformanceGoal -> "Quality"];
d = ContourPlot3D[
sol[x, y, z], {x, 0.5, 1}, {y, 0.5, 1}, {z, -0.25, -0.00001},
PlotTheme -> "Detailed", ColorFunction -> "Rainbow",
PerformanceGoal -> "Quality", Contours -> 1, Mesh -> None];
electricField[x_, y_, z_] = -Grad[sol[x, y, z], {x, y, z}];
v = Show[VectorPlot3D[
electricField[x, y, z], {x, 0.5, 1}, {y, 0.5,
1}, {z, -0.25, -0.00001}, PlotTheme -> "Detailed",
ColorFunction -> "Rainbow", PerformanceGoal -> "Quality",
VectorScale -> 0.05, VectorPoints -> 7], M]
```
ToElementMesh[r]
. Perhaps you could get rid of the rest of the code after that, since it is likely that it would work if you fixed the first error. You may also want to add a representation of the problematic region, so people can easily get an idea of what's going on. Finally, you may change the import code toImport["https://www.dropbox.com/s/jajk5y3b1xtej8w/squareAp_large.obj?dl=1"]
to import the mesh directly from your dropbox link (note the change to?dl=1
at the end of the link to access the file directly. $\endgroup$