OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

moleculeIO.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 2008-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "molecule.H"
00028 #include "IOstreams.H"
00029 #include "moleculeCloud.H"
00030 
00031 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00032 
00033 Foam::molecule::molecule
00034 (
00035     const Cloud<molecule>& cloud,
00036     Istream& is,
00037     bool readFields
00038 )
00039 :
00040     Particle<molecule>(cloud, is, readFields),
00041     Q_(tensor::zero),
00042     v_(vector::zero),
00043     a_(vector::zero),
00044     pi_(vector::zero),
00045     tau_(vector::zero),
00046     specialPosition_(vector::zero),
00047     potentialEnergy_(0.0),
00048     rf_(tensor::zero),
00049     special_(0),
00050     id_(0),
00051     siteForces_(0),
00052     sitePositions_(0)
00053 {
00054     if (readFields)
00055     {
00056         if (is.format() == IOstream::ASCII)
00057         {
00058             is  >> Q_;
00059             is  >> v_;
00060             is  >> a_;
00061             is  >> pi_;
00062             is  >> tau_;
00063             is  >> siteForces_;
00064             is  >> sitePositions_;
00065             is  >> specialPosition_;
00066             potentialEnergy_ = readScalar(is);
00067             is  >> rf_;
00068             special_ = readLabel(is);
00069             id_ = readLabel(is);
00070         }
00071         else
00072         {
00073             is.read
00074             (
00075                 reinterpret_cast<char*>(&Q_),
00076                 sizeof(Q_)
00077               + sizeof(v_)
00078               + sizeof(a_)
00079               + sizeof(pi_)
00080               + sizeof(tau_)
00081               + sizeof(specialPosition_)
00082               + sizeof(potentialEnergy_)
00083               + sizeof(rf_)
00084               + sizeof(special_)
00085               + sizeof(id_)
00086             );
00087 
00088             is  >> siteForces_ >> sitePositions_;
00089         }
00090     }
00091 
00092     // Check state of Istream
00093     is.check
00094     (
00095         "Foam::molecule::molecule"
00096         "(const Cloud<molecule>& cloud, Foam::Istream&), bool"
00097     );
00098 }
00099 
00100 
00101 void Foam::molecule::readFields(moleculeCloud& mC)
00102 {
00103     if (!mC.size())
00104     {
00105         return;
00106     }
00107 
00108     IOField<tensor> Q(mC.fieldIOobject("Q", IOobject::MUST_READ));
00109     mC.checkFieldIOobject(mC, Q);
00110 
00111     IOField<vector> v(mC.fieldIOobject("v", IOobject::MUST_READ));
00112     mC.checkFieldIOobject(mC, v);
00113 
00114     IOField<vector> a(mC.fieldIOobject("a", IOobject::MUST_READ));
00115     mC.checkFieldIOobject(mC, a);
00116 
00117     IOField<vector> pi(mC.fieldIOobject("pi", IOobject::MUST_READ));
00118     mC.checkFieldIOobject(mC, pi);
00119 
00120     IOField<vector> tau(mC.fieldIOobject("tau", IOobject::MUST_READ));
00121     mC.checkFieldIOobject(mC, tau);
00122 
00123     IOField<vector> specialPosition
00124     (
00125         mC.fieldIOobject("specialPosition", IOobject::MUST_READ)
00126     );
00127     mC.checkFieldIOobject(mC, specialPosition);
00128 
00129     IOField<label> special(mC.fieldIOobject("special", IOobject::MUST_READ));
00130     mC.checkFieldIOobject(mC, special);
00131 
00132     IOField<label> id(mC.fieldIOobject("id", IOobject::MUST_READ));
00133     mC.checkFieldIOobject(mC, id);
00134 
00135     label i = 0;
00136     forAllIter(moleculeCloud, mC, iter)
00137     {
00138         molecule& mol = iter();
00139 
00140         mol.Q_ = Q[i];
00141         mol.v_ = v[i];
00142         mol.a_ = a[i];
00143         mol.pi_ = pi[i];
00144         mol.tau_ = tau[i];
00145         mol.specialPosition_ = specialPosition[i];
00146         mol.special_ = special[i];
00147         mol.id_ = id[i];
00148         i++;
00149     }
00150 }
00151 
00152 
00153 void Foam::molecule::writeFields(const moleculeCloud& mC)
00154 {
00155     Particle<molecule>::writeFields(mC);
00156 
00157     label np = mC.size();
00158 
00159     IOField<tensor> Q(mC.fieldIOobject("Q", IOobject::NO_READ), np);
00160     IOField<vector> v(mC.fieldIOobject("v", IOobject::NO_READ), np);
00161     IOField<vector> a(mC.fieldIOobject("a", IOobject::NO_READ), np);
00162     IOField<vector> pi(mC.fieldIOobject("pi", IOobject::NO_READ), np);
00163     IOField<vector> tau(mC.fieldIOobject("tau", IOobject::NO_READ), np);
00164     IOField<vector> specialPosition
00165     (
00166         mC.fieldIOobject("specialPosition", IOobject::NO_READ),
00167         np
00168     );
00169     IOField<label> special(mC.fieldIOobject("special", IOobject::NO_READ), np);
00170     IOField<label> id(mC.fieldIOobject("id", IOobject::NO_READ), np);
00171 
00172     // Post processing fields
00173 
00174     IOField<vector> piGlobal
00175     (
00176         mC.fieldIOobject("piGlobal", IOobject::NO_READ),
00177         np
00178     );
00179 
00180     IOField<vector> tauGlobal
00181     (
00182         mC.fieldIOobject("tauGlobal", IOobject::NO_READ),
00183         np
00184     );
00185 
00186     IOField<vector> orientation1
00187     (
00188         mC.fieldIOobject("orientation1", IOobject::NO_READ),
00189         np
00190     );
00191 
00192     IOField<vector> orientation2
00193     (
00194         mC.fieldIOobject("orientation2", IOobject::NO_READ),
00195         np
00196     );
00197 
00198     IOField<vector> orientation3
00199     (
00200         mC.fieldIOobject("orientation3", IOobject::NO_READ),
00201         np
00202     );
00203 
00204     label i = 0;
00205     forAllConstIter(moleculeCloud, mC, iter)
00206     {
00207         const molecule& mol = iter();
00208 
00209         Q[i] = mol.Q_;
00210         v[i] = mol.v_;
00211         a[i] = mol.a_;
00212         pi[i] = mol.pi_;
00213         tau[i] = mol.tau_;
00214         specialPosition[i] = mol.specialPosition_;
00215         special[i] = mol.special_;
00216         id[i] = mol.id_;
00217 
00218         piGlobal[i] = mol.Q_ & mol.pi_;
00219         tauGlobal[i] = mol.Q_ & mol.tau_;
00220 
00221         orientation1[i] = mol.Q_ & vector(1,0,0);
00222         orientation2[i] = mol.Q_ & vector(0,1,0);
00223         orientation3[i] = mol.Q_ & vector(0,0,1);
00224 
00225         i++;
00226     }
00227 
00228     Q.write();
00229     v.write();
00230     a.write();
00231     pi.write();
00232     tau.write();
00233     specialPosition.write();
00234     special.write();
00235     id.write();
00236 
00237     piGlobal.write();
00238     tauGlobal.write();
00239 
00240     orientation1.write();
00241     orientation2.write();
00242     orientation3.write();
00243 
00244     mC.writeXYZ
00245     (
00246         mC.mesh().time().timePath() + "/lagrangian" + "/moleculeCloud.xmol"
00247     );
00248 }
00249 
00250 
00251 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00252 
00253 Foam::Ostream& Foam::operator<<(Ostream& os, const molecule& mol)
00254 {
00255     if (os.format() == IOstream::ASCII)
00256     {
00257         os  << token::SPACE << static_cast<const Particle<molecule>&>(mol)
00258             << token::SPACE << mol.face()
00259             << token::SPACE << mol.stepFraction()
00260             << token::SPACE << mol.Q_
00261             << token::SPACE << mol.v_
00262             << token::SPACE << mol.a_
00263             << token::SPACE << mol.pi_
00264             << token::SPACE << mol.tau_
00265             << token::SPACE << mol.specialPosition_
00266             << token::SPACE << mol.potentialEnergy_
00267             << token::SPACE << mol.rf_
00268             << token::SPACE << mol.special_
00269             << token::SPACE << mol.id_
00270             << token::SPACE << mol.siteForces_
00271             << token::SPACE << mol.sitePositions_;
00272     }
00273     else
00274     {
00275         os  << static_cast<const Particle<molecule>&>(mol);
00276         os.write
00277         (
00278             reinterpret_cast<const char*>(&mol.Q_),
00279             sizeof(mol.Q_)
00280           + sizeof(mol.v_)
00281           + sizeof(mol.a_)
00282           + sizeof(mol.pi_)
00283           + sizeof(mol.tau_)
00284           + sizeof(mol.specialPosition_)
00285           + sizeof(mol.potentialEnergy_)
00286           + sizeof(mol.rf_)
00287           + sizeof(mol.special_)
00288           + sizeof(mol.id_)
00289         );
00290         os  << mol.siteForces_ << mol.sitePositions_;
00291     }
00292 
00293     // Check state of Ostream
00294     os.check
00295     (
00296         "Foam::Ostream& Foam::operator<<"
00297         "(Foam::Ostream&, const Foam::molecule&)"
00298     );
00299 
00300     return os;
00301 }
00302 
00303 
00304 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd