Bay-Delta SELFE Tools

trimesh Module

This is a class to hold an unstructured triangular mesh.

Lots of the codes are copied from Rusty Chris Collerman’s trigrid program and modified a bit to meet our needs.

Prerequisite: Numpy, rtree package, and libspatialindex for rtree


alias of Enum


alias of Enum

class trimesh.TriMesh

Bases: object

Class that holds a triangular mesh information


add_boundary(nodes, btype)

Add boundary types to an edge with the given array of node indices

allocate(n_elems, n_nodes)

Allocate memory for nodes and elems

Parameters :

n_elems: integer :

Total number of elems

n_nodes: integer :

Total number of nodes


Build centers of sides

Returns :

numpy.array :

list of side centers


This is a function copied and modified from TriGrid


Deep copy mesh information.


Array of edges

Getter :Get the array of the edges.
Type :Numpy integer array

Get edge indices from the give element index elem_i = the element index return = generator of found edge indices


Array of node indices of each element. The shape of the array is (# of elems, 3). It is assumed that all elems are triangular.

Getter :Get the Numpy array of the node indices.
Type :Numpy integer array
find_closest_elems(pos, count=1)

Find indices of the closet elems with the given position. The distance is measured with the element mass center. All triangular elems is assumed. pos = position tuple return = element indices

find_closest_nodes(pos, count=1, boundary=False)

Returns the count closest nodes to the given node in 2D space. pos = position count = # of nodes to retrieve boundary=1: only choose nodes on the boundary. Copied from TriGrid


Find a element index from a coordinate pos = A coordinate (2D) return = element index

find_elem_with_tolerance(pos, tolerance)

Find a element index from a coordinate with some tolerance pos = A coordinate (2D) return = element index


Find nodse in a bounding box box = a numpy array of bounding box, [x_min, x_max, y_min, y_max] return = node indices


Get edge indices related to node_i


Get neighboring node indices from the given node index.


Check if the given element with index elem_i is on the boundary elem_i = element index return = True if the element is on the boundary, otherwise False


Get the total number of edges.


Get the total nuber of elems.


Get the total number of nodes.


Node array consisting of three-dimensional coordinates of each node. The shape of the array is (# of nodes, 3)

Getter :Get the array of the nodes.
Type :Numpy float array.
set_elem(index, connectivities)

Set element connectivity information. Memory for elems must be allocated already.

Parameters :

index: integer :

Zero-based element index

connectivities: Numpy array :

a Numpy array of element connectivity, which means node indies in the element.

set_node(index, coords)

Set one node information. Memory for nodes must be allocated already.

Parameters :

index: integer :

Zero-based node index

coords: Numpy array :

a Numpy array of node coordinates

shortest_path(n1, n2, boundary_only=False)

dijkstra on the edge graph from n1 to n2. copied and modified form Rusty’s code. n1 = node_i for one end of the path n2 = node_i for the other end boundary_only = limit search to edges on the boundary (have a -1 for element2)


Given a path, trim all elems to the left of it. This fuction is lifted and modified slightly from Rusty’s code.


A enum type definition. Copied from