1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2011 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "adjustPhi.H"
27 #include <finiteVolume/volFields.H>
28 #include <finiteVolume/surfaceFields.H>
29 #include <finiteVolume/processorFvsPatchFields.H>
30 #include <finiteVolume/inletOutletFvPatchFields.H>
32 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
36 surfaceScalarField& phi,
37 const volVectorField& U,
41 if (p.needReference())
43 // p coefficients should not be updated here
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 (!isA<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 (!isA<processorFvsPatchScalarField>(phip))
136 || isA<inletOutletFvPatchVectorField>(Up)
150 return mag(massIn)/totalFlux < SMALL
151 && mag(fixedMassOut)/totalFlux < SMALL
152 && mag(adjustableMassOut)/totalFlux < SMALL;
161 // ************************ vim: set sw=4 sts=4 et: ************************ //