pairPotentialList.C
Go to the documentation of this file.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 "pairPotentialList.H"
00028 #include "OFstream.H"
00029 #include "Time.H"
00030
00031
00032
00033 void Foam::pairPotentialList::readPairPotentialDict
00034 (
00035 const List<word>& idList,
00036 const dictionary& pairPotentialDict,
00037 const polyMesh& mesh
00038 )
00039 {
00040 Info<< nl << "Building pair potentials." << endl;
00041
00042 rCutMax_ = 0.0;
00043
00044 for (label a = 0; a < nIds_; ++a)
00045 {
00046 word idA = idList[a];
00047
00048 for (label b = a; b < nIds_; ++b)
00049 {
00050 word idB = idList[b];
00051
00052 word pairPotentialName;
00053
00054 if (a == b)
00055 {
00056 if (pairPotentialDict.found(idA + "-" + idB))
00057 {
00058 pairPotentialName = idA + "-" + idB;
00059 }
00060 else
00061 {
00062 FatalErrorIn("pairPotentialList::buildPotentials") << nl
00063 << "Pair pairPotential specification subDict "
00064 << idA << "-" << idB << " not found"
00065 << nl << abort(FatalError);
00066 }
00067 }
00068 else
00069 {
00070 if (pairPotentialDict.found(idA + "-" + idB))
00071 {
00072 pairPotentialName = idA + "-" + idB;
00073 }
00074
00075 else if (pairPotentialDict.found(idB + "-" + idA))
00076 {
00077 pairPotentialName = idB + "-" + idA;
00078 }
00079
00080 else
00081 {
00082 FatalErrorIn("pairPotentialList::buildPotentials") << nl
00083 << "Pair pairPotential specification subDict "
00084 << idA << "-" << idB << " or "
00085 << idB << "-" << idA << " not found"
00086 << nl << abort(FatalError);
00087 }
00088
00089 if
00090 (
00091 pairPotentialDict.found(idA+"-"+idB)
00092 && pairPotentialDict.found(idB+"-"+idA)
00093 )
00094 {
00095 FatalErrorIn("pairPotentialList::buildPotentials") << nl
00096 << "Pair pairPotential specification subDict "
00097 << idA << "-" << idB << " and "
00098 << idB << "-" << idA << " found multiple definition"
00099 << nl << abort(FatalError);
00100 }
00101 }
00102
00103 (*this).set
00104 (
00105 pairPotentialIndex(a, b),
00106 pairPotential::New
00107 (
00108 pairPotentialName,
00109 pairPotentialDict.subDict(pairPotentialName)
00110 )
00111 );
00112
00113 if ((*this)[pairPotentialIndex(a, b)].rCut() > rCutMax_)
00114 {
00115 rCutMax_ = (*this)[pairPotentialIndex(a, b)].rCut();
00116 }
00117
00118 if ((*this)[pairPotentialIndex(a, b)].writeTables())
00119 {
00120 OFstream ppTabFile(mesh.time().path()/pairPotentialName);
00121
00122 if
00123 (
00124 !(*this)[pairPotentialIndex(a, b)].writeEnergyAndForceTables
00125 (
00126 ppTabFile
00127 )
00128 )
00129 {
00130 FatalErrorIn("pairPotentialList::readPairPotentialDict")
00131 << "Failed writing to "
00132 << ppTabFile.name() << nl
00133 << abort(FatalError);
00134 }
00135 }
00136 }
00137 }
00138
00139 if (!pairPotentialDict.found("electrostatic"))
00140 {
00141 FatalErrorIn("pairPotentialList::buildPotentials") << nl
00142 << "Pair pairPotential specification subDict electrostatic"
00143 << nl << abort(FatalError);
00144 }
00145
00146 electrostaticPotential_ = pairPotential::New
00147 (
00148 "electrostatic",
00149 pairPotentialDict.subDict("electrostatic")
00150 );
00151
00152 if (electrostaticPotential_->rCut() > rCutMax_)
00153 {
00154 rCutMax_ = electrostaticPotential_->rCut();
00155 }
00156
00157 if (electrostaticPotential_->writeTables())
00158 {
00159 OFstream ppTabFile(mesh.time().path()/"electrostatic");
00160
00161 if(!electrostaticPotential_->writeEnergyAndForceTables(ppTabFile))
00162 {
00163 FatalErrorIn("pairPotentialList::readPairPotentialDict")
00164 << "Failed writing to "
00165 << ppTabFile.name() << nl
00166 << abort(FatalError);
00167 }
00168 }
00169
00170 rCutMaxSqr_ = rCutMax_*rCutMax_;
00171 }
00172
00173
00174
00175
00176 Foam::pairPotentialList::pairPotentialList()
00177 :
00178 PtrList<pairPotential>()
00179 {}
00180
00181
00182 Foam::pairPotentialList::pairPotentialList
00183 (
00184 const List<word>& idList,
00185 const dictionary& pairPotentialDict,
00186 const polyMesh& mesh
00187 )
00188 :
00189 PtrList<pairPotential>()
00190 {
00191 buildPotentials(idList, pairPotentialDict, mesh);
00192 }
00193
00194
00195
00196
00197 Foam::pairPotentialList::~pairPotentialList()
00198 {}
00199
00200
00201
00202
00203 void Foam::pairPotentialList::buildPotentials
00204 (
00205 const List<word>& idList,
00206 const dictionary& pairPotentialDict,
00207 const polyMesh& mesh
00208 )
00209 {
00210 setSize(((idList.size()*(idList.size() + 1))/2));
00211
00212 nIds_ = idList.size();
00213
00214 readPairPotentialDict(idList, pairPotentialDict, mesh);
00215 }
00216
00217
00218 const Foam::pairPotential& Foam::pairPotentialList::pairPotentialFunction
00219 (
00220 const label a,
00221 const label b
00222 ) const
00223 {
00224 return (*this)[pairPotentialIndex(a, b)];
00225 }
00226
00227
00228 bool Foam::pairPotentialList::rCutMaxSqr(const scalar rIJMagSqr) const
00229 {
00230 if (rIJMagSqr < rCutMaxSqr_)
00231 {
00232 return true;
00233 }
00234 else
00235 {
00236 return false;
00237 }
00238 }
00239
00240
00241 bool Foam::pairPotentialList::rCutSqr
00242 (
00243 const label a,
00244 const label b,
00245 const scalar rIJMagSqr
00246 ) const
00247 {
00248 if (rIJMagSqr < rCutSqr(a, b))
00249 {
00250 return true;
00251 }
00252 else
00253 {
00254 return false;
00255 }
00256 }
00257
00258
00259 Foam::scalar Foam::pairPotentialList::rMin
00260 (
00261 const label a,
00262 const label b
00263 ) const
00264 {
00265 return (*this)[pairPotentialIndex(a, b)].rMin();
00266 }
00267
00268
00269 Foam::scalar Foam::pairPotentialList::dr
00270 (
00271 const label a,
00272 const label b
00273 ) const
00274 {
00275 return (*this)[pairPotentialIndex(a, b)].dr();
00276 }
00277
00278
00279 Foam::scalar Foam::pairPotentialList::rCutSqr
00280 (
00281 const label a,
00282 const label b
00283 ) const
00284 {
00285 return (*this)[pairPotentialIndex(a, b)].rCutSqr();
00286 }
00287
00288
00289 Foam::scalar Foam::pairPotentialList::rCut
00290 (
00291 const label a,
00292 const label b
00293 ) const
00294 {
00295 return (*this)[pairPotentialIndex(a, b)].rCut();
00296 }
00297
00298
00299 Foam::scalar Foam::pairPotentialList::force
00300 (
00301 const label a,
00302 const label b,
00303 const scalar rIJMag
00304 ) const
00305 {
00306 scalar f = (*this)[pairPotentialIndex(a, b)].force(rIJMag);
00307
00308 return f;
00309 }
00310
00311
00312 Foam::scalar Foam::pairPotentialList::energy
00313 (
00314 const label a,
00315 const label b,
00316 const scalar rIJMag
00317 ) const
00318 {
00319 scalar e = (*this)[pairPotentialIndex(a, b)].energy(rIJMag);
00320
00321 return e;
00322 }
00323
00324
00325
Copyright © 2000-2009 OpenCFD Ltd