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  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  particle(is, readFields)
53 {
54  if (readFields)
55  {
56  is >> seti_ >> setF_ >> distance_ >> havePosition0_ >> position0_;
57  }
58 
59  is.check(FUNCTION_NAME);
60 }
61 
62 
64 (
65  const sampledSetParticle& p
66 )
67 :
68  particle(p),
69  seti_(p.seti_),
70  setF_(p.setF_),
71  distance_(p.distance_),
72  havePosition0_(p.havePosition0_),
73  position0_(p.position0_)
74 {}
75 
76 
77 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
78 
80 (
82  trackingData& td
83 )
84 {
85  td.positions_.append(position(td.mesh));
86  td.distances_.append(distance_);
87  td.cells_.append(cell());
88  td.faces_.append(face());
89 }
90 
91 
93 (
95  trackingData& td
96 )
97 {
98  store(cloud, td);
99 }
100 
101 
103 (
105  trackingData& td
106 )
107 {
108  if (havePosition0_)
109  {
110  td.positions_.append((position(td.mesh) + position0_)/2);
111  td.distances_.append(distance_ - mag(position(td.mesh) - position0_)/2);
112  td.cells_.append(cell());
113  td.faces_.append(-1);
114  }
115 
116  havePosition0_ = true;
117  position0_ = position(td.mesh);
118 }
119 
120 
122 (
124  trackingData& td
125 )
126 {
127  td.keepParticle = true;
128  td.sendToProc = -1;
129 
130  while (td.keepParticle && td.sendToProc == -1 && seti_ < td.set_.size() - 1)
131  {
132  const vector s = td.set_[seti_ + 1] - td.set_[seti_];
133  const scalar magS = mag(s);
134 
135  const scalar f = trackToFace(td.mesh, setF_*s, 0);
136  distance_ += (1 - f)*setF_*magS;
137  setF_ *= f;
138 
139  while (onInternalFace(td.mesh))
140  {
141  if (td.storeCells_) storeCell(cloud, td);
142  if (td.storeFaces_ > 0) storeFace(cloud, td);
143 
144  hitFace(setF_*s, 0, cloud, td);
145 
146  const scalar f = trackToFace(td.mesh, setF_*s, 0);
147  distance_ += (1 - f)*setF_*magS;
148  setF_ *= f;
149  }
150 
151  if (onFace())
152  {
153  if (td.storeCells_) storeCell(cloud, td);
154  if (td.storeFaces_ > 0) storeFace(cloud, td);
155 
156  hitFace(setF_*s, 0, cloud, td);
157  }
158 
159  if (onBoundaryFace(td.mesh) && setF_ < rootSmall)
160  {
161  if (td.storeSet_) store(cloud, td);
162  }
163 
164  if (!onFace())
165  {
166  if (td.storeSet_) store(cloud, td);
167 
168  ++ seti_;
169  setF_ = 1;
170  }
171  }
172 
173  return true;
174 }
175 
176 
178 (
180  trackingData& td
181 )
182 {
183  seti_ = labelMax;
184 }
185 
186 
188 (
190  trackingData& td
191 )
192 {
193  seti_ = labelMax;
194 }
195 
196 
198 (
200  trackingData& td
201 )
202 {
203  seti_ = labelMax;
204 }
205 
206 
208 (
210  trackingData& td
211 )
212 {
213  seti_ = labelMax;
214 }
215 
216 
218 (
220  trackingData& td
221 )
222 {
223  const processorPolyPatch& ppp =
224  static_cast<const processorPolyPatch&>
225  (
226  td.mesh.boundaryMesh()[patch(td.mesh)]
227  );
228 
229  if (ppp.transform().transformsPosition())
230  {
231  seti_ = labelMax;
232  }
233  else
234  {
236  }
237 }
238 
239 
241 (
243  trackingData& td
244 )
245 {
246  seti_ = labelMax;
247 }
248 
249 
251 (
253  trackingData& td
254 )
255 {
257 
258  if (td.storeFaces_ > 1) storeFace(cloud, td);
259 }
260 
261 
262 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
263 
265 {
266  os << static_cast<const particle&>(p)
267  << token::SPACE << p.seti_
268  << token::SPACE << p.setF_
269  << token::SPACE << p.distance_
270  << token::SPACE << p.havePosition0_
271  << token::SPACE << p.position0_;
272 
273  os.check(FUNCTION_NAME);
274 
275  return os;
276 }
277 
278 
279 // ************************************************************************* //
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:403
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.
sampledSetParticle(const polyMesh &mesh, const point &position, const label celli, const label seti, const scalar setF, const scalar distance)
Construct from components.
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.
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
static Type NaN()
Return a primitive with all components set to NaN.
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 > &)
static const label labelMax
Definition: label.H:62
Ostream & operator<<(Ostream &, const ensightPart &)
labelList f(nPoints)
volScalarField & p