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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "ParticleTracks.H"
30 #include "Pstream.H"
31 #include "ListListOps.H"
32 #include "IOPtrList.H"
33 
34 // * * * * * * * * * * * * * protected Member Functions * * * * * * * * * * //
35 
36 template<class CloudType>
38 {
39  if (cloudPtr_)
40  {
41  cloudPtr_->write();
42 
43  if (resetOnWrite_)
44  {
45  cloudPtr_->clear();
46  }
47  }
48  else
49  {
50  DebugInFunction << "invalid cloud pointer" << endl;
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_(this->coeffDict().getLabel("trackInterval")),
67  maxSamples_(this->coeffDict().getLabel("maxSamples")),
68  resetOnWrite_(this->coeffDict().getBool("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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
91 template<class CloudType>
93 (
94  const typename parcelType::trackingData& td
95 )
96 {
97  if (!cloudPtr_)
98  {
99  cloudPtr_.reset
100  (
101  this->owner().cloneBare(this->owner().name() + "Tracks").ptr()
102  );
103  }
104 }
105 
106 
107 template<class CloudType>
108 void Foam::ParticleTracks<CloudType>::postFace(const parcelType& p, bool&)
109 {
110  if
111  (
112  this->owner().solution().output()
113  || this->owner().solution().transient()
114  )
115  {
116  if (!cloudPtr_)
117  {
119  << "Cloud storage not allocated" << abort(FatalError);
120  }
121 
122  const label count =
123  ++(faceHitCounter_(labelPair(p.origProc(), p.origId()), 0));
124 
125  const label nSamples = floor(count/trackInterval_);
126 
127  if ((count % trackInterval_) == 0 && nSamples < maxSamples_)
128  {
129  cloudPtr_->append
130  (
131  static_cast<parcelType*>(p.clone(this->owner().mesh()).ptr())
132  );
133  }
134  }
135 }
136 
137 
138 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
Foam::solution
Selector class for relaxation factors, solver type and solution.
Definition: solution.H:55
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::ParticleTracks::write
void write()
Write post-processing info.
Definition: ParticleTracks.C:37
ListListOps.H
Foam::ParticleTracks::preEvolve
virtual void preEvolve(const typename parcelType::trackingData &td)
Pre-evolve hook.
Definition: ParticleTracks.C:93
Foam::ParticleTracks
Records particle state (all variables) on each call to postFace.
Definition: ParticleTracks.H:56
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::ParticleTracks::ParticleTracks
ParticleTracks(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
Definition: ParticleTracks.C:59
Foam::labelPair
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:54
ParticleTracks.H
IOPtrList.H
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:71
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Pstream.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
nSamples
const label nSamples(pdfDictionary.get< label >("nSamples"))
Foam::ParticleTracks::postFace
virtual void postFace(const parcelType &p, bool &keepParticle)
Post-face hook.
Definition: ParticleTracks.C:108
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::CloudFunctionObject
Templated cloud function object base class.
Definition: CloudFunctionObject.H:62
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59