({{, (RefLink[MeshRefinementFunction, paclet:ref/MeshRefinementFunction]) 
is an option for (RefLink[DiscretizeRegion, paclet:ref/DiscretizeRegion]) and related functions that specifies a function to indicate whether mesh cells should be refined or not.}})

OpenersNotesSection(Spacer1)Details

With (RefLink[MeshRefinementFunction, paclet:ref/MeshRefinementFunction])->f, the function f[vlist,m] is applied to each simplex created, where vlist is a list of the vertices and m is the measure. If f[vlist,m] returns (RefLink[True, paclet:ref/True]), the simplex will be refined.

OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Discretize a (RefLink[Disk, paclet:ref/Disk]) so that the triangles near the center are smaller:

DiscretizeRegion[Disk[], MeshRefinementFunction->Function[{vertices,area},area>0.0005(1+10Norm[Mean[vertices]])]]

Discretize a (RefLink[Rectangle, paclet:ref/Rectangle]) so that the triangles in the first quadrant are smaller:

DiscretizeRegion[Rectangle[{-1,-1},{1,1}],MeshRefinementFunction->Function[{vertices,area},Block[{x,y},{x,y}=Mean[vertices];If[x>0&&y>0,area>0.001,area>0.01]]]]

OpenersExampleSection1(Spacer1)Scope  (4)

(RefLink[MeshRefinementFunction, paclet:ref/MeshRefinementFunction]) specifies a function to determine if further refinement is needed:

f=Function[{vertices,area},area>0.0005(21-20Norm[Mean[vertices]])];

Further refinement is performed on triangles for which the function returns (RefLink[True, paclet:ref/True]):

DiscretizeRegion[Disk[], MeshRefinementFunction->f]

Using (RefLink[If, paclet:ref/If]) makes it possible to refine triangles satisfying an implicit equation:

f=Function[{vertices,area},Block[{x,y},{x,y}=Mean[vertices];If[x^4+y^4≤1,area>0.003,area>0.01]]];

mr=DiscretizeRegion[Rectangle[{-1.5,-1.5},{1.5,1.5}],MeshRefinementFunction->f]

See the boundary between large and small triangles:

Show[mr,ContourPlot[x^4+y^4==1,{x,-1.5,1.5},{y,-1.5,1.5},ColorFunction->Hue]]

(RefLink[MeshRefinementFunction, paclet:ref/MeshRefinementFunction]) can be used with (RefLink[TriangulateMesh, paclet:ref/TriangulateMesh]):

mr=MeshRegion[{{0,0},{1,0},{1,1},{0,1}},Polygon[{1,2,3,4}]]

Triangulate it with smaller triangles near the lower-left corner:

TriangulateMesh[mr,MeshRefinementFunction->Function[{vertices,area},area>0.0001(1+20Norm[Mean[vertices]])]]

(RefLink[MeshRefinementFunction, paclet:ref/MeshRefinementFunction]) can be used with (RefLink[DiscretizeRegion, paclet:ref/DiscretizeRegion]):

r=Disk[{0,0},{3,2}];
DiscretizeRegion[r]

Discretize it with smaller triangles further away from the center:

DiscretizeRegion[r,MeshRefinementFunction->Function[{vertices,area},area>0.0025(25-8Norm[Mean[vertices]])]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[DiscretizeRegion, paclet:ref/DiscretizeRegion])  ▪  (RefLink[BoundaryDiscretizeRegion, paclet:ref/BoundaryDiscretizeRegion])  ▪  (RefLink[TriangulateMesh, paclet:ref/TriangulateMesh])  ▪  (RefLink[DiscretizeGraphics, paclet:ref/DiscretizeGraphics])  ▪  (RefLink[BoundaryDiscretizeGraphics, paclet:ref/BoundaryDiscretizeGraphics])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Mesh-Based Geometric Regions, paclet:guide/MeshRegions])}})}})