Skip to content

Generate Trimesh

Generate Trimesh Tool Icon for OilFlow2D

This chapter describes the Generate Trimesh tool, which creates the triangular computational mesh (TriMesh) used for hydrodynamic simulations. The mesh defines the computational domain where flow equations are solved. This tool is located in the second button on the OilFlow2D plugin toolbar.

The dropdown menu offers three mesh generation options:

  • Generate TriMesh: Basic mesh generation without elevation data.

  • Generate TriMesh with elevations from DEM Raster: Generates mesh with elevations sampled from a raster DEM layer.

  • Generate TriMesh with elevations from DEM TIN: Generates mesh with elevations interpolated from a vector TIN layer.

Basic Mesh Generation

The Generate TriMesh option creates a basic triangular mesh without assigning elevation values to the cells. This option is useful when elevations will be assigned later or when only the mesh geometry is needed.

Dialog Window

This option does not display a dialog window. When selected, the tool automatically executes the mesh generation process using the configuration defined by the project layers.

Dialog Controls

There are no dialog controls for this option. All mesh generation parameters are automatically obtained from the project layers, primarily from the CellSize field in the Domain Outline layer.

Workflow

  1. Ensure that the Domain Outline layer exists and contains the CellSize field with the desired cell size (see Requirements section).

  2. Verify that the Domain Outline layer is not in edit mode.

  3. Optionally, configure MeshBreakLine, MeshDensityLine, or MeshDensityPolygon layers to control mesh density.

  4. Click on the Generate TriMesh toolbar icon for OilFlow2D icon and select the Generate TriMesh option from the dropdown menu.

  5. The tool will automatically process the layers and generate the mesh.

  6. The resulting TriMesh layer will be loaded into QGIS with graduated symbology.

Requirements

Required layers:

  • Domain Outline: Polygon layer that defines the computational domain boundary. Must contain a CellSize field (or LELEM or ElemenSize) that specifies the desired cell size. The layer must not be in edit mode.

Optional layers:

  • MeshBreakLine: Line layer that imposes mesh element edges along these lines (e.g., levees, walls). Must contain CellSize field.

  • MeshDensityLine: Line layer that defines where mesh density is controlled with variable cell size values.

  • MeshDensityPolygon: Polygon layer that defines areas where a specific cell size is applied.

  • Bridges, Gates, Weirs, DamBreach, Channels1D: Structures that are incorporated into the mesh geometry.

Technical Details

Generation process:

  • The tool densifies the domain geometry according to the CellSize value.

  • Generates a geometry file (.geo) for Gmsh.

  • Executes Gmsh to create the triangular mesh using the 2D Delaunay algorithm.

  • Converts the result to shapefile.

TriMesh output layer:

The tool generates a shapefile layer called TriMesh with the following fields:

  • idT: Unique triangle identifier.

  • N1, N2, N3: Indices of the triangle vertex nodes.

  • MANNINGN: Manning's roughness coefficient (initialized to zero).

  • ELZB: Cell bottom elevation (empty in this option).

  • ELINITWSE: Initial water surface elevation.

  • MINERODE: Minimum erosion depth.

  • DUMMY: Reserved field.

The layer is loaded with graduated symbology based on the ELZB field, with 60% opacity.

Mesh with Elevation from Raster DEM

The Generate TriMesh with elevations from DEM Raster option creates a triangular mesh and assigns elevation values to each cell by sampling a digital elevation model (DEM) in raster format.

Dialog Window

When this option is selected, a dialog titled TriMesh with Elevations appears that allows the user to select the raster DEM layer from which elevations will be sampled.

Dialog Controls

Control Type Description
DEM Layer List Dropdown List of available raster layers in the project. Select the DEM layer containing elevation data.
Use Multiple DEM Boundaries Checkbox If checked, uses the MultipleDemBoundaries layer to define zones with different DEMs. When active, disables the single layer selection dropdown.
OK Button Executes mesh generation with the selected settings.
Cancel Button Closes the dialog without generating the mesh.

Workflow

  1. Ensure all requirements listed in the Requirements section are met.

  2. Load the raster DEM layer into the QGIS project.

  3. Click on the Generate TriMesh toolbar icon for OilFlow2D icon and select the Generate TriMesh with elevations from DEM Raster option from the dropdown menu.

  4. The TriMesh with Elevations dialog appears.

  5. In the dialog, select the DEM layer from the dropdown.

  6. If using multiple DEMs, check the Use Multiple DEM Boundaries checkbox and ensure the MultipleDemBoundaries layer is configured.

  7. Click OK to execute the generation.

  8. The tool will generate the mesh and sample elevations from the DEM for each cell.

  9. If there are cells with null elevation values (outside the DEM), a dialog will be shown to zoom to the problematic cells.

Requirements

In addition to the basic option requirements (Domain Outline layer with CellSize field):

  • Raster DEM layer: Raster layer containing terrain elevation data.

  • The coordinate reference system (CRS) of the DEM must match that of the project.

  • The DEM should cover the entire computational domain to avoid null elevation values.

  • MultipleDemBoundaries (optional): Polygon layer that defines zones using different DEM layers.

Technical Details

Sampling method:

For each cell in the generated mesh, the tool:

  • Calculates the triangle centroid.

  • Samples the elevation value from the raster DEM at the centroid position.

  • Assigns the sampled value to the cell's ELZB field.

TriMesh output layer:

The generated TriMesh layer contains the same fields as the basic option, but with the ELZB field populated with elevation values sampled from the raster DEM. The graduated symbology will show elevation variation across the domain.

Mesh with Elevation from TIN DEM

The Generate TriMesh with elevations from DEM TIN option is a new feature that creates a triangular mesh and assigns elevation values to each cell using barycentric interpolation from a digital elevation model in vector format with TIN (Triangulated Irregular Network) structure.

Dialog Window

When this option is selected, a dialog titled TriMesh with Elevations with subtitle Select TIN Layer appears that allows the user to select the vector TIN layer.

Dialog Controls

Control Type Description
Tin Layer List Dropdown List of available polygon vector layers in the project (excluding system layers like TriMesh, Domain Outline, etc.). Select the TIN layer containing elevation data.
Get elevations from Multiple TIN Boundaries Checkbox If checked, uses the MultipleDemBoundaries layer to define zones with different TIN layers.
OK Button Executes mesh generation with the selected settings.
Cancel Button Closes the dialog without generating the mesh.

Workflow

Before running this tool, verify that the TIN layer meets the requirements described in the Requirements section, including Z coordinate verification.

  1. Load the vector TIN layer into the QGIS project.

  2. Verify that the TIN layer contains valid Z coordinates (see Requirements section).

  3. Click on the Generate TriMesh toolbar icon for OilFlow2D icon and select the Generate TriMesh with elevations from DEM TIN option from the dropdown menu.

  4. The TriMesh with Elevations - Select TIN Layer dialog appears.

  5. In the dialog, select the TIN layer from the Tin Layer List dropdown.

  6. If using multiple TINs, check the Get elevations from Multiple TIN Boundaries checkbox.

  7. Click OK to execute the generation.

  8. The tool will generate the mesh and interpolate elevations using barycentric coordinates.

Requirements

In addition to the basic option requirements (Domain Outline layer with CellSize field):

TIN layer requirements:

  • Structure: Must be composed of a mesh of 3D triangular elements that can be irregular (TIN).

  • Z coordinates: The vertices or nodes of the triangles must contain the Z coordinate value (elevation).

  • Format: The file format must be shapefile. A layer imported from a DXF file can be used, but the sampling process will be very slow.

  • Coordinate system: The CRS must be the same as the project's.

  • Coverage: The TIN DEM must cover the entire computational domain.

Verifying Z coordinates in the TIN layer:

To verify if the TIN layer has valid Z coordinates:

  1. Select the Identify Features button on the QGIS toolbar.

  2. Click on any triangle of the TIN mesh.

  3. In the Identify Results window, expand the (Derived) group.

  4. Verify that the Closest vertex Z field exists and shows a numeric value.

If the Closest vertex Z field does not appear or shows null values, the TIN layer does not contain valid Z coordinates.

Technical Details

Barycentric interpolation method:

For each cell in the generated mesh, the tool:

  • Calculates the triangle centroid.

  • Finds the TIN triangle containing the centroid using a spatial index for fast lookups.

  • Calculates the barycentric coordinates of the centroid with respect to the three vertices of the TIN triangle.

  • Interpolates the elevation value using the Z values of the three vertices and the barycentric coordinates.

  • Assigns the interpolated value to the cell's ELZB field.

Advantages over raster method:

  • Higher accuracy: Barycentric interpolation provides more accurate elevation values by considering the three vertices of the triangle instead of a single raster point.

  • Better terrain representation: TIN models can better represent terrain variations, especially in areas with complex topography.

  • Data efficiency: TINs can represent surfaces with less data than equivalent rasters, especially in areas of smooth topography.

TriMesh output layer:

The generated TriMesh layer contains the same fields as the basic option, but with the ELZB field populated with elevation values interpolated from the TIN. The graduated symbology will show elevation variation across the domain.