Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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
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() == IOstreamOption::ASCII)
100 {
101 is >> start_ >> end_ >> level_ >> i_ >> j_ >> k_;
102 }
103 else
104 {
105 // No non-native streaming
107
108 is.read
109 (
110 reinterpret_cast<char*>(&start_),
112 );
113 }
114 }
117}
118
119
120// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121
123(
125 trackingData& td,
126 const scalar trackTime
127)
128{
129 td.switchProcessor = false;
130
131 scalar tEnd = (1.0 - stepFraction())*trackTime;
132
133 if (tEnd <= SMALL && onBoundaryFace())
134 {
135 // This is a hack to handle particles reaching their endpoint
136 // on a processor boundary. If the endpoint is on a processor face
137 // it currently gets transferred backwards and forwards infinitely.
138
139 // Remove the particle
140 td.keepParticle = false;
141 }
142 else
143 {
144 td.keepParticle = true;
145
146 while (td.keepParticle && !td.switchProcessor && stepFraction() < 1)
147 {
148 // mark visited cell with max level.
149 td.maxLevel_[cell()] = max(td.maxLevel_[cell()], level_);
150
151 const scalar f = 1 - stepFraction();
152 const vector s = end_ - start_;
153 trackToAndHitFace(f*s, f, cloud, td);
155 }
156
157 return td.keepParticle;
158}
159
170 trackingData& td
172{
173 // Remove particle
174 td.keepParticle = false;
175}
176
177
179(
181 trackingData& td
183{
184 // Remove particle
185 td.keepParticle = false;
186}
187
188
190(
192 trackingData& td
194{
195 // Remove particle
196 td.keepParticle = false;
197}
198
199
201(
203 trackingData& td
205{
206 // Remove particle
207 td.keepParticle = false;
208}
209
210
212(
214 trackingData& td,
215 const vector& direction
217{
218 // Remove particle
219 td.keepParticle = false;
220}
221
222
224(
226 trackingData& td,
227 const vector&
229{
230 // Remove particle
231 td.keepParticle = false;
232}
233
234
236(
238 trackingData& td
240{
241 // Move to different processor
242 td.switchProcessor = true;
243}
244
245
247(
249 trackingData& td
251{
252 // Remove particle
253 td.keepParticle = false;
254}
255
256
258(
259 const label patchi,
260 trackingData& td
261)
262{
264
265 label edgeI = k();
266 if (edgeI != -1)
267 {
268 label featI = i();
269
270 // Mark edge we're currently on (was set on sending processor but not
271 // receiving sender)
272 td.featureEdgeVisited_[featI].set(edgeI);
273 }
274}
275
276
277// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
278
279Foam::Ostream& Foam::operator<<(Ostream& os, const trackedParticle& p)
280{
282 {
284 << token::SPACE << p.start_
285 << token::SPACE << p.end_
286 << token::SPACE << p.level_
287 << token::SPACE << p.i_
288 << token::SPACE << p.j_
289 << token::SPACE << p.k_;
290 }
291 else
292 {
294 os.write
295 (
296 reinterpret_cast<const char*>(&p.start_),
298 );
299 }
300
302 return os;
303}
304
305
306// ************************************************************************* //
label k
Base cloud calls templated on particle type.
Definition Cloud.H:64
streamFormat format() const noexcept
Get the current stream format.
@ ASCII
"ascii" (normal default)
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
bool fatalCheckNativeSizes(const char *operation) const
Assert that the label/scalar byte-size associated with the stream are the native label/scalar sizes.
Definition IOstream.C:67
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
virtual Istream & read(token &)=0
Return next token from stream.
virtual Ostream & write(const char c) override
Write character.
Definition OBJstream.C:69
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A cloud is a registry collection of lagrangian particles.
Definition cloud.H:56
Base particle class.
Definition particle.H:72
void correctAfterParallelTransfer(const label patchi, trackingData &td)
Convert processor patch addressing to the global equivalents.
Definition particle.C:1066
vector position() const
Return current particle position.
Definition particleI.H:283
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
const polyMesh & mesh() const noexcept
Return the mesh database.
Definition particleI.H:110
const barycentric & coordinates() const noexcept
Return current particle coordinates.
Definition particleI.H:116
bool onBoundaryFace() const noexcept
Is the particle on a boundary face?
Definition particleI.H:271
scalar stepFraction() const noexcept
Return the fraction of time-step completed.
Definition particleI.H:170
void trackToAndHitFace(const vector &direction, const scalar fraction, TrackCloudType &cloud, trackingData &td)
Convenience function. Combines trackToFace and hitFace.
label cell() const noexcept
Return current cell particle is in.
Definition particleI.H:122
particle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from components.
Definition particle.C:507
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
@ SPACE
Space [isspace].
Definition token.H:144
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.
label i() const noexcept
Transported label.
bool move(Cloud< trackedParticle > &, trackingData &, const scalar)
Track all particles to their end point.
point & end() noexcept
Point to track to.
void hitSymmetryPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
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.
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.
label j() const noexcept
Transported label.
void hitCyclicPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
void hitProcessorPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a processorPatch.
label k() const noexcept
Transported label.
void hitCyclicAMIPatch(Cloud< trackedParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicAMI.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
volScalarField & p
dynamicFvMesh & mesh
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))
wallPoints::trackData td(isBlockedFace, regionToBlockSize)
#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:40
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.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
uint8_t direction
Definition direction.H:49
vector point
Point is a vector.
Definition point.H:37
Barycentric< scalar > barycentric
A scalar version of the templated Barycentric.
Definition barycentric.H:45
Vector< scalar > vector
Definition vector.H:57
labelList f(nPoints)