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-2025 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  // Check that there are some parcels
36  const label nParcels =
37  returnReduce(this->owner().nParcels(), sumOp<label>());
38  if (nParcels == 0)
39  {
40  Info<< type() << ": Not writing the distribution as the cloud "
41  << "is empty" << nl << endl;
42  return;
43  }
44 
45  // Check that there is a non-zero range of diameters
46  const scalar d0 = this->owner().Dmin(), d1 = this->owner().Dmax();
47  if (d1 == d0)
48  {
49  Info<< type() << ": Not writing the distribution as the cloud "
50  << "has uniform particle diameters" << nl << endl;
51  return;
52  }
53 
54  // The x-axis is linearly spaced between the limiting diameters
55  scalarField ds(nPoints_);
56  forAll(ds, i)
57  {
58  const scalar f = scalar(i)/(nPoints_ - 1);
59  ds[i] = (1 - f)*d0 + f*d1;
60  }
61 
62  // Calculate the distribution
63  scalarField particlePDF(nPoints_, 0), parcelPDF(nPoints_, 0);
64  forAllConstIter(typename CloudType, this->owner(), iter)
65  {
66  const scalar nParticle = iter().nParticle();
67  const scalar d = iter().d();
68 
69  const scalar f = (d - d0)/(d1 - d0);
70  const label i = min(floor(f*(nPoints_ - 1)), nPoints_ - 2);
71  const scalar g = f*(nPoints_ - 1) - scalar(i);
72 
73  particlePDF[i] += nParticle*(1 - g);
74  particlePDF[i + 1] += nParticle*g;
75 
76  parcelPDF[i] += 1 - g;
77  parcelPDF[i + 1] += g;
78  }
79 
80  Pstream::listCombineGather(particlePDF, plusEqOp<scalar>());
81  Pstream::listCombineScatter(particlePDF);
82 
83  Pstream::listCombineGather(parcelPDF, plusEqOp<scalar>());
84  Pstream::listCombineScatter(parcelPDF);
85 
86  particlePDF.first() *= 2;
87  particlePDF.last() *= 2;
88  particlePDF /= sum(particlePDF)*(d1 - d0)/(nPoints_ - 1);
89 
90  parcelPDF.first() *= 2;
91  parcelPDF.last() *= 2;
92  parcelPDF /= sum(parcelPDF)*(d1 - d0)/(nPoints_ - 1);
93 
94  Info<< type() << ": Writing the distribution to "
95  << this->writeTimeDir().relativePath() << nl << endl;
96 
97  // Write
98  if (Pstream::master())
99  {
100  mkDir(this->writeTimeDir());
101 
102  formatter_->write
103  (
104  this->writeTimeDir(),
105  "distribution",
106  coordSet(true, "d", ds),
107  "particle-PDF",
108  particlePDF,
109  "parcel-PDF",
110  parcelPDF
111  );
112  }
113 }
114 
115 
116 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
117 
118 template<class CloudType>
120 (
121  const dictionary& dict,
122  CloudType& owner,
123  const word& modelName
124 )
125 :
126  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
127  nPoints_(dict.lookup<label>("nPoints")),
128  formatter_(setWriter::New(dict.lookup("setFormat"), dict))
129 {}
130 
131 
132 template<class CloudType>
134 (
136 )
137 :
139  nPoints_(vf.nPoints_),
140  formatter_(vf.formatter_, false)
141 {}
142 
143 
144 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
145 
146 template<class CloudType>
148 {}
149 
150 
151 // ************************************************************************* //
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:433
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:476
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
static const char nl
Definition: Ostream.H:267
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
labelList f(nPoints)
dictionary dict
mkDir(pdfPath)