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 | Copyright (C) 2013-2017 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "findCellParticle.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 (
32  const polyMesh& mesh,
33  const barycentric& coordinates,
34  const label celli,
35  const label tetFacei,
36  const label tetPtI,
37  const point& end,
38  const label data
39 )
40 :
41  particle(mesh, coordinates, celli, tetFacei, tetPtI),
42  start_(position()),
43  end_(end),
44  data_(data)
45 {}
46 
47 
49 (
50  const polyMesh& mesh,
51  const vector& position,
52  const label celli,
53  const point& end,
54  const label data
55 )
56 :
57  particle(mesh, position, celli),
58  start_(this->position()),
59  end_(end),
60  data_(data)
61 {}
62 
63 
65 (
66  const polyMesh& mesh,
67  Istream& is,
68  bool readFields
69 )
70 :
71  particle(mesh, is, readFields)
72 {
73  if (readFields)
74  {
75  if (is.format() == IOstream::ASCII)
76  {
77  is >> start_ >> end_;
78  data_ = readLabel(is);
79  }
80  else
81  {
82  is.read
83  (
84  reinterpret_cast<char*>(&start_),
85  sizeof(start_) + sizeof(end_) + sizeof(data_)
86  );
87  }
88  }
89 
90  // Check state of Istream
91  is.check
92  (
93  "findCellParticle::findCellParticle"
94  "(const Cloud<findCellParticle>&, Istream&, bool)"
95  );
96 }
97 
98 
99 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 
102 (
103  trackingData& td,
104  const scalar maxTrackLen
105 )
106 {
107  td.switchProcessor = false;
108  td.keepParticle = true;
109 
110  while (td.keepParticle && !td.switchProcessor && stepFraction() < 1)
111  {
112  const scalar f = 1 - stepFraction();
113  trackToFace(f*(end_ - start_), f, td);
114  }
115 
116  if (stepFraction() == 1 || !td.keepParticle)
117  {
118  // Hit endpoint or patch. If patch hit could do fancy stuff but just
119  // to use the patch point is good enough for now.
120  td.cellToData()[cell()].append(data());
121  td.cellToEnd()[cell()].append(position());
122  }
123 
124  return td.keepParticle;
125 }
126 
127 
129 (
130  const polyPatch&,
131  trackingData& td,
132  const label patchi,
133  const scalar trackFraction,
134  const tetIndices& tetIs
135 )
136 {
137  return false;
138 }
139 
140 
142 (
143  const wedgePolyPatch&,
144  trackingData& td
145 )
146 {
147  // Remove particle
148  td.keepParticle = false;
149 }
150 
151 
153 (
154  const symmetryPlanePolyPatch&,
155  trackingData& td
156 )
157 {
158  // Remove particle
159  td.keepParticle = false;
160 }
161 
162 
164 (
165  const symmetryPolyPatch&,
166  trackingData& td
167 )
168 {
169  // Remove particle
170  td.keepParticle = false;
171 }
172 
173 
175 (
176  const cyclicPolyPatch&,
177  trackingData& td
178 )
179 {
180  // Remove particle
181  td.keepParticle = false;
182 }
183 
184 
186 (
187  const processorPolyPatch&,
188  trackingData& td
189 )
190 {
191  // Remove particle
192  td.switchProcessor = true;
193 }
194 
195 
197 (
198  const wallPolyPatch& wpp,
199  trackingData& td,
200  const tetIndices&
201 )
202 {
203  // Remove particle
204  td.keepParticle = false;
205 }
206 
207 
209 (
210  const polyPatch& wpp,
211  trackingData& td
212 )
213 {
214  // Remove particle
215  td.keepParticle = false;
216 }
217 
218 
219 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
220 
222 {
223  if (os.format() == IOstream::ASCII)
224  {
225  os << static_cast<const particle&>(p)
226  << token::SPACE << p.start_
227  << token::SPACE << p.end_
228  << token::SPACE << p.data_;
229  }
230  else
231  {
232  os << static_cast<const particle&>(p);
233  os.write
234  (
235  reinterpret_cast<const char*>(&p.start_),
236  sizeof(p.start_) + sizeof(p.end_) + sizeof(p.data_)
237  );
238  }
239 
240  // Check state of Ostream
241  os.check("Ostream& operator<<(Ostream&, const findCellParticle&)");
242 
243  return os;
244 }
245 
246 
247 // ************************************************************************* //
Symmetry patch for non-planar or multi-plane patches.
void hitWedgePatch(const wedgePolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a wedge.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void hitSymmetryPatch(const symmetryPolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
void hitCyclicPatch(const cyclicPolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a cyclic.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
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.
Base particle class.
Definition: particle.H:81
Neighbour processor patch.
bool hitPatch(const polyPatch &, trackingData &td, const label patchi, const scalar trackFraction, const tetIndices &tetIs)
Overridable function to handle the particle hitting a patch.
virtual Istream & read(token &)=0
Return next token from stream.
Cyclic plane patch.
Foam::wallPolyPatch.
Definition: wallPolyPatch.H:48
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:184
Wedge front and back plane patch.
void hitProcessorPatch(const processorPolyPatch &, trackingData &td)
Storage and named access for the indices of a tet which is part of the decomposition of a cell...
Definition: tetIndices.H:81
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:125
void hitWallPatch(const wallPolyPatch &, trackingData &td, const tetIndices &)
Overridable function to handle the particle hitting a wallPatch.
label readLabel(Istream &is)
Definition: label.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
labelList f(nPoints)
List< List< point > > & cellToEnd()
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Ostream & operator<<(Ostream &, const ensightPart &)
Particle class that finds cells by tracking.
virtual Ostream & write(const token &)=0
Write next token to stream.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
void hitSymmetryPlanePatch(const symmetryPlanePolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a.
volScalarField & p
bool switchProcessor
Flag to switch processor.
Definition: particle.H:122
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Class used to pass tracking data to the trackToFace function.
bool move(trackingData &, const scalar)
Track all particles to their end point.