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-------------------------------------------------------------------------------
11License
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 (
56 )
57 {
58 // Store the location
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
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
269Foam::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
283 return os;
284}
285
286
287// ************************************************************************* //
Base cloud calls templated on particle type.
Definition: Cloud.H:68
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
Minimal example by using system/controlDict.functions:
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void transfer(List< T > &list)
Definition: List.C:447
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
T & last()
Return the last element of the list.
Definition: UListI.H:216
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:57
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition: readFields.H:158
void interpolateFields()
Linearly interpolate volume fields to generate surface fields.
vector position() const
Return current particle position.
Definition: particleI.H:314
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
virtual bool write(const bool valid=true) const
Write using setting from DB.
@ SPACE
Space [isspace].
Definition: token.H:125
Particle class that tracks on triangles of boundary faces. Use trackToEdge similar to trackToFace on ...
Class used to pass tracking data to the trackToEdge function.
const PtrList< interpolation< vector > > & vvInterp_
const PtrList< interpolation< scalar > > & vsInterp_
Particle class that samples fields as it passes through. Used in streamline calculation.
label lifeTime_
Lifetime of particle. Particle dies when reaches 0.
DynamicList< point > sampledPositions_
Sampled positions.
List< DynamicList< vector > > sampledVectors_
Sampled vectors.
List< DynamicList< scalar > > sampledScalars_
Sampled scalars.
static void readFields(Cloud< wallBoundedStreamLineParticle > &)
Read.
U
Definition: pEqn.H:72
volScalarField & p
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
A non-counting (dummy) refCount.
Definition: refCount.H:59