intersection with triangle plane for miss
[OpenFOAM-1.5.x.git] / src / lagrangian / basic / IOPosition / IOPosition.C
bloba0ee0559092cbb48836a66cc3b5ebaabd7f24a74
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 Description
27 \*---------------------------------------------------------------------------*/
29 #include "IOPosition.H"
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 template<class ParticleType>
34 Foam::IOPosition<ParticleType>::IOPosition
36     const Cloud<ParticleType>& c
39     regIOobject
40     (
41         IOobject
42         (
43             "positions",
44             c.time().timeName(),
45             c,
46             IOobject::MUST_READ,
47             IOobject::NO_WRITE
48         )
49     ),
50     cloud_(c)
54 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
56 template<class ParticleType>
57 bool Foam::IOPosition<ParticleType>::write() const
59     if (cloud_.size())
60     {
61         return regIOobject::write();
62     }
63     else
64     {
65         return true;
66     }
70 template<class ParticleType>
71 bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const
73     os<< cloud_.size() << nl << token::BEGIN_LIST << nl;
75     forAllConstIter(typename Cloud<ParticleType>, cloud_, iter)
76     {
77         os<< static_cast<const Particle<ParticleType>&>(iter()) << nl;
78     }
80     os<< token::END_LIST << endl;
82     return os.good();
86 template<class ParticleType>
87 void Foam::IOPosition<ParticleType>::readData
89     Cloud<ParticleType>& c,
90     bool checkClass
93     Istream& is = readStream(checkClass ? typeName : "");
95     token firstToken(is);
97     if (firstToken.isLabel())
98     {
99         label s = firstToken.labelToken();
101         // Read beginning of contents
102         is.readBeginList("Cloud<ParticleType>");
104         for (label i=0; i<s; i++)
105         {
106             c.append(new ParticleType(c, is, false));
107         }
109         // Read end of contents
110         is.readEndList("Cloud<ParticleType>");
111     }
112     else if (firstToken.isPunctuation())
113     {
114         if (firstToken.pToken() != token::BEGIN_LIST)
115         {
116             FatalIOErrorIn
117             (
118                 "void IOPosition<ParticleType>::readData"
119                 "(Cloud<ParticleType>&, bool)",
120                 is
121             )   << "incorrect first token, '(', found "
122                 << firstToken.info()
123                 << exit(FatalIOError);
124         }
126         token lastToken(is);
127         while
128         (
129            !(
130                 lastToken.isPunctuation()
131              && lastToken.pToken() == token::END_LIST
132             )
133         )
134         {
135             is.putBack(lastToken);
136             c.append(new ParticleType(c, is, false));
137             is >> lastToken;
138         }
139     }
140     else
141     {
142         FatalIOErrorIn
143         (
144             "void IOPosition<ParticleType>::readData"
145             "(Cloud<ParticleType>&, bool)",
146             is
147         )   << "incorrect first token, expected <int> or '(', found "
148             << firstToken.info()
149             << exit(FatalIOError);
150     }
152     // Check state of IOstream
153     is.check
154     (
155         "void IOPosition<ParticleType>::readData(Cloud<ParticleType>&, bool)"
156     );
160 // ************************************************************************* //