ParticleTracks.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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 
28 // * * * * * * * * * * * * * protected Member Functions * * * * * * * * * * //
29 
30 template<class CloudType>
32 {
33  cloudPtr_->write();
34 
35  if (resetOnWrite_)
36  {
37  cloudPtr_->clear();
38  }
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
44 template<class CloudType>
46 (
47  const dictionary& dict,
48  CloudType& owner,
49  const word& modelName
50 )
51 :
52  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
53  trackInterval_(this->coeffDict().template lookup<label>("trackInterval")),
54  maxSamples_(this->coeffDict().template lookup<label>("maxSamples")),
55  resetOnWrite_(this->coeffDict().lookup("resetOnWrite")),
56  faceHitCounter_(),
57  cloudPtr_(nullptr)
58 {}
59 
60 
61 template<class CloudType>
63 (
64  const ParticleTracks<CloudType>& ppm
65 )
66 :
68  trackInterval_(ppm.trackInterval_),
69  maxSamples_(ppm.maxSamples_),
70  resetOnWrite_(ppm.resetOnWrite_),
71  faceHitCounter_(ppm.faceHitCounter_),
72  cloudPtr_(ppm.cloudPtr_)
73 {}
74 
75 
76 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
77 
78 template<class CloudType>
80 {}
81 
82 
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
84 
85 template<class CloudType>
87 {
88  if (!cloudPtr_.valid())
89  {
90  cloudPtr_.reset
91  (
92  this->owner().cloneBare(this->owner().name() + "Tracks").ptr()
93  );
94  }
95 }
96 
97 
98 template<class CloudType>
100 {
101  if
102  (
103  !this->owner().solution().output()
104  && !this->owner().solution().transient()
105  )
106  {
107  return;
108  }
109 
110  const labelPair id(p.origProc(), p.origId());
111 
112  hitCountTable::iterator iter = faceHitCounter_.find(id);
113 
114  label hitCount = -1;
115  if (iter != faceHitCounter_.end())
116  {
117  iter() ++;
118  hitCount = iter();
119  }
120  else
121  {
122  faceHitCounter_.insert(id, 1);
123  hitCount = 1;
124  }
125 
126  const label nSamples = floor(hitCount/trackInterval_);
127 
128  if ((hitCount % trackInterval_ == 0) && (nSamples < maxSamples_))
129  {
130  cloudPtr_->append
131  (
132  static_cast<parcelType*>(p.clone().ptr())
133  );
134  }
135 }
136 
137 
138 template<class CloudType>
140 (
141  const parcelType& p,
142  const polyPatch& pp
143 )
144 {
145  if (pp.coupled())
146  {
147  preFace(p);
148  }
149 }
150 
151 
152 // ************************************************************************* //
Templated cloud function object base class.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:80
tmp< GeometricField< Type, PatchField, GeoMesh > > clone() const
Clone.
Records particle state (all variables) on each call to postFace.
virtual void postPatch(const parcelType &p, const polyPatch &pp)
Post-patch hook.
ParticleTracks(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
virtual void preFace(const parcelType &p)
Post-face hook.
virtual ~ParticleTracks()
Destructor.
void write()
Write post-processing info.
virtual void preEvolve()
Pre-evolve hook.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:290
Selector class for relaxation factors, solver type and solution.
Definition: solution.H:51
A class for handling words, derived from string.
Definition: word.H:62
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
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
dictionary dict
volScalarField & p
const label nSamples(pdfDictionary.lookup< label >("nSamples"))