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

moleculeI.H

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 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00028 
00029 inline Foam::molecule::constantProperties::constantProperties()
00030 :
00031     siteReferencePositions_(Field<vector>(0)),
00032     siteMasses_(List<scalar>(0)),
00033     siteCharges_(List<scalar>(0)),
00034     siteIds_(List<label>(0)),
00035     pairPotentialSites_(List<bool>(false)),
00036     electrostaticSites_(List<bool>(false)),
00037     momentOfInertia_(diagTensor(0, 0, 0)),
00038     mass_(0)
00039 {}
00040 
00041 
00042 inline Foam::molecule::constantProperties::constantProperties
00043 (
00044     const dictionary& dict
00045 )
00046 :
00047     siteReferencePositions_(dict.lookup("siteReferencePositions")),
00048     siteMasses_(dict.lookup("siteMasses")),
00049     siteCharges_(dict.lookup("siteCharges")),
00050     siteIds_(List<word>(dict.lookup("siteIds")).size(), -1),
00051     pairPotentialSites_(),
00052     electrostaticSites_(),
00053     momentOfInertia_(),
00054     mass_()
00055 {
00056     checkSiteListSizes();
00057 
00058     setInteracionSiteBools
00059     (
00060         List<word>(dict.lookup("siteIds")),
00061         List<word>(dict.lookup("pairPotentialSiteIds"))
00062     );
00063 
00064     mass_ = sum(siteMasses_);
00065 
00066     vector centreOfMass(vector::zero);
00067 
00068     // Calculate the centre of mass of the body and subtract it from each
00069     // position
00070 
00071     forAll(siteReferencePositions_, i)
00072     {
00073         centreOfMass += siteReferencePositions_[i]*siteMasses_[i];
00074     }
00075 
00076     centreOfMass /= mass_;
00077 
00078     siteReferencePositions_ -= centreOfMass;
00079 
00080     if(siteIds_.size() == 1)
00081     {
00082         // Single site molecule - no rotational motion.
00083 
00084         siteReferencePositions_[0] = vector::zero;
00085 
00086         momentOfInertia_ = diagTensor(-1, -1, -1);
00087     }
00088     else if(linearMoleculeTest())
00089     {
00090         // Linear molecule.
00091 
00092         Info<< nl << "Linear molecule." << endl;
00093 
00094         vector dir = siteReferencePositions_[1] - siteReferencePositions_[0];
00095 
00096         dir /= mag(dir);
00097 
00098         tensor Q = rotationTensor(dir, vector(1,0,0));
00099 
00100         siteReferencePositions_ = (Q & siteReferencePositions_);
00101 
00102         // The rotation was around the centre of mass but remove any
00103         // components that have crept in due to floating point errors
00104 
00105         centreOfMass = vector::zero;
00106 
00107         forAll(siteReferencePositions_, i)
00108         {
00109             centreOfMass += siteReferencePositions_[i]*siteMasses_[i];
00110         }
00111 
00112         centreOfMass /= mass_;
00113 
00114         siteReferencePositions_ -= centreOfMass;
00115 
00116         diagTensor momOfInertia = diagTensor::zero;
00117 
00118         forAll(siteReferencePositions_, i)
00119         {
00120             const vector& p(siteReferencePositions_[i]);
00121 
00122             momOfInertia +=
00123                 siteMasses_[i]*diagTensor(0, p.x()*p.x(), p.x()*p.x());
00124         }
00125 
00126         momentOfInertia_ = diagTensor
00127          (
00128              -1,
00129              momOfInertia.yy(),
00130              momOfInertia.zz()
00131          );
00132     }
00133     else
00134     {
00135         // Fully 6DOF molecule
00136 
00137         // Calculate the inertia tensor in the current orientation
00138 
00139         tensor momOfInertia(tensor::zero);
00140 
00141         forAll(siteReferencePositions_, i)
00142         {
00143             const vector& p(siteReferencePositions_[i]);
00144 
00145             momOfInertia += siteMasses_[i]*tensor
00146             (
00147                 p.y()*p.y() + p.z()*p.z(), -p.x()*p.y(), -p.x()*p.z(),
00148                 -p.y()*p.x(), p.x()*p.x() + p.z()*p.z(), -p.y()*p.z(),
00149                 -p.z()*p.x(), -p.z()*p.y(), p.x()*p.x() + p.y()*p.y()
00150             );
00151         }
00152 
00153         if (eigenValues(momOfInertia).x() < VSMALL)
00154         {
00155             FatalErrorIn("molecule::constantProperties::constantProperties")
00156                 << "An eigenvalue of the inertia tensor is zero, the molecule "
00157                 << dict.name() << " is not a valid 6DOF shape."
00158                 << nl << abort(FatalError);
00159         }
00160 
00161         // Normalise the inertia tensor magnitude to avoid SMALL numbers in the
00162         // components causing problems
00163 
00164         momOfInertia /= eigenValues(momOfInertia).x();
00165 
00166         tensor e = eigenVectors(momOfInertia);
00167 
00168         // Calculate the transformation between the principle axes to the
00169         // global axes
00170 
00171         tensor Q =
00172             vector(1,0,0)*e.x() + vector(0,1,0)*e.y() + vector(0,0,1)*e.z();
00173 
00174         // Transform the site positions
00175 
00176         siteReferencePositions_ = (Q & siteReferencePositions_);
00177 
00178         // Recalculating the moment of inertia with the new site positions
00179 
00180         // The rotation was around the centre of mass but remove any
00181         // components that have crept in due to floating point errors
00182 
00183         centreOfMass = vector::zero;
00184 
00185         forAll(siteReferencePositions_, i)
00186         {
00187             centreOfMass += siteReferencePositions_[i]*siteMasses_[i];
00188         }
00189 
00190         centreOfMass /= mass_;
00191 
00192         siteReferencePositions_ -= centreOfMass;
00193 
00194         // Calculate the moment of inertia in the principle component
00195         // reference frame
00196 
00197         momOfInertia = tensor::zero;
00198 
00199         forAll(siteReferencePositions_, i)
00200         {
00201             const vector& p(siteReferencePositions_[i]);
00202 
00203             momOfInertia += siteMasses_[i]*tensor
00204             (
00205                 p.y()*p.y() + p.z()*p.z(), -p.x()*p.y(), -p.x()*p.z(),
00206                 -p.y()*p.x(), p.x()*p.x() + p.z()*p.z(), -p.y()*p.z(),
00207                 -p.z()*p.x(), -p.z()*p.y(), p.x()*p.x() + p.y()*p.y()
00208             );
00209         }
00210 
00211         momentOfInertia_ = diagTensor
00212         (
00213             momOfInertia.xx(),
00214             momOfInertia.yy(),
00215             momOfInertia.zz()
00216         );
00217     }
00218 }
00219 
00220 
00221 inline Foam::molecule::molecule
00222 (
00223     const Cloud<molecule>& c,
00224     const vector& position,
00225     const label celli,
00226     const tensor& Q,
00227     const vector& v,
00228     const vector& a,
00229     const vector& pi,
00230     const vector& tau,
00231     const vector& specialPosition,
00232     const constantProperties& constProps,
00233     const label special,
00234     const label id
00235 
00236 )
00237 :
00238     Particle<molecule>(c, position, celli),
00239     Q_(Q),
00240     v_(v),
00241     a_(a),
00242     pi_(pi),
00243     tau_(tau),
00244     specialPosition_(specialPosition),
00245     potentialEnergy_(0.0),
00246     rf_(tensor::zero),
00247     special_(special),
00248     id_(id),
00249     siteForces_(constProps.nSites(), vector::zero),
00250     sitePositions_(constProps.nSites())
00251 {
00252     setSitePositions(constProps);
00253 }
00254 
00255 
00256 // * * * constantProperties Private Member Functions * * * * * * * * * * * * //
00257 
00258 
00259 inline void Foam::molecule::constantProperties::checkSiteListSizes() const
00260 {
00261     if
00262     (
00263         siteIds_.size() != siteReferencePositions_.size()
00264      || siteIds_.size() != siteCharges_.size()
00265     )
00266     {
00267         FatalErrorIn("molecule::constantProperties::checkSiteListSizes")
00268             << "Sizes of site id, charge and "
00269             << "referencePositions are not the same. "
00270             << nl << abort(FatalError);
00271     }
00272 }
00273 
00274 
00275 inline void Foam::molecule::constantProperties::setInteracionSiteBools
00276 (
00277     const List<word>& siteIds,
00278     const List<word>& pairPotSiteIds
00279 )
00280 {
00281     pairPotentialSites_.setSize(siteIds_.size());
00282 
00283     electrostaticSites_.setSize(siteIds_.size());
00284 
00285     forAll(siteIds_, i)
00286     {
00287         const word& id(siteIds[i]);
00288 
00289         pairPotentialSites_[i] = (findIndex(pairPotSiteIds, id) > -1);
00290 
00291         electrostaticSites_[i] = (mag(siteCharges_[i]) > VSMALL);
00292     }
00293 }
00294 
00295 
00296 inline bool Foam::molecule::constantProperties::linearMoleculeTest() const
00297 {
00298     if (siteIds_.size() == 2)
00299     {
00300         return true;
00301     }
00302 
00303     vector refDir = siteReferencePositions_[1] - siteReferencePositions_[0];
00304 
00305     refDir /= mag(refDir);
00306 
00307     for
00308     (
00309         label i = 2;
00310         i < siteReferencePositions_.size();
00311         i++
00312     )
00313     {
00314         vector dir = siteReferencePositions_[i] - siteReferencePositions_[i-1];
00315 
00316         dir /= mag(dir);
00317 
00318         if (mag(refDir & dir) < 1 - SMALL)
00319         {
00320             return false;
00321         }
00322     }
00323 
00324     return true;
00325 }
00326 
00327 
00328 // * * * * * * * constantProperties Member Functions * * * * * * * * * * * * //
00329 
00330 inline const Foam::Field<Foam::vector>&
00331 Foam::molecule::constantProperties::siteReferencePositions() const
00332 {
00333     return siteReferencePositions_;
00334 }
00335 
00336 
00337 inline const Foam::List<Foam::scalar>&
00338 Foam::molecule::constantProperties::siteMasses() const
00339 {
00340     return siteMasses_;
00341 }
00342 
00343 
00344 inline const Foam::List<Foam::scalar>&
00345 Foam::molecule::constantProperties::siteCharges() const
00346 {
00347     return siteCharges_;
00348 }
00349 
00350 
00351 inline const Foam::List<Foam::label>&
00352 Foam::molecule::constantProperties::siteIds() const
00353 {
00354     return siteIds_;
00355 }
00356 
00357 
00358 inline Foam::List<Foam::label>&
00359 Foam::molecule::constantProperties::siteIds()
00360 {
00361     return siteIds_;
00362 }
00363 
00364 
00365 inline const Foam::List<bool>&
00366 Foam::molecule::constantProperties::pairPotentialSites() const
00367 {
00368     return pairPotentialSites_;
00369 }
00370 
00371 
00372 inline bool Foam::molecule::constantProperties::pairPotentialSite
00373 (
00374     label sId
00375 ) const
00376 {
00377     label s = findIndex(siteIds_, sId);
00378 
00379     if (s == -1)
00380     {
00381         FatalErrorIn("moleculeI.H") << nl
00382             << sId << " site not found."
00383             << nl << abort(FatalError);
00384     }
00385 
00386     return pairPotentialSites_[s];
00387 }
00388 
00389 
00390 inline const Foam::List<bool>&
00391 Foam::molecule::constantProperties::electrostaticSites() const
00392 {
00393     return electrostaticSites_;
00394 }
00395 
00396 inline bool Foam::molecule::constantProperties::electrostaticSite
00397 (
00398     label sId
00399 ) const
00400 {
00401     label s = findIndex(siteIds_, sId);
00402 
00403     if (s == -1)
00404     {
00405         FatalErrorIn
00406         (
00407             "molecule::constantProperties::electrostaticSite(label)"
00408         )   << sId << " site not found."
00409             << nl << abort(FatalError);
00410     }
00411 
00412     return electrostaticSites_[s];
00413 }
00414 
00415 
00416 inline const Foam::diagTensor&
00417 Foam::molecule::constantProperties::momentOfInertia() const
00418 {
00419     return momentOfInertia_;
00420 }
00421 
00422 
00423 inline bool Foam::molecule::constantProperties::linearMolecule() const
00424 {
00425     return ((momentOfInertia_.xx() < 0) && (momentOfInertia_.yy() > 0));
00426 }
00427 
00428 
00429 inline bool Foam::molecule::constantProperties::pointMolecule() const
00430 {
00431     return (momentOfInertia_.zz() < 0);
00432 }
00433 
00434 
00435 inline Foam::label Foam::molecule::constantProperties::degreesOfFreedom() const
00436 {
00437     if (linearMolecule())
00438     {
00439         return 5;
00440     }
00441     else if (pointMolecule())
00442     {
00443         return 3;
00444     }
00445     else
00446     {
00447         return 6;
00448     }
00449 }
00450 
00451 
00452 inline Foam::scalar Foam::molecule::constantProperties::mass() const
00453 {
00454     return mass_;
00455 }
00456 
00457 
00458 inline Foam::label Foam::molecule::constantProperties::nSites() const
00459 {
00460     return siteIds_.size();
00461 
00462 }
00463 
00464 // * * * * * * * * * * *  trackData Member Functions * * * * * * * * * * * * //
00465 
00466 inline Foam::moleculeCloud& Foam::molecule::trackData::molCloud()
00467 {
00468     return molCloud_;
00469 }
00470 
00471 
00472 inline Foam::label Foam::molecule::trackData::part() const
00473 {
00474     return part_;
00475 }
00476 
00477 
00478 // * * * * * * * * * * * * molecule Member Functions * * * * * * * * * * * * //
00479 
00480 inline const Foam::tensor& Foam::molecule::Q() const
00481 {
00482     return Q_;
00483 }
00484 
00485 
00486 inline Foam::tensor& Foam::molecule::Q()
00487 {
00488     return Q_;
00489 }
00490 
00491 
00492 inline const Foam::vector& Foam::molecule::v() const
00493 {
00494     return v_;
00495 }
00496 
00497 
00498 inline Foam::vector& Foam::molecule::v()
00499 {
00500     return v_;
00501 }
00502 
00503 
00504 inline const Foam::vector& Foam::molecule::a() const
00505 {
00506     return a_;
00507 }
00508 
00509 
00510 inline Foam::vector& Foam::molecule::a()
00511 {
00512     return a_;
00513 }
00514 
00515 
00516 inline const Foam::vector& Foam::molecule::pi() const
00517 {
00518     return pi_;
00519 }
00520 
00521 
00522 inline Foam::vector& Foam::molecule::pi()
00523 {
00524     return pi_;
00525 }
00526 
00527 
00528 inline const Foam::vector& Foam::molecule::tau() const
00529 {
00530     return tau_;
00531 }
00532 
00533 
00534 inline Foam::vector& Foam::molecule::tau()
00535 {
00536     return tau_;
00537 }
00538 
00539 
00540 inline const Foam::List<Foam::vector>& Foam::molecule::siteForces() const
00541 {
00542     return siteForces_;
00543 }
00544 
00545 
00546 inline Foam::List<Foam::vector>& Foam::molecule::siteForces()
00547 {
00548     return siteForces_;
00549 }
00550 
00551 
00552 inline const Foam::List<Foam::vector>& Foam::molecule::sitePositions() const
00553 {
00554     return sitePositions_;
00555 }
00556 
00557 
00558 inline Foam::List<Foam::vector>& Foam::molecule::sitePositions()
00559 {
00560     return sitePositions_;
00561 }
00562 
00563 
00564 inline const Foam::vector& Foam::molecule::specialPosition() const
00565 {
00566     return specialPosition_;
00567 }
00568 
00569 
00570 inline Foam::vector& Foam::molecule::specialPosition()
00571 {
00572     return specialPosition_;
00573 }
00574 
00575 
00576 inline Foam::scalar Foam::molecule::potentialEnergy() const
00577 {
00578     return potentialEnergy_;
00579 }
00580 
00581 
00582 inline Foam::scalar& Foam::molecule::potentialEnergy()
00583 {
00584     return potentialEnergy_;
00585 }
00586 
00587 
00588 inline const Foam::tensor& Foam::molecule::rf() const
00589 {
00590     return rf_;
00591 }
00592 
00593 
00594 inline Foam::tensor& Foam::molecule::rf()
00595 {
00596     return rf_;
00597 }
00598 
00599 
00600 inline Foam::label Foam::molecule::special() const
00601 {
00602     return special_;
00603 }
00604 
00605 
00606 inline bool Foam::molecule::tethered() const
00607 {
00608     return special_ == SPECIAL_TETHERED;
00609 }
00610 
00611 
00612 inline Foam::label Foam::molecule::id() const
00613 {
00614     return id_;
00615 }
00616 
00617 
00618 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd