BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / lagrangian / intermediate / submodels / CloudFunctionObjects / ParticleTracks / ParticleTracks.C
blobff63c62d082ad5da029c45e1f27463ede6f74d4f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "ParticleTracks.H"
27 #include "Pstream.H"
28 #include "ListListOps.H"
29 #include "IOPtrList.H"
31 // * * * * * * * * * * * * * protected Member Functions  * * * * * * * * * * //
33 template<class CloudType>
34 void Foam::ParticleTracks<CloudType>::write()
36     if (cloudPtr_.valid())
37     {
38         cloudPtr_->write();
40         if (resetOnWrite_)
41         {
42             cloudPtr_->clear();
43         }
44     }
45     else
46     {
47         if (debug)
48         {
49             Info<< "void Foam::ParticleTracks<CloudType>::write()" << nl
50                 << "cloupPtr invalid" << endl;
51         }
52     }
56 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
58 template<class CloudType>
59 Foam::ParticleTracks<CloudType>::ParticleTracks
61     const dictionary& dict,
62     CloudType& owner
65     CloudFunctionObject<CloudType>(dict, owner, 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_(NULL)
74 template<class CloudType>
75 Foam::ParticleTracks<CloudType>::ParticleTracks
77     const ParticleTracks<CloudType>& ppm
80     CloudFunctionObject<CloudType>(ppm),
81     trackInterval_(ppm.trackInterval_),
82     maxSamples_(ppm.maxSamples_),
83     resetOnWrite_(ppm.resetOnWrite_),
84     faceHitCounter_(ppm.faceHitCounter_),
85     cloudPtr_(ppm.cloudPtr_)
89 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
91 template<class CloudType>
92 Foam::ParticleTracks<CloudType>::~ParticleTracks()
96 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
98 template<class CloudType>
99 void Foam::ParticleTracks<CloudType>::preEvolve()
101     if (!cloudPtr_.valid())
102     {
103         cloudPtr_.reset
104         (
105             this->owner().cloneBare(this->owner().name() + "Tracks").ptr()
106         );
107     }
111 template<class CloudType>
112 void Foam::ParticleTracks<CloudType>::postFace
114     const parcelType& p,
115     const label faceI
118     if
119     (
120         this->owner().solution().output()
121      || this->owner().solution().transient()
122     )
123     {
124         if (!cloudPtr_.valid())
125         {
126             FatalErrorIn
127             (
128                 "Foam::ParticleTracks<CloudType>::postFace"
129                 "("
130                     "const parcelType,& "
131                     "const label"
132                 ")"
133             )<< "Cloud storage not allocated" << abort(FatalError);
134         }
136         hitTableType::iterator iter =
137             faceHitCounter_.find(labelPair(p.origProc(), p.origId()));
139         label localI = -1;
140         if (iter != faceHitCounter_.end())
141         {
142             iter()++;
143             localI = iter();
144         }
145         else
146         {
147             localI = 1;
148             faceHitCounter_.insert(labelPair(p.origProc(), p.origId()), localI);
149         }
151         label nSamples = floor(localI/trackInterval_);
152         if ((localI % trackInterval_ == 0) && (nSamples < maxSamples_))
153         {
154             cloudPtr_->append
155             (
156                 static_cast<parcelType*>(p.clone(this->owner().mesh()).ptr())
157             );
158         }
159     }
163 // ************************************************************************* //