1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 "flowRateInletVelocityFvPatchVectorField.H"
28 #include "volFields.H"
29 #include "addToRunTimeSelectionTable.H"
30 #include "fvPatchFieldMapper.H"
31 #include "surfaceFields.H"
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 flowRateInletVelocityFvPatchVectorField::
37 flowRateInletVelocityFvPatchVectorField
40 const DimensionedField<vector, volMesh>& iF
43 fixedValueFvPatchField<vector>(p, iF),
51 flowRateInletVelocityFvPatchVectorField::
52 flowRateInletVelocityFvPatchVectorField
54 const flowRateInletVelocityFvPatchVectorField& ptf,
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_)
68 flowRateInletVelocityFvPatchVectorField::
69 flowRateInletVelocityFvPatchVectorField
72 const DimensionedField<vector, volMesh>& iF,
73 const dictionary& dict
76 fixedValueFvPatchField<vector>(p, iF, dict),
77 flowRate_(readScalar(dict.lookup("flowRate"))),
78 phiName_(dict.lookupOrDefault<word>("phi", "phi")),
79 rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
84 flowRateInletVelocityFvPatchVectorField::
85 flowRateInletVelocityFvPatchVectorField
87 const flowRateInletVelocityFvPatchVectorField& ptf
90 fixedValueFvPatchField<vector>(ptf),
91 flowRate_(ptf.flowRate_),
92 phiName_(ptf.phiName_),
93 rhoName_(ptf.rhoName_)
98 flowRateInletVelocityFvPatchVectorField::
99 flowRateInletVelocityFvPatchVectorField
101 const flowRateInletVelocityFvPatchVectorField& ptf,
102 const DimensionedField<vector, volMesh>& iF
105 fixedValueFvPatchField<vector>(ptf, iF),
106 flowRate_(ptf.flowRate_),
107 phiName_(ptf.phiName_),
108 rhoName_(ptf.rhoName_)
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs()
121 // a simpler way of doing this would be nice
122 scalar avgU = -flowRate_/gSum(patch().magSf());
124 vectorField n = patch().nf();
126 const surfaceScalarField& phi =
127 db().lookupObject<surfaceScalarField>(phiName_);
129 if (phi.dimensions() == dimVelocity*dimArea)
131 // volumetric flow-rate
134 else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
136 const fvPatchField<scalar>& rhop =
137 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
140 operator==(n*avgU/rhop);
146 "flowRateInletVelocityFvPatchVectorField::updateCoeffs()"
147 ) << "dimensions of " << phiName_ << " are incorrect" << nl
148 << " on patch " << this->patch().name()
149 << " of field " << this->dimensionedInternalField().name()
150 << " in file " << this->dimensionedInternalField().objectPath()
151 << nl << exit(FatalError);
154 fixedValueFvPatchField<vector>::updateCoeffs();
158 void Foam::flowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
160 fvPatchField<vector>::write(os);
161 os.writeKeyword("flowRate") << flowRate_ << token::END_STATEMENT << nl;
162 if (phiName_ != "phi")
164 os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
166 if (rhoName_ != "rho")
168 os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
170 writeEntry("value", os);
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 flowRateInletVelocityFvPatchVectorField
186 // ************************************************************************* //