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-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 "trackedParticle.H"
27 
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 (
33  const polyMesh& mesh,
34  const vector& position,
35  const label celli,
36  label& nLocateBoundaryHits,
37  const point& end,
38  const label level,
39  const label i,
40  const label j,
41  const label k
42 )
43 :
44  particle(mesh, position, celli, nLocateBoundaryHits),
45  start_(this->position(mesh)),
46  end_(end),
47  level_(level),
48  i_(i),
49  j_(j),
50  k_(k)
51 {}
52 
53 
55 :
56  particle(is, readFields)
57 {
58  if (readFields)
59  {
60  if (is.format() == IOstream::ASCII)
61  {
62  is >> start_ >> end_;
63  level_ = readLabel(is);
64  i_ = readLabel(is);
65  j_ = readLabel(is);
66  k_ = readLabel(is);
67  }
68  else
69  {
70  is.read
71  (
72  reinterpret_cast<char*>(&start_),
73  sizeof(start_) + sizeof(end_) + sizeof(level_)
74  + sizeof(i_) + sizeof(j_) + sizeof(k_)
75  );
76  }
77  }
78 
79  // Check state of Istream
80  is.check
81  (
82  "trackedParticle::trackedParticle"
83  "(const Cloud<trackedParticle>&, Istream&, bool)"
84  );
85 }
86 
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
91 (
93  trackingData& td
94 )
95 {
96  const scalar tEnd = (1.0 - stepFraction())*td.maxTrackLen_;
97 
98  if (tEnd <= small && onBoundaryFace(td.mesh))
99  {
100  // This is a hack to handle particles reaching their endpoint on a
101  // processor boundary. This prevents a particle being endlessly
102  // transferred backwards and forwards across the interface.
103  td.keepParticle = false;
104  td.sendToProc = -1;
105  }
106  else
107  {
108  td.keepParticle = true;
109  td.sendToProc = -1;
110 
111  while (td.keepParticle && td.sendToProc == -1 && stepFraction() < 1)
112  {
113  // mark visited cell with max level.
114  td.maxLevel_[cell()] = max(td.maxLevel_[cell()], level_);
115 
116  const scalar f = 1 - stepFraction();
117  const vector s = end_ - start_;
118  trackToAndHitFace(f*s, f, cloud, td);
119  }
120  }
121 
122  return td.keepParticle;
123 }
124 
125 
127 (
129  trackingData& td
130 )
131 {
132  // Remove particle
133  td.keepParticle = false;
134 }
135 
136 
138 (
140  trackingData& td
141 )
142 {
143  // Remove particle
144  td.keepParticle = false;
145 }
146 
147 
149 (
151  trackingData& td
152 )
153 {
154  // Remove particle
155  td.keepParticle = false;
156 }
157 
158 
160 (
162  trackingData& td
163 )
164 {
165  // Remove particle
166  td.keepParticle = false;
167 }
168 
169 
171 (
173  trackingData& td
174 )
175 {
176  // Remove particle
177  td.keepParticle = false;
178 }
179 
180 
182 (
184  trackingData& td
185 )
186 {
188 
189  // Mark edge we are currently on (if any). This was set on the sending
190  // processor but has not yet been set on the receiving side.
191  const label feati = i(), edgei = k();
192  if (edgei != -1)
193  {
194  td.featureEdgeVisited_[feati].set(edgei, 1u);
195  }
196 }
197 
198 
199 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
200 
202 {
203  if (os.format() == IOstream::ASCII)
204  {
205  os << static_cast<const particle&>(p)
206  << token::SPACE << p.start_
207  << token::SPACE << p.end_
208  << token::SPACE << p.level_
209  << token::SPACE << p.i_
210  << token::SPACE << p.j_
211  << token::SPACE << p.k_;
212  }
213  else
214  {
215  os << static_cast<const particle&>(p);
216  os.write
217  (
218  reinterpret_cast<const char*>(&p.start_),
219  sizeof(p.start_) + sizeof(p.end_) + sizeof(p.level_)
220  + sizeof(p.i_) + sizeof(p.j_) + sizeof(p.k_)
221  );
222  }
223 
224  // Check state of Ostream
225  os.check("Ostream& operator<<(Ostream&, const trackedParticle&)");
226 
227  return os;
228 }
229 
230 
231 // ************************************************************************* //
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.
trackedParticle(const polyMesh &mesh, const vector &position, const label celli, label &nLocateBoundaryHits, 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 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.
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 &os, const fvConstraints &constraints)
labelList f(nPoints)
volScalarField & p