0
$\begingroup$

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]
```
$\endgroup$
4
  • 1
    $\begingroup$ The error you report happens early in your code, when you run 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 to Import["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$
    – MarcoB
    Jun 24 at 21:06
  • $\begingroup$ The region (R) you are subtracting from the cuboids is larger than the cuboids. $\endgroup$
    – user21
    Jun 27 at 8:11
  • $\begingroup$ @MarcoB The code works fine with the first dropbox file provided in the post. I only included the rest of the code after the error so that someone could see (using the first dropbox file) the purpose of the program. The problem arises with the second dropbox file, which I suspect is due to the geometry of the apertures. I am looking for a solution to properly mesh the provided problematic file, since, yes, the first hit comes when I try to ToElementMesh[r]. Thanks! $\endgroup$
    – Zach
    Jun 27 at 16:38
  • $\begingroup$ @user21 Unfortunately it is not so simple. This problem arises regardless of the cuboid size, as I have tested it with cuboids which are slightly larger and even much larger with the same result. $\endgroup$
    – Zach
    Jun 27 at 16:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.