TransWikia.com

Strange behaviour in ToElementMesh

Mathematica Asked on October 22, 2021

Why would that not work:

L = 20;
h = 1;
Needs["NDSolve`FEM`"]
gr = Graphics3D[Cuboid[{-h/2, 0, -h/2}, {h/2, L, h/2}]]
mesh = ToElementMesh[DiscretizeGraphics[gr], "MeshOrder" -> 1]
(* TetGenTetrahedrize: returned error, 2 *)

when with a simple translation of $(h/2, 0, h/2)$ I get no error?

gr = Graphics3D[Cuboid[{0, 0, 0}, {h, L, h}]]
mesh = ToElementMesh[DiscretizeGraphics[gr], "MeshOrder" -> 1]
(* works *)

Edit Filled bug report [CASE:4609730]

One Answer

It seems something with the automatic MaxCellMeasure computation is not quite right. Here is a workaround with a manually specified MaxCellMeasure

mr = DiscretizeGraphics[gr];
(*ToElementMesh[mr]*)
ToElementMesh[mr, MaxCellMeasure -> .1]

Update:

This is a bug in TetGen, the mesh generator used.

(bmesh = ToBoundaryMesh[mr]);
pts = bmesh["Coordinates"];
facets = Partition[
   Join @@ ElementIncidents[bmesh["BoundaryElements"]], 1];
Graphics3D[GraphicsComplex[pts, Map[Polygon, facets]]]

enter image description here

In the below code, if you change the 0.06 to 0.05, TetGen will fail.

Needs["TetGenLink`"]
inInst = TetGenCreate[];
TetGenSetPoints[inInst, pts];
TetGenSetFacets[inInst, facets];

(* changing "pqa0.006" to "pqa0.005" *)
outInst = TetGenTetrahedralize[inInst, "pqa0.006"];
coords = TetGenGetPoints[outInst];
surface = TetGenGetFaces[outInst];
Graphics3D[GraphicsComplex[coords, Polygon[surface]]]

enter image description here

Since TetGen is software that Wolfram Research purchased for inclusion there is little hope that this bug in TetGen will be fixed by myself or other people at Wolfram Research. Since the workaround is easy:

ToElementMesh[Cuboid[{-h/2, 0, -h/2}, {h/2, L, h/2}], 
 "MeshElementType" -> TetrahedronElement]

I do not think this is a critical bug. If you deeply care about this, you could try to make use of the TetGenLink that ships with Wolfram products and compile a newer version of TetGen and link and see if the bug has been fixed. Wolfram Products use TetGen version 1.4.3 and the current version is 1.5.1.

Answered by user21 on October 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP