1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
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 \*---------------------------------------------------------------------------*/
28 #include "IOPosition.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 template<class ParticleType>
33 Foam::word Foam::Cloud<ParticleType>::cloudPropertiesName("cloudProperties");
36 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
38 template<class ParticleType>
39 void Foam::Cloud<ParticleType>::readCloudUniformProperties()
45 "uniform"/cloud::prefix/name(),
47 IOobject::MUST_READ_IF_MODIFIED,
52 if (dictObj.headerOk())
54 const IOdictionary uniformPropsDict(dictObj);
56 const word procName("processor" + Foam::name(Pstream::myProcNo()));
57 if (uniformPropsDict.found(procName))
59 uniformPropsDict.subDict(procName).lookup("particleCount")
60 >> ParticleType::particleCount_;
65 ParticleType::particleCount_ = 0;
70 template<class ParticleType>
71 void Foam::Cloud<ParticleType>::writeCloudUniformProperties() const
73 IOdictionary uniformPropsDict
79 "uniform"/cloud::prefix/name(),
87 labelList np(Pstream::nProcs(), 0);
88 np[Pstream::myProcNo()] = ParticleType::particleCount_;
90 Pstream::listCombineGather(np, maxEqOp<label>());
91 Pstream::listCombineScatter(np);
95 word procName("processor" + Foam::name(i));
96 uniformPropsDict.add(procName, dictionary());
97 uniformPropsDict.subDict(procName).add("particleCount", np[i]);
100 uniformPropsDict.writeObject
103 IOstream::currentVersion,
104 time().writeCompression()
109 template<class ParticleType>
110 void Foam::Cloud<ParticleType>::initCloud(const bool checkClass)
112 readCloudUniformProperties();
114 IOPosition<Cloud<ParticleType> > ioP(*this);
118 ioP.readData(*this, checkClass);
130 Pout<< "Cannot read particle positions file:" << nl
131 << " " << ioP.objectPath() << nl
132 << "Assuming the initial cloud contains 0 particles." << endl;
136 // Ask for the tetBasePtIs to trigger all processors to build
137 // them, otherwise, if some processors have no particles then
138 // there is a comms mismatch.
139 polyMesh_.tetBasePtIs();
141 forAllIter(typename Cloud<ParticleType>, *this, pIter)
143 ParticleType& p = pIter();
150 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
152 template<class ParticleType>
153 Foam::Cloud<ParticleType>::Cloud
155 const polyMesh& pMesh,
156 const bool checkClass
165 initCloud(checkClass);
169 template<class ParticleType>
170 Foam::Cloud<ParticleType>::Cloud
172 const polyMesh& pMesh,
173 const word& cloudName,
174 const bool checkClass
177 cloud(pMesh, cloudName),
183 initCloud(checkClass);
187 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
189 template<class ParticleType>
190 Foam::IOobject Foam::Cloud<ParticleType>::fieldIOobject
192 const word& fieldName,
193 const IOobject::readOption r
208 template<class ParticleType>
209 template<class DataType>
210 void Foam::Cloud<ParticleType>::checkFieldIOobject
212 const Cloud<ParticleType>& c,
213 const IOField<DataType>& data
216 if (data.size() != c.size())
220 "void Cloud<ParticleType>::checkFieldIOobject"
221 "(const Cloud<ParticleType>&, const IOField<DataType>&) const"
222 ) << "Size of " << data.name()
223 << " field " << data.size()
224 << " does not match the number of particles " << c.size()
225 << abort(FatalError);
230 template<class ParticleType>
231 template<class DataType>
232 void Foam::Cloud<ParticleType>::checkFieldFieldIOobject
234 const Cloud<ParticleType>& c,
235 const CompactIOField<Field<DataType>, DataType>& data
238 if (data.size() != c.size())
242 "void Cloud<ParticleType>::checkFieldFieldIOobject"
244 "const Cloud<ParticleType>&, "
245 "const CompactIOField<Field<DataType>, DataType>&"
247 ) << "Size of " << data.name()
248 << " field " << data.size()
249 << " does not match the number of particles " << c.size()
250 << abort(FatalError);
255 template<class ParticleType>
256 void Foam::Cloud<ParticleType>::readFields()
260 template<class ParticleType>
261 void Foam::Cloud<ParticleType>::writeFields() const
265 ParticleType::writeFields(*this);
270 template<class ParticleType>
271 bool Foam::Cloud<ParticleType>::writeObject
273 IOstream::streamFormat fmt,
274 IOstream::versionNumber ver,
275 IOstream::compressionType cmp
278 writeCloudUniformProperties();
283 return cloud::writeObject(fmt, ver, cmp);
292 // * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * //
294 template<class ParticleType>
295 Foam::Ostream& Foam::operator<<(Ostream& os, const Cloud<ParticleType>& pc)
299 // Check state of Ostream
300 os.check("Ostream& operator<<(Ostream&, const Cloud<ParticleType>&)");
306 // ************************************************************************* //