fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / lagrangian / basic / IOPosition / IOPosition.C
blobbf5984bb2f8853d052eadd1bb29d3d18756a8273
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 "IOPosition.H"
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 template<class ParticleType>
32 Foam::IOPosition<ParticleType>::IOPosition
34     const Cloud<ParticleType>& c
37     regIOobject
38     (
39         IOobject
40         (
41             "positions",
42             c.time().timeName(),
43             c,
44             IOobject::MUST_READ,
45             IOobject::NO_WRITE
46         )
47     ),
48     cloud_(c)
52 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
54 template<class ParticleType>
55 bool Foam::IOPosition<ParticleType>::write() const
57     if (cloud_.size())
58     {
59         return regIOobject::write();
60     }
61     else
62     {
63         return true;
64     }
68 template<class ParticleType>
69 bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const
71     os<< cloud_.size() << nl << token::BEGIN_LIST << nl;
73     forAllConstIter(typename Cloud<ParticleType>, cloud_, iter)
74     {
75         // Prevent writing additional fields
76         static_cast<const Particle<ParticleType>&>(iter()).write
77         (
78             os,
79             false
80         );
81         os  << nl;
82     }
84     os<< token::END_LIST << endl;
86     return os.good();
90 template<class ParticleType>
91 void Foam::IOPosition<ParticleType>::readData
93     Cloud<ParticleType>& c,
94     bool checkClass
97     Istream& is = readStream(checkClass ? typeName : "");
99     token firstToken(is);
101     if (firstToken.isLabel())
102     {
103         label s = firstToken.labelToken();
105         // Read beginning of contents
106         is.readBeginList("Cloud<ParticleType>");
108         for (label i=0; i<s; i++)
109         {
110             // Do not read any fields, position only
111             c.append(new ParticleType(c, is, false));
112         }
114         // Read end of contents
115         is.readEndList("Cloud<ParticleType>");
116     }
117     else if (firstToken.isPunctuation())
118     {
119         if (firstToken.pToken() != token::BEGIN_LIST)
120         {
121             FatalIOErrorIn
122             (
123                 "void IOPosition<ParticleType>::readData"
124                 "(Cloud<ParticleType>&, bool)",
125                 is
126             )   << "incorrect first token, '(', found "
127                 << firstToken.info()
128                 << exit(FatalIOError);
129         }
131         token lastToken(is);
132         while
133         (
134            !(
135                 lastToken.isPunctuation()
136              && lastToken.pToken() == token::END_LIST
137             )
138         )
139         {
140             is.putBack(lastToken);
141             // Do not read any fields, position only
142             c.append(new ParticleType(c, is, false));
143             is >> lastToken;
144         }
145     }
146     else
147     {
148         FatalIOErrorIn
149         (
150             "void IOPosition<ParticleType>::readData"
151             "(Cloud<ParticleType>&, bool)",
152             is
153         )   << "incorrect first token, expected <int> or '(', found "
154             << firstToken.info()
155             << exit(FatalIOError);
156     }
158     // Check state of IOstream
159     is.check
160     (
161         "void IOPosition<ParticleType>::readData(Cloud<ParticleType>&, bool)"
162     );
166 // ************************************************************************* //