NDSolve`FEM`
NDSolve`FEM`

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 and Options

  • 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 in this order:
  • "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 in 2D and 3D
    "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". »
  • Setting options for ToElementMesh from NDSolve and related functions is explained in NDSolve Finite Element Options.

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  (29)

Generate a mesh in the region between two circles:

Generate a mesh in the region between two circles using a BooleanRegion:

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 Ball to an element mesh:

Convert a 3D GraphicsComplex to an element mesh:

Create a mesh from a 3D ImplicitRegion:

Create a mesh from a 3D BooleanRegion:

Convert a 3D TransformedRegion to an element mesh:

Create an element mesh from four coordinates and two elements:

For a set of points, ToElementMesh will return a Delaunay triangulation:

1D Line Element Meshes  (3)

Create a line element mesh:

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

Create an ElementMeshRegionProduct from a 1D ElementMesh:

2D Triangle Element Meshes  (2)

Create a triangle element mesh:

Create an ElementMeshRegionProduct from a 2D ElementMesh and a 1D ElementMesh:

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:

Images  (2)

Convert an Image to a mesh:

Convert an Image to a mesh without region holes:

Region Markers  (1)

Region marker are useful to specify multiple materials in a region and are explained further in the section Markers in the Element Mesh Generation.

Create a mixed-element mesh with region markers:

Boundary Markers  (1)

Boundary markers are useful to specify NeumannValue on a region boundary and are explained further in the section Markers in the Element Mesh Generation.

Create a rectangle with boundary markers:

Point Markers  (1)

Point markers are useful to specify DirichletCondition on a region boundary and are explained further in the section Markers in the Element Mesh Generation.

Create a rectangle with point markers:

Options  (41)

"BoundaryMarkerFunction"  (2)

Boundary markers are useful to specify NeumannValue on a region boundary and are explained further in the section Markers in the Element Mesh Generation.

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"  (2)

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 on the ToBoundaryMesh reference page.

The "OpenCascade" boundary mesh generator is well suited for 3D BooleanRegion expressions consisting of Graphics3D primitives.

Specify a region:

Use "OpenCascade" as a boundary mesh generator:

Generate colors for the boundary markers:

Visualize the element mesh with highlighted boundary markers:

"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"  (3)

Create an element mesh:

Specify a circle of additional points:

Create a mesh with the include points:

Points added with "IncludePoints" will be addressable with DirichletCondition. Additionally, if the predicate in DirichletCondition is True, then the boundary condition will take effect at the include points.

Adding include points to a quadrilateral mesh:

"IncludePoints" is an option for ToBoundaryMesh and ToElementMesh that will pass the option on. This means, however, that when ToElementMesh is presented a boundary ElementMesh, it cannot fulfill the request:

The point {0,0} has not been included. The solution to this is to either specify the "IncludePoints" during the call to ToBoundaryMesh or make use of the symbolic region when calling ToElementMesh.

Use "IncludePoints" during the call to ToBoundaryMesh:

The alternative is to use the symbolic region in the call to ToElementMesh:

"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:

Inspect the mesh order:

Integrate over the mesh and assess the accuracy of the integration:

Mesh the same region with a first-order mesh:

Inspect the mesh order:

Integrate over the mesh and assess the accuracy of the integration:

More information about the "MeshOrder" option can be found in this section of the Element Mesh Generation tutorial or in this section of the Element Mesh Generation tutorial.

"MeshQualityGoal"  (1)

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

Triangulate with more regular triangles:

"MeshRefinementFunction"  (9)

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:

In 1D use DiscretizeRegion to do the refinement:

"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)

Point markers are useful to specify DirichletCondition on a region boundary and are explained further in the section Markers in the Element Mesh Generation.

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:

"PointMarkers"  (1)

Point markers are useful to specify DirichletCondition on a region boundary and are explained further in the section Markers in the Element Mesh Generation.

The way point markers are set up in a mesh can be done in different ways. One possible option is to derive point markers from boundary markers.

Mesh the region and deduce the point markers from the boundary markers:

Browse through the surfaces:

Select from which surfaces the point markers should be constructed:

Visualize the points with the selected point marker:

Find the intersection such that only points connected to all surfaces are considered. Boundary element marker ID 7 is the large cylinder body surface:

Visualize the points with the selected point marker:

"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:

Applications  (2)

Create an ElementMesh of a river from a GeoGraphics:

Generate an element mesh of two nested half-annuli with . Each annulus represents a different subdomain. The first subdomain has an inner radius of and a outer radius of , and the second subdomain has an inner radius of and a outer radius of .

First, create a series of three half-disks, then a union of the three subregions is generated and finally, to create the two annuli, the first half-disk is taken to represent an inner hole.

Define the inner and outer radius of the first annulus:

Define the outer radius of the second annulus:

Create the half-disks using Circle:

When a union of half-disks is created, the left boundary will automatically be deleted from the union. So to bound the region again, a line segment is created and joined to the union of half-disks. To cut a hole out of the first half-disk, you can just bound the union from to and from to in the direction, leaving aside the first half-disk.

Create two line segments:

Generate a union of the half-disks and the lines:

Assign an element marker for each annulus:

Generate an element mesh with the defined subdomains using RegionMarker and restrict the mesh to :

Visualize the element mesh wireframe:

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  (11)

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:

For this specific case, it is possible to generate the ElementMesh directly by using ToGradedMesh and ElementMeshRegionProduct:

The arguments to ToElementMesh are specified as rules and need to be given in the correct order: "Coordinates", "MeshElements" and optionally "BoundaryElements" and "PointElements":

Specify the arguments in the correct order:

Some mesh generation algorithms for implicit regions are not entirely deterministic in that they return slightly different meshes for the same input:

Note that the number of elements can differ between the runs.

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:

Wolfram Research (2014), ToElementMesh, Wolfram Language function, https://reference.wolfram.com/language/FEMDocumentation/ref/ToElementMesh.html (updated 2022).

Text

Wolfram Research (2014), ToElementMesh, Wolfram Language function, https://reference.wolfram.com/language/FEMDocumentation/ref/ToElementMesh.html (updated 2022).

CMS

Wolfram Language. 2014. "ToElementMesh." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/FEMDocumentation/ref/ToElementMesh.html.

APA

Wolfram Language. (2014). ToElementMesh. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/FEMDocumentation/ref/ToElementMesh.html

BibTeX

@misc{reference.wolfram_2024_toelementmesh, author="Wolfram Research", title="{ToElementMesh}", year="2022", howpublished="\url{https://reference.wolfram.com/language/FEMDocumentation/ref/ToElementMesh.html}", note=[Accessed: 21-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_toelementmesh, organization={Wolfram Research}, title={ToElementMesh}, year={2022}, url={https://reference.wolfram.com/language/FEMDocumentation/ref/ToElementMesh.html}, note=[Accessed: 21-December-2024 ]}