1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
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 "potential.H"
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 void Foam::potential::setSiteIdList(const IOdictionary& moleculePropertiesDict)
33 DynamicList<word> siteIdList;
35 DynamicList<word> pairPotentialSiteIdList;
39 const word& id(idList_[i]);
41 if (!moleculePropertiesDict.found(id))
43 FatalErrorIn("potential.C") << nl
44 << id << " molecule subDict not found"
45 << nl << abort(FatalError);
48 const dictionary& molDict(moleculePropertiesDict.subDict(id));
50 List<word> siteIdNames = molDict.lookup("siteIds");
52 forAll(siteIdNames, sI)
54 const word& siteId = siteIdNames[sI];
56 if(findIndex(siteIdList, siteId) == -1)
58 siteIdList.append(siteId);
62 List<word> pairPotSiteIds = molDict.lookup("pairPotentialSiteIds");
64 forAll(pairPotSiteIds, sI)
66 const word& siteId = pairPotSiteIds[sI];
68 if(findIndex(siteIdNames, siteId) == -1)
70 FatalErrorIn("potential.C") << nl
71 << siteId << " in pairPotentialSiteIds is not in siteIds: "
72 << siteIdNames << nl << abort(FatalError);
75 if(findIndex(pairPotentialSiteIdList, siteId) == -1)
77 pairPotentialSiteIdList.append(siteId);
82 nPairPotIds_ = pairPotentialSiteIdList.size();
84 forAll(siteIdList, aSIN)
86 const word& siteId = siteIdList[aSIN];
88 if(findIndex(pairPotentialSiteIdList, siteId) == -1)
90 pairPotentialSiteIdList.append(siteId);
94 siteIdList_.transfer(pairPotentialSiteIdList.shrink());
98 void Foam::potential::potential::readPotentialDict()
100 Info<< nl << "Reading potential dictionary:" << endl;
102 IOdictionary idListDict
107 mesh_.time().constant(),
114 idList_ = List<word>(idListDict.lookup("idList"));
116 IOdictionary moleculePropertiesDict
120 "moleculeProperties",
121 mesh_.time().constant(),
129 setSiteIdList(moleculePropertiesDict);
131 List<word> pairPotentialSiteIdList
133 SubList<word>(siteIdList_, nPairPotIds_)
136 Info<< nl << "Unique site ids found: " << siteIdList_
137 << nl << "Site Ids requiring a pair potential: "
138 << pairPotentialSiteIdList
141 List<word> tetherSiteIdList(0);
143 if (idListDict.found("tetherSiteIdList"))
145 tetherSiteIdList = List<word>(idListDict.lookup("tetherSiteIdList"));
148 IOdictionary potentialDict
153 mesh_.time().system(),
160 potentialEnergyLimit_ = readScalar
162 potentialDict.lookup("potentialEnergyLimit")
165 if (potentialDict.found("removalOrder"))
167 List<word> remOrd = potentialDict.lookup("removalOrder");
169 removalOrder_.setSize(remOrd.size());
171 forAll(removalOrder_, rO)
173 removalOrder_[rO] = findIndex(idList_, remOrd[rO]);
175 if (removalOrder_[rO] == -1)
177 FatalErrorIn("potentials.C") << nl
178 << "removalOrder entry: " << remOrd[rO]
179 << " not found in idList."
180 << nl << abort(FatalError);
185 // *************************************************************************
188 if (!potentialDict.found("pair"))
190 FatalErrorIn("potentials.C") << nl
191 << "pair potential specification subDict not found"
192 << abort(FatalError);
195 const dictionary& pairDict = potentialDict.subDict("pair");
197 pairPotentials_.buildPotentials
199 pairPotentialSiteIdList,
204 // *************************************************************************
207 if (tetherSiteIdList.size())
209 if (!potentialDict.found("tether"))
211 FatalErrorIn("potential.C") << nl
212 << "tether potential specification subDict not found"
213 << abort(FatalError);
216 const dictionary& tetherDict = potentialDict.subDict("tether");
218 tetherPotentials_.buildPotentials
226 // *************************************************************************
229 gravity_ = vector::zero;
231 if (potentialDict.found("external"))
234 Info << nl << "Reading external forces:" << endl;
236 const dictionary& externalDict = potentialDict.subDict("external");
238 // *********************************************************************
241 if (externalDict.found("gravity"))
243 gravity_ = externalDict.lookup("gravity");
247 Info << nl << tab << "gravity = " << gravity_ << endl;
251 void Foam::potential::potential::readMdInitialiseDict
253 const IOdictionary& mdInitialiseDict,
254 IOdictionary& idListDict
257 IOdictionary moleculePropertiesDict
261 "moleculeProperties",
262 mesh_.time().constant(),
270 DynamicList<word> idList;
272 DynamicList<word> tetherSiteIdList;
274 forAll(mdInitialiseDict.toc(), zone)
276 const dictionary& zoneDict = mdInitialiseDict.subDict
278 mdInitialiseDict.toc()[zone]
281 List<word> latticeIds
283 zoneDict.lookup("latticeIds")
286 forAll(latticeIds, i)
288 const word& id = latticeIds[i];
290 if(!moleculePropertiesDict.found(id))
292 FatalErrorIn("potential.C") << nl
295 << " not found in moleculeProperties dictionary."
297 << abort(FatalError);
300 if (findIndex(idList,id) == -1)
306 List<word> tetherSiteIds
308 zoneDict.lookup("tetherSiteIds")
311 forAll(tetherSiteIds, t)
313 const word& tetherSiteId = tetherSiteIds[t];
315 bool idFound = false;
317 forAll(latticeIds, i)
324 const word& id = latticeIds[i];
328 moleculePropertiesDict.subDict(id).lookup("siteIds")
331 if (findIndex(siteIds, tetherSiteId) != -1)
339 tetherSiteIdList.append(tetherSiteId);
343 FatalErrorIn("potential.C") << nl
346 << " not found as a site of any molecule in zone."
348 << abort(FatalError);
353 idList_.transfer(idList);
355 tetherSiteIdList.shrink();
357 idListDict.add("idList", idList_);
359 idListDict.add("tetherSiteIdList", tetherSiteIdList);
361 setSiteIdList(moleculePropertiesDict);
364 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
366 Foam::potential::potential(const polyMesh& mesh)
374 Foam::potential::potential
376 const polyMesh& mesh,
377 const IOdictionary& mdInitialiseDict,
378 IOdictionary& idListDict
383 readMdInitialiseDict(mdInitialiseDict, idListDict);
386 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
388 Foam::potential::~potential()
392 // ************************************************************************* //