particleI.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) 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 "particle.H"
27 #include "tracking.H"
28 #include "polyMesh.H"
29 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 
34 {
35  const label id = particleCount ++;
36 
37  if (id == labelMax)
38  {
40  << "Particle counter has overflowed. This might cause problems"
41  << " when reconstructing particle tracks." << endl;
42  }
43 
44  return id;
45 }
46 
47 
49 {
50  return coordinates_;
51 }
52 
53 
55 {
56  return celli_;
57 }
58 
59 
61 {
62  return tetFacei_;
63 }
64 
65 
67 {
68  return tetPti_;
69 }
70 
71 
73 {
74  return facei_;
75 }
76 
77 
79 {
80  return facei_;
81 }
82 
83 
84 inline Foam::scalar Foam::particle::stepFraction() const
85 {
86  return stepFraction_;
87 }
88 
89 
90 inline Foam::scalar& Foam::particle::stepFraction()
91 {
92  return stepFraction_;
93 }
94 
95 
97 {
98  return origProc_;
99 }
100 
101 
103 {
104  return origProc_;
105 }
106 
107 
109 {
110  return origId_;
111 }
112 
113 
115 {
116  return origId_;
117 }
118 
119 
121 (
122  const polyMesh& mesh
123 ) const
124 {
125  return tetIndices(celli_, tetFacei_, tetPti_);
126 }
127 
128 
130 {
131  return currentTetIndices(mesh).faceTri(mesh).normal();
132 }
133 
134 
135 inline bool Foam::particle::onFace() const
136 {
137  return facei_ >= 0;
138 }
139 
140 
142 {
143  return onFace() && mesh.isInternalFace(facei_);
144 }
145 
146 
148 {
149  return onFace() && !mesh.isInternalFace(facei_);
150 }
151 
152 
154 {
155  return onFace() ? mesh.boundaryMesh().whichPatch(facei_) : -1;
156 }
157 
158 
160 {
161  return
163  (
164  mesh,
165  coordinates_,
166  celli_,
167  tetFacei_,
168  tetPti_,
169  stepFraction_
170  );
171 }
172 
173 
174 inline void Foam::particle::reset(const scalar stepFraction)
175 {
176  stepFraction_ = stepFraction;
177  stepFractionBehind_ = 0;
178  nTracksBehind_ = 0;
179 }
180 
181 
183 (
184  const polyMesh& mesh,
185  vector& normal,
186  vector& displacement
187 ) const
188 {
189  if (!onBoundaryFace(mesh))
190  {
192  << "Patch data was requested for a particle that isn't on a patch"
193  << exit(FatalError);
194  }
195 
196  const Pair<vector> normalAndDisplacement =
198  (
199  mesh,
200  coordinates_,
201  celli_,
202  tetFacei_,
203  tetPti_,
204  stepFraction_
205  );
206 
207  normal = normalAndDisplacement.first();
208  displacement = normalAndDisplacement.second();
209 }
210 
211 
212 // ************************************************************************* //
An ordered pair of two objects of type <Type> with first() and second() elements.
Definition: Pair.H:66
const Type & second() const
Return second.
Definition: PairI.H:121
const Type & first() const
Return first.
Definition: PairI.H:107
label face() const
Return current face particle is on otherwise -1.
Definition: particleI.H:72
vector normal(const polyMesh &mesh) const
Return the normal of the tri on tetFacei_ for the.
Definition: particleI.H:129
label tetPt() const
Return current tet face particle is in.
Definition: particleI.H:66
label origProc() const
Return the originating processor ID.
Definition: particleI.H:96
const barycentric & coordinates() const
Return current particle coordinates.
Definition: particleI.H:48
label cell() const
Return current cell particle is in.
Definition: particleI.H:54
void reset(const scalar stepFraction)
Set the step fraction and clear the behind data in preparation.
Definition: particleI.H:174
label patch(const polyMesh &mesh) const
Return the index of patch that the particle is on.
Definition: particleI.H:153
scalar stepFraction() const
Return the fraction of time-step completed.
Definition: particleI.H:84
bool onFace() const
Is the particle on a face?
Definition: particleI.H:135
void patchData(const polyMesh &mesh, vector &normal, vector &displacement) const
Get the normal and displacement of the current patch location.
Definition: particleI.H:183
bool onBoundaryFace(const polyMesh &mesh) const
Is the particle on a boundary face?
Definition: particleI.H:147
tetIndices currentTetIndices(const polyMesh &mesh) const
Return the indices of the current tet that the.
Definition: particleI.H:121
bool onInternalFace(const polyMesh &mesh) const
Is the particle on an internal face?
Definition: particleI.H:141
vector position(const polyMesh &mesh) const
Return current particle position.
Definition: particleI.H:159
label getNewParticleIndex() const
Get unique particle creation id.
Definition: particleI.H:33
label origId() const
Return the particle ID on the originating processor.
Definition: particleI.H:108
static label particleCount
Cumulative particle counter - used to provide unique ID.
Definition: particle.H:203
label tetFace() const
Return current tet face particle is in.
Definition: particleI.H:60
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:401
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Definition: tetIndices.H:82
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define WarningInFunction
Report a warning using Foam::Warning.
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:1302
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
error FatalError
static const label labelMax
Definition: label.H:62