intersection with triangle plane for miss
[OpenFOAM-1.5.x.git] / src / lagrangian / basic / Cloud / CloudIO.C
blobea37ea27a9c9d4670e1d39faca79a4deb1ab6d4a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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     allFaces_(pMesh.faces()),
71     points_(pMesh.points()),
72     cellFaces_(pMesh.cells()),
73     allFaceCentres_(pMesh.faceCentres()),
74     owner_(pMesh.faceOwner()),
75     neighbour_(pMesh.faceNeighbour()),
76     meshInfo_(polyMesh_)
78     initCloud(checkClass);
82 template<class ParticleType>
83 Foam::Cloud<ParticleType>::Cloud
85     const polyMesh& pMesh,
86     const word& cloudName,
87     const bool checkClass
90     cloud(pMesh, cloudName),
91     polyMesh_(pMesh),
92     allFaces_(pMesh.faces()),
93     points_(pMesh.points()),
94     cellFaces_(pMesh.cells()),
95     allFaceCentres_(pMesh.faceCentres()),
96     owner_(pMesh.faceOwner()),
97     neighbour_(pMesh.faceNeighbour()),
98     meshInfo_(polyMesh_)
100     initCloud(checkClass);
104 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
106 template<class ParticleType>
107 template<class DataType>
108 void Foam::Cloud<ParticleType>::checkFieldIOobject
110     const Cloud<ParticleType>& c,
111     const IOField<DataType>& data
112 ) const
114     if (data.size() != c.size())
115     {
116         FatalErrorIn
117         (
118             "void Cloud<ParticleType>::checkFieldIOobject"
119             "(Cloud<ParticleType>, IOField<DataType>)"
120         )   << "Size of " << data.name()
121             << " field does not match the number of particles"
122             << abort(FatalError);
123     }
127 template<class ParticleType>
128 Foam::IOobject Foam::Cloud<ParticleType>::fieldIOobject
130     const word& fieldName
131 ) const
133     return IOobject
134     (
135         fieldName,
136         time().timeName(),
137         *this,
138         IOobject::MUST_READ,
139         IOobject::NO_WRITE,
140         false
141     );
145 template<class ParticleType>
146 template<class Type>
147 Foam::tmp<Foam::IOField<Type> > Foam::Cloud<ParticleType>::readField
149     const word& fieldName
150 ) const
152     return tmp<IOField<Type> >(new IOField<Type>(fieldIOobject(fieldName)));
156 template<class ParticleType>
157 void Foam::Cloud<ParticleType>::readFields()
161 template<class ParticleType>
162 void Foam::Cloud<ParticleType>::writeFields() const
166 template<class ParticleType>
167 bool Foam::Cloud<ParticleType>::writeObject
169     IOstream::streamFormat fmt,
170     IOstream::versionNumber ver,
171     IOstream::compressionType cmp
172 ) const
174     if (this->size())
175     {
176         writeFields();
177         return cloud::writeObject(fmt, ver, cmp);
178     }
179     else
180     {
181         return true;
182     }
186 // * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * //
188 template<class ParticleType>
189 Foam::Ostream& Foam::operator<<(Ostream& os, const Cloud<ParticleType>& pc)
191     pc.writeData(os);
193     // Check state of Ostream
194     os.check("Ostream& operator<<(Ostream&, const Cloud<ParticleType>&)");
196     return os;
200 // ************************************************************************* //