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