1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 "pairPotentialList.H"
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 void Foam::pairPotentialList::readPairPotentialDict
35 const dictionary& pairPotentialDict,
39 Info<< nl << "Building pair potentials." << endl;
43 for (label a = 0; a < nIds(); ++a)
45 word idA = idList_[a];
47 for (label b = a; b < nIds(); ++b)
49 word idB = idList_[b];
51 word pairPotentialName;
55 if (pairPotentialDict.found(idA + "-" + idB))
57 pairPotentialName = idA + "-" + idB;
61 FatalErrorIn("pairPotentialList::buildPotentials") << nl
62 << "Pair pairPotential specification subDict "
63 << idA << "-" << idB << " not found"
64 << nl << abort(FatalError);
69 if (pairPotentialDict.found(idA + "-" + idB))
71 pairPotentialName = idA + "-" + idB;
74 else if (pairPotentialDict.found(idB + "-" + idA))
76 pairPotentialName = idB + "-" + idA;
81 FatalErrorIn("pairPotentialList::buildPotentials") << nl
82 << "Pair pairPotential specification subDict "
83 << idA << "-" << idB << " or "
84 << idB << "-" << idA << " not found"
85 << nl << abort(FatalError);
90 pairPotentialDict.found(idA + "-" + idB)
91 && pairPotentialDict.found(idB + "-" + idA)
94 FatalErrorIn("pairPotentialList::buildPotentials") << nl
95 << "Pair pairPotential specification subDict "
96 << idA << "-" << idB << " and "
97 << idB << "-" << idA << " found multiple definition"
98 << nl << abort(FatalError);
104 pairPotentialIndex(a, b),
108 pairPotentialDict.subDict(pairPotentialName)
112 if ((*this)[pairPotentialIndex(a, b)].rCut() > rCutMax_)
114 rCutMax_ = (*this)[pairPotentialIndex(a, b)].rCut();
117 if ((*this)[pairPotentialIndex(a, b)].writeTables())
119 OFstream ppTabFile(mesh.time().path()/pairPotentialName);
123 !(*this)[pairPotentialIndex(a, b)].writeEnergyAndForceTables
129 FatalErrorIn("pairPotentialList::readPairPotentialDict")
130 << "Failed writing to "
131 << ppTabFile.name() << nl
132 << abort(FatalError);
138 rCutMaxSqr_ = rCutMax_*rCutMax_;
141 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
143 Foam::pairPotentialList::pairPotentialList()
145 PtrList<pairPotential>(),
150 Foam::pairPotentialList::pairPotentialList
152 const dictionary& idListDict,
153 const dictionary& pairPotentialDict,
157 PtrList<pairPotential>(),
160 buildPotentials(idListDict, pairPotentialDict, mesh);
164 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
166 Foam::pairPotentialList::~pairPotentialList()
170 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 void Foam::pairPotentialList::buildPotentials
174 const dictionary& idListDict,
175 const dictionary& pairPotentialDict,
179 idList_ = List<word>(idListDict.lookup("idList"));
181 setSize(((idList_.size()*(idList_.size() + 1))/2));
183 readPairPotentialDict(pairPotentialDict, mesh);
187 const Foam::pairPotential& Foam::pairPotentialList::pairPotentialFunction
193 return (*this)[pairPotentialIndex(a, b)];
197 bool Foam::pairPotentialList::rCutSqr
201 const scalar rIJMagSqr
204 if (rIJMagSqr < rCutSqr(a, b))
215 Foam::scalar Foam::pairPotentialList::rMin
221 return (*this)[pairPotentialIndex(a, b)].rMin();
225 Foam::scalar Foam::pairPotentialList::dr
231 return (*this)[pairPotentialIndex(a, b)].dr();
235 Foam::scalar Foam::pairPotentialList::rCutSqr
241 return (*this)[pairPotentialIndex(a, b)].rCutSqr();
245 Foam::scalar Foam::pairPotentialList::rCut
251 return (*this)[pairPotentialIndex(a, b)].rCut();
255 Foam::scalar Foam::pairPotentialList::force
262 scalar f = (*this)[pairPotentialIndex(a, b)].forceLookup(rIJMag);
268 Foam::scalar Foam::pairPotentialList::energy
275 scalar e = (*this)[pairPotentialIndex(a, b)].energyLookup(rIJMag);
281 // ************************************************************************* //