-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreference_element.py
More file actions
58 lines (43 loc) · 1.72 KB
/
reference_element.py
File metadata and controls
58 lines (43 loc) · 1.72 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
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
from dataclasses import dataclass
from typing import Callable
import numpy as np
import numpy.typing as npt
@dataclass
class ReferenceElement:
"""
This class describes the structure of the reference element with regard to the
shape functions and their gradient.
"""
n_dof_bubble: int = 4
n_dof_lin: int = 3
@property
def gradient_list(self) -> list[Callable[[float, float], npt.NDArray[np.float64]]]:
return [self.grad_phi_1, self.grad_phi_2, self.grad_phi_3, self.grad_phi_4]
@property
def linear_shape_func_list(self) -> list[Callable[[float, float], float]]:
return [self.phi_1, self.phi_2, self.phi_3]
@property
def bubble_shape_func_list(self) -> list[Callable[[float, float], float]]:
return [self.phi_1, self.phi_2, self.phi_3, self.phi_4]
def phi_1(self, x_1: float, x_2: float) -> float:
return 1 - x_1 - x_2
def phi_2(self, x_1: float, x_2: float) -> float:
return x_1
def phi_3(self, x_1: float, x_2: float) -> float:
return x_2
def phi_4(self, x_1: float, x_2: float) -> float:
return 27 * (1 - x_1 - x_2) * (x_1) * (x_2)
def grad_phi_1(self, x_1: float, x_2: float) -> npt.NDArray[np.float64]:
return np.array([-1, -1])
def grad_phi_2(self, x_1: float, x_2: float) -> npt.NDArray[np.float64]:
return np.array([1, 0])
def grad_phi_3(self, x_1: float, x_2: float) -> npt.NDArray[np.float64]:
return np.array([0, 1])
def grad_phi_4(self, x_1: float, x_2: float) -> npt.NDArray[np.float64]:
grad = np.array(
[
27 * (x_2 - 2 * x_1 * x_2 - x_2**2),
27 * (x_1 - x_1**2 - 2 * x_1 * x_2),
]
)
return grad