primitiveMesh::pointInCell(const point& p, label celli) may fail on non-convex cells
Summary
Steps to reproduce
The function primitiveMesh::pointInCell(const point& p, label celli) may fail on non-convex cells i.e. if p is inside the cell, this function may return false if the cell is non-convex.
I understand that OpenFOAM expects convex cells but there are cases where slightly convex cells can be used without introducing significant errors.
Example case
Consider a mesh with one non-convex hexahedral cell, and the coordinates (given in blockMesh compatible ordering): (0 0 0) (1 0 0) (0.2 0.2 0) (0 1 0) (0 0 1) (1 0 1) (0.2 0.2 1) (0 1 1)
The point (0.3 0.1 0.5) is within the cell, but pointInCell will return false.
What is the current bug behaviour?
Valid points are incorrectly characterised as outside the cell.
What is the expected correct behavior?
Valid points should be correctly characterised as inside the cell.
Relevant logs and/or images
N/A
Environment information
- OpenFOAM version : ALL
- Operating system : N/A
- Hardware info : N/A
- Compiler : N/A
Possible fixes
I can think of at least two fixes:
-
Print a warning if there are non-convex cells letting the user know that this function may fail
-
Create a pointInNonConvexCell function, for example, using an algorithm like the one described here https://stackoverflow.com/questions/44513525/testing-whether-a-3d-point-is-inside-a-3d-polyhedron
I have implemented 2 in pointInNonConvexCell.C and it works on the test cases I have tried.