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-2023 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  label& nLocateBoundaryHits,
36  const vector& displacement,
37  const label data
38 )
39 :
40  particle(mesh, position, celli, nLocateBoundaryHits),
41  displacement_(displacement),
42  data_(data)
43 {}
44 
45 
47 :
48  particle(is, readFields)
49 {
50  if (readFields)
51  {
52  if (is.format() == IOstream::ASCII)
53  {
54  is >> displacement_;
55  data_ = readLabel(is);
56  }
57  else
58  {
59  is.read
60  (
61  reinterpret_cast<char*>(&displacement_),
62  sizeof(displacement_) + sizeof(data_)
63  );
64  }
65  }
66 
67  // Check state of Istream
68  is.check
69  (
70  "findCellParticle::findCellParticle"
71  "(const Cloud<findCellParticle>&, Istream&, bool)"
72  );
73 }
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
79 (
81  trackingData& td
82 )
83 {
84  td.keepParticle = true;
85  td.sendToProc = -1;
86 
87  while (td.keepParticle && td.sendToProc == -1 && stepFraction() < 1)
88  {
89  const scalar f = 1 - stepFraction();
90  trackToAndHitFace(f*displacement_, f, cloud, td);
91  }
92 
93  if (td.sendToProc == -1)
94  {
95  // Hit endpoint or patch. If patch hit could do fancy stuff but just
96  // to use the patch point is good enough for now.
97  td.cellToData()[cell()].append(data());
98  td.cellToEnd()[cell()].append(position(td.mesh));
99  }
100 
101  return td.keepParticle;
102 }
103 
104 
106 (
108  trackingData& td
109 )
110 {
111  // Remove particle
112  td.keepParticle = false;
113 }
114 
115 
117 (
119  trackingData& td
120 )
121 {
122  // Remove particle
123  td.keepParticle = false;
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  const processorPolyPatch& ppp =
156  static_cast<const processorPolyPatch&>
157  (
158  td.mesh.boundaryMesh()[patch(td.mesh)]
159  );
160 
161  if (ppp.transform().transforms())
162  {
163  td.keepParticle = false;
164  }
165  else
166  {
168  }
169 }
170 
171 
173 (
175  trackingData& td
176 )
177 {
178  // Remove particle
179  td.keepParticle = false;
180 }
181 
182 
183 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
184 
186 {
187  if (os.format() == IOstream::ASCII)
188  {
189  os << static_cast<const particle&>(p)
190  << token::SPACE << p.displacement_
191  << token::SPACE << p.data_;
192  }
193  else
194  {
195  os << static_cast<const particle&>(p);
196  os.write
197  (
198  reinterpret_cast<const char*>(&p.displacement_),
199  sizeof(p.displacement_) + sizeof(p.data_)
200  );
201  }
202 
203  // Check state of Ostream
204  os.check("Ostream& operator<<(Ostream&, const findCellParticle&)");
205 
206  return os;
207 }
208 
209 
210 // ************************************************************************* //
Base cloud calls templated on particle type.
Definition: Cloud.H:74
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
virtual Istream & read(token &)=0
Return next token from stream.
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
virtual Ostream & write(const char)=0
Write character.
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:60
A cloud is a collection of lagrangian particles.
Definition: cloud.H:55
Class used to pass tracking data to the trackToFace function.
List< List< point > > & cellToEnd()
Particle class that finds cells by tracking.
void hitWallPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a wallPatch.
findCellParticle(const polyMesh &mesh, const vector &position, const label celli, label &nLocateBoundaryHits, const vector &displacement, const label data)
Construct from a position and a cell, searching for the rest of the.
void hitProcessorPatch(Cloud< findCellParticle > &, trackingData &)
void hitSymmetryPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
void hitSymmetryPlanePatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
void hitWedgePatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a wedge.
void hitCyclicPatch(Cloud< findCellParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
bool move(Cloud< findCellParticle > &, trackingData &)
Track all particles to their end point.
label sendToProc
Processor to send the particle to. -1 indicates that this.
Definition: particle.H:113
bool keepParticle
Flag to indicate whether to keep particle (false = delete)
Definition: particle.H:109
const polyMesh & mesh
Reference to the mesh.
Definition: particle.H:106
Base particle class.
Definition: particle.H:83
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
void hitProcessorPatch(TrackCloudType &, trackingData &)
Overridable function to handle the particle hitting a.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:404
Neighbour processor patch.
virtual const transformer & transform() const
Return null transform between processor patches.
bool transforms() const
Return true if the transformer transforms a type.
Definition: transformerI.H:133
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 readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const HashSet< word > &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the specified type.
Definition: ReadFields.C:244
label readLabel(Istream &is)
Definition: label.H:64
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
labelList f(nPoints)
volScalarField & p