OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

flowRateInletVelocityFvPatchVectorField.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 2006-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "flowRateInletVelocityFvPatchVectorField.H"
00028 #include "volFields.H"
00029 #include "addToRunTimeSelectionTable.H"
00030 #include "fvPatchFieldMapper.H"
00031 #include "surfaceFields.H"
00032 
00033 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00034 
00035 Foam::
00036 flowRateInletVelocityFvPatchVectorField::
00037 flowRateInletVelocityFvPatchVectorField
00038 (
00039     const fvPatch& p,
00040     const DimensionedField<vector, volMesh>& iF
00041 )
00042 :
00043     fixedValueFvPatchField<vector>(p, iF),
00044     flowRate_(0),
00045     phiName_("phi"),
00046     rhoName_("rho")
00047 {}
00048 
00049 
00050 Foam::
00051 flowRateInletVelocityFvPatchVectorField::
00052 flowRateInletVelocityFvPatchVectorField
00053 (
00054     const flowRateInletVelocityFvPatchVectorField& ptf,
00055     const fvPatch& p,
00056     const DimensionedField<vector, volMesh>& iF,
00057     const fvPatchFieldMapper& mapper
00058 )
00059 :
00060     fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
00061     flowRate_(ptf.flowRate_),
00062     phiName_(ptf.phiName_),
00063     rhoName_(ptf.rhoName_)
00064 {}
00065 
00066 
00067 Foam::
00068 flowRateInletVelocityFvPatchVectorField::
00069 flowRateInletVelocityFvPatchVectorField
00070 (
00071     const fvPatch& p,
00072     const DimensionedField<vector, volMesh>& iF,
00073     const dictionary& dict
00074 )
00075 :
00076     fixedValueFvPatchField<vector>(p, iF, dict),
00077     flowRate_(readScalar(dict.lookup("flowRate"))),
00078     phiName_(dict.lookupOrDefault<word>("phi", "phi")),
00079     rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
00080 {}
00081 
00082 
00083 Foam::
00084 flowRateInletVelocityFvPatchVectorField::
00085 flowRateInletVelocityFvPatchVectorField
00086 (
00087     const flowRateInletVelocityFvPatchVectorField& ptf
00088 )
00089 :
00090     fixedValueFvPatchField<vector>(ptf),
00091     flowRate_(ptf.flowRate_),
00092     phiName_(ptf.phiName_),
00093     rhoName_(ptf.rhoName_)
00094 {}
00095 
00096 
00097 Foam::
00098 flowRateInletVelocityFvPatchVectorField::
00099 flowRateInletVelocityFvPatchVectorField
00100 (
00101     const flowRateInletVelocityFvPatchVectorField& ptf,
00102     const DimensionedField<vector, volMesh>& iF
00103 )
00104 :
00105     fixedValueFvPatchField<vector>(ptf, iF),
00106     flowRate_(ptf.flowRate_),
00107     phiName_(ptf.phiName_),
00108     rhoName_(ptf.rhoName_)
00109 {}
00110 
00111 
00112 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00113 
00114 void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs()
00115 {
00116     if (updated())
00117     {
00118         return;
00119     }
00120 
00121     // a simpler way of doing this would be nice
00122     scalar avgU = -flowRate_/gSum(patch().magSf());
00123 
00124     vectorField n = patch().nf();
00125 
00126     const surfaceScalarField& phi =
00127         db().lookupObject<surfaceScalarField>(phiName_);
00128 
00129     if (phi.dimensions() == dimVelocity*dimArea)
00130     {
00131         // volumetric flow-rate
00132         operator==(n*avgU);
00133     }
00134     else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
00135     {
00136         const fvPatchField<scalar>& rhop =
00137             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
00138 
00139         // mass flow-rate
00140         operator==(n*avgU/rhop);
00141     }
00142     else
00143     {
00144         FatalErrorIn
00145         (
00146             "flowRateInletVelocityFvPatchVectorField::updateCoeffs()"
00147         )   << "dimensions of " << phiName_ << " are incorrect" << nl
00148             << "    on patch " << this->patch().name()
00149             << " of field " << this->dimensionedInternalField().name()
00150             << " in file " << this->dimensionedInternalField().objectPath()
00151             << nl << exit(FatalError);
00152     }
00153 
00154     fixedValueFvPatchField<vector>::updateCoeffs();
00155 }
00156 
00157 
00158 void Foam::flowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
00159 {
00160     fvPatchField<vector>::write(os);
00161     os.writeKeyword("flowRate") << flowRate_ << token::END_STATEMENT << nl;
00162     if (phiName_ != "phi")
00163     {
00164         os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
00165     }
00166     if (rhoName_ != "rho")
00167     {
00168         os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
00169     }
00170     writeEntry("value", os);
00171 }
00172 
00173 
00174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00175 
00176 namespace Foam
00177 {
00178    makePatchTypeField
00179    (
00180        fvPatchVectorField,
00181        flowRateInletVelocityFvPatchVectorField
00182    );
00183 }
00184 
00185 
00186 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd