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 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 "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:
60 particle(mesh, position, celli),
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() == IOstream::ASCII)
80 {
81 is >> start_ >> end_ >> data_;
82 }
83 else if (!is.checkLabelSize<>() || !is.checkScalarSize<>())
84 {
85 // Non-native label or scalar size
86 is.beginRawRead();
87
88 readRawScalar(is, start_.data(), vector::nComponents);
89 readRawScalar(is, end_.data(), vector::nComponents);
90 readRawLabel(is, &data_);
91
92 is.endRawRead();
93 }
94 else
95 {
96 is.read
97 (
98 reinterpret_cast<char*>(&start_),
99 sizeof(start_) + sizeof(end_) + sizeof(data_)
100 );
101 }
102 }
103
105}
106
107
108// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109
111(
113 trackingData& td,
114 const scalar maxTrackLen
115)
116{
117 td.switchProcessor = false;
118 td.keepParticle = true;
119
120 while (td.keepParticle && !td.switchProcessor && stepFraction() < 1)
121 {
122 const scalar f = 1 - stepFraction();
123 trackToAndHitFace(f*(end_ - start_), f, cloud, td);
124 }
125
126 // Note: stepFraction is might not be exactly 1 so check for 1 or
127 // slightly larger
128
129 if (stepFraction() >= 1 || !td.keepParticle)
130 {
131 // Hit endpoint or patch. If patch hit could do fancy stuff but just
132 // to use the patch point is good enough for now.
133 td.cellToData()[cell()].append(data());
134 td.cellToEnd()[cell()].append(position());
135 }
136
137 return td.keepParticle;
138}
139
140
142{
143 return false;
144}
145
146
148(
150 trackingData& td
151)
152{
153 // Remove particle
154 td.keepParticle = false;
155}
156
157
159(
161 trackingData& td
162)
163{
164 // Remove particle
165 td.keepParticle = false;
166}
167
168
170(
172 trackingData& td
173)
174{
175 // Remove particle
176 td.keepParticle = false;
177}
178
179
181(
183 trackingData& td
184)
185{
186 // Remove particle
187 td.keepParticle = false;
188}
189
190
192(
194 trackingData& td,
195 const vector&
196)
197{
198 // Remove particle
199 td.keepParticle = false;
200}
201
202
204(
206 trackingData& td,
207 const vector&
208)
209{
210 // Remove particle
211 td.keepParticle = false;
212}
213
214
216(
218 trackingData& td
219)
220{
221 // Remove particle
222 td.switchProcessor = true;
223}
224
225
227(
229 trackingData& td
230)
231{
232 // Remove particle
233 td.keepParticle = false;
234}
235
236
237// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
238
240{
241 if (os.format() == IOstream::ASCII)
242 {
243 os << static_cast<const particle&>(p)
244 << token::SPACE << p.start_
245 << token::SPACE << p.end_
246 << token::SPACE << p.data_;
247 }
248 else
249 {
250 os << static_cast<const particle&>(p);
251 os.write
252 (
253 reinterpret_cast<const char*>(&p.start_),
254 sizeof(p.start_) + sizeof(p.end_) + sizeof(p.data_)
255 );
256 }
257
259 return os;
260}
261
262
263// ************************************************************************* //
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.
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
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
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
virtual void move()=0
Class used to pass tracking data to the trackToFace function.
List< List< point > > & cellToEnd()
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 &)
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.
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.
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
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
volScalarField & p
dynamicFvMesh & mesh
PtrList< coordinateSystem > coordinates(solidRegions.size())
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
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
labelList f(nPoints)