1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
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 \*---------------------------------------------------------------------------*/
26 #include "IOPosition.H"
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 template<class CloudType>
31 Foam::IOPosition<CloudType>::IOPosition(const CloudType& c)
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 template<class CloudType>
51 bool Foam::IOPosition<CloudType>::write() const
55 return regIOobject::write();
64 template<class CloudType>
65 bool Foam::IOPosition<CloudType>::writeData(Ostream& os) const
67 os << cloud_.size() << nl << token::BEGIN_LIST << nl;
69 forAllConstIter(typename CloudType, cloud_, iter)
71 const typename CloudType::particleType& p = iter();
73 // Prevent writing additional fields
79 os << token::END_LIST << endl;
85 template<class CloudType>
86 void Foam::IOPosition<CloudType>::readData(CloudType& c, bool checkClass)
88 const polyMesh& mesh = c.pMesh();
90 Istream& is = readStream(checkClass ? typeName : "");
94 if (firstToken.isLabel())
96 label s = firstToken.labelToken();
98 // Read beginning of contents
99 is.readBeginList("IOPosition<CloudType>::readData(CloudType, bool)");
101 for (label i=0; i<s; i++)
103 // Do not read any fields, position only
104 c.append(new typename CloudType::particleType(mesh, is, false));
107 // Read end of contents
108 is.readEndList("IOPosition<CloudType>::readData(CloudType, bool)");
110 else if (firstToken.isPunctuation())
112 if (firstToken.pToken() != token::BEGIN_LIST)
116 "void IOPosition<CloudType>::readData(CloudType&, bool)",
118 ) << "incorrect first token, '(', found "
119 << firstToken.info() << exit(FatalIOError);
126 lastToken.isPunctuation()
127 && lastToken.pToken() == token::END_LIST
131 is.putBack(lastToken);
132 // Do not read any fields, position only
133 c.append(new typename CloudType::particleType(mesh, is, false));
141 "void IOPosition<ParticleType>::readData(CloudType&, bool)",
143 ) << "incorrect first token, expected <int> or '(', found "
144 << firstToken.info() << exit(FatalIOError);
147 // Check state of IOstream
150 "void IOPosition<CloudType>::readData(CloudType&, bool)"
155 // ************************************************************************* //