FEMDocumentation`
FEMDocumentation`

ToElementMesh

ToElementMesh[r]

generates an ElementMesh object from a region r.

ToElementMesh[r,{{xmin,xmax},}]

generates an ElementMesh object from a region r restricted to the bounding box [x_(min),x_(max)]x....

ToElementMesh[rules]

generates an ElementMesh object from a set of rules specifying coordinates and elements.

ToElementMesh[emesh]

generates a new ElementMesh object from an existing ElementMesh, MeshRegion, or BoundaryMeshRegion.

Details

  • ToElementMesh[r] generates an ElementMesh object that approximates a possibly symbolic region r.
  • The specification for regions r includes objects described by geometric regions and ImplicitRegion.
  • The region r should be a constant region for which ConstantRegionQ gives True.
  • To generate an approximation to the region r, ToElementMesh first calls ToBoundaryMesh.
  • In ToElementMesh[rules], the following rules should be given:
  • "Coordinates"->{c1,c2,}required to specify the coordinates to be c1, c2,
    "MeshElements"->{e1,}required to specify the elements in the mesh to be e1,
    "BoundaryElements"->{b1,}optionally specify the boundary elements in the mesh to be b1,
    "PointElements"->{p1,}optionally specify the point elements in the mesh to be p1,
  • For a 1D element mesh, "MeshElements" are LineElement. "BoundaryElements" and "PointElements" are, if specified, PointElement.
  • For a 2D element mesh, "MeshElements" can be TriangleElement and QuadElement. "BoundaryElements", if specified, are LineElement, and "PointElements" are PointElement.
  • For a 3D element mesh, "MeshElements" can be TetrahedronElement or HexahedronElement. "BoundaryElements", if specified, are TriangleElement and QuadElement, and "PointElements" are PointElement.
  • ToElementMesh has the same options as ToBoundaryMesh, with the following additions:
  • "CheckQuality"Automaticcompute a quality assessment
    "ElementMeshGenerator"Automaticfunction to generate an ElementMesh object from a boundary ElementMesh object
    "ImproveBoundaryPosition"Automaticimprove the position of the boundary nodes
    "MeshElementBlocks"1number of blocks of mesh elements
    "MeshElementConstraint"Automaticadditional constraints for mesh elements
    "MeshElementType"Automaticelement type used to mesh input
    "MeshOrder"Automaticorder of the element mesh
    MeshQualityGoalAutomaticspecify a mesh element quality goal
    MeshRefinementFunctionAutomaticcontrol element refinement
    "NodeReordering"Automaticreorder nodes to generate minimal bandwidth matrices
    "SteinerPoints"Automaticcontrol the insertion of Steiner points
    "RegionMarker"Nonespecify region markers
  • ToElementMesh[emesh,opts] may be used to modify an ElementMesh object emesh in various ways by specifying any of the options for ToElementMesh.
  • If ToElementMesh cannot generate an ElementMesh, then $Failed is returned.
  • Invoking ToElementMesh on an EmptyRegion will return an EmptyRegion.
  • Options given to ToElementMesh can be given to NDSolve by specifying "MeshOptions". »

Examples

open allclose all

Basic Examples  (4)

Load the package:

Generate an element mesh for a disk:

Visualize the element mesh wireframe:

Generate an element mesh for the union of a disk and a rectangle:

Specify an unbounded region with a bounding box:

Specify the elements of an element mesh:

Scope  (22)

Generate a mesh in the region between two circles:

Convert an ImplicitRegion with an explicit bounding box:

Convert an ImplicitRegion computed from a RegionDistance with an explicit bounding box:

Convert a GraphicsComplex to an element mesh:

Convert a TransformedRegion to an element mesh:

Convert a 3D Sphere to an element mesh:

Convert a 3D GraphicsComplex to an element mesh:

Create a mesh from a 3D ImplicitRegion:

Convert a 3D TransformedRegion to an element mesh:

Create an element mesh from four coordinates and two elements:

1D Line Element Meshes  (2)

Create a line element mesh:

Create a 1D ElementMesh with region holes from an ImplicitRegion:

2D Triangle Element Meshes  (1)

Create a triangle element mesh:

2D Quad Element Meshes  (2)

Create a quad element mesh:

Create a quad element mesh:

Visualize the node numbers in red and the element numbers in blue:

2D Mixed-Element Type Meshes  (1)

Create a mixed-element mesh:

2D Higher-Order Element Meshes  (1)

Create a mixed-element mesh with quadratic elements:

3D Tetrahedron Element Meshes  (1)

A linear tetrahedron element mesh with markers:

Visualizing the index of the coordinates at their respective positions:

Create the mesh:

Visualize the mesh with the elements' markers:

3D Hexahedron Element Meshes  (1)

Create an element mesh consisting of hexahedra:

Region Markers  (1)

Create a mixed-element mesh with region markers:

Boundary Markers  (1)

Create a rectangle with boundary markers:

Point Markers  (1)

Create a rectangle with point markers:

Options  (37)

"BoundaryMarkerFunction"  (2)

Compute integer markers for edges depending on the coordinates of the edge elements:

Inspect the boundary elements:

If "PointElementMarkers" are also computed, those are accessible as the second argument in the function given to "BoundaryMarkerFunction".

Markers can be specified for quad mesh elements:

"BoundaryMeshGenerator"  (1)

The "Continuation" method uses a curve continuation method that can in many cases resolve corners, cusps, and sharp changes quite well:

The "RegionPlot" method is based on improving output from RegionPlot and can sometimes be faster:

More information on the "BoundaryMeshGenerator" option can be found in the ToBoundaryMesh reference page.

"ElementMeshGenerator"  (1)

Replace the internal mesh generator with a custom mesh generator:

The numerical region given to the custom mesh generators will contain a "BoundaryMesh". If the interface to the external mesh generator does not need a boundary mesh representation because the mesh generator interface works with a symbolic representation the generation of the boundary mesh can be avoided by setting "BoundaryMeshGenerator"->None.

"ImproveBoundaryPosition"  (1)

Approximation of an ImplicitRegion is generally not exact. The "ImproveBoundaryPosition" option helps to improve the position of boundary nodes:

The sum of the squares of the boundary nodes is not necessarily all at value 1:

Automatic improvement is the default in 2D, and the results are better:

When the "ImproveBoundaryPosition" option is set to False, quadratic elements will not have their middle nodes on the boundary of a curved part of the region.

"IncludePoints"  (2)

Create an element mesh:

Specify a circle of additional points:

Create a mesh with the include points:

Adding include points to a quadrilateral mesh:

"MaxBoundaryCellMeasure"  (2)

With "MaxBoundaryCellMeasure"->m, a boundary cell size is chosen:

Specify a boundary cell size and a cell size:

"MaxCellMeasure"  (4)

With MaxCellMeasure->m, a cell size is chosen and a boundary cell size is set to be appropriate for good-quality cells in the embedding dimension:

Find the maximum mesh element area:

Set a smaller max cell measure:

Find the maximum mesh element area:

The max cell measure targets linear elements. In the case of a higher-order mesh for a curved boundary, the actual cell measure may be higher.

A specific length can be specified using MaxCellMeasure->{"Length"->len}:

If a specific length and area are specified using MaxCellMeasure->{"Length"->len,"Area"->area}, the more stringent requirement is satisfied:

Find the maximum mesh element area:

Set a maximum cell measure on the boundary:

"MeshElementBlocks"  (1)

Create an element mesh:

Mesh the same region and split the elements into five blocks:

"MeshElementConstraint"  (2)

For two-dimensional meshes based on TriangleElement, a minimum triangle angle can be specified via the "MeshElementConstraint" option:

With the default:

The minimum angle specified must be smaller then 33 degrees. Theoretically, the algorithm is guaranteed to terminate for minimum angles smaller than 22.7 degrees, but in practice it often succeeds for minimum angles up to 33 degrees.

For three-dimensional TetrahedronElement meshes, a minimum ratio of the tetrahedral radius to edge length can be specified via the "MeshElementConstraint" option:

With the default setting:

The radius-edge ratio must be larger than . Theoretically, the algorithm is guaranteed to terminate for a radius-edge ratio of 2, but in practice it often succeeds for radius-edge ratios down to .

"MeshElementType"  (1)

Mesh a region with quad mesh elements:

Mesh the same region with triangle elements:

Quad elements are currently only generated for rectangular regions.

"MeshOrder"  (1)

Create a second-order element mesh for a region:

Mesh the same region with a first-order mesh:

"MeshQualityGoal"  (1)

The quality measure is computed so that for regular mesh elements , and for degenerate mesh elements :

Triangulate with more regular triangles:

"MeshRefinementFunction"  (8)

Create a function that returns True if a specific 2D triangle element needs to be refined:

Create a full mesh of the boundary mesh with the refinement function:

Visualize the resulting mesh:

Compare to a mesh generated without refinement:

Create a compiled function that returns True if a specific 2D triangle element needs to be refined:

Create a mesh of a disk with the refinement function:

Visualize the resulting mesh:

Create a gradual refinement toward the center:

Create a gradual refinement toward the boundary:

Create a refinement in a subregion:

Visualize the mesh with the refinement contour:

Use an image as a refinement function:

Create a distance transform of that image:

Visualize the distance transform of the image:

Create an interpolation function from the image distance transform:

Create a compiled refinement function calling the interpolation function:

Create a triangle mesh with a given refinement:

Visualize the mesh:

Create a function that returns True if a specific 2D triangle element needs to be refined:

Create a compiled function that returns True or False :

Create a full mesh of the boundary mesh with the compiled refinement function:

Visualize the resulting mesh:

Create a compiled function that returns True if a specific 3D tetrahedron element needs to be refined:

Create a boundary mesh:

Create a full mesh of the boundary mesh with the refinement function:

Visualize the resulting mesh:

"NodeReordering"  (2)

Create an ElementMesh from a region:

Visualize the incidences of the mesh elements:

Create a mesh from the same region with node reordering:

The pattern of the incidences is much more organized:

A function for the node reordering can be provided:

"NodeReordering" is also known as matrix bandwidth reduction.

"PointMarkerFunction"  (1)

Compute integer markers for edges depending on the coordinates of the edge nodes:

Create an element mesh with the point markers:

Inspect the boundary elements:

The point marker values of the mid-side nodes for second-order meshes are derived from the boundary element markers. Since none are given here, the values are arbitrary:

If "BoundaryMarkerFunction" is also computed, middle nodes will have values derived from the boundary element markers:

"RegionHoles"  (4)

Create a boundary mesh with an internal region:

Create a full mesh from the boundary mesh:

Create a full mesh from the boundary mesh, with the interior specified as a region hole:

Create an element mesh with a hole in the middle:

Mesh the region, including the hole:

Mesh the region without the hole by explicitly giving a coordinate in the region that is a hole:

Create and visualize a region with holes:

Generate a full mesh from the boundary mesh:

Specify a region hole and a region marker:

Specify a region hole in 3D:

Visualize the boundary mesh and a point inside the interior box:

Create the full element mesh with a hole inside:

Visualize the full element mesh:

"RegionMarker"  (2)

Create a boundary mesh:

The boundary element containing {1/2,3/4} should use the marker 1, and the region containing {1/2,1/4} should use the marker 2:

Additionally, a refinement parameter for the region with marker 1 is given to the markers:

Specify a region in 3D:

Create the full element mesh with subregions inside that follow different refinements:

Visualize the full element mesh:

"SteinerPoints"  (1)

For 2D triangle meshes, the insertion of Steiner points can be controlled. In this case, the boundary respects the boundary size and does not further subdivide:

In this case, the second-order mid-side nodes are still present:

Using a first-order mesh avoids mid-side nodes:

Properties & Relations  (5)

An ElementMesh can be part of an InterpolatingFunction returned by NDSolve:

Pass an ElementMesh to NDSolve:

Pass an ElementMesh to NDEigensystem:

Pass options for ToElementMesh to NDSolve to solve a stationary PDE:

Inspect the mesh used to solve the equation:

This is the same mesh:

Pass options for ToElementMesh to NDSolve to solve a time-dependent PDE:

Possible Issues  (9)

If the input symbolic region is unbounded, a default bounding box from is assumed in each space direction:

By specifying an explicit bounding box, the default can be overridden:

Some features of the region may be too small to be represented:

Specifying a smaller boundary size may help:

An ImplicitRegion must not have unspecified symbolic parameters:

If the bounding box intersects with the region specification, low-quality or wrong meshes may result:

Possibly enlarging the bounding box is an option:

The mesh elements in an ElementMesh need to be of the same order:

The element incidents must be given in counterclockwise order:

Mesh elements in an element mesh may not intersect:

Also, combinations of clockwise ordering and self-intersection are detected:

A conversion of a MeshRegion to an ElementMesh may not always be done in a direct mesh conversion:

The reason for this is that ToElementMesh needs to be able to respect mesh options given to it. It is not possible to deduce parameters that were used to generate a MeshRegion and check if ToElementMesh options are satisfied. It may be possible to do a direct conversion of the MeshRegion to an ElementMesh:

Neat Examples  (2)

To convert an image to an element mesh, first the image is converted to a distance function:

The image data is extracted and converted into an interpolation function:

Convert the interpolation function to an element mesh:

Convert the orbiter of the Space Shuttle to an ElementMesh: