initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / lagrangian / molecularDynamics / molecule / molecule / moleculeIO.C
blobfa2e2393048f5d88a457acf0d6385653e7ccafad
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 \*---------------------------------------------------------------------------*/
27 #include "molecule.H"
28 #include "IOstreams.H"
29 #include "moleculeCloud.H"
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 Foam::molecule::molecule
35     const Cloud<molecule>& cloud,
36     Istream& is,
37     bool readFields
40     Particle<molecule>(cloud, is, readFields),
41     Q_(tensor::zero),
42     v_(vector::zero),
43     a_(vector::zero),
44     pi_(vector::zero),
45     tau_(vector::zero),
46     specialPosition_(vector::zero),
47     potentialEnergy_(0.0),
48     rf_(tensor::zero),
49     special_(0),
50     id_(0),
51     siteForces_(0),
52     sitePositions_(0)
54     if (readFields)
55     {
56         if (is.format() == IOstream::ASCII)
57         {
58             is  >> Q_;
59             is  >> v_;
60             is  >> a_;
61             is  >> pi_;
62             is  >> tau_;
63             is  >> siteForces_;
64             is  >> sitePositions_;
65             is  >> specialPosition_;
66             potentialEnergy_ = readScalar(is);
67             is  >> rf_;
68             special_ = readLabel(is);
69             id_ = readLabel(is);
70         }
71         else
72         {
73             is.read
74             (
75                 reinterpret_cast<char*>(&Q_),
76                 sizeof(Q_)
77               + sizeof(v_)
78               + sizeof(a_)
79               + sizeof(pi_)
80               + sizeof(tau_)
81               + sizeof(specialPosition_)
82               + sizeof(potentialEnergy_)
83               + sizeof(rf_)
84               + sizeof(special_)
85               + sizeof(id_)
86             );
88             is  >> siteForces_ >> sitePositions_;
89         }
90     }
92     // Check state of Istream
93     is.check
94     (
95         "Foam::molecule::molecule"
96         "(const Cloud<molecule>& cloud, Foam::Istream&), bool"
97     );
101 void Foam::molecule::readFields(moleculeCloud& mC)
103     if (!mC.size())
104     {
105         return;
106     }
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
124     (
125         mC.fieldIOobject("specialPosition", IOobject::MUST_READ)
126     );
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);
135     label i = 0;
136     forAllIter(moleculeCloud, mC, iter)
137     {
138         molecule& mol = iter();
140         mol.Q_ = Q[i];
141         mol.v_ = v[i];
142         mol.a_ = a[i];
143         mol.pi_ = pi[i];
144         mol.tau_ = tau[i];
145         mol.specialPosition_ = specialPosition[i];
146         mol.special_ = special[i];
147         mol.id_ = id[i];
148         i++;
149     }
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
165     (
166         mC.fieldIOobject("specialPosition", IOobject::NO_READ),
167         np
168     );
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
175     (
176         mC.fieldIOobject("piGlobal", IOobject::NO_READ),
177         np
178     );
180     IOField<vector> tauGlobal
181     (
182         mC.fieldIOobject("tauGlobal", IOobject::NO_READ),
183         np
184     );
186     IOField<vector> orientation1
187     (
188         mC.fieldIOobject("orientation1", IOobject::NO_READ),
189         np
190     );
192     IOField<vector> orientation2
193     (
194         mC.fieldIOobject("orientation2", IOobject::NO_READ),
195         np
196     );
198     IOField<vector> orientation3
199     (
200         mC.fieldIOobject("orientation3", IOobject::NO_READ),
201         np
202     );
204     label i = 0;
205     forAllConstIter(moleculeCloud, mC, iter)
206     {
207         const molecule& mol = iter();
209         Q[i] = mol.Q_;
210         v[i] = mol.v_;
211         a[i] = mol.a_;
212         pi[i] = mol.pi_;
213         tau[i] = mol.tau_;
214         specialPosition[i] = mol.specialPosition_;
215         special[i] = mol.special_;
216         id[i] = mol.id_;
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);
225         i++;
226     }
228     Q.write();
229     v.write();
230     a.write();
231     pi.write();
232     tau.write();
233     specialPosition.write();
234     special.write();
235     id.write();
237     piGlobal.write();
238     tauGlobal.write();
240     orientation1.write();
241     orientation2.write();
242     orientation3.write();
244     mC.writeXYZ
245     (
246         mC.mesh().time().timePath() + "/lagrangian" + "/moleculeCloud.xmol"
247     );
251 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
253 Foam::Ostream& Foam::operator<<(Ostream& os, const molecule& mol)
255     if (os.format() == IOstream::ASCII)
256     {
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_;
272     }
273     else
274     {
275         os  << static_cast<const Particle<molecule>&>(mol);
276         os.write
277         (
278             reinterpret_cast<const char*>(&mol.Q_),
279             sizeof(mol.Q_)
280           + sizeof(mol.v_)
281           + sizeof(mol.a_)
282           + sizeof(mol.pi_)
283           + sizeof(mol.tau_)
284           + sizeof(mol.specialPosition_)
285           + sizeof(mol.potentialEnergy_)
286           + sizeof(mol.rf_)
287           + sizeof(mol.special_)
288           + sizeof(mol.id_)
289         );
290         os  << mol.siteForces_ << mol.sitePositions_;
291     }
293     // Check state of Ostream
294     os.check
295     (
296         "Foam::Ostream& Foam::operator<<"
297         "(Foam::Ostream&, const Foam::molecule&)"
298     );
300     return os;
304 // ************************************************************************* //