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-2018 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  td.switchProcessor = false;
126 
127  scalar tEnd = (1.0 - stepFraction())*trackTime;
128 
129  if (tEnd <= small && onBoundaryFace())
130  {
131  // This is a hack to handle particles reaching their endpoint
132  // on a processor boundary. If the endpoint is on a processor face
133  // it currently gets transferred backwards and forwards infinitely.
134 
135  // Remove the particle
136  td.keepParticle = false;
137  }
138  else
139  {
140  td.keepParticle = true;
141 
142  while (td.keepParticle && !td.switchProcessor && stepFraction() < 1)
143  {
144  // mark visited cell with max level.
145  td.maxLevel_[cell()] = max(td.maxLevel_[cell()], level_);
146 
147  const scalar f = 1 - stepFraction();
148  const vector s = end_ - start_;
149  trackToAndHitFace(f*s, f, cloud, td);
150  }
151  }
152 
153  return td.keepParticle;
154 }
155 
156 
158 {
159  return false;
160 }
161 
162 
164 (
166  trackingData& td
167 )
168 {
169  // Remove particle
170  td.keepParticle = false;
171 }
172 
173 
175 (
177  trackingData& td
178 )
179 {
180  // Remove particle
181  td.keepParticle = false;
182 }
183 
184 
186 (
188  trackingData& td
189 )
190 {
191  // Remove particle
192  td.keepParticle = false;
193 }
194 
195 
197 (
199  trackingData& td
200 )
201 {
202  // Remove particle
203  td.keepParticle = false;
204 }
205 
206 
208 (
209  const vector&,
210  const scalar,
212  trackingData& td
213 )
214 {
215  // Remove particle
216  td.keepParticle = false;
217 }
218 
219 
221 (
222  const vector&,
223  const scalar,
225  trackingData& td
226 )
227 {
228  // Remove particle
229  td.keepParticle = false;
230 }
231 
232 
234 (
235  const vector&,
236  const scalar,
238  trackingData& td
239 )
240 {
241  // Remove particle
242  td.keepParticle = false;
243 }
244 
245 
247 (
249  trackingData& td
250 )
251 {
252  // Move to different processor
253  td.switchProcessor = true;
254 }
255 
256 
258 (
260  trackingData& td
261 )
262 {
263  // Remove particle
264  td.keepParticle = false;
265 }
266 
267 
269 (
270  const label patchi,
271  trackingData& td
272 )
273 {
275 
276  label edgeI = k();
277  if (edgeI != -1)
278  {
279  label featI = i();
280 
281  // Mark edge we're currently on (was set on sending processor but not
282  // receiving sender)
283  td.featureEdgeVisited_[featI].set(edgeI, 1u);
284  }
285 }
286 
287 
288 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
289 
291 {
292  if (os.format() == IOstream::ASCII)
293  {
294  os << static_cast<const particle&>(p)
295  << token::SPACE << p.start_
296  << token::SPACE << p.end_
297  << token::SPACE << p.level_
298  << token::SPACE << p.i_
299  << token::SPACE << p.j_
300  << token::SPACE << p.k_;
301  }
302  else
303  {
304  os << static_cast<const particle&>(p);
305  os.write
306  (
307  reinterpret_cast<const char*>(&p.start_),
308  sizeof(p.start_) + sizeof(p.end_) + sizeof(p.level_)
309  + sizeof(p.i_) + sizeof(p.j_) + sizeof(p.k_)
310  );
311  }
312 
313  // Check state of Ostream
314  os.check("Ostream& operator<<(Ostream&, const trackedParticle&)");
315 
316  return os;
317 }
318 
319 
320 // ************************************************************************* //
void hitWallPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wallPatch.
void correctAfterParallelTransfer(const label patchi, trackingData &td)
Convert processor patch addressing to the global equivalents.
Definition: particle.C:1060
virtual Ostream & write(const char)=0
Write character.
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
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
void hitCyclicRepeatAMIPatch(const vector &, const scalar, Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
List< PackedBoolList > & featureEdgeVisited_
bool hitPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a patch.
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:83
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.
bool switchProcessor
Flag to switch processor.
Definition: particle.H:109
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 correctAfterParallelTransfer(const label, trackingData &)
Convert processor patch addressing to the global equivalents.
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 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:112
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
void hitProcessorPatch(Cloud< trackedParticle > &, trackingData &)
label i() const
Transported label.
Ostream & operator<<(Ostream &, const ensightPart &)
void hitCyclicPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
void hitCyclicACMIPatch(const vector &, const scalar, Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclicACMI.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p