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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2017-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "trackedParticle.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
34 (
35  sizeof(trackedParticle) - offsetof(trackedParticle, start_)
36 );
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 (
43  const polyMesh& mesh,
44  const barycentric& coordinates,
45  const label celli,
46  const label tetFacei,
47  const label tetPtI,
48  const point& end,
49  const label level,
50  const label i,
51  const label j,
52  const label k
53 )
54 :
55  particle(mesh, coordinates, celli, tetFacei, tetPtI),
56  start_(position()),
57  end_(end),
58  level_(level),
59  i_(i),
60  j_(j),
61  k_(k)
62 {}
63 
64 
66 (
67  const polyMesh& mesh,
68  const vector& position,
69  const label celli,
70  const point& end,
71  const label level,
72  const label i,
73  const label j,
74  const label k
75 )
76 :
77  particle(mesh, position, celli),
78  start_(this->position()),
79  end_(end),
80  level_(level),
81  i_(i),
82  j_(j),
83  k_(k)
84 {}
85 
86 
88 (
89  const polyMesh& mesh,
90  Istream& is,
91  bool readFields,
92  bool newFormat
93 )
94 :
95  particle(mesh, is, readFields, newFormat)
96 {
97  if (readFields)
98  {
99  if (is.format() == IOstream::ASCII)
100  {
101  is >> start_ >> end_ >> level_ >> i_ >> j_ >> k_;
102  }
103  else if (!is.checkLabelSize<>() || !is.checkScalarSize<>())
104  {
105  // Non-native label or scalar size
106  is.beginRawRead();
107 
108  readRawScalar(is, start_.data(), vector::nComponents);
109  readRawScalar(is, end_.data(), vector::nComponents);
110  readRawLabel(is, &level_);
111  readRawLabel(is, &i_);
112  readRawLabel(is, &j_);
113  readRawLabel(is, &k_);
114 
115  is.endRawRead();
116  }
117  else
118  {
119  is.read
120  (
121  reinterpret_cast<char*>(&start_),
122  sizeofFields_
123  );
124  }
125  }
126 
127  is.check(FUNCTION_NAME);
128 }
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
134 (
136  trackingData& td,
137  const scalar trackTime
138 )
139 {
140  td.switchProcessor = false;
141 
142  scalar tEnd = (1.0 - stepFraction())*trackTime;
143 
144  if (tEnd <= SMALL && onBoundaryFace())
145  {
146  // This is a hack to handle particles reaching their endpoint
147  // on a processor boundary. If the endpoint is on a processor face
148  // it currently gets transferred backwards and forwards infinitely.
149 
150  // Remove the particle
151  td.keepParticle = false;
152  }
153  else
154  {
155  td.keepParticle = true;
156 
157  while (td.keepParticle && !td.switchProcessor && stepFraction() < 1)
158  {
159  // mark visited cell with max level.
160  td.maxLevel_[cell()] = max(td.maxLevel_[cell()], level_);
161 
162  const scalar f = 1 - stepFraction();
163  const vector s = end_ - start_;
164  trackToAndHitFace(f*s, f, cloud, td);
165  }
166  }
167 
168  return td.keepParticle;
169 }
170 
171 
173 {
174  return false;
175 }
176 
177 
179 (
181  trackingData& td
182 )
183 {
184  // Remove particle
185  td.keepParticle = false;
186 }
187 
188 
190 (
192  trackingData& td
193 )
194 {
195  // Remove particle
196  td.keepParticle = false;
197 }
198 
199 
201 (
203  trackingData& td
204 )
205 {
206  // Remove particle
207  td.keepParticle = false;
208 }
209 
210 
212 (
214  trackingData& td
215 )
216 {
217  // Remove particle
218  td.keepParticle = false;
219 }
220 
221 
223 (
225  trackingData& td,
226  const vector& direction
227 )
228 {
229  // Remove particle
230  td.keepParticle = false;
231 }
232 
233 
235 (
237  trackingData& td,
238  const vector&
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);
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_),
309  );
310  }
311 
313  return os;
314 }
315 
316 
317 // ************************************************************************* //
Foam::trackedParticle::hitPatch
bool hitPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a patch.
Definition: trackedParticle.C:172
Foam::trackedParticle::trackingData
Class used to pass tracking data to the trackToFace function.
Definition: trackedParticle.H:92
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::trackedParticle::sizeofFields_
static const std::size_t sizeofFields_
Size in bytes of the fields.
Definition: trackedParticle.H:123
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
Definition: gmvOutputSpray.H:25
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:286
Foam::OBJstream::write
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::trackedParticle::hitSymmetryPlanePatch
void hitSymmetryPlanePatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
Definition: trackedParticle.C:190
Foam::IOstream::checkLabelSize
std::enable_if< std::is_integral< T >::value, bool >::type checkLabelSize() const noexcept
Definition: IOstream.H:300
Foam::Istream::endRawRead
virtual bool endRawRead()=0
End of low-level raw binary read.
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
coordinates
PtrList< coordinateSystem > coordinates(solidRegions.size())
Foam::trackedParticle::hitSymmetryPatch
void hitSymmetryPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
Definition: trackedParticle.C:201
Foam::Barycentric< scalar >
Foam::particle::trackingData::keepParticle
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:105
Foam::particle::trackingData::switchProcessor
bool switchProcessor
Flag to switch processor.
Definition: particle.H:102
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::IOstream::checkScalarSize
std::enable_if< std::is_floating_point< T >::value, bool >::type checkScalarSize() const noexcept
Definition: IOstream.H:309
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
Foam::particle::correctAfterParallelTransfer
void correctAfterParallelTransfer(const label patchi, trackingData &td)
Convert processor patch addressing to the global equivalents.
Definition: particle.C:1088
Foam::trackedParticle::hitWedgePatch
void hitWedgePatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wedge.
Definition: trackedParticle.C:179
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam::trackedParticle::trackingData::maxLevel_
labelList & maxLevel_
Definition: trackedParticle.H:98
trackedParticle.H
Foam::readFields
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
Definition: ReadFieldsTemplates.C:312
Foam::trackedParticle::hitWallPatch
void hitWallPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wallPatch.
Definition: trackedParticle.C:258
Foam::cloud
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:57
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
Foam::Istream::beginRawRead
virtual bool beginRawRead()=0
Start of low-level raw binary read.
Foam::trackedParticle::hitCyclicPatch
void hitCyclicPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
Definition: trackedParticle.C:212
Foam::trackedParticle::trackedParticle
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.
Definition: trackedParticle.C:42
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
Foam::particle
Base particle class.
Definition: particle.H:76
Foam::trackedParticle::hitCyclicAMIPatch
void hitCyclicAMIPatch(Cloud< trackedParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicAMI.
Definition: trackedParticle.C:223
Foam::Cloud
Base cloud calls templated on particle type.
Definition: Cloud.H:55
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::direction
uint8_t direction
Definition: direction.H:52
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::trackedParticle::hitProcessorPatch
void hitProcessorPatch(Cloud< trackedParticle > &, trackingData &)
Definition: trackedParticle.C:247
Foam::readRawLabel
label readRawLabel(Istream &is)
Read raw label from binary stream.
Definition: label.C:46
Foam::trackedParticle
Particle class that marks cells it passes through. Used to mark cells visited by feature edges.
Definition: trackedParticle.H:62
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::trackedParticle::hitCyclicACMIPatch
void hitCyclicACMIPatch(Cloud< trackedParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicACMI.
Definition: trackedParticle.C:235
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54
Foam::trackedParticle::trackingData::featureEdgeVisited_
List< bitSet > & featureEdgeVisited_
Definition: trackedParticle.H:100
Foam::trackedParticle::move
bool move(Cloud< trackedParticle > &, trackingData &, const scalar)
Track all particles to their end point.
Definition: trackedParticle.C:134
Foam::trackedParticle::correctAfterParallelTransfer
void correctAfterParallelTransfer(const label, trackingData &)
Convert processor patch addressing to the global equivalents.
Definition: trackedParticle.C:269
Foam::Istream::read
virtual Istream & read(token &)=0
Return next token from stream.