ParticleTracks.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 | Copyright (C) 2011-2015 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 "ParticleTracks.H"
27 #include "Pstream.H"
28 #include "ListListOps.H"
29 #include "IOPtrList.H"
30 
31 // * * * * * * * * * * * * * protected Member Functions * * * * * * * * * * //
32 
33 template<class CloudType>
35 {
36  if (cloudPtr_.valid())
37  {
38  cloudPtr_->write();
39 
40  if (resetOnWrite_)
41  {
42  cloudPtr_->clear();
43  }
44  }
45  else
46  {
47  if (debug)
48  {
49  Info<< "void Foam::ParticleTracks<CloudType>::write()" << nl
50  << "cloupPtr invalid" << endl;
51  }
52  }
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 
58 template<class CloudType>
60 (
61  const dictionary& dict,
62  CloudType& owner,
63  const word& modelName
64 )
65 :
66  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
67  trackInterval_(readLabel(this->coeffDict().lookup("trackInterval"))),
68  maxSamples_(readLabel(this->coeffDict().lookup("maxSamples"))),
69  resetOnWrite_(this->coeffDict().lookup("resetOnWrite")),
70  faceHitCounter_(),
71  cloudPtr_(NULL)
72 {}
73 
74 
75 template<class CloudType>
77 (
78  const ParticleTracks<CloudType>& ppm
79 )
80 :
82  trackInterval_(ppm.trackInterval_),
83  maxSamples_(ppm.maxSamples_),
84  resetOnWrite_(ppm.resetOnWrite_),
85  faceHitCounter_(ppm.faceHitCounter_),
86  cloudPtr_(ppm.cloudPtr_)
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
91 
92 template<class CloudType>
94 {}
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
99 template<class CloudType>
101 {
102  if (!cloudPtr_.valid())
103  {
104  cloudPtr_.reset
105  (
106  this->owner().cloneBare(this->owner().name() + "Tracks").ptr()
107  );
108  }
109 }
110 
111 
112 template<class CloudType>
114 (
115  const parcelType& p,
116  const label,
117  bool&
118 )
119 {
120  if
121  (
122  this->owner().solution().output()
123  || this->owner().solution().transient()
124  )
125  {
126  if (!cloudPtr_.valid())
127  {
129  << "Cloud storage not allocated" << abort(FatalError);
130  }
131 
132  hitTableType::iterator iter =
133  faceHitCounter_.find(labelPair(p.origProc(), p.origId()));
134 
135  label localI = -1;
136  if (iter != faceHitCounter_.end())
137  {
138  iter()++;
139  localI = iter();
140  }
141  else
142  {
143  localI = 1;
144  faceHitCounter_.insert(labelPair(p.origProc(), p.origId()), localI);
145  }
146 
147  label nSamples = floor(localI/trackInterval_);
148  if ((localI % trackInterval_ == 0) && (nSamples < maxSamples_))
149  {
150  cloudPtr_->append
151  (
152  static_cast<parcelType*>(p.clone(this->owner().mesh()).ptr())
153  );
154  }
155  }
156 }
157 
158 
159 // ************************************************************************* //
Foam::ParticleTracks::preEvolve
virtual void preEvolve()
Pre-evolve hook.
Definition: ParticleTracks.C:100
Foam::solution
Selector class for relaxation factors, solver type and solution.
Definition: solution.H:48
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::ParticleTracks::trackInterval_
label trackInterval_
Number of face-hit intervals between storing parcel data.
Definition: ParticleTracks.H:65
Foam::ParticleTracks::write
void write()
Write post-processing info.
Definition: ParticleTracks.C:34
ListListOps.H
Foam::ParticleTracks::parcelType
CloudType::parcelType parcelType
Convenience typedef for parcel type.
Definition: ParticleTracks.H:58
Foam::ParticleTracks
Records particle state (all variables) on each call to postFace.
Definition: ParticleTracks.H:49
nSamples
const label nSamples(readLabel(pdfDictionary.lookup("nSamples")))
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::ParticleTracks::ParticleTracks
ParticleTracks(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
Definition: ParticleTracks.C:60
Foam::ParticleTracks::cloudPtr_
autoPtr< Cloud< parcelType > > cloudPtr_
Pointer to the cloud storage.
Definition: ParticleTracks.H:77
Foam::label
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
ParticleTracks.H
IOPtrList.H
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::ParticleTracks::~ParticleTracks
virtual ~ParticleTracks()
Destructor.
Definition: ParticleTracks.C:93
Foam::ParticleTracks::faceHitCounter_
hitTableType faceHitCounter_
Table of number of times a particle has hit a face.
Definition: ParticleTracks.H:74
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::ParticleTracks::resetOnWrite_
Switch resetOnWrite_
Flag to indicate whether data should be reset/cleared on writing.
Definition: ParticleTracks.H:71
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Pstream.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::ParticleTracks::maxSamples_
label maxSamples_
Maximum number of particles to store per track.
Definition: ParticleTracks.H:68
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::CloudFunctionObject
Templated cloud function object base class.
Definition: CloudFunctionObject.H:56
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
Foam::ParticleTracks::postFace
virtual void postFace(const parcelType &p, const label faceI, bool &keepParticle)
Post-face hook.
Definition: ParticleTracks.C:114
Foam::labelPair
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
lookup
stressControl lookup("compactNormalStress") >> compactNormalStress