moleculeCloudI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "constants.H"
27 
28 using namespace Foam::constant;
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
33 (
34  molecule& molI,
35  molecule& molJ
36 )
37 {
38  const pairPotentialList& pairPot = pot_.pairPotentials();
39 
40  const pairPotential& electrostatic = pairPot.electrostatic();
41 
42  label idI = molI.id();
43 
44  label idJ = molJ.id();
45 
46  const molecule::constantProperties& constPropI(constProps(idI));
47 
48  const molecule::constantProperties& constPropJ(constProps(idJ));
49 
50  List<label> siteIdsI = constPropI.siteIds();
51 
52  List<label> siteIdsJ = constPropJ.siteIds();
53 
54  List<bool> pairPotentialSitesI = constPropI.pairPotentialSites();
55 
56  List<bool> electrostaticSitesI = constPropI.electrostaticSites();
57 
58  List<bool> pairPotentialSitesJ = constPropJ.pairPotentialSites();
59 
60  List<bool> electrostaticSitesJ = constPropJ.electrostaticSites();
61 
62  forAll(siteIdsI, sI)
63  {
64  label idsI(siteIdsI[sI]);
65 
66  forAll(siteIdsJ, sJ)
67  {
68  label idsJ(siteIdsJ[sJ]);
69 
70  if (pairPotentialSitesI[sI] && pairPotentialSitesJ[sJ])
71  {
72  vector rsIsJ =
73  molI.sitePositions()[sI] - molJ.sitePositions()[sJ];
74 
75  scalar rsIsJMagSq = magSqr(rsIsJ);
76 
77  if (pairPot.rCutSqr(idsI, idsJ, rsIsJMagSq))
78  {
79  scalar rsIsJMag = mag(rsIsJ);
80 
81  vector fsIsJ =
82  (rsIsJ/rsIsJMag)
83  *pairPot.force(idsI, idsJ, rsIsJMag);
84 
85  molI.siteForces()[sI] += fsIsJ;
86 
87  molJ.siteForces()[sJ] += -fsIsJ;
88 
89  scalar potentialEnergy
90  (
91  pairPot.energy(idsI, idsJ, rsIsJMag)
92  );
93 
94  molI.potentialEnergy() += 0.5*potentialEnergy;
95 
96  molJ.potentialEnergy() += 0.5*potentialEnergy;
97 
98  vector rIJ = molI.position() - molJ.position();
99 
100  tensor virialContribution =
101  (rsIsJ*fsIsJ)*(rsIsJ & rIJ)/rsIsJMagSq;
102 
103  molI.rf() += virialContribution;
104 
105  molJ.rf() += virialContribution;
106  }
107  }
108 
109  if (electrostaticSitesI[sI] && electrostaticSitesJ[sJ])
110  {
111  vector rsIsJ =
112  molI.sitePositions()[sI] - molJ.sitePositions()[sJ];
113 
114  scalar rsIsJMagSq = magSqr(rsIsJ);
115 
116  if (rsIsJMagSq <= electrostatic.rCutSqr())
117  {
118  scalar rsIsJMag = mag(rsIsJ);
119 
120  scalar chargeI = constPropI.siteCharges()[sI];
121 
122  scalar chargeJ = constPropJ.siteCharges()[sJ];
123 
124  vector fsIsJ =
125  (rsIsJ/rsIsJMag)
126  *chargeI*chargeJ*electrostatic.force(rsIsJMag);
127 
128  molI.siteForces()[sI] += fsIsJ;
129 
130  molJ.siteForces()[sJ] += -fsIsJ;
131 
132  scalar potentialEnergy =
133  chargeI*chargeJ
134  *electrostatic.energy(rsIsJMag);
135 
136  molI.potentialEnergy() += 0.5*potentialEnergy;
137 
138  molJ.potentialEnergy() += 0.5*potentialEnergy;
139 
140  vector rIJ = molI.position() - molJ.position();
141 
142  tensor virialContribution =
143  (rsIsJ*fsIsJ)*(rsIsJ & rIJ)/rsIsJMagSq;
144 
145  molI.rf() += virialContribution;
146 
147  molJ.rf() += virialContribution;
148  }
149  }
150  }
151  }
152 }
153 
154 
156 (
157  molecule& molI,
158  molecule& molJ
159 ) const
160 {
161  const pairPotentialList& pairPot = pot_.pairPotentials();
162 
163  const pairPotential& electrostatic = pairPot.electrostatic();
164 
165  label idI = molI.id();
166 
167  label idJ = molJ.id();
168 
169  const molecule::constantProperties& constPropI(constProps(idI));
170 
171  const molecule::constantProperties& constPropJ(constProps(idJ));
172 
173  List<label> siteIdsI = constPropI.siteIds();
174 
175  List<label> siteIdsJ = constPropJ.siteIds();
176 
177  List<bool> pairPotentialSitesI = constPropI.pairPotentialSites();
178 
179  List<bool> electrostaticSitesI = constPropI.electrostaticSites();
180 
181  List<bool> pairPotentialSitesJ = constPropJ.pairPotentialSites();
182 
183  List<bool> electrostaticSitesJ = constPropJ.electrostaticSites();
184 
185  forAll(siteIdsI, sI)
186  {
187  label idsI(siteIdsI[sI]);
188 
189  forAll(siteIdsJ, sJ)
190  {
191  label idsJ(siteIdsJ[sJ]);
192 
193  if (pairPotentialSitesI[sI] && pairPotentialSitesJ[sJ])
194  {
195  vector rsIsJ =
196  molI.sitePositions()[sI] - molJ.sitePositions()[sJ];
197 
198  scalar rsIsJMagSq = magSqr(rsIsJ);
199 
200  if (pairPot.rCutSqr(idsI, idsJ, rsIsJMagSq))
201  {
202  scalar rsIsJMag = mag(rsIsJ);
203 
204  // Guard against pairPot.energy being evaluated
205  // if rIJMag < SMALL. A floating point exception will
206  // happen otherwise.
207 
208  if (rsIsJMag < SMALL)
209  {
211  << "Molecule site pair closer than "
212  << SMALL
213  << ": mag separation = " << rsIsJMag
214  << ". These may have been placed on top of each"
215  << " other by a rounding error in mdInitialise in"
216  << " parallel or a block filled with molecules"
217  << " twice. Removing one of the molecules."
218  << endl;
219 
220  return true;
221  }
222 
223  // Guard against pairPot.energy being evaluated if rIJMag <
224  // rMin. A tabulation lookup error will occur otherwise.
225 
226  if (rsIsJMag < pairPot.rMin(idsI, idsJ))
227  {
228  return true;
229  }
230 
231  if
232  (
233  mag(pairPot.energy(idsI, idsJ, rsIsJMag))
234  > pot_.potentialEnergyLimit()
235  )
236  {
237  return true;
238  };
239  }
240  }
241 
242  if (electrostaticSitesI[sI] && electrostaticSitesJ[sJ])
243  {
244  vector rsIsJ =
245  molI.sitePositions()[sI] - molJ.sitePositions()[sJ];
246 
247  scalar rsIsJMagSq = magSqr(rsIsJ);
248 
249  if (pairPot.rCutMaxSqr(rsIsJMagSq))
250  {
251  scalar rsIsJMag = mag(rsIsJ);
252 
253  // Guard against pairPot.energy being evaluated
254  // if rIJMag < SMALL. A floating point exception will
255  // happen otherwise.
256 
257  if (rsIsJMag < SMALL)
258  {
260  << "Molecule site pair closer than "
261  << SMALL
262  << ": mag separation = " << rsIsJMag
263  << ". These may have been placed on top of each"
264  << " other by a rounding error in mdInitialise in"
265  << " parallel or a block filled with molecules"
266  << " twice. Removing one of the molecules."
267  << endl;
268 
269  return true;
270  }
271 
272  if (rsIsJMag < electrostatic.rMin())
273  {
274  return true;
275  }
276 
277  scalar chargeI = constPropI.siteCharges()[sI];
278 
279  scalar chargeJ = constPropJ.siteCharges()[sJ];
280 
281  if
282  (
283  mag(chargeI*chargeJ*electrostatic.energy(rsIsJMag))
284  > pot_.potentialEnergyLimit()
285  )
286  {
287  return true;
288  };
289  }
290  }
291  }
292  }
293 
294  return false;
295 }
296 
297 
299 (
300  scalar temperature,
301  scalar mass
302 )
303 {
304  return sqrt(physicoChemical::k.value()*temperature/mass)*vector
305  (
306  rndGen_.GaussNormal(),
307  rndGen_.GaussNormal(),
308  rndGen_.GaussNormal()
309  );
310 }
311 
312 
314 (
315  scalar temperature,
317 )
318 {
319  scalar sqrtKbT = sqrt(physicoChemical::k.value()*temperature);
320 
321  if (cP.linearMolecule())
322  {
323  return sqrtKbT*vector
324  (
325  0.0,
326  sqrt(cP.momentOfInertia().yy())*rndGen_.GaussNormal(),
327  sqrt(cP.momentOfInertia().zz())*rndGen_.GaussNormal()
328  );
329  }
330  else
331  {
332  return sqrtKbT*vector
333  (
334  sqrt(cP.momentOfInertia().xx())*rndGen_.GaussNormal(),
335  sqrt(cP.momentOfInertia().yy())*rndGen_.GaussNormal(),
336  sqrt(cP.momentOfInertia().zz())*rndGen_.GaussNormal()
337  );
338  }
339 }
340 
341 
342 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
343 
345 {
346  return mesh_;
347 }
348 
349 
351 {
352  return pot_;
353 }
354 
355 
358 {
359  return cellOccupancy_;
360 }
361 
362 
365 {
366  return il_;
367 }
368 
369 
372 {
373  return constPropList_;
374 }
375 
376 
379 {
380  return constPropList_[id];
381 }
382 
383 
385 {
386  return rndGen_;
387 }
388 
389 
390 // ************************************************************************* //
Foam::moleculeCloud::cellOccupancy
const List< DynamicList< molecule * > > & cellOccupancy() const
Definition: moleculeCloudI.H:357
Foam::DiagTensor::xx
const Cmpt & xx() const
Definition: DiagTensorI.H:76
Foam::Random
Simple random number generator.
Definition: Random.H:49
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::moleculeCloud::il
const InteractionLists< molecule > & il() const
Definition: moleculeCloudI.H:364
Foam::pairPotentialList
Definition: pairPotentialList.H:51
Foam::constant::physicoChemical::k
const dimensionedScalar k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::pairPotential::rCutSqr
scalar rCutSqr() const
Definition: pairPotentialI.H:46
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::constant
Collection of constants.
Definition: atomicConstants.C:37
Foam::molecule::constantProperties::siteIds
const List< label > & siteIds() const
Definition: moleculeI.H:352
Foam::DiagTensor::yy
const Cmpt & yy() const
Definition: DiagTensorI.H:82
Foam::pairPotential::force
scalar force(const scalar r) const
Definition: pairPotential.C:95
Foam::molecule::id
label id() const
Definition: moleculeI.H:598
Foam::pairPotentialList::electrostatic
const pairPotential & electrostatic() const
Definition: pairPotentialListI.H:73
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::moleculeCloud::equipartitionLinearVelocity
vector equipartitionLinearVelocity(scalar temperature, scalar mass)
Definition: moleculeCloudI.H:299
Foam::pairPotential::energy
scalar energy(const scalar r) const
Definition: pairPotential.C:132
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::pairPotentialList::rCutMaxSqr
scalar rCutMaxSqr() const
Definition: pairPotentialListI.H:67
Foam::molecule::sitePositions
const List< vector > & sitePositions() const
Definition: moleculeI.H:538
Foam::molecule::constantProperties::siteCharges
const List< scalar > & siteCharges() const
Definition: moleculeI.H:345
Foam::DiagTensor::zz
const Cmpt & zz() const
Definition: DiagTensorI.H:88
Foam::moleculeCloud::constProps
const List< molecule::constantProperties > constProps() const
Definition: moleculeCloudI.H:371
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::pairPotentialList::rCutSqr
bool rCutSqr(const label a, const label b, const scalar rIJMagSqr) const
Definition: pairPotentialList.C:241
Foam::molecule
Foam::molecule.
Definition: molecule.H:56
Foam::pairPotentialList::energy
scalar energy(const label a, const label b, const scalar rIJMag) const
Definition: pairPotentialList.C:312
Foam::pairPotential::rMin
scalar rMin() const
Definition: pairPotentialI.H:28
Foam::pairPotentialList::rMin
scalar rMin(const label a, const label b) const
Definition: pairPotentialList.C:259
Foam::InteractionLists< Foam::molecule >
Foam::molecule::constantProperties::momentOfInertia
const diagTensor & momentOfInertia() const
Definition: moleculeI.H:416
Foam::molecule::constantProperties::pairPotentialSites
const List< bool > & pairPotentialSites() const
Definition: moleculeI.H:366
Foam::molecule::constantProperties::linearMolecule
bool linearMolecule() const
Definition: moleculeI.H:422
Foam::molecule::rf
const tensor & rf() const
Definition: moleculeI.H:574
Foam::molecule::constantProperties::electrostaticSites
const List< bool > & electrostaticSites() const
Definition: moleculeI.H:391
Foam::moleculeCloud::mesh
const polyMesh & mesh() const
Definition: moleculeCloudI.H:344
Foam::molecule::siteForces
const List< vector > & siteForces() const
Definition: moleculeI.H:526
Foam::moleculeCloud::evaluatePotentialLimit
bool evaluatePotentialLimit(molecule &molI, molecule &molJ) const
Definition: moleculeCloudI.H:156
Foam::moleculeCloud::rndGen
Random & rndGen()
Definition: moleculeCloudI.H:384
Foam::potential
Definition: potential.H:53
Foam::pairPotential
Definition: pairPotential.H:57
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
constants.H
Foam::pairPotentialList::force
scalar force(const label a, const label b, const scalar rIJMag) const
Definition: pairPotentialList.C:299
Foam::moleculeCloud::pot
const potential & pot() const
Definition: moleculeCloudI.H:350
Foam::molecule::potentialEnergy
scalar potentialEnergy() const
Definition: moleculeI.H:562
Foam::Vector< scalar >
Foam::List< label >
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:142
Foam::molecule::constantProperties
Class to hold molecule constant properties.
Definition: molecule.H:81
Foam::particle::position
const vector & position() const
Return current particle position.
Definition: particleI.H:586
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::moleculeCloud::equipartitionAngularMomentum
vector equipartitionAngularMomentum(scalar temperature, const molecule::constantProperties &cP)
Definition: moleculeCloudI.H:314
Foam::moleculeCloud::evaluatePair
void evaluatePair(molecule &molI, molecule &molJ)
Definition: moleculeCloudI.H:33