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-2022 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() == IOstreamOption::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_),
123  );
124  }
125  }
126 
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 
290 Foam::Ostream& Foam::operator<<(Ostream& os, const trackedParticle& p)
291 {
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 // ************************************************************************* //
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:1076
uint8_t direction
Definition: direction.H:46
std::enable_if< std::is_floating_point< T >::value, bool >::type checkScalarSize() const noexcept
Check if the scalar byte-size associated with the stream is the same as the given type...
Definition: IOstream.H:379
virtual Ostream & write(const char c) override
Write character.
Definition: OBJstream.C:69
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
void hitCyclicAMIPatch(Cloud< trackedParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicAMI.
bool hitPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a patch.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
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
"ascii" (normal default)
virtual bool endRawRead()=0
End of low-level raw binary read.
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
label k
Boltzmann constant.
bool move(Cloud< trackedParticle > &, trackingData &, const scalar)
Track all particles to their end point.
Base particle class.
Definition: particle.H:69
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...
virtual Istream & read(token &)=0
Return next token from stream.
dynamicFvMesh & mesh
void hitSymmetryPlanePatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const NameMatchPredicate &selectedFields, DynamicList< regIOobject *> &storedObjects)
Read the selected GeometricFields of the templated type and store on the objectRegistry.
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:53
Space [isspace].
Definition: token.H:131
void hitWedgePatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wedge.
Vector< scalar > vector
Definition: vector.H:57
Base cloud calls templated on particle type.
Definition: Cloud.H:51
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void correctAfterParallelTransfer(const label, trackingData &)
Convert processor patch addressing to the global equivalents.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:201
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
labelList f(nPoints)
Class used to pass tracking data to the trackToFace function.
static const std::size_t sizeofFields_
Size in bytes of the fields.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
label readRawLabel(Istream &is)
Read raw label from binary stream.
Definition: label.C:39
PtrList< coordinateSystem > coordinates(solidRegions.size())
void hitSymmetryPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
virtual bool beginRawRead()=0
Start of low-level raw binary read.
void hitProcessorPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a processorPatch.
void hitCyclicPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
std::enable_if< std::is_integral< T >::value, bool >::type checkLabelSize() const noexcept
Check if the label byte-size associated with the stream is the same as the given type.
Definition: IOstream.H:368
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p
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))
streamFormat format() const noexcept
Get the current stream format.