molecule.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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 Class
25  Foam::molecule
26 
27 Description
28  Foam::molecule
29 
30 SourceFiles
31  moleculeI.H
32  molecule.C
33  moleculeIO.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef molecule_H
38 #define molecule_H
39 
40 #include "particle.H"
41 #include "Cloud.H"
42 #include "IOstream.H"
43 #include "autoPtr.H"
44 #include "diagTensor.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Class forward declarations
52 class moleculeCloud;
53 
54 
55 // Forward declaration of friend functions and operators
56 
57 class molecule;
58 
59 Ostream& operator<<(Ostream&, const molecule&);
60 
61 
62 /*---------------------------------------------------------------------------*\
63  Class molecule Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class molecule
67 :
68  public particle
69 {
70  // Private Data
71 
72  //- Size in bytes of the fields
73  static const std::size_t sizeofFields_;
74 
75 
76 public:
77 
78  // Values of special that are less than zero are for built-in functionality.
79  // Values greater than zero are user specifiable/expandable (i.e. test
80  // special_ >= SPECIAL_USER)
81 
82  enum specialTypes
83  {
87  SPECIAL_USER = 1
88  };
89 
90  //- Class to hold molecule constant properties
91  class constantProperties
92  {
93  // Private Data
94 
95  Field<vector> siteReferencePositions_;
96 
97  List<scalar> siteMasses_;
98 
99  List<scalar> siteCharges_;
100 
101  List<label> siteIds_;
102 
103  List<bool> pairPotentialSites_;
104 
105  List<bool> electrostaticSites_;
106 
107  diagTensor momentOfInertia_;
108 
109  scalar mass_;
110 
111 
112  // Private Member Functions
113 
114  void checkSiteListSizes() const;
115 
116  void setInteractionSiteBools
117  (
118  const List<word>& siteIds,
119  const List<word>& pairPotSiteIds
120  );
121 
122  bool linearMoleculeTest() const;
123 
124 
125  public:
126 
127  inline constantProperties();
128 
129  //- Construct from dictionary
130  inline constantProperties(const dictionary& dict);
131 
132  // Member Functions
133 
134  inline const Field<vector>& siteReferencePositions() const;
135 
136  inline const List<scalar>& siteMasses() const;
137 
138  inline const List<scalar>& siteCharges() const;
139 
140  inline const List<label>& siteIds() const;
141 
142  inline List<label>& siteIds();
143 
144  inline const List<bool>& pairPotentialSites() const;
145 
146  inline bool pairPotentialSite(label sId) const;
147 
148  inline const List<bool>& electrostaticSites() const;
149 
150  inline bool electrostaticSite(label sId) const;
151 
152  inline const diagTensor& momentOfInertia() const;
153 
154  inline bool linearMolecule() const;
155 
156  inline bool pointMolecule() const;
157 
158  inline label degreesOfFreedom() const;
159 
160  inline scalar mass() const;
161 
162  inline label nSites() const;
163  };
164 
165 
166  //- Class used to pass tracking data to the trackToFace function
167  class trackingData
168  :
170  {
171  public:
173  enum trackPart
174  {
175  tpVelocityHalfStep0,
176  tpLinearTrack,
177  tpRotationalTrack,
178  tpVelocityHalfStep1
179  };
180 
181 
182  private:
183 
184  // Private Data
185 
186  //- Which part of the integration algorithm is taking place
187  trackPart part_;
188 
189 
190  public:
191 
192  // Constructors
193 
194  //- Construct from components
196  :
197  particle::trackingData(cloud)
198  {}
199 
200 
201  // Member Functions
202 
203  //- Return the part of the tracking operation taking place
204  inline trackPart part() const
205  {
206  return part_;
207  }
208 
209  //- Access to the part of the tracking operation taking place
210  inline trackPart& part()
211  {
212  return part_;
213  }
214  };
215 
216 
217 private:
218 
219  // Private Data
220 
221  tensor Q_;
222 
223  vector v_;
224 
225  vector a_;
226 
227  vector pi_;
228 
229  vector tau_;
230 
231  vector specialPosition_;
232 
233  scalar potentialEnergy_;
234 
235  // - r_ij f_ij, stress dyad
236  tensor rf_;
237 
238  label special_;
239 
240  label id_;
241 
242  List<vector> siteForces_;
243 
244  List<vector> sitePositions_;
245 
246 
247  // Private Member Functions
248 
249  tensor rotationTensorX(scalar deltaT) const;
250 
251  tensor rotationTensorY(scalar deltaT) const;
252 
253  tensor rotationTensorZ(scalar deltaT) const;
254 
255 
256 public:
258  friend class Cloud<molecule>;
259 
260  // Constructors
261 
262  //- Construct from components
263  inline molecule
264  (
265  const polyMesh& mesh,
266  const barycentric& coordinates,
267  const label celli,
268  const label tetFacei,
269  const label tetPti,
270  const tensor& Q,
271  const vector& v,
272  const vector& a,
273  const vector& pi,
274  const vector& tau,
275  const vector& specialPosition,
276  const constantProperties& constProps,
277  const label special,
278  const label id
279  );
280 
281  //- Construct from a position and a cell, searching for the rest of the
282  // required topology
283  inline molecule
284  (
285  const polyMesh& mesh,
286  const vector& position,
287  const label celli,
288  const tensor& Q,
289  const vector& v,
290  const vector& a,
291  const vector& pi,
292  const vector& tau,
293  const vector& specialPosition,
294  const constantProperties& constProps,
295  const label special,
296  const label id
297  );
298 
299  //- Construct from Istream
300  molecule
301  (
302  const polyMesh& mesh,
303  Istream& is,
304  bool readFields = true
305  );
306 
307  //- Construct and return a clone
308  autoPtr<particle> clone() const
309  {
310  return autoPtr<particle>(new molecule(*this));
311  }
312 
313  //- Factory class to read-construct particles used for
314  // parallel transfer
315  class iNew
316  {
317  const polyMesh& mesh_;
318 
319  public:
321  iNew(const polyMesh& mesh)
322  :
323  mesh_(mesh)
324  {}
326  autoPtr<molecule> operator()(Istream& is) const
327  {
328  return autoPtr<molecule>(new molecule(mesh_, is, true));
329  }
330  };
331 
332 
333  // Member Functions
334 
335  // Tracking
336 
337  bool move(moleculeCloud&, trackingData&, const scalar trackTime);
338 
339  virtual void transformProperties(const transformer&);
340 
341  void setSitePositions(const constantProperties& constProps);
342 
343  void setSiteSizes(label size);
344 
345 
346  // Access
347 
348  inline const tensor& Q() const;
349  inline tensor& Q();
350 
351  inline const vector& v() const;
352  inline vector& v();
353 
354  inline const vector& a() const;
355  inline vector& a();
356 
357  inline const vector& pi() const;
358  inline vector& pi();
359 
360  inline const vector& tau() const;
361  inline vector& tau();
362 
363  inline const List<vector>& siteForces() const;
364  inline List<vector>& siteForces();
365 
366  inline const List<vector>& sitePositions() const;
367  inline List<vector>& sitePositions();
368 
369  inline const vector& specialPosition() const;
370  inline vector& specialPosition();
371 
372  inline scalar potentialEnergy() const;
373  inline scalar& potentialEnergy();
374 
375  inline const tensor& rf() const;
376  inline tensor& rf();
377 
378  inline label special() const;
379 
380  inline bool tethered() const;
381 
382  inline label id() const;
383 
384 
385  // Member Operators
386 
387  //- Overridable function to handle the particle hitting a patch
388  // Executed before other patch-hitting functions
390 
391  //- Overridable function to handle the particle hitting a processorPatch
392  void hitProcessorPatch(moleculeCloud& cloud, trackingData& td);
393 
394  //- Overridable function to handle the particle hitting a wallPatch
395  void hitWallPatch(moleculeCloud& cloud, trackingData& td);
396 
397 
398  // I-O
399 
400  static void readFields(Cloud<molecule>& mC);
401 
402  static void writeFields(const Cloud<molecule>& mC);
403 
404 
405  // IOstream Operators
406 
407  friend Ostream& operator<<(Ostream&, const molecule&);
408 };
409 
410 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
411 
412 } // End namespace Foam
413 
414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 
416 #include "moleculeI.H"
417 
418 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
419 
420 #endif
421 
422 // ************************************************************************* //
scalar potentialEnergy() const
Definition: moleculeI.H:597
const tensor & Q() const
Definition: moleculeI.H:501
dictionary dict
const List< bool > & electrostaticSites() const
Definition: moleculeI.H:426
const polyMesh & mesh() const
Return the mesh database.
Definition: particleI.H:125
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
const List< vector > & sitePositions() const
Definition: moleculeI.H:573
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space...
Definition: transformer.H:83
const tensor & rf() const
Definition: moleculeI.H:609
const diagTensor & momentOfInertia() const
Definition: moleculeI.H:451
Class to hold molecule constant properties.
Definition: molecule.H:90
void setSitePositions(const constantProperties &constProps)
Definition: molecule.C:216
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
const List< vector > & siteForces() const
Definition: moleculeI.H:561
bool hitPatch(moleculeCloud &cloud, trackingData &td)
Overridable function to handle the particle hitting a patch.
Definition: molecule.C:230
label special() const
Definition: moleculeI.H:621
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const List< label > & siteIds() const
Definition: moleculeI.H:387
void hitProcessorPatch(moleculeCloud &cloud, trackingData &td)
Overridable function to handle the particle hitting a processorPatch.
Definition: molecule.C:236
bool tethered() const
Definition: moleculeI.H:627
virtual void transformProperties(const transformer &)
Transform the physical properties of the particle.
Definition: molecule.C:189
const vector & pi() const
Definition: moleculeI.H:537
static void writeFields(const Cloud< molecule > &mC)
Definition: moleculeIO.C:150
bool move(moleculeCloud &, trackingData &, const scalar trackTime)
Definition: molecule.C:69
static void readFields(Cloud< molecule > &mC)
Definition: moleculeIO.C:94
Base particle class.
Definition: particle.H:83
const Field< vector > & siteReferencePositions() const
Definition: moleculeI.H:366
const vector & a() const
Definition: moleculeI.H:525
friend Ostream & operator<<(Ostream &, const molecule &)
molecule(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti, const tensor &Q, const vector &v, const vector &a, const vector &pi, const vector &tau, const vector &specialPosition, const constantProperties &constProps, const label special, const label id)
Construct from components.
Definition: moleculeI.H:221
A cloud is a collection of lagrangian particles.
Definition: cloud.H:51
Base cloud calls templated on particle type.
Definition: Cloud.H:52
autoPtr< particle > clone() const
Construct and return a clone.
Definition: molecule.H:307
const List< bool > & pairPotentialSites() const
Definition: moleculeI.H:401
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void hitWallPatch(moleculeCloud &cloud, trackingData &td)
Overridable function to handle the particle hitting a wallPatch.
Definition: molecule.C:242
Factory class to read-construct particles used for.
Definition: molecule.H:314
bool electrostaticSite(label sId) const
Definition: moleculeI.H:433
Class used to pass tracking data to the trackToFace function.
Definition: molecule.H:166
void setSiteSizes(label size)
Definition: molecule.C:222
Ostream & operator<<(Ostream &, const ensightPart &)
const barycentric & coordinates() const
Return current particle coordinates.
Definition: particleI.H:131
Foam::molecule.
Definition: molecule.H:65
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
bool pairPotentialSite(label sId) const
Definition: moleculeI.H:408
label id() const
Definition: moleculeI.H:633
const List< scalar > & siteMasses() const
Definition: moleculeI.H:373
const vector & tau() const
Definition: moleculeI.H:549
vector position() const
Return current particle position.
Definition: particleI.H:278
Namespace for OpenFOAM.
const List< scalar > & siteCharges() const
Definition: moleculeI.H:380
const vector & specialPosition() const
Definition: moleculeI.H:585
const vector & v() const
Definition: moleculeI.H:513