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>
109 (
110  const parcelType& p,
111  const typename parcelType::trackingData& td
112 )
113 {
114  if
115  (
116  this->owner().solution().output()
117  || this->owner().solution().transient()
118  )
119  {
120  if (!cloudPtr_)
121  {
123  << "Cloud storage not allocated" << abort(FatalError);
124  }
125 
126  const label count =
127  ++(faceHitCounter_(labelPair(p.origProc(), p.origId()), 0));
128 
129  const label nSamples = floor(count/trackInterval_);
130 
131  if ((count % trackInterval_) == 0 && nSamples < maxSamples_)
132  {
133  cloudPtr_->append
134  (
135  static_cast<parcelType*>(p.clone(this->owner().mesh()).ptr())
136  );
137  }
138  }
139 
140  return true;
141 }
142 
143 
144 // ************************************************************************* //
dictionary dict
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Records particle state (all variables) on each call to postFace.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
#define DebugInFunction
Report an information message using Foam::Info.
const label nSamples(pdfDictionary.get< label >("nSamples"))
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void write()
Write post-processing info.
virtual void preEvolve(const typename parcelType::trackingData &td)
Pre-evolve hook.
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:51
ParticleTracks(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
virtual bool postFace(const parcelType &p, const typename parcelType::trackingData &td)
Post-face hook.
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:44
volScalarField & p
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:67
Templated cloud function object base class.