FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "flowRateInletVelocityFvPatchVectorField.H"
00027 #include <finiteVolume/volFields.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029 #include <finiteVolume/fvPatchFieldMapper.H>
00030 #include <finiteVolume/surfaceFields.H>
00031 
00032 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00033 
00034 Foam::
00035 flowRateInletVelocityFvPatchVectorField::
00036 flowRateInletVelocityFvPatchVectorField
00037 (
00038     const fvPatch& p,
00039     const DimensionedField<vector, volMesh>& iF
00040 )
00041 :
00042     fixedValueFvPatchField<vector>(p, iF),
00043     flowRate_(0),
00044     phiName_("phi"),
00045     rhoName_("rho")
00046 {}
00047 
00048 
00049 Foam::
00050 flowRateInletVelocityFvPatchVectorField::
00051 flowRateInletVelocityFvPatchVectorField
00052 (
00053     const flowRateInletVelocityFvPatchVectorField& ptf,
00054     const fvPatch& p,
00055     const DimensionedField<vector, volMesh>& iF,
00056     const fvPatchFieldMapper& mapper
00057 )
00058 :
00059     fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
00060     flowRate_(ptf.flowRate_),
00061     phiName_(ptf.phiName_),
00062     rhoName_(ptf.rhoName_)
00063 {}
00064 
00065 
00066 Foam::
00067 flowRateInletVelocityFvPatchVectorField::
00068 flowRateInletVelocityFvPatchVectorField
00069 (
00070     const fvPatch& p,
00071     const DimensionedField<vector, volMesh>& iF,
00072     const dictionary& dict
00073 )
00074 :
00075     fixedValueFvPatchField<vector>(p, iF, dict),
00076     flowRate_(readScalar(dict.lookup("flowRate"))),
00077     phiName_(dict.lookupOrDefault<word>("phi", "phi")),
00078     rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
00079 {}
00080 
00081 
00082 Foam::
00083 flowRateInletVelocityFvPatchVectorField::
00084 flowRateInletVelocityFvPatchVectorField
00085 (
00086     const flowRateInletVelocityFvPatchVectorField& ptf
00087 )
00088 :
00089     fixedValueFvPatchField<vector>(ptf),
00090     flowRate_(ptf.flowRate_),
00091     phiName_(ptf.phiName_),
00092     rhoName_(ptf.rhoName_)
00093 {}
00094 
00095 
00096 Foam::
00097 flowRateInletVelocityFvPatchVectorField::
00098 flowRateInletVelocityFvPatchVectorField
00099 (
00100     const flowRateInletVelocityFvPatchVectorField& ptf,
00101     const DimensionedField<vector, volMesh>& iF
00102 )
00103 :
00104     fixedValueFvPatchField<vector>(ptf, iF),
00105     flowRate_(ptf.flowRate_),
00106     phiName_(ptf.phiName_),
00107     rhoName_(ptf.rhoName_)
00108 {}
00109 
00110 
00111 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00112 
00113 void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs()
00114 {
00115     if (updated())
00116     {
00117         return;
00118     }
00119 
00120     // a simpler way of doing this would be nice
00121     scalar avgU = -flowRate_/gSum(patch().magSf());
00122 
00123     vectorField n = patch().nf();
00124 
00125     const surfaceScalarField& phi =
00126         db().lookupObject<surfaceScalarField>(phiName_);
00127 
00128     if (phi.dimensions() == dimVelocity*dimArea)
00129     {
00130         // volumetric flow-rate
00131         operator==(n*avgU);
00132     }
00133     else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
00134     {
00135         const fvPatchField<scalar>& rhop =
00136             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
00137 
00138         // mass flow-rate
00139         operator==(n*avgU/rhop);
00140     }
00141     else
00142     {
00143         FatalErrorIn
00144         (
00145             "flowRateInletVelocityFvPatchVectorField::updateCoeffs()"
00146         )   << "dimensions of " << phiName_ << " are incorrect" << nl
00147             << "    on patch " << this->patch().name()
00148             << " of field " << this->dimensionedInternalField().name()
00149             << " in file " << this->dimensionedInternalField().objectPath()
00150             << nl << exit(FatalError);
00151     }
00152 
00153     fixedValueFvPatchField<vector>::updateCoeffs();
00154 }
00155 
00156 
00157 void Foam::flowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
00158 {
00159     fvPatchField<vector>::write(os);
00160     os.writeKeyword("flowRate") << flowRate_ << token::END_STATEMENT << nl;
00161     if (phiName_ != "phi")
00162     {
00163         os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
00164     }
00165     if (rhoName_ != "rho")
00166     {
00167         os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
00168     }
00169     writeEntry("value", os);
00170 }
00171 
00172 
00173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00174 
00175 namespace Foam
00176 {
00177    makePatchTypeField
00178    (
00179        fvPatchVectorField,
00180        flowRateInletVelocityFvPatchVectorField
00181    );
00182 }
00183 
00184 
00185 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines