tracking.H
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) 2024-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 Namespace
25  Foam::tracking
26 
27 Description
28  Functions for tracking locations through a mesh
29 
30 SourceFiles
31  tracking.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef tracking_H
36 #define tracking_H
37 
38 #include "polyMesh.H"
39 #include "barycentric.H"
40 #include "barycentricTensor.H"
41 #include "vector.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 class meshSearch;
49 class wedgePolyPatch;
50 class cyclicPolyPatch;
51 class processorPolyPatch;
52 
53 namespace tracking
54 {
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 // Geometry
59 
60  //- Return the position given the coordinates and tet topology
61  inline point position
62  (
63  const polyMesh& mesh,
64  const barycentric& coordinates,
65  const label celli,
66  const label facei,
67  const label faceTrii,
68  const scalar stepFraction
69  );
70 
71  //- Return the coordinates given the position and tet topology
73  (
74  const polyMesh& mesh,
75  const point& position,
76  const label celli,
77  const label facei,
78  const label faceTrii,
79  const scalar stepFraction
80  );
81 
82  //- Return the normal of the corresponding point on the associated face and
83  // the displacement of that point over the time-step
84  Pair<vector> faceNormalAndDisplacement
85  (
86  const polyMesh& mesh,
87  const barycentric& coordinates,
88  const label celli,
89  const label facei,
90  const label faceTrii,
91  const scalar stepFraction
92  );
93 
94 
95 // Tracking
96 
97  //- Track along the displacement for a given fraction of the overall
98  // time-step. End when the track is complete or when a face is hit. Return
99  // whether or not a face was hit (true) or the track completed (false) and
100  // the proportion of the displacement still to be completed. Displacement
101  // can be a single vector, d, in which case the path is linear and equal
102  // to x0 + lambda*d, where x0 is the starting position and lambda is the
103  // local coordinate along the path. Or, displacement can be a pair of
104  // vectors, d1 and d2, in which case the path is parabolic and equal to
105  // x0 + lambda*d1 + lambda*lambda*d2.
106  template<class Displacement>
108  (
109  const polyMesh& mesh,
110  const Displacement& displacement,
111  const scalar fraction,
113  label& celli,
114  label& facei,
115  label& faceTrii,
116  scalar& stepFraction,
117  scalar& stepFractionBehind,
118  label& nTracksBehind,
119  const string& debugPrefix = NullObjectRef<string>()
120  );
121 
122  //- As toFace, except that if the track ends on an internal face then this
123  // face will be crossed
124  template<class Displacement>
126  (
127  const polyMesh& mesh,
128  const Displacement& displacement,
129  const scalar fraction,
131  label& celli,
132  label& facei,
133  label& faceTrii,
134  scalar& stepFraction,
135  scalar& stepFractionBehind,
136  label& nTracksBehind,
137  const string& debugPrefix = NullObjectRef<string>()
138  );
139 
140  //- As toFace, except that the track continues across multiple cells until
141  // it ends or until a boundary face is hit
142  template<class Displacement>
144  (
145  const polyMesh& mesh,
146  const Displacement& displacement,
147  const scalar fraction,
149  label& celli,
150  label& facei,
151  label& faceTrii,
152  scalar& stepFraction,
153  scalar& stepFractionBehind,
154  label& nTracksBehind,
155  const string& debugPrefix = NullObjectRef<string>()
156  );
157 
158 
159 // Initialisation
160 
161  //- Initialise the location at the given position. Returns whether or not a
162  // boundary was hit. The cell index must be valid.
163  bool locate
164  (
165  const polyMesh& mesh,
166  const point& position,
168  label& celli,
169  label& facei,
170  label& faceTrii,
171  const scalar stepFraction,
172  const string& debugPrefix = NullObjectRef<string>()
173  );
174 
175  //- Initialise the location at the given position. Returns whether or not a
176  // boundary was hit. The cell index may be invalid, in which case a tree
177  // search is performed to find the cell containing the position.
178  bool locate
179  (
180  const meshSearch& searchEngine,
181  const point& position,
183  label& celli,
184  label& facei,
185  label& faceTrii,
186  const scalar stepFraction,
187  const string& debugPrefix = NullObjectRef<string>()
188  );
189 
190 
191 // Topology Changes
192 
193  //- Cross an internal face
194  void crossInternalFace
195  (
196  const polyMesh& mesh,
198  label& celli,
199  label& facei,
200  label& faceTrii
201  );
202 
203  //- Cross a wedge patch
204  void crossWedge
205  (
206  const wedgePolyPatch& inPatch,
208  label& celli,
209  label& facei,
210  label& faceTrii,
211  const scalar stepFraction
212  );
213 
214  //- Cross a cyclic patch
215  void crossCyclic
216  (
217  const cyclicPolyPatch& inPatch,
219  label& celli,
220  label& facei,
221  label& faceTrii
222  );
223 
224  //- Initialise crossing of a processor patch. Breaks the topology in order
225  // to store the destination patch face in advance of communication.
226  void inProcessor
227  (
228  const processorPolyPatch& inPatch,
229  label& celli,
230  label& facei
231  );
232 
233  //- Complete crossing of a processor patch. Restore the topology.
234  void outProcessor
235  (
236  const processorPolyPatch& outPatch,
238  label& celli,
239  label& facei,
240  label& faceTrii
241  );
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 } // End namespace tracking
246 } // End namespace Foam
247 
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 
250 #include "trackingI.H"
251 
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 
254 #endif
255 
256 // ************************************************************************* //
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:66
Cyclic plane patch.
Mesh object that implements searches within the local cells and faces.
Definition: meshSearch.H:59
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
Neighbour processor patch.
Wedge front and back plane patch.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
barycentric coordinates(const polyMesh &mesh, const point &position, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the coordinates given the position and tet topology.
Definition: tracking.C:1258
Tuple2< bool, scalar > toCell(const polyMesh &mesh, const Displacement &displacement, const scalar fraction, barycentric &coordinates, label &celli, label &facei, label &faceTrii, scalar &stepFraction, scalar &stepFractionBehind, label &nTracksBehind, const string &debugPrefix=NullObjectRef< string >())
As toFace, except that if the track ends on an internal face then this.
Pair< vector > faceNormalAndDisplacement(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the normal of the corresponding point on the associated face and.
Definition: tracking.C:1301
Tuple2< bool, scalar > toBoundary(const polyMesh &mesh, const Displacement &displacement, const scalar fraction, barycentric &coordinates, label &celli, label &facei, label &faceTrii, scalar &stepFraction, scalar &stepFractionBehind, label &nTracksBehind, const string &debugPrefix=NullObjectRef< string >())
As toFace, except that the track continues across multiple cells until.
void crossInternalFace(const polyMesh &mesh, barycentric &coordinates, label &celli, label &facei, label &faceTrii)
Cross an internal face.
Definition: tracking.C:1709
void crossCyclic(const cyclicPolyPatch &inPatch, barycentric &coordinates, label &celli, label &facei, label &faceTrii)
Cross a cyclic patch.
Definition: tracking.C:1764
void outProcessor(const processorPolyPatch &outPatch, barycentric &coordinates, label &celli, label &facei, label &faceTrii)
Complete crossing of a processor patch. Restore the topology.
Definition: tracking.C:1805
void inProcessor(const processorPolyPatch &inPatch, label &celli, label &facei)
Initialise crossing of a processor patch. Breaks the topology in order.
Definition: tracking.C:1790
void crossWedge(const wedgePolyPatch &inPatch, barycentric &coordinates, label &celli, label &facei, label &faceTrii, const scalar stepFraction)
Cross a wedge patch.
Definition: tracking.C:1728
point position(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the position given the coordinates and tet topology.
Definition: trackingI.H:224
Tuple2< bool, scalar > toFace(const polyMesh &mesh, const Displacement &displacement, const scalar fraction, barycentric &coordinates, label &celli, label &facei, label &faceTrii, scalar &stepFraction, scalar &stepFractionBehind, label &nTracksBehind, const string &debugPrefix=NullObjectRef< string >())
Track along the displacement for a given fraction of the overall.
bool locate(const polyMesh &mesh, const point &position, barycentric &coordinates, label &celli, label &facei, label &faceTrii, const scalar stepFraction, const string &debugPrefix=NullObjectRef< string >())
Initialise the location at the given position. Returns whether or not a.
Definition: tracking.C:1592
const unitSet fraction
Namespace for OpenFOAM.
Barycentric< scalar > barycentric
A scalar version of the templated Barycentric.
Definition: barycentric.H:45
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
vector point
Point is a vector.
Definition: point.H:41