Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
Henry
committed
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "multiphaseSystem.H"
#include "alphaContactAngleFvPatchScalarField.H"
#include "fixedValueFvsPatchFields.H"
#include "Time.H"
#include "subCycle.H"
#include "MULES.H"
#include "surfaceInterpolate.H"
#include "fvcGrad.H"
#include "fvcDiv.H"
#include "fvcAverage.H"
// * * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * //
const Foam::scalar Foam::multiphaseSystem::convertToRad =
Foam::constant::mathematical::pi/180.0;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::multiphaseSystem::calcAlphas()
{
scalar level = 0.0;
alphas_ == 0.0;
forAllIter(PtrDictionary<phaseModel>, phases_, iter)
{
alphas_ += level*iter();
level += 1.0;
}
alphas_.correctBoundaryConditions();
}
void Foam::multiphaseSystem::solveAlphas()
{
PtrList<surfaceScalarField> phiAlphaCorrs(phases_.size());
int phasei = 0;
forAllIter(PtrDictionary<phaseModel>, phases_, iter)
{
phaseModel& phase1 = iter();
phase1.phiAlpha() =
dimensionedScalar("0", dimensionSet(0, 3, -1, 0, 0), 0);
phiAlphaCorrs.set
(
phasei,
new surfaceScalarField
(
fvc::flux
(
phi_,
phase1,
)
)
);
surfaceScalarField& phiAlphaCorr = phiAlphaCorrs[phasei];
forAllIter(PtrDictionary<phaseModel>, phases_, iter2)
{
phaseModel& phase2 = iter2();
surfaceScalarField phir(phase1.phi() - phase2.phi());
scalarCoeffSymmTable::const_iterator cAlpha
cAlphas_.find(interfacePair(phase1, phase2))
if (cAlpha != cAlphas_.end())
{
surfaceScalarField phic
(
(mag(phi_) + mag(phase1.phi() - phase2.phi()))/mesh_.magSf()
);
phir += min(cAlpha()*phic, max(phic))*nHatf(phase1, phase2);
}
word phirScheme
(
"div(phir," + alpha2.name() + ',' + alpha1.name() + ')'
);
// Ensure that the flux at inflow BCs is preserved
phiAlphaCorr.boundaryField() = min
(
phase1.phi().boundaryField()*alpha1.boundaryField(),
phiAlphaCorr.boundaryField()
);
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
MULES::limit
(
geometricOneField(),
phase1,
phi_,
phiAlphaCorr,
zeroField(),
zeroField(),
1,
0,
3,
true
);
phasei++;
}
MULES::limitSum(phiAlphaCorrs);
volScalarField sumAlpha
(
IOobject
(
"sumAlpha",
mesh_.time().timeName(),
mesh_
),
mesh_,
dimensionedScalar("sumAlpha", dimless, 0)
);
phasei = 0;
forAllIter(PtrDictionary<phaseModel>, phases_, iter)
{
phaseModel& phase1 = iter();
surfaceScalarField& phiAlpha = phiAlphaCorrs[phasei];
phiAlpha += upwind<scalar>(mesh_, phi_).flux(phase1);
MULES::explicitSolve
(
geometricOneField(),
phase1,
phiAlpha,
zeroField(),
zeroField()
);
phase1.phiAlpha() += phiAlpha;
Info<< phase1.name() << " volume fraction, min, max = "
<< phase1.weightedAverage(mesh_.V()).value()
<< ' ' << min(phase1).value()
<< ' ' << max(phase1).value()
<< endl;
sumAlpha += phase1;
phasei++;
}
Info<< "Phase-sum volume fraction, min, max = "
<< sumAlpha.weightedAverage(mesh_.V()).value()
<< ' ' << min(sumAlpha).value()
<< ' ' << max(sumAlpha).value()
<< endl;
calcAlphas();
}
Foam::tmp<Foam::surfaceVectorField> Foam::multiphaseSystem::nHatfv
(
const volScalarField& alpha1,
const volScalarField& alpha2
) const
{
/*
// Cell gradient of alpha
volVectorField gradAlpha =
alpha2*fvc::grad(alpha1) - alpha1*fvc::grad(alpha2);
// Interpolated face-gradient of alpha
surfaceVectorField gradAlphaf = fvc::interpolate(gradAlpha);
*/
surfaceVectorField gradAlphaf
(
fvc::interpolate(alpha2)*fvc::interpolate(fvc::grad(alpha1))
- fvc::interpolate(alpha1)*fvc::interpolate(fvc::grad(alpha2))
);
// Face unit interface normal
return gradAlphaf/(mag(gradAlphaf) + deltaN_);
}
Foam::tmp<Foam::surfaceScalarField> Foam::multiphaseSystem::nHatf
(
const volScalarField& alpha1,
const volScalarField& alpha2
) const
{
// Face unit interface normal flux
return nHatfv(alpha1, alpha2) & mesh_.Sf();
}
// Correction for the boundary condition on the unit normal nHat on
// walls to produce the correct contact angle.
// The dynamic contact angle is calculated from the component of the
// velocity on the direction of the interface, parallel to the wall.
void Foam::multiphaseSystem::correctContactAngle
(
const phaseModel& phase1,
const phaseModel& phase2,
surfaceVectorField::GeometricBoundaryField& nHatb
) const
{
const volScalarField::GeometricBoundaryField& gbf
= phase1.boundaryField();
const fvBoundaryMesh& boundary = mesh_.boundary();
forAll(boundary, patchi)
{
if (isA<alphaContactAngleFvPatchScalarField>(gbf[patchi]))
{
const alphaContactAngleFvPatchScalarField& acap =
refCast<const alphaContactAngleFvPatchScalarField>(gbf[patchi]);
vectorField& nHatPatch = nHatb[patchi];
vectorField AfHatPatch
(
mesh_.Sf().boundaryField()[patchi]
/mesh_.magSf().boundaryField()[patchi]
);
alphaContactAngleFvPatchScalarField::thetaPropsTable::
const_iterator tp =
acap.thetaProps().find(interfacePair(phase1, phase2));
if (tp == acap.thetaProps().end())
{
FatalErrorIn
(
"multiphaseSystem::correctContactAngle"
"(const phaseModel& phase1, const phaseModel& phase2, "
"fvPatchVectorFieldField& nHatb) const"
) << "Cannot find interface " << interfacePair(phase1, phase2)
<< "\n in table of theta properties for patch "
<< acap.patch().name()
<< exit(FatalError);
}
bool matched = (tp.key().first() == phase1.name());
scalar theta0 = convertToRad*tp().theta0(matched);
scalarField theta(boundary[patchi].size(), theta0);
scalar uTheta = tp().uTheta();
// Calculate the dynamic contact angle if required
if (uTheta > SMALL)
{
scalar thetaA = convertToRad*tp().thetaA(matched);
scalar thetaR = convertToRad*tp().thetaR(matched);
// Calculated the component of the velocity parallel to the wall
vectorField Uwall
(
phase1.U().boundaryField()[patchi].patchInternalField()
- phase1.U().boundaryField()[patchi]
);
Uwall -= (AfHatPatch & Uwall)*AfHatPatch;
// Find the direction of the interface parallel to the wall
vectorField nWall
(
nHatPatch - (AfHatPatch & nHatPatch)*AfHatPatch
);
// Normalise nWall
nWall /= (mag(nWall) + SMALL);
// Calculate Uwall resolved normal to the interface parallel to
// the interface
scalarField uwall(nWall & Uwall);
theta += (thetaA - thetaR)*tanh(uwall/uTheta);
}
// Reset nHatPatch to correspond to the contact angle
scalarField a12(nHatPatch & AfHatPatch);
scalarField b1(cos(theta));
scalarField b2(nHatPatch.size());
forAll(b2, facei)
{
b2[facei] = cos(acos(a12[facei]) - theta[facei]);
}
scalarField det(1.0 - a12*a12);
scalarField a((b1 - a12*b2)/det);
scalarField b((b2 - a12*b1)/det);
nHatPatch = a*AfHatPatch + b*nHatPatch;
nHatPatch /= (mag(nHatPatch) + deltaN_.value());
}
}
}
Foam::tmp<Foam::volScalarField> Foam::multiphaseSystem::K
(
const phaseModel& phase1,
const phaseModel& phase2
) const
{
tmp<surfaceVectorField> tnHatfv = nHatfv(phase1, phase2);
correctContactAngle(phase1, phase2, tnHatfv().boundaryField());
// Simple expression for curvature
return -fvc::div(tnHatfv & mesh_.Sf());
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::multiphaseSystem::multiphaseSystem
(
IOdictionary
(
IOobject
(
"transportProperties",
U.time().constant(),
U.db(),
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
),
phases_(lookup("phases"), phaseModel::iNew(U.mesh())),
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
phi_(phi),
alphas_
(
IOobject
(
"alphas",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh_,
dimensionedScalar("alphas", dimless, 0.0),
zeroGradientFvPatchScalarField::typeName
),
sigmas_(lookup("sigmas")),
dimSigma_(1, 0, -2, 0, 0),
cAlphas_(lookup("interfaceCompression")),
Cvms_(lookup("virtualMass")),
deltaN_
(
"deltaN",
1e-8/pow(average(mesh_.V()), 1.0/3.0)
)
{
calcAlphas();
alphas_.write();
interfaceDictTable dragModelsDict(lookup("drag"));
forAllConstIter(interfaceDictTable, dragModelsDict, iter)
{
dragModels_.insert
(
iter.key(),
dragModel::New
(
iter(),
*phases_.lookup(iter.key().first()),
*phases_.lookup(iter.key().second())
Henry
committed
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
forAllConstIter(PtrDictionary<phaseModel>, phases_, iter1)
{
const phaseModel& phase1 = iter1();
forAllConstIter(PtrDictionary<phaseModel>, phases_, iter2)
{
const phaseModel& phase2 = iter2();
if (&phase2 != &phase1)
{
scalarCoeffSymmTable::const_iterator sigma
(
sigmas_.find(interfacePair(phase1, phase2))
);
if (sigma != sigmas_.end())
{
scalarCoeffSymmTable::const_iterator cAlpha
(
cAlphas_.find(interfacePair(phase1, phase2))
);
if (cAlpha == cAlphas_.end())
{
WarningIn
(
"multiphaseSystem::multiphaseSystem"
"(const volVectorField& U,"
"const surfaceScalarField& phi)"
) << "Compression coefficient not specified for "
"phase pair ("
<< phase1.name() << ' ' << phase2.name()
<< ") for which a surface tension "
"coefficient is specified"
<< endl;
}
}
}
}
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::tmp<Foam::volScalarField> Foam::multiphaseSystem::rho() const
{
PtrDictionary<phaseModel>::const_iterator iter = phases_.begin();
tmp<volScalarField> trho = iter()*iter().rho();
for (++iter; iter != phases_.end(); ++iter)
{
trho() += iter()*iter().rho();
}
return trho;
}
Foam::tmp<Foam::scalarField>
Foam::multiphaseSystem::rho(const label patchi) const
{
PtrDictionary<phaseModel>::const_iterator iter = phases_.begin();
tmp<scalarField> trho = iter().boundaryField()[patchi]*iter().rho().value();
for (++iter; iter != phases_.end(); ++iter)
{
trho() += iter().boundaryField()[patchi]*iter().rho().value();
}
return trho;
}
Foam::tmp<Foam::volScalarField> Foam::multiphaseSystem::nu() const
{
PtrDictionary<phaseModel>::const_iterator iter = phases_.begin();
tmp<volScalarField> tmu = iter()*(iter().rho()*iter().nu());
for (++iter; iter != phases_.end(); ++iter)
{
tmu() += iter()*(iter().rho()*iter().nu());
}
return tmu/rho();
}
Foam::tmp<Foam::scalarField>
Foam::multiphaseSystem::nu(const label patchi) const
{
PtrDictionary<phaseModel>::const_iterator iter = phases_.begin();
tmp<scalarField> tmu =
iter().boundaryField()[patchi]
*(iter().rho().value()*iter().nu().value());
for (++iter; iter != phases_.end(); ++iter)
{
tmu() +=
iter().boundaryField()[patchi]
*(iter().rho().value()*iter().nu().value());
return tmu/rho(patchi);
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
Foam::tmp<Foam::volScalarField> Foam::multiphaseSystem::Cvm
(
const phaseModel& phase
) const
{
tmp<volScalarField> tCvm
(
new volScalarField
(
IOobject
(
"Cvm",
mesh_.time().timeName(),
mesh_
),
mesh_,
dimensionedScalar
(
"Cvm",
dimensionSet(1, -3, 0, 0, 0),
0
)
)
);
forAllConstIter(PtrDictionary<phaseModel>, phases_, iter)
{
const phaseModel& phase2 = iter();
if (&phase2 != &phase)
{
scalarCoeffTable::const_iterator Cvm
(
Cvms_.find(interfacePair(phase, phase2))
);
if (Cvm != Cvms_.end())
{
tCvm() += Cvm()*phase2.rho()*phase2;
}
else
{
Cvm = Cvms_.find(interfacePair(phase2, phase));
if (Cvm != Cvms_.end())
{
tCvm() += Cvm()*phase.rho()*phase2;
}
}
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
}
}
return tCvm;
}
Foam::tmp<Foam::volVectorField> Foam::multiphaseSystem::Svm
(
const phaseModel& phase
) const
{
tmp<volVectorField> tSvm
(
new volVectorField
(
IOobject
(
"Svm",
mesh_.time().timeName(),
mesh_
),
mesh_,
dimensionedVector
(
"Svm",
dimensionSet(1, -2, -2, 0, 0),
vector::zero
)
)
);
forAllConstIter(PtrDictionary<phaseModel>, phases_, iter)
{
const phaseModel& phase2 = iter();
if (&phase2 != &phase)
{
scalarCoeffTable::const_iterator Cvm
(
Cvms_.find(interfacePair(phase, phase2))
);
if (Cvm != Cvms_.end())
{
tSvm() += Cvm()*phase2.rho()*phase2*phase2.DDtU();
}
else
{
Cvm = Cvms_.find(interfacePair(phase2, phase));
if (Cvm != Cvms_.end())
{
tSvm() += Cvm()*phase.rho()*phase2*phase2.DDtU();
}
}
// Remove virtual mass at fixed-flux boundaries
forAll(phase.phi().boundaryField(), patchi)
{
if
(
isA<fixedValueFvsPatchScalarField>
(
phase.phi().boundaryField()[patchi]
)
)
{
tSvm().boundaryField()[patchi] = vector::zero;
}
}
return tSvm;
}
Foam::autoPtr<Foam::multiphaseSystem::dragCoeffFields>
Foam::multiphaseSystem::dragCoeffs() const
{
autoPtr<dragCoeffFields> dragCoeffsPtr(new dragCoeffFields);
forAllConstIter(dragModelTable, dragModels_, iter)
{
const dragModel& dm = *iter();
volScalarField* Kptr =
max
(
//fvc::average(dm.phase1()*dm.phase2()),
//fvc::average(dm.phase1())*fvc::average(dm.phase2()),
dm.phase1()*dm.phase2(),
dm.residualPhaseFraction()
)
*dm.K
(
max
(
mag(dm.phase1().U() - dm.phase2().U()),
dm.residualSlip()
)
)
).ptr();
// Remove drag at fixed-flux boundaries
forAll(dm.phase1().phi().boundaryField(), patchi)
{
if
(
isA<fixedValueFvsPatchScalarField>
(
dm.phase1().phi().boundaryField()[patchi]
)
)
{
Kptr->boundaryField()[patchi] = 0.0;
}
}
dragCoeffsPtr().insert(iter.key(), Kptr);
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
}
return dragCoeffsPtr;
}
Foam::tmp<Foam::volScalarField> Foam::multiphaseSystem::dragCoeff
(
const phaseModel& phase,
const dragCoeffFields& dragCoeffs
) const
{
tmp<volScalarField> tdragCoeff
(
new volScalarField
(
IOobject
(
"dragCoeff",
mesh_.time().timeName(),
mesh_
),
mesh_,
dimensionedScalar
(
"dragCoeff",
dimensionSet(1, -3, -1, 0, 0),
0
)
)
);
dragModelTable::const_iterator dmIter = dragModels_.begin();
dragCoeffFields::const_iterator dcIter = dragCoeffs.begin();
for
(
;
dmIter != dragModels_.end() && dcIter != dragCoeffs.end();
++dmIter, ++dcIter
)
{
if
(
&phase == &dmIter()->phase1()
|| &phase == &dmIter()->phase2()
)
{
tdragCoeff() += *dcIter();
}
}
return tdragCoeff;
}
Foam::tmp<Foam::surfaceScalarField> Foam::multiphaseSystem::surfaceTension
(
const phaseModel& phase1
) const
tmp<surfaceScalarField> tSurfaceTension
(
new surfaceScalarField
(
IOobject
(
mesh_.time().timeName(),
mesh_
),
mesh_,
dimensionedScalar
(
forAllConstIter(PtrDictionary<phaseModel>, phases_, iter)
const phaseModel& phase2 = iter();
if (&phase2 != &phase1)
scalarCoeffSymmTable::const_iterator sigma
(
sigmas_.find(interfacePair(phase1, phase2))
);
if (sigma != sigmas_.end())
{
tSurfaceTension() +=
dimensionedScalar("sigma", dimSigma_, sigma())
*fvc::interpolate(K(phase1, phase2))*
(
fvc::interpolate(phase2)*fvc::snGrad(phase1)
- fvc::interpolate(phase1)*fvc::snGrad(phase2)
);
}
return tSurfaceTension;
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
}
Foam::tmp<Foam::volScalarField>
Foam::multiphaseSystem::nearInterface() const
{
tmp<volScalarField> tnearInt
(
new volScalarField
(
IOobject
(
"nearInterface",
mesh_.time().timeName(),
mesh_
),
mesh_,
dimensionedScalar("nearInterface", dimless, 0.0)
)
);
forAllConstIter(PtrDictionary<phaseModel>, phases_, iter)
{
tnearInt() = max(tnearInt(), pos(iter() - 0.01)*pos(0.99 - iter()));
}
return tnearInt;
}
void Foam::multiphaseSystem::solve()
{
forAllIter(PtrDictionary<phaseModel>, phases_, iter)
{
iter().correct();
}
const Time& runTime = mesh_.time();
Henry
committed
const dictionary& alphaControls = mesh_.solverDict("alpha");
label nAlphaSubCycles(readLabel(alphaControls.lookup("nAlphaSubCycles")));
if (nAlphaSubCycles > 1)
{
dimensionedScalar totalDeltaT = runTime.deltaT();
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
PtrList<volScalarField> alpha0s(phases_.size());
PtrList<surfaceScalarField> phiSums(phases_.size());
int phasei = 0;
forAllIter(PtrDictionary<phaseModel>, phases_, iter)
{
phaseModel& phase = iter();
volScalarField& alpha = phase;
alpha0s.set
(
phasei,
new volScalarField(alpha.oldTime())
);
phiSums.set
(
phasei,
new surfaceScalarField
(
IOobject
(
"phiSum" + alpha.name(),
runTime.timeName(),
mesh_
),
mesh_,
dimensionedScalar("0", dimensionSet(0, 3, -1, 0, 0), 0)
)
);
phasei++;
}
subCycleTime alphaSubCycle
(
const_cast<Time&>(runTime),
nAlphaSubCycles
);
!(++alphaSubCycle).end();
)
{
solveAlphas();
int phasei = 0;
forAllIter(PtrDictionary<phaseModel>, phases_, iter)
{
phiSums[phasei] += (runTime.deltaT()/totalDeltaT)*iter().phi();
phasei++;
}
}
phasei = 0;
forAllIter(PtrDictionary<phaseModel>, phases_, iter)
{
phaseModel& phase = iter();
volScalarField& alpha = phase;
phase.phi() = phiSums[phasei];
// Correct the time index of the field
// to correspond to the global time
alpha.timeIndex() = runTime.timeIndex();
// Reset the old-time field value
alpha.oldTime() = alpha0s[phasei];
alpha.oldTime().timeIndex() = runTime.timeIndex();
phasei++;
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
}
}
else
{
solveAlphas();
}
}
bool Foam::multiphaseSystem::read()
{
if (regIOobject::read())
{
bool readOK = true;
PtrList<entry> phaseData(lookup("phases"));
label phasei = 0;
forAllIter(PtrDictionary<phaseModel>, phases_, iter)
{
readOK &= iter().read(phaseData[phasei++].dict());
}
lookup("sigmas") >> sigmas_;
lookup("interfaceCompression") >> cAlphas_;
lookup("virtualMass") >> Cvms_;
return readOK;
}
else
{
return false;
}
}
// ************************************************************************* //