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-2018 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>
112 void Foam::ParticleTracks<CloudType>::postFace(const parcelType& p, bool&)
113 {
114  if
115  (
116  this->owner().solution().output()
117  || this->owner().solution().transient()
118  )
119  {
120  if (!cloudPtr_.valid())
121  {
123  << "Cloud storage not allocated" << abort(FatalError);
124  }
125 
126  hitTableType::iterator iter =
127  faceHitCounter_.find(labelPair(p.origProc(), p.origId()));
128 
129  label localI = -1;
130  if (iter != faceHitCounter_.end())
131  {
132  iter()++;
133  localI = iter();
134  }
135  else
136  {
137  localI = 1;
138  faceHitCounter_.insert(labelPair(p.origProc(), p.origId()), localI);
139  }
140 
141  label nSamples = floor(localI/trackInterval_);
142  if ((localI % trackInterval_ == 0) && (nSamples < maxSamples_))
143  {
144  cloudPtr_->append
145  (
146  static_cast<parcelType*>(p.clone(this->owner().mesh()).ptr())
147  );
148  }
149  }
150 }
151 
152 
153 // ************************************************************************* //
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:256
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
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")))
volScalarField & p
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.