3
$\begingroup$

I have had a problem properly meshing certain .obj files, where others are meshed successfully.

Here is an example of a successfully meshed .obj:

Success

Whereas, using the code at the bottom which includes the imported problematic .obj, this error (shown at bottom of the image) is produced:

Success

Both methods of producing the mesh for these two examples are the same and only differ in their geometry. Is there anything that can be done?

Best to all.

Clear["Global`*"];
Needs["NDSolve`FEM`"]

R = Import[
   "https://www.dropbox.com/s/499qd6zwu4who1e/round9.obj?dl=1"];
RegionDimension[R];
Imp = BoundaryMeshRegion[MeshCoordinates[R], MeshCells[R, 2]];
RegionDimension[Imp];
Volume[Imp];

M = RegionDifference[Cuboid[{0, 0, 0}, {2, 2, 0.0072}], Imp]

r = RegionDifference[
  RegionDifference[RegionDifference[Cuboid[{0, 0, -1}, {2, 2, 1}], M],
    Cuboid[{0, 0, 0.9}, {2, 2, 1}]], Cuboid[{0, 0, -1}, {2, 2, -0.9}]]
ToElementMesh[r]["Wireframe"]
```
$\endgroup$
2
  • $\begingroup$ The message is about a region hole, but you do not show code that produces that message. $\endgroup$
    – user21
    Jul 7, 2022 at 16:07
  • $\begingroup$ @user21 Weird. I copied and pasted the exact code I presented above and tried to run it and it produced the exact error I showed in image 2? It doesn't show that error for you? $\endgroup$
    – Zach
    Jul 7, 2022 at 16:42

1 Answer 1

5
$\begingroup$

This gives some clues as to why it does not work:

FindMeshDefects[r]

Here is a different approach for this geometry:

Needs["NDSolve`FEM`"]
Needs["OpenCascadeLink`"]

R = Import[
   "https://www.dropbox.com/s/499qd6zwu4who1e/round9.obj?dl=1"];
s1 = OpenCascadeShape[ToBoundaryMesh[R]];
s2 = OpenCascadeShapeDifference[
   OpenCascadeShape[Cuboid[{0, 0, 0}, {2, 2, 0.0072}]], s1];
s3 = OpenCascadeShapeDifference[
   OpenCascadeShape[Cuboid[{0, 0, -1}, {2, 2, 1}]], s2];
s4 = OpenCascadeShapeDifference[s3, 
   OpenCascadeShape[Cuboid[{0, 0, 0.9}, {2, 2, 1}]]];
s5 = OpenCascadeShapeDifference[s4, 
   OpenCascadeShape[Cuboid[{0, 0, -1}, {2, 2, -0.9}]]];
bmesh = OpenCascadeShapeSurfaceMeshToBoundaryMesh[s5];
ToElementMesh[bmesh]["Wireframe"]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thank you!!! I didn't think to specify a requirement when initially making this post. I am trying perform NDSolveValue over this mesh, and it appears that the output form of bmesh is not a BoundaryMeshRegion, but a member of ElementMesh. Is there a way to convert the bmesh to a BoundaryMeshRegion? $\endgroup$
    – Zach
    Jul 7, 2022 at 17:05
  • $\begingroup$ I am trying to solve: 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] bmesh] $\endgroup$
    – Zach
    Jul 7, 2022 at 17:06
  • 1
    $\begingroup$ If you want to do FEM forget about MeshRegion and BoundaryMeshRegion as the FEM internally uses ElementMesh anyways. You need to convert the boundary element mesh (bmesh) to a full mesh (with ToElementMesh) and give that to NDSolve. Search for ToElementMesh in the documentation, there are plenty reference, tutorial and examples. $\endgroup$
    – user21
    Jul 8, 2022 at 8:19
  • $\begingroup$ Thank you. I just failed to remove the ["Wireframe"] when I tried using ToElementMesh of bmesh. $\endgroup$
    – Zach
    Jul 8, 2022 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.