-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaffinemap.py
103 lines (89 loc) · 3.17 KB
/
affinemap.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from dataclasses import dataclass
from typing import Tuple
import numpy as np
import numpy.typing as npt
@dataclass
class AffineMap:
"""
This Class contains the whole structure of the affine map which maps from the reference element
to the physical element.
Attributes
----------
vertex_coords: npt.NDArray[np.float64]
Array containing the 3 vertices of the physical triangle.
Properties
----------
jacobian: npt.NDArray[np.float64]
2by2 matrix/ array representing the constant jacobian over the triangle
inverse_jacobian: npt.NDArray[np.float64]
2by2 matrix representing the inverse of the jacobian
determinant_jacobian: float
Float value representing the determinant of the Jacobian for the specific
triangle.
Methods
-------
a_map
Actual affine map, that takes coordinates from the reference space and returns
the corresponding coordinates in the physical space.
"""
vertex_coords: npt.NDArray[np.float64]
@property
def jacobian(self) -> npt.NDArray[np.float64]:
"""
2by2 matrix/ array representing the constant jacobian over the triangle
"""
jacobian = np.array( # type: ignore
[
[
self.vertex_coords[1][0] - self.vertex_coords[0][0],
self.vertex_coords[2][0] - self.vertex_coords[0][0],
],
[
self.vertex_coords[1][1] - self.vertex_coords[0][1],
self.vertex_coords[2][1] - self.vertex_coords[0][1],
],
]
)
return jacobian # type: ignore
@property
def inverse_jacobian(self) -> npt.NDArray[np.float64]:
"""
2by2 matrix representing the inverse of the jacobian
"""
return np.linalg.inv(self.jacobian)
@property
def determinant_jacobian(self) -> float:
"""
Float value representing the determinant of the Jacobian for the specific
triangle.
"""
return (
self.jacobian[0][0] * self.jacobian[1][1]
- self.jacobian[0][1] * self.jacobian[1][0]
)
def aff_map(self, x1_hat: float, x2_hat: float) -> Tuple[float, float]:
"""
Actual affine map, that takes coordinates from the reference space and returns
the corresponding coordinates in the physical space.
Parameters
----------
x1_hat: float
x_1 coordinate in the reference space
x2_hat: float
x_2 coordinate in the reference space
Returns
-------
Tuple[float,float]
Tuple representing the x_1 and x_2 coordinate in the physical space.
"""
x_1 = (
self.vertex_coords[0][0]
+ (self.vertex_coords[1][0] - self.vertex_coords[0][0]) * x1_hat
+ (self.vertex_coords[2][0] - self.vertex_coords[0][0]) * x2_hat
)
x_2 = (
self.vertex_coords[0][1]
+ (self.vertex_coords[1][1] - self.vertex_coords[0][1]) * x1_hat
+ (self.vertex_coords[2][1] - self.vertex_coords[0][1]) * x2_hat
)
return x_1, x_2