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-2014 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 :
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 // ************************************************************************* //
Foam::trackedParticle::hitProcessorPatch
void hitProcessorPatch(const processorPolyPatch &, trackingData &td)
Definition: trackedParticle.C:196
Foam::trackedParticle::trackingData
Class used to pass tracking data to the trackToFace function.
Definition: trackedParticle.H:79
Foam::IOstream::format
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
Foam::trackedParticle::hitPatch
bool hitPatch(const polyPatch &, trackingData &td, const label patchI, const scalar trackFraction, const tetIndices &tetIs)
Overridable function to handle the particle hitting a patch.
Definition: trackedParticle.C:139
p
p
Definition: pEqn.H:62
Foam::trackedParticle::trackingData::featureEdgeVisited_
List< PackedBoolList > & featureEdgeVisited_
Definition: trackedParticle.H:87
Foam::wedgePolyPatch
Wedge front and back plane patch.
Definition: wedgePolyPatch.H:48
Foam::cyclicPolyPatch
Cyclic plane patch.
Definition: cyclicPolyPatch.H:63
Foam::particle::TrackingData::keepParticle
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:112
Foam::trackedParticle::move
bool move(trackingData &, const scalar)
Track all particles to their end point.
Definition: trackedParticle.C:96
Foam::readFields
This function object reads fields from the time directories and adds them to the mesh database for fu...
Definition: readFields.H:104
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::trackedParticle::hitSymmetryPatch
void hitSymmetryPatch(const symmetryPolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a.
Definition: trackedParticle.C:174
Foam::trackedParticle::hitCyclicPatch
void hitCyclicPatch(const cyclicPolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a cyclic.
Definition: trackedParticle.C:185
Foam::label
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
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Ostream::write
virtual Ostream & write(const token &)=0
Write next token to stream.
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::symmetryPlanePolyPatch
Symmetry-plane patch.
Definition: symmetryPlanePolyPatch.H:48
Foam::symmetryPolyPatch
Symmetry patch for non-planar or multi-plane patches.
Definition: symmetryPolyPatch.H:51
Foam::processorPolyPatch
Neighbour processor patch.
Definition: processorPolyPatch.H:55
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Foam::trackedParticle::trackedParticle
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.
Definition: trackedParticle.C:32
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::trackedParticle::trackingData::maxLevel_
labelList & maxLevel_
Definition: trackedParticle.H:85
Foam::wallPolyPatch
Foam::wallPolyPatch.
Definition: wallPolyPatch.H:48
trackedParticle.H
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::particle::TrackingData::switchProcessor
bool switchProcessor
Flag to switch processor.
Definition: particle.H:109
Foam::tetIndices
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Definition: tetIndices.H:73
Foam::Vector< scalar >
Foam::particle
Base particle class.
Definition: particle.H:78
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::trackedParticle::hitWallPatch
void hitWallPatch(const wallPolyPatch &, trackingData &td, const tetIndices &)
Overridable function to handle the particle hitting a wallPatch.
Definition: trackedParticle.C:207
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
Foam::trackedParticle::hitWedgePatch
void hitWedgePatch(const wedgePolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a wedge.
Definition: trackedParticle.C:152
Foam::trackedParticle
Particle class that marks cells it passes through. Used to mark cells visited by feature edges.
Definition: trackedParticle.H:52
Foam::trackedParticle::hitSymmetryPlanePatch
void hitSymmetryPlanePatch(const symmetryPlanePolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a.
Definition: trackedParticle.C:163
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::trackedParticle::correctAfterParallelTransfer
void correctAfterParallelTransfer(const label, trackingData &)
Convert processor patch addressing to the global equivalents.
Definition: trackedParticle.C:230
Foam::Istream::read
virtual Istream & read(token &)=0
Return next token from stream.