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

fixedFluxPressureFvPatchScalarField.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) 1991-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 "fixedFluxPressureFvPatchScalarField.H"
00027 #include <finiteVolume/fvPatchFieldMapper.H>
00028 #include <finiteVolume/volFields.H>
00029 #include <finiteVolume/surfaceFields.H>
00030 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00031 
00032 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00033 
00034 Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
00035 (
00036     const fvPatch& p,
00037     const DimensionedField<scalar, volMesh>& iF
00038 )
00039 :
00040     fixedGradientFvPatchScalarField(p, iF),
00041     UName_("U"),
00042     phiName_("phi"),
00043     rhoName_("rho"),
00044     adjoint_(false)
00045 {}
00046 
00047 
00048 Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
00049 (
00050     const fixedFluxPressureFvPatchScalarField& ptf,
00051     const fvPatch& p,
00052     const DimensionedField<scalar, volMesh>& iF,
00053     const fvPatchFieldMapper& mapper
00054 )
00055 :
00056     fixedGradientFvPatchScalarField(ptf, p, iF, mapper),
00057     UName_(ptf.UName_),
00058     phiName_(ptf.phiName_),
00059     rhoName_(ptf.rhoName_),
00060     adjoint_(ptf.adjoint_)
00061 {}
00062 
00063 
00064 Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
00065 (
00066     const fvPatch& p,
00067     const DimensionedField<scalar, volMesh>& iF,
00068     const dictionary& dict
00069 )
00070 :
00071     fixedGradientFvPatchScalarField(p, iF),
00072     UName_(dict.lookupOrDefault<word>("U", "U")),
00073     phiName_(dict.lookupOrDefault<word>("phi", "phi")),
00074     rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
00075     adjoint_(dict.lookup("adjoint"))
00076 {
00077     if (dict.found("gradient"))
00078     {
00079         gradient() = scalarField("gradient", dict, p.size());
00080         fixedGradientFvPatchScalarField::updateCoeffs();
00081         fixedGradientFvPatchScalarField::evaluate();
00082     }
00083     else
00084     {
00085         fvPatchField<scalar>::operator=(patchInternalField());
00086         gradient() = 0.0;
00087     }
00088 }
00089 
00090 
00091 Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
00092 (
00093     const fixedFluxPressureFvPatchScalarField& wbppsf
00094 )
00095 :
00096     fixedGradientFvPatchScalarField(wbppsf),
00097     UName_(wbppsf.UName_),
00098     phiName_(wbppsf.phiName_),
00099     rhoName_(wbppsf.rhoName_),
00100     adjoint_(wbppsf.adjoint_)
00101 {}
00102 
00103 
00104 Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
00105 (
00106     const fixedFluxPressureFvPatchScalarField& wbppsf,
00107     const DimensionedField<scalar, volMesh>& iF
00108 )
00109 :
00110     fixedGradientFvPatchScalarField(wbppsf, iF),
00111     UName_(wbppsf.UName_),
00112     phiName_(wbppsf.phiName_),
00113     rhoName_(wbppsf.rhoName_),
00114     adjoint_(wbppsf.adjoint_)
00115 {}
00116 
00117 
00118 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00119 
00120 void Foam::fixedFluxPressureFvPatchScalarField::updateCoeffs()
00121 {
00122     if (updated())
00123     {
00124         return;
00125     }
00126 
00127     const fvPatchField<vector>& Up =
00128         patch().lookupPatchField<volVectorField, vector>(UName_);
00129 
00130     const surfaceScalarField& phi =
00131         db().lookupObject<surfaceScalarField>(phiName_);
00132 
00133     fvsPatchField<scalar> phip =
00134         patch().patchField<surfaceScalarField, scalar>(phi);
00135 
00136     if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
00137     {
00138         const fvPatchField<scalar>& rhop =
00139             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
00140 
00141         phip /= rhop;
00142     }
00143 
00144     const fvPatchField<scalar>& rAp =
00145         patch().lookupPatchField<volScalarField, scalar>("(1|A("+UName_+"))");
00146 
00147     if (adjoint_)
00148     {
00149         gradient() = ((patch().Sf() & Up) - phip)/patch().magSf()/rAp;
00150     }
00151     else
00152     {
00153         gradient() = (phip - (patch().Sf() & Up))/patch().magSf()/rAp;
00154     }
00155 
00156     fixedGradientFvPatchScalarField::updateCoeffs();
00157 }
00158 
00159 
00160 void Foam::fixedFluxPressureFvPatchScalarField::write(Ostream& os) const
00161 {
00162     fvPatchScalarField::write(os);
00163     if (UName_ != "U")
00164     {
00165         os.writeKeyword("U") << UName_ << token::END_STATEMENT << nl;
00166     }
00167     if (phiName_ != "phi")
00168     {
00169         os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
00170     }
00171     if (rhoName_ != "rho")
00172     {
00173         os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
00174     }
00175     os.writeKeyword("adjoint") << adjoint_ << token::END_STATEMENT << nl;
00176     gradient().writeEntry("gradient", os);
00177 }
00178 
00179 
00180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00181 
00182 namespace Foam
00183 {
00184     makePatchTypeField
00185     (
00186         fvPatchScalarField,
00187         fixedFluxPressureFvPatchScalarField
00188     );
00189 }
00190 
00191 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines