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

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