initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / lagrangian / basic / Cloud / CloudIO.C
blobc1e4b30f808a9f8015f07e57bf3eb1ceaaa61b7d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "Cloud.H"
28 #include "Particle.H"
29 #include "Time.H"
30 #include "IOPosition.H"
32 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
34 template<class ParticleType>
35 void Foam::Cloud<ParticleType>::initCloud(const bool checkClass)
37     IOPosition<ParticleType> ioP(*this);
39     if (ioP.headerOk())
40     {
41         ioP.readData(*this, checkClass);
42         ioP.close();
44         if (this->size())
45         {
46             readFields();
47         }
48     }
49     else
50     {
51         WarningIn("Cloud<ParticleType>::initCloud(const bool checkClass)")
52             << "Cannot read particle positions file " << nl
53             << "    " << ioP.path() << nl
54             << "    assuming the initial cloud contains 0 particles." << endl;
55     }
59 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
61 template<class ParticleType>
62 Foam::Cloud<ParticleType>::Cloud
64     const polyMesh& pMesh,
65     const bool checkClass
68     cloud(pMesh),
69     polyMesh_(pMesh),
70     particleCount_(0)
72     initCloud(checkClass);
76 template<class ParticleType>
77 Foam::Cloud<ParticleType>::Cloud
79     const polyMesh& pMesh,
80     const word& cloudName,
81     const bool checkClass
84     cloud(pMesh, cloudName),
85     polyMesh_(pMesh),
86     particleCount_(0)
88     initCloud(checkClass);
92 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
94 template<class ParticleType>
95 Foam::IOobject Foam::Cloud<ParticleType>::fieldIOobject
97     const word& fieldName,
98     const IOobject::readOption r
99 ) const
101     return IOobject
102     (
103         fieldName,
104         time().timeName(),
105         *this,
106         r,
107         IOobject::NO_WRITE,
108         false
109     );
113 template<class ParticleType>
114 template<class DataType>
115 void Foam::Cloud<ParticleType>::checkFieldIOobject
117     const Cloud<ParticleType>& c,
118     const IOField<DataType>& data
119 ) const
121     if (data.size() != c.size())
122     {
123         FatalErrorIn
124         (
125             "void Cloud<ParticleType>::checkFieldIOobject"
126             "(const Cloud<ParticleType>&, const IOField<DataType>&) const"
127         )   << "Size of " << data.name()
128             << " field " << data.size()
129             << " does not match the number of particles " << c.size()
130             << abort(FatalError);
131     }
135 template<class ParticleType>
136 void Foam::Cloud<ParticleType>::readFields()
140 template<class ParticleType>
141 void Foam::Cloud<ParticleType>::writeFields() const
145 template<class ParticleType>
146 bool Foam::Cloud<ParticleType>::writeObject
148     IOstream::streamFormat fmt,
149     IOstream::versionNumber ver,
150     IOstream::compressionType cmp
151 ) const
153     if (this->size())
154     {
155         writeFields();
156         return cloud::writeObject(fmt, ver, cmp);
157     }
158     else
159     {
160         return true;
161     }
165 // * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * //
167 template<class ParticleType>
168 Foam::Ostream& Foam::operator<<(Ostream& os, const Cloud<ParticleType>& pc)
170     pc.writeData(os);
172     // Check state of Ostream
173     os.check("Ostream& operator<<(Ostream&, const Cloud<ParticleType>&)");
175     return os;
179 // ************************************************************************* //