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-------------------------------------------------------------------------------
11License
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,
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_),
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
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// ************************************************************************* //
label k
Base cloud calls templated on particle type.
Definition: Cloud.H:68
streamFormat format() const noexcept
Get the current stream format.
std::enable_if< std::is_integral< T >::value, bool >::type checkLabelSize() const noexcept
Definition: IOstream.H:300
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
std::enable_if< std::is_floating_point< T >::value, bool >::type checkScalarSize() const noexcept
Definition: IOstream.H:309
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
virtual bool endRawRead()=0
End of low-level raw binary read.
virtual bool beginRawRead()=0
Start of low-level raw binary read.
virtual Istream & read(token &)=0
Return next token from stream.
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:57
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:60
virtual void move()=0
static constexpr direction nComponents
Number of components in bool is 1.
Definition: bool.H:98
bool switchProcessor
Flag to switch processor.
Definition: particle.H:102
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:105
Base particle class.
Definition: particle.H:79
void correctAfterParallelTransfer(const label patchi, trackingData &td)
Convert processor patch addressing to the global equivalents.
Definition: particle.C:1088
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
@ SPACE
Space [isspace].
Definition: token.H:125
Class used to pass tracking data to the trackToFace function.
Particle class that marks cells it passes through. Used to mark cells visited by feature edges.
void correctAfterParallelTransfer(const label, trackingData &)
Convert processor patch addressing to the global equivalents.
void hitWedgePatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wedge.
bool hitPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a patch.
void hitSymmetryPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
void hitSymmetryPlanePatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
void hitWallPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wallPatch.
static const std::size_t sizeofFields_
Size in bytes of the fields.
void hitCyclicACMIPatch(Cloud< trackedParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicACMI.
void hitCyclicPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
void hitProcessorPatch(Cloud< trackedParticle > &, trackingData &)
void hitCyclicAMIPatch(Cloud< trackedParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicAMI.
volScalarField & p
dynamicFvMesh & mesh
PtrList< coordinateSystem > coordinates(solidRegions.size())
OBJstream os(runTime.globalPath()/outputName)
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))
#define FUNCTION_NAME
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
label readRawLabel(Istream &is)
Read raw label from binary stream.
Definition: label.C:46
uint8_t direction
Definition: direction.H:56
labelList f(nPoints)