1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 Templated base class for dsmc cloud
34 \*---------------------------------------------------------------------------*/
40 #include "DsmcBaseCloud.H"
41 #include "IOdictionary.H"
45 #include "volFields.H"
46 #include "scalarIOField.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 // Forward declaration of classes
55 template<class CloudType>
56 class BinaryCollisionModel;
58 template<class CloudType>
59 class WallInteractionModel;
61 template<class CloudType>
62 class InflowBoundaryModel;
64 /*---------------------------------------------------------------------------*\
65 Class DsmcCloud Declaration
66 \*---------------------------------------------------------------------------*/
68 template<class ParcelType>
71 public Cloud<ParcelType>,
76 //- Cloud type - used to set the name of the parcel properties
77 // dictionary by appending "Properties"
78 const word cloudName_;
80 //- References to the mesh and time databases
83 //- Dictionary of particle properties
84 IOdictionary particleProperties_;
86 //- A list of unique instances of molecule types in the
87 // simulation. The position of an entry in the list maps to
88 // the label identifying the typeId, i.e. where typeIdList_ =
89 // (N2 O2 CO2) N2 has typeId label = 0, O2 = 1, CO2 = 2.
90 List<word> typeIdList_;
92 //- Number of real atoms/molecules represented by a parcel
95 //- A data structure holding which particles are in which cell
96 List<DynamicList<ParcelType*> > cellOccupancy_;
98 //- A field holding the value of (sigmaT * cR)max for each
99 // cell (see Bird p220). Initialised with the parcels,
100 // updated as required, and read in on start/restart.
101 volScalarField sigmaTcRMax_;
103 //- A field holding the remainder from the previous collision selections
104 scalarField collisionSelectionRemainder_;
106 //- Heat flux at surface field
109 //- Force density at surface field
112 //- number density field
113 volScalarField rhoN_;
115 //- Mass density field
116 volScalarField rhoM_;
118 //- dsmc particle density field
119 volScalarField dsmcRhoN_;
121 //- linear kinetic energy density field
122 volScalarField linearKE_;
124 //- Internal energy density field
125 volScalarField internalE_;
127 // Internal degree of freedom density field
128 volScalarField iDof_;
130 //- Momentum density field
131 volVectorField momentum_;
133 //- Parcel constant properties - one for each type
134 List<typename ParcelType::constantProperties> constProps_;
136 //- Random number generator
140 // boundary value fields
142 //- boundary temperature
143 volScalarField boundaryT_;
145 //- boundary velocity
146 volVectorField boundaryU_;
149 // References to the cloud sub-models
151 //- Binary collision model
152 autoPtr<BinaryCollisionModel<DsmcCloud<ParcelType> > >
153 binaryCollisionModel_;
155 //- Wall interaction model
156 autoPtr<WallInteractionModel<DsmcCloud<ParcelType> > >
157 wallInteractionModel_;
159 //- Inflow boundary model
160 autoPtr<InflowBoundaryModel<DsmcCloud<ParcelType> > >
161 inflowBoundaryModel_;
164 // Private Member Functions
166 //- Build the constant properties for all of the species
167 void buildConstProps();
169 //- Record which particles are in which cell
170 void buildCellOccupancy();
172 //- Initialise the system
173 void initialise(const IOdictionary& dsmcInitialiseDict);
175 //- Calculate collisions between molecules
178 //- Reset the data accumulation field values to zero
181 //- Calculate the volume field data
182 void calculateFields();
184 //- Disallow default bitwise copy construct
185 DsmcCloud(const DsmcCloud&);
187 //- Disallow default bitwise assignment
188 void operator=(const DsmcCloud&);
195 //- Construct given name and mesh, will read Parcels and fields from
199 const word& cloudName,
201 bool readFields = true
204 //- Construct given name, mesh and initialisation dictionary.
207 const word& cloudName,
209 const IOdictionary& dsmcInitialiseDict
214 virtual ~DsmcCloud();
217 //- Type of parcel the cloud was instantiated for
218 typedef ParcelType parcelType;
225 // References to the mesh and databases
227 //- Return the cloud type
228 inline const word& cloudName() const;
230 //- Return refernce to the mesh
231 inline const fvMesh& mesh() const;
234 // References to the dsmc specific data
236 //- Return particle properties dictionary
237 inline const IOdictionary& particleProperties() const;
239 //- Return the idList
240 inline const List<word>& typeIdList() const;
242 //- Return the number of real particles represented by one
244 inline scalar nParticle() const;
246 //- Return the cell occupancy addressing
247 inline const List<DynamicList<ParcelType*> >&
248 cellOccupancy() const;
250 //- Return the sigmaTcRMax field. non-const access to allow
252 inline volScalarField& sigmaTcRMax();
254 //- Return the collision selection remainder field. non-const
255 // access to allow updating.
256 inline scalarField& collisionSelectionRemainder();
258 //- Return all of the constant properties
259 inline const List<typename ParcelType::constantProperties>&
262 //- Return the constant properties of the given typeId
263 inline const typename ParcelType::constantProperties&
264 constProps(label typeId) const;
266 //- Return refernce to the random object
267 inline Random& rndGen();
270 // References to the boundary fields for surface data collection
272 //- Return non-const heat flux boundary field reference
273 inline volScalarField::GeometricBoundaryField& qBF();
275 //- Return non-const force density at boundary field reference
276 inline volVectorField::GeometricBoundaryField& fDBF();
278 //- Return non-const number density boundary field reference
279 inline volScalarField::GeometricBoundaryField& rhoNBF();
281 //- Return non-const mass density boundary field reference
282 inline volScalarField::GeometricBoundaryField& rhoMBF();
284 //- Return non-const linear kinetic energy density boundary
286 inline volScalarField::GeometricBoundaryField& linearKEBF();
288 //- Return non-const internal energy density boundary field
290 inline volScalarField::GeometricBoundaryField& internalEBF();
292 //- Return non-const internal degree of freedom density boundary
294 inline volScalarField::GeometricBoundaryField& iDofBF();
296 //- Return non-const momentum density boundary field reference
297 inline volVectorField::GeometricBoundaryField& momentumBF();
300 // References to the macroscopic fields
302 //- Return macroscopic temperature
303 inline const volScalarField& boundaryT() const;
305 //- Return macroscopic velocity
306 inline const volVectorField& boundaryU() const;
308 //- Return heat flux at surface field
309 inline const volScalarField& q() const;
311 //- Return force density at surface field
312 inline const volVectorField& fD() const;
314 //- Return the real particle number density field
315 inline const volScalarField& rhoN() const;
317 //- Return the particle mass density field
318 inline const volScalarField& rhoM() const;
320 //- Return the field of number of DSMC particles
321 inline const volScalarField& dsmcRhoN() const;
323 //- Return the total linear kinetic energy (translational and
324 // thermal density field
325 inline const volScalarField& linearKE() const;
327 //- Return the internal energy density field
328 inline const volScalarField& internalE() const;
330 //- Return the average internal degrees of freedom field
331 inline const volScalarField& iDof() const;
333 //- Return the momentum density field
334 inline const volVectorField& momentum() const;
337 // Kinetic theory helper functions
339 //- Generate a random velocity sampled from the Maxwellian speed
341 vector equipartitionLinearVelocity
347 //- Generate a random internal energy, sampled from the
348 // equilibrium distribution (Bird eqn 11.22 and 11.23 and
349 // adapting code from DSMC3.FOR)
350 scalar equipartitionInternalEnergy
353 scalar internalDegreesOfFreedom
357 // From the Maxwellian distribution:
358 //- Average particle speed
359 inline scalar maxwellianAverageSpeed
365 inline scalarField maxwellianAverageSpeed
367 scalarField temperature,
371 //- RMS particle speed
372 inline scalar maxwellianRMSSpeed
378 inline scalarField maxwellianRMSSpeed
380 scalarField temperature,
384 //- Most probable speed
385 inline scalar maxwellianMostProbableSpeed
391 inline scalarField maxwellianMostProbableSpeed
393 scalarField temperature,
400 //- Return reference to binary elastic collision model
401 inline const BinaryCollisionModel<DsmcCloud<ParcelType> >&
402 binaryCollision() const;
404 //- Return non-const reference to binary elastic collision model
405 inline BinaryCollisionModel<DsmcCloud<ParcelType> >&
408 //- Return reference to wall interaction model
409 inline const WallInteractionModel<DsmcCloud<ParcelType> >&
410 wallInteraction() const;
412 //- Return non-const reference to wall interaction model
413 inline WallInteractionModel<DsmcCloud<ParcelType> >&
416 //- Return reference to wall interaction model
417 inline const InflowBoundaryModel<DsmcCloud<ParcelType> >&
418 inflowBoundary() const;
420 //- Return non-const reference to wall interaction model
421 inline InflowBoundaryModel<DsmcCloud<ParcelType> >&
427 //- Total mass injected
428 inline scalar massInjected() const;
430 //- Total mass in system
431 inline scalar massInSystem() const;
433 //- Total linear momentum of the system
434 inline vector linearMomentumOfSystem() const;
436 //- Total linear kinetic energy in the system
437 inline scalar linearKineticEnergyOfSystem() const;
439 //- Total internal energy in the system
440 inline scalar internalEnergyOfSystem() const;
442 //- Print cloud information
445 //- Dump particle positions to .obj file
446 void dumpParticlePositions() const;
451 // Cloud evolution functions
456 const vector& position,
460 const label tetFaceI,
465 //- Evolve the cloud (move, collide)
473 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
475 } // End namespace Foam
477 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
479 #include "DsmcCloudI.H"
481 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
484 # include "DsmcCloud.C"
487 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
491 // ************************************************************************* //