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-2016 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  InfoInFunction << "cloupPtr invalid" << endl;
50  }
51  }
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
57 template<class CloudType>
59 (
60  const dictionary& dict,
61  CloudType& owner,
62  const word& modelName
63 )
64 :
65  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
66  trackInterval_(readLabel(this->coeffDict().lookup("trackInterval"))),
67  maxSamples_(readLabel(this->coeffDict().lookup("maxSamples"))),
68  resetOnWrite_(this->coeffDict().lookup("resetOnWrite")),
69  faceHitCounter_(),
70  cloudPtr_(nullptr)
71 {}
72 
73 
74 template<class CloudType>
76 (
77  const ParticleTracks<CloudType>& ppm
78 )
79 :
81  trackInterval_(ppm.trackInterval_),
82  maxSamples_(ppm.maxSamples_),
83  resetOnWrite_(ppm.resetOnWrite_),
84  faceHitCounter_(ppm.faceHitCounter_),
85  cloudPtr_(ppm.cloudPtr_)
86 {}
87 
88 
89 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
90 
91 template<class CloudType>
93 {}
94 
95 
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 
98 template<class CloudType>
100 {
101  if (!cloudPtr_.valid())
102  {
103  cloudPtr_.reset
104  (
105  this->owner().cloneBare(this->owner().name() + "Tracks").ptr()
106  );
107  }
108 }
109 
110 
111 template<class CloudType>
113 (
114  const parcelType& p,
115  const label,
116  bool&
117 )
118 {
119  if
120  (
121  this->owner().solution().output()
122  || this->owner().solution().transient()
123  )
124  {
125  if (!cloudPtr_.valid())
126  {
128  << "Cloud storage not allocated" << abort(FatalError);
129  }
130 
131  hitTableType::iterator iter =
132  faceHitCounter_.find(labelPair(p.origProc(), p.origId()));
133 
134  label localI = -1;
135  if (iter != faceHitCounter_.end())
136  {
137  iter()++;
138  localI = iter();
139  }
140  else
141  {
142  localI = 1;
143  faceHitCounter_.insert(labelPair(p.origProc(), p.origId()), localI);
144  }
145 
146  label nSamples = floor(localI/trackInterval_);
147  if ((localI % trackInterval_ == 0) && (nSamples < maxSamples_))
148  {
149  cloudPtr_->append
150  (
151  static_cast<parcelType*>(p.clone(this->owner().mesh()).ptr())
152  );
153  }
154  }
155 }
156 
157 
158 // ************************************************************************* //
dictionary dict
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
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Records particle state (all variables) on each call to postFace.
stressControl lookup("compactNormalStress") >> compactNormalStress
A class for handling words, derived from string.
Definition: word.H:59
virtual void preEvolve()
Pre-evolve hook.
virtual void postFace(const parcelType &p, const label facei, bool &keepParticle)
Post-face hook.
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
errorManip< error > abort(error &err)
Definition: errorManip.H:131
label readLabel(Istream &is)
Definition: label.H:64
void write()
Write post-processing info.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
ParticleTracks(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
Selector class for relaxation factors, solver type and solution.
Definition: solution.H:48
const label nSamples(readLabel(pdfDictionary.lookup("nSamples")))
virtual ~ParticleTracks()
Destructor.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:69
Templated cloud function object base class.
#define InfoInFunction
Report an information message using Foam::Info.