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 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 :
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 // ************************************************************************* //
Foam::IOstream::format
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
Foam::findCellParticle::hitWallPatch
void hitWallPatch(const wallPolyPatch &, trackingData &td, const tetIndices &)
Overridable function to handle the particle hitting a wallPatch.
Definition: findCellParticle.C:188
p
p
Definition: pEqn.H:62
Foam::wedgePolyPatch
Wedge front and back plane patch.
Definition: wedgePolyPatch.H:48
Foam::cyclicPolyPatch
Cyclic plane patch.
Definition: cyclicPolyPatch.H:63
Foam::findCellParticle::hitSymmetryPlanePatch
void hitSymmetryPlanePatch(const symmetryPlanePolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a.
Definition: findCellParticle.C:144
Foam::particle::TrackingData::keepParticle
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:112
Foam::findCellParticle::trackingData::cellToEnd
List< List< point > > & cellToEnd()
Definition: findCellParticle.H:100
Foam::findCellParticle::hitCyclicPatch
void hitCyclicPatch(const cyclicPolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a cyclic.
Definition: findCellParticle.C:166
Foam::readFields
This function object reads fields from the time directories and adds them to the mesh database for fu...
Definition: readFields.H:104
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::label
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
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::List::append
void append(const T &)
Append an element at the end of the list.
Foam::Ostream::write
virtual Ostream & write(const token &)=0
Write next token to stream.
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::findCellParticle::hitProcessorPatch
void hitProcessorPatch(const processorPolyPatch &, trackingData &td)
Definition: findCellParticle.C:177
Foam::symmetryPlanePolyPatch
Symmetry-plane patch.
Definition: symmetryPlanePolyPatch.H:48
Foam::symmetryPolyPatch
Symmetry patch for non-planar or multi-plane patches.
Definition: symmetryPolyPatch.H:51
Foam::processorPolyPatch
Neighbour processor patch.
Definition: processorPolyPatch.H:55
Foam::findCellParticle::trackingData::cellToData
labelListList & cellToData()
Definition: findCellParticle.H:95
findCellParticle.H
Foam::findCellParticle
Particle class that finds cells by tracking.
Definition: findCellParticle.H:51
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::wallPolyPatch
Foam::wallPolyPatch.
Definition: wallPolyPatch.H:48
Foam::findCellParticle::findCellParticle
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.
Definition: findCellParticle.C:31
Foam::particle::TrackingData::switchProcessor
bool switchProcessor
Flag to switch processor.
Definition: particle.H:109
Foam::tetIndices
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Definition: tetIndices.H:73
Foam::findCellParticle::hitSymmetryPatch
void hitSymmetryPatch(const symmetryPolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a.
Definition: findCellParticle.C:155
Foam::Vector< scalar >
Foam::particle
Base particle class.
Definition: particle.H:78
Foam::findCellParticle::hitPatch
bool hitPatch(const polyPatch &, trackingData &td, const label patchI, const scalar trackFraction, const tetIndices &tetIs)
Overridable function to handle the particle hitting a patch.
Definition: findCellParticle.C:120
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
Foam::findCellParticle::hitWedgePatch
void hitWedgePatch(const wedgePolyPatch &, trackingData &td)
Overridable function to handle the particle hitting a wedge.
Definition: findCellParticle.C:133
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::findCellParticle::move
bool move(trackingData &, const scalar)
Track all particles to their end point.
Definition: findCellParticle.C:85
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
Foam::findCellParticle::trackingData
Class used to pass tracking data to the trackToFace function.
Definition: findCellParticle.H:69
Foam::Istream::read
virtual Istream & read(token &)=0
Return next token from stream.