BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / finiteVolume / fields / fvPatchFields / derived / fanPressure / fanPressureFvPatchScalarField.C
blob9cf87f4f9586c1d1aff7dc04241dbc38446651f2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
35     template<>
36     const char* NamedEnum
37     <
38         fanPressureFvPatchScalarField::fanFlowDirection,
39         2
40     >::names[] =
41     {
42         "in",
43         "out"
44     };
47 const Foam::NamedEnum
49     Foam::fanPressureFvPatchScalarField::fanFlowDirection,
50     2
51 > Foam::fanPressureFvPatchScalarField::fanFlowDirectionNames_;
54 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
56 Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField
58     const fvPatch& p,
59     const DimensionedField<scalar, volMesh>& iF
62     totalPressureFvPatchScalarField(p, iF),
63     fanCurve_(),
64     direction_(ffdOut)
68 Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField
70     const fanPressureFvPatchScalarField& ptf,
71     const fvPatch& p,
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
84     const fvPatch& p,
85     const DimensionedField<scalar, volMesh>& iF,
86     const dictionary& dict
89     totalPressureFvPatchScalarField(p, iF, dict),
90     fanCurve_(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()
122     if (updated())
123     {
124         return;
125     }
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)
140     {
141         aveFlowRate = dir*gSum(phip)/gSum(patch().magSf());
142     }
143     else if (phi.dimensions() == dimVelocity*dimArea*dimDensity)
144     {
145         const scalarField& rhop =
146             patch().lookupPatchField<volScalarField, scalar>(rhoName());
147         aveFlowRate = dir*gSum(phip/rhop)/gSum(patch().magSf());
148     }
149     else
150     {
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
156                 << exit(FatalError);
157     }
159     // Pressure drop for this flow rate
160     const scalar pdFan = fanCurve_(max(aveFlowRate, 0.0));
162     totalPressureFvPatchScalarField::updateCoeffs
163     (
164         p0() - dir*pdFan,
165         patch().lookupPatchField<volVectorField, vector>(UName())
166     );
170 void Foam::fanPressureFvPatchScalarField::write(Ostream& os) const
172     totalPressureFvPatchScalarField::write(os);
173     fanCurve_.write(os);
174     os.writeKeyword("direction")
175         << fanFlowDirectionNames_[direction_] << token::END_STATEMENT << nl;
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 namespace Foam
183     makePatchTypeField
184     (
185         fvPatchScalarField,
186         fanPressureFvPatchScalarField
187     );
191 // ************************************************************************* //