pairPotentialList.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2019-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "pairPotentialList.H"
30#include "OFstream.H"
31#include "Time.H"
32
33// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34
35void Foam::pairPotentialList::readPairPotentialDict
36(
37 const List<word>& idList,
38 const dictionary& pairPotentialDict,
39 const polyMesh& mesh
40)
41{
42 Info<< nl << "Building pair potentials." << endl;
43
44 rCutMax_ = 0.0;
45
46 for (label a = 0; a < nIds_; ++a)
47 {
48 word idA = idList[a];
49
50 for (label b = a; b < nIds_; ++b)
51 {
52 word idB = idList[b];
53
54 word pairPotentialName;
55
56 if (a == b)
57 {
58 if (pairPotentialDict.found(idA + "-" + idB))
59 {
60 pairPotentialName = idA + "-" + idB;
61 }
62 else
63 {
65 << "Pair pairPotential specification subDict "
66 << idA << "-" << idB << " not found"
67 << nl << abort(FatalError);
68 }
69 }
70 else
71 {
72 if (pairPotentialDict.found(idA + "-" + idB))
73 {
74 pairPotentialName = idA + "-" + idB;
75 }
76
77 else if (pairPotentialDict.found(idB + "-" + idA))
78 {
79 pairPotentialName = idB + "-" + idA;
80 }
81
82 else
83 {
85 << "Pair pairPotential specification subDict "
86 << idA << "-" << idB << " or "
87 << idB << "-" << idA << " not found"
88 << nl << abort(FatalError);
89 }
90
91 if
92 (
93 pairPotentialDict.found(idA+"-"+idB)
94 && pairPotentialDict.found(idB+"-"+idA)
95 )
96 {
98 << "Pair pairPotential specification subDict "
99 << idA << "-" << idB << " and "
100 << idB << "-" << idA << " found multiple definition"
101 << nl << abort(FatalError);
102 }
103 }
104
105 (*this).set
106 (
107 pairPotentialIndex(a, b),
109 (
110 pairPotentialName,
111 pairPotentialDict.subDict(pairPotentialName)
112 )
113 );
114
115 if ((*this)[pairPotentialIndex(a, b)].rCut() > rCutMax_)
116 {
117 rCutMax_ = (*this)[pairPotentialIndex(a, b)].rCut();
118 }
119
120 if ((*this)[pairPotentialIndex(a, b)].writeTables())
121 {
123 autoPtr<OSstream> ppTabFile
124 (
125 fileHandler().NewOFstream
126 (
127 mesh.time().path()/pairPotentialName
128 )
129 );
130
131 if
132 (
133 !(*this)[pairPotentialIndex(a, b)].writeEnergyAndForceTables
134 (
135 ppTabFile()
136 )
137 )
138 {
140 << "Failed writing to "
141 << ppTabFile().name() << nl
142 << abort(FatalError);
143 }
144 }
145 }
146 }
147
148 if (!pairPotentialDict.found("electrostatic"))
149 {
151 << "Pair pairPotential specification subDict electrostatic"
152 << nl << abort(FatalError);
153 }
154
155 electrostaticPotential_ = pairPotential::New
156 (
157 "electrostatic",
158 pairPotentialDict.subDict("electrostatic")
159 );
160
161 if (electrostaticPotential_->rCut() > rCutMax_)
162 {
163 rCutMax_ = electrostaticPotential_->rCut();
164 }
165
166 if (electrostaticPotential_->writeTables())
167 {
169 autoPtr<OSstream> ppTabFile
170 (
171 fileHandler().NewOFstream
172 (
173 mesh.time().path()/"electrostatic"
174 )
175 );
176
177 if (!electrostaticPotential_->writeEnergyAndForceTables(ppTabFile()))
178 {
180 << "Failed writing to "
181 << ppTabFile().name() << nl
182 << abort(FatalError);
183 }
184 }
185
186 rCutMaxSqr_ = rCutMax_*rCutMax_;
187}
188
189
190// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
191
193:
195{}
196
197
199(
200 const List<word>& idList,
201 const dictionary& pairPotentialDict,
202 const polyMesh& mesh
203)
204:
206{
207 buildPotentials(idList, pairPotentialDict, mesh);
208}
209
210
211// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
212
214{}
215
216
217// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
218
220(
221 const List<word>& idList,
222 const dictionary& pairPotentialDict,
223 const polyMesh& mesh
224)
225{
226 setSize(((idList.size()*(idList.size() + 1))/2));
227
228 nIds_ = idList.size();
229
230 readPairPotentialDict(idList, pairPotentialDict, mesh);
231}
232
233
235(
236 const label a,
237 const label b
238) const
239{
240 return (*this)[pairPotentialIndex(a, b)];
241}
242
243
244bool Foam::pairPotentialList::rCutMaxSqr(const scalar rIJMagSqr) const
245{
246 if (rIJMagSqr < rCutMaxSqr_)
247 {
248 return true;
249 }
250
251 return false;
252}
253
254
256(
257 const label a,
258 const label b,
259 const scalar rIJMagSqr
260) const
261{
262 if (rIJMagSqr < rCutSqr(a, b))
263 {
264 return true;
265 }
266
267 return false;
268}
269
270
272(
273 const label a,
274 const label b
275) const
276{
277 return (*this)[pairPotentialIndex(a, b)].rMin();
278}
279
280
282(
283 const label a,
284 const label b
285) const
286{
287 return (*this)[pairPotentialIndex(a, b)].dr();
288}
289
290
292(
293 const label a,
294 const label b
295) const
296{
297 return (*this)[pairPotentialIndex(a, b)].rCutSqr();
298}
299
300
302(
303 const label a,
304 const label b
305) const
306{
307 return (*this)[pairPotentialIndex(a, b)].rCut();
308}
309
310
312(
313 const label a,
314 const label b,
315 const scalar rIJMag
316) const
317{
318 scalar f = (*this)[pairPotentialIndex(a, b)].force(rIJMag);
319
320 return f;
321}
322
323
325(
326 const label a,
327 const label b,
328 const scalar rIJMag
329) const
330{
331 scalar e = (*this)[pairPotentialIndex(a, b)].energy(rIJMag);
332
333 return e;
334}
335
336
337// ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
fileName path() const
Return path.
Definition: Time.H:358
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
virtual bool mkDir(const fileName &, mode_t=0777) const =0
Make directory.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
scalar energy(const label a, const label b, const scalar rIJMag) const
scalar rCut(const label a, const label b) const
void buildPotentials(const List< word > &idList, const dictionary &pairPotentialDict, const polyMesh &mesh)
const pairPotential & pairPotentialFunction(const label a, const label b) const
scalar dr() const
scalar rMin() const
scalar rCutSqr() const
scalar rCut() const
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Base class for film (stress-based) force models.
Definition: force.H:59
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const fileOperation & fileHandler()
Get current file handler.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
points setSize(newPointi)
labelList f(nPoints)
volScalarField & b
Definition: createFields.H:27
volScalarField & e
Definition: createFields.H:11