Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / lagrangian / basic / particle / particleIO.C
blobab089d522b4e42b9d2d220af2ea8e3b8c2f0e574
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2011 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
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
19     for more details.
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 "particle.H"
27 #include "IOstreams.H"
28 #include "IOPosition.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 Foam::string Foam::particle::propHeader =
33     "(Px Py Pz) cellI tetFaceI tetPtI origProc origId";
36 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
38 Foam::particle::particle(const polyMesh& mesh, Istream& is, bool readFields)
40     mesh_(mesh),
41     position_(),
42     cellI_(-1),
43     faceI_(-1),
44     stepFraction_(0.0),
45     tetFaceI_(-1),
46     tetPtI_(-1),
47     origProc_(Pstream::myProcNo()),
48     origId_(-1)
50     // readFields : read additional data. Should be consistent with writeFields.
52     if (is.format() == IOstream::ASCII)
53     {
54         is  >> position_ >> cellI_;
56         if (readFields)
57         {
58             is  >> tetFaceI_ >> tetPtI_ >> origProc_ >> origId_;
59         }
60     }
61     else
62     {
63         // In binary read all particle data - needed for parallel transfer
64         if (readFields)
65         {
66             is.read
67             (
68                 reinterpret_cast<char*>(&position_),
69                 sizeof(position_)
70               + sizeof(cellI_)
71               + sizeof(faceI_)
72               + sizeof(stepFraction_)
73               + sizeof(tetFaceI_)
74               + sizeof(tetPtI_)
75               + sizeof(origProc_)
76               + sizeof(origId_)
77             );
78         }
79         else
80         {
81             is.read
82             (
83                 reinterpret_cast<char*>(&position_),
84                 sizeof(position_)
85               + sizeof(cellI_)
86               + sizeof(faceI_)
87               + sizeof(stepFraction_)
88             );
89         }
90     }
92     // Check state of Istream
93     is.check("particle::particle(Istream&, bool)");
97 void Foam::particle::write(Ostream& os, bool writeFields) const
99     if (os.format() == IOstream::ASCII)
100     {
101         if (writeFields)
102         {
103             // Write the additional entries
104             os  << position_
105                 << token::SPACE << cellI_
106                 << token::SPACE << tetFaceI_
107                 << token::SPACE << tetPtI_
108                 << token::SPACE << origProc_
109                 << token::SPACE << origId_;
110         }
111         else
112         {
113             os  << position_
114                 << token::SPACE << cellI_;
115         }
116     }
117     else
118     {
119         // In binary write both cellI_ and faceI_, needed for parallel transfer
120         if (writeFields)
121         {
122             os.write
123             (
124                 reinterpret_cast<const char*>(&position_),
125                 sizeof(position_)
126               + sizeof(cellI_)
127               + sizeof(faceI_)
128               + sizeof(stepFraction_)
129               + sizeof(tetFaceI_)
130               + sizeof(tetPtI_)
131               + sizeof(origProc_)
132               + sizeof(origId_)
133             );
134         }
135         else
136         {
137             os.write
138             (
139                 reinterpret_cast<const char*>(&position_),
140                 sizeof(position_)
141               + sizeof(cellI_)
142               + sizeof(faceI_)
143               + sizeof(stepFraction_)
144             );
145         }
146     }
148     // Check state of Ostream
149     os.check("particle::write(Ostream& os, bool) const");
153 Foam::Ostream& Foam::operator<<(Ostream& os, const particle& p)
155     // Write all data
156     p.write(os, true);
158     return os;
162 // ************************************************************************* //