Mesh2D is the 2D mesh generator from Elmer FEM. It reads a geometry description and writes an Elmer mesh: mesh.header, mesh.nodes, mesh.elements and mesh.boundary. Elmer installs it as ElmerMesh2D, and its meshes are used by several of the solver's consistency tests.
This repository packages it on its own so it can be built, tested and released independently.
Part of Elmer, developed at CSC - IT Center for Science Ltd., Finland. Extracted from ElmerCSC/elmerfem with git filter-repo, so the commit history of the meshgen2d/ directory is preserved rather than starting from a squashed import. It is not an official CSC distribution.
GPL 2.0, the licence of the Elmer repository this came from.
Worth stating plainly, because it is not as clear-cut as it should be: Elmer's own license_texts/ElmerLicensePolicy.md names the parts under LGPL, the solver library, matc and fhutiter, and the parts under GPL, ElmerGUI, ElmerGrid and most solver modules. meshgen2d appears in neither list, and the sources carry no licence header. The repository as a whole is GPL 2.0 and meshgen2d is not among the stated exceptions, so GPL 2.0 is the reading taken here. If that is wrong, the place to correct it is upstream, and this repository should follow.
Binaries for each supported platform are on the releases page. There is no single binary that runs everywhere: this is native code, so there is one archive per operating system and CPU architecture.
Mesh2D [--bgmesh=filename] [--bgcontrol=filename] <input file> [mesh directory]
The input is an ElmerFront geometry file, conventionally .mif. For example, using the geometry included here for testing:
$ Mesh2D tests/kulma.mif out/
$ ls out
mesh.boundary mesh.elements mesh.header mesh.nodes
Running it with no arguments prints the usage line and exits without meshing.
Requires CMake 3.12 or newer and a C++ compiler.
cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failure
The test meshes tests/kulma.mif and checks that the mesh files were written and that mesh.nodes is not empty. Exit code alone would not be enough, since Mesh2D prints its usage and returns without meshing when it dislikes its arguments.
One thing to know if you port it further: src/include/coreGeometry.h includes minmaxpatch.h when WIN32 is defined, and that header supplies its own std::min and std::max unless MINGW32 is also defined. Both come from the Elmer top level build, so a standalone build has to define them too or every translation unit fails with "redefinition of std::min". That is handled here.
Mesh2D does not validate its input. Given a file that is not a geometry it crashes rather than reporting an error; on Windows that surfaces as an access violation. The test here treats a non-zero exit as failure, so this is visible rather than silent, but it is a real robustness gap in the generator and is worth fixing upstream.
Elmer can consume this repository as a submodule, with its own build unchanged: the directory is added with ADD_SUBDIRECTORY(meshgen2d) exactly as before, and the Mesh2D target it produces is the same. A clone then needs --recurse-submodules, or git submodule update --init.
The CMake here works both ways. As the top level project it supplies its own project(), the definitions above and the test; added as a subdirectory it takes those from the parent and nothing about the Elmer build changes.