trackedParticle.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 "trackedParticle.H"
27 
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 (
33  const meshSearch& searchEngine,
34  const vector& position,
35  const label celli,
36  label& nLocateBoundaryHits,
37  const point& end,
38  const label level,
39  const label i,
40  const label j,
41  const label k
42 )
43 :
44  particle(searchEngine, position, celli, nLocateBoundaryHits),
45  start_(position),
46  end_(end),
47  fraction_(1),
48  level_(level),
49  i_(i),
50  j_(j),
51  k_(k)
52 {}
53 
54 
56 :
57  particle(is, readFields)
58 {
59  if (readFields)
60  {
61  if (is.format() == IOstream::ASCII)
62  {
63  is >> start_ >> end_ >> fraction_;
64  level_ = readLabel(is);
65  i_ = readLabel(is);
66  j_ = readLabel(is);
67  k_ = readLabel(is);
68  }
69  else
70  {
71  is.read
72  (
73  reinterpret_cast<char*>(&start_),
74  sizeof(start_) + sizeof(end_) + sizeof(fraction_)
75  + sizeof(level_) + sizeof(i_) + sizeof(j_) + sizeof(k_)
76  );
77  }
78  }
79 
80  // Check state of Istream
81  is.check
82  (
83  "trackedParticle::trackedParticle"
84  "(const Cloud<trackedParticle>&, Istream&, bool)"
85  );
86 }
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
92 (
94  trackingData& td
95 )
96 {
97  td.keepParticle = true;
98  td.sendToProc = -1;
99 
100  while (td.keepParticle && td.sendToProc == -1)
101  {
102  // mark visited cell with max level
103  td.maxLevel_[cell()] = max(td.maxLevel_[cell()], level_);
104 
105  const vector displacement = fraction_*(end_ - start_);
106 
107  fraction_ *= trackToFace(td.mesh, displacement, 0);
108 
109  if (!onFace()) break;
110 
111  hitFace(displacement, 0, cloud, td);
112  }
113 
114  return td.keepParticle;
115 }
116 
117 
119 (
121  trackingData& td
122 )
123 {
124  // Remove particle
125  td.keepParticle = false;
126 }
127 
128 
130 (
132  trackingData& td
133 )
134 {
135  // Remove particle
136  td.keepParticle = false;
137 }
138 
139 
141 (
143  trackingData& td
144 )
145 {
146  // Remove particle
147  td.keepParticle = false;
148 }
149 
150 
152 (
154  trackingData& td
155 )
156 {
157  // Remove particle
158  td.keepParticle = false;
159 }
160 
161 
163 (
165  trackingData& td
166 )
167 {
168  // Remove particle
169  td.keepParticle = false;
170 }
171 
172 
174 (
176  trackingData& td
177 )
178 {
180 
181  // Mark edge we are currently on (if any). This was set on the sending
182  // processor but has not yet been set on the receiving side.
183  const label feati = i(), edgei = k();
184  if (edgei != -1)
185  {
186  td.featureEdgeVisited_[feati].set(edgei, 1u);
187  }
188 }
189 
190 
191 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
192 
194 {
195  if (os.format() == IOstream::ASCII)
196  {
197  os << static_cast<const particle&>(p)
198  << token::SPACE << p.start_
199  << token::SPACE << p.end_
200  << token::SPACE << p.fraction_
201  << token::SPACE << p.level_
202  << token::SPACE << p.i_
203  << token::SPACE << p.j_
204  << token::SPACE << p.k_;
205  }
206  else
207  {
208  os << static_cast<const particle&>(p);
209  os.write
210  (
211  reinterpret_cast<const char*>(&p.start_),
212  sizeof(p.start_) + sizeof(p.end_) + sizeof(p.fraction_)
213  + sizeof(p.level_) + sizeof(p.i_) + sizeof(p.j_) + sizeof(p.k_)
214  );
215  }
216 
217  // Check state of Ostream
218  os.check("Ostream& operator<<(Ostream&, const trackedParticle&)");
219 
220  return os;
221 }
222 
223 
224 // ************************************************************************* //
label k
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:108
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
virtual Istream & read(token &)=0
Return next token from stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
virtual Ostream & write(const token &)
Write token.
Definition: Ostream.C:51
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:60
Base class for clouds. Provides a basic evolution algorithm, models, and a database for caching deriv...
Definition: cloud.H:61
Mesh object that implements searches within the local cells and faces.
Definition: meshSearch.H:59
label sendToProc
Processor to send the particle to. -1 indicates that this.
Definition: particle.H:111
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:107
const polyMesh & mesh
Reference to the mesh.
Definition: particle.H:104
Base particle class.
Definition: particle.H:85
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
void correctAfterParallelTransfer(TrackCloudType &, trackingData &)
Make changes following a parallel transfer. Runs either.
Class used to pass tracking data to the trackToFace function.
List< PackedBoolList > & featureEdgeVisited_
Particle class that marks cells it passes through. Used to mark cells visited by feature edges.
void hitCyclicPatch(lagrangian::Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
void correctAfterParallelTransfer(lagrangian::Cloud< trackedParticle > &, trackingData &)
Do corrections to the particle and tracking data following a.
void hitWallPatch(lagrangian::Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wallPatch.
void hitSymmetryPatch(lagrangian::Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
void hitWedgePatch(lagrangian::Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wedge.
trackedParticle(const meshSearch &searchEngine, const vector &position, const label celli, label &nLocateBoundaryHits, const point &end, const label level, const label i, const label j, const label k)
Construct from a position and a cell, searching for the rest of the.
void hitSymmetryPlanePatch(lagrangian::Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
bool move(lagrangian::Cloud< trackedParticle > &, trackingData &)
Track all particles to their end point.
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
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
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const HashSet< word > &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the specified type.
Definition: ReadFields.C:244
label readLabel(Istream &is)
Definition: label.H:64
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
volScalarField & p