Normals are flipped in concave polygons
wmboon opened this issue · comments
Hi,
We tried to create a grid with a single, concave element in 2D and noticed that the normal is not oriented correctly.
Note that we would like all normals to be oriented outward (as specified in cell_faces) but it gets flipped if the cell center is not inside the polygon.
Our guess is that it should not be cell_center but a star-shaped point in the line:
porepy/src/porepy/grids/grid.py
Line 414 in 1533c7e
MWE:
import porepy as pp
import numpy as np
import scipy.sparse as sps
def test(alpha):
nodes = np.array([[0, 0.5, 1, 0.5], [0, alpha, 0, 1], np.zeros(4)])
indices = np.array([0, 1, 1, 2, 2, 3, 3, 0])
face_nodes = sps.csc_matrix((np.ones(8), indices, np.arange(0, 9, 2)))
cell_faces = sps.csc_matrix(np.ones((4, 1)))
sd = pp.Grid(2, nodes, face_nodes, cell_faces, "bug")
sd.compute_geometry()
print(sd.face_normals[:, :2])
test(0.25)
# correct
# [[ 0.25 -0.25]
# [-0.5 -0.5 ]
# [ 0. 0. ]]
test(0.5)
# incorrect
# [[-0.5 0.5]
# [ 0.5 0.5]
# [ 0. 0. ]]
That makes sense.
I am afraid I will not prioritize fixing this for the foreseeable future, but if you make a PR we will include it unless the change has unexpected side effects. If you make the PR, please include the tests as well.
I understand.
However, there are more problems with _compute_geometry_2d()
. In particular, for the example above with alpha = 0.5
:
- The cell centroid should be
[0.5, 0.5]
but PorePy returns[0.5, 31/72]
. - The cell area should be
0.25
but PorePy returns0.375
.
Both of these are computed before the face_normals are "flipped".
In 3D, we assume that the nodes in face_nodes are ordered in a specific (counter)clockwise way. Is there any information to the ordering of nodes in face_nodes in 2D? Without this information, I don't quite see an easy fix.