FreeFOAM The Cross-Platform CFD Toolkit
ThermoParcelIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ThermoParcel.H"
27 #include <OpenFOAM/IOstreams.H>
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 template <class ParcelType>
33  KinematicParcel<ParcelType>::propHeader
34  + " T"
35  + " cp";
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
40 template<class ParcelType>
42 (
43  const Cloud<ParcelType>& cloud,
44  Istream& is,
45  bool readFields
46 )
47 :
49  T_(0.0),
50  cp_(0.0),
51  Tc_(0.0),
52  cpc_(0.0)
53 {
54  if (readFields)
55  {
56  if (is.format() == IOstream::ASCII)
57  {
58  T_ = readScalar(is);
59  cp_ = readScalar(is);
60  }
61  else
62  {
63  is.read
64  (
65  reinterpret_cast<char*>(&T_),
66  + sizeof(T_)
67  + sizeof(cp_)
68  );
69  }
70  }
71 
72  // Check state of Istream
73  is.check
74  (
75  "ThermoParcel::ThermoParcel(const Cloud<ParcelType>&, Istream&, bool)"
76  );
77 }
78 
79 
80 template<class ParcelType>
82 {
83  if (!c.size())
84  {
85  return;
86  }
87 
89 
90  IOField<scalar> T(c.fieldIOobject("T", IOobject::MUST_READ));
91  c.checkFieldIOobject(c, T);
92 
93  IOField<scalar> cp(c.fieldIOobject("cp", IOobject::MUST_READ));
94  c.checkFieldIOobject(c, cp);
95 
96 
97  label i = 0;
98  forAllIter(typename Cloud<ParcelType>, c, iter)
99  {
100  ThermoParcel<ParcelType>& p = iter();
101 
102  p.T_ = T[i];
103  p.cp_ = cp[i];
104  i++;
105  }
106 }
107 
108 
109 template<class ParcelType>
111 {
113 
114  label np = c.size();
115 
116  IOField<scalar> T(c.fieldIOobject("T", IOobject::NO_READ), np);
117  IOField<scalar> cp(c.fieldIOobject("cp", IOobject::NO_READ), np);
118 
119  label i = 0;
120  forAllConstIter(typename Cloud<ParcelType>, c, iter)
121  {
122  const ThermoParcel<ParcelType>& p = iter();
123 
124  T[i] = p.T_;
125  cp[i] = p.cp_;
126  i++;
127  }
128 
129  T.write();
130  cp.write();
131 }
132 
133 
134 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
135 
136 template<class ParcelType>
137 Foam::Ostream& Foam::operator<<
138 (
139  Ostream& os,
141 )
142 {
143  if (os.format() == IOstream::ASCII)
144  {
145  os << static_cast<const KinematicParcel<ParcelType>&>(p)
146  << token::SPACE << p.T()
147  << token::SPACE << p.cp();
148  }
149  else
150  {
151  os << static_cast<const KinematicParcel<ParcelType>&>(p);
152  os.write
153  (
154  reinterpret_cast<const char*>(&p.T_),
155  sizeof(p.T()) + sizeof(p.cp())
156  );
157  }
158 
159  // Check state of Ostream
160  os.check
161  (
162  "Ostream& operator<<(Ostream&, const ThermoParcel<ParcelType>&)"
163  );
164 
165  return os;
166 }
167 
168 
169 // ************************ vim: set sw=4 sts=4 et: ************************ //