1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Templated base class for dsmc cloud
34 \*---------------------------------------------------------------------------*/
36 #ifndef DsmcCloudTemplate_H
37 #define DsmcCloudTemplate_H
39 #include "CloudTemplate.H"
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 simulation.
87 // The position of an entry in the list maps to the label identifying
88 // the typeId, i.e. where typeIdList_ = (N2 O2 CO2)
89 // 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 //- An IOField holding the value of (sigmaT * cR)max for each cell (see
99 // Bird p220). Initialised with the parcels, updated as required, and
100 // 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&);
193 // Static data members
195 //- Boltzmann constant
201 //- Construct given name and mesh, will read Parcels and fields from
205 const word& cloudName,
207 bool readFields = true
210 //- Construct given name, mesh and initialisation dictionary.
213 const word& cloudName,
215 const IOdictionary& dsmcInitialiseDict
220 virtual ~DsmcCloud();
227 // References to the mesh and databases
229 //- Return the cloud type
230 inline const word& cloudName() const;
232 //- Return refernce to the mesh
233 inline const fvMesh& mesh() const;
236 // References to the dsmc specific data
238 //- Return particle properties dictionary
239 inline const IOdictionary& particleProperties() const;
241 //- Return the idList
242 inline const List<word>& typeIdList() const;
244 //- Return the number of real particles represented by one
246 inline scalar nParticle() const;
248 //- Return the cell occupancy addressing
249 inline const List<DynamicList<ParcelType*> >&
250 cellOccupancy() const;
252 //- Return the sigmaTcRMax field. non-const access to allow
254 inline volScalarField& sigmaTcRMax();
256 //- Return the collision selection remainder field. non-const
257 // access to allow updating.
258 inline scalarField& collisionSelectionRemainder();
260 //- Return all of the constant properties
261 inline const List<typename ParcelType::constantProperties>&
264 //- Return the constant properties of the given typeId
265 inline const typename ParcelType::constantProperties&
266 constProps(label typeId) const;
268 //- Return refernce to the random object
269 inline Random& rndGen();
272 // References to the boundary fields for surface data collection
274 //- Return non-const heat flux boundary field reference
275 inline volScalarField::GeometricBoundaryField& qBF();
277 //- Return non-const force density at boundary field reference
278 inline volVectorField::GeometricBoundaryField& fDBF();
280 //- Return non-const number density boundary field reference
281 inline volScalarField::GeometricBoundaryField& rhoNBF();
283 //- Return non-const mass density boundary field reference
284 inline volScalarField::GeometricBoundaryField& rhoMBF();
286 //- Return non-const linear kinetic energy density boundary
288 inline volScalarField::GeometricBoundaryField& linearKEBF();
290 //- Return non-const internal energy density boundary field
292 inline volScalarField::GeometricBoundaryField& internalEBF();
294 //- Return non-const internal degree of freedom density boundary
296 inline volScalarField::GeometricBoundaryField& iDofBF();
298 //- Return non-const momentum density boundary field reference
299 inline volVectorField::GeometricBoundaryField& momentumBF();
302 // References to the macroscopic fields
304 //- Return macroscopic temperature
305 inline const volScalarField& boundaryT() const;
307 //- Return macroscopic velocity
308 inline const volVectorField& boundaryU() const;
310 //- Return heat flux at surface field
311 inline const volScalarField& q() const;
313 //- Return force density at surface field
314 inline const volVectorField& fD() const;
316 //- Return the real particle number density field
317 inline const volScalarField& rhoN() const;
319 //- Return the particle mass density field
320 inline const volScalarField& rhoM() const;
322 //- Return the field of number of DSMC particles
323 inline const volScalarField& dsmcRhoN() const;
325 //- Return the total linear kinetic energy (translational and
326 // thermal density field
327 inline const volScalarField& linearKE() const;
329 //- Return the internal energy density field
330 inline const volScalarField& internalE() const;
332 //- Return the average internal degrees of freedom field
333 inline const volScalarField& iDof() const;
335 //- Return the momentum density field
336 inline const volVectorField& momentum() const;
339 // Kinetic theory helper functions
341 //- Generate a random velocity sampled from the Maxwellian speed
343 vector equipartitionLinearVelocity
349 //- Generate a random internal energy, sampled from the
350 // equilibrium distribution (Bird eqn 11.22 and 11.23 and
351 // adapting code from DSMC3.FOR)
352 scalar equipartitionInternalEnergy
355 scalar internalDegreesOfFreedom
359 // From the Maxwellian distribution:
360 //- Average particle speed
361 inline scalar maxwellianAverageSpeed
367 inline scalarField maxwellianAverageSpeed
369 scalarField temperature,
373 //- RMS particle speed
374 inline scalar maxwellianRMSSpeed
380 inline scalarField maxwellianRMSSpeed
382 scalarField temperature,
386 //- Most probable speed
387 inline scalar maxwellianMostProbableSpeed
393 inline scalarField maxwellianMostProbableSpeed
395 scalarField temperature,
402 //- Return reference to binary elastic collision model
403 inline const BinaryCollisionModel<DsmcCloud<ParcelType> >&
404 binaryCollision() const;
406 //- Return non-const reference to binary elastic collision model
407 inline BinaryCollisionModel<DsmcCloud<ParcelType> >&
410 //- Return reference to wall interaction model
411 inline const WallInteractionModel<DsmcCloud<ParcelType> >&
412 wallInteraction() const;
414 //- Return non-const reference to wall interaction model
415 inline WallInteractionModel<DsmcCloud<ParcelType> >&
418 //- Return reference to wall interaction model
419 inline const InflowBoundaryModel<DsmcCloud<ParcelType> >&
420 inflowBoundary() const;
422 //- Return non-const reference to wall interaction model
423 inline InflowBoundaryModel<DsmcCloud<ParcelType> >&
429 //- Total mass injected
430 inline scalar massInjected() const;
432 //- Total mass in system
433 inline scalar massInSystem() const;
435 //- Total linear momentum of the system
436 inline vector linearMomentumOfSystem() const;
438 //- Total linear kinetic energy in the system
439 inline scalar linearKineticEnergyOfSystem() const;
441 //- Total internal energy in the system
442 inline scalar internalEnergyOfSystem() const;
444 //- Print cloud information
447 //- Dump particle positions to .obj file
448 void dumpParticlePositions() const;
453 // Cloud evolution functions
458 const vector& position,
465 //- Evolve the cloud (move, collide)
473 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
475 } // End namespace Foam
477 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
479 #include "DsmcCloudTemplateI.H"
481 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
484 # include "DsmcCloudTemplate.C"
487 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
491 // ************************************************************************* //