00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "molecule.H"
00027 #include <OpenFOAM/IOstreams.H>
00028 #include <molecule/moleculeCloud.H>
00029
00030
00031
00032 Foam::molecule::molecule
00033 (
00034 const Cloud<molecule>& cloud,
00035 Istream& is,
00036 bool readFields
00037 )
00038 :
00039 Particle<molecule>(cloud, is, readFields),
00040 Q_(tensor::zero),
00041 v_(vector::zero),
00042 a_(vector::zero),
00043 pi_(vector::zero),
00044 tau_(vector::zero),
00045 specialPosition_(vector::zero),
00046 potentialEnergy_(0.0),
00047 rf_(tensor::zero),
00048 special_(0),
00049 id_(0),
00050 siteForces_(0),
00051 sitePositions_(0)
00052 {
00053 if (readFields)
00054 {
00055 if (is.format() == IOstream::ASCII)
00056 {
00057 is >> Q_;
00058 is >> v_;
00059 is >> a_;
00060 is >> pi_;
00061 is >> tau_;
00062 is >> siteForces_;
00063 is >> sitePositions_;
00064 is >> specialPosition_;
00065 potentialEnergy_ = readScalar(is);
00066 is >> rf_;
00067 special_ = readLabel(is);
00068 id_ = readLabel(is);
00069 }
00070 else
00071 {
00072 is.read
00073 (
00074 reinterpret_cast<char*>(&Q_),
00075 sizeof(Q_)
00076 + sizeof(v_)
00077 + sizeof(a_)
00078 + sizeof(pi_)
00079 + sizeof(tau_)
00080 + sizeof(specialPosition_)
00081 + sizeof(potentialEnergy_)
00082 + sizeof(rf_)
00083 + sizeof(special_)
00084 + sizeof(id_)
00085 );
00086
00087 is >> siteForces_ >> sitePositions_;
00088 }
00089 }
00090
00091
00092 is.check
00093 (
00094 "Foam::molecule::molecule"
00095 "(const Cloud<molecule>& cloud, Foam::Istream&), bool"
00096 );
00097 }
00098
00099
00100 void Foam::molecule::readFields(Cloud<molecule>& mC)
00101 {
00102 if (!mC.size())
00103 {
00104 return;
00105 }
00106
00107 Particle<molecule>::readFields(mC);
00108
00109 IOField<tensor> Q(mC.fieldIOobject("Q", IOobject::MUST_READ));
00110 mC.checkFieldIOobject(mC, Q);
00111
00112 IOField<vector> v(mC.fieldIOobject("v", IOobject::MUST_READ));
00113 mC.checkFieldIOobject(mC, v);
00114
00115 IOField<vector> a(mC.fieldIOobject("a", IOobject::MUST_READ));
00116 mC.checkFieldIOobject(mC, a);
00117
00118 IOField<vector> pi(mC.fieldIOobject("pi", IOobject::MUST_READ));
00119 mC.checkFieldIOobject(mC, pi);
00120
00121 IOField<vector> tau(mC.fieldIOobject("tau", IOobject::MUST_READ));
00122 mC.checkFieldIOobject(mC, tau);
00123
00124 IOField<vector> specialPosition
00125 (
00126 mC.fieldIOobject("specialPosition", IOobject::MUST_READ)
00127 );
00128 mC.checkFieldIOobject(mC, specialPosition);
00129
00130 IOField<label> special(mC.fieldIOobject("special", IOobject::MUST_READ));
00131 mC.checkFieldIOobject(mC, special);
00132
00133 IOField<label> id(mC.fieldIOobject("id", IOobject::MUST_READ));
00134 mC.checkFieldIOobject(mC, id);
00135
00136 label i = 0;
00137 forAllIter(moleculeCloud, mC, iter)
00138 {
00139 molecule& mol = iter();
00140
00141 mol.Q_ = Q[i];
00142 mol.v_ = v[i];
00143 mol.a_ = a[i];
00144 mol.pi_ = pi[i];
00145 mol.tau_ = tau[i];
00146 mol.specialPosition_ = specialPosition[i];
00147 mol.special_ = special[i];
00148 mol.id_ = id[i];
00149 i++;
00150 }
00151 }
00152
00153
00154 void Foam::molecule::writeFields(const Cloud<molecule>& mC)
00155 {
00156 Particle<molecule>::writeFields(mC);
00157
00158 label np = mC.size();
00159
00160 IOField<tensor> Q(mC.fieldIOobject("Q", IOobject::NO_READ), np);
00161 IOField<vector> v(mC.fieldIOobject("v", IOobject::NO_READ), np);
00162 IOField<vector> a(mC.fieldIOobject("a", IOobject::NO_READ), np);
00163 IOField<vector> pi(mC.fieldIOobject("pi", IOobject::NO_READ), np);
00164 IOField<vector> tau(mC.fieldIOobject("tau", IOobject::NO_READ), np);
00165 IOField<vector> specialPosition
00166 (
00167 mC.fieldIOobject("specialPosition", IOobject::NO_READ),
00168 np
00169 );
00170 IOField<label> special(mC.fieldIOobject("special", IOobject::NO_READ), np);
00171 IOField<label> id(mC.fieldIOobject("id", IOobject::NO_READ), np);
00172
00173
00174
00175 IOField<vector> piGlobal
00176 (
00177 mC.fieldIOobject("piGlobal", IOobject::NO_READ),
00178 np
00179 );
00180
00181 IOField<vector> tauGlobal
00182 (
00183 mC.fieldIOobject("tauGlobal", IOobject::NO_READ),
00184 np
00185 );
00186
00187 IOField<vector> orientation1
00188 (
00189 mC.fieldIOobject("orientation1", IOobject::NO_READ),
00190 np
00191 );
00192
00193 IOField<vector> orientation2
00194 (
00195 mC.fieldIOobject("orientation2", IOobject::NO_READ),
00196 np
00197 );
00198
00199 IOField<vector> orientation3
00200 (
00201 mC.fieldIOobject("orientation3", IOobject::NO_READ),
00202 np
00203 );
00204
00205 label i = 0;
00206 forAllConstIter(moleculeCloud, mC, iter)
00207 {
00208 const molecule& mol = iter();
00209
00210 Q[i] = mol.Q_;
00211 v[i] = mol.v_;
00212 a[i] = mol.a_;
00213 pi[i] = mol.pi_;
00214 tau[i] = mol.tau_;
00215 specialPosition[i] = mol.specialPosition_;
00216 special[i] = mol.special_;
00217 id[i] = mol.id_;
00218
00219 piGlobal[i] = mol.Q_ & mol.pi_;
00220 tauGlobal[i] = mol.Q_ & mol.tau_;
00221
00222 orientation1[i] = mol.Q_ & vector(1,0,0);
00223 orientation2[i] = mol.Q_ & vector(0,1,0);
00224 orientation3[i] = mol.Q_ & vector(0,0,1);
00225
00226 i++;
00227 }
00228
00229 Q.write();
00230 v.write();
00231 a.write();
00232 pi.write();
00233 tau.write();
00234 specialPosition.write();
00235 special.write();
00236 id.write();
00237
00238 piGlobal.write();
00239 tauGlobal.write();
00240
00241 orientation1.write();
00242 orientation2.write();
00243 orientation3.write();
00244
00245 const moleculeCloud& m = dynamic_cast<const moleculeCloud&>(mC);
00246 m.writeXYZ
00247 (
00248 m.mesh().time().timePath() + "/lagrangian" + "/moleculeCloud.xmol"
00249 );
00250 }
00251
00252
00253
00254
00255 Foam::Ostream& Foam::operator<<(Ostream& os, const molecule& mol)
00256 {
00257 if (os.format() == IOstream::ASCII)
00258 {
00259 os << token::SPACE << static_cast<const Particle<molecule>&>(mol)
00260 << token::SPACE << mol.face()
00261 << token::SPACE << mol.stepFraction()
00262 << token::SPACE << mol.Q_
00263 << token::SPACE << mol.v_
00264 << token::SPACE << mol.a_
00265 << token::SPACE << mol.pi_
00266 << token::SPACE << mol.tau_
00267 << token::SPACE << mol.specialPosition_
00268 << token::SPACE << mol.potentialEnergy_
00269 << token::SPACE << mol.rf_
00270 << token::SPACE << mol.special_
00271 << token::SPACE << mol.id_
00272 << token::SPACE << mol.siteForces_
00273 << token::SPACE << mol.sitePositions_;
00274 }
00275 else
00276 {
00277 os << static_cast<const Particle<molecule>&>(mol);
00278 os.write
00279 (
00280 reinterpret_cast<const char*>(&mol.Q_),
00281 sizeof(mol.Q_)
00282 + sizeof(mol.v_)
00283 + sizeof(mol.a_)
00284 + sizeof(mol.pi_)
00285 + sizeof(mol.tau_)
00286 + sizeof(mol.specialPosition_)
00287 + sizeof(mol.potentialEnergy_)
00288 + sizeof(mol.rf_)
00289 + sizeof(mol.special_)
00290 + sizeof(mol.id_)
00291 );
00292 os << mol.siteForces_ << mol.sitePositions_;
00293 }
00294
00295
00296 os.check
00297 (
00298 "Foam::Ostream& Foam::operator<<"
00299 "(Foam::Ostream&, const Foam::molecule&)"
00300 );
00301
00302 return os;
00303 }
00304
00305
00306