Skip to content

Commit 037a2b1

Browse files
mursalfkndem0
authored andcommitted
Tried fixing the error on the shape
Tried fixing the error on the shape while working for the PyDMD simulations.
1 parent 183bc95 commit 037a2b1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

smithers/io/openfoam/openfoamhandler.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@ def _normal(cls, points):
3333
# first_index = 0
3434
# while first_index + 3 <= points.shape[0]:
3535
# print(first_index, points.shape[0])
36-
37-
for idx in range(points.shape[0] - 3):
38-
triangle = points[idx+1:idx+3] - points[idx]
39-
40-
n = np.cross(triangle[0], triangle[1])
41-
if normal is None:
42-
normal = n
43-
else:
44-
normal += n if np.dot(normal, n) > 0 else -n
36+
37+
if points.shape[0] == 3:
38+
triangle = points[1:3] - points[0]
39+
normal = np.cross(triangle[0], triangle[1])
40+
else:
41+
for idx in range(points.shape[0] - 3):
42+
triangle = points[idx+1:idx+3] - points[idx]
43+
44+
n = np.cross(triangle[0], triangle[1])
45+
if normal is None:
46+
normal = n
47+
else:
48+
normal += n if np.dot(normal, n) > 0 else -n
4549

4650
return np.divide(normal, np.linalg.norm(normal))
4751

0 commit comments

Comments
 (0)