OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

multiphaseMixture.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "multiphaseMixture.H"
00028 #include "alphaContactAngleFvPatchScalarField.H"
00029 #include "Time.H"
00030 #include "subCycle.H"
00031 #include "fvCFD.H"
00032 
00033 // * * * * * * * * * * * * * * * Static Member Data  * * * * * * * * * * * * //
00034 
00035 const scalar Foam::multiphaseMixture::convertToRad =
00036     Foam::mathematicalConstant::pi/180.0;
00037 
00038 
00039 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00040 
00041 void Foam::multiphaseMixture::calcAlphas()
00042 {
00043     scalar level = 0.0;
00044     alphas_ == 0.0;
00045 
00046     forAllIter(PtrDictionary<phase>, phases_, iter)
00047     {
00048         alphas_ += level*iter();
00049         level += 1.0;
00050     }
00051 
00052     alphas_.correctBoundaryConditions();
00053 }
00054 
00055 
00056 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00057 
00058 Foam::multiphaseMixture::multiphaseMixture
00059 (
00060     const volVectorField& U,
00061     const surfaceScalarField& phi
00062 )
00063 :
00064     transportModel(U, phi),
00065     phases_(lookup("phases"), phase::iNew(U, phi)),
00066     refPhase_(*phases_.lookup(word(lookup("refPhase")))),
00067 
00068     mesh_(U.mesh()),
00069     U_(U),
00070     phi_(phi),
00071 
00072     rhoPhi_
00073     (
00074         IOobject
00075         (
00076             "rho*phi",
00077             mesh_.time().timeName(),
00078             mesh_,
00079             IOobject::NO_READ,
00080             IOobject::NO_WRITE
00081         ),
00082         mesh_,
00083         dimensionedScalar("rho*phi", dimMass/dimTime, 0.0)
00084     ),
00085 
00086     alphas_
00087     (
00088         IOobject
00089         (
00090             "alphas",
00091             mesh_.time().timeName(),
00092             mesh_,
00093             IOobject::NO_READ,
00094             IOobject::AUTO_WRITE
00095         ),
00096         mesh_,
00097         dimensionedScalar("alphas", dimless, 0.0),
00098         zeroGradientFvPatchScalarField::typeName
00099     ),
00100 
00101     sigmas_(lookup("sigmas")),
00102     dimSigma_(1, 0, -2, 0, 0),
00103     deltaN_
00104     (
00105         "deltaN",
00106         1e-8/pow(average(mesh_.V()), 1.0/3.0)
00107     )
00108 {
00109     calcAlphas();
00110     alphas_.write();
00111 
00112     forAllIter(PtrDictionary<phase>, phases_, iter)
00113     {
00114         alphaTable_.add(iter());
00115     }
00116 }
00117 
00118 
00119 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
00120 
00121 Foam::tmp<Foam::volScalarField> Foam::multiphaseMixture::rho() const
00122 {
00123     PtrDictionary<phase>::const_iterator iter = phases_.begin();
00124 
00125     tmp<volScalarField> trho = iter()*iter().rho();
00126 
00127     for(++iter; iter != phases_.end(); ++iter)
00128     {
00129         trho() += iter()*iter().rho();
00130     }
00131 
00132     return trho;
00133 }
00134 
00135 
00136 Foam::tmp<Foam::volScalarField> Foam::multiphaseMixture::mu() const
00137 {
00138     PtrDictionary<phase>::const_iterator iter = phases_.begin();
00139 
00140     tmp<volScalarField> tmu = iter()*iter().rho()*iter().nu();
00141 
00142     for(++iter; iter != phases_.end(); ++iter)
00143     {
00144         tmu() += iter()*iter().rho()*iter().nu();
00145     }
00146 
00147     return tmu;
00148 }
00149 
00150 
00151 Foam::tmp<Foam::surfaceScalarField> Foam::multiphaseMixture::muf() const
00152 {
00153     PtrDictionary<phase>::const_iterator iter = phases_.begin();
00154 
00155     tmp<surfaceScalarField> tmuf =
00156         fvc::interpolate(iter())*iter().rho()*fvc::interpolate(iter().nu());
00157 
00158     for(++iter; iter != phases_.end(); ++iter)
00159     {
00160         tmuf() +=
00161             fvc::interpolate(iter())*iter().rho()*fvc::interpolate(iter().nu());
00162     }
00163 
00164     return tmuf;
00165 }
00166 
00167 
00168 Foam::tmp<Foam::volScalarField> Foam::multiphaseMixture::nu() const
00169 {
00170     return mu()/rho();
00171 }
00172 
00173 
00174 Foam::tmp<Foam::surfaceScalarField> Foam::multiphaseMixture::nuf() const
00175 {
00176     return muf()/fvc::interpolate(rho());
00177 }
00178 
00179 
00180 Foam::tmp<Foam::surfaceScalarField>
00181 Foam::multiphaseMixture::surfaceTensionForce() const
00182 {
00183     tmp<surfaceScalarField> tstf
00184     (
00185         new surfaceScalarField
00186         (
00187             IOobject
00188             (
00189                 "surfaceTensionForce",
00190                 mesh_.time().timeName(),
00191                 mesh_
00192             ),
00193             mesh_,
00194             dimensionedScalar
00195             (
00196                 "surfaceTensionForce",
00197                 dimensionSet(1, -2, -2, 0, 0),
00198                 0.0
00199             )
00200         )
00201     );
00202 
00203     surfaceScalarField& stf = tstf();
00204 
00205     forAllConstIter(PtrDictionary<phase>, phases_, iter1)
00206     {
00207         const phase& alpha1 = iter1();
00208 
00209         PtrDictionary<phase>::const_iterator iter2 = iter1;
00210         ++iter2;
00211 
00212         for(; iter2 != phases_.end(); ++iter2)
00213         {
00214             const phase& alpha2 = iter2();
00215 
00216             sigmaTable::const_iterator sigma =
00217                 sigmas_.find(interfacePair(alpha1, alpha2));
00218 
00219             if (sigma == sigmas_.end())
00220             {
00221                 FatalErrorIn("multiphaseMixture::surfaceTensionForce() const")
00222                     << "Cannot find interface " << interfacePair(alpha1, alpha2)
00223                     << " in list of sigma values"
00224                     << exit(FatalError);
00225             }
00226 
00227             stf += dimensionedScalar("sigma", dimSigma_, sigma())
00228                *fvc::interpolate(K(alpha1, alpha2))*
00229                 (
00230                     fvc::interpolate(alpha2)*fvc::snGrad(alpha1)
00231                   - fvc::interpolate(alpha1)*fvc::snGrad(alpha2)
00232                 );
00233         }
00234     }
00235 
00236     return tstf;
00237 }
00238 
00239 
00240 void Foam::multiphaseMixture::correct()
00241 {
00242     forAllIter(PtrDictionary<phase>, phases_, iter)
00243     {
00244         iter().correct();
00245     }
00246 
00247     const Time& runTime = mesh_.time();
00248 
00249     label nAlphaSubCycles
00250     (
00251         readLabel
00252         (
00253             mesh_.solutionDict().subDict("PISO").lookup("nAlphaSubCycles")
00254         )
00255     );
00256 
00257     label nAlphaCorr
00258     (
00259         readLabel(mesh_.solutionDict().subDict("PISO").lookup("nAlphaCorr"))
00260     );
00261 
00262     bool cycleAlpha
00263     (
00264         Switch(mesh_.solutionDict().subDict("PISO").lookup("cycleAlpha"))
00265     );
00266 
00267     scalar cAlpha
00268     (
00269         readScalar(mesh_.solutionDict().subDict("PISO").lookup("cAlpha"))
00270     );
00271 
00272 
00273     volScalarField& alpha = phases_.first();
00274 
00275     if (nAlphaSubCycles > 1)
00276     {
00277         surfaceScalarField rhoPhiSum = 0.0*rhoPhi_;
00278         dimensionedScalar totalDeltaT = runTime.deltaT();
00279 
00280         for
00281         (
00282             subCycle<volScalarField> alphaSubCycle(alpha, nAlphaSubCycles);
00283             !(++alphaSubCycle).end();
00284         )
00285         {
00286             solveAlphas(nAlphaCorr, cycleAlpha, cAlpha);
00287             rhoPhiSum += (runTime.deltaT()/totalDeltaT)*rhoPhi_;
00288         }
00289 
00290         rhoPhi_ = rhoPhiSum;
00291     }
00292     else
00293     {
00294         solveAlphas(nAlphaCorr, cycleAlpha, cAlpha);
00295     }
00296 }
00297 
00298 
00299 Foam::tmp<Foam::surfaceVectorField> Foam::multiphaseMixture::nHatfv
00300 (
00301     const volScalarField& alpha1,
00302     const volScalarField& alpha2
00303 ) const
00304 {
00305     /*
00306     // Cell gradient of alpha
00307     volVectorField gradAlpha =
00308         alpha2*fvc::grad(alpha1) - alpha1*fvc::grad(alpha2);
00309 
00310     // Interpolated face-gradient of alpha
00311     surfaceVectorField gradAlphaf = fvc::interpolate(gradAlpha);
00312     */
00313 
00314     surfaceVectorField gradAlphaf =
00315         fvc::interpolate(alpha2)*fvc::interpolate(fvc::grad(alpha1))
00316       - fvc::interpolate(alpha1)*fvc::interpolate(fvc::grad(alpha2));
00317 
00318     // Face unit interface normal
00319     return gradAlphaf/(mag(gradAlphaf) + deltaN_);
00320 }
00321 
00322 
00323 Foam::tmp<Foam::surfaceScalarField> Foam::multiphaseMixture::nHatf
00324 (
00325     const volScalarField& alpha1,
00326     const volScalarField& alpha2
00327 ) const
00328 {
00329     // Face unit interface normal flux
00330     return nHatfv(alpha1, alpha2) & mesh_.Sf();
00331 }
00332 
00333 
00334 // Correction for the boundary condition on the unit normal nHat on
00335 // walls to produce the correct contact angle.
00336 
00337 // The dynamic contact angle is calculated from the component of the
00338 // velocity on the direction of the interface, parallel to the wall.
00339 
00340 void Foam::multiphaseMixture::correctContactAngle
00341 (
00342     const phase& alpha1,
00343     const phase& alpha2,
00344     surfaceVectorField::GeometricBoundaryField& nHatb
00345 ) const
00346 {
00347     const volScalarField::GeometricBoundaryField& gbf
00348         = refPhase_.boundaryField();
00349 
00350     const fvBoundaryMesh& boundary = mesh_.boundary();
00351 
00352     forAll(boundary, patchi)
00353     {
00354         if (typeid(gbf[patchi]) == typeid(alphaContactAngleFvPatchScalarField))
00355         {
00356             const alphaContactAngleFvPatchScalarField& acap =
00357                 refCast<const alphaContactAngleFvPatchScalarField>(gbf[patchi]);
00358 
00359             vectorField& nHatPatch = nHatb[patchi];
00360 
00361             vectorField AfHatPatch =
00362                 mesh_.Sf().boundaryField()[patchi]
00363                /mesh_.magSf().boundaryField()[patchi];
00364 
00365             alphaContactAngleFvPatchScalarField::thetaPropsTable::
00366                 const_iterator tp =
00367                 acap.thetaProps().find(interfacePair(alpha1, alpha2));
00368 
00369             if (tp == acap.thetaProps().end())
00370             {
00371                 FatalErrorIn
00372                 (
00373                     "multiphaseMixture::correctContactAngle"
00374                     "(const phase& alpha1, const phase& alpha2, "
00375                     "fvPatchVectorFieldField& nHatb) const"
00376                 )   << "Cannot find interface " << interfacePair(alpha1, alpha2)
00377                     << "\n    in table of theta properties for patch "
00378                     << acap.patch().name()
00379                     << exit(FatalError);
00380             }
00381 
00382             bool matched = (tp.key().first() == alpha1.name());
00383 
00384             scalar theta0 = convertToRad*tp().theta0(matched);
00385             scalarField theta(boundary[patchi].size(), theta0);
00386 
00387             scalar uTheta = tp().uTheta();
00388 
00389             // Calculate the dynamic contact angle if required
00390             if (uTheta > SMALL)
00391             {
00392                 scalar thetaA = convertToRad*tp().thetaA(matched);
00393                 scalar thetaR = convertToRad*tp().thetaR(matched);
00394 
00395                 // Calculated the component of the velocity parallel to the wall
00396                 vectorField Uwall =
00397                     U_.boundaryField()[patchi].patchInternalField()
00398                   - U_.boundaryField()[patchi];
00399                 Uwall -= (AfHatPatch & Uwall)*AfHatPatch;
00400 
00401                 // Find the direction of the interface parallel to the wall
00402                 vectorField nWall =
00403                     nHatPatch - (AfHatPatch & nHatPatch)*AfHatPatch;
00404 
00405                 // Normalise nWall
00406                 nWall /= (mag(nWall) + SMALL);
00407 
00408                 // Calculate Uwall resolved normal to the interface parallel to
00409                 // the interface
00410                 scalarField uwall = nWall & Uwall;
00411 
00412                 theta += (thetaA - thetaR)*tanh(uwall/uTheta);
00413             }
00414 
00415 
00416             // Reset nHatPatch to correspond to the contact angle
00417 
00418             scalarField a12 = nHatPatch & AfHatPatch;
00419 
00420             scalarField b1 = cos(theta);
00421 
00422             scalarField b2(nHatPatch.size());
00423 
00424             forAll(b2, facei)
00425             {
00426                 b2[facei] = cos(acos(a12[facei]) - theta[facei]);
00427             }
00428 
00429             scalarField det = 1.0 - a12*a12;
00430 
00431             scalarField a = (b1 - a12*b2)/det;
00432             scalarField b = (b2 - a12*b1)/det;
00433 
00434             nHatPatch = a*AfHatPatch + b*nHatPatch;
00435 
00436             nHatPatch /= (mag(nHatPatch) + deltaN_.value());
00437         }
00438     }
00439 }
00440 
00441 
00442 Foam::tmp<Foam::volScalarField> Foam::multiphaseMixture::K
00443 (
00444     const phase& alpha1,
00445     const phase& alpha2
00446 ) const
00447 {
00448     tmp<surfaceVectorField> tnHatfv = nHatfv(alpha1, alpha2);
00449 
00450     correctContactAngle(alpha1, alpha2, tnHatfv().boundaryField());
00451 
00452     // Simple expression for curvature
00453     return -fvc::div(tnHatfv & mesh_.Sf());
00454 }
00455 
00456 
00457 void Foam::multiphaseMixture::solveAlphas
00458 (
00459     const label nAlphaCorr,
00460     const bool cycleAlpha,
00461     const scalar cAlpha
00462 )
00463 {
00464     static label nSolves=-1;
00465     nSolves++;
00466 
00467     word alphaScheme("div(phi,alpha)");
00468     word alphacScheme("div(phic,alpha)");
00469 
00470     tmp<fv::convectionScheme<scalar> > mvConvection
00471     (
00472         fv::convectionScheme<scalar>::New
00473         (
00474             mesh_,
00475             alphaTable_,
00476             phi_,
00477             mesh_.divScheme(alphaScheme)
00478         )
00479     );
00480 
00481     surfaceScalarField phic = mag(phi_/mesh_.magSf());
00482     phic = min(cAlpha*phic, max(phic));
00483 
00484     for (int gCorr=0; gCorr<nAlphaCorr; gCorr++)
00485     {
00486         phase* refPhasePtr = &refPhase_;
00487 
00488         if (cycleAlpha)
00489         {
00490             PtrDictionary<phase>::iterator refPhaseIter = phases_.begin();
00491             for(label i=0; i<nSolves%phases_.size(); i++)
00492             {
00493                 ++refPhaseIter;
00494             }
00495             refPhasePtr = &refPhaseIter();
00496         }
00497 
00498         phase& refPhase = *refPhasePtr;
00499 
00500         volScalarField refPhaseNew = refPhase;
00501         refPhaseNew == 1.0;
00502 
00503         rhoPhi_ = phi_*refPhase.rho();
00504 
00505         forAllIter(PtrDictionary<phase>, phases_, iter)
00506         {
00507             phase& alpha = iter();
00508 
00509             if (&alpha == &refPhase) continue;
00510 
00511             fvScalarMatrix alphaEqn
00512             (
00513                 fvm::ddt(alpha)
00514               + mvConvection->fvmDiv(phi_, alpha)
00515             );
00516 
00517             forAllIter(PtrDictionary<phase>, phases_, iter2)
00518             {
00519                 phase& alpha2 = iter2();
00520 
00521                 if (&alpha2 == &alpha) continue;
00522 
00523                 surfaceScalarField phir = phic*nHatf(alpha, alpha2);
00524                 surfaceScalarField phirb12 =
00525                     -fvc::flux(-phir, alpha2, alphacScheme);
00526 
00527                 alphaEqn += fvm::div(phirb12, alpha, alphacScheme);
00528             }
00529 
00530             alphaEqn.solve(mesh_.solver("alpha"));
00531 
00532             rhoPhi_ += alphaEqn.flux()*(alpha.rho() - refPhase.rho());
00533 
00534             Info<< alpha.name() << " volume fraction, min, max = "
00535                 << alpha.weightedAverage(mesh_.V()).value()
00536                 << ' ' << min(alpha).value()
00537                 << ' ' << max(alpha).value()
00538                 << endl;
00539 
00540             refPhaseNew == refPhaseNew - alpha;
00541         }
00542 
00543         refPhase == refPhaseNew;
00544 
00545         Info<< refPhase.name() << " volume fraction, min, max = "
00546             << refPhase.weightedAverage(mesh_.V()).value()
00547             << ' ' << min(refPhase).value()
00548             << ' ' << max(refPhase).value()
00549             << endl;
00550     }
00551 
00552     calcAlphas();
00553 }
00554 
00555 
00556 bool Foam::multiphaseMixture::read()
00557 {
00558     if (transportModel::read())
00559     {
00560         bool readOK = true;
00561 
00562         PtrList<entry> phaseData(lookup("phases"));
00563         label phasei = 0;
00564 
00565         forAllIter(PtrDictionary<phase>, phases_, iter)
00566         {
00567             readOK &= iter().read(phaseData[phasei++].dict());
00568         }
00569 
00570         lookup("sigmas") >> sigmas_;
00571 
00572         return readOK;
00573     }
00574     else
00575     {
00576         return false;
00577     }
00578 }
00579 
00580 
00581 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd