streamLine.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) 2015-2022 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 
29 #include "streamLine.H"
31 #include "sampledSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionObjects
39 {
40  defineTypeNameAndDebug(streamLine, 0);
42 }
43 }
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
49 {
50  // Start with empty cloud
52 
53  const sampledSet& seedPoints = sampledSetPoints();
54 
55  forAll(seedPoints, seedi)
56  {
57  particles.addParticle
58  (
59  new streamLineParticle
60  (
61  mesh_,
62  seedPoints[seedi],
63  seedPoints.cells()[seedi],
64  (trackDir_ == trackDirType::FORWARD),
65  lifeTime_
66  )
67  );
68 
69  if (trackDir_ == trackDirType::BIDIRECTIONAL)
70  {
71  // Add additional particle for the forward bit of the track
72  particles.addParticle
73  (
74  new streamLineParticle
75  (
76  mesh_,
77  seedPoints[seedi],
78  seedPoints.cells()[seedi],
79  true,
80  lifeTime_
81  )
82  );
83  }
84  }
85 
86  label nSeeds = returnReduce(particles.size(), sumOp<label>());
87 
88  Log << " seeded " << nSeeds << " particles" << endl;
89 
90  // Field interpolators
91  // Velocity interpolator
92  PtrList<interpolation<scalar>> vsInterp;
93  PtrList<interpolation<vector>> vvInterp;
94 
95  refPtr<interpolation<vector>> UInterp
96  (
97  initInterpolations(nSeeds, vsInterp, vvInterp)
98  );
99 
100  // Additional particle info
101  streamLineParticle::trackingData td
102  (
103  particles,
104  vsInterp,
105  vvInterp,
106  UInterp.cref(), // velocity interpolator (possibly within vvInterp)
107  nSubCycle_, // automatic track control:step through cells in steps?
108  trackLength_, // fixed track length
109 
110  allTracks_,
111  allScalars_,
113  );
114 
115 
116  // Set very large dt. Note: cannot use GREAT since 1/GREAT is SMALL
117  // which is a trigger value for the tracking...
118  const scalar trackTime = Foam::sqrt(GREAT);
119 
120  // Track
121  particles.move(particles, td, trackTime);
122 }
123 
124 
125 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
126 
128 (
129  const word& name,
130  const Time& runTime,
131  const dictionary& dict
132 )
133 :
135 {
136  read(dict_);
137 }
138 
139 
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 
143 {
145  {
146  bool subCycling = dict.found("nSubCycle");
147  bool fixedLength = dict.found("trackLength");
148 
149  if (subCycling && fixedLength)
150  {
152  << "Cannot both specify automatic time stepping (through '"
153  << "nSubCycle' specification) and fixed track length (through '"
154  << "trackLength')"
155  << exit(FatalIOError);
156  }
157 
158  nSubCycle_ = 1;
159  if (dict.readIfPresent("nSubCycle", nSubCycle_))
160  {
161  trackLength_ = VGREAT;
162  nSubCycle_ = max(nSubCycle_, 1);
163 
164  Info<< " automatic track length specified through"
165  << " number of sub cycles : " << nSubCycle_ << nl
166  << endl;
167  }
168  }
169  return true;
170 }
171 
172 
173 // ************************************************************************* //
dictionary dict
const sampledSet & sampledSetPoints() const
Demand driven construction of the sampledSet.
defineTypeNameAndDebug(ObukhovLength, 0)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
DynamicList< List< point > > allTracks_
All tracks. Per track the points it passed through.
engineTime & runTime
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
const cellList & cells() const
refPtr< interpolation< vector > > initInterpolations(const label nSeeds, PtrList< interpolation< scalar >> &vsInterp, PtrList< interpolation< vector >> &vvInterp)
Initialise interpolators and track storage.
Abstract base-class for Time/database function objects.
List< DynamicList< scalarList > > allScalars_
Per scalarField, per track, the sampled values.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:127
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
List< DynamicList< vectorList > > allVectors_
Per vectorField, per track, the sampled values.
trackDirType trackDir_
Whether to use +U, -U or both.
virtual bool read(const dictionary &)
Read settings.
Definition: streamLine.C:135
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
virtual bool read(const dictionary &)
Read the field average data.
A class for handling words, derived from Foam::string.
Definition: word.H:63
word cloudName_
Optional specified name of particles.
label lifeTime_
Maximum lifetime (= number of cells) of particle.
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
A Cloud of streamLine particles.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Generates streamline data by sampling a set of user-specified fields along a particle track...
Definition: streamLine.H:270
#define Log
Definition: PDRblock.C:28
messageStream Info
Information stream (stdout output on master, null elsewhere)
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
streamLine(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: streamLine.C:121
const fvMesh & mesh_
Reference to the fvMesh.
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
virtual void track()
Do the actual tracking to fill the track data.
Definition: streamLine.C:41