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-2016 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 vector& position,
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, position, celli, tetFacei, tetPtI),
46  end_(end),
47  level_(level),
48  i_(i),
49  j_(j),
50  k_(k)
51 {}
52 
53 
55 (
56  const polyMesh& mesh,
57  Istream& is,
58  bool readFields
59 )
60 :
61  particle(mesh, is, readFields)
62 {
63  if (readFields)
64  {
65  if (is.format() == IOstream::ASCII)
66  {
67  is >> end_;
68  level_ = readLabel(is);
69  i_ = readLabel(is);
70  j_ = readLabel(is);
71  k_ = readLabel(is);
72  }
73  else
74  {
75  is.read
76  (
77  reinterpret_cast<char*>(&end_),
78  sizeof(end_) + sizeof(level_)
79  + sizeof(i_) + sizeof(j_) + sizeof(k_)
80  );
81  }
82  }
83 
84  // Check state of Istream
85  is.check
86  (
87  "trackedParticle::trackedParticle"
88  "(const Cloud<trackedParticle>&, Istream&, bool)"
89  );
90 }
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
96 (
97  trackingData& td,
98  const scalar trackTime
99 )
100 {
101  td.switchProcessor = false;
102 
103  scalar tEnd = (1.0 - stepFraction())*trackTime;
104  scalar dtMax = tEnd;
105 
106  if (tEnd <= SMALL && onBoundary())
107  {
108  // This is a hack to handle particles reaching their endpoint
109  // on a processor boundary. If the endpoint is on a processor face
110  // it currently gets transferred backwards and forwards infinitely.
111 
112  // Remove the particle
113  td.keepParticle = false;
114  }
115  else
116  {
117  td.keepParticle = true;
118 
119  while (td.keepParticle && !td.switchProcessor && tEnd > SMALL)
120  {
121  // set the lagrangian time-step
122  scalar dt = min(dtMax, tEnd);
123 
124  // mark visited cell with max level.
125  td.maxLevel_[cell()] = max(td.maxLevel_[cell()], level_);
126 
127  dt *= trackToFace(end_, td);
128 
129  tEnd -= dt;
130  stepFraction() = 1.0 - tEnd/trackTime;
131  }
132  }
133 
134  return td.keepParticle;
135 }
136 
137 
139 (
140  const polyPatch&,
141  trackingData& td,
142  const label patchi,
143  const scalar trackFraction,
144  const tetIndices& tetIs
145 )
146 {
147  return false;
148 }
149 
150 
152 (
153  const wedgePolyPatch&,
154  trackingData& td
155 )
156 {
157  // Remove particle
158  td.keepParticle = false;
159 }
160 
161 
163 (
164  const symmetryPlanePolyPatch&,
165  trackingData& td
166 )
167 {
168  // Remove particle
169  td.keepParticle = false;
170 }
171 
172 
174 (
175  const symmetryPolyPatch&,
176  trackingData& td
177 )
178 {
179  // Remove particle
180  td.keepParticle = false;
181 }
182 
183 
185 (
186  const cyclicPolyPatch&,
187  trackingData& td
188 )
189 {
190  // Remove particle
191  td.keepParticle = false;
192 }
193 
194 
196 (
197  const processorPolyPatch&,
198  trackingData& td
199 )
200 {
201  // Move to different processor
202  td.switchProcessor = true;
203 }
204 
205 
207 (
208  const wallPolyPatch& wpp,
209  trackingData& td,
210  const tetIndices&
211 )
212 {
213  // Remove particle
214  td.keepParticle = false;
215 }
216 
217 
219 (
220  const polyPatch& wpp,
221  trackingData& td
222 )
223 {
224  // Remove particle
225  td.keepParticle = false;
226 }
227 
228 
230 (
231  const label patchi,
232  trackingData& td
233 )
234 {
235  particle::correctAfterParallelTransfer(patchi, td);
236 
237  label edgeI = k();
238  if (edgeI != -1)
239  {
240  label featI = i();
241 
242  // Mark edge we're currently on (was set on sending processor but not
243  // receiving sender)
244  td.featureEdgeVisited_[featI].set(edgeI, 1u);
245  }
246 }
247 
248 
249 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
250 
252 {
253  if (os.format() == IOstream::ASCII)
254  {
255  os << static_cast<const particle&>(p)
256  << token::SPACE << p.end_
257  << token::SPACE << p.level_
258  << token::SPACE << p.i_
259  << token::SPACE << p.j_
260  << token::SPACE << p.k_;
261  }
262  else
263  {
264  os << static_cast<const particle&>(p);
265  os.write
266  (
267  reinterpret_cast<const char*>(&p.end_),
268  sizeof(p.end_) + sizeof(p.level_)
269  + sizeof(p.i_) + sizeof(p.j_) + sizeof(p.k_)
270  );
271  }
272 
273  // Check state of Ostream
274  os.check("Ostream& operator<<(Ostream&, const trackedParticle&)");
275 
276  return os;
277 }
278 
279 
280 // ************************************************************************* //
Symmetry patch for non-planar or multi-plane patches.
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
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 > &)
List< PackedBoolList > & featureEdgeVisited_
trackedParticle(const polyMesh &mesh, const vector &position, 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.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
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:78
Neighbour processor patch.
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
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:112
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.
Class used to pass tracking data to the trackToFace function.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
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:109
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.