pointInCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "pointInCell.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
32 (
33  const point& p,
34  const polyMesh& mesh,
35  const label celli
36 )
37 {
38  const labelList& cFaces = mesh.cells()[celli];
39 
40  forAll(cFaces, cFacei)
41  {
42  const label facei = cFaces[cFacei];
43  const bool isOwn = mesh.faceOwner()[facei] == celli;
44 
45  const vector normal =
46  isOwn ? mesh.faceAreas()[facei] : - mesh.faceAreas()[facei];
47 
48  const vector proj = p - mesh.faceCentres()[facei];
49 
50  if ((normal & proj) > 0)
51  {
52  return false;
53  }
54  }
55 
56  return true;
57 }
58 
59 
61 (
62  const point& p,
63  const polyMesh& mesh,
64  const label celli
65 )
66 {
67  const cell& cFaces = mesh.cells()[celli];
68 
69  forAll(cFaces, cFacei)
70  {
71  const label facei = cFaces[cFacei];
72  const face& f = mesh.faces()[facei];
73  const point& fCentre = mesh.faceCentres()[facei];
74  const bool isOwn = mesh.faceOwner()[facei] == celli;
75 
76  forAll(f, fPointi)
77  {
78  label pointi;
79  label nextPointi;
80  if (isOwn)
81  {
82  pointi = f[fPointi];
83  nextPointi = f.nextLabel(fPointi);
84  }
85  else
86  {
87  pointi = f.nextLabel(fPointi);
88  nextPointi = f[fPointi];
89  }
90 
91  const triPointRef faceTri
92  (
93  mesh.points()[pointi],
94  mesh.points()[nextPointi],
95  fCentre
96  );
97 
98  const vector proj = p - faceTri.centre();
99 
100  if ((faceTri.area() & proj) > 0)
101  {
102  return false;
103  }
104  }
105  }
106 
107  return true;
108 }
109 
110 
112 (
113  const point& p,
114  const polyMesh& mesh,
115  const label celli
116 )
117 {
118  const cell& cFaces = mesh.cells()[celli];
119 
120  forAll(cFaces, cFacei)
121  {
122  const label facei = cFaces[cFacei];
123  const face& f = mesh.faces()[facei];
124 
125  for (label tetPti = 1; tetPti < f.size() - 1; tetPti++)
126  {
127  const triPointRef faceTri =
128  tetIndices(celli, facei, tetPti).faceTri(mesh);
129 
130  const vector proj = p - faceTri.centre();
131 
132  if ((faceTri.area() & proj) > 0)
133  {
134  return false;
135  }
136  }
137  }
138 
139  return true;
140 }
141 
142 
144 (
145  const point& p,
146  const polyMesh& mesh,
147  const label celli
148 )
149 {
150  return polyMeshTetDecomposition::findTet(mesh, celli, p).face() != -1;
151 }
152 
153 
155 (
156  const point& p,
157  const polyMesh& mesh,
158  const label celli,
160 )
161 {
162  switch (cellShapes)
163  {
164  case pointInCellShapes::facePlanes:
165  return pointInCellFacePlanes(p, mesh, celli);
166  case pointInCellShapes::faceCentreTris:
167  return pointInCellFaceCentreTris(p, mesh, celli);
168  case pointInCellShapes::faceDiagonalTris:
169  return pointInCellFaceDiagTris(p, mesh, celli);
170  case pointInCellShapes::tets:
171  return pointInCellTets(p, mesh, celli);
172  }
173 
174  return false;
175 
176 }
177 
178 
179 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:60
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1308
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1321
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1295
const vectorField & faceCentres() const
const vectorField & faceAreas() const
const cellList & cells() const
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Definition: tetIndices.H:82
triPointRef faceTri(const polyMesh &mesh, const pointField &meshPoints) const
Return the geometry corresponding to the tri on the face for.
Definition: tetIndicesI.H:134
A triangle primitive used to calculate face areas and swept volumes.
Definition: triangle.H:80
vector area() const
Return vector area.
Definition: triangleI.H:96
Point centre() const
Return centre (centroid)
Definition: triangleI.H:89
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
const cellShapeList & cellShapes
bool pointInCellFaceDiagTris(const point &p, const polyMesh &mesh, const label celli)
Test if a point is in a given cell. For each of the cell's faces,.
Definition: pointInCell.C:112
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
pointInCellShapes
Enumeration for the sub-shapes used to perform the inside calculation.
Definition: pointInCell.H:52
bool pointInCellFaceCentreTris(const point &p, const polyMesh &mesh, const label celli)
Test if a point is in a given cell. For each of the cell's faces,.
Definition: pointInCell.C:61
bool pointInCellTets(const point &p, const polyMesh &mesh, const label celli)
Test if a point is in a given cell by decomposing the cell into tetrahedra.
Definition: pointInCell.C:144
bool pointInCellFacePlanes(const point &p, const polyMesh &mesh, const label celli)
Test if a point is in a given cell. For each of the cell's faces, define a.
Definition: pointInCell.C:32
bool pointInCell(const point &p, const polyMesh &mesh, const label celli, const pointInCellShapes=pointInCellShapes::tets)
Test if a point is in a given cell.
Definition: pointInCell.C:155
Function for determining if a point is within a cell of a polyMesh.
labelList f(nPoints)
volScalarField & p