initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / finiteVolume / fields / fvPatchFields / derived / flowRateInletVelocity / flowRateInletVelocityFvPatchVectorField.C
blob2d2f6f204c49d2e26b6f09f888bd72f3b5bf58a8
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2006-2008 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 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
19     for more details.
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 "flowRateInletVelocityFvPatchVectorField.H"
28 #include "volFields.H"
29 #include "addToRunTimeSelectionTable.H"
30 #include "fvPatchFieldMapper.H"
31 #include "surfaceFields.H"
33 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
35 Foam::
36 flowRateInletVelocityFvPatchVectorField::
37 flowRateInletVelocityFvPatchVectorField
39     const fvPatch& p,
40     const DimensionedField<vector, volMesh>& iF
43     fixedValueFvPatchField<vector>(p, iF),
44     flowRate_(0),
45     phiName_("phi"),
46     rhoName_("rho")
50 Foam::
51 flowRateInletVelocityFvPatchVectorField::
52 flowRateInletVelocityFvPatchVectorField
54     const flowRateInletVelocityFvPatchVectorField& ptf,
55     const fvPatch& p,
56     const DimensionedField<vector, volMesh>& iF,
57     const fvPatchFieldMapper& mapper
60     fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
61     flowRate_(ptf.flowRate_),
62     phiName_(ptf.phiName_),
63     rhoName_(ptf.rhoName_)
67 Foam::
68 flowRateInletVelocityFvPatchVectorField::
69 flowRateInletVelocityFvPatchVectorField
71     const fvPatch& p,
72     const DimensionedField<vector, volMesh>& iF,
73     const dictionary& dict
76     fixedValueFvPatchField<vector>(p, iF, dict),
77     flowRate_(readScalar(dict.lookup("flowRate"))),
78     phiName_("phi"),
79     rhoName_("rho")
81     if (dict.found("phi"))
82     {
83         dict.lookup("phi") >> phiName_;
84     }
86     if (dict.found("rho"))
87     {
88         dict.lookup("rho") >> rhoName_;
89     }
93 Foam::
94 flowRateInletVelocityFvPatchVectorField::
95 flowRateInletVelocityFvPatchVectorField
97     const flowRateInletVelocityFvPatchVectorField& ptf
100     fixedValueFvPatchField<vector>(ptf),
101     flowRate_(ptf.flowRate_),
102     phiName_(ptf.phiName_),
103     rhoName_(ptf.rhoName_)
107 Foam::
108 flowRateInletVelocityFvPatchVectorField::
109 flowRateInletVelocityFvPatchVectorField
111     const flowRateInletVelocityFvPatchVectorField& ptf,
112     const DimensionedField<vector, volMesh>& iF
115     fixedValueFvPatchField<vector>(ptf, iF),
116     flowRate_(ptf.flowRate_),
117     phiName_(ptf.phiName_),
118     rhoName_(ptf.rhoName_)
122 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
124 void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs()
126     if (updated())
127     {
128         return;
129     }
131     // a simpler way of doing this would be nice
132     scalar avgU = -flowRate_/gSum(patch().magSf());
134     vectorField n = patch().nf();
136     const surfaceScalarField& phi = db().lookupObject<surfaceScalarField>
137     (
138         phiName_
139     );
141     if (phi.dimensions() == dimVelocity*dimArea)
142     {
143         // volumetric flow-rate
144         operator==(n*avgU);
145     }
146     else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
147     {
148         const fvPatchField<scalar>& rhop =
149             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
151         // mass flow-rate
152         operator==(n*avgU/rhop);
153     }
154     else
155     {
156         FatalErrorIn
157         (
158             "flowRateInletVelocityFvPatchVectorField::updateCoeffs()"
159         )   << "dimensions of " << phiName_ << " are incorrect" << nl
160             << "    on patch " << this->patch().name()
161             << " of field " << this->dimensionedInternalField().name()
162             << " in file " << this->dimensionedInternalField().objectPath()
163             << nl << exit(FatalError);
164     }
166     fixedValueFvPatchField<vector>::updateCoeffs();
170 void Foam::flowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
172     fvPatchField<vector>::write(os);
174     os.writeKeyword("flowRate") << flowRate_
175         << token::END_STATEMENT << nl;
177     if (phiName_ != "phi")
178     {
179         os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
180     }
182     if (rhoName_ != "rho")
183     {
184         os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
185     }
187     writeEntry("value", os);
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 namespace Foam
195    makePatchTypeField
196    (
197        fvPatchVectorField,
198        flowRateInletVelocityFvPatchVectorField
199    );
203 // ************************************************************************* //