1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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 "fanPressureFvPatchScalarField.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "volFields.H"
29 #include "surfaceFields.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 fanPressureFvPatchScalarField::fanFlowDirection,
49 Foam::fanPressureFvPatchScalarField::fanFlowDirection,
51 > Foam::fanPressureFvPatchScalarField::fanFlowDirectionNames_;
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField
59 const DimensionedField<scalar, volMesh>& iF
62 totalPressureFvPatchScalarField(p, iF),
68 Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField
70 const fanPressureFvPatchScalarField& ptf,
72 const DimensionedField<scalar, volMesh>& iF,
73 const fvPatchFieldMapper& mapper
76 totalPressureFvPatchScalarField(ptf, p, iF, mapper),
77 fanCurve_(ptf.fanCurve_),
78 direction_(ptf.direction_)
82 Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField
85 const DimensionedField<scalar, volMesh>& iF,
86 const dictionary& dict
89 totalPressureFvPatchScalarField(p, iF, dict),
91 direction_(fanFlowDirectionNames_.read(dict.lookup("direction")))
95 Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField
97 const fanPressureFvPatchScalarField& pfopsf
100 totalPressureFvPatchScalarField(pfopsf),
101 fanCurve_(pfopsf.fanCurve_),
102 direction_(pfopsf.direction_)
106 Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField
108 const fanPressureFvPatchScalarField& pfopsf,
109 const DimensionedField<scalar, volMesh>& iF
112 totalPressureFvPatchScalarField(pfopsf, iF),
113 fanCurve_(pfopsf.fanCurve_),
114 direction_(pfopsf.direction_)
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 void Foam::fanPressureFvPatchScalarField::updateCoeffs()
127 // Retrieve flux field
128 const surfaceScalarField& phi =
129 db().lookupObject<surfaceScalarField>(phiName());
131 const fvsPatchField<scalar>& phip =
132 patch().patchField<surfaceScalarField, scalar>(phi);
134 int dir = 2*direction_ - 1;
136 // Average volumetric flow rate
137 scalar aveFlowRate = 0;
139 if (phi.dimensions() == dimVelocity*dimArea)
141 aveFlowRate = dir*gSum(phip)/gSum(patch().magSf());
143 else if (phi.dimensions() == dimVelocity*dimArea*dimDensity)
145 const scalarField& rhop =
146 patch().lookupPatchField<volScalarField, scalar>(rhoName());
147 aveFlowRate = dir*gSum(phip/rhop)/gSum(patch().magSf());
151 FatalErrorIn("fanPressureFvPatchScalarField::updateCoeffs()")
152 << "dimensions of phi are not correct"
153 << "\n on patch " << patch().name()
154 << " of field " << dimensionedInternalField().name()
155 << " in file " << dimensionedInternalField().objectPath() << nl
159 // Pressure drop for this flow rate
160 const scalar pdFan = fanCurve_(max(aveFlowRate, 0.0));
162 totalPressureFvPatchScalarField::updateCoeffs
165 patch().lookupPatchField<volVectorField, vector>(UName())
170 void Foam::fanPressureFvPatchScalarField::write(Ostream& os) const
172 totalPressureFvPatchScalarField::write(os);
174 os.writeKeyword("direction")
175 << fanFlowDirectionNames_[direction_] << token::END_STATEMENT << nl;
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 fanPressureFvPatchScalarField
191 // ************************************************************************* //