fanPressureFvPatchScalarField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2020 OpenCFD Ltd
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 #include "volFields.H"
32 #include "surfaceFields.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 const Foam::Enum
37 <
39 >
41 ({
42  { fanFlowDirection::ffdIn, "in" },
43  { fanFlowDirection::ffdOut, "out" },
44 });
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 (
51  const fvPatch& p,
53 )
54 :
56  fanCurve_(),
57  direction_(ffdOut),
58  rpm_(0),
59  dm_(0),
60  nonDimensional_(false)
61 {}
62 
63 
65 (
67  const fvPatch& p,
69  const fvPatchFieldMapper& mapper
70 )
71 :
72  totalPressureFvPatchScalarField(ptf, p, iF, mapper),
73  fanCurve_(ptf.fanCurve_),
74  direction_(ptf.direction_),
75  rpm_(ptf.rpm_),
76  dm_(ptf.dm_),
77  nonDimensional_(ptf.nonDimensional_)
78 {}
79 
80 
82 (
83  const fvPatch& p,
85  const dictionary& dict
86 )
87 :
89  fanCurve_(dict),
90  direction_(fanFlowDirectionNames_.get("direction", dict)),
91  rpm_(0),
92  dm_(0),
93  nonDimensional_(dict.getOrDefault("nonDimensional", false))
94 {
95  if (nonDimensional_)
96  {
97  dict.readEntry("rpm", rpm_);
98  dict.readEntry("dm", dm_);
99  }
100 }
101 
102 
104 (
105  const fanPressureFvPatchScalarField& pfopsf
106 )
107 :
109  fanCurve_(pfopsf.fanCurve_),
110  direction_(pfopsf.direction_),
111  rpm_(pfopsf.rpm_),
112  dm_(pfopsf.dm_),
113  nonDimensional_(pfopsf.nonDimensional_)
114 {}
115 
116 
118 (
119  const fanPressureFvPatchScalarField& pfopsf,
121 )
122 :
124  fanCurve_(pfopsf.fanCurve_),
125  direction_(pfopsf.direction_),
126  rpm_(pfopsf.rpm_),
127  dm_(pfopsf.dm_),
128  nonDimensional_(pfopsf.nonDimensional_)
129 {}
130 
131 
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 
135 {
136  if (updated())
137  {
138  return;
139  }
140 
141  // Retrieve flux field
142  const surfaceScalarField& phi =
143  db().lookupObject<surfaceScalarField>(phiName());
144 
145  const fvsPatchField<scalar>& phip =
146  patch().patchField<surfaceScalarField, scalar>(phi);
147 
148  int dir = 2*direction_ - 1;
149 
150  // Average volumetric flow rate
151  scalar volFlowRate = 0;
152 
153  if (phi.dimensions() == dimVelocity*dimArea)
154  {
155  volFlowRate = dir*gSum(phip);
156  }
157  else if (phi.dimensions() == dimVelocity*dimArea*dimDensity)
158  {
159  const scalarField& rhop =
160  patch().lookupPatchField<volScalarField, scalar>(rhoName());
161  volFlowRate = dir*gSum(phip/rhop);
162  }
163  else
164  {
166  << "dimensions of phi are not correct"
167  << "\n on patch " << patch().name()
168  << " of field " << internalField().name()
169  << " in file " << internalField().objectPath() << nl
170  << exit(FatalError);
171  }
172 
173  if (nonDimensional_)
174  {
175  // Create an non-dimensional flow rate
176  volFlowRate =
177  120.0*volFlowRate/pow3(constant::mathematical::pi)/pow3(dm_)/rpm_;
178  }
179 
180  // Pressure drop for this flow rate
181  scalar pdFan = fanCurve_(max(volFlowRate, 0.0));
182 
183  if (nonDimensional_)
184  {
185  // Convert the non-dimensional deltap from curve into deltaP
186  pdFan = pdFan*pow4(constant::mathematical::pi)*sqr(dm_*rpm_)/1800;
187  }
188 
190  (
191  p0() - dir*pdFan,
192  patch().lookupPatchField<volVectorField, vector>(UName())
193  );
194 }
195 
196 
198 {
200  fanCurve_.write(os);
201  os.writeEntry("direction", fanFlowDirectionNames_[direction_]);
202  if (nonDimensional_)
203  {
204  os.writeEntry("nonDimensional", "true");
205  os.writeEntry("rpm", rpm_);
206  os.writeEntry("dm", dm_);
207  }
208 }
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 namespace Foam
214 {
216  (
219  );
220 };
221 
222 
223 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
Foam::fanPressureFvPatchScalarField
This boundary condition can be applied to assign either a pressure inlet or outlet total pressure con...
Definition: fanPressureFvPatchScalarField.H:154
volFields.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::dimVelocity
const dimensionSet dimVelocity
Foam::dimDensity
const dimensionSet dimDensity
Foam::fanPressureFvPatchScalarField::write
virtual void write(Ostream &os) const
Write.
Definition: fanPressureFvPatchScalarField.C:197
Foam::fvsPatchField
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:68
surfaceFields.H
Foam::surfaceFields.
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField
fanPressureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
Definition: fanPressureFvPatchScalarField.C:50
Foam::pow4
dimensionedScalar pow4(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:100
fanPressureFvPatchScalarField.H
Foam::totalPressureFvPatchScalarField
This boundary condition provides a total pressure condition. Four variants are possible:
Definition: totalPressureFvPatchScalarField.H:256
Foam::dimArea
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:60
Foam::Field< scalar >
Foam::pow3
dimensionedScalar pow3(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:89
Foam::totalPressureFvPatchScalarField::phiName
const word & phiName() const
Return the name of the flux field.
Definition: totalPressureFvPatchScalarField.H:368
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::totalPressureFvPatchScalarField::UName
const word & UName() const
Return the name of the velocity field.
Definition: totalPressureFvPatchScalarField.H:355
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::fanPressureFvPatchScalarField::fanFlowDirection
fanFlowDirection
Fan flow direction.
Definition: fanPressureFvPatchScalarField.H:162
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::totalPressureFvPatchScalarField::rhoName
const word & rhoName() const
Return the name of the density field.
Definition: totalPressureFvPatchScalarField.H:381
Foam::totalPressureFvPatchScalarField::p0
const scalarField & p0() const
Return the total pressure.
Definition: totalPressureFvPatchScalarField.H:419
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:372
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::constant::mathematical::pi
constexpr scalar pi(M_PI)
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::surfaceScalarField
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Definition: surfaceFieldsFwd.H:54
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::fanPressureFvPatchScalarField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fanPressureFvPatchScalarField.C:134
Foam::totalPressureFvPatchScalarField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: totalPressureFvPatchScalarField.C:236
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
Foam::totalPressureFvPatchScalarField::write
virtual void write(Ostream &) const
Write.
Definition: totalPressureFvPatchScalarField.C:246
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::fanPressureFvPatchScalarField::fanFlowDirectionNames_
static const Enum< fanFlowDirection > fanFlowDirectionNames_
Fan flow direction names.
Definition: fanPressureFvPatchScalarField.H:169
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::makePatchTypeField
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
Foam::GeometricField< scalar, fvsPatchField, surfaceMesh >
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54