FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::DsmcCloud
00026 
00027 Description
00028     Templated base class for dsmc cloud
00029 
00030 SourceFiles
00031     DsmcCloudI.H
00032     DsmcCloud.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef DsmcCloud_H
00037 #define DsmcCloud_H
00038 
00039 #include <lagrangian/Cloud.H>
00040 #include <dsmc/DsmcBaseCloud.H>
00041 #include <OpenFOAM/IOdictionary.H>
00042 #include <OpenFOAM/autoPtr.H>
00043 #include <OpenFOAM/Random.H>
00044 #include <finiteVolume/fvMesh.H>
00045 #include <finiteVolume/volFields.H>
00046 #include <OpenFOAM/scalarIOField.H>
00047 
00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00049 
00050 namespace Foam
00051 {
00052 
00053 // Forward declaration of classes
00054 
00055 template<class CloudType>
00056 class BinaryCollisionModel;
00057 
00058 template<class CloudType>
00059 class WallInteractionModel;
00060 
00061 template<class CloudType>
00062 class InflowBoundaryModel;
00063 
00064 /*---------------------------------------------------------------------------*\
00065                          Class DsmcCloud Declaration
00066 \*---------------------------------------------------------------------------*/
00067 
00068 template<class ParcelType>
00069 class DsmcCloud
00070 :
00071     public Cloud<ParcelType>,
00072     public DsmcBaseCloud
00073 {
00074     // Private data
00075 
00076         //- Cloud type - used to set the name of the parcel properties
00077         //  dictionary by appending "Properties"
00078         const word cloudName_;
00079 
00080         //- References to the mesh and time databases
00081         const fvMesh& mesh_;
00082 
00083         //- Dictionary of particle properties
00084         IOdictionary particleProperties_;
00085 
00086         //- A list of unique instances of molecule types in the simulation.
00087         // The position of an entry in the list maps to the label identifying
00088         // the typeId, i.e. where typeIdList_ = (N2 O2 CO2)
00089         // N2 has typeId label = 0, O2 = 1, CO2 = 2.
00090         List<word> typeIdList_;
00091 
00092         //- Number of real atoms/molecules represented by a parcel
00093         scalar nParticle_;
00094 
00095         //- A data structure holding which particles are in which cell
00096         List<DynamicList<ParcelType*> > cellOccupancy_;
00097 
00098         //- An IOField holding the value of (sigmaT * cR)max for each cell (see
00099         // Bird p220). Initialised with the parcels, updated as required, and
00100         // read in on start/restart.
00101         volScalarField sigmaTcRMax_;
00102 
00103         //- A field holding the remainder from the previous collision selections
00104         scalarField collisionSelectionRemainder_;
00105 
00106         //- Heat flux at surface field
00107         volScalarField q_;
00108 
00109         //- Force density at surface field
00110         volVectorField fD_;
00111 
00112         //- number density field
00113         volScalarField rhoN_;
00114 
00115         //- Mass density field
00116         volScalarField rhoM_;
00117 
00118         //- dsmc particle density field
00119         volScalarField dsmcRhoN_;
00120 
00121         //- linear kinetic energy density field
00122         volScalarField linearKE_;
00123 
00124         //- Internal energy density field
00125         volScalarField internalE_;
00126 
00127         // Internal degree of freedom density field
00128         volScalarField iDof_;
00129 
00130         //- Momentum density field
00131         volVectorField momentum_;
00132 
00133         //- Parcel constant properties - one for each type
00134         List<typename ParcelType::constantProperties> constProps_;
00135 
00136         //- Random number generator
00137         Random rndGen_;
00138 
00139 
00140         // boundary value fields
00141 
00142             //- boundary temperature
00143             volScalarField boundaryT_;
00144 
00145             //- boundary velocity
00146             volVectorField boundaryU_;
00147 
00148 
00149         // References to the cloud sub-models
00150 
00151             //- Binary collision model
00152             autoPtr<BinaryCollisionModel<DsmcCloud<ParcelType> > >
00153                 binaryCollisionModel_;
00154 
00155             //- Wall interaction model
00156             autoPtr<WallInteractionModel<DsmcCloud<ParcelType> > >
00157                 wallInteractionModel_;
00158 
00159             //- Inflow boundary model
00160             autoPtr<InflowBoundaryModel<DsmcCloud<ParcelType> > >
00161                 inflowBoundaryModel_;
00162 
00163 
00164     // Private Member Functions
00165 
00166         //- Build the constant properties for all of the species
00167         void buildConstProps();
00168 
00169         //- Record which particles are in which cell
00170         void buildCellOccupancy();
00171 
00172         //- Initialise the system
00173         void initialise(const IOdictionary& dsmcInitialiseDict);
00174 
00175         //- Calculate collisions between molecules
00176         void collisions();
00177 
00178         //- Reset the data accumulation field values to zero
00179         void resetFields();
00180 
00181         //- Calculate the volume field data
00182         void calculateFields();
00183 
00184         //- Disallow default bitwise copy construct
00185         DsmcCloud(const DsmcCloud&);
00186 
00187         //- Disallow default bitwise assignment
00188         void operator=(const DsmcCloud&);
00189 
00190 
00191 public:
00192 
00193     // Static data members
00194 
00195         //- Boltzmann constant
00196         static scalar kb;
00197 
00198 
00199     // Constructors
00200 
00201         //- Construct given name and mesh, will read Parcels and fields from
00202         //  file
00203         DsmcCloud
00204         (
00205             const word& cloudName,
00206             const fvMesh& mesh,
00207             bool readFields = true
00208         );
00209 
00210         //- Construct given name, mesh and initialisation dictionary.
00211         DsmcCloud
00212         (
00213             const word& cloudName,
00214             const fvMesh& mesh,
00215             const IOdictionary& dsmcInitialiseDict
00216         );
00217 
00218 
00219     //- Destructor
00220     virtual ~DsmcCloud();
00221 
00222 
00223     // Member Functions
00224 
00225         // Access
00226 
00227             // References to the mesh and databases
00228 
00229                 //- Return the cloud type
00230                 inline const word& cloudName() const;
00231 
00232                 //- Return refernce to the mesh
00233                 inline const fvMesh& mesh() const;
00234 
00235 
00236             // References to the dsmc specific data
00237 
00238                 //- Return particle properties dictionary
00239                 inline const IOdictionary& particleProperties() const;
00240 
00241                 //- Return the idList
00242                 inline const List<word>& typeIdList() const;
00243 
00244                 //- Return the number of real particles represented by one
00245                 //  parcel
00246                 inline scalar nParticle() const;
00247 
00248                 //- Return the cell occupancy addressing
00249                 inline const List<DynamicList<ParcelType*> >&
00250                     cellOccupancy() const;
00251 
00252                 //- Return the sigmaTcRMax field.  non-const access to allow
00253                 // updating.
00254                 inline volScalarField& sigmaTcRMax();
00255 
00256                 //- Return the collision selection remainder field.  non-const
00257                 // access to allow updating.
00258                 inline scalarField& collisionSelectionRemainder();
00259 
00260                 //- Return all of the constant properties
00261                 inline const List<typename ParcelType::constantProperties>&
00262                     constProps() const;
00263 
00264                 //- Return the constant properties of the given typeId
00265                 inline const typename ParcelType::constantProperties&
00266                     constProps(label typeId) const;
00267 
00268                 //- Return refernce to the random object
00269                 inline Random& rndGen();
00270 
00271 
00272             // References to the boundary fields for surface data collection
00273 
00274                 //- Return non-const heat flux boundary field reference
00275                 inline volScalarField::GeometricBoundaryField& qBF();
00276 
00277                 //- Return non-const force density at boundary field reference
00278                 inline volVectorField::GeometricBoundaryField& fDBF();
00279 
00280                 //- Return non-const number density boundary field reference
00281                 inline volScalarField::GeometricBoundaryField& rhoNBF();
00282 
00283                 //- Return non-const mass density boundary field reference
00284                 inline volScalarField::GeometricBoundaryField& rhoMBF();
00285 
00286                 //- Return non-const linear kinetic energy density boundary
00287                 //  field reference
00288                 inline volScalarField::GeometricBoundaryField& linearKEBF();
00289 
00290                 //- Return non-const internal energy density boundary field
00291                 // reference
00292                 inline volScalarField::GeometricBoundaryField& internalEBF();
00293 
00294                 //- Return non-const internal degree of freedom density boundary
00295                 //  field reference
00296                 inline volScalarField::GeometricBoundaryField& iDofBF();
00297 
00298                 //- Return non-const momentum density boundary field reference
00299                 inline volVectorField::GeometricBoundaryField& momentumBF();
00300 
00301 
00302             // References to the macroscopic fields
00303 
00304                 //- Return macroscopic temperature
00305                 inline const volScalarField& boundaryT() const;
00306 
00307                 //- Return macroscopic velocity
00308                 inline const volVectorField& boundaryU() const;
00309 
00310                 //- Return heat flux at surface field
00311                 inline const volScalarField& q() const;
00312 
00313                 //- Return force density at surface field
00314                 inline const volVectorField& fD() const;
00315 
00316                 //- Return the real particle number density field
00317                 inline const volScalarField& rhoN() const;
00318 
00319                 //- Return the particle mass density field
00320                 inline const volScalarField& rhoM() const;
00321 
00322                 //- Return the field of number of DSMC particles
00323                 inline const volScalarField& dsmcRhoN() const;
00324 
00325                 //- Return the total linear kinetic energy (translational and
00326                 // thermal density field
00327                 inline const volScalarField& linearKE() const;
00328 
00329                 //- Return the internal energy density field
00330                 inline const volScalarField& internalE() const;
00331 
00332                 //- Return the average internal degrees of freedom  field
00333                 inline const volScalarField& iDof() const;
00334 
00335                 //- Return the momentum density field
00336                 inline const volVectorField& momentum() const;
00337 
00338 
00339             // Kinetic theory helper functions
00340 
00341                 //- Generate a random velocity sampled from the Maxwellian speed
00342                 // distribution
00343                 vector equipartitionLinearVelocity
00344                 (
00345                     scalar temperature,
00346                     scalar mass
00347                 );
00348 
00349                 //- Generate a random internal energy, sampled from the
00350                 // equilibrium distribution (Bird eqn 11.22 and 11.23 and
00351                 // adapting code from DSMC3.FOR)
00352                 scalar equipartitionInternalEnergy
00353                 (
00354                     scalar temperature,
00355                     scalar internalDegreesOfFreedom
00356                 );
00357 
00358 
00359                 // From the Maxwellian distribution:
00360                 //- Average particle speed
00361                 inline scalar maxwellianAverageSpeed
00362                 (
00363                     scalar temperature,
00364                     scalar mass
00365                 ) const;
00366 
00367                 inline scalarField maxwellianAverageSpeed
00368                 (
00369                     scalarField temperature,
00370                     scalar mass
00371                 ) const;
00372 
00373                 //- RMS particle speed
00374                 inline scalar maxwellianRMSSpeed
00375                 (
00376                     scalar temperature,
00377                     scalar mass
00378                 ) const;
00379 
00380                 inline scalarField maxwellianRMSSpeed
00381                 (
00382                     scalarField temperature,
00383                     scalar mass
00384                 ) const;
00385 
00386                 //- Most probable speed
00387                 inline scalar maxwellianMostProbableSpeed
00388                 (
00389                     scalar temperature,
00390                     scalar mass
00391                 ) const;
00392 
00393                 inline scalarField maxwellianMostProbableSpeed
00394                 (
00395                     scalarField temperature,
00396                     scalar mass
00397                 ) const;
00398 
00399 
00400             // Sub-models
00401 
00402                 //- Return reference to binary elastic collision model
00403                 inline const BinaryCollisionModel<DsmcCloud<ParcelType> >&
00404                     binaryCollision() const;
00405 
00406                 //- Return non-const reference to binary elastic collision model
00407                 inline BinaryCollisionModel<DsmcCloud<ParcelType> >&
00408                     binaryCollision();
00409 
00410                 //- Return reference to wall interaction model
00411                 inline const WallInteractionModel<DsmcCloud<ParcelType> >&
00412                     wallInteraction() const;
00413 
00414                 //- Return non-const reference to wall interaction model
00415                 inline WallInteractionModel<DsmcCloud<ParcelType> >&
00416                     wallInteraction();
00417 
00418                 //- Return reference to wall interaction model
00419                 inline const InflowBoundaryModel<DsmcCloud<ParcelType> >&
00420                     inflowBoundary() const;
00421 
00422                 //- Return non-const reference to wall interaction model
00423                 inline InflowBoundaryModel<DsmcCloud<ParcelType> >&
00424                     inflowBoundary();
00425 
00426 
00427         // Check
00428 
00429             //- Total mass injected
00430             inline scalar massInjected() const;
00431 
00432             //- Total mass in system
00433             inline scalar massInSystem() const;
00434 
00435             //- Total linear momentum of the system
00436             inline vector linearMomentumOfSystem() const;
00437 
00438             //- Total linear kinetic energy in the system
00439             inline scalar linearKineticEnergyOfSystem() const;
00440 
00441             //- Total internal energy in the system
00442             inline scalar internalEnergyOfSystem() const;
00443 
00444             //- Print cloud information
00445             void info() const;
00446 
00447             //- Dump particle positions to .obj file
00448             void dumpParticlePositions() const;
00449 
00450 
00451 
00452 
00453         // Cloud evolution functions
00454 
00455             //- Add new parcel
00456             void addNewParcel
00457             (
00458                 const vector& position,
00459                 const vector& U,
00460                 const scalar Ei,
00461                 const label cellId,
00462                 const label typeId
00463             );
00464 
00465             //- Evolve the cloud (move, collide)
00466             void evolve();
00467 
00468             //- Clear the Cloud
00469             inline void clear();
00470 };
00471 
00472 
00473 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00474 
00475 } // End namespace Foam
00476 
00477 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00478 
00479 #include "DsmcCloudI_.H"
00480 
00481 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00482 
00483 #ifdef NoRepository
00484 #   include "DsmcCloud_.C"
00485 #endif
00486 
00487 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00488 
00489 #endif
00490 
00491 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines