Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / transportModels / incompressible / incompressibleTwoPhaseMixture / twoPhaseMixture.C
blob331775738d25a67182931190bc93cb674e1edea1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "twoPhaseMixture.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "surfaceFields.H"
29 #include "fvc.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
36 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
38 //- Calculate and return the laminar viscosity
39 word twoPhaseMixture::getPhaseName(const word& key) const
41     if (isDict(key))
42     {
43         return key;
44     }
45     else
46     {
47         return word(lookup(key));
48     }
51 void twoPhaseMixture::calcNu()
53     nuModel1_->correct();
54     nuModel2_->correct();
56     volScalarField limitedAlpha1
57     (
58         "limitedAlpha1",
59         min(max(alpha1_, scalar(0)), scalar(1))
60     );
62     // Average kinematic viscosity calculated from dynamic viscosity
63     nu_ = mu()/(limitedAlpha1*rho1_ + (scalar(1) - limitedAlpha1)*rho2_);
67 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
69 twoPhaseMixture::twoPhaseMixture
71     const volVectorField& U,
72     const surfaceScalarField& phi,
73     const word& alpha1Name
76     transportModel(U, phi),
78     phase1Name_(getPhaseName("phase1")),
79     phase2Name_(getPhaseName("phase2")),
81     nuModel1_
82     (
83         viscosityModel::New
84         (
85             "nu1",
86             subDict(phase1Name_),
87             U,
88             phi
89         )
90     ),
91     nuModel2_
92     (
93         viscosityModel::New
94         (
95             "nu2",
96             subDict(phase2Name_),
97             U,
98             phi
99         )
100     ),
102     rho1_(nuModel1_->viscosityProperties().lookup("rho")),
103     rho2_(nuModel2_->viscosityProperties().lookup("rho")),
105     U_(U),
106     phi_(phi),
108     alpha1_(U_.db().lookupObject<const volScalarField> (alpha1Name)),
110     nu_
111     (
112         IOobject
113         (
114             "nu",
115             U_.time().timeName(),
116             U_.db()
117         ),
118         U_.mesh(),
119         dimensionedScalar("nu", dimensionSet(0, 2, -1, 0, 0), 0),
120         calculatedFvPatchScalarField::typeName
121     )
123     calcNu();
127 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
129 tmp<volScalarField> twoPhaseMixture::rho() const
131     volScalarField limitedAlpha1 = min(max(alpha1_, scalar(0)), scalar(1));
133     return tmp<volScalarField>
134     (
135         new volScalarField
136         (
137             "rho_twoPhaseMixture",
138             limitedAlpha1*rho1_
139           + (scalar(1) - limitedAlpha1)*rho2_
140         )
141     );
145 tmp<volScalarField> twoPhaseMixture::mu() const
147     volScalarField limitedAlpha1 = min(max(alpha1_, scalar(0)), scalar(1));
149     return tmp<volScalarField>
150     (
151         new volScalarField
152         (
153             "mu_twoPhaseMixture",
154             limitedAlpha1*rho1_*nuModel1_->nu()
155           + (scalar(1) - limitedAlpha1)*rho2_*nuModel2_->nu()
156         )
157     );
161 tmp<surfaceScalarField> twoPhaseMixture::muf() const
163     surfaceScalarField alpha1f =
164         min(max(fvc::interpolate(alpha1_), scalar(0)), scalar(1));
166     return tmp<surfaceScalarField>
167     (
168         new surfaceScalarField
169         (
170             "muf_twoPhaseMixture",
171             alpha1f*rho1_*fvc::interpolate(nuModel1_->nu())
172           + (scalar(1) - alpha1f)*rho2_*fvc::interpolate(nuModel2_->nu())
173         )
174     );
178 tmp<surfaceScalarField> twoPhaseMixture::nuf() const
180     surfaceScalarField alpha1f =
181         min(max(fvc::interpolate(alpha1_), scalar(0)), scalar(1));
183     return tmp<surfaceScalarField>
184     (
185         new surfaceScalarField
186         (
187             "nuf_twoPhaseMixture",
188             (
189                 alpha1f*rho1_*fvc::interpolate(nuModel1_->nu())
190               + (scalar(1) - alpha1f)*rho2_*fvc::interpolate(nuModel2_->nu())
191             )/(alpha1f*rho1_ + (scalar(1) - alpha1f)*rho2_)
192         )
193     );
197 bool twoPhaseMixture::read()
199     if (transportModel::read())
200     {
201         if
202         (
203             nuModel1_().read(subDict(phase1Name_))
204          && nuModel2_().read(subDict(phase2Name_))
205         )
206         {
207             nuModel1_->viscosityProperties().lookup("rho") >> rho1_;
208             nuModel2_->viscosityProperties().lookup("rho") >> rho2_;
210             return true;
211         }
212         else
213         {
214             return false;
215         }
216     }
217     else
218     {
219         return false;
220     }
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 } // End namespace Foam
228 // ************************************************************************* //