SizeDistribution.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "SizeDistribution.H"
27 #include "OSspecific.H"
28 #include "setWriter.H"
29 
30 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
31 
32 template<class CloudType>
34 {
35  const scalar d0 = this->owner().Dmin(), d1 = this->owner().Dmax();
36 
37  // Quit if there is no distribution of diameters
38  if (d1 == d0) return;
39 
40  // The x-axis is linearly spaced between the limiting diameters
41  scalarField ds(nPoints_);
42  forAll(ds, i)
43  {
44  const scalar f = scalar(i)/(nPoints_ - 1);
45  ds[i] = (1 - f)*d0 + f*d1;
46  }
47 
48  // Calculate the distribution
49  scalarField particlePDF(nPoints_, 0), parcelPDF(nPoints_, 0);
50  forAllConstIter(typename CloudType, this->owner(), iter)
51  {
52  const scalar nParticle = iter().nParticle();
53  const scalar d = iter().d();
54 
55  const scalar f = (d - d0)/(d1 - d0);
56  const label i = min(floor(f*(nPoints_ - 1)), nPoints_ - 2);
57  const scalar g = f*(nPoints_ - 1) - scalar(i);
58 
59  particlePDF[i] += nParticle*(1 - g);
60  particlePDF[i + 1] += nParticle*g;
61 
62  parcelPDF[i] += 1 - g;
63  parcelPDF[i + 1] += g;
64  }
65 
66  Pstream::listCombineGather(particlePDF, plusEqOp<scalar>());
67  Pstream::listCombineScatter(particlePDF);
68 
69  Pstream::listCombineGather(parcelPDF, plusEqOp<scalar>());
70  Pstream::listCombineScatter(parcelPDF);
71 
72  particlePDF.first() *= 2;
73  particlePDF.last() *= 2;
74  particlePDF /= sum(particlePDF)*(d1 - d0)/(nPoints_ - 1);
75 
76  parcelPDF.first() *= 2;
77  parcelPDF.last() *= 2;
78  parcelPDF /= sum(parcelPDF)*(d1 - d0)/(nPoints_ - 1);
79 
80  // Write
81  if (Pstream::master())
82  {
83  mkDir(this->writeTimeDir());
84 
85  formatter_->write
86  (
87  this->writeTimeDir(),
88  "distribution",
89  coordSet(true, "d", ds),
90  "particle-PDF",
91  particlePDF,
92  "parcel-PDF",
93  parcelPDF
94  );
95  }
96 }
97 
98 
99 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 
101 template<class CloudType>
103 (
104  const dictionary& dict,
105  CloudType& owner,
106  const word& modelName
107 )
108 :
109  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
110  nPoints_(dict.lookup<label>("nPoints")),
111  formatter_(setWriter::New(dict.lookup("setFormat"), dict))
112 {}
113 
114 
115 template<class CloudType>
117 (
119 )
120 :
122  nPoints_(vf.nPoints_),
123  formatter_(vf.formatter_, false)
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
128 
129 template<class CloudType>
131 {}
132 
133 
134 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Templated cloud function object base class.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:80
Creates graphs of a cloud's size distribution.
virtual ~SizeDistribution()
Destructor.
virtual void write()
Write post-processing info.
SizeDistribution(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
T & first()
Return the first element of the list.
Definition: UListI.H:114
T & last()
Return the last element of the list.
Definition: UListI.H:128
Holds list of sampling positions.
Definition: coordSet.H:51
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Base class for writing coordinate sets with data.
Definition: setWriter.H:64
A class for handling words, derived from string.
Definition: word.H:62
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
labelList f(nPoints)
dictionary dict
mkDir(pdfPath)