Added measurement of surface values of velocity and temperature to allow slip
[OpenFOAM-1.6.x.git] / src / lagrangian / dsmc / clouds / Templates / DsmcCloud / DsmcCloud.H
blob2a9088d5b276dc4357ce44879caaca998aed3bcd
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2009-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::DsmcCloud
28 Description
29     Templated base class for dsmc cloud
31 SourceFiles
32     DsmcCloudI.H
33     DsmcCloud.C
35 \*---------------------------------------------------------------------------*/
37 #ifndef DsmcCloud_H
38 #define DsmcCloud_H
40 #include "Cloud.H"
41 #include "DsmcBaseCloud.H"
42 #include "IOdictionary.H"
43 #include "autoPtr.H"
44 #include "Random.H"
45 #include "fvMesh.H"
46 #include "volFields.H"
47 #include "scalarIOField.H"
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 namespace Foam
54 // Forward declaration of classes
56 template<class CloudType>
57 class BinaryCollisionModel;
59 template<class CloudType>
60 class WallInteractionModel;
62 template<class CloudType>
63 class InflowBoundaryModel;
65 /*---------------------------------------------------------------------------*\
66                          Class DsmcCloud Declaration
67 \*---------------------------------------------------------------------------*/
69 template<class ParcelType>
70 class DsmcCloud
72     public Cloud<ParcelType>,
73     public DsmcBaseCloud
75     // Private data
77         //- Cloud type - used to set the name of the parcel properties
78         //  dictionary by appending "Properties"
79         const word cloudName_;
81         //- References to the mesh and time databases
82         const fvMesh& mesh_;
84         //- Dictionary of particle properties
85         IOdictionary particleProperties_;
87         //- A list of unique instances of molecule types in the simulation.
88         // The position of an entry in the list maps to the label identifying
89         // the typeId, i.e. where typeIdList_ = (N2 O2 CO2)
90         // N2 has typeId label = 0, O2 = 1, CO2 = 2.
91         List<word> typeIdList_;
93         //- Number of real atoms/molecules represented by a parcel
94         scalar nParticle_;
96         //- A data structure holding which particles are in which cell
97         List<DynamicList<ParcelType*> > cellOccupancy_;
99         //- An IOField holding the value of (sigmaT * cR)max for each cell (see
100         // Bird p220). Initialised with the parcels, updated as required, and
101         // read in on start/restart.
102         volScalarField sigmaTcRMax_;
104         //- A field holding the remainder from the previous collision selections
105         scalarField collisionSelectionRemainder_;
107         //- Heat flux at surface field
108         volScalarField q_;
110         //- Force density at surface field
111         volVectorField fD_;
113         //- number density field
114         volScalarField rhoN_;
116         //- Mass density field
117         volScalarField rhoM_;
119         //- dsmc particle density field
120         volScalarField dsmcRhoN_;
122         //- linear kinetic energy density field
123         volScalarField linearKE_;
125         //- Internal energy density field
126         volScalarField internalE_;
128         // Internal degree of freedom density field
129         volScalarField iDof_;
131         //- Momentum density field
132         volVectorField momentum_;
134         //- Parcel constant properties - one for each type
135         List<typename ParcelType::constantProperties> constProps_;
137         //- Random number generator
138         Random rndGen_;
141         // boundary value fields
143             //- boundary temperature
144             volScalarField boundaryT_;
146             //- boundary velocity
147             volVectorField boundaryU_;
150         // References to the cloud sub-models
152             //- Binary collision model
153             autoPtr<BinaryCollisionModel<DsmcCloud<ParcelType> > >
154                 binaryCollisionModel_;
156             //- Wall interaction model
157             autoPtr<WallInteractionModel<DsmcCloud<ParcelType> > >
158                 wallInteractionModel_;
160             //- Inflow boundary model
161             autoPtr<InflowBoundaryModel<DsmcCloud<ParcelType> > >
162                 inflowBoundaryModel_;
165     // Private Member Functions
167         //- Build the constant properties for all of the species
168         void buildConstProps();
170         //- Record which particles are in which cell
171         void buildCellOccupancy();
173         //- Initialise the system
174         void initialise(const IOdictionary& dsmcInitialiseDict);
176         //- Calculate collisions between molecules
177         void collisions();
179         //- Reset the data accumulation field values to zero
180         void resetFields();
182         //- Calculate the volume field data
183         void calculateFields();
185         //- Disallow default bitwise copy construct
186         DsmcCloud(const DsmcCloud&);
188         //- Disallow default bitwise assignment
189         void operator=(const DsmcCloud&);
192 public:
194     // Static data members
196         //- Boltzmann constant
197         static scalar kb;
200     // Constructors
202         //- Construct given name and mesh, will read Parcels and fields from
203         //  file
204         DsmcCloud
205         (
206             const word& cloudName,
207             const fvMesh& mesh,
208             bool readFields = true
209         );
211         //- Construct given name, mesh and initialisation dictionary.
212         DsmcCloud
213         (
214             const word& cloudName,
215             const fvMesh& mesh,
216             const IOdictionary& dsmcInitialiseDict
217         );
220     //- Destructor
221     virtual ~DsmcCloud();
224     // Member Functions
226         // Access
228             // References to the mesh and databases
230                 //- Return the cloud type
231                 inline const word& cloudName() const;
233                 //- Return refernce to the mesh
234                 inline const fvMesh& mesh() const;
237             // References to the dsmc specific data
239                 //- Return particle properties dictionary
240                 inline const IOdictionary& particleProperties() const;
242                 //- Return the idList
243                 inline const List<word>& typeIdList() const;
245                 //- Return the number of real particles represented by one
246                 //  parcel
247                 inline scalar nParticle() const;
249                 //- Return the cell occupancy addressing
250                 inline const List<DynamicList<ParcelType*> >&
251                     cellOccupancy() const;
253                 //- Return the sigmaTcRMax field.  non-const access to allow
254                 // updating.
255                 inline volScalarField& sigmaTcRMax();
257                 //- Return the collision selection remainder field.  non-const
258                 // access to allow updating.
259                 inline scalarField& collisionSelectionRemainder();
261                 //- Return all of the constant properties
262                 inline const List<typename ParcelType::constantProperties>&
263                     constProps() const;
265                 //- Return the constant properties of the given typeId
266                 inline const typename ParcelType::constantProperties&
267                     constProps(label typeId) const;
269                 //- Return refernce to the random object
270                 inline Random& rndGen();
273             // References to the boundary fields for surface data collection
275                 //- Return non-const heat flux boundary field reference
276                 inline volScalarField::GeometricBoundaryField& qBF();
278                 //- Return non-const force density at boundary field reference
279                 inline volVectorField::GeometricBoundaryField& fDBF();
281                 //- Return non-const number density boundary field reference
282                 inline volScalarField::GeometricBoundaryField& rhoNBF();
284                 //- Return non-const mass density boundary field reference
285                 inline volScalarField::GeometricBoundaryField& rhoMBF();
287                 //- Return non-const linear kinetic energy density boundary
288                 //  field reference
289                 inline volScalarField::GeometricBoundaryField& linearKEBF();
291                 //- Return non-const internal energy density boundary field
292                 // reference
293                 inline volScalarField::GeometricBoundaryField& internalEBF();
295                 //- Return non-const internal degree of freedom density boundary
296                 //  field reference
297                 inline volScalarField::GeometricBoundaryField& iDofBF();
299                 //- Return non-const momentum density boundary field reference
300                 inline volVectorField::GeometricBoundaryField& momentumBF();
303             // References to the macroscopic fields
305                 //- Return macroscopic temperature
306                 inline const volScalarField& boundaryT() const;
308                 //- Return macroscopic velocity
309                 inline const volVectorField& boundaryU() const;
311                 //- Return heat flux at surface field
312                 inline const volScalarField& q() const;
314                 //- Return force density at surface field
315                 inline const volVectorField& fD() const;
317                 //- Return the real particle number density field
318                 inline const volScalarField& rhoN() const;
320                 //- Return the particle mass density field
321                 inline const volScalarField& rhoM() const;
323                 //- Return the field of number of DSMC particles
324                 inline const volScalarField& dsmcRhoN() const;
326                 //- Return the total linear kinetic energy (translational and
327                 // thermal density field
328                 inline const volScalarField& linearKE() const;
330                 //- Return the internal energy density field
331                 inline const volScalarField& internalE() const;
333                 //- Return the average internal degrees of freedom  field
334                 inline const volScalarField& iDof() const;
336                 //- Return the momentum density field
337                 inline const volVectorField& momentum() const;
340             // Kinetic theory helper functions
342                 //- Generate a random velocity sampled from the Maxwellian speed
343                 // distribution
344                 vector equipartitionLinearVelocity
345                 (
346                     scalar temperature,
347                     scalar mass
348                 );
350                 //- Generate a random internal energy, sampled from the
351                 // equilibrium distribution (Bird eqn 11.22 and 11.23 and
352                 // adapting code from DSMC3.FOR)
353                 scalar equipartitionInternalEnergy
354                 (
355                     scalar temperature,
356                     scalar internalDegreesOfFreedom
357                 );
360                 // From the Maxwellian distribution:
361                 //- Average particle speed
362                 inline scalar maxwellianAverageSpeed
363                 (
364                     scalar temperature,
365                     scalar mass
366                 ) const;
368                 inline scalarField maxwellianAverageSpeed
369                 (
370                     scalarField temperature,
371                     scalar mass
372                 ) const;
374                 //- RMS particle speed
375                 inline scalar maxwellianRMSSpeed
376                 (
377                     scalar temperature,
378                     scalar mass
379                 ) const;
381                 inline scalarField maxwellianRMSSpeed
382                 (
383                     scalarField temperature,
384                     scalar mass
385                 ) const;
387                 //- Most probable speed
388                 inline scalar maxwellianMostProbableSpeed
389                 (
390                     scalar temperature,
391                     scalar mass
392                 ) const;
394                 inline scalarField maxwellianMostProbableSpeed
395                 (
396                     scalarField temperature,
397                     scalar mass
398                 ) const;
401             // Sub-models
403                 //- Return reference to binary elastic collision model
404                 inline const BinaryCollisionModel<DsmcCloud<ParcelType> >&
405                     binaryCollision() const;
407                 //- Return non-const reference to binary elastic collision model
408                 inline BinaryCollisionModel<DsmcCloud<ParcelType> >&
409                     binaryCollision();
411                 //- Return reference to wall interaction model
412                 inline const WallInteractionModel<DsmcCloud<ParcelType> >&
413                     wallInteraction() const;
415                 //- Return non-const reference to wall interaction model
416                 inline WallInteractionModel<DsmcCloud<ParcelType> >&
417                     wallInteraction();
419                 //- Return reference to wall interaction model
420                 inline const InflowBoundaryModel<DsmcCloud<ParcelType> >&
421                     inflowBoundary() const;
423                 //- Return non-const reference to wall interaction model
424                 inline InflowBoundaryModel<DsmcCloud<ParcelType> >&
425                     inflowBoundary();
428         // Check
430             //- Total mass injected
431             inline scalar massInjected() const;
433             //- Total mass in system
434             inline scalar massInSystem() const;
436             //- Total linear momentum of the system
437             inline vector linearMomentumOfSystem() const;
439             //- Total linear kinetic energy in the system
440             inline scalar linearKineticEnergyOfSystem() const;
442             //- Total internal energy in the system
443             inline scalar internalEnergyOfSystem() const;
445             //- Print cloud information
446             void info() const;
448             //- Dump particle positions to .obj file
449             void dumpParticlePositions() const;
454         // Cloud evolution functions
456             //- Add new parcel
457             void addNewParcel
458             (
459                 const vector& position,
460                 const vector& U,
461                 const scalar Ei,
462                 const label cellId,
463                 const label typeId
464             );
466             //- Evolve the cloud (move, collide)
467             void evolve();
469             //- Clear the Cloud
470             inline void clear();
474 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
476 } // End namespace Foam
478 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
480 #include "DsmcCloudI.H"
482 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
484 #ifdef NoRepository
485 #   include "DsmcCloud.C"
486 #endif
488 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
490 #endif
492 // ************************************************************************* //