updates
[OpenFOAM-1.5.x.git] / src / lagrangian / intermediate / parcels / Templates / ThermoParcel / ThermoParcelIO.C
blobd0242e5e514f420ae4fe231f39888533f05cebbb
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 "ThermoParcel.H"
28 #include "IOstreams.H"
30 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
32 template<class ParcelType>
33 Foam::ThermoParcel<ParcelType>::ThermoParcel
35     const Cloud<ParcelType>& cloud,
36     Istream& is,
37     bool readFields
40     KinematicParcel<ParcelType>(cloud, is, readFields),
41     T_(0.0),
42     cp_(0.0),
43     Tc_(0.0),
44     cpc_(0.0)
46     if (readFields)
47     {
48         if (is.format() == IOstream::ASCII)
49         {
50             T_ = readScalar(is);
51             cp_ = readScalar(is);
52         }
53         else
54         {
55             is.read
56             (
57                 reinterpret_cast<char*>(&T_),
58               + sizeof(T_)
59               + sizeof(cp_)
60             );
61         }
62     }
64     // Check state of Istream
65     is.check
66     (
67         "ThermoParcel::ThermoParcel(const Cloud<ParcelType>&, Istream&, bool)"
68     );
72 template<class ParcelType>
73 void Foam::ThermoParcel<ParcelType>::readFields
75     ThermoCloud<ParcelType>& c
78     if (!c.size())
79     {
80         return;
81     }
83     KinematicParcel<ParcelType>::readFields(c);
85     IOField<scalar> T(c.fieldIOobject("T"));
86     c.checkFieldIOobject(c, T);
88     IOField<scalar> cp(c.fieldIOobject("cp"));
89     c.checkFieldIOobject(c, cp);
92     label i = 0;
93     forAllIter(typename Cloud<ParcelType>, c, iter)
94     {
95         ThermoParcel<ParcelType>& p = iter();
97         p.T_ = T[i];
98         p.cp_ = cp[i];
99         i++;
100     }
104 template<class ParcelType>
105 void Foam::ThermoParcel<ParcelType>::writeFields
107     const ThermoCloud<ParcelType>& c
110     KinematicParcel<ParcelType>::writeFields(c);
112     label np =  c.size();
114     IOField<scalar> T(c.fieldIOobject("T"), np);
115     IOField<scalar> cp(c.fieldIOobject("cp"), np);
117     label i = 0;
118     forAllConstIter(typename Cloud<ParcelType>, c, iter)
119     {
120         const ThermoParcel<ParcelType>& p = iter();
122         T[i] = p.T_;
123         cp[i] = p.cp_;
124         i++;
125     }
127     T.write();
128     cp.write();
132 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
134 template<class ParcelType>
135 Foam::Ostream& Foam::operator<<
137     Ostream& os,
138     const ThermoParcel<ParcelType>& p
141     if (os.format() == IOstream::ASCII)
142     {
143         os  << static_cast<const KinematicParcel<ParcelType>& >(p)
144             << token::SPACE << p.T()
145             << token::SPACE << p.cp();
146     }
147     else
148     {
149         os  << static_cast<const KinematicParcel<ParcelType>& >(p);
150         os.write
151         (
152             reinterpret_cast<const char*>(&p.T_),
153             sizeof(p.T()) + sizeof(p.cp())
154         );
155     }
157     // Check state of Ostream
158     os.check
159     (
160         "Ostream& operator<<(Ostream&, const ThermoParcel<ParcelType>&)"
161     );
163     return os;
167 // ************************************************************************* //