BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / lagrangian / molecularDynamics / potential / pairPotential / pairPotentialList / pairPotentialList.C
blobd19dd6668f88936062870e01abeb530d41811c92
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
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
19     for more details.
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"
27 #include "OFstream.H"
28 #include "Time.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 void Foam::pairPotentialList::readPairPotentialDict
34     const List<word>& idList,
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     if (!pairPotentialDict.found("electrostatic"))
139     {
140         FatalErrorIn("pairPotentialList::buildPotentials") << nl
141             << "Pair pairPotential specification subDict electrostatic"
142             << nl << abort(FatalError);
143     }
145     electrostaticPotential_ = pairPotential::New
146     (
147         "electrostatic",
148         pairPotentialDict.subDict("electrostatic")
149     );
151     if (electrostaticPotential_->rCut() > rCutMax_)
152     {
153         rCutMax_ = electrostaticPotential_->rCut();
154     }
156     if (electrostaticPotential_->writeTables())
157     {
158         OFstream ppTabFile(mesh.time().path()/"electrostatic");
160         if (!electrostaticPotential_->writeEnergyAndForceTables(ppTabFile))
161         {
162             FatalErrorIn("pairPotentialList::readPairPotentialDict")
163                 << "Failed writing to "
164                 << ppTabFile.name() << nl
165                 << abort(FatalError);
166         }
167     }
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,
185     const polyMesh& mesh
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,
206     const polyMesh& mesh
209     setSize(((idList.size()*(idList.size() + 1))/2));
211     nIds_ = idList.size();
213     readPairPotentialDict(idList, pairPotentialDict, mesh);
217 const Foam::pairPotential& Foam::pairPotentialList::pairPotentialFunction
219     const label a,
220     const label b
221 ) const
223     return (*this)[pairPotentialIndex(a, b)];
227 bool Foam::pairPotentialList::rCutMaxSqr(const scalar rIJMagSqr) const
229     if (rIJMagSqr < rCutMaxSqr_)
230     {
231         return true;
232     }
233     else
234     {
235         return false;
236     }
240 bool Foam::pairPotentialList::rCutSqr
242     const label a,
243     const label b,
244     const scalar rIJMagSqr
245 ) const
247     if (rIJMagSqr < rCutSqr(a, b))
248     {
249         return true;
250     }
251     else
252     {
253         return false;
254     }
258 Foam::scalar Foam::pairPotentialList::rMin
260     const label a,
261     const label b
262 ) const
264     return (*this)[pairPotentialIndex(a, b)].rMin();
268 Foam::scalar Foam::pairPotentialList::dr
270     const label a,
271     const label b
272 ) const
274     return (*this)[pairPotentialIndex(a, b)].dr();
278 Foam::scalar Foam::pairPotentialList::rCutSqr
280     const label a,
281     const label b
282 ) const
284     return (*this)[pairPotentialIndex(a, b)].rCutSqr();
288 Foam::scalar Foam::pairPotentialList::rCut
290     const label a,
291     const label b
292 ) const
294     return (*this)[pairPotentialIndex(a, b)].rCut();
298 Foam::scalar Foam::pairPotentialList::force
300     const label a,
301     const label b,
302     const scalar rIJMag
303 ) const
305     scalar f = (*this)[pairPotentialIndex(a, b)].force(rIJMag);
307     return f;
311 Foam::scalar Foam::pairPotentialList::energy
313     const label a,
314     const label b,
315     const scalar rIJMag
316 ) const
318     scalar e = (*this)[pairPotentialIndex(a, b)].energy(rIJMag);
320     return e;
324 // ************************************************************************* //