FreeFOAM The Cross-Platform CFD Toolkit
KinematicParcelIO.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 "KinematicParcel.H"
27 #include <OpenFOAM/IOstreams.H>
28 #include <OpenFOAM/IOField.H>
29 #include <lagrangian/Cloud.H>
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 template <class ParcelType>
35  Particle<ParcelType>::propHeader
36  + " active"
37  + " typeId"
38  + " nParticle"
39  + " d"
40  + " (Ux Uy Uz)"
41  + " rho"
42  + " tTurb"
43  + " (UTurbx UTurby UTurbz)";
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
48 template <class ParcelType>
50 (
51  const Cloud<ParcelType>& cloud,
52  Istream& is,
53  bool readFields
54 )
55 :
56  Particle<ParcelType>(cloud, is, readFields),
57  active_(false),
58  typeId_(0),
59  nParticle_(0.0),
60  d_(0.0),
61  U_(vector::zero),
62  rho_(0.0),
63  tTurb_(0.0),
64  UTurb_(vector::zero),
65  rhoc_(0.0),
66  Uc_(vector::zero),
67  muc_(0.0)
68 {
69  if (readFields)
70  {
71  if (is.format() == IOstream::ASCII)
72  {
73  active_ = readBool(is);
74  typeId_ = readLabel(is);
75  nParticle_ = readScalar(is);
76  d_ = readScalar(is);
77  is >> U_;
78  rho_ = readScalar(is);
79  tTurb_ = readScalar(is);
80  is >> UTurb_;
81  }
82  else
83  {
84  is.read
85  (
86  reinterpret_cast<char*>(&active_),
87  sizeof(active_)
88  + sizeof(typeId_)
89  + sizeof(nParticle_)
90  + sizeof(d_)
91  + sizeof(U_)
92  + sizeof(rho_)
93  + sizeof(tTurb_)
94  + sizeof(UTurb_)
95  );
96  }
97  }
98 
99  // Check state of Istream
100  is.check
101  (
102  "KinematicParcel<ParcelType>::KinematicParcel"
103  "(const Cloud<ParcelType>&, Istream&, bool)"
104  );
105 }
106 
107 
108 template<class ParcelType>
110 {
111  if (!c.size())
112  {
113  return;
114  }
115 
117 
118  IOField<label> active(c.fieldIOobject("active", IOobject::MUST_READ));
119  c.checkFieldIOobject(c, active);
120 
121  IOField<label> typeId(c.fieldIOobject("typeId", IOobject::MUST_READ));
122  c.checkFieldIOobject(c, typeId);
123 
125  nParticle(c.fieldIOobject("nParticle", IOobject::MUST_READ));
126  c.checkFieldIOobject(c, nParticle);
127 
128  IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
129  c.checkFieldIOobject(c, d);
130 
131  IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
132  c.checkFieldIOobject(c, U);
133 
134  IOField<scalar> rho(c.fieldIOobject("rho", IOobject::MUST_READ));
135  c.checkFieldIOobject(c, rho);
136 
137  IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::MUST_READ));
138  c.checkFieldIOobject(c, tTurb);
139 
140  IOField<vector> UTurb(c.fieldIOobject("UTurb", IOobject::MUST_READ));
141  c.checkFieldIOobject(c, UTurb);
142 
143  label i = 0;
144  forAllIter(typename Cloud<ParcelType>, c, iter)
145  {
146  ParcelType& p = iter();
147 
148  p.active_ = active[i];
149  p.typeId_ = typeId[i];
150  p.nParticle_ = nParticle[i];
151  p.d_ = d[i];
152  p.U_ = U[i];
153  p.rho_ = rho[i];
154  p.tTurb_ = tTurb[i];
155  p.UTurb_ = UTurb[i];
156  i++;
157  }
158 }
159 
160 
161 template<class ParcelType>
163 {
165 
166  label np = c.size();
167 
168  IOField<label> active(c.fieldIOobject("active", IOobject::NO_READ), np);
169  IOField<label> typeId(c.fieldIOobject("typeId", IOobject::NO_READ), np);
170  IOField<scalar> nParticle
171  (
172  c.fieldIOobject("nParticle", IOobject::NO_READ),
173  np
174  );
175  IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
176  IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
177  IOField<scalar> rho(c.fieldIOobject("rho", IOobject::NO_READ), np);
178  IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::NO_READ), np);
179  IOField<vector> UTurb(c.fieldIOobject("UTurb", IOobject::NO_READ), np);
180 
181  label i = 0;
182  forAllConstIter(typename Cloud<ParcelType>, c, iter)
183  {
184  const KinematicParcel<ParcelType>& p = iter();
185 
186  active[i] = p.active();
187  typeId[i] = p.typeId();
188  nParticle[i] = p.nParticle();
189  d[i] = p.d();
190  U[i] = p.U();
191  rho[i] = p.rho();
192  tTurb[i] = p.tTurb();
193  UTurb[i] = p.UTurb();
194  i++;
195  }
196 
197  active.write();
198  typeId.write();
199  nParticle.write();
200  d.write();
201  U.write();
202  rho.write();
203  tTurb.write();
204  UTurb.write();
205 }
206 
207 
208 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
209 
210 template<class ParcelType>
211 Foam::Ostream& Foam::operator<<
212 (
213  Ostream& os,
215 )
216 {
217  if (os.format() == IOstream::ASCII)
218  {
219  os << static_cast<const Particle<ParcelType>&>(p)
220  << token::SPACE << p.active()
221  << token::SPACE << p.typeId()
222  << token::SPACE << p.nParticle()
223  << token::SPACE << p.d()
224  << token::SPACE << p.U()
225  << token::SPACE << p.rho()
226  << token::SPACE << p.tTurb()
227  << token::SPACE << p.UTurb();
228  }
229  else
230  {
231  os << static_cast<const Particle<ParcelType>&>(p);
232  os.write
233  (
234  reinterpret_cast<const char*>(&p.active_),
235  sizeof(p.active())
236  + sizeof(p.typeId())
237  + sizeof(p.nParticle())
238  + sizeof(p.d())
239  + sizeof(p.U())
240  + sizeof(p.rho())
241  + sizeof(p.tTurb())
242  + sizeof(p.UTurb())
243  );
244  }
245 
246  // Check state of Ostream
247  os.check
248  (
249  "Ostream& operator<<(Ostream&, const KinematicParcel<ParcelType>&)"
250  );
251 
252  return os;
253 }
254 
255 
256 // ************************ vim: set sw=4 sts=4 et: ************************ //