1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "adjustPhi.H"
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 #include "processorFvsPatchFields.H"
31 #include "inletOutletFvPatchFields.H"
33 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
37 surfaceScalarField& phi,
38 const volVectorField& U,
42 if (p.needReference())
44 p.boundaryField().updateCoeffs();
47 scalar fixedMassOut = 0.0;
48 scalar adjustableMassOut = 0.0;
50 forAll (phi.boundaryField(), patchi)
52 const fvPatchVectorField& Up = U.boundaryField()[patchi];
53 const fvsPatchScalarField& phip = phi.boundaryField()[patchi];
55 if (!isType<processorFvsPatchScalarField>(phip))
60 && !isA<inletOutletFvPatchVectorField>(Up)
71 fixedMassOut += phip[i];
85 adjustableMassOut += phip[i];
92 // Calculate the total flux in the domain, used for normalisation
93 scalar totalFlux = VSMALL + sum(mag(phi)).value();
95 reduce(massIn, sumOp<scalar>());
96 reduce(fixedMassOut, sumOp<scalar>());
97 reduce(adjustableMassOut, sumOp<scalar>());
99 scalar massCorr = 1.0;
100 scalar magAdjustableMassOut = mag(adjustableMassOut);
104 magAdjustableMassOut > VSMALL
105 && magAdjustableMassOut/totalFlux > SMALL
108 massCorr = (massIn - fixedMassOut)/adjustableMassOut;
110 else if(mag(fixedMassOut - massIn)/totalFlux > 1e-10)
114 "adjustPhi(surfaceScalarField& phi, const volVectorField& U,"
115 "const volScalarField& p"
116 ) << "Continuity error cannot be removed by adjusting the"
117 " outflow.\nPlease check the velocity boundary conditions"
118 " and/or run potentialFoam to initialise the outflow." << nl
119 << "Total flux : " << totalFlux << nl
120 << "Specified mass inflow : " << massIn << nl
121 << "Specified mass outflow : " << fixedMassOut << nl
122 << "Adjustable mass outflow : " << adjustableMassOut << nl
126 forAll (phi.boundaryField(), patchi)
128 const fvPatchVectorField& Up = U.boundaryField()[patchi];
129 fvsPatchScalarField& phip = phi.boundaryField()[patchi];
131 if (!isType<processorFvsPatchScalarField>(phip))
136 || isA<inletOutletFvPatchVectorField>(Up)
150 return mag(massIn)/totalFlux < SMALL
151 && mag(fixedMassOut)/totalFlux < SMALL
152 && mag(adjustableMassOut)/totalFlux < SMALL;
161 // ************************************************************************* //