1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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>(),
149 Foam::pairPotentialList::pairPotentialList
151 const dictionary& idListDict,
152 const dictionary& pairPotentialDict,
156 PtrList<pairPotential>(),
159 buildPotentials(idListDict, pairPotentialDict, mesh);
163 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
165 Foam::pairPotentialList::~pairPotentialList()
169 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
171 void Foam::pairPotentialList::buildPotentials
173 const dictionary& idListDict,
174 const dictionary& pairPotentialDict,
178 idList_ = List<word>(idListDict.lookup("idList"));
180 setSize(((idList_.size()*(idList_.size() + 1))/2));
182 readPairPotentialDict(pairPotentialDict, mesh);
186 const Foam::pairPotential& Foam::pairPotentialList::pairPotentialFunction
192 return (*this)[pairPotentialIndex (a, b)];
196 bool Foam::pairPotentialList::rCutSqr
200 const scalar rIJMagSqr
203 if (rIJMagSqr <= rCutSqr (a, b))
214 Foam::scalar Foam::pairPotentialList::rMin
220 return (*this)[pairPotentialIndex (a, b)].rMin();
224 Foam::scalar Foam::pairPotentialList::dr
230 return (*this)[pairPotentialIndex (a, b)].dr();
234 Foam::scalar Foam::pairPotentialList::rCutSqr
240 return (*this)[pairPotentialIndex (a, b)].rCutSqr();
244 Foam::scalar Foam::pairPotentialList::rCut
250 return (*this)[pairPotentialIndex (a, b)].rCut();
254 Foam::scalar Foam::pairPotentialList::force
261 scalar f = (*this)[pairPotentialIndex (a, b)].forceLookup(rIJMag);
267 Foam::scalar Foam::pairPotentialList::energy
274 scalar e = (*this)[pairPotentialIndex (a, b)].energyLookup(rIJMag);
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 // ************************************************************************* //