1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
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 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
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 \*---------------------------------------------------------------------------*/
28 #include "IOstreams.H"
29 #include "moleculeCloud.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 Foam::molecule::molecule
35 const Cloud<molecule>& cloud,
40 Particle<molecule>(cloud, is, readFields),
46 specialPosition_(vector::zero),
47 potentialEnergy_(0.0),
56 if (is.format() == IOstream::ASCII)
65 is >> specialPosition_;
66 potentialEnergy_ = readScalar(is);
68 special_ = readLabel(is);
75 reinterpret_cast<char*>(&Q_),
81 + sizeof(specialPosition_)
82 + sizeof(potentialEnergy_)
88 is >> siteForces_ >> sitePositions_;
92 // Check state of Istream
95 "Foam::molecule::molecule"
96 "(const Cloud<molecule>& cloud, Foam::Istream&), bool"
101 void Foam::molecule::readFields(moleculeCloud& mC)
108 IOField<tensor> Q(mC.fieldIOobject("Q", IOobject::MUST_READ));
109 mC.checkFieldIOobject(mC, Q);
111 IOField<vector> v(mC.fieldIOobject("v", IOobject::MUST_READ));
112 mC.checkFieldIOobject(mC, v);
114 IOField<vector> a(mC.fieldIOobject("a", IOobject::MUST_READ));
115 mC.checkFieldIOobject(mC, a);
117 IOField<vector> pi(mC.fieldIOobject("pi", IOobject::MUST_READ));
118 mC.checkFieldIOobject(mC, pi);
120 IOField<vector> tau(mC.fieldIOobject("tau", IOobject::MUST_READ));
121 mC.checkFieldIOobject(mC, tau);
123 IOField<vector> specialPosition
125 mC.fieldIOobject("specialPosition", IOobject::MUST_READ)
127 mC.checkFieldIOobject(mC, specialPosition);
129 IOField<label> special(mC.fieldIOobject("special", IOobject::MUST_READ));
130 mC.checkFieldIOobject(mC, special);
132 IOField<label> id(mC.fieldIOobject("id", IOobject::MUST_READ));
133 mC.checkFieldIOobject(mC, id);
136 forAllIter(moleculeCloud, mC, iter)
138 molecule& mol = iter();
145 mol.specialPosition_ = specialPosition[i];
146 mol.special_ = special[i];
153 void Foam::molecule::writeFields(const moleculeCloud& mC)
155 Particle<molecule>::writeFields(mC);
157 label np = mC.size();
159 IOField<tensor> Q(mC.fieldIOobject("Q", IOobject::NO_READ), np);
160 IOField<vector> v(mC.fieldIOobject("v", IOobject::NO_READ), np);
161 IOField<vector> a(mC.fieldIOobject("a", IOobject::NO_READ), np);
162 IOField<vector> pi(mC.fieldIOobject("pi", IOobject::NO_READ), np);
163 IOField<vector> tau(mC.fieldIOobject("tau", IOobject::NO_READ), np);
164 IOField<vector> specialPosition
166 mC.fieldIOobject("specialPosition", IOobject::NO_READ),
169 IOField<label> special(mC.fieldIOobject("special", IOobject::NO_READ), np);
170 IOField<label> id(mC.fieldIOobject("id", IOobject::NO_READ), np);
172 // Post processing fields
174 IOField<vector> piGlobal
176 mC.fieldIOobject("piGlobal", IOobject::NO_READ),
180 IOField<vector> tauGlobal
182 mC.fieldIOobject("tauGlobal", IOobject::NO_READ),
186 IOField<vector> orientation1
188 mC.fieldIOobject("orientation1", IOobject::NO_READ),
192 IOField<vector> orientation2
194 mC.fieldIOobject("orientation2", IOobject::NO_READ),
198 IOField<vector> orientation3
200 mC.fieldIOobject("orientation3", IOobject::NO_READ),
205 forAllConstIter(moleculeCloud, mC, iter)
207 const molecule& mol = iter();
214 specialPosition[i] = mol.specialPosition_;
215 special[i] = mol.special_;
218 piGlobal[i] = mol.Q_ & mol.pi_;
219 tauGlobal[i] = mol.Q_ & mol.tau_;
221 orientation1[i] = mol.Q_ & vector(1,0,0);
222 orientation2[i] = mol.Q_ & vector(0,1,0);
223 orientation3[i] = mol.Q_ & vector(0,0,1);
233 specialPosition.write();
240 orientation1.write();
241 orientation2.write();
242 orientation3.write();
246 mC.mesh().time().timePath() + "/lagrangian" + "/moleculeCloud.xmol"
251 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
253 Foam::Ostream& Foam::operator<<(Ostream& os, const molecule& mol)
255 if (os.format() == IOstream::ASCII)
257 os << token::SPACE << static_cast<const Particle<molecule>&>(mol)
258 << token::SPACE << mol.face()
259 << token::SPACE << mol.stepFraction()
260 << token::SPACE << mol.Q_
261 << token::SPACE << mol.v_
262 << token::SPACE << mol.a_
263 << token::SPACE << mol.pi_
264 << token::SPACE << mol.tau_
265 << token::SPACE << mol.specialPosition_
266 << token::SPACE << mol.potentialEnergy_
267 << token::SPACE << mol.rf_
268 << token::SPACE << mol.special_
269 << token::SPACE << mol.id_
270 << token::SPACE << mol.siteForces_
271 << token::SPACE << mol.sitePositions_;
275 os << static_cast<const Particle<molecule>&>(mol);
278 reinterpret_cast<const char*>(&mol.Q_),
284 + sizeof(mol.specialPosition_)
285 + sizeof(mol.potentialEnergy_)
287 + sizeof(mol.special_)
290 os << mol.siteForces_ << mol.sitePositions_;
293 // Check state of Ostream
296 "Foam::Ostream& Foam::operator<<"
297 "(Foam::Ostream&, const Foam::molecule&)"
304 // ************************************************************************* //