3
$\begingroup$

I am trying to generate a 3D mesh for Finite Element simulations. I need to provide some precomputed inputs to the mesh points and will like my mesh to be the same for a given shape. However, everytime I run my code I am getting different numbers of nodes. Here is the example:

W = ImplicitRegion[x^2 + y^2 + z^2 <= 1, {x, y, z}];
mesh = ToElementMesh[W, "MaxBoundaryCellMeasure" -> 0.02, "MaxCellMeasure" -> 0.1, "MeshQualityGoal" -> 1];
pts = mesh["Coordinates"];
Dimensions[pts]

The dimension of pts keeps on changing every time I run the code. I will like to obtain the same number every time. However, if I do the same problem as:

mesh = ToElementMesh[Ball[], "MaxBoundaryCellMeasure" -> 0.02, "MaxCellMeasure" -> 0.1, "MeshQualityGoal" -> 1];
pts = mesh["Coordinates"];
Dimensions[pts]

then the dimension does not change. While this is a viable solution for sphere/ellipsoids, I will need it to work for ImplicitRegion since I will be looking into more general surfaces. Thanks in advance!

$\endgroup$
4
  • 1
    $\begingroup$ I think this is a duplicate of the other question you have found. This W = ImplicitRegion[x^2 + y^2 + z^2 <= 1, {x, y, z}]; m1 = BoundaryDiscretizeRegion[W]; m2 = BoundaryDiscretizeRegion[W]; MeshCoordinates[m1] == MeshCoordinates[m2] False produces the same issue and I believe that this is because of the underling TetGen (that does the (boundary) mesh generation) is not fully deterministic. I have asked coworkers for their opinion and if they do not come up with something else then there is not much that can be done. I'll keep you posted if I find anything new. $\endgroup$
    – user21
    Jul 6 at 16:04
  • $\begingroup$ One other thought is to put this in the possible issues section $\endgroup$
    – user21
    Jul 6 at 16:37
  • $\begingroup$ No, I agree. I found that discussion as well. You are right. $\endgroup$
    – bchakra
    Jul 6 at 21:23
  • $\begingroup$ I have added an example of this to the reference page of ToElementMesh in the possible issues section. This will be available in the next version (13.2?) $\endgroup$
    – user21
    Jul 7 at 4:31

1 Answer 1

3
$\begingroup$

Include intermediate step DiscretizeRegion[W]

ToElementMesh[DiscretizeRegion[W] , "MaxBoundaryCellMeasure" -> 1/50,"MaxCellMeasure" -> 1/10, "MeshQualityGoal" -> 1]
(*ElementMesh[{{-0.99773, 0.99773}, {-0.99773, 0.99773},{-0.99773, 0.99773}}, {TetrahedronElement["<" 14405 ">"]}]*)
$\endgroup$
7
  • $\begingroup$ Unfortunately this does not solve the problem. If you use: Dimensions[%["Coordinates"]] after your code then you will see that the dimension is changing every time you run it. $\endgroup$
    – bchakra
    Jul 6 at 13:23
  • $\begingroup$ I meant running the code after clearing global variables. $\endgroup$
    – bchakra
    Jul 6 at 13:30
  • $\begingroup$ What means " running the code after clearing global variables"? $\endgroup$ Jul 6 at 13:31
  • 1
    $\begingroup$ Perhaps ToBoundaryMesh[W, "MaxBoundaryCellMeasure" -> 0.02, "MaxCellMeasure" -> 0.1, "MeshQualityGoal" -> 1] is what you're looking for? $\endgroup$ Jul 6 at 13:41
  • 1
    $\begingroup$ I meant running the code after restarting Mathematica or after clearing variables. But I guess there is a inherent randomness in the underlying meshing tool that cannot be controlled. After much digging I found a similar question: mathematica.stackexchange.com/questions/162461/…. Do you think that there is a way to get around this apart from saving the mesh? $\endgroup$
    – bchakra
    Jul 6 at 13:42

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