Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / finiteVolume / fields / fvPatchFields / derived / flowRateInletVelocity / flowRateInletVelocityFvPatchVectorField.C
blob28b28fa221d6103e55905b2121ce7d44af011b44
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2006-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 "flowRateInletVelocityFvPatchVectorField.H"
27 #include "volFields.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "surfaceFields.H"
32 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
34 Foam::
35 flowRateInletVelocityFvPatchVectorField::
36 flowRateInletVelocityFvPatchVectorField
38     const fvPatch& p,
39     const DimensionedField<vector, volMesh>& iF
42     fixedValueFvPatchField<vector>(p, iF),
43     flowRate_(0),
44     phiName_("phi"),
45     rhoName_("rho")
49 Foam::
50 flowRateInletVelocityFvPatchVectorField::
51 flowRateInletVelocityFvPatchVectorField
53     const flowRateInletVelocityFvPatchVectorField& ptf,
54     const fvPatch& p,
55     const DimensionedField<vector, volMesh>& iF,
56     const fvPatchFieldMapper& mapper
59     fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
60     flowRate_(ptf.flowRate_),
61     phiName_(ptf.phiName_),
62     rhoName_(ptf.rhoName_)
66 Foam::
67 flowRateInletVelocityFvPatchVectorField::
68 flowRateInletVelocityFvPatchVectorField
70     const fvPatch& p,
71     const DimensionedField<vector, volMesh>& iF,
72     const dictionary& dict
75     fixedValueFvPatchField<vector>(p, iF, dict),
76     flowRate_(readScalar(dict.lookup("flowRate"))),
77     phiName_(dict.lookupOrDefault<word>("phi", "phi")),
78     rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
82 Foam::
83 flowRateInletVelocityFvPatchVectorField::
84 flowRateInletVelocityFvPatchVectorField
86     const flowRateInletVelocityFvPatchVectorField& ptf
89     fixedValueFvPatchField<vector>(ptf),
90     flowRate_(ptf.flowRate_),
91     phiName_(ptf.phiName_),
92     rhoName_(ptf.rhoName_)
96 Foam::
97 flowRateInletVelocityFvPatchVectorField::
98 flowRateInletVelocityFvPatchVectorField
100     const flowRateInletVelocityFvPatchVectorField& ptf,
101     const DimensionedField<vector, volMesh>& iF
104     fixedValueFvPatchField<vector>(ptf, iF),
105     flowRate_(ptf.flowRate_),
106     phiName_(ptf.phiName_),
107     rhoName_(ptf.rhoName_)
111 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
113 void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs()
115     if (updated())
116     {
117         return;
118     }
120     // a simpler way of doing this would be nice
121     const scalar avgU = -flowRate_/gSum(patch().magSf());
123     tmp<vectorField> n = patch().nf();
125     const surfaceScalarField& phi =
126         db().lookupObject<surfaceScalarField>(phiName_);
128     if (phi.dimensions() == dimVelocity*dimArea)
129     {
130         // volumetric flow-rate
131         operator==(n*avgU);
132     }
133     else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
134     {
135         const fvPatchField<scalar>& rhop =
136             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
138         // mass flow-rate
139         operator==(n*avgU/rhop);
140     }
141     else
142     {
143         FatalErrorIn
144         (
145             "flowRateInletVelocityFvPatchVectorField::updateCoeffs()"
146         )   << "dimensions of " << phiName_ << " are incorrect" << nl
147             << "    on patch " << this->patch().name()
148             << " of field " << this->dimensionedInternalField().name()
149             << " in file " << this->dimensionedInternalField().objectPath()
150             << nl << exit(FatalError);
151     }
153     fixedValueFvPatchField<vector>::updateCoeffs();
157 void Foam::flowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
159     fvPatchField<vector>::write(os);
160     os.writeKeyword("flowRate") << flowRate_ << token::END_STATEMENT << nl;
161     writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
162     writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
163     writeEntry("value", os);
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 namespace Foam
171    makePatchTypeField
172    (
173        fvPatchVectorField,
174        flowRateInletVelocityFvPatchVectorField
175    );
179 // ************************************************************************* //