DNDSR 0.2.1
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
ElemInterpolate.py
Go to the documentation of this file.
1from DNDSR import DNDS, Geom
2import numpy as np
3import numba
4
5
6def elem_get_interpolation_base(type: Geom.Elem.ElemType, coords: np.ndarray, xq):
7 """
8 Note:
9 xq must be internal
10 """
11 if type in [Geom.Elem.ElemType.Tri3, Geom.Elem.ElemType.Quad4]:
12 nv = 3 if type == Geom.Elem.ElemType.Tri3 else 4
13
14 xRel = coords.T - xq
15 areas = np.zeros(nv)
16 for i in range(nv):
17 areas[i] = np.linalg.norm(np.cross(xRel[i], xRel[(i + 1) % nv]))
18 if type == Geom.Elem.ElemType.Tri3:
19 # area = [A2, A0, A1]
20 return np.roll(areas, -1) / areas.sum()
21 if type == Geom.Elem.ElemType.Quad4:
22 vxi = areas[3] / (areas[1] + areas[3])
23 vet = areas[0] / (areas[0] + areas[2])
24 return np.array(
25 [(1 - vxi) * (1 - vet), vxi * (1 - vet), vxi * vet, (1 - vxi) * vet]
26 )
27 else:
28 raise ValueError(f"type not supported: {type}")
29
30
31if __name__ == "__main__":
32 coords = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], dtype=np.float64).T
33 print(
34 elem_get_interpolation_base(
35 Geom.Elem.ElemType.Tri3, coords, np.array([0.1, 0.1, 0])
36 )
37 )
38 print(
39 elem_get_interpolation_base(
40 Geom.Elem.ElemType.Quad4, coords, np.array([0.1, 0.1, 0])
41 )
42 )