1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
29 Templated base class for dsmc cloud
35 \*---------------------------------------------------------------------------*/
41 #include "DsmcBaseCloud.H"
42 #include "IOdictionary.H"
46 #include "volFields.H"
47 #include "scalarIOField.H"
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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>
72 public Cloud<ParcelType>,
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
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
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
110 //- Force density at surface field
113 //- Parcel constant properties - one for each type
114 List<typename ParcelType::constantProperties> constProps_;
116 //- Random number generator
119 //- In-cloud cache of deltaT, lookup in submodels and parcel is
121 scalar cachedDeltaT_;
124 // References to the macroscopic fields
127 const volScalarField& T_;
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
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&);
174 // Static data members
176 //- Boltzmann constant
182 //- Construct given name and mesh, will read Parcels from file
185 const word& cloudName,
186 const volScalarField& T,
187 const volVectorField& U
190 //- Construct given name and mesh. Used to initialise.
193 const word& cloudName,
199 virtual ~DsmcCloud();
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
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
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>&
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
285 vector equipartitionLinearVelocity
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
297 scalar internalDegreesOfFreedom
301 // From the Maxwellian distribution:
302 //- Average particle speed
303 inline scalar maxwellianAverageSpeed
309 inline scalarField maxwellianAverageSpeed
311 scalarField temperature,
315 //- RMS particle speed
316 inline scalar maxwellianRMSSpeed
322 inline scalarField maxwellianRMSSpeed
324 scalarField temperature,
328 //- Most probable speed
329 inline scalar maxwellianMostProbableSpeed
335 inline scalarField maxwellianMostProbableSpeed
337 scalarField temperature,
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> >&
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> >&
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> >&
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
388 //- Dump particle positions to .obj file
389 void dumpParticlePositions() const;
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
422 const vector& position,
429 //- Evolve the cloud (move, collide)
440 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
442 } // End namespace Foam
444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
446 #include "DsmcCloudI.H"
448 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
451 # include "DsmcCloud.C"
454 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
458 // ************************************************************************* //