meshBoundarySearch.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) 2011-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 "meshBoundarySearch.H"
27 #include "meshSearchBoundBox.H"
28 
29 /*---------------------------------------------------------------------------*\
30  Class meshBoundarySearch::findUniqueIntersectOp Declaration
31 \*---------------------------------------------------------------------------*/
32 
34 :
36 {
37 public:
38 
39  //- Reference to the boundary tree
41 
42  //- List of current hits
44 
45 
46 public:
47 
48  //- Construct from components
50  (
51  const indexedOctree<treeDataFace>& tree,
52  const List<pointIndexHit>& hits
53  )
54  :
56  tree_(tree),
57  hits_(hits)
58  {}
59 
60  //- Calculate intersection of triangle with ray. Sets result
61  // accordingly
62  bool operator()
63  (
64  const label index,
65  const point& start,
66  const point& end,
67  point& intersectionPoint
68  ) const
69  {
70  const primitiveMesh& mesh = tree_.shapes().mesh();
71 
72  // Check whether this hit has already happened. If the new face
73  // index is the same as an existing hit then return no new hit. If
74  // the new face shares a point with an existing hit face and the
75  // line passes through both faces in the same direction, then this
76  // is also assumed to be a duplicate hit.
77  const label newFacei = tree_.shapes().faceLabels()[index];
78  const face& newFace = mesh.faces()[newFacei];
79  const scalar newDot = mesh.faceAreas()[newFacei] & (end - start);
80  forAll(hits_, hiti)
81  {
82  const label oldFacei = hits_[hiti].index();
83  const face& oldFace = mesh.faces()[oldFacei];
84  const scalar oldDot =
85  mesh.faceAreas()[oldFacei] & (end - start);
86 
87  if
88  (
89  hits_[hiti].index() == newFacei
90  || (
91  newDot*oldDot > 0
92  && (labelHashSet(newFace) & labelHashSet(oldFace)).size()
93  )
94  )
95  {
96  return false;
97  }
98  }
99 
100  const bool hit =
101  treeDataFace::findIntersectOp::operator()
102  (
103  index,
104  start,
105  end,
106  intersectionPoint
107  );
108 
109  return hit;
110  }
111 };
112 
113 
114 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
115 
116 namespace Foam
117 {
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
123 
125 :
127  <
128  polyMesh,
131  >(mesh),
132  boundaryTree_
133  (
135  (
136  false,
137  mesh,
139  (
140  mesh.nInternalFaces(),
141  mesh.nFaces() - mesh.nInternalFaces()
142  )
143  ),
144  meshSearchBoundBox::New(mesh).bb(),
145  8,
146  10,
147  scalar(3)
148  )
149 {}
150 
151 
152 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
153 
155 {}
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
161 (
162  const point& p
163 ) const
164 {
165  pointIndexHit info =
166  boundaryTree().findNearest
167  (
168  p,
169  magSqr
170  (
171  boundaryTree().bb().max() - boundaryTree().bb().min()
172  )
173  );
174 
175  if (!info.hit())
176  {
177  info = boundaryTree().findNearest(p, sqr(great));
178  }
179 
180  return boundaryTree().shapes().faceLabels()[info.index()];
181 }
182 
183 
185 (
186  const point& pStart,
187  const point& pEnd
188 ) const
189 {
190  pointIndexHit curHit = boundaryTree().findLine(pStart, pEnd);
191 
192  if (curHit.hit())
193  {
194  // Change index into octreeData into face label
195  curHit.setIndex(boundaryTree().shapes().faceLabels()[curHit.index()]);
196  }
197 
198  return curHit;
199 }
200 
201 
203 (
204  const point& pStart,
205  const point& pEnd
206 ) const
207 {
209  pointIndexHit curHit;
210 
211  findUniqueIntersectOp iop(boundaryTree(), hits);
212 
213  while (true)
214  {
215  // Get the next hit, or quit
216  curHit = boundaryTree().findLine(pStart, pEnd, iop);
217  if (!curHit.hit()) break;
218 
219  // Change index into octreeData into face label
220  curHit.setIndex(boundaryTree().shapes().faceLabels()[curHit.index()]);
221 
222  hits.append(curHit);
223  }
224 
225  hits.shrink();
226 
227  return hits;
228 }
229 
230 
232 {
233  return boundaryTree().getVolumeType(p) == volumeType::inside;
234 }
235 
236 
237 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
MeshObject types:
Definition: MeshObjects.H:67
Templated abstract base-class for demand-driven mesh objects used to automate their allocation to the...
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
Definition: DynamicListI.H:252
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:54
label index() const
Return index.
bool hit() const
Is there a hit.
void setIndex(const label index)
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
Non-pointer based hierarchical recursive searching.
Definition: indexedOctree.H:72
const List< pointIndexHit > & hits_
List of current hits.
findUniqueIntersectOp(const indexedOctree< treeDataFace > &tree, const List< pointIndexHit > &hits)
Construct from components.
const indexedOctree< treeDataFace > & tree_
Reference to the boundary tree.
Mesh object that implements searches within the local boundary faces.
pointIndexHit intersection(const point &pStart, const point &pEnd) const
Find the first intersection of the boundary with the line.
label findNearestBoundaryFace(const point &p) const
Find the boundary face with centre closest to the given point.
bool isInside(const point &) const
Determine whether the given point is inside the mesh boundary.
List< pointIndexHit > intersections(const point &pStart, const point &pEnd) const
Find all intersections of the boundary with the line.
virtual ~meshBoundarySearch()
Destructor.
meshBoundarySearch(const polyMesh &mesh)
Construct from mesh.
Mesh object to hold a bound box for use by mesh search engines.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1315
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:75
const vectorField & faceAreas() const
findIntersectOp(const indexedOctree< treeDataFace > &tree)
Definition: treeDataFace.C:158
Encapsulation of data needed to search for faces.
Definition: treeDataFace.H:59
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
Namespace for OpenFOAM.
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
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
void sqr(LagrangianPatchField< typename outerProduct< Type, Type >::type > &f, const LagrangianPatchField< Type > &f1)
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:213
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
volScalarField & p