FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

pairPotentialList.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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*----------------------------------------------------------------------------*/
00025 
00026 #include "pairPotentialList.H"
00027 #include <OpenFOAM/OFstream.H>
00028 #include <OpenFOAM/Time.H>
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 void Foam::pairPotentialList::readPairPotentialDict
00033 (
00034     const List<word>& idList,
00035     const dictionary& pairPotentialDict,
00036     const polyMesh& mesh
00037 )
00038 {
00039     Info<< nl << "Building pair potentials." << endl;
00040 
00041     rCutMax_ = 0.0;
00042 
00043     for (label a = 0; a < nIds_; ++a)
00044     {
00045         word idA = idList[a];
00046 
00047         for (label b = a; b < nIds_; ++b)
00048         {
00049             word idB = idList[b];
00050 
00051             word pairPotentialName;
00052 
00053             if (a == b)
00054             {
00055                 if (pairPotentialDict.found(idA + "-" + idB))
00056                 {
00057                     pairPotentialName = idA + "-" + idB;
00058                 }
00059                 else
00060                 {
00061                     FatalErrorIn("pairPotentialList::buildPotentials") << nl
00062                         << "Pair pairPotential specification subDict "
00063                         << idA << "-" << idB << " not found"
00064                         << nl << abort(FatalError);
00065                 }
00066             }
00067             else
00068             {
00069                 if (pairPotentialDict.found(idA + "-" + idB))
00070                 {
00071                     pairPotentialName = idA + "-" + idB;
00072                 }
00073 
00074                 else if (pairPotentialDict.found(idB + "-" + idA))
00075                 {
00076                     pairPotentialName = idB + "-" + idA;
00077                 }
00078 
00079                 else
00080                 {
00081                     FatalErrorIn("pairPotentialList::buildPotentials") << nl
00082                         << "Pair pairPotential specification subDict "
00083                         << idA << "-" << idB << " or "
00084                         << idB << "-" << idA << " not found"
00085                         << nl << abort(FatalError);
00086                 }
00087 
00088                 if
00089                 (
00090                     pairPotentialDict.found(idA+"-"+idB)
00091                  && pairPotentialDict.found(idB+"-"+idA)
00092                 )
00093                 {
00094                     FatalErrorIn("pairPotentialList::buildPotentials") << nl
00095                         << "Pair pairPotential specification subDict "
00096                         << idA << "-" << idB << " and "
00097                         << idB << "-" << idA << " found multiple definition"
00098                         << nl << abort(FatalError);
00099                 }
00100             }
00101 
00102             (*this).set
00103             (
00104                 pairPotentialIndex(a, b),
00105                 pairPotential::New
00106                 (
00107                     pairPotentialName,
00108                     pairPotentialDict.subDict(pairPotentialName)
00109                 )
00110             );
00111 
00112             if ((*this)[pairPotentialIndex(a, b)].rCut() > rCutMax_)
00113             {
00114                 rCutMax_ = (*this)[pairPotentialIndex(a, b)].rCut();
00115             }
00116 
00117             if ((*this)[pairPotentialIndex(a, b)].writeTables())
00118             {
00119                 OFstream ppTabFile(mesh.time().path()/pairPotentialName);
00120 
00121                 if
00122                 (
00123                     !(*this)[pairPotentialIndex(a, b)].writeEnergyAndForceTables
00124                     (
00125                         ppTabFile
00126                     )
00127                 )
00128                 {
00129                     FatalErrorIn("pairPotentialList::readPairPotentialDict")
00130                         << "Failed writing to "
00131                         << ppTabFile.name() << nl
00132                         << abort(FatalError);
00133                 }
00134             }
00135         }
00136     }
00137 
00138     if (!pairPotentialDict.found("electrostatic"))
00139     {
00140         FatalErrorIn("pairPotentialList::buildPotentials") << nl
00141             << "Pair pairPotential specification subDict electrostatic"
00142             << nl << abort(FatalError);
00143     }
00144 
00145     electrostaticPotential_ = pairPotential::New
00146     (
00147         "electrostatic",
00148         pairPotentialDict.subDict("electrostatic")
00149     );
00150 
00151     if (electrostaticPotential_->rCut() > rCutMax_)
00152     {
00153         rCutMax_ = electrostaticPotential_->rCut();
00154     }
00155 
00156     if (electrostaticPotential_->writeTables())
00157     {
00158         OFstream ppTabFile(mesh.time().path()/"electrostatic");
00159 
00160         if(!electrostaticPotential_->writeEnergyAndForceTables(ppTabFile))
00161         {
00162             FatalErrorIn("pairPotentialList::readPairPotentialDict")
00163                 << "Failed writing to "
00164                 << ppTabFile.name() << nl
00165                 << abort(FatalError);
00166         }
00167     }
00168 
00169     rCutMaxSqr_ = rCutMax_*rCutMax_;
00170 }
00171 
00172 
00173 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00174 
00175 Foam::pairPotentialList::pairPotentialList()
00176 :
00177     PtrList<pairPotential>()
00178 {}
00179 
00180 
00181 Foam::pairPotentialList::pairPotentialList
00182 (
00183     const List<word>& idList,
00184     const dictionary& pairPotentialDict,
00185     const polyMesh& mesh
00186 )
00187 :
00188     PtrList<pairPotential>()
00189 {
00190     buildPotentials(idList, pairPotentialDict, mesh);
00191 }
00192 
00193 
00194 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00195 
00196 Foam::pairPotentialList::~pairPotentialList()
00197 {}
00198 
00199 
00200 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00201 
00202 void Foam::pairPotentialList::buildPotentials
00203 (
00204     const List<word>& idList,
00205     const dictionary& pairPotentialDict,
00206     const polyMesh& mesh
00207 )
00208 {
00209     setSize(((idList.size()*(idList.size() + 1))/2));
00210 
00211     nIds_ = idList.size();
00212 
00213     readPairPotentialDict(idList, pairPotentialDict, mesh);
00214 }
00215 
00216 
00217 const Foam::pairPotential& Foam::pairPotentialList::pairPotentialFunction
00218 (
00219     const label a,
00220     const label b
00221 ) const
00222 {
00223     return (*this)[pairPotentialIndex(a, b)];
00224 }
00225 
00226 
00227 bool Foam::pairPotentialList::rCutMaxSqr(const scalar rIJMagSqr) const
00228 {
00229     if (rIJMagSqr < rCutMaxSqr_)
00230     {
00231         return true;
00232     }
00233     else
00234     {
00235         return false;
00236     }
00237 }
00238 
00239 
00240 bool Foam::pairPotentialList::rCutSqr
00241 (
00242     const label a,
00243     const label b,
00244     const scalar rIJMagSqr
00245 ) const
00246 {
00247     if (rIJMagSqr < rCutSqr(a, b))
00248     {
00249         return true;
00250     }
00251     else
00252     {
00253         return false;
00254     }
00255 }
00256 
00257 
00258 Foam::scalar Foam::pairPotentialList::rMin
00259 (
00260     const label a,
00261     const label b
00262 ) const
00263 {
00264     return (*this)[pairPotentialIndex(a, b)].rMin();
00265 }
00266 
00267 
00268 Foam::scalar Foam::pairPotentialList::dr
00269 (
00270     const label a,
00271     const label b
00272 ) const
00273 {
00274     return (*this)[pairPotentialIndex(a, b)].dr();
00275 }
00276 
00277 
00278 Foam::scalar Foam::pairPotentialList::rCutSqr
00279 (
00280     const label a,
00281     const label b
00282 ) const
00283 {
00284     return (*this)[pairPotentialIndex(a, b)].rCutSqr();
00285 }
00286 
00287 
00288 Foam::scalar Foam::pairPotentialList::rCut
00289 (
00290     const label a,
00291     const label b
00292 ) const
00293 {
00294     return (*this)[pairPotentialIndex(a, b)].rCut();
00295 }
00296 
00297 
00298 Foam::scalar Foam::pairPotentialList::force
00299 (
00300     const label a,
00301     const label b,
00302     const scalar rIJMag
00303 ) const
00304 {
00305     scalar f = (*this)[pairPotentialIndex(a, b)].force(rIJMag);
00306 
00307     return f;
00308 }
00309 
00310 
00311 Foam::scalar Foam::pairPotentialList::energy
00312 (
00313     const label a,
00314     const label b,
00315     const scalar rIJMag
00316 ) const
00317 {
00318     scalar e = (*this)[pairPotentialIndex(a, b)].energy(rIJMag);
00319 
00320     return e;
00321 }
00322 
00323 
00324 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines