trackedParticle.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) 2011-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 "trackedParticle.H"
27 
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 (
33  const polyMesh& mesh,
34  const vector& position,
35  const label celli,
36  const point& end,
37  const label level,
38  const label i,
39  const label j,
40  const label k
41 )
42 :
43  particle(mesh, position, celli),
44  start_(this->position(mesh)),
45  end_(end),
46  level_(level),
47  i_(i),
48  j_(j),
49  k_(k)
50 {}
51 
52 
54 :
55  particle(is, readFields)
56 {
57  if (readFields)
58  {
59  if (is.format() == IOstream::ASCII)
60  {
61  is >> start_ >> end_;
62  level_ = readLabel(is);
63  i_ = readLabel(is);
64  j_ = readLabel(is);
65  k_ = readLabel(is);
66  }
67  else
68  {
69  is.read
70  (
71  reinterpret_cast<char*>(&start_),
72  sizeof(start_) + sizeof(end_) + sizeof(level_)
73  + sizeof(i_) + sizeof(j_) + sizeof(k_)
74  );
75  }
76  }
77 
78  // Check state of Istream
79  is.check
80  (
81  "trackedParticle::trackedParticle"
82  "(const Cloud<trackedParticle>&, Istream&, bool)"
83  );
84 }
85 
86 
87 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88 
90 (
92  trackingData& td
93 )
94 {
95  const scalar tEnd = (1.0 - stepFraction())*td.maxTrackLen_;
96 
97  if (tEnd <= small && onBoundaryFace(td.mesh))
98  {
99  // This is a hack to handle particles reaching their endpoint on a
100  // processor boundary. This prevents a particle being endlessly
101  // transferred backwards and forwards across the interface.
102  td.keepParticle = false;
103  td.sendToProc = -1;
104  }
105  else
106  {
107  td.keepParticle = true;
108  td.sendToProc = -1;
109 
110  while (td.keepParticle && td.sendToProc == -1 && stepFraction() < 1)
111  {
112  // mark visited cell with max level.
113  td.maxLevel_[cell()] = max(td.maxLevel_[cell()], level_);
114 
115  const scalar f = 1 - stepFraction();
116  const vector s = end_ - start_;
117  trackToAndHitFace(f*s, f, cloud, td);
118  }
119  }
120 
121  return td.keepParticle;
122 }
123 
124 
126 (
128  trackingData& td
129 )
130 {
131  // Remove particle
132  td.keepParticle = false;
133 }
134 
135 
137 (
139  trackingData& td
140 )
141 {
142  // Remove particle
143  td.keepParticle = false;
144 }
145 
146 
148 (
150  trackingData& td
151 )
152 {
153  // Remove particle
154  td.keepParticle = false;
155 }
156 
157 
159 (
161  trackingData& td
162 )
163 {
164  // Remove particle
165  td.keepParticle = false;
166 }
167 
168 
170 (
172  trackingData& td
173 )
174 {
175  // Remove particle
176  td.keepParticle = false;
177 }
178 
179 
181 (
183  trackingData& td
184 )
185 {
187 
188  // Mark edge we are currently on (if any). This was set on the sending
189  // processor but has not yet been set on the receiving side.
190  const label feati = i(), edgei = k();
191  if (edgei != -1)
192  {
193  td.featureEdgeVisited_[feati].set(edgei, 1u);
194  }
195 }
196 
197 
198 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
199 
201 {
202  if (os.format() == IOstream::ASCII)
203  {
204  os << static_cast<const particle&>(p)
205  << token::SPACE << p.start_
206  << token::SPACE << p.end_
207  << token::SPACE << p.level_
208  << token::SPACE << p.i_
209  << token::SPACE << p.j_
210  << token::SPACE << p.k_;
211  }
212  else
213  {
214  os << static_cast<const particle&>(p);
215  os.write
216  (
217  reinterpret_cast<const char*>(&p.start_),
218  sizeof(p.start_) + sizeof(p.end_) + sizeof(p.level_)
219  + sizeof(p.i_) + sizeof(p.j_) + sizeof(p.k_)
220  );
221  }
222 
223  // Check state of Ostream
224  os.check("Ostream& operator<<(Ostream&, const trackedParticle&)");
225 
226  return os;
227 }
228 
229 
230 // ************************************************************************* //
label k
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.
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
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 correctAfterParallelTransfer(TrackCloudType &, trackingData &)
Make changes following a parallel transfer. Runs either.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class used to pass tracking data to the trackToFace function.
List< PackedBoolList > & featureEdgeVisited_
Particle class that marks cells it passes through. Used to mark cells visited by feature edges.
void hitWedgePatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wedge.
void hitSymmetryPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
void hitSymmetryPlanePatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a.
trackedParticle(const polyMesh &mesh, const vector &position, const label celli, const point &end, const label level, const label i, const label j, const label k)
Construct from a position and a cell, searching for the rest of the.
void hitWallPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a wallPatch.
void correctAfterParallelTransfer(Cloud< trackedParticle > &, trackingData &)
Do corrections to the particle and tracking data following a.
void hitCyclicPatch(Cloud< trackedParticle > &, trackingData &)
Overridable function to handle the particle hitting a cyclic.
bool move(Cloud< trackedParticle > &, trackingData &)
Track all particles to their end point.
if(!fvConstraints.PtrListDictionary< fvConstraint >::size())
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
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
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
label readLabel(Istream &is)
Definition: label.H:64
Ostream & operator<<(Ostream &, const ensightPart &)
labelList f(nPoints)
volScalarField & p