-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmesh_triangle.py
More file actions
31 lines (23 loc) · 1.12 KB
/
mesh_triangle.py
File metadata and controls
31 lines (23 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import Sequence
from elementary_matrix import compute_elementary_matrix
class MeshTriangle:
__slots__ = ("vertices", "hx", "hy", "elementary_matrix")
def __init__(self, v1: Sequence, v2: Sequence, v3: Sequence, hx, hy) -> None:
self.vertices = {v1: 0, v2: 1, v3: 2} # local numbering
# elementary assembly matrix associated with the triangle
self.elementary_matrix = compute_elementary_matrix(v1, v2, v3, hx, hy)
def __repr__(self) -> str:
string = f"MeshTriangle["
for ii, vi in enumerate(self.vertices.keys()):
string += f"v{ii}={vi}"
string += "]"
return string
def is_in(self, v: Sequence) -> bool:
# check if the point v is a point defining the triangle
return v in self.vertices
def get_local_num(self, v: Sequence) -> int:
# retrieves the local number
return self.vertices[v]
def get_matrix_entry(self, v1: Sequence, v2: Sequence):
# retrieves the input associated with points v1 (row) and v2 (column)
return self.elementary_matrix[self.get_local_num(v1)][self.get_local_num(v2)]