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

trimesh.BoundaryTypes

alias of Enum

trimesh.EdgeTypes

alias of Enum

class trimesh.TriMesh

Bases: object

Class that holds a triangular mesh information

Methods

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_edgecenters()

Build centers of sides

Returns :

numpy.array :

list of side centers

build_edges_from_elems()

This is a function copied and modified from TriGrid

deepcopy(mesh)

Deep copy mesh information.

edges

Array of edges

Getter :Get the array of the edges.
Type :Numpy integer array
element2edges(elem_i)

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

elems

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_elem(pos)

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_nodes_in_box(box)

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_edges_from_node(node_i)

Get edge indices related to node_i

get_elems_i_from_node(node_i)
get_neighbor_nodes(node_i)

Get neighboring node indices from the given node index.

is_elem_on_boundary(elem_i)

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

n_edges()

Get the total number of edges.

n_elems()

Get the total nuber of elems.

n_nodes()

Get the total number of nodes.

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)

trim_to_left(paths)

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

trimesh.enum(**enums)

A enum type definition. Copied from http://stackoverflow.com/questions/36932/how-can-i-represent-an-enum-in-python