Loading...
Searching...
No Matches
findCellParticle.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) 2013-2017 OpenFOAM Foundation
9 Copyright (C) 2018-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/>.
27\*---------------------------------------------------------------------------*/
28
29#include "findCellParticle.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
34(
35 const polyMesh& mesh,
37 const label celli,
38 const label tetFacei,
39 const label tetPti,
40 const point& end,
41 const label data
42)
43:
44 particle(mesh, coordinates, celli, tetFacei, tetPti),
45 start_(position()),
46 end_(end),
47 data_(data)
48{}
49
50
52(
53 const polyMesh& mesh,
54 const vector& position,
55 const label celli,
56 const point& end,
57 const label data
58)
59:
61 start_(this->position()),
62 end_(end),
63 data_(data)
64{}
65
66
68(
69 const polyMesh& mesh,
70 Istream& is,
71 bool readFields,
72 bool newFormat
73)
74:
75 particle(mesh, is, readFields, newFormat)
76{
77 if (readFields)
78 {
79 if (is.format() == IOstreamOption::ASCII)
80 {
81 is >> start_ >> end_ >> data_;
82 }
83 else
84 {
85 // No non-native streaming
87
88 is.read
89 (
90 reinterpret_cast<char*>(&start_),
91 sizeof(start_) + sizeof(end_) + sizeof(data_)
92 );
93 }
94 }
97}
98
99
100// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101
103(
105 trackingData& td,
106 const scalar maxTrackLen
107)
108{
109 td.switchProcessor = false;
110 td.keepParticle = true;
111
112 while (td.keepParticle && !td.switchProcessor && stepFraction() < 1)
113 {
114 const scalar f = 1 - stepFraction();
115 trackToAndHitFace(f*(end_ - start_), f, cloud, td);
116 }
117
118 // Note: stepFraction is might not be exactly 1 so check for 1 or
119 // slightly larger
120
121 if (stepFraction() >= 1 || !td.keepParticle)
122 {
123 // Hit endpoint or patch. If patch hit could do fancy stuff but just
124 // to use the patch point is good enough for now.
125 td.cellToData()[cell()].append(data());
126 td.cellToEnd()[cell()].append(position());
127 }
128
129 return td.keepParticle;
130}
131
142 trackingData& td
144{
145 // Remove particle
146 td.keepParticle = false;
147}
148
149
151(
153 trackingData& td
155{
156 // Remove particle
157 td.keepParticle = false;
158}
159
160
162(
164 trackingData& td
166{
167 // Remove particle
168 td.keepParticle = false;
169}
170
171
173(
175 trackingData& td
177{
178 // Remove particle
179 td.keepParticle = false;
180}
181
182
184(
186 trackingData& td,
187 const vector&
189{
190 // Remove particle
191 td.keepParticle = false;
192}
193
194
196(
198 trackingData& td,
199 const vector&
201{
202 // Remove particle
203 td.keepParticle = false;
204}
205
206
208(
210 trackingData& td
212{
213 // Remove particle
214 td.switchProcessor = true;
215}
216
217
219(
221 trackingData& td
222)
223{
224 // Remove particle
225 td.keepParticle = false;
226}
227
228
229// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
230
231Foam::Ostream& Foam::operator<<(Ostream& os, const findCellParticle& p)
232{
233 if (os.format() == IOstreamOption::ASCII)
234 {
236 << token::SPACE << p.start_
237 << token::SPACE << p.end_
238 << token::SPACE << p.data_;
239 }
240 else
241 {
243 os.write
244 (
245 reinterpret_cast<const char*>(&p.start_),
246 sizeof(p.start_) + sizeof(p.end_) + sizeof(p.data_)
247 );
248 }
249
251 return os;
252}
253
254
255// ************************************************************************* //
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
Class used to pass tracking data to the trackToFace function.
Particle class that finds cells by tracking.
bool hitPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a patch.
void hitWallPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a wallPatch.
void hitProcessorPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a processorPatch.
void hitSymmetryPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
void hitCyclicACMIPatch(Cloud< findCellParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicACMI.
void hitSymmetryPlanePatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
bool move(Cloud< findCellParticle > &, trackingData &, const scalar)
Track all particles to their end point.
findCellParticle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti, const point &end, const label data)
Construct from components.
label data() const noexcept
Transported label.
const point & end() const noexcept
Point to track to.
void hitWedgePatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a wedge.
void hitCyclicAMIPatch(Cloud< findCellParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicAMI.
void hitCyclicPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
Base particle class.
Definition particle.H:72
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
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
volScalarField & p
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
wallPoints::trackData td(isBlockedFace, regionToBlockSize)
#define FUNCTION_NAME
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).
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)