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 (
210  trackingData& td,
211  const vector& direction
212 )
213 {
214  // Remove particle
215  td.keepParticle = false;
216 }
217 
218 
220 (
222  trackingData& td,
223  const vector&
224 )
225 {
226  // Remove particle
227  td.keepParticle = false;
228 }
229 
230 
232 (
234  trackingData& td
235 )
236 {
237  // Move to different processor
238  td.switchProcessor = true;
239 }
240 
241 
243 (
245  trackingData& td
246 )
247 {
248  // Remove particle
249  td.keepParticle = false;
250 }
251 
252 
254 (
255  const label patchi,
256  trackingData& td
257 )
258 {
260 
261  label edgeI = k();
262  if (edgeI != -1)
263  {
264  label featI = i();
265 
266  // Mark edge we're currently on (was set on sending processor but not
267  // receiving sender)
268  td.featureEdgeVisited_[featI].set(edgeI, 1u);
269  }
270 }
271 
272 
273 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
274 
276 {
277  if (os.format() == IOstream::ASCII)
278  {
279  os << static_cast<const particle&>(p)
280  << token::SPACE << p.start_
281  << token::SPACE << p.end_
282  << token::SPACE << p.level_
283  << token::SPACE << p.i_
284  << token::SPACE << p.j_
285  << token::SPACE << p.k_;
286  }
287  else
288  {
289  os << static_cast<const particle&>(p);
290  os.write
291  (
292  reinterpret_cast<const char*>(&p.start_),
293  sizeof(p.start_) + sizeof(p.end_) + sizeof(p.level_)
294  + sizeof(p.i_) + sizeof(p.j_) + sizeof(p.k_)
295  );
296  }
297 
298  // Check state of Ostream
299  os.check("Ostream& operator<<(Ostream&, const trackedParticle&)");
300 
301  return os;
302 }
303 
304 
305 // ************************************************************************* //
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:988
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 hitCyclicAMIPatch(Cloud< trackedParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicAMI.
List< PackedBoolList > & featureEdgeVisited_
bool hitPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a patch.
void hitCyclicACMIPatch(Cloud< trackedParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicACMI.
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:84
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:116
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:377
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:53
void correctAfterParallelTransfer(const label, trackingData &)
Convert processor patch addressing to the global equivalents.
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:119
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.
virtual Ostream & write(const token &)=0
Write next token to stream.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p