1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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"
30 #include "moleculeCloud.H"
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 Foam::molecule::molecule
36 const Cloud<molecule>& cloud,
41 Particle<molecule>(cloud, is)
45 if (is.format() == IOstream::ASCII)
48 mass_ = readScalar(is);
51 is >> potentialEnergy_;
54 is >> tetherPosition_;
60 reinterpret_cast<char*>(&mass_),
64 + sizeof(tetherPosition_)
65 + sizeof(potentialEnergy_)
73 // Check state of Istream
74 is.check("Foam::molecule::molecule(Foam::Istream&)");
81 void molecule::readFields(moleculeCloud& mC)
88 IOField<label> id(mC.fieldIOobject("id"));
89 mC.checkFieldIOobject(mC, id);
91 IOField<scalar> mass(mC.fieldIOobject("mass"));
92 mC.checkFieldIOobject(mC, mass);
94 IOField<vector> U(mC.fieldIOobject("U"));
95 mC.checkFieldIOobject(mC, U);
97 IOField<vector> A(mC.fieldIOobject("A"));
98 mC.checkFieldIOobject(mC, A);
100 IOField<label> tethered(mC.fieldIOobject("tethered"));
101 mC.checkFieldIOobject(mC, tethered);
103 IOField<vector> tetherPositions(mC.fieldIOobject("tetherPositions"));
104 mC.checkFieldIOobject(mC, tetherPositions);
107 forAllIter(moleculeCloud, mC, iter)
109 molecule& mol = iter();
115 mol.potentialEnergy_ = 0.0;
116 mol.rf_ = tensor::zero;
117 mol.tethered_ = tethered[i];
118 mol.tetherPosition_ = tetherPositions[i];
124 void molecule::writeFields(const moleculeCloud& mC)
126 Particle<molecule>::writeFields(mC);
128 label np = mC.size();
130 IOField<label> id(mC.fieldIOobject("id"), np);
131 IOField<scalar> mass(mC.fieldIOobject("mass"), np);
132 IOField<vector> U(mC.fieldIOobject("U"), np);
133 IOField<vector> A(mC.fieldIOobject("A"), np);
134 IOField<label> tethered(mC.fieldIOobject("tethered"), np);
135 IOField<vector> tetherPositions(mC.fieldIOobject("tetherPositions"), np);
138 forAllConstIter(moleculeCloud, mC, iter)
140 const molecule& mol = iter();
146 tethered[i] = mol.tethered_;
147 tetherPositions[i] = mol.tetherPosition_;
156 tetherPositions.write();
159 }; // end of namespace Foam
162 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
164 Foam::Ostream& Foam::operator<<(Ostream& os, const molecule& mol)
166 if (os.format() == IOstream::ASCII)
169 << token::SPACE << mol.mass_
170 << token::SPACE << static_cast<const Particle<molecule>&>(mol)
171 << token::SPACE << mol.face()
172 << token::SPACE << mol.stepFraction()
173 << token::SPACE << mol.U_
174 << token::SPACE << mol.A_
175 << token::SPACE << mol.potentialEnergy_
176 << token::SPACE << mol.rf_
177 << token::SPACE << mol.tethered_
178 << token::SPACE << mol.tetherPosition_;
182 os << static_cast<const Particle<molecule>&>(mol);
185 reinterpret_cast<const char*>(&mol.mass_),
189 + sizeof(mol.tetherPosition_)
190 + sizeof(mol.potentialEnergy_)
192 + sizeof(mol.tethered_)
197 // Check state of Ostream
200 "Foam::Ostream& Foam::operator<<"
201 "(Foam::Ostream&, const Foam::molecule&)"
208 // ************************************************************************* //