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 -------------------------------------------------------------------------------
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 "findCellParticle.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 (
35  const polyMesh& mesh,
36  const barycentric& coordinates,
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 
104  is.check(FUNCTION_NAME);
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 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::findCellParticle::hitProcessorPatch
void hitProcessorPatch(Cloud< findCellParticle > &, trackingData &)
Definition: findCellParticle.C:216
Foam::findCellParticle::trackingData::cellToEnd
List< List< point > > & cellToEnd()
Definition: findCellParticle.H:111
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:286
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
Foam::OBJstream::write
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
Foam::findCellParticle::hitSymmetryPatch
void hitSymmetryPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
Definition: findCellParticle.C:170
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::IOstream::checkLabelSize
std::enable_if< std::is_integral< T >::value, bool >::type checkLabelSize() const noexcept
Definition: IOstream.H:300
Foam::Istream::endRawRead
virtual bool endRawRead()=0
End of low-level raw binary read.
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::findCellParticle::move
bool move(Cloud< findCellParticle > &, trackingData &, const scalar)
Track all particles to their end point.
Definition: findCellParticle.C:111
coordinates
PtrList< coordinateSystem > coordinates(solidRegions.size())
Foam::Barycentric< scalar >
Foam::particle::trackingData::keepParticle
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:105
Foam::particle::trackingData::switchProcessor
bool switchProcessor
Flag to switch processor.
Definition: particle.H:102
Foam::findCellParticle::trackingData::cellToData
labelListList & cellToData()
Definition: findCellParticle.H:106
findCellParticle.H
Foam::findCellParticle::hitWallPatch
void hitWallPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a wallPatch.
Definition: findCellParticle.C:227
Foam::findCellParticle::findCellParticle
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.
Definition: findCellParticle.C:34
Foam::findCellParticle
Particle class that finds cells by tracking.
Definition: findCellParticle.H:59
Foam::IOstream::checkScalarSize
std::enable_if< std::is_floating_point< T >::value, bool >::type checkScalarSize() const noexcept
Definition: IOstream.H:309
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::findCellParticle::hitCyclicAMIPatch
void hitCyclicAMIPatch(Cloud< findCellParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicAMI.
Definition: findCellParticle.C:192
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam::findCellParticle::hitSymmetryPlanePatch
void hitSymmetryPlanePatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
Definition: findCellParticle.C:159
Foam::findCellParticle::hitCyclicPatch
void hitCyclicPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
Definition: findCellParticle.C:181
Foam::readFields
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
Definition: ReadFieldsTemplates.C:312
Foam::findCellParticle::hitWedgePatch
void hitWedgePatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a wedge.
Definition: findCellParticle.C:148
Foam::cloud
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:57
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
Foam::Istream::beginRawRead
virtual bool beginRawRead()=0
Start of low-level raw binary read.
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
Foam::particle
Base particle class.
Definition: particle.H:76
Foam::Cloud
Base cloud calls templated on particle type.
Definition: Cloud.H:55
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::readRawLabel
label readRawLabel(Istream &is)
Read raw label from binary stream.
Definition: label.C:46
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::findCellParticle::hitCyclicACMIPatch
void hitCyclicACMIPatch(Cloud< findCellParticle > &, trackingData &, const vector &)
Overridable function to handle the particle hitting a cyclicACMI.
Definition: findCellParticle.C:204
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55
Foam::findCellParticle::hitPatch
bool hitPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a patch.
Definition: findCellParticle.C:141
Foam::findCellParticle::trackingData
Class used to pass tracking data to the trackToFace function.
Definition: findCellParticle.H:80
Foam::Istream::read
virtual Istream & read(token &)=0
Return next token from stream.