Updates from Graham:
[OpenFOAM-1.5.x.git] / src / lagrangian / molecularDynamics / potential / pairPotential / pairPotentialList / pairPotentialList.C
blobdbd2bb9ceb9bc846ab934af0ade93662344c83a7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
28 #include "OFstream.H"
29 #include "Time.H"
31 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
33 void Foam::pairPotentialList::readPairPotentialDict
35     const dictionary& pairPotentialDict,
36     const polyMesh& mesh
39     Info<< nl << "Building pair potentials." << endl;
41     rCutMax_ = 0.0;
43     for (label a = 0; a < nIds(); ++a)
44     {
45         word idA = idList_[a];
47         for (label b = a; b < nIds(); ++b)
48         {
49             word idB = idList_[b];
51             word pairPotentialName;
53             if (a == b)
54             {
55                 if (pairPotentialDict.found(idA + "-" + idB))
56                 {
57                     pairPotentialName = idA + "-" + idB;
58                 }
59                 else
60                 {
61                     FatalErrorIn("pairPotentialList::buildPotentials") << nl
62                             << "Pair pairPotential specification subDict "
63                             << idA << "-" << idB << " not found"
64                             << nl << abort(FatalError);
65                 }
66             }
67             else
68             {
69                 if (pairPotentialDict.found(idA + "-" + idB))
70                 {
71                     pairPotentialName = idA + "-" + idB;
72                 }
74                 else if (pairPotentialDict.found(idB + "-" + idA))
75                 {
76                     pairPotentialName = idB + "-" + idA;
77                 }
79                 else
80                 {
81                     FatalErrorIn("pairPotentialList::buildPotentials") << nl
82                         << "Pair pairPotential specification subDict "
83                         << idA << "-" << idB << " or "
84                         << idB << "-" << idA << " not found"
85                         << nl << abort(FatalError);
86                 }
88                 if
89                 (
90                     pairPotentialDict.found(idA + "-" + idB)
91                  && pairPotentialDict.found(idB + "-" + idA)
92                 )
93                 {
94                     FatalErrorIn("pairPotentialList::buildPotentials") << nl
95                         << "Pair pairPotential specification subDict "
96                         << idA << "-" << idB << " and "
97                         << idB << "-" << idA << " found multiple definition"
98                         << nl << abort(FatalError);
99                 }
100             }
102             (*this).set
103             (
104                 pairPotentialIndex(a, b),
105                 pairPotential::New
106                 (
107                     pairPotentialName,
108                     pairPotentialDict.subDict(pairPotentialName)
109                 )
110             );
112             if ((*this)[pairPotentialIndex(a, b)].rCut() > rCutMax_)
113             {
114                 rCutMax_ = (*this)[pairPotentialIndex(a, b)].rCut();
115             }
117             if ((*this)[pairPotentialIndex(a, b)].writeTables())
118             {
119                 OFstream ppTabFile(mesh.time().path()/pairPotentialName);
121                 if
122                 (
123                     !(*this)[pairPotentialIndex(a, b)].writeEnergyAndForceTables
124                     (
125                         ppTabFile
126                     )
127                 )
128                 {
129                     FatalErrorIn("pairPotentialList::readPairPotentialDict")
130                         << "Failed writing to "
131                         << ppTabFile.name() << nl
132                         << abort(FatalError);
133                 }
134             }
135         }
136     }
138     rCutMaxSqr_ = rCutMax_*rCutMax_;
141 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
143 Foam::pairPotentialList::pairPotentialList()
145     PtrList<pairPotential>(),
146     idList_()
150 Foam::pairPotentialList::pairPotentialList
152     const dictionary& idListDict,
153     const dictionary& pairPotentialDict,
154     const polyMesh& mesh
157     PtrList<pairPotential>(),
158     idList_()
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,
176     const polyMesh& mesh
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
189     const label a,
190     const label b
191 ) const
193     return (*this)[pairPotentialIndex(a, b)];
197 bool Foam::pairPotentialList::rCutSqr
199     const label a,
200     const label b,
201     const scalar rIJMagSqr
202 ) const
204     if (rIJMagSqr < rCutSqr(a, b))
205     {
206         return true;
207     }
208     else
209     {
210         return false;
211     }
215 Foam::scalar Foam::pairPotentialList::rMin
217     const label a,
218     const label b
219 ) const
221     return (*this)[pairPotentialIndex(a, b)].rMin();
225 Foam::scalar Foam::pairPotentialList::dr
227     const label a,
228     const label b
229 ) const
231     return (*this)[pairPotentialIndex(a, b)].dr();
235 Foam::scalar Foam::pairPotentialList::rCutSqr
237     const label a,
238     const label b
239 ) const
241     return (*this)[pairPotentialIndex(a, b)].rCutSqr();
245 Foam::scalar Foam::pairPotentialList::rCut
247     const label a,
248     const label b
249 ) const
251     return (*this)[pairPotentialIndex(a, b)].rCut();
255 Foam::scalar Foam::pairPotentialList::force
257     const label a,
258     const label b,
259     const scalar rIJMag
260 ) const
262     scalar f = (*this)[pairPotentialIndex(a, b)].forceLookup(rIJMag);
264     return f;
268 Foam::scalar Foam::pairPotentialList::energy
270     const label a,
271     const label b,
272     const scalar rIJMag
273 ) const
275     scalar e = (*this)[pairPotentialIndex(a, b)].energyLookup(rIJMag);
277     return e;
281 // ************************************************************************* //