1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 List<word>& idList,
36 const dictionary& pairPotentialDict,
40 Info<< nl << "Building pair potentials." << endl;
44 for (label a = 0; a < nIds_; ++a)
48 for (label b = a; b < nIds_; ++b)
52 word pairPotentialName;
56 if (pairPotentialDict.found(idA + "-" + idB))
58 pairPotentialName = idA + "-" + idB;
62 FatalErrorIn("pairPotentialList::buildPotentials") << nl
63 << "Pair pairPotential specification subDict "
64 << idA << "-" << idB << " not found"
65 << nl << abort(FatalError);
70 if (pairPotentialDict.found(idA + "-" + idB))
72 pairPotentialName = idA + "-" + idB;
75 else if (pairPotentialDict.found(idB + "-" + idA))
77 pairPotentialName = idB + "-" + idA;
82 FatalErrorIn("pairPotentialList::buildPotentials") << nl
83 << "Pair pairPotential specification subDict "
84 << idA << "-" << idB << " or "
85 << idB << "-" << idA << " not found"
86 << nl << abort(FatalError);
91 pairPotentialDict.found(idA+"-"+idB)
92 && pairPotentialDict.found(idB+"-"+idA)
95 FatalErrorIn("pairPotentialList::buildPotentials") << nl
96 << "Pair pairPotential specification subDict "
97 << idA << "-" << idB << " and "
98 << idB << "-" << idA << " found multiple definition"
99 << nl << abort(FatalError);
105 pairPotentialIndex(a, b),
109 pairPotentialDict.subDict(pairPotentialName)
113 if ((*this)[pairPotentialIndex(a, b)].rCut() > rCutMax_)
115 rCutMax_ = (*this)[pairPotentialIndex(a, b)].rCut();
118 if ((*this)[pairPotentialIndex(a, b)].writeTables())
120 OFstream ppTabFile(mesh.time().path()/pairPotentialName);
124 !(*this)[pairPotentialIndex(a, b)].writeEnergyAndForceTables
130 FatalErrorIn("pairPotentialList::readPairPotentialDict")
131 << "Failed writing to "
132 << ppTabFile.name() << nl
133 << abort(FatalError);
139 if (!pairPotentialDict.found("electrostatic"))
141 FatalErrorIn("pairPotentialList::buildPotentials") << nl
142 << "Pair pairPotential specification subDict electrostatic"
143 << nl << abort(FatalError);
146 electrostaticPotential_ = pairPotential::New
149 pairPotentialDict.subDict("electrostatic")
152 if (electrostaticPotential_->rCut() > rCutMax_)
154 rCutMax_ = electrostaticPotential_->rCut();
157 if (electrostaticPotential_->writeTables())
159 OFstream ppTabFile(mesh.time().path()/"electrostatic");
161 if(!electrostaticPotential_->writeEnergyAndForceTables(ppTabFile))
163 FatalErrorIn("pairPotentialList::readPairPotentialDict")
164 << "Failed writing to "
165 << ppTabFile.name() << nl
166 << abort(FatalError);
170 rCutMaxSqr_ = rCutMax_*rCutMax_;
174 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
176 Foam::pairPotentialList::pairPotentialList()
178 PtrList<pairPotential>()
182 Foam::pairPotentialList::pairPotentialList
184 const List<word>& idList,
185 const dictionary& pairPotentialDict,
189 PtrList<pairPotential>()
191 buildPotentials(idList, pairPotentialDict, mesh);
195 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
197 Foam::pairPotentialList::~pairPotentialList()
201 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
203 void Foam::pairPotentialList::buildPotentials
205 const List<word>& idList,
206 const dictionary& pairPotentialDict,
210 setSize(((idList.size()*(idList.size() + 1))/2));
212 nIds_ = idList.size();
214 readPairPotentialDict(idList, pairPotentialDict, mesh);
218 const Foam::pairPotential& Foam::pairPotentialList::pairPotentialFunction
224 return (*this)[pairPotentialIndex(a, b)];
228 bool Foam::pairPotentialList::rCutMaxSqr(const scalar rIJMagSqr) const
230 if (rIJMagSqr < rCutMaxSqr_)
241 bool Foam::pairPotentialList::rCutSqr
245 const scalar rIJMagSqr
248 if (rIJMagSqr < rCutSqr(a, b))
259 Foam::scalar Foam::pairPotentialList::rMin
265 return (*this)[pairPotentialIndex(a, b)].rMin();
269 Foam::scalar Foam::pairPotentialList::dr
275 return (*this)[pairPotentialIndex(a, b)].dr();
279 Foam::scalar Foam::pairPotentialList::rCutSqr
285 return (*this)[pairPotentialIndex(a, b)].rCutSqr();
289 Foam::scalar Foam::pairPotentialList::rCut
295 return (*this)[pairPotentialIndex(a, b)].rCut();
299 Foam::scalar Foam::pairPotentialList::force
306 scalar f = (*this)[pairPotentialIndex(a, b)].force(rIJMag);
312 Foam::scalar Foam::pairPotentialList::energy
319 scalar e = (*this)[pairPotentialIndex(a, b)].energy(rIJMag);
325 // ************************************************************************* //