wallBoundedStreamLineParticle.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "vectorFieldIOField.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
35 (
36  const trackingData& td,
37  const point& position,
38  const label celli,
39  const label facei
40 )
41 {
42  if (celli == -1)
43  {
45  << "Cell:" << celli << abort(FatalError);
46  }
47 
48  const vector U =
49  td.vvInterp_[td.UIndex_].interpolate(position, celli, facei);
50 
51  // Check if at different position
52  if
53  (
54  !sampledPositions_.size()
55  || magSqr(sampledPositions_.last() - position) > Foam::sqr(SMALL)
56  )
57  {
58  // Store the location
59  sampledPositions_.append(position);
60 
61  // Store the scalar fields
62  sampledScalars_.setSize(td.vsInterp_.size());
63  forAll(td.vsInterp_, scalari)
64  {
65  sampledScalars_[scalari].append
66  (
67  td.vsInterp_[scalari].interpolate(position, celli, facei)
68  );
69  }
70 
71  // Store the vector fields
72  sampledVectors_.setSize(td.vvInterp_.size());
73  forAll(td.vvInterp_, vectori)
74  {
75  vector positionU;
76  if (vectori == td.UIndex_)
77  {
78  positionU = U;
79  }
80  else
81  {
82  positionU =
83  td.vvInterp_[vectori].interpolate(position, celli, facei);
84  }
85  sampledVectors_[vectori].append(positionU);
86  }
87  }
88 
89  return U;
90 }
91 
92 
94 (
95  trackingData& td
96 )
97 {
98  vector U = interpolateFields(td, localPosition_, cell(), face());
99 
100  if (!trackForward_)
101  {
102  U = -U;
103  }
104 
105  scalar magU = mag(U);
106 
107  if (magU < SMALL)
108  {
109  // Stagnant particle. Might as well stop
110  lifeTime_ = 0;
111  return vector::zero;
112  }
113  else
114  {
115  return U/magU;
116  }
117 }
118 
119 
120 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
121 
123 (
124  const polyMesh& mesh,
125  const point& position,
126  const label celli,
127  const label tetFacei,
128  const label tetPti,
129  const label meshEdgeStart,
130  const label diagEdge,
131  const bool trackForward,
132  const label lifeTime
133 )
134 :
136  (
137  mesh,
138  position,
139  celli,
140  tetFacei,
141  tetPti,
142  meshEdgeStart,
143  diagEdge
144  ),
145  trackForward_(trackForward),
146  lifeTime_(lifeTime)
147 {}
148 
149 
151 (
152  const polyMesh& mesh,
153  Istream& is,
154  bool readFields,
155  bool newFormat
156 )
157 :
158  wallBoundedParticle(mesh, is, readFields, newFormat)
159 {
160  if (readFields)
161  {
162  List<scalarList> sampledScalars;
163  List<vectorList> sampledVectors;
164 
165  is >> trackForward_ >> lifeTime_
166  >> sampledPositions_ >> sampledScalars >> sampledVectors;
167 
168  sampledScalars_.setSize(sampledScalars.size());
169  forAll(sampledScalars, i)
170  {
171  sampledScalars_[i].transfer(sampledScalars[i]);
172  }
173  sampledVectors_.setSize(sampledVectors.size());
174  forAll(sampledVectors, i)
175  {
176  sampledVectors_[i].transfer(sampledVectors[i]);
177  }
178  }
179 
180  is.check(FUNCTION_NAME);
181 }
182 
183 
185 (
187 )
188 :
190  trackForward_(p.trackForward_),
191  lifeTime_(p.lifeTime_),
192  sampledPositions_(p.sampledPositions_),
193  sampledScalars_(p.sampledScalars_),
194  sampledVectors_(p.sampledVectors_)
195 {}
196 
197 
198 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
199 
201 (
203 )
204 {
205  if (!c.size())
206  {
207  return;
208  }
209 
211 
212  IOField<label> lifeTime
213  (
214  c.fieldIOobject("lifeTime", IOobject::MUST_READ)
215  );
216  c.checkFieldIOobject(c, lifeTime);
217 
218  vectorFieldIOField sampledPositions
219  (
220  c.fieldIOobject("sampledPositions", IOobject::MUST_READ)
221  );
222  c.checkFieldIOobject(c, sampledPositions);
223 
224  label i = 0;
226  {
227  p.lifeTime_ = lifeTime[i];
228  p.sampledPositions_.transfer(sampledPositions[i]);
229  ++i;
230  }
231 }
232 
233 
235 (
237 )
238 {
240 
241  const label np = c.size();
242 
243  IOField<label> lifeTime
244  (
245  c.fieldIOobject("lifeTime", IOobject::NO_READ),
246  np
247  );
248  vectorFieldIOField sampledPositions
249  (
250  c.fieldIOobject("sampledPositions", IOobject::NO_READ),
251  np
252  );
253 
254  label i = 0;
255  for (const wallBoundedStreamLineParticle& p : c)
256  {
257  lifeTime[i] = p.lifeTime_;
258  sampledPositions[i] = p.sampledPositions_;
259  ++i;
260  }
261 
262  lifeTime.write();
263  sampledPositions.write();
264 }
265 
266 
267 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
268 
269 Foam::Ostream& Foam::operator<<
270 (
271  Ostream& os,
273 )
274 {
275  os << static_cast<const wallBoundedParticle&>(p)
276  << token::SPACE << p.trackForward_
277  << token::SPACE << p.lifeTime_
278  << token::SPACE << p.sampledPositions_
279  << token::SPACE << p.sampledScalars_
280  << token::SPACE << p.sampledVectors_;
281 
282  os.check(FUNCTION_NAME);
283  return os;
284 }
285 
286 
287 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::wallBoundedStreamLineParticle::wallBoundedStreamLineParticle
wallBoundedStreamLineParticle(const polyMesh &c, const point &position, const label celli, const label tetFacei, const label tetPti, const label meshEdgeStart, const label diagEdge, const bool trackForward, const label lifeTime)
Construct from components.
Definition: wallBoundedStreamLineParticle.C:123
Foam::wallBoundedStreamLineParticle::trackingData::UIndex_
const label UIndex_
Definition: wallBoundedStreamLineParticle.H:84
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::wallBoundedStreamLineParticle::sample
vector sample(trackingData &td)
Definition: wallBoundedStreamLineParticle.C:94
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::wallBoundedStreamLineParticle::trackingData
Class used to pass tracking data to the trackToEdge function.
Definition: wallBoundedStreamLineParticle.H:74
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
vectorFieldIOField.H
Foam::wallBoundedParticle
Particle class that tracks on triangles of boundary faces. Use trackToEdge similar to trackToFace on ...
Definition: wallBoundedParticle.H:63
Foam::wallBoundedStreamLineParticle
Particle class that samples fields as it passes through. Used in streamline calculation.
Definition: wallBoundedStreamLineParticle.H:66
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::wallBoundedStreamLineParticle::trackingData::vvInterp_
const PtrList< interpolation< vector > > & vvInterp_
Definition: wallBoundedStreamLineParticle.H:83
Foam::wallBoundedStreamLineParticle::writeFields
static void writeFields(const Cloud< wallBoundedStreamLineParticle > &)
Write.
Definition: wallBoundedStreamLineParticle.C:235
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
Foam::FatalError
error FatalError
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::readFields
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
Definition: ReadFieldsTemplates.C:312
U
U
Definition: pEqn.H:72
Foam::wallBoundedStreamLineParticle::readFields
static void readFields(Cloud< wallBoundedStreamLineParticle > &)
Read.
Definition: wallBoundedStreamLineParticle.C:201
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::Vector< scalar >
Foam::List< scalarList >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::Cloud< wallBoundedStreamLineParticle >
Foam::wallBoundedStreamLineParticle::trackingData::vsInterp_
const PtrList< interpolation< scalar > > & vsInterp_
Definition: wallBoundedStreamLineParticle.H:82
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
wallBoundedStreamLineParticle.H
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::wallBoundedStreamLineParticle::interpolateFields
vector interpolateFields(const trackingData &td, const point &position, const label celli, const label facei)
Definition: wallBoundedStreamLineParticle.C:35
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54
Foam::writeFields
void writeFields(const fvMesh &mesh, const wordHashSet &selectedFields, const bool writeFaceFields)