00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "potential.H"
00028
00029
00030
00031 void Foam::potential::setSiteIdList(const IOdictionary& moleculePropertiesDict)
00032 {
00033 DynamicList<word> siteIdList;
00034
00035 DynamicList<word> pairPotentialSiteIdList;
00036
00037 forAll(idList_, i)
00038 {
00039 const word& id(idList_[i]);
00040
00041 if (!moleculePropertiesDict.found(id))
00042 {
00043 FatalErrorIn("potential.C") << nl
00044 << id << " molecule subDict not found"
00045 << nl << abort(FatalError);
00046 }
00047
00048 const dictionary& molDict(moleculePropertiesDict.subDict(id));
00049
00050 List<word> siteIdNames = molDict.lookup("siteIds");
00051
00052 forAll(siteIdNames, sI)
00053 {
00054 const word& siteId = siteIdNames[sI];
00055
00056 if(findIndex(siteIdList, siteId) == -1)
00057 {
00058 siteIdList.append(siteId);
00059 }
00060 }
00061
00062 List<word> pairPotSiteIds = molDict.lookup("pairPotentialSiteIds");
00063
00064 forAll(pairPotSiteIds, sI)
00065 {
00066 const word& siteId = pairPotSiteIds[sI];
00067
00068 if(findIndex(siteIdNames, siteId) == -1)
00069 {
00070 FatalErrorIn("potential.C") << nl
00071 << siteId << " in pairPotentialSiteIds is not in siteIds: "
00072 << siteIdNames << nl << abort(FatalError);
00073 }
00074
00075 if(findIndex(pairPotentialSiteIdList, siteId) == -1)
00076 {
00077 pairPotentialSiteIdList.append(siteId);
00078 }
00079 }
00080 }
00081
00082 nPairPotIds_ = pairPotentialSiteIdList.size();
00083
00084 forAll(siteIdList, aSIN)
00085 {
00086 const word& siteId = siteIdList[aSIN];
00087
00088 if(findIndex(pairPotentialSiteIdList, siteId) == -1)
00089 {
00090 pairPotentialSiteIdList.append(siteId);
00091 }
00092 }
00093
00094 siteIdList_.transfer(pairPotentialSiteIdList.shrink());
00095 }
00096
00097
00098 void Foam::potential::potential::readPotentialDict()
00099 {
00100 Info<< nl << "Reading potential dictionary:" << endl;
00101
00102 IOdictionary idListDict
00103 (
00104 IOobject
00105 (
00106 "idList",
00107 mesh_.time().constant(),
00108 mesh_,
00109 IOobject::MUST_READ,
00110 IOobject::NO_WRITE
00111 )
00112 );
00113
00114 idList_ = List<word>(idListDict.lookup("idList"));
00115
00116 IOdictionary moleculePropertiesDict
00117 (
00118 IOobject
00119 (
00120 "moleculeProperties",
00121 mesh_.time().constant(),
00122 mesh_,
00123 IOobject::MUST_READ,
00124 IOobject::NO_WRITE,
00125 false
00126 )
00127 );
00128
00129 setSiteIdList(moleculePropertiesDict);
00130
00131 List<word> pairPotentialSiteIdList
00132 (
00133 SubList<word>(siteIdList_, nPairPotIds_)
00134 );
00135
00136 Info<< nl << "Unique site ids found: " << siteIdList_
00137 << nl << "Site Ids requiring a pair potential: "
00138 << pairPotentialSiteIdList
00139 << endl;
00140
00141 List<word> tetherSiteIdList(0);
00142
00143 if (idListDict.found("tetherSiteIdList"))
00144 {
00145 tetherSiteIdList = List<word>(idListDict.lookup("tetherSiteIdList"));
00146 }
00147
00148 IOdictionary potentialDict
00149 (
00150 IOobject
00151 (
00152 "potentialDict",
00153 mesh_.time().system(),
00154 mesh_,
00155 IOobject::MUST_READ,
00156 IOobject::NO_WRITE
00157 )
00158 );
00159
00160 potentialEnergyLimit_ = readScalar
00161 (
00162 potentialDict.lookup("potentialEnergyLimit")
00163 );
00164
00165 if (potentialDict.found("removalOrder"))
00166 {
00167 List<word> remOrd = potentialDict.lookup("removalOrder");
00168
00169 removalOrder_.setSize(remOrd.size());
00170
00171 forAll(removalOrder_, rO)
00172 {
00173 removalOrder_[rO] = findIndex(idList_, remOrd[rO]);
00174
00175 if (removalOrder_[rO] == -1)
00176 {
00177 FatalErrorIn("potentials.C") << nl
00178 << "removalOrder entry: " << remOrd[rO]
00179 << " not found in idList."
00180 << nl << abort(FatalError);
00181 }
00182 }
00183 }
00184
00185
00186
00187
00188 if (!potentialDict.found("pair"))
00189 {
00190 FatalErrorIn("potentials.C") << nl
00191 << "pair potential specification subDict not found"
00192 << abort(FatalError);
00193 }
00194
00195 const dictionary& pairDict = potentialDict.subDict("pair");
00196
00197 pairPotentials_.buildPotentials
00198 (
00199 pairPotentialSiteIdList,
00200 pairDict,
00201 mesh_
00202 );
00203
00204
00205
00206
00207 if (tetherSiteIdList.size())
00208 {
00209 if (!potentialDict.found("tether"))
00210 {
00211 FatalErrorIn("potential.C") << nl
00212 << "tether potential specification subDict not found"
00213 << abort(FatalError);
00214 }
00215
00216 const dictionary& tetherDict = potentialDict.subDict("tether");
00217
00218 tetherPotentials_.buildPotentials
00219 (
00220 siteIdList_,
00221 tetherDict,
00222 tetherSiteIdList
00223 );
00224 }
00225
00226
00227
00228
00229 gravity_ = vector::zero;
00230
00231 if (potentialDict.found("external"))
00232 {
00233
00234 Info << nl << "Reading external forces:" << endl;
00235
00236 const dictionary& externalDict = potentialDict.subDict("external");
00237
00238
00239
00240
00241 if (externalDict.found("gravity"))
00242 {
00243 gravity_ = externalDict.lookup("gravity");
00244 }
00245 }
00246
00247 Info << nl << tab << "gravity = " << gravity_ << endl;
00248 }
00249
00250
00251 void Foam::potential::potential::readMdInitialiseDict
00252 (
00253 const IOdictionary& mdInitialiseDict,
00254 IOdictionary& idListDict
00255 )
00256 {
00257 IOdictionary moleculePropertiesDict
00258 (
00259 IOobject
00260 (
00261 "moleculeProperties",
00262 mesh_.time().constant(),
00263 mesh_,
00264 IOobject::MUST_READ,
00265 IOobject::NO_WRITE,
00266 false
00267 )
00268 );
00269
00270 DynamicList<word> idList;
00271
00272 DynamicList<word> tetherSiteIdList;
00273
00274 forAll(mdInitialiseDict.toc(), zone)
00275 {
00276 const dictionary& zoneDict = mdInitialiseDict.subDict
00277 (
00278 mdInitialiseDict.toc()[zone]
00279 );
00280
00281 List<word> latticeIds
00282 (
00283 zoneDict.lookup("latticeIds")
00284 );
00285
00286 forAll(latticeIds, i)
00287 {
00288 const word& id = latticeIds[i];
00289
00290 if(!moleculePropertiesDict.found(id))
00291 {
00292 FatalErrorIn("potential.C") << nl
00293 << "Molecule type "
00294 << id
00295 << " not found in moleculeProperties dictionary."
00296 << nl
00297 << abort(FatalError);
00298 }
00299
00300 if (findIndex(idList,id) == -1)
00301 {
00302 idList.append(id);
00303 }
00304 }
00305
00306 List<word> tetherSiteIds
00307 (
00308 zoneDict.lookup("tetherSiteIds")
00309 );
00310
00311 forAll(tetherSiteIds, t)
00312 {
00313 const word& tetherSiteId = tetherSiteIds[t];
00314
00315 bool idFound = false;
00316
00317 forAll(latticeIds, i)
00318 {
00319 if (idFound)
00320 {
00321 break;
00322 }
00323
00324 const word& id = latticeIds[i];
00325
00326 List<word> siteIds
00327 (
00328 moleculePropertiesDict.subDict(id).lookup("siteIds")
00329 );
00330
00331 if (findIndex(siteIds, tetherSiteId) != -1)
00332 {
00333 idFound = true;
00334 }
00335 }
00336
00337 if (idFound)
00338 {
00339 tetherSiteIdList.append(tetherSiteId);
00340 }
00341 else
00342 {
00343 FatalErrorIn("potential.C") << nl
00344 << "Tether id "
00345 << tetherSiteId
00346 << " not found as a site of any molecule in zone."
00347 << nl
00348 << abort(FatalError);
00349 }
00350 }
00351 }
00352
00353 idList_.transfer(idList);
00354
00355 tetherSiteIdList.shrink();
00356
00357 idListDict.add("idList", idList_);
00358
00359 idListDict.add("tetherSiteIdList", tetherSiteIdList);
00360
00361 setSiteIdList(moleculePropertiesDict);
00362 }
00363
00364
00365
00366 Foam::potential::potential(const polyMesh& mesh)
00367 :
00368 mesh_(mesh)
00369 {
00370 readPotentialDict();
00371 }
00372
00373
00374 Foam::potential::potential
00375 (
00376 const polyMesh& mesh,
00377 const IOdictionary& mdInitialiseDict,
00378 IOdictionary& idListDict
00379 )
00380 :
00381 mesh_(mesh)
00382 {
00383 readMdInitialiseDict(mdInitialiseDict, idListDict);
00384 }
00385
00386
00387
00388 Foam::potential::~potential()
00389 {}
00390
00391
00392