1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*----------------------------------------------------------------------------*/
26 #include "pairPotentialList.H"
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 void Foam::pairPotentialList::readPairPotentialDict
34 const List<word>& idList,
35 const dictionary& pairPotentialDict,
39 Info<< nl << "Building pair potentials." << endl;
43 for (label a = 0; a < nIds_; ++a)
47 for (label b = a; b < nIds_; ++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 if (!pairPotentialDict.found("electrostatic"))
140 FatalErrorIn("pairPotentialList::buildPotentials") << nl
141 << "Pair pairPotential specification subDict electrostatic"
142 << nl << abort(FatalError);
145 electrostaticPotential_ = pairPotential::New
148 pairPotentialDict.subDict("electrostatic")
151 if (electrostaticPotential_->rCut() > rCutMax_)
153 rCutMax_ = electrostaticPotential_->rCut();
156 if (electrostaticPotential_->writeTables())
158 OFstream ppTabFile(mesh.time().path()/"electrostatic");
160 if (!electrostaticPotential_->writeEnergyAndForceTables(ppTabFile))
162 FatalErrorIn("pairPotentialList::readPairPotentialDict")
163 << "Failed writing to "
164 << ppTabFile.name() << nl
165 << abort(FatalError);
169 rCutMaxSqr_ = rCutMax_*rCutMax_;
173 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
175 Foam::pairPotentialList::pairPotentialList()
177 PtrList<pairPotential>()
181 Foam::pairPotentialList::pairPotentialList
183 const List<word>& idList,
184 const dictionary& pairPotentialDict,
188 PtrList<pairPotential>()
190 buildPotentials(idList, pairPotentialDict, mesh);
194 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
196 Foam::pairPotentialList::~pairPotentialList()
200 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
202 void Foam::pairPotentialList::buildPotentials
204 const List<word>& idList,
205 const dictionary& pairPotentialDict,
209 setSize(((idList.size()*(idList.size() + 1))/2));
211 nIds_ = idList.size();
213 readPairPotentialDict(idList, pairPotentialDict, mesh);
217 const Foam::pairPotential& Foam::pairPotentialList::pairPotentialFunction
223 return (*this)[pairPotentialIndex(a, b)];
227 bool Foam::pairPotentialList::rCutMaxSqr(const scalar rIJMagSqr) const
229 if (rIJMagSqr < rCutMaxSqr_)
240 bool Foam::pairPotentialList::rCutSqr
244 const scalar rIJMagSqr
247 if (rIJMagSqr < rCutSqr(a, b))
258 Foam::scalar Foam::pairPotentialList::rMin
264 return (*this)[pairPotentialIndex(a, b)].rMin();
268 Foam::scalar Foam::pairPotentialList::dr
274 return (*this)[pairPotentialIndex(a, b)].dr();
278 Foam::scalar Foam::pairPotentialList::rCutSqr
284 return (*this)[pairPotentialIndex(a, b)].rCutSqr();
288 Foam::scalar Foam::pairPotentialList::rCut
294 return (*this)[pairPotentialIndex(a, b)].rCut();
298 Foam::scalar Foam::pairPotentialList::force
305 scalar f = (*this)[pairPotentialIndex(a, b)].force(rIJMag);
311 Foam::scalar Foam::pairPotentialList::energy
318 scalar e = (*this)[pairPotentialIndex(a, b)].energy(rIJMag);
324 // ************************************************************************* //