MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
postProcessBSD.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2016 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 Application
25  postProcessBSD
26 
27 Description
28  This is a post-processing application to analyze the results of population balance equation. It calcualtes the mean and variance of bubble size distribution at each time step and write the results as field variables in each time directory. They can be further processed using "postProcess -func probe" to probe the values on the required points.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 
33 #include "twoPhaseMixtureThermo.H"
34 #include "fvCFD.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
44 {
45 
46 private:
47  volScalarField& M0;
48  volScalarField& M1;
49  volScalarField& M2;
50  const volScalarField& alpha1;
51  const fvMesh& mesh;
52 
53 public:
63  (
64  volScalarField &M0_, volScalarField &M1_,
65  volScalarField &M2_, volScalarField &alpha1_,
66  const fvMesh &mesh_
67  )
68  :
69  M0(M0_),
70  M1(M1_),
71  M2(M2_),
72  alpha1(alpha1_),
73  mesh(mesh_)
74  {}
75 
81  volScalarField meanBSD()
82  {
83  volScalarField alphaCutOff
84  (
85  IOobject
86  (
87  "alphaCutOff",
88  mesh,
89  IOobject::READ_IF_PRESENT,
90  IOobject::NO_WRITE
91  ),
92  mesh,
93  dimensionedScalar("alphaCutOff", dimless, 0.5)
94  );
95  volScalarField insideFoam(pos(alphaCutOff - alpha1));
96  volScalarField mean_
97  (
98  IOobject
99  (
100  "mean_",
101  mesh,
102  IOobject::READ_IF_PRESENT,
103  IOobject::NO_WRITE
104  ),
105  mesh,
106  dimensionedScalar("mean_", dimless, 0.0)
107  );
108  forAll(mesh.C(), celli)
109  {
110  M0 = Foam::max(M0, dimensionedScalar("M0min", M0.dimensions(), SMALL));
111  M1 = Foam::max(M1, dimensionedScalar("M1min", M1.dimensions(), SMALL));
112  M2 = Foam::max(M2, dimensionedScalar("M2min", M2.dimensions(), SMALL));
113  mean_[celli] = scalar(2.0)*Foam::log(M1[celli]/M0[celli]) -
114  scalar(0.5)*Foam::log(M2[celli]/M0[celli]);
115  }
116  return (insideFoam*mean_);
117  }
123  volScalarField varianceBSD()
124  {
125  volScalarField alphaCutOff
126  (
127  IOobject
128  (
129  "alphaCutOff",
130  mesh,
131  IOobject::READ_IF_PRESENT,
132  IOobject::NO_WRITE
133  ),
134  mesh,
135  dimensionedScalar("alphaCutOff", dimless, 0.5)
136  );
137  volScalarField insideFoam(pos(alphaCutOff - alpha1));
138  volScalarField variance_
139  (
140  IOobject
141  (
142  "variance_",
143  mesh,
144  IOobject::READ_IF_PRESENT,
145  IOobject::NO_WRITE
146  ),
147  mesh,
148  dimensionedScalar("variance_", dimless, 0.0)
149  );
150  forAll(mesh.C(), celli)
151  {
152  M0 = Foam::max(M0, dimensionedScalar("M0min", M0.dimensions(), SMALL));
153  M1 = Foam::max(M1, dimensionedScalar("M1min", M1.dimensions(), SMALL));
154  M2 = Foam::max(M2, dimensionedScalar("M2min", M2.dimensions(), SMALL));
155  variance_[celli] =
156  (
157  scalar(2.0)*(
158  scalar(0.5)*Foam::log(M2[celli]/M0[celli])
159  - Foam::log(M1[celli]/M0[celli])
160  )
161  );
162  if (variance_[celli] < 0.0)
163  {
164  variance_[celli] = 0.0;
165  }
166  }
167  return (insideFoam*variance_);
168  }
169 };
170 
186 int main(int argc, char *argv[])
187 {
188  timeSelector::addOptions();
189 
190 # include "setRootCase.H"
191 # include "createTime.H"
192 
193  instantList timeDirs = timeSelector::select0(runTime, args);
194 
195 # include "createMesh.H"
196 
197  forAll(timeDirs, timeI)
198  {
199  runTime.setTime(timeDirs[timeI], timeI);
200 
201  Info<< "Time = " << runTime.timeName() << endl;
202 
203  IOobject M0header
204  (
205  "M0",
206  runTime.timeName(),
207  mesh,
208  IOobject::MUST_READ
209  );
210 
211  IOobject M1header
212  (
213  "M1",
214  runTime.timeName(),
215  mesh,
216  IOobject::MUST_READ
217  );
218 
219  IOobject M2header
220  (
221  "M2",
222  runTime.timeName(),
223  mesh,
224  IOobject::MUST_READ
225  );
226 
227  // Check M0, M1 and M2 exist
228  if
229  (
230  M0header.headerOk()
231  && M1header.headerOk()
232  && M2header.headerOk()
233  )
234  {
235  mesh.readUpdate();
236 
237  Info<< " Reading M0" << endl;
238  volScalarField M0(M0header, mesh);
239 
240  Info<< " Reading M1" << endl;
241  volScalarField M1(M1header, mesh);
242 
243  Info<< " Reading M2" << endl;
244  volScalarField M2(M2header, mesh);
245 
246  Info<< " Calculating BSD properties ... " << endl;
247 
248  twoPhaseMixtureThermo mixture(mesh);
249  volScalarField& alpha1(mixture.alpha1());
250 
251  BSDProperties mu(M0, M1, M2, alpha1, mesh);
252  volScalarField BSDMean
253  (
254  IOobject
255  (
256  "BSDMean",
257  runTime.timeName(),
258  mesh,
259  IOobject::NO_READ,
260  IOobject::AUTO_WRITE
261  ),
262  mu.meanBSD()
263  );
264  // Info<< "BSDMean = " << BSDMean.internalField() << endl;
265  BSDMean.write();
266 
267  BSDProperties sigmaTwo(M0, M1, M2, alpha1, mesh);
268  volScalarField BSDVariance
269  (
270  IOobject
271  (
272  "BSDVariance",
273  runTime.timeName(),
274  mesh,
275  IOobject::NO_READ,
276  IOobject::AUTO_WRITE
277  ),
278  sigmaTwo.varianceBSD()
279  );
280  // Info<< "BSDVariance = " << BSDVariance.internalField() << endl;
281  BSDVariance.write();
282  }
283  else
284  {
285  Info<< " Moments are not available." << endl;
286  }
287 
288  Info<< endl;
289  }
290  Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
291  << " ClockTime = " << runTime.elapsedClockTime() << " s"
292  << nl << endl;
293 
294  Info<< "End\n" << endl;
295 
296  return 0;
297 }
298 
299 
300 // ************************************************************************* //
this class is meant to compute the mean and variance of bubble/cell size distribution.
volScalarField meanBSD()
member function to calculate the mean of bubble size distribution
int main(int argc, char *argv[])
Reads parameters. Creates struts and walls. Saves foam morphology to a file.
Definition: foams.cc:23
BSDProperties(volScalarField &M0_, volScalarField &M1_, volScalarField &M2_, volScalarField &alpha1_, const fvMesh &mesh_)
volScalarField varianceBSD()
member function to compute the variance of bubble size distribution