1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
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 "KinematicParcel.H"
27 #include "IOstreams.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 template<class ParcelType>
34 Foam::string Foam::KinematicParcel<ParcelType>::propHeader =
35 ParcelType::propHeader
43 + " (angularMomentumx angularMomentumy angularMomentumz)"
44 + " (torquex torquey torquez)"
48 + " (UTurbx UTurby UTurbz)";
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 template<class ParcelType>
53 Foam::KinematicParcel<ParcelType>::KinematicParcel
60 ParcelType(mesh, is, readFields),
68 angularMomentum_(vector::zero),
69 torque_(vector::zero),
80 if (is.format() == IOstream::ASCII)
82 active_ = readBool(is);
83 typeId_ = readLabel(is);
84 nParticle_ = readScalar(is);
86 dTarget_ = readScalar(is);
89 is >> angularMomentum_;
91 rho_ = readScalar(is);
92 age_ = readScalar(is);
93 tTurb_ = readScalar(is);
100 reinterpret_cast<char*>(&active_),
108 + sizeof(angularMomentum_)
118 // Check state of Istream
121 "KinematicParcel<ParcelType>::KinematicParcel"
122 "(const polyMesh&, Istream&, bool)"
127 template<class ParcelType>
128 template<class CloudType>
129 void Foam::KinematicParcel<ParcelType>::readFields(CloudType& c)
136 ParcelType::readFields(c);
138 IOField<label> active(c.fieldIOobject("active", IOobject::MUST_READ));
139 c.checkFieldIOobject(c, active);
141 IOField<label> typeId(c.fieldIOobject("typeId", IOobject::MUST_READ));
142 c.checkFieldIOobject(c, typeId);
145 nParticle(c.fieldIOobject("nParticle", IOobject::MUST_READ));
146 c.checkFieldIOobject(c, nParticle);
148 IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
149 c.checkFieldIOobject(c, d);
151 IOField<scalar> dTarget(c.fieldIOobject("dTarget", IOobject::MUST_READ));
152 c.checkFieldIOobject(c, dTarget);
154 IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
155 c.checkFieldIOobject(c, U);
157 IOField<vector> f(c.fieldIOobject("f", IOobject::MUST_READ));
158 c.checkFieldIOobject(c, f);
160 IOField<vector> angularMomentum
162 c.fieldIOobject("angularMomentum", IOobject::MUST_READ)
164 c.checkFieldIOobject(c, angularMomentum);
166 IOField<vector> torque(c.fieldIOobject("torque", IOobject::MUST_READ));
167 c.checkFieldIOobject(c, torque);
169 IOField<scalar> rho(c.fieldIOobject("rho", IOobject::MUST_READ));
170 c.checkFieldIOobject(c, rho);
172 IOField<scalar> age(c.fieldIOobject("age", IOobject::MUST_READ));
173 c.checkFieldIOobject(c, age);
175 IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::MUST_READ));
176 c.checkFieldIOobject(c, tTurb);
178 IOField<vector> UTurb(c.fieldIOobject("UTurb", IOobject::MUST_READ));
179 c.checkFieldIOobject(c, UTurb);
183 forAllIter(typename CloudType, c, iter)
185 KinematicParcel<ParcelType>& p = iter();
187 p.active_ = active[i];
188 p.typeId_ = typeId[i];
189 p.nParticle_ = nParticle[i];
191 p.dTarget_ = dTarget[i];
194 p.angularMomentum_ = angularMomentum[i];
205 template<class ParcelType>
206 template<class CloudType>
207 void Foam::KinematicParcel<ParcelType>::writeFields(const CloudType& c)
209 ParcelType::writeFields(c);
213 IOField<label> active(c.fieldIOobject("active", IOobject::NO_READ), np);
214 IOField<label> typeId(c.fieldIOobject("typeId", IOobject::NO_READ), np);
215 IOField<scalar> nParticle
217 c.fieldIOobject("nParticle", IOobject::NO_READ),
220 IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
221 IOField<scalar> dTarget(c.fieldIOobject("dTarget", IOobject::NO_READ), np);
222 IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
223 IOField<vector> f(c.fieldIOobject("f", IOobject::NO_READ), np);
224 IOField<vector> angularMomentum
226 c.fieldIOobject("angularMomentum", IOobject::NO_READ),
229 IOField<vector> torque(c.fieldIOobject("torque", IOobject::NO_READ), np);
230 IOField<scalar> rho(c.fieldIOobject("rho", IOobject::NO_READ), np);
231 IOField<scalar> age(c.fieldIOobject("age", IOobject::NO_READ), np);
232 IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::NO_READ), np);
233 IOField<vector> UTurb(c.fieldIOobject("UTurb", IOobject::NO_READ), np);
237 forAllConstIter(typename CloudType, c, iter)
239 const KinematicParcel<ParcelType>& p = iter();
241 active[i] = p.active();
242 typeId[i] = p.typeId();
243 nParticle[i] = p.nParticle();
245 dTarget[i] = p.dTarget();
248 angularMomentum[i] = p.angularMomentum();
249 torque[i] = p.torque();
252 tTurb[i] = p.tTurb();
253 UTurb[i] = p.UTurb();
265 angularMomentum.write();
274 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
276 template<class ParcelType>
277 Foam::Ostream& Foam::operator<<
280 const KinematicParcel<ParcelType>& p
283 if (os.format() == IOstream::ASCII)
285 os << static_cast<const ParcelType&>(p)
286 << token::SPACE << p.active()
287 << token::SPACE << p.typeId()
288 << token::SPACE << p.nParticle()
289 << token::SPACE << p.d()
290 << token::SPACE << p.dTarget()
291 << token::SPACE << p.U()
292 << token::SPACE << p.f()
293 << token::SPACE << p.angularMomentum()
294 << token::SPACE << p.torque()
295 << token::SPACE << p.rho()
296 << token::SPACE << p.age()
297 << token::SPACE << p.tTurb()
298 << token::SPACE << p.UTurb();
302 os << static_cast<const ParcelType&>(p);
305 reinterpret_cast<const char*>(&p.active_),
308 + sizeof(p.nParticle())
310 + sizeof(p.dTarget())
313 + sizeof(p.angularMomentum())
322 // Check state of Ostream
325 "Ostream& operator<<(Ostream&, const KinematicParcel<ParcelType>&)"
332 // ************************************************************************* //