7
$\begingroup$

DiscretizeRegion doesn't seem to run the supplied MeshRefinementFunction when meshing a 2D surface in 3D.

For example:

reg = MeshRegion[{{0, 1, 0}, {1, 0, 0}, {1, 1, 0}, {1, 0, 1}},
       Polygon[{{1, 2, 3}, {2, 3, 4}}]];
DiscretizeRegion[reg, MeshRefinementFunction ->
       Function[{vertices, area}, area > 0.025 (1 - 10 Norm[Mean[vertices]])]]

Not only is their no difference between the output of DiscretizeRegion and reg, but it doesn't seem that is ever evaluated; when I put a Print in the MeshRefinementFunction I don't see any output.

This also fails with simpler regions eg reg = Triangle[{{1, 0, 0}, {0, 1, 0}, {1, 1, 0}}].

I wonder if this has to do with MeshRefinementFunction trying to use volume as the cell measure, and, as these regions have no volume, it fails in an unexpected way.

$\endgroup$
3
$\begingroup$

This is an extended comment rather than an answer.

DiscretizeRegion understands how to mesh 2D objects embedded in 3D to some degree as can be shown by the following:

reg = MeshRegion[{{0, 1, 0}, {1, 0, 0}, {1, 1, 0}, {1, 0, 1}}, 
   Polygon[{{1, 2, 3}, {2, 3, 4}}]];
HighlightMesh[DiscretizeRegion[reg, MaxCellMeasure -> {"Area" -> #}], 
   1] & /@ {0.025, 0.0025}

Max cell measure

We can now show that your current mesh refinement function probably needs revision since it will cause an infinite loop because the right-hand side will evaluate negative for some values of the vertices. The area will always be positive, and therefore the function will evaluate to true going into a refinement iteration.

(*Extract vertices of region*)
verts = MeshCoordinates[reg]
(*Extract vertices of 1st triangle*)
verts3d1 = Most@verts
(*Evaluate mesh refinement function*)
0.025 (1 - 10 Norm[Mean[verts3d1]])

Negative mesh refinement function

Here's an example of a more well-behaved mesh refinement function in 2D.

verts2d1 = Most[verts /. {{x_, y_, z_} :> {x, y}}]
center2d1 = Mean[verts2d1]
DiscretizeRegion[Polygon[verts2d1], 
 MeshRefinementFunction -> 
  Function[{vertices, area}, 
   area > 0.000025 (1 + 100 Norm[Mean[vertices] - center2d1])]]

2D mesh refinement

We consider the 1st triangle only, we can show that the improved mesh refinement function still fails. First, we will show that are simplified region succeeds again with MaxCellMeasure:

reg3d1 = MeshRegion[verts3d1, Polygon[{{1, 2, 3}}]];
HighlightMesh[
   DiscretizeRegion[reg3d1, MaxCellMeasure -> {"Area" -> #}], 
   1] & /@ {0.025, 0.0025}

1 triangle with Max cell measure

Second, we will show that it fails with the improved MeshRefinementFunction.

center3d1 = Mean[verts3d1]; 
DiscretizeRegion[reg3d1, 
 MeshRefinementFunction -> 
  Function[{vertices, area}, 
   area > 0.000025 (1 + 100 Norm[Mean[vertices] - center3d1])]]

Failing with mesh refinement function

This result is similar to that obtained with the simple example in the OP.

Interestingly, there is a somewhat related recent question Change mesh density of Graphics3D object made of Triangles. To me, this indicates that DiscretizeRegion may not be entirely robust when it comes to embedding 2D objects in 3D. Hopefully, someone can find a suitable workaround.

$\endgroup$

Your Answer

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

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