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-2016 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 vector& position,
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, position, celli, tetFacei, tetPtI),
42  end_(end),
43  data_(data)
44 {}
45 
46 
48 (
49  const polyMesh& mesh,
50  Istream& is,
51  bool readFields
52 )
53 :
54  particle(mesh, is, readFields)
55 {
56  if (readFields)
57  {
58  if (is.format() == IOstream::ASCII)
59  {
60  is >> end_;
61  data_ = readLabel(is);
62  }
63  else
64  {
65  is.read
66  (
67  reinterpret_cast<char*>(&end_),
68  sizeof(end_) + sizeof(data_)
69  );
70  }
71  }
72 
73  // Check state of Istream
74  is.check
75  (
76  "findCellParticle::findCellParticle"
77  "(const Cloud<findCellParticle>&, Istream&, bool)"
78  );
79 }
80 
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
85 (
86  trackingData& td,
87  const scalar maxTrackLen
88 )
89 {
90  td.switchProcessor = false;
91  td.keepParticle = true;
92 
93  scalar tEnd = (1.0 - stepFraction())*maxTrackLen;
94  scalar dtMax = tEnd;
95 
96  while (td.keepParticle && !td.switchProcessor && tEnd > SMALL)
97  {
98  // set the lagrangian time-step
99  scalar dt = min(dtMax, tEnd);
100 
101  dt *= trackToFace(end_, td);
102 
103  tEnd -= dt;
104  stepFraction() = 1.0 - tEnd/maxTrackLen;
105  }
106 
107  if (tEnd < SMALL || !td.keepParticle)
108  {
109  // Hit endpoint or patch. If patch hit could do fancy stuff but just
110  // to use the patch point is good enough for now.
111  td.cellToData()[cell()].append(data());
112  td.cellToEnd()[cell()].append(position());
113  }
114 
115  return td.keepParticle;
116 }
117 
118 
120 (
121  const polyPatch&,
122  trackingData& td,
123  const label patchi,
124  const scalar trackFraction,
125  const tetIndices& tetIs
126 )
127 {
128  return false;
129 }
130 
131 
133 (
134  const wedgePolyPatch&,
135  trackingData& td
136 )
137 {
138  // Remove particle
139  td.keepParticle = false;
140 }
141 
142 
144 (
145  const symmetryPlanePolyPatch&,
146  trackingData& td
147 )
148 {
149  // Remove particle
150  td.keepParticle = false;
151 }
152 
153 
155 (
156  const symmetryPolyPatch&,
157  trackingData& td
158 )
159 {
160  // Remove particle
161  td.keepParticle = false;
162 }
163 
164 
166 (
167  const cyclicPolyPatch&,
168  trackingData& td
169 )
170 {
171  // Remove particle
172  td.keepParticle = false;
173 }
174 
175 
177 (
178  const processorPolyPatch&,
179  trackingData& td
180 )
181 {
182  // Remove particle
183  td.switchProcessor = true;
184 }
185 
186 
188 (
189  const wallPolyPatch& wpp,
190  trackingData& td,
191  const tetIndices&
192 )
193 {
194  // Remove particle
195  td.keepParticle = false;
196 }
197 
198 
200 (
201  const polyPatch& wpp,
202  trackingData& td
203 )
204 {
205  // Remove particle
206  td.keepParticle = false;
207 }
208 
209 
210 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
211 
213 {
214  if (os.format() == IOstream::ASCII)
215  {
216  os << static_cast<const particle&>(p)
217  << token::SPACE << p.end_
218  << token::SPACE << p.data_;
219  }
220  else
221  {
222  os << static_cast<const particle&>(p);
223  os.write
224  (
225  reinterpret_cast<const char*>(&p.end_),
226  sizeof(p.end_) + sizeof(p.data_)
227  );
228  }
229 
230  // Check state of Ostream
231  os.check("Ostream& operator<<(Ostream&, const findCellParticle&)");
232 
233  return os;
234 }
235 
236 
237 // ************************************************************************* //
Symmetry patch for non-planar or multi-plane patches.
void hitWedgePatch(const wedgePolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a wedge.
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
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.
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
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
findCellParticle(const polyMesh &mesh, const vector &position, const label celli, const label tetFacei, const label tetPtI, const point &end, const label data)
Construct from components.
Base particle class.
Definition: particle.H:78
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:97
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
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:112
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
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
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:109
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.