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