findCellParticle.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2022 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 vector& displacement,
38  const label data
39 )
40 :
41  particle(mesh, coordinates, celli, tetFacei, tetPtI),
42  displacement_(displacement),
43  data_(data)
44 {}
45 
46 
48 (
49  const polyMesh& mesh,
50  const vector& position,
51  const label celli,
52  const vector& displacement,
53  const label data
54 )
55 :
56  particle(mesh, position, celli),
57  displacement_(displacement),
58  data_(data)
59 {}
60 
61 
63 (
64  const polyMesh& mesh,
65  Istream& is,
66  bool readFields
67 )
68 :
69  particle(mesh, is, readFields)
70 {
71  if (readFields)
72  {
73  if (is.format() == IOstream::ASCII)
74  {
75  is >> displacement_;
76  data_ = readLabel(is);
77  }
78  else
79  {
80  is.read
81  (
82  reinterpret_cast<char*>(&displacement_),
83  sizeof(displacement_) + sizeof(data_)
84  );
85  }
86  }
87 
88  // Check state of Istream
89  is.check
90  (
91  "findCellParticle::findCellParticle"
92  "(const Cloud<findCellParticle>&, Istream&, bool)"
93  );
94 }
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
100 (
102  trackingData& td,
103  const scalar maxTrackLen
104 )
105 {
106  td.keepParticle = true;
107  td.sendToProc = -1;
108 
109  while (td.keepParticle && td.sendToProc == -1 && stepFraction() < 1)
110  {
111  const scalar f = 1 - stepFraction();
112  trackToAndHitFace(f*displacement_, f, cloud, td);
113  }
114 
115  if (td.sendToProc == -1)
116  {
117  // Hit endpoint or patch. If patch hit could do fancy stuff but just
118  // to use the patch point is good enough for now.
119  td.cellToData()[cell()].append(data());
120  td.cellToEnd()[cell()].append(position());
121  }
122 
123  return td.keepParticle;
124 }
125 
126 
128 (
130  trackingData& td
131 )
132 {
133  // Remove particle
134  td.keepParticle = false;
135 }
136 
137 
139 (
141  trackingData& td
142 )
143 {
144  // Remove particle
145  td.keepParticle = false;
146 }
147 
148 
150 (
152  trackingData& td
153 )
154 {
155  // Remove particle
156  td.keepParticle = false;
157 }
158 
159 
161 (
163  trackingData& td
164 )
165 {
166  // Remove particle
167  td.keepParticle = false;
168 }
169 
170 
172 (
173  const vector&,
174  const scalar,
176  trackingData& td
177 )
178 {
179  // Remove particle
180  td.keepParticle = false;
181 }
182 
183 
185 (
187  trackingData& td
188 )
189 {
190  const processorPolyPatch& ppp =
191  static_cast<const processorPolyPatch&>(mesh().boundaryMesh()[patch()]);
192 
193  if (ppp.transform().transforms())
194  {
195  td.keepParticle = false;
196  }
197  else
198  {
199  particle::hitProcessorPatch(cloud, td);
200  }
201 }
202 
203 
205 (
207  trackingData& td
208 )
209 {
210  // Remove particle
211  td.keepParticle = false;
212 }
213 
214 
215 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
216 
218 {
219  if (os.format() == IOstream::ASCII)
220  {
221  os << static_cast<const particle&>(p)
222  << token::SPACE << p.displacement_
223  << token::SPACE << p.data_;
224  }
225  else
226  {
227  os << static_cast<const particle&>(p);
228  os.write
229  (
230  reinterpret_cast<const char*>(&p.displacement_),
231  sizeof(p.displacement_) + sizeof(p.data_)
232  );
233  }
234 
235  // Check state of Ostream
236  os.check("Ostream& operator<<(Ostream&, const findCellParticle&)");
237 
238  return os;
239 }
240 
241 
242 // ************************************************************************* //
virtual Ostream & write(const char)=0
Write character.
bool move(Cloud< findCellParticle > &, trackingData &, const scalar)
Track all particles to their end point.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
bool transforms() const
Return true if the transformer transforms a type.
Definition: transformerI.H:133
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
fvMesh & mesh
void hitCyclicPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
void hitSymmetryPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
Base particle class.
Definition: particle.H:81
Neighbour processor patch.
void hitProcessorPatch(Cloud< findCellParticle > &, trackingData &)
void hitWedgePatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a wedge.
virtual Istream & read(token &)=0
Return next token from stream.
findCellParticle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPtI, const vector &displacement, const label data)
Construct from components.
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
label readLabel(Istream &is)
Definition: label.H:64
Base cloud calls templated on particle type.
Definition: Cloud.H:52
void hitCyclicAMIPatch(const vector &, const scalar, Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclicAMI.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
labelList f(nPoints)
List< List< point > > & cellToEnd()
virtual const transformer & transform() const
Return null transform between processor patches.
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:107
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:57
Ostream & operator<<(Ostream &, const ensightPart &)
Particle class that finds cells by tracking.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
volScalarField & p
void hitWallPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a wallPatch.
label sendToProc
Processor to send the particle to. -1 indicates that this.
Definition: particle.H:111
Class used to pass tracking data to the trackToFace function.
void hitSymmetryPlanePatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a.