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-2020 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 
30 // * * * * * * * * * * * * * protected Member Functions * * * * * * * * * * //
31 
32 template<class CloudType>
34 {
35  if (cloudPtr_.valid())
36  {
37  cloudPtr_->write();
38 
39  if (resetOnWrite_)
40  {
41  cloudPtr_->clear();
42  }
43  }
44  else
45  {
46  if (debug)
47  {
48  InfoInFunction << "cloupPtr invalid" << endl;
49  }
50  }
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
56 template<class CloudType>
58 (
59  const dictionary& dict,
60  CloudType& owner,
61  const word& modelName
62 )
63 :
64  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
65  trackInterval_(this->coeffDict().template lookup<label>("trackInterval")),
66  maxSamples_(this->coeffDict().template lookup<label>("maxSamples")),
67  resetOnWrite_(this->coeffDict().lookup("resetOnWrite")),
68  faceHitCounter_(),
69  cloudPtr_(nullptr)
70 {}
71 
72 
73 template<class CloudType>
75 (
76  const ParticleTracks<CloudType>& ppm
77 )
78 :
80  trackInterval_(ppm.trackInterval_),
81  maxSamples_(ppm.maxSamples_),
82  resetOnWrite_(ppm.resetOnWrite_),
83  faceHitCounter_(ppm.faceHitCounter_),
84  cloudPtr_(ppm.cloudPtr_)
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
89 
90 template<class CloudType>
92 {}
93 
94 
95 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
96 
97 template<class CloudType>
99 {
100  if (!cloudPtr_.valid())
101  {
102  cloudPtr_.reset
103  (
104  this->owner().cloneBare(this->owner().name() + "Tracks").ptr()
105  );
106  }
107 }
108 
109 
110 template<class CloudType>
111 void Foam::ParticleTracks<CloudType>::postFace(const parcelType& p, bool&)
112 {
113  if
114  (
115  this->owner().solution().output()
116  || this->owner().solution().transient()
117  )
118  {
119  if (!cloudPtr_.valid())
120  {
122  << "Cloud storage not allocated" << abort(FatalError);
123  }
124 
125  hitTableType::iterator iter =
126  faceHitCounter_.find(labelPair(p.origProc(), p.origId()));
127 
128  label localI = -1;
129  if (iter != faceHitCounter_.end())
130  {
131  iter()++;
132  localI = iter();
133  }
134  else
135  {
136  localI = 1;
137  faceHitCounter_.insert(labelPair(p.origProc(), p.origId()), localI);
138  }
139 
140  label nSamples = floor(localI/trackInterval_);
141  if ((localI % trackInterval_ == 0) && (nSamples < maxSamples_))
142  {
143  cloudPtr_->append
144  (
145  static_cast<parcelType*>(p.clone(this->owner().mesh()).ptr())
146  );
147  }
148  }
149 }
150 
151 
152 // ************************************************************************* //
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:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Records particle state (all variables) on each call to postFace.
virtual void postFace(const parcelType &p, bool &keepParticle)
Post-face hook.
stressControl lookup("compactNormalStress") >> compactNormalStress
A class for handling words, derived from string.
Definition: word.H:59
virtual void preEvolve()
Pre-evolve hook.
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void write()
Write post-processing info.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
const label nSamples(pdfDictionary.lookup< label >("nSamples"))
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
volScalarField & p
virtual ~ParticleTracks()
Destructor.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:75
Templated cloud function object base class.
#define InfoInFunction
Report an information message using Foam::Info.