molecule.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2016 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::molecule
29 
30 Description
31  Foam::molecule
32 
33 SourceFiles
34  moleculeI.H
35  molecule.C
36  moleculeIO.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef molecule_H
41 #define molecule_H
42 
43 #include "particle.H"
44 #include "IOstream.H"
45 #include "autoPtr.H"
46 #include "diagTensor.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Class forward declarations
54 class moleculeCloud;
55 
56 
57 // Forward declaration of friend functions and operators
58 
59 class molecule;
60 
61 Ostream& operator<<(Ostream&, const molecule&);
62 
63 
64 /*---------------------------------------------------------------------------*\
65  Class molecule Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class molecule
69 :
70  public particle
71 {
72 public:
73 
74  //- Size in bytes of the fields
75  static const std::size_t sizeofFields;
76 
77 
78  // Values of special that are less than zero are for built-in functionality.
79  // Values greater than zero are user specifiable/expandable
80  // (i.e. test special_ >= SPECIAL_USER)
81 
83  {
85  SPECIAL_FROZEN = -2,
86  NOT_SPECIAL = 0,
87  SPECIAL_USER = 1
88  };
89 
90 
91  //- Class to hold molecule constant properties
92  class constantProperties
93  {
94  // Private data
95 
96  Field<vector> siteReferencePositions_;
97 
98  List<scalar> siteMasses_;
99 
100  List<scalar> siteCharges_;
101 
102  List<label> siteIds_;
103 
104  List<bool> pairPotentialSites_;
105 
106  List<bool> electrostaticSites_;
107 
108  diagTensor momentOfInertia_;
109 
110  scalar mass_;
111 
112 
113  // Private Member Functions
114 
115  void checkSiteListSizes() const;
116 
117  void setInteracionSiteBools
118  (
119  const List<word>& siteIds,
120  const List<word>& pairPotSiteIds
121  );
122 
123  bool linearMoleculeTest() const;
124 
125 
126  public:
127 
128  inline constantProperties();
129 
130  //- Construct from dictionary
131  inline constantProperties(const dictionary& dict);
132 
133  // Member functions
134 
135  inline const Field<vector>& siteReferencePositions() const;
136 
137  inline const List<scalar>& siteMasses() const;
138 
139  inline const List<scalar>& siteCharges() const;
140 
141  inline const List<label>& siteIds() const;
142 
143  inline List<label>& siteIds();
144 
145  inline const List<bool>& pairPotentialSites() const;
146 
147  inline bool pairPotentialSite(label sId) const;
148 
149  inline const List<bool>& electrostaticSites() const;
150 
151  inline bool electrostaticSite(label sId) const;
152 
153  inline const diagTensor& momentOfInertia() const;
154 
155  inline bool linearMolecule() const;
156 
157  inline bool pointMolecule() const;
158 
159  inline label degreesOfFreedom() const;
160 
161  inline scalar mass() const;
162 
163  inline label nSites() const;
164  };
165 
166 
167  //- Class used to pass tracking data to the trackToFace function
168  class trackingData
169  :
171  {
172  // label specifying which part of the integration algorithm is taking
173  label part_;
174 
175 
176  public:
177 
178  // Constructors
179 
181  :
183  part_(part)
184  {}
185 
186  // Member functions
187 
188  inline label part() const
189  {
190  return part_;
191  }
192  };
193 
194 
195 private:
196 
197  // Private data
198 
199  tensor Q_;
200 
201  vector v_;
202 
203  vector a_;
204 
205  vector pi_;
206 
207  vector tau_;
208 
209  vector specialPosition_;
210 
211  scalar potentialEnergy_;
212 
213  // - r_ij f_ij, stress dyad
214  tensor rf_;
215 
216  label special_;
217 
218  label id_;
219 
220  List<vector> siteForces_;
221 
222  List<vector> sitePositions_;
223 
224 
225  // Private Member Functions
226 
227  tensor rotationTensorX(scalar deltaT) const;
228 
229  tensor rotationTensorY(scalar deltaT) const;
230 
231  tensor rotationTensorZ(scalar deltaT) const;
232 
233 
234 public:
235 
236  friend class Cloud<molecule>;
237 
238  // Constructors
240  //- Construct from components
241  inline molecule
242  (
243  const polyMesh& mesh,
244  const barycentric& coordinates,
245  const label celli,
246  const label tetFacei,
247  const label tetPti,
248  const tensor& Q,
249  const vector& v,
250  const vector& a,
251  const vector& pi,
252  const vector& tau,
253  const vector& specialPosition,
254  const constantProperties& constProps,
255  const label special,
256  const label id
257  );
258 
259  //- Construct from a position and a cell, searching for the rest of the
260  // required topology
261  inline molecule
262  (
263  const polyMesh& mesh,
264  const vector& position,
265  const label celli,
266  const tensor& Q,
267  const vector& v,
268  const vector& a,
269  const vector& pi,
270  const vector& tau,
271  const vector& specialPosition,
272  const constantProperties& constProps,
273  const label special,
274  const label id
275  );
276 
277  //- Construct from Istream
278  molecule
279  (
280  const polyMesh& mesh,
281  Istream& is,
282  bool readFields = true,
283  bool newFormat = true
284  );
285 
286  //- Construct and return a clone
287  autoPtr<particle> clone() const
288  {
289  return autoPtr<particle>(new molecule(*this));
290  }
291 
292  //- Factory class to read-construct particles used for
293  // parallel transfer
294  class iNew
295  {
296  const polyMesh& mesh_;
297 
298  public:
300  iNew(const polyMesh& mesh)
301  :
302  mesh_(mesh)
303  {}
304 
306  {
307  return autoPtr<molecule>::New(mesh_, is, true);
308  }
309  };
310 
311 
312  // Member Functions
313 
314  // Tracking
316  bool move(moleculeCloud&, trackingData&, const scalar trackTime);
317 
318  virtual void transformProperties(const tensor& T);
319 
320  virtual void transformProperties(const vector& separation);
321 
322  void setSitePositions(const constantProperties& constProps);
323 
324  void setSiteSizes(label size);
325 
326 
327  // Access
328 
329  inline const tensor& Q() const;
330  inline tensor& Q();
331 
332  inline const vector& v() const;
333  inline vector& v();
334 
335  inline const vector& a() const;
336  inline vector& a();
337 
338  inline const vector& pi() const;
339  inline vector& pi();
340 
341  inline const vector& tau() const;
342  inline vector& tau();
343 
344  inline const List<vector>& siteForces() const;
345  inline List<vector>& siteForces();
346 
347  inline const List<vector>& sitePositions() const;
348  inline List<vector>& sitePositions();
349 
350  inline const vector& specialPosition() const;
351  inline vector& specialPosition();
352 
353  inline scalar potentialEnergy() const;
354  inline scalar& potentialEnergy();
355 
356  inline const tensor& rf() const;
357  inline tensor& rf();
358 
359  inline label special() const;
360 
361  inline bool tethered() const;
362 
363  inline label id() const;
364 
365 
366  // Member Operators
367 
368  //- Overridable function to handle the particle hitting a patch
369  // Executed before other patch-hitting functions
371 
372  //- Overridable function to handle the particle hitting a processorPatch
374 
375  //- Overridable function to handle the particle hitting a wallPatch
377 
378 
379  // I-O
380 
381  static void readFields(Cloud<molecule>& mC);
382 
383  static void writeFields(const Cloud<molecule>& mC);
384 
385 
386  // IOstream Operators
387 
388  friend Ostream& operator<<(Ostream&, const molecule&);
389 };
390 
391 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
392 
393 } // End namespace Foam
394 
395 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
396 
397 #include "moleculeI.H"
398 
399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
400 
401 #endif
402 
403 // ************************************************************************* //
scalar potentialEnergy() const
Definition: moleculeI.H:598
autoPtr< molecule > operator()(Istream &is) const
Definition: molecule.H:320
const tensor & Q() const
Definition: moleculeI.H:502
dictionary dict
const List< bool > & electrostaticSites() const
Definition: moleculeI.H:427
const List< vector > & sitePositions() const
Definition: moleculeI.H:574
const tensor & rf() const
Definition: moleculeI.H:610
trackingData(moleculeCloud &cloud, label part)
Definition: molecule.H:183
const diagTensor & momentOfInertia() const
Definition: moleculeI.H:452
Class to hold molecule constant properties.
Definition: molecule.H:91
void setSitePositions(const constantProperties &constProps)
Definition: molecule.C:219
iNew(const polyMesh &mesh)
Definition: molecule.H:315
const barycentric & coordinates() const noexcept
Return current particle coordinates.
Definition: particleI.H:116
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const List< vector > & siteForces() const
Definition: moleculeI.H:562
bool hitPatch(moleculeCloud &cloud, trackingData &td)
Overridable function to handle the particle hitting a patch.
Definition: molecule.C:233
label special() const
Definition: moleculeI.H:622
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:388
static const std::size_t sizeofFields
Size in bytes of the fields.
Definition: molecule.H:72
void hitProcessorPatch(moleculeCloud &cloud, trackingData &td)
Overridable function to handle the particle hitting a processorPatch.
Definition: molecule.C:239
bool tethered() const
Definition: moleculeI.H:628
const vector & pi() const
Definition: moleculeI.H:538
static void writeFields(const Cloud< molecule > &mC)
Definition: moleculeIO.C:163
bool move(moleculeCloud &, trackingData &, const scalar trackTime)
Definition: molecule.C:64
static void readFields(Cloud< molecule > &mC)
Definition: moleculeIO.C:104
Base particle class.
Definition: particle.H:69
const Field< vector > & siteReferencePositions() const
Definition: moleculeI.H:367
const vector & a() const
Definition: moleculeI.H:526
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:219
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:53
virtual void transformProperties(const tensor &T)
Transform the physical properties of the particle.
Definition: molecule.C:184
Base cloud calls templated on particle type.
Definition: Cloud.H:51
autoPtr< particle > clone() const
Construct and return a clone.
Definition: molecule.H:299
const List< bool > & pairPotentialSites() const
Definition: moleculeI.H:402
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void hitWallPatch(moleculeCloud &cloud, trackingData &td)
Overridable function to handle the particle hitting a wallPatch.
Definition: molecule.C:245
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
bool electrostaticSite(label sId) const
Definition: moleculeI.H:434
const polyMesh & mesh() const noexcept
Return the mesh database.
Definition: particleI.H:110
Class used to pass tracking data to the trackToFace function.
Definition: molecule.H:171
void setSiteSizes(label size)
Definition: molecule.C:225
Foam::molecule.
Definition: molecule.H:63
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
bool pairPotentialSite(label sId) const
Definition: moleculeI.H:409
label id() const
Definition: moleculeI.H:634
Tensor of scalars, i.e. Tensor<scalar>.
const List< scalar > & siteMasses() const
Definition: moleculeI.H:374
const vector & tau() const
Definition: moleculeI.H:550
vector position() const
Return current particle position.
Definition: particleI.H:283
Namespace for OpenFOAM.
const List< scalar > & siteCharges() const
Definition: moleculeI.H:381
const vector & specialPosition() const
Definition: moleculeI.H:586
const vector & v() const
Definition: moleculeI.H:514