trackedParticle.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2017 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  trackingData& td,
121  const scalar trackTime
122 )
123 {
124  td.switchProcessor = false;
125 
126  scalar tEnd = (1.0 - stepFraction())*trackTime;
127 
128  if (tEnd <= SMALL && onBoundaryFace())
129  {
130  // This is a hack to handle particles reaching their endpoint
131  // on a processor boundary. If the endpoint is on a processor face
132  // it currently gets transferred backwards and forwards infinitely.
133 
134  // Remove the particle
135  td.keepParticle = false;
136  }
137  else
138  {
139  td.keepParticle = true;
140 
141  while (td.keepParticle && !td.switchProcessor && stepFraction() < 1)
142  {
143  // mark visited cell with max level.
144  td.maxLevel_[cell()] = max(td.maxLevel_[cell()], level_);
145 
146  const scalar f = 1 - stepFraction();
147  trackToFace(f*(end_ - start_), f, td);
148  }
149  }
150 
151  return td.keepParticle;
152 }
153 
154 
156 (
157  const polyPatch&,
158  trackingData& td,
159  const label patchi,
160  const scalar trackFraction,
161  const tetIndices& tetIs
162 )
163 {
164  return false;
165 }
166 
167 
169 (
170  const wedgePolyPatch&,
171  trackingData& td
172 )
173 {
174  // Remove particle
175  td.keepParticle = false;
176 }
177 
178 
180 (
181  const symmetryPlanePolyPatch&,
182  trackingData& td
183 )
184 {
185  // Remove particle
186  td.keepParticle = false;
187 }
188 
189 
191 (
192  const symmetryPolyPatch&,
193  trackingData& td
194 )
195 {
196  // Remove particle
197  td.keepParticle = false;
198 }
199 
200 
202 (
203  const cyclicPolyPatch&,
204  trackingData& td
205 )
206 {
207  // Remove particle
208  td.keepParticle = false;
209 }
210 
211 
213 (
214  const cyclicAMIPolyPatch&,
215  trackingData& td,
216  const vector&
217 )
218 {
219  // Remove particle
220  td.keepParticle = false;
221 }
222 
223 
225 (
226  const processorPolyPatch&,
227  trackingData& td
228 )
229 {
230  // Move to different processor
231  td.switchProcessor = true;
232 }
233 
234 
236 (
237  const wallPolyPatch& wpp,
238  trackingData& td,
239  const tetIndices&
240 )
241 {
242  // Remove particle
243  td.keepParticle = false;
244 }
245 
246 
248 (
249  const polyPatch& wpp,
250  trackingData& td
251 )
252 {
253  // Remove particle
254  td.keepParticle = false;
255 }
256 
257 
259 (
260  const label patchi,
261  trackingData& td
262 )
263 {
264  particle::correctAfterParallelTransfer(patchi, td);
265 
266  label edgeI = k();
267  if (edgeI != -1)
268  {
269  label featI = i();
270 
271  // Mark edge we're currently on (was set on sending processor but not
272  // receiving sender)
273  td.featureEdgeVisited_[featI].set(edgeI, 1u);
274  }
275 }
276 
277 
278 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
279 
281 {
282  if (os.format() == IOstream::ASCII)
283  {
284  os << static_cast<const particle&>(p)
285  << token::SPACE << p.start_
286  << token::SPACE << p.end_
287  << token::SPACE << p.level_
288  << token::SPACE << p.i_
289  << token::SPACE << p.j_
290  << token::SPACE << p.k_;
291  }
292  else
293  {
294  os << static_cast<const particle&>(p);
295  os.write
296  (
297  reinterpret_cast<const char*>(&p.start_),
298  sizeof(p.start_) + sizeof(p.end_) + sizeof(p.level_)
299  + sizeof(p.i_) + sizeof(p.j_) + sizeof(p.k_)
300  );
301  }
302 
303  // Check state of Ostream
304  os.check("Ostream& operator<<(Ostream&, const trackedParticle&)");
305 
306  return os;
307 }
308 
309 
310 // ************************************************************************* //
Symmetry patch for non-planar or multi-plane patches.
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(const cyclicAMIPolyPatch &, trackingData &td, const vector &)
Overridable function to handle the particle hitting a cyclicAMI.
List< PackedBoolList > & featureEdgeVisited_
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void hitCyclicPatch(const cyclicPolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a cyclic.
label k
Boltzmann constant.
Base particle class.
Definition: particle.H:81
Neighbour processor patch.
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.
void hitProcessorPatch(const processorPolyPatch &, trackingData &td)
Particle class that marks cells it passes through. Used to mark cells visited by feature edges...
virtual Istream & read(token &)=0
Return next token from stream.
void hitWallPatch(const wallPolyPatch &, trackingData &td, const tetIndices &)
Overridable function to handle the particle hitting a wallPatch.
Cyclic plane patch.
Foam::wallPolyPatch.
Definition: wallPolyPatch.H:48
Wedge front and back plane patch.
Storage and named access for the indices of a tet which is part of the decomposition of a cell...
Definition: tetIndices.H:81
Cyclic patch for Arbitrary Mesh Interface (AMI)
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:125
label readLabel(Istream &is)
Definition: label.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void hitSymmetryPlanePatch(const symmetryPlanePolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a.
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(const symmetryPolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a.
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Ostream & operator<<(Ostream &, const ensightPart &)
virtual Ostream & write(const token &)=0
Write next token to stream.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p
bool switchProcessor
Flag to switch processor.
Definition: particle.H:122
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
void hitWedgePatch(const wedgePolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a wedge.
bool move(trackingData &, const scalar)
Track all particles to their end point.
bool hitPatch(const polyPatch &, trackingData &td, const label patchi, const scalar trackFraction, const tetIndices &tetIs)
Overridable function to handle the particle hitting a patch.