Skip to content
/ TQMesh Public

A simple two-dimensional mesh generator with triangular and quadrilateral elements in C++

License

Notifications You must be signed in to change notification settings

FloSewn/TQMesh

Repository files navigation

TQMesh: Simplifying Two-Dimensional Mesh Generation


TQMesh-Example-6

TQMesh is a C++ library and standalone application for generating two-dimensional meshes composed of triangular and quadrilateral elements. It is intended for use in scientific and engineering applications such as finite element and finite volume methods, where control over element size, topology, and boundary representation is required.

The mesh generation is based on an advancing-front approach. Users describe the computational domain by boundary segments and optional interior constraints, while element sizes can be controlled through boundary attributes or user-defined size functions.


Features

  • Advancing‑front mesh generation
    Meshes are generated from user‑defined boundary segments, providing explicit control over the domain geometry.

  • Triangular and quadrilateral elements
    The mesher supports pure triangular meshes as well as mixed meshes with quadrilateral elements, including quad layers near boundaries.

  • Local mesh size control
    Element sizes can be influenced by boundary‑based sizing factors or by user‑defined size functions.

  • Boundary and interior constraints
    Boundary markers, fixed interior vertices, and fixed interior edges can be used to guide the meshing process.

  • Multiple meshes and merging
    Several meshes can be generated and merged while preserving conformity along shared boundaries.


Used in Research

This library has been used in the following academic work:

  • Quadrilateral Mesh-Based Reactive Transport Modeling in Non-Orthogonal Random Fracture-Matrix Systems
    Su, Danyang, et al.
    SSRN 5251117

Installation

TQMesh is a header‑only library. To use the library components, include the headers located in:

  • src/algorithm
  • src/utils

The directory src/app contains the source code for the standalone application.

Build and install the application

git clone https://github.com/FloSewn/TQMesh
cd TQMesh
mkdir build
cd build
cmake ..
make install

To select a specific compiler or build type, pass the appropriate options to CMake, for example:

cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug ..

Library Usage

Example programs demonstrating how to use the TQMesh library are provided in src/examples.

After building the project, the examples can be executed using:

./bin/run_examples <example-id>

where <example-id> refers to one of the available example configurations.


Application Usage

The TQMesh application reads simple parameter files describing the mesh geometry and options. Example input files are provided in the input/ directory.

Run the application from the project root using:

./bin/TQMesh <input-file>

Examples and Capabilities

Mesh generation in TQMesh is based on a small set of global parameters, boundary definitions (nodes and edges), and optional interior constraints. Boundary edges can be assigned markers that are propagated to the resulting mesh.

The following examples illustrate typical use cases.

Local mesh refinement

Element sizes can be controlled through boundary‑based sizing factors or user‑defined size functions.

Simple triangular mesh

Thin fracture mesh

Quadrilateral layers and refinement

Quadrilateral elements and quad layers near boundaries can be generated using a paving‑style approach, followed by optional quad refinement.

Quad-dominated mesh

Quad refinement

Boundary shapes

Meshes can be created from predefined boundary shapes such as rectangles, circles, and triangles.

Boundary shapes

Mesh refinement example

Mesh refinement example

Element coloring and interior control

Each element carries an associated color value that can be modified during meshing. Fixed interior vertices may be defined to locally influence mesh resolution.

Fixed interior vertices

Merging meshes

Multiple meshes can be generated and merged while preserving boundary conformity, enabling different regions to be assigned different element attributes.

Merged meshes

Multiple meshes

Importing boundaries from CSV

Boundary definitions can be imported from CSV files to support automated meshing workflows.

Airfoil mesh

Fixed interior edges

Interior edges can be specified explicitly to guide the advancing‑front process.

Fixed interior edges


Output Formats

Meshes can be exported in:

  • VTU format (readable by ParaView)
  • A plain text format

The text format includes vertex coordinates, element connectivity, boundary information, adjacency data, and size function values.


OpenFOAM Conversion

A helper script is provided to convert TQMesh output into a format suitable for OpenFOAM by extruding the 2D mesh in the z‑direction:

python scripts/convert2foam.py [-e EXTRUSION] Mesh.txt export-prefix

Plotting Meshes

A Python script for visualizing meshes is available at scripts/plot_mesh.py:

python scripts/plot_mesh.py Mesh.txt (-s -c -v -e -b -f)

Optional flags enable visualization of size functions, element colors, indices, and boundaries.

Mesh visualization


Tests and Benchmarks

TQMesh uses a customized QuadTree data structure to store and access mesh entities. Benchmark plots illustrating performance characteristics are provided below.

QuadTree benchmark

Mesh benchmark


Roadmap

  • Improved triangle‑to‑quad morphing
  • Boundary definitions via splines
  • Extended documentation and tests

Contributions are welcome.


Third‑Party Libraries

  • exprtk — C++ Mathematical Expression Toolkit Library

References

  • O'Rourke, J. Computational Geometry in C. Cambridge University Press, 1998.
  • Shewchuk, J. R. Lecture Notes on Delaunay Mesh Generation, 2012.
  • Lo, D. S. H. Finite Element Mesh Generation. CRC Press, 2014.
  • Blazek, J. Computational Fluid Dynamics: Principles and Applications. Butterworth‑Heinemann, 2015.
  • Zhou, T., & Shimada, K. An Angle‑Based Approach to Two‑Dimensional Mesh Smoothing, IMR 2000.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages