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 //- number density field
114 volScalarField rhoN_;
116 //- Mass density field
117 volScalarField rhoM_;
119 //- dsmc particle density field
120 volScalarField dsmcRhoN_;
122 //- linear kinetic energy density field
123 volScalarField linearKE_;
125 //- Internal energy density field
126 volScalarField internalE_;
128 // Internal degree of freedom density field
129 volScalarField iDof_;
131 //- Momentum density field
132 volVectorField momentum_;
134 //- Parcel constant properties - one for each type
135 List<typename ParcelType::constantProperties> constProps_;
137 //- Random number generator
141 // boundary value fields
143 //- boundary temperature
144 volScalarField boundaryT_;
146 //- boundary velocity
147 volVectorField boundaryU_;
150 // References to the cloud sub-models
152 //- Binary collision model
153 autoPtr<BinaryCollisionModel<DsmcCloud<ParcelType> > >
154 binaryCollisionModel_;
156 //- Wall interaction model
157 autoPtr<WallInteractionModel<DsmcCloud<ParcelType> > >
158 wallInteractionModel_;
160 //- Inflow boundary model
161 autoPtr<InflowBoundaryModel<DsmcCloud<ParcelType> > >
162 inflowBoundaryModel_;
165 // Private Member Functions
167 //- Build the constant properties for all of the species
168 void buildConstProps();
170 //- Record which particles are in which cell
171 void buildCellOccupancy();
173 //- Initialise the system
174 void initialise(const IOdictionary& dsmcInitialiseDict);
176 //- Calculate collisions between molecules
179 //- Reset the data accumulation field values to zero
182 //- Calculate the volume field data
183 void calculateFields();
185 //- Disallow default bitwise copy construct
186 DsmcCloud(const DsmcCloud&);
188 //- Disallow default bitwise assignment
189 void operator=(const DsmcCloud&);
194 // Static data members
196 //- Boltzmann constant
202 //- Construct given name and mesh, will read Parcels and fields from
206 const word& cloudName,
208 bool readFields = true
211 //- Construct given name, mesh and initialisation dictionary.
214 const word& cloudName,
216 const IOdictionary& dsmcInitialiseDict
221 virtual ~DsmcCloud();
228 // References to the mesh and databases
230 //- Return the cloud type
231 inline const word& cloudName() const;
233 //- Return refernce to the mesh
234 inline const fvMesh& mesh() const;
237 // References to the dsmc specific data
239 //- Return particle properties dictionary
240 inline const IOdictionary& particleProperties() const;
242 //- Return the idList
243 inline const List<word>& typeIdList() const;
245 //- Return the number of real particles represented by one
247 inline scalar nParticle() const;
249 //- Return the cell occupancy addressing
250 inline const List<DynamicList<ParcelType*> >&
251 cellOccupancy() const;
253 //- Return the sigmaTcRMax field. non-const access to allow
255 inline volScalarField& sigmaTcRMax();
257 //- Return the collision selection remainder field. non-const
258 // access to allow updating.
259 inline scalarField& collisionSelectionRemainder();
261 //- Return all of the constant properties
262 inline const List<typename ParcelType::constantProperties>&
265 //- Return the constant properties of the given typeId
266 inline const typename ParcelType::constantProperties&
267 constProps(label typeId) const;
269 //- Return refernce to the random object
270 inline Random& rndGen();
273 // References to the boundary fields for surface data collection
275 //- Return non-const heat flux boundary field reference
276 inline volScalarField::GeometricBoundaryField& qBF();
278 //- Return non-const force density at boundary field reference
279 inline volVectorField::GeometricBoundaryField& fDBF();
281 //- Return non-const number density boundary field reference
282 inline volScalarField::GeometricBoundaryField& rhoNBF();
284 //- Return non-const mass density boundary field reference
285 inline volScalarField::GeometricBoundaryField& rhoMBF();
287 //- Return non-const linear kinetic energy density boundary
289 inline volScalarField::GeometricBoundaryField& linearKEBF();
291 //- Return non-const internal energy density boundary field
293 inline volScalarField::GeometricBoundaryField& internalEBF();
295 //- Return non-const internal degree of freedom density boundary
297 inline volScalarField::GeometricBoundaryField& iDofBF();
299 //- Return non-const momentum density boundary field reference
300 inline volVectorField::GeometricBoundaryField& momentumBF();
303 // References to the macroscopic fields
305 //- Return macroscopic temperature
306 inline const volScalarField& boundaryT() const;
308 //- Return macroscopic velocity
309 inline const volVectorField& boundaryU() const;
311 //- Return heat flux at surface field
312 inline const volScalarField& q() const;
314 //- Return force density at surface field
315 inline const volVectorField& fD() const;
317 //- Return the real particle number density field
318 inline const volScalarField& rhoN() const;
320 //- Return the particle mass density field
321 inline const volScalarField& rhoM() const;
323 //- Return the field of number of DSMC particles
324 inline const volScalarField& dsmcRhoN() const;
326 //- Return the total linear kinetic energy (translational and
327 // thermal density field
328 inline const volScalarField& linearKE() const;
330 //- Return the internal energy density field
331 inline const volScalarField& internalE() const;
333 //- Return the average internal degrees of freedom field
334 inline const volScalarField& iDof() const;
336 //- Return the momentum density field
337 inline const volVectorField& momentum() const;
340 // Kinetic theory helper functions
342 //- Generate a random velocity sampled from the Maxwellian speed
344 vector equipartitionLinearVelocity
350 //- Generate a random internal energy, sampled from the
351 // equilibrium distribution (Bird eqn 11.22 and 11.23 and
352 // adapting code from DSMC3.FOR)
353 scalar equipartitionInternalEnergy
356 scalar internalDegreesOfFreedom
360 // From the Maxwellian distribution:
361 //- Average particle speed
362 inline scalar maxwellianAverageSpeed
368 inline scalarField maxwellianAverageSpeed
370 scalarField temperature,
374 //- RMS particle speed
375 inline scalar maxwellianRMSSpeed
381 inline scalarField maxwellianRMSSpeed
383 scalarField temperature,
387 //- Most probable speed
388 inline scalar maxwellianMostProbableSpeed
394 inline scalarField maxwellianMostProbableSpeed
396 scalarField temperature,
403 //- Return reference to binary elastic collision model
404 inline const BinaryCollisionModel<DsmcCloud<ParcelType> >&
405 binaryCollision() const;
407 //- Return non-const reference to binary elastic collision model
408 inline BinaryCollisionModel<DsmcCloud<ParcelType> >&
411 //- Return reference to wall interaction model
412 inline const WallInteractionModel<DsmcCloud<ParcelType> >&
413 wallInteraction() const;
415 //- Return non-const reference to wall interaction model
416 inline WallInteractionModel<DsmcCloud<ParcelType> >&
419 //- Return reference to wall interaction model
420 inline const InflowBoundaryModel<DsmcCloud<ParcelType> >&
421 inflowBoundary() const;
423 //- Return non-const reference to wall interaction model
424 inline InflowBoundaryModel<DsmcCloud<ParcelType> >&
430 //- Total mass injected
431 inline scalar massInjected() const;
433 //- Total mass in system
434 inline scalar massInSystem() const;
436 //- Total linear momentum of the system
437 inline vector linearMomentumOfSystem() const;
439 //- Total linear kinetic energy in the system
440 inline scalar linearKineticEnergyOfSystem() const;
442 //- Total internal energy in the system
443 inline scalar internalEnergyOfSystem() const;
445 //- Print cloud information
448 //- Dump particle positions to .obj file
449 void dumpParticlePositions() const;
454 // Cloud evolution functions
459 const vector& position,
466 //- Evolve the cloud (move, collide)
474 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
476 } // End namespace Foam
478 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
480 #include "DsmcCloudI.H"
482 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
485 # include "DsmcCloud.C"
488 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
492 // ************************************************************************* //