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 "moleculeCloud.H"
00028 #include "fvMesh.H"
00029
00030
00031
00032 namespace Foam
00033 {
00034 defineParticleTypeNameAndDebug(molecule, 0);
00035 defineTemplateTypeNameAndDebug(Cloud<molecule>, 0);
00036 };
00037
00038 Foam::scalar Foam::moleculeCloud::kb = 1.380650277e-23;
00039
00040 Foam::scalar Foam::moleculeCloud::elementaryCharge = 1.602176487e-19;
00041
00042 Foam::scalar Foam::moleculeCloud::vacuumPermittivity = 8.854187817e-12;
00043
00044
00045
00046
00047 void Foam::moleculeCloud::buildConstProps()
00048 {
00049 Info<< nl << "Reading moleculeProperties dictionary." << endl;
00050
00051 const List<word>& idList(pot_.idList());
00052
00053 constPropList_.setSize(idList.size());
00054
00055 const List<word>& siteIdList(pot_.siteIdList());
00056
00057 IOdictionary moleculePropertiesDict
00058 (
00059 IOobject
00060 (
00061 "moleculeProperties",
00062 mesh_.time().constant(),
00063 mesh_,
00064 IOobject::MUST_READ,
00065 IOobject::NO_WRITE,
00066 false
00067 )
00068 );
00069
00070 forAll(idList, i)
00071 {
00072 const word& id(idList[i]);
00073
00074 const dictionary& molDict(moleculePropertiesDict.subDict(id));
00075
00076 List<word> siteIdNames = molDict.lookup("siteIds");
00077
00078 List<label> siteIds(siteIdNames.size());
00079
00080 forAll(siteIdNames, sI)
00081 {
00082 const word& siteId = siteIdNames[sI];
00083
00084 siteIds[sI] = findIndex(siteIdList, siteId);
00085
00086 if (siteIds[sI] == -1)
00087 {
00088 FatalErrorIn("moleculeCloud.C") << nl
00089 << siteId << " site not found."
00090 << nl << abort(FatalError);
00091 }
00092 }
00093
00094 molecule::constantProperties& constProp = constPropList_[i];
00095
00096 constProp = molecule::constantProperties(molDict);
00097
00098 constProp.siteIds() = siteIds;
00099 }
00100 }
00101
00102
00103 void Foam::moleculeCloud::setSiteSizesAndPositions()
00104 {
00105 iterator mol(this->begin());
00106
00107 for (mol = this->begin(); mol != this->end(); ++mol)
00108 {
00109 const molecule::constantProperties& cP = constProps(mol().id());
00110
00111 mol().setSiteSizes(cP.nSites());
00112
00113 mol().setSitePositions(cP);
00114 }
00115 }
00116
00117
00118 void Foam::moleculeCloud::buildCellOccupancy()
00119 {
00120 forAll(cellOccupancy_, cO)
00121 {
00122 cellOccupancy_[cO].clear();
00123 }
00124
00125 iterator mol(this->begin());
00126
00127 for
00128 (
00129 mol = this->begin();
00130 mol != this->end();
00131 ++mol
00132 )
00133 {
00134 cellOccupancy_[mol().cell()].append(&mol());
00135 }
00136
00137 forAll(cellOccupancy_, cO)
00138 {
00139 cellOccupancy_[cO].shrink();
00140 }
00141
00142 il_.ril().referMolecules(cellOccupancy());
00143 }
00144
00145
00146 void Foam::moleculeCloud::calculatePairForce()
00147 {
00148 iterator mol(this->begin());
00149
00150 {
00151
00152
00153 molecule* molI = &mol();
00154
00155 molecule* molJ = &mol();
00156
00157 const directInteractionList& dil(il_.dil());
00158
00159 forAll(dil, d)
00160 {
00161 forAll(cellOccupancy_[d],cellIMols)
00162 {
00163 molI = cellOccupancy_[d][cellIMols];
00164
00165 forAll(dil[d], interactingCells)
00166 {
00167 List< molecule* > cellJ =
00168 cellOccupancy_[dil[d][interactingCells]];
00169
00170 forAll(cellJ, cellJMols)
00171 {
00172 molJ = cellJ[cellJMols];
00173
00174 evaluatePair(molI, molJ);
00175 }
00176 }
00177
00178 forAll(cellOccupancy_[d],cellIOtherMols)
00179 {
00180 molJ = cellOccupancy_[d][cellIOtherMols];
00181
00182 if (molJ > molI)
00183 {
00184 evaluatePair(molI, molJ);
00185 }
00186 }
00187 }
00188 }
00189 }
00190
00191 {
00192
00193
00194 molecule* molK = &mol();
00195
00196 referredCellList& ril(il_.ril());
00197
00198 forAll(ril, r)
00199 {
00200 const List<label>& realCells = ril[r].realCellsForInteraction();
00201
00202 forAll(ril[r], refMols)
00203 {
00204 referredMolecule* molL(&(ril[r][refMols]));
00205
00206 forAll(realCells, rC)
00207 {
00208 List<molecule*> cellK = cellOccupancy_[realCells[rC]];
00209
00210 forAll(cellK, cellKMols)
00211 {
00212 molK = cellK[cellKMols];
00213
00214 evaluatePair(molK, molL);
00215 }
00216 }
00217 }
00218 }
00219 }
00220 }
00221
00222
00223 void Foam::moleculeCloud::calculateTetherForce()
00224 {
00225 const tetherPotentialList& tetherPot(pot_.tetherPotentials());
00226
00227 iterator mol(this->begin());
00228
00229 for (mol = this->begin(); mol != this->end(); ++mol)
00230 {
00231 if (mol().tethered())
00232 {
00233 vector rIT = mol().position() - mol().specialPosition();
00234
00235 label idI = mol().id();
00236
00237 scalar massI = constProps(idI).mass();
00238
00239 vector fIT = tetherPot.force(idI, rIT);
00240
00241 mol().a() += fIT/massI;
00242
00243 mol().potentialEnergy() += tetherPot.energy(idI, rIT);
00244
00245
00246
00247 }
00248 }
00249 }
00250
00251
00252 void Foam::moleculeCloud::calculateExternalForce()
00253 {
00254 iterator mol(this->begin());
00255
00256 for (mol = this->begin(); mol != this->end(); ++mol)
00257 {
00258 mol().a() += pot_.gravity();
00259 }
00260 }
00261
00262
00263 void Foam::moleculeCloud::removeHighEnergyOverlaps()
00264 {
00265 Info<< nl << "Removing high energy overlaps, limit = "
00266 << pot_.potentialEnergyLimit()
00267 << nl << "Removal order:";
00268
00269 forAll(pot_.removalOrder(), rO)
00270 {
00271 Info<< ' ' << pot_.idList()[pot_.removalOrder()[rO]];
00272 }
00273
00274 Info<< nl ;
00275
00276 label initialSize = this->size();
00277
00278 buildCellOccupancy();
00279
00280
00281 iterator mol(this->begin());
00282
00283 {
00284 mol = this->begin();
00285
00286 molecule* molI = &mol();
00287
00288 molecule* molJ = &mol();
00289
00290 DynamicList<molecule*> molsToDelete;
00291
00292 const directInteractionList& dil(il_.dil());
00293
00294 forAll(dil, d)
00295 {
00296 forAll(cellOccupancy_[d],cellIMols)
00297 {
00298 molI = cellOccupancy_[d][cellIMols];
00299
00300 forAll(dil[d], interactingCells)
00301 {
00302 List< molecule* > cellJ =
00303 cellOccupancy_[dil[d][interactingCells]];
00304
00305 forAll(cellJ, cellJMols)
00306 {
00307 molJ = cellJ[cellJMols];
00308
00309 if (evaluatePotentialLimit(molI, molJ))
00310 {
00311 label idI = molI->id();
00312
00313 label idJ = molJ->id();
00314
00315 if
00316 (
00317 idI == idJ
00318 || findIndex(pot_.removalOrder(), idJ)
00319 < findIndex(pot_.removalOrder(), idI)
00320 )
00321 {
00322 if (findIndex(molsToDelete, molJ) == -1)
00323 {
00324 molsToDelete.append(molJ);
00325 }
00326 }
00327 else if (findIndex(molsToDelete, molI) == -1)
00328 {
00329 molsToDelete.append(molI);
00330 }
00331 }
00332 }
00333 }
00334 }
00335
00336 forAll(cellOccupancy_[d],cellIOtherMols)
00337 {
00338 molJ = cellOccupancy_[d][cellIOtherMols];
00339
00340 if (molJ > molI)
00341 {
00342 if (evaluatePotentialLimit(molI, molJ))
00343 {
00344 label idI = molI->id();
00345
00346 label idJ = molJ->id();
00347
00348 if
00349 (
00350 idI == idJ
00351 || findIndex(pot_.removalOrder(), idJ)
00352 < findIndex(pot_.removalOrder(), idI)
00353 )
00354 {
00355 if (findIndex(molsToDelete, molJ) == -1)
00356 {
00357 molsToDelete.append(molJ);
00358 }
00359 }
00360 else if (findIndex(molsToDelete, molI) == -1)
00361 {
00362 molsToDelete.append(molI);
00363 }
00364 }
00365 }
00366 }
00367 }
00368
00369 forAll (molsToDelete, mTD)
00370 {
00371 deleteParticle(*(molsToDelete[mTD]));
00372 }
00373 }
00374
00375 buildCellOccupancy();
00376
00377
00378
00379 {
00380 molecule* molK = &mol();
00381
00382 DynamicList<molecule*> molsToDelete;
00383
00384 referredCellList& ril(il_.ril());
00385
00386 forAll(ril, r)
00387 {
00388 referredCell& refCell = ril[r];
00389
00390 forAll(refCell, refMols)
00391 {
00392 referredMolecule* molL = &(refCell[refMols]);
00393
00394 List <label> realCells = refCell.realCellsForInteraction();
00395
00396 forAll(realCells, rC)
00397 {
00398 label cellK = realCells[rC];
00399
00400 List<molecule*> cellKMols = cellOccupancy_[cellK];
00401
00402 forAll(cellKMols, cKM)
00403 {
00404 molK = cellKMols[cKM];
00405
00406 if (evaluatePotentialLimit(molK, molL))
00407 {
00408 label idK = molK->id();
00409
00410 label idL = molL->id();
00411
00412 if
00413 (
00414 findIndex(pot_.removalOrder(), idK)
00415 < findIndex(pot_.removalOrder(), idL)
00416 )
00417 {
00418 if (findIndex(molsToDelete, molK) == -1)
00419 {
00420 molsToDelete.append(molK);
00421 }
00422 }
00423
00424 else if
00425 (
00426 findIndex(pot_.removalOrder(), idK)
00427 == findIndex(pot_.removalOrder(), idL)
00428 )
00429 {
00430 if
00431 (
00432 Pstream::myProcNo() == refCell.sourceProc()
00433 && cellK <= refCell.sourceCell()
00434 )
00435 {
00436 if (findIndex(molsToDelete, molK) == -1)
00437 {
00438 molsToDelete.append(molK);
00439 }
00440 }
00441
00442 else if
00443 (
00444 Pstream::myProcNo() < refCell.sourceProc()
00445 )
00446 {
00447 if (findIndex(molsToDelete, molK) == -1)
00448 {
00449 molsToDelete.append(molK);
00450 }
00451 }
00452 }
00453 }
00454 }
00455 }
00456 }
00457 }
00458
00459 forAll (molsToDelete, mTD)
00460 {
00461 deleteParticle(*(molsToDelete[mTD]));
00462 }
00463 }
00464
00465 buildCellOccupancy();
00466
00467 label molsRemoved = initialSize - this->size();
00468
00469 if (Pstream::parRun())
00470 {
00471 reduce(molsRemoved, sumOp<label>());
00472 }
00473
00474 Info<< tab << molsRemoved << " molecules removed" << endl;
00475 }
00476
00477
00478 void Foam::moleculeCloud::initialiseMolecules
00479 (
00480 const IOdictionary& mdInitialiseDict
00481 )
00482 {
00483 Info<< nl
00484 << "Initialising molecules in each zone specified in mdInitialiseDict."
00485 << endl;
00486
00487 const cellZoneMesh& cellZones = mesh_.cellZones();
00488
00489 if (!cellZones.size())
00490 {
00491 FatalErrorIn("void Foam::moleculeCloud::initialiseMolecules")
00492 << "No cellZones found in the mesh."
00493 << abort(FatalError);
00494 }
00495
00496 forAll (cellZones, z)
00497 {
00498 const cellZone& zone(cellZones[z]);
00499
00500 if (zone.size())
00501 {
00502 if (!mdInitialiseDict.found(zone.name()))
00503 {
00504 Info<< "No specification subDictionary for zone "
00505 << zone.name() << " found, skipping." << endl;
00506 }
00507 else
00508 {
00509 const dictionary& zoneDict =
00510 mdInitialiseDict.subDict(zone.name());
00511
00512 const scalar temperature
00513 (
00514 readScalar(zoneDict.lookup("temperature"))
00515 );
00516
00517 const vector bulkVelocity(zoneDict.lookup("bulkVelocity"));
00518
00519 List<word> latticeIds
00520 (
00521 zoneDict.lookup("latticeIds")
00522 );
00523
00524 List<vector> latticePositions
00525 (
00526 zoneDict.lookup("latticePositions")
00527 );
00528
00529 if(latticeIds.size() != latticePositions.size())
00530 {
00531 FatalErrorIn("Foam::moleculeCloud::initialiseMolecules")
00532 << "latticeIds and latticePositions must be the same "
00533 << " size." << nl
00534 << abort(FatalError);
00535 }
00536
00537 diagTensor latticeCellShape
00538 (
00539 zoneDict.lookup("latticeCellShape")
00540 );
00541
00542 scalar latticeCellScale = 0.0;
00543
00544 if (zoneDict.found("numberDensity"))
00545 {
00546 scalar numberDensity = readScalar
00547 (
00548 zoneDict.lookup("numberDensity")
00549 );
00550
00551 if (numberDensity < VSMALL)
00552 {
00553 WarningIn("moleculeCloud::initialiseMolecules")
00554 << "numberDensity too small, not filling zone "
00555 << zone.name() << endl;
00556
00557 continue;
00558 }
00559
00560 latticeCellScale = pow
00561 (
00562 latticeIds.size()/(det(latticeCellShape)*numberDensity),
00563 (1.0/3.0)
00564 );
00565 }
00566 else if (zoneDict.found("massDensity"))
00567 {
00568 scalar unitCellMass = 0.0;
00569
00570 forAll(latticeIds, i)
00571 {
00572 label id = findIndex(pot_.idList(), latticeIds[i]);
00573
00574 const molecule::constantProperties& cP(constProps(id));
00575
00576 unitCellMass += cP.mass();
00577 }
00578
00579 scalar massDensity = readScalar
00580 (
00581 zoneDict.lookup("massDensity")
00582 );
00583
00584 if (massDensity < VSMALL)
00585 {
00586 WarningIn("moleculeCloud::initialiseMolecules")
00587 << "massDensity too small, not filling zone "
00588 << zone.name() << endl;
00589
00590 continue;
00591 }
00592
00593
00594 latticeCellScale = pow
00595 (
00596 unitCellMass/(det(latticeCellShape)*massDensity),
00597 (1.0/3.0)
00598 );
00599 }
00600 else
00601 {
00602 FatalErrorIn("Foam::moleculeCloud::initialiseMolecules")
00603 << "massDensity or numberDensity not specified " << nl
00604 << abort(FatalError);
00605 }
00606
00607 latticeCellShape *= latticeCellScale;
00608
00609 vector anchor(zoneDict.lookup("anchor"));
00610
00611 bool tethered = false;
00612
00613 if (zoneDict.found("tetherSiteIds"))
00614 {
00615 tethered = bool
00616 (
00617 List<word>(zoneDict.lookup("tetherSiteIds")).size()
00618 );
00619 }
00620
00621 const vector orientationAngles
00622 (
00623 zoneDict.lookup("orientationAngles")
00624 );
00625
00626 scalar phi
00627 (
00628 orientationAngles.x()*mathematicalConstant::pi/180.0
00629 );
00630
00631 scalar theta
00632 (
00633 orientationAngles.y()*mathematicalConstant::pi/180.0
00634 );
00635
00636 scalar psi
00637 (
00638 orientationAngles.z()*mathematicalConstant::pi/180.0
00639 );
00640
00641 const tensor R
00642 (
00643 cos(psi)*cos(phi) - cos(theta)*sin(phi)*sin(psi),
00644 cos(psi)*sin(phi) + cos(theta)*cos(phi)*sin(psi),
00645 sin(psi)*sin(theta),
00646 - sin(psi)*cos(phi) - cos(theta)*sin(phi)*cos(psi),
00647 - sin(psi)*sin(phi) + cos(theta)*cos(phi)*cos(psi),
00648 cos(psi)*sin(theta),
00649 sin(theta)*sin(phi),
00650 - sin(theta)*cos(phi),
00651 cos(theta)
00652 );
00653
00654
00655
00656
00657
00658 vector zoneMin = VGREAT*vector::one;
00659
00660 vector zoneMax = -VGREAT*vector::one;
00661
00662 forAll (zone, cell)
00663 {
00664 const point cellCentre = mesh_.cellCentres()[zone[cell]];
00665
00666 if (cellCentre.x() > zoneMax.x())
00667 {
00668 zoneMax.x() = cellCentre.x();
00669 }
00670 if (cellCentre.x() < zoneMin.x())
00671 {
00672 zoneMin.x() = cellCentre.x();
00673 }
00674 if (cellCentre.y() > zoneMax.y())
00675 {
00676 zoneMax.y() = cellCentre.y();
00677 }
00678 if (cellCentre.y() < zoneMin.y())
00679 {
00680 zoneMin.y() = cellCentre.y();
00681 }
00682 if (cellCentre.z() > zoneMax.z())
00683 {
00684 zoneMax.z() = cellCentre.z();
00685 }
00686 if (cellCentre.z() < zoneMin.z())
00687 {
00688 zoneMin.z() = cellCentre.z();
00689 }
00690 }
00691
00692 point zoneMid = 0.5*(zoneMin + zoneMax);
00693
00694 point latticeMid = inv(latticeCellShape) & (R.T()
00695 & (zoneMid - anchor));
00696
00697 point latticeAnchor
00698 (
00699 label(latticeMid.x() + 0.5*sign(latticeMid.x())),
00700 label(latticeMid.y() + 0.5*sign(latticeMid.y())),
00701 label(latticeMid.z() + 0.5*sign(latticeMid.z()))
00702 );
00703
00704 anchor += (R & (latticeCellShape & latticeAnchor));
00705
00706
00707
00708
00709
00710
00711
00712 label n = 0;
00713
00714 label totalZoneMols = 0;
00715
00716 label molsPlacedThisIteration = 0;
00717
00718 while
00719 (
00720 molsPlacedThisIteration != 0
00721 || totalZoneMols == 0
00722 )
00723 {
00724 label sizeBeforeIteration = this->size();
00725
00726 bool partOfLayerInBounds = false;
00727
00728
00729
00730
00731
00732 if (n == 0)
00733 {
00734
00735
00736
00737 labelVector unitCellLatticePosition(0,0,0);
00738
00739 forAll(latticePositions, p)
00740 {
00741 label id = findIndex(pot_.idList(), latticeIds[p]);
00742
00743 const vector& latticePosition =
00744 vector
00745 (
00746 unitCellLatticePosition.x(),
00747 unitCellLatticePosition.y(),
00748 unitCellLatticePosition.z()
00749 )
00750 + latticePositions[p];
00751
00752 point globalPosition =
00753 anchor + (R & (latticeCellShape & latticePosition));
00754
00755 partOfLayerInBounds =
00756 mesh_.bounds().contains(globalPosition);
00757
00758 label cell = mesh_.findCell(globalPosition);
00759
00760 if (findIndex(zone, cell) != -1)
00761 {
00762 createMolecule
00763 (
00764 globalPosition,
00765 cell,
00766 id,
00767 tethered,
00768 temperature,
00769 bulkVelocity
00770 );
00771 }
00772 }
00773 }
00774 else
00775 {
00776
00777
00778 labelVector unitCellLatticePosition(0,0,0);
00779
00780 for
00781 (
00782 unitCellLatticePosition.z() = -n;
00783 unitCellLatticePosition.z() <= n;
00784 unitCellLatticePosition.z() += 2*n
00785 )
00786 {
00787 for
00788 (
00789 unitCellLatticePosition.y() = -n;
00790 unitCellLatticePosition.y() <= n;
00791 unitCellLatticePosition.y()++
00792 )
00793 {
00794 for
00795 (
00796 unitCellLatticePosition.x() = -n;
00797 unitCellLatticePosition.x() <= n;
00798 unitCellLatticePosition.x()++
00799 )
00800 {
00801 forAll(latticePositions, p)
00802 {
00803 label id = findIndex
00804 (
00805 pot_.idList(),
00806 latticeIds[p]
00807 );
00808
00809 const vector& latticePosition =
00810 vector
00811 (
00812 unitCellLatticePosition.x(),
00813 unitCellLatticePosition.y(),
00814 unitCellLatticePosition.z()
00815 )
00816 + latticePositions[p];
00817
00818 point globalPosition = anchor
00819 + (R
00820 &(latticeCellShape & latticePosition));
00821
00822 partOfLayerInBounds =
00823 mesh_.bounds().contains(globalPosition);
00824
00825 label cell = mesh_.findCell
00826 (
00827 globalPosition
00828 );
00829
00830 if (findIndex(zone, cell) != -1)
00831 {
00832 createMolecule
00833 (
00834 globalPosition,
00835 cell,
00836 id,
00837 tethered,
00838 temperature,
00839 bulkVelocity
00840 );
00841 }
00842 }
00843 }
00844 }
00845 }
00846
00847 for
00848 (
00849 unitCellLatticePosition.z() = -(n-1);
00850 unitCellLatticePosition.z() <= (n-1);
00851 unitCellLatticePosition.z()++
00852 )
00853 {
00854 for (label iR = 0; iR <= 2*n -1; iR++)
00855 {
00856 unitCellLatticePosition.x() = n;
00857
00858 unitCellLatticePosition.y() = -n + (iR + 1);
00859
00860 for (label iK = 0; iK < 4; iK++)
00861 {
00862 forAll(latticePositions, p)
00863 {
00864 label id = findIndex
00865 (
00866 pot_.idList(),
00867 latticeIds[p]
00868 );
00869
00870 const vector& latticePosition =
00871 vector
00872 (
00873 unitCellLatticePosition.x(),
00874 unitCellLatticePosition.y(),
00875 unitCellLatticePosition.z()
00876 )
00877 + latticePositions[p];
00878
00879 point globalPosition = anchor
00880 + (R
00881 &(latticeCellShape & latticePosition));
00882
00883 partOfLayerInBounds =
00884 mesh_.bounds().contains(globalPosition);
00885
00886 label cell = mesh_.findCell
00887 (
00888 globalPosition
00889 );
00890
00891 if (findIndex(zone, cell) != -1)
00892 {
00893 createMolecule
00894 (
00895 globalPosition,
00896 cell,
00897 id,
00898 tethered,
00899 temperature,
00900 bulkVelocity
00901 );
00902 }
00903 }
00904
00905 unitCellLatticePosition =
00906 labelVector
00907 (
00908 - unitCellLatticePosition.y(),
00909 unitCellLatticePosition.x(),
00910 unitCellLatticePosition.z()
00911 );
00912 }
00913 }
00914 }
00915 }
00916
00917
00918
00919
00920
00921 if
00922 (
00923 totalZoneMols == 0
00924 && !partOfLayerInBounds
00925 )
00926 {
00927 WarningIn("Foam::moleculeCloud::initialiseMolecules()")
00928 << "A whole layer of unit cells was placed "
00929 << "outside the bounds of the mesh, but no "
00930 << "molecules have been placed in zone '"
00931 << zone.name()
00932 << "'. This is likely to be because the zone "
00933 << "has few cells ("
00934 << zone.size()
00935 << " in this case) and no lattice position "
00936 << "fell inside them. "
00937 << "Aborting filling this zone."
00938 << endl;
00939
00940 break;
00941 }
00942
00943 molsPlacedThisIteration =
00944 this->size() - sizeBeforeIteration;
00945
00946 totalZoneMols += molsPlacedThisIteration;
00947
00948 n++;
00949 }
00950 }
00951 }
00952 }
00953 }
00954
00955
00956 void Foam::moleculeCloud::createMolecule
00957 (
00958 const point& position,
00959 label cell,
00960 label id,
00961 bool tethered,
00962 scalar temperature,
00963 const vector& bulkVelocity
00964 )
00965 {
00966 const Cloud<molecule>& cloud = *this;
00967
00968 if (cell == -1)
00969 {
00970 cell = mesh_.findCell(position);
00971 }
00972
00973 if (cell == -1)
00974 {
00975 FatalErrorIn("Foam::moleculeCloud::createMolecule")
00976 << "Position specified does not correspond to a mesh cell." << nl
00977 << abort(FatalError);
00978 }
00979
00980 point specialPosition(vector::zero);
00981
00982 label special = 0;
00983
00984 if (tethered)
00985 {
00986 specialPosition = position;
00987
00988 special = molecule::SPECIAL_TETHERED;
00989 }
00990
00991 const molecule::constantProperties& cP(constProps(id));
00992
00993 vector v = equipartitionLinearVelocity(temperature, cP.mass());
00994
00995 v += bulkVelocity;
00996
00997 vector pi = vector::zero;
00998
00999 tensor Q = I;
01000
01001 if (!cP.pointMolecule())
01002 {
01003 pi = equipartitionAngularMomentum(temperature, cP);
01004
01005 scalar phi(rndGen_.scalar01()*mathematicalConstant::twoPi);
01006
01007 scalar theta(rndGen_.scalar01()*mathematicalConstant::twoPi);
01008
01009 scalar psi(rndGen_.scalar01()*mathematicalConstant::twoPi);
01010
01011 Q = tensor
01012 (
01013 cos(psi)*cos(phi) - cos(theta)*sin(phi)*sin(psi),
01014 cos(psi)*sin(phi) + cos(theta)*cos(phi)*sin(psi),
01015 sin(psi)*sin(theta),
01016 - sin(psi)*cos(phi) - cos(theta)*sin(phi)*cos(psi),
01017 - sin(psi)*sin(phi) + cos(theta)*cos(phi)*cos(psi),
01018 cos(psi)*sin(theta),
01019 sin(theta)*sin(phi),
01020 - sin(theta)*cos(phi),
01021 cos(theta)
01022 );
01023 }
01024
01025 addParticle
01026 (
01027 new molecule
01028 (
01029 cloud,
01030 position,
01031 cell,
01032 Q,
01033 v,
01034 vector::zero,
01035 pi,
01036 vector::zero,
01037 specialPosition,
01038 constProps(id),
01039 special,
01040 id
01041 )
01042 );
01043 }
01044
01045
01046 Foam::label Foam::moleculeCloud::nSites() const
01047 {
01048 label n = 0;
01049
01050 const_iterator mol(this->begin());
01051
01052 for (mol = this->begin(); mol != this->end(); ++mol)
01053 {
01054 n += constProps(mol().id()).nSites();
01055 }
01056
01057 return n;
01058 }
01059
01060
01061
01062
01063 Foam::moleculeCloud::moleculeCloud
01064 (
01065 const polyMesh& mesh,
01066 const potential& pot
01067 )
01068 :
01069 Cloud<molecule>(mesh, "moleculeCloud", false),
01070 mesh_(mesh),
01071 pot_(pot),
01072 cellOccupancy_(mesh_.nCells()),
01073 il_(mesh_, pot_.pairPotentials().rCutMaxSqr(), false),
01074 constPropList_(),
01075 rndGen_(clock::getTime())
01076 {
01077 molecule::readFields(*this);
01078
01079 buildConstProps();
01080
01081 setSiteSizesAndPositions();
01082
01083 removeHighEnergyOverlaps();
01084
01085 calculateForce();
01086 }
01087
01088
01089 Foam::moleculeCloud::moleculeCloud
01090 (
01091 const polyMesh& mesh,
01092 const potential& pot,
01093 const IOdictionary& mdInitialiseDict
01094 )
01095 :
01096 Cloud<molecule>(mesh, "moleculeCloud", false),
01097 mesh_(mesh),
01098 pot_(pot),
01099 il_(mesh_),
01100 constPropList_(),
01101 rndGen_(clock::getTime())
01102 {
01103 molecule::readFields(*this);
01104
01105 clear();
01106
01107 buildConstProps();
01108
01109 initialiseMolecules(mdInitialiseDict);
01110 }
01111
01112
01113
01114
01115 void Foam::moleculeCloud::evolve()
01116 {
01117 molecule::trackData td0(*this, 0);
01118 Cloud<molecule>::move(td0);
01119
01120 molecule::trackData td1(*this, 1);
01121 Cloud<molecule>::move(td1);
01122
01123 molecule::trackData td2(*this, 2);
01124 Cloud<molecule>::move(td2);
01125
01126 calculateForce();
01127
01128 molecule::trackData td3(*this, 3);
01129 Cloud<molecule>::move(td3);
01130 }
01131
01132
01133 void Foam::moleculeCloud::calculateForce()
01134 {
01135 buildCellOccupancy();
01136
01137 iterator mol(this->begin());
01138
01139
01140 for (mol = this->begin(); mol != this->end(); ++mol)
01141 {
01142 mol().siteForces() = vector::zero;
01143
01144 mol().potentialEnergy() = 0.0;
01145
01146 mol().rf() = tensor::zero;
01147 }
01148
01149 calculatePairForce();
01150
01151 calculateTetherForce();
01152
01153 calculateExternalForce();
01154 }
01155
01156
01157 void Foam::moleculeCloud::applyConstraintsAndThermostats
01158 (
01159 const scalar targetTemperature,
01160 const scalar measuredTemperature
01161 )
01162 {
01163 scalar temperatureCorrectionFactor =
01164 sqrt(targetTemperature/measuredTemperature);
01165
01166 Info<< "----------------------------------------" << nl
01167 << "Temperature equilibration" << nl
01168 << "Target temperature = "
01169 << targetTemperature << nl
01170 << "Measured temperature = "
01171 << measuredTemperature << nl
01172 << "Temperature correction factor = "
01173 << temperatureCorrectionFactor << nl
01174 << "----------------------------------------"
01175 << endl;
01176
01177 iterator mol(this->begin());
01178
01179 for (mol = this->begin(); mol != this->end(); ++mol)
01180 {
01181 mol().v() *= temperatureCorrectionFactor;
01182
01183 mol().pi() *= temperatureCorrectionFactor;
01184 }
01185 }
01186
01187
01188 void Foam::moleculeCloud::writeFields() const
01189 {
01190 molecule::writeFields(*this);
01191 }
01192
01193
01194 void Foam::moleculeCloud::writeXYZ(const fileName& fName) const
01195 {
01196 OFstream str(fName);
01197
01198 str << nSites() << nl << "moleculeCloud site positions in angstroms" << nl;
01199
01200 const_iterator mol(this->begin());
01201
01202 for (mol = this->begin(); mol != this->end(); ++mol)
01203 {
01204 const molecule::constantProperties& cP = constProps(mol().id());
01205
01206 forAll(mol().sitePositions(), i)
01207 {
01208 const point& sP = mol().sitePositions()[i];
01209
01210 str << pot_.siteIdList()[cP.siteIds()[i]]
01211 << ' ' << sP.x()*1e10
01212 << ' ' << sP.y()*1e10
01213 << ' ' << sP.z()*1e10
01214 << nl;
01215 }
01216 }
01217 }
01218
01219
01220