Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / finiteVolume / fields / fvPatchFields / derived / buoyantPressure / buoyantPressureFvPatchScalarField.C
blob5a0952e57a104d279a98a28626b90d05da8cd4e5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "buoyantPressureFvPatchScalarField.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #include "uniformDimensionedFields.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
37 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
39 buoyantPressureFvPatchScalarField::
40 buoyantPressureFvPatchScalarField
42     const fvPatch& p,
43     const DimensionedField<scalar, volMesh>& iF
46     fixedGradientFvPatchScalarField(p, iF),
47     rhoName_("rho")
51 buoyantPressureFvPatchScalarField::
52 buoyantPressureFvPatchScalarField
54     const fvPatch& p,
55     const DimensionedField<scalar, volMesh>& iF,
56     const dictionary& dict
59     fixedGradientFvPatchScalarField(p, iF),
60     rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
62     fvPatchField<scalar>::operator=(patchInternalField());
63     gradient() = 0.0;
67 buoyantPressureFvPatchScalarField::
68 buoyantPressureFvPatchScalarField
70     const buoyantPressureFvPatchScalarField& ptf,
71     const fvPatch& p,
72     const DimensionedField<scalar, volMesh>& iF,
73     const fvPatchFieldMapper& mapper
76     fixedGradientFvPatchScalarField(ptf, p, iF, mapper),
77     rhoName_(ptf.rhoName_)
81 buoyantPressureFvPatchScalarField::
82 buoyantPressureFvPatchScalarField
84     const buoyantPressureFvPatchScalarField& ptf
87     fixedGradientFvPatchScalarField(ptf),
88     rhoName_(ptf.rhoName_)
92 buoyantPressureFvPatchScalarField::
93 buoyantPressureFvPatchScalarField
95     const buoyantPressureFvPatchScalarField& ptf,
96     const DimensionedField<scalar, volMesh>& iF
99     fixedGradientFvPatchScalarField(ptf, iF),
100     rhoName_(ptf.rhoName_)
104 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
106 void buoyantPressureFvPatchScalarField::updateCoeffs()
108     if (updated())
109     {
110         return;
111     }
113     // If variables are not found, evaluate as zero gradient
114     // HJ, 17/Jan/2012
115     if
116     (
117         !db().foundObject<uniformDimensionedVectorField>("g")
118      || !db().foundObject<volScalarField>(rhoName_)
119     )
120     {
121         InfoIn
122         (
123             "void buoyantPressureFvPatchScalarField::updateCoeffs()"
124         )   << "Fields required for evaluation not found for patch "
125             << patch().name() << endl;
127         gradient() = 0;
128         fixedGradientFvPatchScalarField::updateCoeffs();
130         return;
131     }
133     const uniformDimensionedVectorField& g =
134         db().lookupObject<uniformDimensionedVectorField>("g");
136     const fvPatchField<scalar>& rho =
137         lookupPatchField<volScalarField, scalar>(rhoName_);
139     // If the variable name is "p_rgh" or "pd" assume it is p - rho*g.h
140     // and set the gradient appropriately.
141     // Otherwise assume the variable is the static pressure.
142     if
143     (
144         dimensionedInternalField().name() == "p_rgh"
145      || dimensionedInternalField().name() == "pd"
146     )
147     {
148         gradient() = -rho.snGrad()*(g.value() & patch().Cf());
149     }
150     else
151     {
152         gradient() = rho*(g.value() & patch().nf());
153     }
155     fixedGradientFvPatchScalarField::updateCoeffs();
159 void buoyantPressureFvPatchScalarField::write(Ostream& os) const
161     fixedGradientFvPatchScalarField::write(os);
162     os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
163     writeEntry("value", os);
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 makePatchTypeField
171     fvPatchScalarField,
172     buoyantPressureFvPatchScalarField
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 } // End namespace Foam
179 // ************************************************************************* //