FreeFOAM The Cross-Platform CFD Toolkit
DsmcCloud_.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) 2009-2010 OpenCFD Ltd.
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::DsmcCloud
26 
27 Description
28  Templated base class for dsmc cloud
29 
30 SourceFiles
31  DsmcCloudI.H
32  DsmcCloud.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef DsmcCloud_H
37 #define DsmcCloud_H
38 
39 #include <lagrangian/Cloud.H>
40 #include <dsmc/DsmcBaseCloud.H>
41 #include <OpenFOAM/IOdictionary.H>
42 #include <OpenFOAM/autoPtr.H>
43 #include <OpenFOAM/Random.H>
44 #include <finiteVolume/fvMesh.H>
45 #include <finiteVolume/volFields.H>
46 #include <OpenFOAM/scalarIOField.H>
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward declaration of classes
54 
55 template<class CloudType>
56 class BinaryCollisionModel;
57 
58 template<class CloudType>
59 class WallInteractionModel;
60 
61 template<class CloudType>
62 class InflowBoundaryModel;
63 
64 /*---------------------------------------------------------------------------*\
65  Class DsmcCloud Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 template<class ParcelType>
69 class DsmcCloud
70 :
71  public Cloud<ParcelType>,
72  public DsmcBaseCloud
73 {
74  // Private data
75 
76  //- Cloud type - used to set the name of the parcel properties
77  // dictionary by appending "Properties"
78  const word cloudName_;
79 
80  //- References to the mesh and time databases
81  const fvMesh& mesh_;
82 
83  //- Dictionary of particle properties
84  IOdictionary particleProperties_;
85 
86  //- A list of unique instances of molecule types in the simulation.
87  // The position of an entry in the list maps to the label identifying
88  // the typeId, i.e. where typeIdList_ = (N2 O2 CO2)
89  // N2 has typeId label = 0, O2 = 1, CO2 = 2.
90  List<word> typeIdList_;
91 
92  //- Number of real atoms/molecules represented by a parcel
93  scalar nParticle_;
94 
95  //- A data structure holding which particles are in which cell
96  List<DynamicList<ParcelType*> > cellOccupancy_;
97 
98  //- An IOField holding the value of (sigmaT * cR)max for each cell (see
99  // Bird p220). Initialised with the parcels, updated as required, and
100  // read in on start/restart.
101  volScalarField sigmaTcRMax_;
102 
103  //- A field holding the remainder from the previous collision selections
104  scalarField collisionSelectionRemainder_;
105 
106  //- Heat flux at surface field
107  volScalarField q_;
108 
109  //- Force density at surface field
110  volVectorField fD_;
111 
112  //- number density field
113  volScalarField rhoN_;
114 
115  //- Mass density field
116  volScalarField rhoM_;
117 
118  //- dsmc particle density field
119  volScalarField dsmcRhoN_;
120 
121  //- linear kinetic energy density field
122  volScalarField linearKE_;
123 
124  //- Internal energy density field
125  volScalarField internalE_;
126 
127  // Internal degree of freedom density field
128  volScalarField iDof_;
129 
130  //- Momentum density field
131  volVectorField momentum_;
132 
133  //- Parcel constant properties - one for each type
135 
136  //- Random number generator
137  Random rndGen_;
138 
139 
140  // boundary value fields
141 
142  //- boundary temperature
143  volScalarField boundaryT_;
144 
145  //- boundary velocity
146  volVectorField boundaryU_;
147 
148 
149  // References to the cloud sub-models
150 
151  //- Binary collision model
153  binaryCollisionModel_;
154 
155  //- Wall interaction model
157  wallInteractionModel_;
158 
159  //- Inflow boundary model
161  inflowBoundaryModel_;
162 
163 
164  // Private Member Functions
165 
166  //- Build the constant properties for all of the species
167  void buildConstProps();
168 
169  //- Record which particles are in which cell
170  void buildCellOccupancy();
171 
172  //- Initialise the system
173  void initialise(const IOdictionary& dsmcInitialiseDict);
174 
175  //- Calculate collisions between molecules
176  void collisions();
177 
178  //- Reset the data accumulation field values to zero
179  void resetFields();
180 
181  //- Calculate the volume field data
182  void calculateFields();
183 
184  //- Disallow default bitwise copy construct
185  DsmcCloud(const DsmcCloud&);
186 
187  //- Disallow default bitwise assignment
188  void operator=(const DsmcCloud&);
189 
190 
191 public:
192 
193  // Static data members
194 
195  //- Boltzmann constant
196  static scalar kb;
197 
198 
199  // Constructors
200 
201  //- Construct given name and mesh, will read Parcels and fields from
202  // file
203  DsmcCloud
204  (
205  const word& cloudName,
206  const fvMesh& mesh,
207  bool readFields = true
208  );
209 
210  //- Construct given name, mesh and initialisation dictionary.
211  DsmcCloud
212  (
213  const word& cloudName,
214  const fvMesh& mesh,
215  const IOdictionary& dsmcInitialiseDict
216  );
217 
218 
219  //- Destructor
220  virtual ~DsmcCloud();
221 
222 
223  // Member Functions
224 
225  // Access
226 
227  // References to the mesh and databases
228 
229  //- Return the cloud type
230  inline const word& cloudName() const;
231 
232  //- Return refernce to the mesh
233  inline const fvMesh& mesh() const;
234 
235 
236  // References to the dsmc specific data
237 
238  //- Return particle properties dictionary
239  inline const IOdictionary& particleProperties() const;
240 
241  //- Return the idList
242  inline const List<word>& typeIdList() const;
243 
244  //- Return the number of real particles represented by one
245  // parcel
246  inline scalar nParticle() const;
247 
248  //- Return the cell occupancy addressing
249  inline const List<DynamicList<ParcelType*> >&
250  cellOccupancy() const;
251 
252  //- Return the sigmaTcRMax field. non-const access to allow
253  // updating.
254  inline volScalarField& sigmaTcRMax();
255 
256  //- Return the collision selection remainder field. non-const
257  // access to allow updating.
259 
260  //- Return all of the constant properties
262  constProps() const;
263 
264  //- Return the constant properties of the given typeId
265  inline const typename ParcelType::constantProperties&
266  constProps(label typeId) const;
267 
268  //- Return refernce to the random object
269  inline Random& rndGen();
270 
271 
272  // References to the boundary fields for surface data collection
273 
274  //- Return non-const heat flux boundary field reference
275  inline volScalarField::GeometricBoundaryField& qBF();
276 
277  //- Return non-const force density at boundary field reference
278  inline volVectorField::GeometricBoundaryField& fDBF();
279 
280  //- Return non-const number density boundary field reference
281  inline volScalarField::GeometricBoundaryField& rhoNBF();
282 
283  //- Return non-const mass density boundary field reference
284  inline volScalarField::GeometricBoundaryField& rhoMBF();
285 
286  //- Return non-const linear kinetic energy density boundary
287  // field reference
288  inline volScalarField::GeometricBoundaryField& linearKEBF();
289 
290  //- Return non-const internal energy density boundary field
291  // reference
292  inline volScalarField::GeometricBoundaryField& internalEBF();
293 
294  //- Return non-const internal degree of freedom density boundary
295  // field reference
296  inline volScalarField::GeometricBoundaryField& iDofBF();
297 
298  //- Return non-const momentum density boundary field reference
299  inline volVectorField::GeometricBoundaryField& momentumBF();
300 
301 
302  // References to the macroscopic fields
303 
304  //- Return macroscopic temperature
305  inline const volScalarField& boundaryT() const;
306 
307  //- Return macroscopic velocity
308  inline const volVectorField& boundaryU() const;
309 
310  //- Return heat flux at surface field
311  inline const volScalarField& q() const;
312 
313  //- Return force density at surface field
314  inline const volVectorField& fD() const;
315 
316  //- Return the real particle number density field
317  inline const volScalarField& rhoN() const;
318 
319  //- Return the particle mass density field
320  inline const volScalarField& rhoM() const;
321 
322  //- Return the field of number of DSMC particles
323  inline const volScalarField& dsmcRhoN() const;
324 
325  //- Return the total linear kinetic energy (translational and
326  // thermal density field
327  inline const volScalarField& linearKE() const;
328 
329  //- Return the internal energy density field
330  inline const volScalarField& internalE() const;
331 
332  //- Return the average internal degrees of freedom field
333  inline const volScalarField& iDof() const;
334 
335  //- Return the momentum density field
336  inline const volVectorField& momentum() const;
337 
338 
339  // Kinetic theory helper functions
340 
341  //- Generate a random velocity sampled from the Maxwellian speed
342  // distribution
344  (
345  scalar temperature,
346  scalar mass
347  );
348 
349  //- Generate a random internal energy, sampled from the
350  // equilibrium distribution (Bird eqn 11.22 and 11.23 and
351  // adapting code from DSMC3.FOR)
353  (
354  scalar temperature,
355  scalar internalDegreesOfFreedom
356  );
357 
358 
359  // From the Maxwellian distribution:
360  //- Average particle speed
361  inline scalar maxwellianAverageSpeed
362  (
363  scalar temperature,
364  scalar mass
365  ) const;
366 
368  (
369  scalarField temperature,
370  scalar mass
371  ) const;
372 
373  //- RMS particle speed
374  inline scalar maxwellianRMSSpeed
375  (
376  scalar temperature,
377  scalar mass
378  ) const;
379 
381  (
382  scalarField temperature,
383  scalar mass
384  ) const;
385 
386  //- Most probable speed
387  inline scalar maxwellianMostProbableSpeed
388  (
389  scalar temperature,
390  scalar mass
391  ) const;
392 
394  (
395  scalarField temperature,
396  scalar mass
397  ) const;
398 
399 
400  // Sub-models
401 
402  //- Return reference to binary elastic collision model
404  binaryCollision() const;
405 
406  //- Return non-const reference to binary elastic collision model
408  binaryCollision();
409 
410  //- Return reference to wall interaction model
412  wallInteraction() const;
413 
414  //- Return non-const reference to wall interaction model
416  wallInteraction();
417 
418  //- Return reference to wall interaction model
420  inflowBoundary() const;
421 
422  //- Return non-const reference to wall interaction model
424  inflowBoundary();
425 
426 
427  // Check
428 
429  //- Total mass injected
430  inline scalar massInjected() const;
431 
432  //- Total mass in system
433  inline scalar massInSystem() const;
434 
435  //- Total linear momentum of the system
436  inline vector linearMomentumOfSystem() const;
437 
438  //- Total linear kinetic energy in the system
439  inline scalar linearKineticEnergyOfSystem() const;
440 
441  //- Total internal energy in the system
442  inline scalar internalEnergyOfSystem() const;
443 
444  //- Print cloud information
445  void info() const;
446 
447  //- Dump particle positions to .obj file
448  void dumpParticlePositions() const;
449 
450 
451 
452 
453  // Cloud evolution functions
454 
455  //- Add new parcel
456  void addNewParcel
457  (
458  const vector& position,
459  const vector& U,
460  const scalar Ei,
461  const label cellId,
462  const label typeId
463  );
464 
465  //- Evolve the cloud (move, collide)
466  void evolve();
467 
468  //- Clear the Cloud
469  inline void clear();
470 };
471 
472 
473 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
474 
475 } // End namespace Foam
476 
477 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
478 
479 #include "DsmcCloudI_.H"
480 
481 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
482 
483 #ifdef NoRepository
484 # include "DsmcCloud_.C"
485 #endif
486 
487 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
488 
489 #endif
490 
491 // ************************ vim: set sw=4 sts=4 et: ************************ //