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

swirlFlowRateInletVelocityFvPatchVectorField.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) 2010-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 "swirlFlowRateInletVelocityFvPatchVectorField.H"
00027 #include <finiteVolume/volFields.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029 #include <finiteVolume/fvPatchFieldMapper.H>
00030 #include <finiteVolume/surfaceFields.H>
00031 #include <OpenFOAM/mathematicalConstants.H>
00032 
00033 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00034 
00035 Foam::
00036 swirlFlowRateInletVelocityFvPatchVectorField::
00037 swirlFlowRateInletVelocityFvPatchVectorField
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     rpm_(0)
00048 {}
00049 
00050 
00051 Foam::
00052 swirlFlowRateInletVelocityFvPatchVectorField::
00053 swirlFlowRateInletVelocityFvPatchVectorField
00054 (
00055     const swirlFlowRateInletVelocityFvPatchVectorField& ptf,
00056     const fvPatch& p,
00057     const DimensionedField<vector, volMesh>& iF,
00058     const fvPatchFieldMapper& mapper
00059 )
00060 :
00061     fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
00062     flowRate_(ptf.flowRate_),
00063     phiName_(ptf.phiName_),
00064     rhoName_(ptf.rhoName_),
00065     rpm_(ptf.rpm_)
00066 {}
00067 
00068 
00069 Foam::
00070 swirlFlowRateInletVelocityFvPatchVectorField::
00071 swirlFlowRateInletVelocityFvPatchVectorField
00072 (
00073     const fvPatch& p,
00074     const DimensionedField<vector, volMesh>& iF,
00075     const dictionary& dict
00076 )
00077 :
00078     fixedValueFvPatchField<vector>(p, iF, dict),
00079     flowRate_(readScalar(dict.lookup("flowRate"))),
00080     phiName_(dict.lookupOrDefault<word>("phi", "phi")),
00081     rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
00082     rpm_(readScalar(dict.lookup("rpm")))
00083 {}
00084 
00085 
00086 Foam::
00087 swirlFlowRateInletVelocityFvPatchVectorField::
00088 swirlFlowRateInletVelocityFvPatchVectorField
00089 (
00090     const swirlFlowRateInletVelocityFvPatchVectorField& ptf
00091 )
00092 :
00093     fixedValueFvPatchField<vector>(ptf),
00094     flowRate_(ptf.flowRate_),
00095     phiName_(ptf.phiName_),
00096     rhoName_(ptf.rhoName_),
00097     rpm_(ptf.rpm_)
00098 {}
00099 
00100 
00101 Foam::
00102 swirlFlowRateInletVelocityFvPatchVectorField::
00103 swirlFlowRateInletVelocityFvPatchVectorField
00104 (
00105     const swirlFlowRateInletVelocityFvPatchVectorField& ptf,
00106     const DimensionedField<vector, volMesh>& iF
00107 )
00108 :
00109     fixedValueFvPatchField<vector>(ptf, iF),
00110     flowRate_(ptf.flowRate_),
00111     phiName_(ptf.phiName_),
00112     rhoName_(ptf.rhoName_),
00113     rpm_(ptf.rpm_)
00114 {}
00115 
00116 
00117 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00118 
00119 void Foam::swirlFlowRateInletVelocityFvPatchVectorField::updateCoeffs()
00120 {
00121     if (updated())
00122     {
00123         return;
00124     }
00125 
00126     const scalar totArea   = gSum(patch().magSf());
00127     // a simpler way of doing this would be nice
00128     const scalar avgU = -flowRate_/totArea;
00129 
00130     const vector avgCenter = gSum(patch().Cf()*patch().magSf())/totArea;
00131     const vector avgNormal = gSum(patch().Sf())/totArea;
00132 
00133     // Update angular velocity - convert [rpm] to [rad/s]
00134     vectorField tangentialVelocity =
00135     (
00136         (rpm_*mathematicalConstant::pi/30.0)
00137       * (patch().Cf() - avgCenter) ^ avgNormal
00138     );
00139 
00140     tmp<vectorField> n = patch().nf();
00141 
00142     const surfaceScalarField& phi =
00143         db().lookupObject<surfaceScalarField>(phiName_);
00144 
00145     if (phi.dimensions() == dimVelocity*dimArea)
00146     {
00147         // volumetric flow-rate
00148         operator==(tangentialVelocity + n*avgU);
00149     }
00150     else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
00151     {
00152         const fvPatchField<scalar>& rhop =
00153             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
00154 
00155         // mass flow-rate
00156         operator==(tangentialVelocity + n*avgU/rhop);
00157     }
00158     else
00159     {
00160         FatalErrorIn
00161         (
00162             "swirlFlowRateInletVelocityFvPatchVectorField::updateCoeffs()"
00163         )   << "dimensions of " << phiName_ << " are incorrect" << nl
00164             << "    on patch " << this->patch().name()
00165             << " of field " << this->dimensionedInternalField().name()
00166             << " in file " << this->dimensionedInternalField().objectPath()
00167             << nl << exit(FatalError);
00168     }
00169 
00170     fixedValueFvPatchField<vector>::updateCoeffs();
00171 }
00172 
00173 
00174 void Foam::swirlFlowRateInletVelocityFvPatchVectorField::write
00175 (
00176     Ostream& os
00177 ) const
00178 {
00179     fvPatchField<vector>::write(os);
00180     os.writeKeyword("flowRate") << flowRate_ << token::END_STATEMENT << nl;
00181     writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
00182     writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
00183     os.writeKeyword("rpm") << rpm_ << token::END_STATEMENT << nl;
00184     writeEntry("value", os);
00185 }
00186 
00187 
00188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00189 
00190 namespace Foam
00191 {
00192    makePatchTypeField
00193    (
00194        fvPatchVectorField,
00195        swirlFlowRateInletVelocityFvPatchVectorField
00196    );
00197 }
00198 
00199 
00200 // ************************************************************************* //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines