All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
multiphaseMixture.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) 2011-2022 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 "multiphaseMixture.H"
27 #include "alphaContactAngleFvPatchScalarField.H"
28 #include "correctContactAngle.H"
29 #include "Time.H"
30 #include "subCycle.H"
31 #include "MULES.H"
32 #include "surfaceInterpolate.H"
33 #include "fvcGrad.H"
34 #include "fvcSnGrad.H"
35 #include "fvcDiv.H"
36 #include "fvcFlux.H"
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::multiphaseMixture::calcAlphas()
42 {
43  scalar level = 0.0;
44  alphas_ == 0.0;
45 
46  forAllIter(PtrDictionary<phase>, phases_, iter)
47  {
48  alphas_ += level*iter();
49  level += 1.0;
50  }
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
57 (
58  const volVectorField& U,
59  const surfaceScalarField& phi
60 )
61 :
63  (
64  IOobject
65  (
66  "phaseProperties",
67  U.time().constant(),
68  U.db(),
71  )
72  ),
73 
74  phases_(lookup("phases"), phase::iNew(U, phi)),
75 
76  mesh_(U.mesh()),
77  U_(U),
78  phi_(phi),
79 
80  rhoPhi_
81  (
82  IOobject
83  (
84  "rhoPhi",
85  mesh_.time().timeName(),
86  mesh_,
89  ),
90  mesh_,
92  ),
93 
94  alphas_
95  (
96  IOobject
97  (
98  "alphas",
99  mesh_.time().timeName(),
100  mesh_,
101  IOobject::NO_READ,
103  ),
104  mesh_,
106  ),
107 
108  nu_
109  (
110  IOobject
111  (
112  "nu",
113  mesh_.time().timeName(),
114  mesh_
115  ),
116  mu()/rho()
117  ),
118 
119  sigmas_(lookup("sigmas")),
120  dimSigma_(1, 0, -2, 0, 0),
121  deltaN_
122  (
123  "deltaN",
124  1e-8/pow(average(mesh_.V()), 1.0/3.0)
125  )
126 {
127  calcAlphas();
128  alphas_.write();
129 }
130 
131 
132 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
133 
136 {
137  PtrDictionary<phase>::const_iterator iter = phases_.begin();
138 
139  tmp<volScalarField> trho = iter()*iter().rho();
140  volScalarField& rho = trho.ref();
141 
142  for (++iter; iter != phases_.end(); ++iter)
143  {
144  rho += iter()*iter().rho();
145  }
146 
147  return trho;
148 }
149 
150 
152 Foam::multiphaseMixture::rho(const label patchi) const
153 {
154  PtrDictionary<phase>::const_iterator iter = phases_.begin();
155 
156  tmp<scalarField> trho = iter().boundaryField()[patchi]*iter().rho().value();
157  scalarField& rho = trho.ref();
158 
159  for (++iter; iter != phases_.end(); ++iter)
160  {
161  rho += iter().boundaryField()[patchi]*iter().rho().value();
162  }
163 
164  return trho;
165 }
166 
167 
170 {
171  PtrDictionary<phase>::const_iterator iter = phases_.begin();
172 
173  tmp<volScalarField> tmu = iter()*iter().rho()*iter().nu();
174  volScalarField& mu = tmu.ref();
175 
176  for (++iter; iter != phases_.end(); ++iter)
177  {
178  mu += iter()*iter().rho()*iter().nu();
179  }
180 
181  return tmu;
182 }
183 
184 
186 Foam::multiphaseMixture::mu(const label patchi) const
187 {
188  PtrDictionary<phase>::const_iterator iter = phases_.begin();
189 
190  tmp<scalarField> tmu =
191  iter().boundaryField()[patchi]
192  *iter().rho().value()
193  *iter().nu(patchi);
194  scalarField& mu = tmu.ref();
195 
196  for (++iter; iter != phases_.end(); ++iter)
197  {
198  mu +=
199  iter().boundaryField()[patchi]
200  *iter().rho().value()
201  *iter().nu(patchi);
202  }
203 
204  return tmu;
205 }
206 
207 
210 {
211  PtrDictionary<phase>::const_iterator iter = phases_.begin();
212 
213  tmp<surfaceScalarField> tmuf =
214  fvc::interpolate(iter())*iter().rho()*fvc::interpolate(iter().nu());
215  surfaceScalarField& muf = tmuf.ref();
216 
217  for (++iter; iter != phases_.end(); ++iter)
218  {
219  muf +=
220  fvc::interpolate(iter())*iter().rho()*fvc::interpolate(iter().nu());
221  }
222 
223  return tmuf;
224 }
225 
226 
229 {
230  return nu_;
231 }
232 
233 
235 Foam::multiphaseMixture::nu(const label patchi) const
236 {
237  return nu_.boundaryField()[patchi];
238 }
239 
240 
243 {
244  return muf()/fvc::interpolate(rho());
245 }
246 
247 
250 {
251  tmp<surfaceScalarField> tstf
252  (
254  (
255  "surfaceTensionForce",
256  mesh_,
257  dimensionedScalar(dimensionSet(1, -2, -2, 0, 0), 0)
258  )
259  );
260 
261  surfaceScalarField& stf = tstf.ref();
262 
263  forAllConstIter(PtrDictionary<phase>, phases_, iter1)
264  {
265  const phase& alpha1 = iter1();
266 
268  ++iter2;
269 
270  for (; iter2 != phases_.end(); ++iter2)
271  {
272  const phase& alpha2 = iter2();
273 
275  sigmas_.find(interfacePair(alpha1, alpha2));
276 
277  if (sigma == sigmas_.end())
278  {
280  << "Cannot find interface " << interfacePair(alpha1, alpha2)
281  << " in list of sigma values"
282  << exit(FatalError);
283  }
284 
285  stf += dimensionedScalar(dimSigma_, sigma())
286  *fvc::interpolate(K(alpha1, alpha2))*
287  (
288  fvc::interpolate(alpha2)*fvc::snGrad(alpha1)
289  - fvc::interpolate(alpha1)*fvc::snGrad(alpha2)
290  );
291  }
292  }
293 
294  return tstf;
295 }
296 
297 
299 {
300  correct();
301 
302  const Time& runTime = mesh_.time();
303 
304  volScalarField& alpha = phases_.first();
305 
306  const dictionary& alphaControls = mesh_.solution().solverDict("alpha");
307  label nAlphaSubCycles(alphaControls.lookup<label>("nAlphaSubCycles"));
308  scalar cAlpha(alphaControls.lookup<scalar>("cAlpha"));
309 
310  if (nAlphaSubCycles > 1)
311  {
312  surfaceScalarField rhoPhiSum
313  (
314  IOobject
315  (
316  "rhoPhiSum",
317  runTime.timeName(),
318  mesh_
319  ),
320  mesh_,
321  dimensionedScalar(rhoPhi_.dimensions(), 0)
322  );
323 
324  dimensionedScalar totalDeltaT = runTime.deltaT();
325 
326  for
327  (
328  subCycle<volScalarField> alphaSubCycle(alpha, nAlphaSubCycles);
329  !(++alphaSubCycle).end();
330  )
331  {
332  solveAlphas(cAlpha);
333  rhoPhiSum += (runTime.deltaT()/totalDeltaT)*rhoPhi_;
334  }
335 
336  rhoPhi_ = rhoPhiSum;
337  }
338  else
339  {
340  solveAlphas(cAlpha);
341  }
342 
343  // Update the mixture kinematic viscosity
344  nu_ = mu()/rho();
345 }
346 
347 
349 {
350  forAllIter(PtrDictionary<phase>, phases_, iter)
351  {
352  iter().correct();
353  }
354 }
355 
356 
357 Foam::tmp<Foam::surfaceVectorField> Foam::multiphaseMixture::nHatfv
358 (
359  const volScalarField& alpha1,
360  const volScalarField& alpha2
361 ) const
362 {
363  /*
364  // Cell gradient of alpha
365  volVectorField gradAlpha =
366  alpha2*fvc::grad(alpha1) - alpha1*fvc::grad(alpha2);
367 
368  // Interpolated face-gradient of alpha
369  surfaceVectorField gradAlphaf = fvc::interpolate(gradAlpha);
370  */
371 
372  surfaceVectorField gradAlphaf
373  (
375  - fvc::interpolate(alpha1)*fvc::interpolate(fvc::grad(alpha2))
376  );
377 
378  // Face unit interface normal
379  return gradAlphaf/(mag(gradAlphaf) + deltaN_);
380 }
381 
382 
383 Foam::tmp<Foam::surfaceScalarField> Foam::multiphaseMixture::nHatf
384 (
385  const volScalarField& alpha1,
386  const volScalarField& alpha2
387 ) const
388 {
389  // Face unit interface normal flux
390  return nHatfv(alpha1, alpha2) & mesh_.Sf();
391 }
392 
393 
394 Foam::tmp<Foam::volScalarField> Foam::multiphaseMixture::K
395 (
396  const phase& alpha1,
397  const phase& alpha2
398 ) const
399 {
400  tmp<surfaceVectorField> tnHatfv = nHatfv(alpha1, alpha2);
401 
403  (
404  alpha1,
405  alpha2,
406  U_.boundaryField(),
407  deltaN_,
408  tnHatfv.ref().boundaryFieldRef()
409  );
410 
411  // Simple expression for curvature
412  return -fvc::div(tnHatfv & mesh_.Sf());
413 }
414 
415 
418 {
419  tmp<volScalarField> tnearInt
420  (
422  (
423  "nearInterface",
424  mesh_,
426  )
427  );
428 
429  forAllConstIter(PtrDictionary<phase>, phases_, iter)
430  {
431  tnearInt.ref() =
432  max(tnearInt(), pos0(iter() - 0.01)*pos0(0.99 - iter()));
433  }
434 
435  return tnearInt;
436 }
437 
438 
439 void Foam::multiphaseMixture::solveAlphas
440 (
441  const scalar cAlpha
442 )
443 {
444  static label nSolves=-1;
445  nSolves++;
446 
447  word alphaScheme("div(phi,alpha)");
448  word alpharScheme("div(phirb,alpha)");
449 
450  surfaceScalarField phic(mag(phi_/mesh_.magSf()));
451  phic = min(cAlpha*phic, max(phic));
452 
453  UPtrList<const volScalarField> alphas(phases_.size());
454  PtrList<surfaceScalarField> alphaPhis(phases_.size());
455  int phasei = 0;
456 
457  forAllIter(PtrDictionary<phase>, phases_, iter)
458  {
459  const phase& alpha = iter();
460 
461  alphas.set(phasei, &alpha);
462 
463  alphaPhis.set
464  (
465  phasei,
467  (
468  "phi" + alpha.name() + "Corr",
469  fvc::flux
470  (
471  phi_,
472  alpha,
474  )
475  )
476  );
477 
478  surfaceScalarField& alphaPhi = alphaPhis[phasei];
479 
480  forAllIter(PtrDictionary<phase>, phases_, iter2)
481  {
482  phase& alpha2 = iter2();
483 
484  if (&alpha2 == &alpha) continue;
485 
486  surfaceScalarField phir(phic*nHatf(alpha, alpha2));
487 
488  alphaPhi += fvc::flux
489  (
490  -fvc::flux(-phir, alpha2, alpharScheme),
491  alpha,
493  );
494  }
495 
496  // Limit alphaPhi for each phase
498  (
499  1.0/mesh_.time().deltaT().value(),
500  geometricOneField(),
501  alpha,
502  phi_,
503  alphaPhi,
504  zeroField(),
505  zeroField(),
506  oneField(),
507  zeroField(),
508  false
509  );
510 
511  phasei++;
512  }
513 
514  MULES::limitSum(alphas, alphaPhis, phi_);
515 
516  rhoPhi_ = dimensionedScalar(dimensionSet(1, 0, -1, 0, 0), 0);
517 
518  volScalarField sumAlpha
519  (
520  IOobject
521  (
522  "sumAlpha",
523  mesh_.time().timeName(),
524  mesh_
525  ),
526  mesh_,
528  );
529 
530  phasei = 0;
531 
532  forAllIter(PtrDictionary<phase>, phases_, iter)
533  {
534  phase& alpha = iter();
535  surfaceScalarField& alphaPhi = alphaPhis[phasei];
536 
538  (
539  geometricOneField(),
540  alpha,
541  alphaPhi
542  );
543 
544  rhoPhi_ += alphaPhi*alpha.rho();
545 
546  Info<< alpha.name() << " volume fraction, min, max = "
547  << alpha.weightedAverage(mesh_.V()).value()
548  << ' ' << min(alpha).value()
549  << ' ' << max(alpha).value()
550  << endl;
551 
552  sumAlpha += alpha;
553 
554  phasei++;
555  }
556 
557  Info<< "Phase-sum volume fraction, min, max = "
558  << sumAlpha.weightedAverage(mesh_.V()).value()
559  << ' ' << min(sumAlpha).value()
560  << ' ' << max(sumAlpha).value()
561  << endl;
562 
563  // Correct the sum of the phase-fractions to avoid 'drift'
564  volScalarField sumCorr(1.0 - sumAlpha);
565  forAllIter(PtrDictionary<phase>, phases_, iter)
566  {
567  phase& alpha = iter();
568  alpha += alpha*sumCorr;
569  }
570 
571  calcAlphas();
572 }
573 
574 
576 {
577  if (regIOobject::read())
578  {
579  lookup("sigmas") >> sigmas_;
580  return true;
581  }
582  else
583  {
584  return false;
585  }
586 }
587 
588 
589 // ************************************************************************* //
void limit(const RdeltaTType &rDeltaT, const RhoType &rho, const volScalarField &psi, const surfaceScalarField &phi, surfaceScalarField &phiPsi, const SpType &Sp, const SuType &Su, const PsiMaxType &psiMax, const PsiMinType &psiMin, const bool returnCorr)
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
const surfaceVectorField & Sf() const
Return cell face area vectors.
tmp< surfaceScalarField > muf() const
Return the face-interpolated dynamic laminar viscosity.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
label phasei
Definition: pEqn.H:27
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112
virtual bool read()
Read object.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
const Boundary & boundaryField() const
Return const-reference to the boundary field.
void correctContactAngle(const volScalarField &alpha1, const volScalarField &alpha2, const volVectorField::Boundary &Ubf, const dimensionedScalar &deltaN, surfaceVectorField::Boundary &nHatbf)
Correct the contact angle for the two volume fraction fields.
const word alphaScheme(mesh.schemes().div(divAlphaName)[1].wordToken())
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:47
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
IOobject(const word &name, const fileName &instance, const objectRegistry &registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
Construct from name, instance, registry, io options.
Definition: IOobject.C:167
volScalarField alpha(IOobject("alpha", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
static tmp< GeometricField< scalar, fvsPatchField, surfaceMesh > > New(const word &name, const Internal &, const PtrList< fvsPatchField< scalar >> &)
Return a temporary field constructed from name,.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
tmp< volScalarField > trho
tmp< volScalarField > nearInterface() const
Indicator of the proximity of the interface.
surfaceScalarField phir(fvc::flux(mixture.Udm()))
Calculate the snGrad of the given volField.
const fvSolution & solution() const
Return the fvSchemes.
Definition: fvMesh.C:1683
const dimensionSet dimless
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:372
const dictionary & solverDict(const word &name) const
Return the solver controls dictionary for the given field.
Definition: solution.C:335
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:59
fvMesh & mesh
CGAL::Exact_predicates_exact_constructions_kernel K
multiphaseMixture(const volVectorField &U, const surfaceScalarField &phi)
Construct from components.
tmp< volScalarField > rho() const
Return the mixture density.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:142
dictionary()
Construct top-level dictionary null.
Definition: dictionary.C:440
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:58
const dimensionedScalar sigma
Stefan-Boltzmann constant: default SI units: [W/m^2/K^4].
const dimensionSet dimTime
const dimensionSet & dimensions() const
Return dimensions.
bool read()
Read base phaseProperties dictionary.
void limitSum(UPtrList< scalarField > &phiPsiCorrs)
Definition: MULES.C:30
Calculate the gradient of the given field.
phic
Definition: correctPhic.H:2
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
Definition: Time.C:666
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void correct()
Correct the mixture properties.
Calculate the face-flux of the given field.
friend class const_iterator
Declare friendship with the const_iterator.
Definition: HashTable.H:197
const Type & value() const
Return const reference to value.
surfaceScalarField alphaPhi(phi.name()+alpha1.name(), fvc::flux(phi, alpha1, alphaScheme))
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
word timeName
Definition: getTimeIndex.H:3
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
const iterator & end()
Definition: UILList.H:223
tmp< volScalarField > nu() const
Return the kinematic laminar viscosity.
IOdictionary(const IOobject &io, const word &wantedType)
Construct given an IOobject, supply wanted typeName.
Definition: IOdictionary.C:47
Calculate the divergence of the given field.
const surfaceScalarField & magSf() const
Return cell face area magnitudes.
dimensionedScalar pos0(const dimensionedScalar &ds)
tmp< volScalarField > mu() const
Return the dynamic laminar viscosity.
const label nAlphaSubCycles(alphaControls.lookup< label >("nAlphaSubCycles"))
void solve()
Solve for the mixture phase-fractions.
const dimensionSet dimMass
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
Internal & ref()
Return a reference to the dimensioned internal field.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
tmp< surfaceScalarField > nuf() const
Return the face-interpolated dynamic laminar viscosity.
label patchi
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const Time & time() const
Return time.
Definition: IOobject.C:318
word alpharScheme("div(phirb,alpha)")
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
MULES: Multidimensional universal limiter for explicit solution.
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:105
A class for managing temporary objects.
Definition: PtrList.H:53
tmp< surfaceScalarField > flux(const volVectorField &vvf)
Return the face-flux field obtained from the given volVectorField.
Definition: fvcFlux.C:32
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:312
void explicitSolve(const RdeltaTType &rDeltaT, const RhoType &rho, volScalarField &psi, const surfaceScalarField &phiPsi, const SpType &Sp, const SuType &Su)
dimensionedScalar deltaT() const
Return time step.
Definition: TimeStateI.H:46
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:45
friend class const_iterator
Definition: LPtrList.H:87
tmp< surfaceScalarField > surfaceTensionForce() const
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864