2D FEM Mesh Generation with femmesh
Contents
See also:
femmesh is an interactive UNIX/OpenWindows tool for creating circular, rectangular or irregular 2D FEM meshes.
The mesh files produced by femmesh can be used in FEM main programs (solvers) to produce solutions at the nodal points of the mesh.
Features of femmesh include:
- Variable, user-definable mesh resolution.
- Automatic mesh generation from imported outline data.
- Interactive local element subdivision.
- Node positioning and deletion.
- Tools for regional modification of element absorption, scattering and refractive index.
- Point source placement.
Location (only for Medical Physics users):
~martins/bin/femmesh
Syntax:
femmesh [mesh-file]
When invoked, femmesh comes up with a mesh display window and a control panel. The control panel is used to create, modify and save a mesh.

Sample femmesh screen.
To create a mesh from scratch,
- Click on the "New" button to bring up the mesh generation dialog.
- Select the required mesh type.
For circular meshes:
- Select the number of element rings and sectors into which the circle is to be divided. This determines the element size and node density of the mesh. A value of 6 for the number of sectors is usually optimal, as this produces the most regular triangular elements. The number of rings is typically between 16 and 50, depending on the physical size of the circle, the optical properties and the required accuracy of the solution. A standard value is 32 for a circle of 25 mm radius and typical optical properties.
- Select the mesh radius.
For rectangular meshes:
- Select a mesh structure.
WARNING: The first structure type, containing rectangular elements, is not supported by the FEM library. The second type, splitting each rectangle into two triangles, may cause problems with some solvers. It is highly recommended to choose the third type, splitting each rectangle into four triangles.
- Select the physical dimensions of the mesh by specifying the coordinates of the left, right, lower and upper boundaries.
- Specify the number of element columns and rows into which the mesh is to be divided.
For irregular meshes:
- Specify the bounding box of the mesh.
- Click on "Force equidistant front nodes", if the boundary nodes should automatically be placed with with constant spacing.
- Select "Frontlines|Create"
- Drop the boundary nodes in the mesh display window (see Creating irregular meshes below).
Once all parameters for circular, rectangular or irregular meshes have been set, click on "Apply" to start the mesh generation process. Note that this can take a while, especially for large meshes. When the mesh is complete, click on "Done" to remove the mesh creation dialog box.

'New' dialog for rectangular meshes.
- To generate meshes with other than circular or rectangular shapes, use the "Irregular" option in the mesh generation dialog box.
- After selecting the bounding box of the mesh, select "Frontlines|Create" to start the interactive outlining process.
- Move the mouse pointer into the mesh display window, and click the left button to drop a boundary node.
- Drop boundary nodes all along the outline of the mesh. Note that
- Boundary nodes must be dropped clockwise along the mesh boundary.
- Nodes should be dropped evenly, as this produces more regular and stable meshes. If you click on "Force equidistant front nodes" before dropping the first node, then equal spacing is ensured automatically. In this case the distance between the first and second node defines the spacing for all other nodes.
- After dropping the last node, click the middle button to close the outline polygon.
- More than one frontline can be created for the same mesh. This is useful if there are internal structures along which the element structure should be aligned. However,
- Frontlines must not intersect.
- The mesh must be compact, i.e. there must be one frontline enclosing all other frontlines.
- Internal frontlines need not be created clockwise.
- When a frontline has been finished, and before the mesh generation is started by clicking on "Apply", the frontline information can be saved to a file by "Frontlines|Save" and retrieved at a later time by "Frontlines|Load". This is helpful for very large meshes, where the mesh generation could take very long. If the mesh generation has to be aborted, then at least the frontlines are still available.
- Click "Apply" to start the mesh generation.
The node density of a mesh can be locally increased by subdividing elements manually.
- Click on the "Refine" button.
- Move the mouse pointer into the mesh display window and click on the element to be refined. The element is split into two elements.
- Note that usually at least one of the element's neighbours is also refined, to ensure the validity of the mesh.
- Optimised meshes cannot be refined, since optimised mesh files do not contain refinement information.
The optical coefficients for each element can be set individually with the 'Modify Coefficient' tool.
- Click on the 'Coeff' button.
- Select the coefficient types you want to change by pressing or releasing the 'Coefficient' buttons.
- Enter the new values for the coefficients.
- To apply the new values to all elements of the mesh, to elements with lower values than the specified, or to elements with higher values than the specified, click the appropriate button.
- To apply the new values only to a certain region within the mesh, click one of the 'Paint mode' buttons: Freehand, flood fill, rectangle, ellipse.
- For freehand: Left-click on any element in the display window you want to assign the new values to.
- For flood fill: Left-click on one of the elements in the region you want to assign the new values to. The whole region is then filled with the new values.
- For rectangle: Left-click on the upper right corner of the rectangular region, and drag the cross-hair to the lower right corner.
- For ellipse: Left-click on the upper right corner of the bounding box of the ellipse, and drag the cross-hair to the lower right corner.
- Close the dialog box with the 'Done' button.

'Modify Coefficients' dialog.
Back to FEM contents page
The information on this page is supplied and compiled by Martin Schweiger
E-mail: martins@medphys.ucl.ac.uk
Last update 18/12/95