1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "fixedFluxPressureFvPatchScalarField.H"
27 #include "fvPatchFieldMapper.H"
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
37 const DimensionedField<scalar, volMesh>& iF
40 fixedGradientFvPatchScalarField(p, iF),
48 Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
50 const fixedFluxPressureFvPatchScalarField& ptf,
52 const DimensionedField<scalar, volMesh>& iF,
53 const fvPatchFieldMapper& mapper
56 fixedGradientFvPatchScalarField(ptf, p, iF, mapper),
58 phiName_(ptf.phiName_),
59 rhoName_(ptf.rhoName_),
60 adjoint_(ptf.adjoint_)
64 Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
67 const DimensionedField<scalar, volMesh>& iF,
68 const dictionary& dict
71 fixedGradientFvPatchScalarField(p, iF),
72 UName_(dict.lookupOrDefault<word>("U", "U")),
73 phiName_(dict.lookupOrDefault<word>("phi", "phi")),
74 rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
75 adjoint_(dict.lookup("adjoint"))
77 if (dict.found("gradient"))
79 gradient() = scalarField("gradient", dict, p.size());
80 fixedGradientFvPatchScalarField::updateCoeffs();
81 fixedGradientFvPatchScalarField::evaluate();
85 fvPatchField<scalar>::operator=(patchInternalField());
91 Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
93 const fixedFluxPressureFvPatchScalarField& wbppsf
96 fixedGradientFvPatchScalarField(wbppsf),
97 UName_(wbppsf.UName_),
98 phiName_(wbppsf.phiName_),
99 rhoName_(wbppsf.rhoName_),
100 adjoint_(wbppsf.adjoint_)
104 Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
106 const fixedFluxPressureFvPatchScalarField& wbppsf,
107 const DimensionedField<scalar, volMesh>& iF
110 fixedGradientFvPatchScalarField(wbppsf, iF),
111 UName_(wbppsf.UName_),
112 phiName_(wbppsf.phiName_),
113 rhoName_(wbppsf.rhoName_),
114 adjoint_(wbppsf.adjoint_)
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 void Foam::fixedFluxPressureFvPatchScalarField::updateCoeffs()
127 const fvPatchField<vector>& Up =
128 patch().lookupPatchField<volVectorField, vector>(UName_);
130 const surfaceScalarField& phi =
131 db().lookupObject<surfaceScalarField>(phiName_);
133 fvsPatchField<scalar> phip =
134 patch().patchField<surfaceScalarField, scalar>(phi);
136 if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
138 const fvPatchField<scalar>& rhop =
139 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
144 const fvPatchField<scalar>& rAp =
145 patch().lookupPatchField<volScalarField, scalar>("(1|A("+UName_+"))");
149 gradient() = ((patch().Sf() & Up) - phip)/patch().magSf()/rAp;
153 gradient() = (phip - (patch().Sf() & Up))/patch().magSf()/rAp;
156 fixedGradientFvPatchScalarField::updateCoeffs();
160 void Foam::fixedFluxPressureFvPatchScalarField::write(Ostream& os) const
162 fvPatchScalarField::write(os);
163 writeEntryIfDifferent<word>(os, "U", "U", UName_);
164 writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
165 writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
166 os.writeKeyword("adjoint") << adjoint_ << token::END_STATEMENT << nl;
167 gradient().writeEntry("gradient", os);
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 fixedFluxPressureFvPatchScalarField
182 // ************************************************************************* //