sampledSetParticle.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) 2021-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 "sampledSetParticle.H"
27 #include "sampledSetCloud.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 (
33  const polyMesh& mesh,
34  const point& position,
35  const label celli,
36  const label seti,
37  const scalar setF,
38  const scalar distance
39 )
40 :
41  particle(mesh, position, celli),
42  seti_(seti),
43  setF_(setF),
44  distance_(distance),
45  havePosition0_(false),
46  position0_(point::uniform(NaN))
47 {}
48 
49 
51 (
52  const polyMesh& mesh,
53  Istream& is,
54  bool readFields
55 )
56 :
57  particle(mesh, is, readFields)
58 {
59  if (readFields)
60  {
61  is >> seti_ >> setF_ >> distance_ >> havePosition0_ >> position0_;
62  }
63 
64  is.check(FUNCTION_NAME);
65 }
66 
67 
69 (
70  const sampledSetParticle& p
71 )
72 :
73  particle(p),
74  seti_(p.seti_),
75  setF_(p.setF_),
76  distance_(p.distance_),
77  havePosition0_(p.havePosition0_),
78  position0_(p.position0_)
79 {}
80 
81 
82 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
83 
85 (
86  sampledSetCloud& cloud,
87  trackingData& td
88 )
89 {
90  td.positions_.append(position());
91  td.distances_.append(distance_);
92  td.cells_.append(cell());
93  td.faces_.append(face());
94 }
95 
96 
98 (
99  sampledSetCloud& cloud,
100  trackingData& td
101 )
102 {
103  store(cloud, td);
104 }
105 
106 
108 (
109  sampledSetCloud& cloud,
110  trackingData& td
111 )
112 {
113  if (havePosition0_)
114  {
115  td.positions_.append((position() + position0_)/2);
116  td.distances_.append(distance_ - mag(position() - position0_)/2);
117  td.cells_.append(cell());
118  td.faces_.append(-1);
119  }
120 
121  havePosition0_ = true;
122  position0_ = position();
123 }
124 
125 
127 (
128  sampledSetCloud& cloud,
129  trackingData& td,
130  const scalar
131 )
132 {
133  td.keepParticle = true;
134  td.sendToProc = -1;
135 
136  while (td.keepParticle && td.sendToProc == -1 && seti_ < td.set_.size() - 1)
137  {
138  const vector s = td.set_[seti_ + 1] - td.set_[seti_];
139  const scalar magS = mag(s);
140 
141  const scalar f = trackToFace(setF_*s, 0);
142  distance_ += (1 - f)*setF_*magS;
143  setF_ *= f;
144 
145  while (onInternalFace())
146  {
147  if (td.storeCells_) storeCell(cloud, td);
148  if (td.storeFaces_) storeFace(cloud, td);
149 
150  hitFace(setF_*s, 0, cloud, td);
151 
152  const scalar f = trackToFace(setF_*s, 0);
153  distance_ += (1 - f)*setF_*magS;
154  setF_ *= f;
155  }
156 
157  if (onFace())
158  {
159  if (td.storeCells_) storeCell(cloud, td);
160  if (td.storeFaces_) storeFace(cloud, td);
161 
162  hitFace(setF_*s, 0, cloud, td);
163  }
164 
165  if (onBoundaryFace() && setF_ < rootSmall)
166  {
167  if (td.storeSet_) store(cloud, td);
168  }
169 
170  if (!onFace())
171  {
172  if (td.storeSet_) store(cloud, td);
173 
174  ++ seti_;
175  setF_ = 1;
176  }
177  }
178 
179  return true;
180 }
181 
182 
184 (
186  trackingData& td
187 )
188 {
189  seti_ = labelMax;
190 }
191 
192 
194 (
196  trackingData& td
197 )
198 {
199  seti_ = labelMax;
200 }
201 
202 
204 (
206  trackingData& td
207 )
208 {
209  seti_ = labelMax;
210 }
211 
212 
214 (
215  sampledSetCloud& cloud,
216  trackingData& td
217 )
218 {
219  seti_ = labelMax;
220 }
221 
222 
224 (
225  const vector& displacement,
226  const scalar fraction,
227  sampledSetCloud& cloud,
228  trackingData& td
229 )
230 {
231  seti_ = labelMax;
232 }
233 
234 
236 (
237  sampledSetCloud& cloud,
238  trackingData& td
239 )
240 {
241  const processorPolyPatch& ppp =
242  static_cast<const processorPolyPatch&>(mesh().boundaryMesh()[patch()]);
243 
244  if (ppp.transform().transformsPosition())
245  {
246  seti_ = labelMax;
247  }
248  else
249  {
250  particle::hitProcessorPatch(cloud, td);
251  }
252 }
253 
254 
256 (
258  trackingData& td
259 )
260 {
261  seti_ = labelMax;
262 }
263 
264 
265 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
266 
268 {
269  os << static_cast<const particle&>(p)
270  << token::SPACE << p.seti_
271  << token::SPACE << p.setF_
272  << token::SPACE << p.distance_
273  << token::SPACE << p.havePosition0_
274  << token::SPACE << p.position0_;
275 
276  os.check(FUNCTION_NAME);
277 
278  return os;
279 }
280 
281 
282 // ************************************************************************* //
bool move(sampledSetCloud &, trackingData &, const scalar)
Track all particles to their end point.
Particle for generating line-type sampled sets.
DynamicList< label > & faces_
Stored face indices.
void hitSymmetryPlanePatch(sampledSetCloud &, trackingData &)
Hit a symmetry patch. Ends the track.
void store(sampledSetCloud &, trackingData &)
Store a point.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
void hitCyclicAMIPatch(const vector &, const scalar, sampledSetCloud &, trackingData &)
Hit a cyclicAMI patch. Ends the track.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
void hitSymmetryPatch(sampledSetCloud &, trackingData &)
Hit a symmetry plane patch. Ends the track.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const bool storeCells_
Are we storing the cells we track through?
DynamicList< point > & positions_
Stored positions.
void hitProcessorPatch(sampledSetCloud &, trackingData &)
Hit a processor patch. Transfers the particle if there is no.
void storeFace(sampledSetCloud &, trackingData &)
Store a point on a face.
fvMesh & mesh
Base particle class.
Definition: particle.H:81
Neighbour processor patch.
void storeCell(sampledSetCloud &, trackingData &)
Store a point in a cell.
const bool storeFaces_
Are we storing the faces we track through?
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.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
void hitCyclicPatch(sampledSetCloud &, trackingData &)
Hit a cyclic patch. Ends the track.
A Cloud of sampledSet particles.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
const bool storeSet_
Are we storing the set points?
static const label labelMax
Definition: label.H:62
DynamicList< label > & cells_
Stored cell indices.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
#define FUNCTION_NAME
labelList f(nPoints)
bool transformsPosition() const
Return true if the transformer transforms a point.
Definition: transformerI.H:146
DynamicList< scalar > & distances_
Stored distances.
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 &)
void hitWedgePatch(sampledSetCloud &, trackingData &)
Hit a wedge patch. Ends the track.
dimensioned< scalar > mag(const dimensioned< Type > &)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
const List< point > & set_
List of set points to track through.
volScalarField & p
label sendToProc
Processor to send the particle to. -1 indicates that this.
Definition: particle.H:111
sampledSetParticle(const polyMesh &mesh, const point &position, const label celli, const label seti, const scalar setF, const scalar distance)
Construct from components.
void hitWallPatch(sampledSetCloud &, trackingData &)
Hit a wall patch. Ends the track.