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-2022 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 polyMesh& mesh,
34  const barycentric& coordinates,
35  const label celli,
36  const label tetFacei,
37  const label tetPtI,
38  const point& end,
39  const label level,
40  const label i,
41  const label j,
42  const label k
43 )
44 :
45  particle(mesh, coordinates, celli, tetFacei, tetPtI),
46  start_(position()),
47  end_(end),
48  level_(level),
49  i_(i),
50  j_(j),
51  k_(k)
52 {}
53 
54 
56 (
57  const polyMesh& mesh,
58  const vector& position,
59  const label celli,
60  const point& end,
61  const label level,
62  const label i,
63  const label j,
64  const label k
65 )
66 :
67  particle(mesh, position, celli),
68  start_(this->position()),
69  end_(end),
70  level_(level),
71  i_(i),
72  j_(j),
73  k_(k)
74 {}
75 
76 
78 (
79  const polyMesh& mesh,
80  Istream& is,
81  bool readFields
82 )
83 :
84  particle(mesh, is, readFields)
85 {
86  if (readFields)
87  {
88  if (is.format() == IOstream::ASCII)
89  {
90  is >> start_ >> end_;
91  level_ = readLabel(is);
92  i_ = readLabel(is);
93  j_ = readLabel(is);
94  k_ = readLabel(is);
95  }
96  else
97  {
98  is.read
99  (
100  reinterpret_cast<char*>(&start_),
101  sizeof(start_) + sizeof(end_) + sizeof(level_)
102  + sizeof(i_) + sizeof(j_) + sizeof(k_)
103  );
104  }
105  }
106 
107  // Check state of Istream
108  is.check
109  (
110  "trackedParticle::trackedParticle"
111  "(const Cloud<trackedParticle>&, Istream&, bool)"
112  );
113 }
114 
115 
116 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
117 
119 (
120  Cloud<trackedParticle>& cloud,
121  trackingData& td,
122  const scalar trackTime
123 )
124 {
125  scalar tEnd = (1.0 - stepFraction())*trackTime;
126 
127  if (tEnd <= small && onBoundaryFace())
128  {
129  // This is a hack to handle particles reaching their endpoint on a
130  // processor boundary. This prevents a particle being endlessly
131  // transferred backwards and forwards across the interface.
132  td.keepParticle = false;
133  td.sendToProc = -1;
134  }
135  else
136  {
137  td.keepParticle = true;
138  td.sendToProc = -1;
139 
140  while (td.keepParticle && td.sendToProc == -1 && stepFraction() < 1)
141  {
142  // mark visited cell with max level.
143  td.maxLevel_[cell()] = max(td.maxLevel_[cell()], level_);
144 
145  const scalar f = 1 - stepFraction();
146  const vector s = end_ - start_;
147  trackToAndHitFace(f*s, f, cloud, td);
148  }
149  }
150 
151  return td.keepParticle;
152 }
153 
154 
156 (
158  trackingData& td
159 )
160 {
161  // Remove particle
162  td.keepParticle = false;
163 }
164 
165 
167 (
169  trackingData& td
170 )
171 {
172  // Remove particle
173  td.keepParticle = false;
174 }
175 
176 
178 (
180  trackingData& td
181 )
182 {
183  // Remove particle
184  td.keepParticle = false;
185 }
186 
187 
189 (
191  trackingData& td
192 )
193 {
194  // Remove particle
195  td.keepParticle = false;
196 }
197 
198 
200 (
201  const vector&,
202  const scalar,
204  trackingData& td
205 )
206 {
207  // Remove particle
208  td.keepParticle = false;
209 }
210 
211 
213 (
215  trackingData& td
216 )
217 {
218  // Remove particle
219  td.keepParticle = false;
220 }
221 
222 
224 {
226 
227  // Mark edge we are currently on (if any). This was set on the sending
228  // processor but has not yet been set on the receiving side.
229  const label feati = i(), edgei = k();
230  if (edgei != -1)
231  {
232  td.featureEdgeVisited_[feati].set(edgei, 1u);
233  }
234 }
235 
236 
237 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
238 
240 {
241  if (os.format() == IOstream::ASCII)
242  {
243  os << static_cast<const particle&>(p)
244  << token::SPACE << p.start_
245  << token::SPACE << p.end_
246  << token::SPACE << p.level_
247  << token::SPACE << p.i_
248  << token::SPACE << p.j_
249  << token::SPACE << p.k_;
250  }
251  else
252  {
253  os << static_cast<const particle&>(p);
254  os.write
255  (
256  reinterpret_cast<const char*>(&p.start_),
257  sizeof(p.start_) + sizeof(p.end_) + sizeof(p.level_)
258  + sizeof(p.i_) + sizeof(p.j_) + sizeof(p.k_)
259  );
260  }
261 
262  // Check state of Ostream
263  os.check("Ostream& operator<<(Ostream&, const trackedParticle&)");
264 
265  return os;
266 }
267 
268 
269 // ************************************************************************* //
void hitWallPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wallPatch.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
virtual Ostream & write(const char)=0
Write character.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
void correctAfterParallelTransfer(trackingData &td)
Make changes following a parallel transfer. Runs either processor.
Definition: particle.C:1047
List< PackedBoolList > & featureEdgeVisited_
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
bool move(Cloud< trackedParticle > &, trackingData &, const scalar)
Track all particles to their end point.
Base particle class.
Definition: particle.H:81
trackedParticle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPtI, const point &end, const label level, const label i, const label j, const label k)
Construct from components.
Particle class that marks cells it passes through. Used to mark cells visited by feature edges...
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
virtual Istream & read(token &)=0
Return next token from stream.
void hitSymmetryPlanePatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
void hitWedgePatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wedge.
label k() const
Transported label.
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
label readLabel(Istream &is)
Definition: label.H:64
Base cloud calls templated on particle type.
Definition: Cloud.H:52
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void hitCyclicAMIPatch(const vector &, const scalar, Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclicAMI.
labelList f(nPoints)
Class used to pass tracking data to the trackToFace function.
void correctAfterParallelTransfer(trackingData &)
Do corrections to the particle and tracking data following a.
void hitSymmetryPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:107
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:57
label i() const
Transported label.
Ostream & operator<<(Ostream &, const ensightPart &)
void hitCyclicPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
volScalarField & p
label sendToProc
Processor to send the particle to. -1 indicates that this.
Definition: particle.H:111