OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

DsmcCloud.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 2009-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::DsmcCloud
00027 
00028 Description
00029     Templated base class for dsmc cloud
00030 
00031 SourceFiles
00032     DsmcCloudI.H
00033     DsmcCloud.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef DsmcCloud_H
00038 #define DsmcCloud_H
00039 
00040 #include "Cloud.H"
00041 #include "DsmcBaseCloud.H"
00042 #include "IOdictionary.H"
00043 #include "autoPtr.H"
00044 #include "Random.H"
00045 #include "fvMesh.H"
00046 #include "volFields.H"
00047 #include "scalarIOField.H"
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 namespace Foam
00052 {
00053 
00054 // Forward declaration of classes
00055 
00056 template<class CloudType>
00057 class BinaryCollisionModel;
00058 
00059 template<class CloudType>
00060 class WallInteractionModel;
00061 
00062 template<class CloudType>
00063 class InflowBoundaryModel;
00064 
00065 /*---------------------------------------------------------------------------*\
00066                          Class DsmcCloud Declaration
00067 \*---------------------------------------------------------------------------*/
00068 
00069 template<class ParcelType>
00070 class DsmcCloud
00071 :
00072     public Cloud<ParcelType>,
00073     public DsmcBaseCloud
00074 {
00075     // Private data
00076 
00077         //- Cloud type - used to set the name of the parcel properties
00078         //  dictionary by appending "Properties"
00079         const word cloudName_;
00080 
00081         //- References to the mesh and time databases
00082         const fvMesh& mesh_;
00083 
00084         //- Dictionary of particle properties
00085         IOdictionary particleProperties_;
00086 
00087         //- A list of unique instances of molecule types in the simulation.
00088         // The position of an entry in the list maps to the label identifying
00089         // the typeId, i.e. where typeIdList_ = (N2 O2 CO2)
00090         // N2 has typeId label = 0, O2 = 1, CO2 = 2.
00091         List<word> typeIdList_;
00092 
00093         //- Number of real atoms/molecules represented by a parcel
00094         scalar nParticle_;
00095 
00096         //- A data structure holding which particles are in which cell
00097         List<DynamicList<ParcelType*> > cellOccupancy_;
00098 
00099         //- An IOField holding the value of (sigmaT * cR)max for each cell (see
00100         // Bird p220). Initialised with the parcels, updated as required, and
00101         // read in on start/restart.
00102         volScalarField sigmaTcRMax_;
00103 
00104         //- A field holding the remainder from the previous collision selections
00105         scalarField collisionSelectionRemainder_;
00106 
00107         //- Heat flux at surface field
00108         volScalarField q_;
00109 
00110         //- Force density at surface field
00111         volVectorField fD_;
00112 
00113         //- Parcel constant properties - one for each type
00114         List<typename ParcelType::constantProperties> constProps_;
00115 
00116         //- Random number generator
00117         Random rndGen_;
00118 
00119         //- In-cloud cache of deltaT, lookup in submodels and parcel is
00120         //  expensive
00121         scalar cachedDeltaT_;
00122 
00123 
00124         // References to the macroscopic fields
00125 
00126             //- Temperature
00127             const volScalarField& T_;
00128 
00129             //- Velocity
00130             const volVectorField& U_;
00131 
00132 
00133         // References to the cloud sub-models
00134 
00135             //- Binary collision model
00136             autoPtr<BinaryCollisionModel<DsmcCloud<ParcelType> > >
00137                 binaryCollisionModel_;
00138 
00139             //- Wall interaction model
00140             autoPtr<WallInteractionModel<DsmcCloud<ParcelType> > >
00141                 wallInteractionModel_;
00142 
00143             //- Inflow boundary model
00144             autoPtr<InflowBoundaryModel<DsmcCloud<ParcelType> > >
00145                 inflowBoundaryModel_;
00146 
00147 
00148     // Private Member Functions
00149 
00150         //- Build the constant properties for all of the species
00151         void buildConstProps();
00152 
00153         //- Record which particles are in which cell
00154         void buildCellOccupancy();
00155 
00156         //- Initialise the system
00157         void initialise(const IOdictionary& dsmcInitialiseDict);
00158 
00159         //- Calculate collisions between molecules
00160         void collisions();
00161 
00162         //- Reset the surface data accumulation field values
00163         void resetSurfaceDataFields();
00164 
00165         //- Disallow default bitwise copy construct
00166         DsmcCloud(const DsmcCloud&);
00167 
00168         //- Disallow default bitwise assignment
00169         void operator=(const DsmcCloud&);
00170 
00171 
00172 public:
00173 
00174     // Static data members
00175 
00176         //- Boltzmann constant
00177         static scalar kb;
00178 
00179 
00180     // Constructors
00181 
00182         //- Construct given name and mesh, will read Parcels from file
00183         DsmcCloud
00184         (
00185             const word& cloudName,
00186             const volScalarField& T,
00187             const volVectorField& U
00188         );
00189 
00190         //- Construct given name and mesh.  Used to initialise.
00191         DsmcCloud
00192         (
00193             const word& cloudName,
00194             const fvMesh& mesh
00195         );
00196 
00197 
00198     //- Destructor
00199     virtual ~DsmcCloud();
00200 
00201 
00202     // Member Functions
00203 
00204         // Access
00205 
00206             // References to the mesh and databases
00207 
00208                 //- Return the cloud type
00209                 inline const word& cloudName() const;
00210 
00211                 //- Return refernce to the mesh
00212                 inline const fvMesh& mesh() const;
00213 
00214 
00215             // References to the dsmc specific data
00216 
00217                 //- Return particle properties dictionary
00218                 inline const IOdictionary& particleProperties() const;
00219 
00220                 //- Return the idList
00221                 inline const List<word>& typeIdList() const;
00222 
00223                 //- Return the number of real particles represented by one
00224                 //  parcel
00225                 inline scalar nParticle() const;
00226 
00227                 //- Return the cell occupancy addressing
00228                 inline const List<DynamicList<ParcelType*> >&
00229                     cellOccupancy() const;
00230 
00231                 //- Return the sigmaTcRMax field.  non-const access to allow
00232                 // updating.
00233                 inline volScalarField& sigmaTcRMax();
00234 
00235                 //- Return the collision selection remainder field.  non-const
00236                 // access to allow updating.
00237                 inline scalarField& collisionSelectionRemainder();
00238 
00239                 //- Return all of the constant properties
00240                 inline const List<typename ParcelType::constantProperties>&
00241                     constProps() const;
00242 
00243                 //- Return the constant properties of the given typeId
00244                 inline const typename ParcelType::constantProperties&
00245                     constProps(label typeId) const;
00246 
00247                 //- Return refernce to the random object
00248                 inline Random& rndGen();
00249 
00250                 //- Store (cache) the current value of deltaT
00251                 inline void storeDeltaT();
00252 
00253                 //- Return the cached value of deltaT
00254                 inline scalar cachedDeltaT() const;
00255 
00256 
00257             // References to the surface data collection fields
00258 
00259                 //- Return heat flux at surface field
00260                 inline const volScalarField& q() const;
00261 
00262                 //- Return non-const heat flux at surface field
00263                 inline volScalarField& q();
00264 
00265                 //- Return force density at surface field
00266                 inline const volVectorField& fD() const;
00267 
00268                 //- Return non-const force density at surface field
00269                 inline volVectorField& fD();
00270 
00271 
00272             // References to the macroscopic fields
00273 
00274                 //- Return macroscopic temperature
00275                 inline const volScalarField& T() const;
00276 
00277                 //- Return macroscopic velocity
00278                 inline const volVectorField& U() const;
00279 
00280 
00281             // Kinetic theory helper functions
00282 
00283                 //- Generate a random velocity sampled from the Maxwellian speed
00284                 // distribution
00285                 vector equipartitionLinearVelocity
00286                 (
00287                     scalar temperature,
00288                     scalar mass
00289                 );
00290 
00291                 //- Generate a random internal energy, sampled from the
00292                 // equilibrium distribution (Bird eqn 11.22 and 11.23 and
00293                 // adapting code from DSMC3.FOR)
00294                 scalar equipartitionInternalEnergy
00295                 (
00296                     scalar temperature,
00297                     scalar internalDegreesOfFreedom
00298                 );
00299 
00300 
00301                 // From the Maxwellian distribution:
00302                 //- Average particle speed
00303                 inline scalar maxwellianAverageSpeed
00304                 (
00305                     scalar temperature,
00306                     scalar mass
00307                 ) const;
00308 
00309                 inline scalarField maxwellianAverageSpeed
00310                 (
00311                     scalarField temperature,
00312                     scalar mass
00313                 ) const;
00314 
00315                 //- RMS particle speed
00316                 inline scalar maxwellianRMSSpeed
00317                 (
00318                     scalar temperature,
00319                     scalar mass
00320                 ) const;
00321 
00322                 inline scalarField maxwellianRMSSpeed
00323                 (
00324                     scalarField temperature,
00325                     scalar mass
00326                 ) const;
00327 
00328                 //- Most probable speed
00329                 inline scalar maxwellianMostProbableSpeed
00330                 (
00331                     scalar temperature,
00332                     scalar mass
00333                 ) const;
00334 
00335                 inline scalarField maxwellianMostProbableSpeed
00336                 (
00337                     scalarField temperature,
00338                     scalar mass
00339                 ) const;
00340 
00341             // Sub-models
00342 
00343                 //- Return reference to binary elastic collision model
00344                 inline const BinaryCollisionModel<DsmcCloud<ParcelType> >&
00345                     binaryCollision() const;
00346 
00347                 //- Return non-const reference to binary elastic collision model
00348                 inline BinaryCollisionModel<DsmcCloud<ParcelType> >&
00349                     binaryCollision();
00350 
00351                 //- Return reference to wall interaction model
00352                 inline const WallInteractionModel<DsmcCloud<ParcelType> >&
00353                     wallInteraction() const;
00354 
00355                 //- Return non-const reference to wall interaction model
00356                 inline WallInteractionModel<DsmcCloud<ParcelType> >&
00357                     wallInteraction();
00358 
00359                 //- Return reference to wall interaction model
00360                 inline const InflowBoundaryModel<DsmcCloud<ParcelType> >&
00361                     inflowBoundary() const;
00362 
00363                 //- Return non-const reference to wall interaction model
00364                 inline InflowBoundaryModel<DsmcCloud<ParcelType> >&
00365                     inflowBoundary();
00366 
00367 
00368         // Check
00369 
00370             //- Total mass injected
00371             inline scalar massInjected() const;
00372 
00373             //- Total mass in system
00374             inline scalar massInSystem() const;
00375 
00376             //- Total linear momentum of the system
00377             inline vector linearMomentumOfSystem() const;
00378 
00379             //- Total linear kinetic energy in the system
00380             inline scalar linearKineticEnergyOfSystem() const;
00381 
00382             //- Total internal energy in the system
00383             inline scalar internalEnergyOfSystem() const;
00384 
00385             //- Print cloud information
00386             void info() const;
00387 
00388             //- Dump particle positions to .obj file
00389             void dumpParticlePositions() const;
00390 
00391 
00392             // Fields
00393 
00394                 //- Return the real particle number density field
00395                 inline const tmp<volScalarField> rhoN() const;
00396 
00397                 //- Return the particle mass density field
00398                 inline const tmp<volScalarField> rhoM() const;
00399 
00400                 //- Return the field of number of DSMC particles
00401                 inline const tmp<volScalarField> dsmcRhoN() const;
00402 
00403                 //- Return the momentum density field
00404                 inline const tmp<volVectorField> momentum() const;
00405 
00406                 //- Return the total linear kinetic energy (translational and
00407                 // thermal density field
00408                 inline const tmp<volScalarField> linearKE() const;
00409 
00410                 //- Return the internal energy density field
00411                 inline const tmp<volScalarField> internalE() const;
00412 
00413                 //- Return the average internal degrees of freedom  field
00414                 inline const tmp<volScalarField> iDof() const;
00415 
00416 
00417         // Cloud evolution functions
00418 
00419             //- Add new parcel
00420             void addNewParcel
00421             (
00422                 const vector& position,
00423                 const vector& U,
00424                 const scalar Ei,
00425                 const label cellId,
00426                 const label typeId
00427             );
00428 
00429             //- Evolve the cloud (move, collide)
00430             void evolve();
00431 
00432 
00433             //- Clear the Cloud
00434             inline void clear();
00435 
00436 
00437 };
00438 
00439 
00440 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00441 
00442 } // End namespace Foam
00443 
00444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00445 
00446 #include "DsmcCloudI.H"
00447 
00448 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00449 
00450 #ifdef NoRepository
00451 #   include "DsmcCloud.C"
00452 #endif
00453 
00454 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00455 
00456 #endif
00457 
00458 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd