Skip to main content

Create unstructured Landlab grids using Jonathan Shewchuk's Triangle mesh generation software

Project description

landlab-triangle

View Landlab Documentation

View triangle Documentation

This repository adds TriangleModelGrid, a new Landlab grid type that enables unstructured triangular meshes. Unlike Landlab's standard structured grids, TriangleModelGrid allows for complex geometries with irregular boundaries, interior holes, and variable grid resolution.

Uses Jonathan Shewchuk's Triangle software.

Installation

Installing from PyPI

pip install triangle landlab-triangle

Usage

Option 1: direct initialization

from landlab_triangle import TriangleModelGrid
import numpy as np

# Create a grid directly with exterior coordinates and optional holes
exterior_y = [-1.0, -1.0, 11.0, 11.0]
exterior_x = [0.0, 10.0, 10.0, 0.0]

holes = np.array([[5.0, 5.0]])  # Optional: define interior holes

grid = TriangleModelGrid(
    exterior_y_and_x=(exterior_y, exterior_x),
    holes=holes,
    triangle_opts="pqa1Devjz"
)

print(f"Number of nodes: {grid.number_of_nodes}")
print(f"Number of cells: {grid.number_of_cells}")
print(f"Number of holes: {len(grid._holes)}")

Option 2: from a dictionary

from landlab_triangle import TriangleModelGrid

# Create a grid from a dictionary with "x" and "y" keys
grid_params = {
    "x": [0.0, 10.0, 10.0, 0.0],
    "y": [0.0, 0.0, 10.0, 10.0],
    "triangle_opts": "pqDevjz"
}

grid = TriangleModelGrid.from_dict(grid_params)

Option 3: from a shapefile

from landlab_triangle import TriangleModelGrid

# Create a grid from a shapefile, GeoJSON, or other supported format
grid = TriangleModelGrid.from_shapefile(
    "path/to/polygon.geojson",
    triangle_opts="pqDevjz",
    timeout=10
)

# The grid automatically handles holes defined in the input file
print(f"Number of holes: {len(grid._holes)}")

Triangle options

The triangle_opts parameter controls the behavior of the Triangle meshing software. Common options include:

  • q: Quality mesh generation - ensures no angles smaller than N degrees (defaults to 20)
  • a: Area constraint - limits the maximum area of triangles

Timeout: The timeout parameter (in seconds) prevents the meshing process from running indefinitely if Triangle encounters complex geometries.

Example with area constraint

# Create a grid with maximum triangle area of 0.1
grid = TriangleModelGrid(
    exterior_y_and_x=(exterior_y, exterior_x),
    triangle_opts="pqa0.1Devjz"  # 'a0.1' sets max area to 0.1
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

landlab_triangle-0.0.2.tar.gz (44.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

landlab_triangle-0.0.2-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file landlab_triangle-0.0.2.tar.gz.

File metadata

  • Download URL: landlab_triangle-0.0.2.tar.gz
  • Upload date:
  • Size: 44.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for landlab_triangle-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ea8b7e65c0de00dc26e2ece1bbfde686b2d58d434538cef2fbf94ade16467b18
MD5 3eb18512ee3d7ade57053e32b1b915b8
BLAKE2b-256 4f9c1ab70bbcd2a378aa96ad75f4113decae9c9134169e6f80aa31e182f48437

See more details on using hashes here.

File details

Details for the file landlab_triangle-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for landlab_triangle-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e96e7062815e8aac3dfa37ffe19f77bcc9a314750478b88f48dacb3155ae4265
MD5 8e5662b421d7343b165d7e57e13d526d
BLAKE2b-256 3a9eef907d342ad4d7d61fbe483c6b9edff3aae59c2d2e1c8d89532dd0883a5e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page