initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / lagrangian / dsmc / clouds / Templates / DsmcCloud / DsmcCloud.H
blob76b1dd7e79046022dd7869178c84dbc612211abf
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         //- Parcel constant properties - one for each type
114         List<typename ParcelType::constantProperties> constProps_;
116         //- Random number generator
117         Random rndGen_;
119         //- In-cloud cache of deltaT, lookup in submodels and parcel is
120         //  expensive
121         scalar cachedDeltaT_;
124         // References to the macroscopic fields
126             //- Temperature
127             const volScalarField& T_;
129             //- Velocity
130             const volVectorField& U_;
133         // References to the cloud sub-models
135             //- Binary collision model
136             autoPtr<BinaryCollisionModel<DsmcCloud<ParcelType> > >
137                 binaryCollisionModel_;
139             //- Wall interaction model
140             autoPtr<WallInteractionModel<DsmcCloud<ParcelType> > >
141                 wallInteractionModel_;
143             //- Inflow boundary model
144             autoPtr<InflowBoundaryModel<DsmcCloud<ParcelType> > >
145                 inflowBoundaryModel_;
148     // Private Member Functions
150         //- Build the constant properties for all of the species
151         void buildConstProps();
153         //- Record which particles are in which cell
154         void buildCellOccupancy();
156         //- Initialise the system
157         void initialise(const IOdictionary& dsmcInitialiseDict);
159         //- Calculate collisions between molecules
160         void collisions();
162         //- Reset the surface data accumulation field values
163         void resetSurfaceDataFields();
165         //- Disallow default bitwise copy construct
166         DsmcCloud(const DsmcCloud&);
168         //- Disallow default bitwise assignment
169         void operator=(const DsmcCloud&);
172 public:
174     // Static data members
176         //- Boltzmann constant
177         static scalar kb;
180     // Constructors
182         //- Construct given name and mesh, will read Parcels from file
183         DsmcCloud
184         (
185             const word& cloudName,
186             const volScalarField& T,
187             const volVectorField& U
188         );
190         //- Construct given name and mesh.  Used to initialise.
191         DsmcCloud
192         (
193             const word& cloudName,
194             const fvMesh& mesh
195         );
198     //- Destructor
199     virtual ~DsmcCloud();
202     // Member Functions
204         // Access
206             // References to the mesh and databases
208                 //- Return the cloud type
209                 inline const word& cloudName() const;
211                 //- Return refernce to the mesh
212                 inline const fvMesh& mesh() const;
215             // References to the dsmc specific data
217                 //- Return particle properties dictionary
218                 inline const IOdictionary& particleProperties() const;
220                 //- Return the idList
221                 inline const List<word>& typeIdList() const;
223                 //- Return the number of real particles represented by one
224                 //  parcel
225                 inline scalar nParticle() const;
227                 //- Return the cell occupancy addressing
228                 inline const List<DynamicList<ParcelType*> >&
229                     cellOccupancy() const;
231                 //- Return the sigmaTcRMax field.  non-const access to allow
232                 // updating.
233                 inline volScalarField& sigmaTcRMax();
235                 //- Return the collision selection remainder field.  non-const
236                 // access to allow updating.
237                 inline scalarField& collisionSelectionRemainder();
239                 //- Return all of the constant properties
240                 inline const List<typename ParcelType::constantProperties>&
241                     constProps() const;
243                 //- Return the constant properties of the given typeId
244                 inline const typename ParcelType::constantProperties&
245                     constProps(label typeId) const;
247                 //- Return refernce to the random object
248                 inline Random& rndGen();
250                 //- Store (cache) the current value of deltaT
251                 inline void storeDeltaT();
253                 //- Return the cached value of deltaT
254                 inline scalar cachedDeltaT() const;
257             // References to the surface data collection fields
259                 //- Return heat flux at surface field
260                 inline const volScalarField& q() const;
262                 //- Return non-const heat flux at surface field
263                 inline volScalarField& q();
265                 //- Return force density at surface field
266                 inline const volVectorField& fD() const;
268                 //- Return non-const force density at surface field
269                 inline volVectorField& fD();
272             // References to the macroscopic fields
274                 //- Return macroscopic temperature
275                 inline const volScalarField& T() const;
277                 //- Return macroscopic velocity
278                 inline const volVectorField& U() const;
281             // Kinetic theory helper functions
283                 //- Generate a random velocity sampled from the Maxwellian speed
284                 // distribution
285                 vector equipartitionLinearVelocity
286                 (
287                     scalar temperature,
288                     scalar mass
289                 );
291                 //- Generate a random internal energy, sampled from the
292                 // equilibrium distribution (Bird eqn 11.22 and 11.23 and
293                 // adapting code from DSMC3.FOR)
294                 scalar equipartitionInternalEnergy
295                 (
296                     scalar temperature,
297                     scalar internalDegreesOfFreedom
298                 );
301                 // From the Maxwellian distribution:
302                 //- Average particle speed
303                 inline scalar maxwellianAverageSpeed
304                 (
305                     scalar temperature,
306                     scalar mass
307                 ) const;
309                 inline scalarField maxwellianAverageSpeed
310                 (
311                     scalarField temperature,
312                     scalar mass
313                 ) const;
315                 //- RMS particle speed
316                 inline scalar maxwellianRMSSpeed
317                 (
318                     scalar temperature,
319                     scalar mass
320                 ) const;
322                 inline scalarField maxwellianRMSSpeed
323                 (
324                     scalarField temperature,
325                     scalar mass
326                 ) const;
328                 //- Most probable speed
329                 inline scalar maxwellianMostProbableSpeed
330                 (
331                     scalar temperature,
332                     scalar mass
333                 ) const;
335                 inline scalarField maxwellianMostProbableSpeed
336                 (
337                     scalarField temperature,
338                     scalar mass
339                 ) const;
341             // Sub-models
343                 //- Return reference to binary elastic collision model
344                 inline const BinaryCollisionModel<DsmcCloud<ParcelType> >&
345                     binaryCollision() const;
347                 //- Return non-const reference to binary elastic collision model
348                 inline BinaryCollisionModel<DsmcCloud<ParcelType> >&
349                     binaryCollision();
351                 //- Return reference to wall interaction model
352                 inline const WallInteractionModel<DsmcCloud<ParcelType> >&
353                     wallInteraction() const;
355                 //- Return non-const reference to wall interaction model
356                 inline WallInteractionModel<DsmcCloud<ParcelType> >&
357                     wallInteraction();
359                 //- Return reference to wall interaction model
360                 inline const InflowBoundaryModel<DsmcCloud<ParcelType> >&
361                     inflowBoundary() const;
363                 //- Return non-const reference to wall interaction model
364                 inline InflowBoundaryModel<DsmcCloud<ParcelType> >&
365                     inflowBoundary();
368         // Check
370             //- Total mass injected
371             inline scalar massInjected() const;
373             //- Total mass in system
374             inline scalar massInSystem() const;
376             //- Total linear momentum of the system
377             inline vector linearMomentumOfSystem() const;
379             //- Total linear kinetic energy in the system
380             inline scalar linearKineticEnergyOfSystem() const;
382             //- Total internal energy in the system
383             inline scalar internalEnergyOfSystem() const;
385             //- Print cloud information
386             void info() const;
388             //- Dump particle positions to .obj file
389             void dumpParticlePositions() const;
392             // Fields
394                 //- Return the real particle number density field
395                 inline const tmp<volScalarField> rhoN() const;
397                 //- Return the particle mass density field
398                 inline const tmp<volScalarField> rhoM() const;
400                 //- Return the field of number of DSMC particles
401                 inline const tmp<volScalarField> dsmcRhoN() const;
403                 //- Return the momentum density field
404                 inline const tmp<volVectorField> momentum() const;
406                 //- Return the total linear kinetic energy (translational and
407                 // thermal density field
408                 inline const tmp<volScalarField> linearKE() const;
410                 //- Return the internal energy density field
411                 inline const tmp<volScalarField> internalE() const;
413                 //- Return the average internal degrees of freedom  field
414                 inline const tmp<volScalarField> iDof() const;
417         // Cloud evolution functions
419             //- Add new parcel
420             void addNewParcel
421             (
422                 const vector& position,
423                 const vector& U,
424                 const scalar Ei,
425                 const label cellId,
426                 const label typeId
427             );
429             //- Evolve the cloud (move, collide)
430             void evolve();
433             //- Clear the Cloud
434             inline void clear();
440 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
442 } // End namespace Foam
444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
446 #include "DsmcCloudI.H"
448 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
450 #ifdef NoRepository
451 #   include "DsmcCloud.C"
452 #endif
454 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
456 #endif
458 // ************************************************************************* //