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-------------------------------------------------------------------------------
11License
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
36template<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
57template<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
74template<class CloudType>
76(
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
91template<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
107template<class CloudType>
108void 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// ************************************************************************* //
Templated cloud function object base class.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:75
tmp< GeometricField< Type, PatchField, GeoMesh > > clone() const
Clone.
Records particle state (all variables) on each call to postFace.
void write()
Write post-processing info.
virtual void preEvolve(const typename parcelType::trackingData &td)
Pre-evolve hook.
virtual void postFace(const parcelType &p, bool &keepParticle)
Post-face hook.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Class used to pass data into container.
Selector class for relaxation factors, solver type and solution.
Definition: solution.H:66
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define DebugInFunction
Report an information message using Foam::Info.
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
dictionary dict
const label nSamples(pdfDictionary.get< label >("nSamples"))