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 #include "TableFile.H"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 const Foam::Enum
38 <
40 >
42 ({
43  { fanFlowDirection::ffdIn, "in" },
44  { fanFlowDirection::ffdOut, "out" },
45 });
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 (
52  const fvPatch& p,
54 )
55 :
57  fanCurve_(nullptr),
58  direction_(ffdOut),
59  nonDimensional_(false),
60  rpm_(0),
61  dm_(0)
62 {}
63 
64 
66 (
68  const fvPatch& p,
70  const fvPatchFieldMapper& mapper
71 )
72 :
73  totalPressureFvPatchScalarField(ptf, p, iF, mapper),
74  fanCurve_(ptf.fanCurve_.clone()),
75  direction_(ptf.direction_),
76  nonDimensional_(ptf.nonDimensional_),
77  rpm_(ptf.rpm_),
78  dm_(ptf.dm_)
79 {}
80 
81 
83 (
84  const fvPatch& p,
86  const dictionary& dict
87 )
88 :
90  fanCurve_(nullptr),
91  direction_(fanFlowDirectionNames_.get("direction", dict)),
92  nonDimensional_(dict.getOrDefault("nonDimensional", false)),
93  rpm_(0),
94  dm_(0)
95 {
96  // Backwards compatibility
97  if (dict.found("file"))
98  {
99  fanCurve_.reset
100  (
101  new Function1Types::TableFile<scalar>("fanCurve", dict)
102  );
103  }
104  else
105  {
106  fanCurve_.reset
107  (
108  Function1<scalar>::New("fanCurve", dict)
109  );
110  }
111 
112  if (nonDimensional_)
113  {
114  dict.readEntry("rpm", rpm_);
115  dict.readEntry("dm", dm_);
116  }
117 }
118 
119 
121 (
122  const fanPressureFvPatchScalarField& fppsf
123 )
124 :
126  fanCurve_(fppsf.fanCurve_.clone()),
127  direction_(fppsf.direction_),
128  nonDimensional_(fppsf.nonDimensional_),
129  rpm_(fppsf.rpm_),
130  dm_(fppsf.dm_)
131 {}
132 
133 
135 (
136  const fanPressureFvPatchScalarField& fppsf,
138 )
139 :
141  fanCurve_(fppsf.fanCurve_.clone()),
142  direction_(fppsf.direction_),
143  nonDimensional_(fppsf.nonDimensional_),
144  rpm_(fppsf.rpm_),
145  dm_(fppsf.dm_)
146 {}
147 
148 
149 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
150 
152 {
153  if (updated())
154  {
155  return;
156  }
157 
158  // Retrieve flux field
159  const auto& phi = db().lookupObject<surfaceScalarField>(phiName());
160 
161  const auto& phip = patch().patchField<surfaceScalarField, scalar>(phi);
162 
163  const int dir = 2*direction_ - 1;
164 
165  // Average volumetric flow rate
166  scalar volFlowRate = 0;
167 
168  if (phi.dimensions() == dimVelocity*dimArea)
169  {
170  volFlowRate = dir*gSum(phip);
171  }
172  else if (phi.dimensions() == dimVelocity*dimArea*dimDensity)
173  {
174  const scalarField& rhop =
175  patch().lookupPatchField<volScalarField, scalar>(rhoName());
176  volFlowRate = dir*gSum(phip/rhop);
177  }
178  else
179  {
181  << "dimensions of phi are not correct\n"
182  << " on patch " << patch().name()
183  << " of field " << internalField().name()
184  << " in file " << internalField().objectPath() << nl
185  << exit(FatalError);
186  }
187 
188  if (nonDimensional_)
189  {
190  // Create an non-dimensional flow rate
191  volFlowRate =
192  120.0*volFlowRate/pow3(constant::mathematical::pi)/pow3(dm_)/rpm_;
193  }
194 
195  // Pressure drop for this flow rate
196  scalar pdFan = fanCurve_->value(max(volFlowRate, scalar(0)));
197 
198  if (nonDimensional_)
199  {
200  // Convert the non-dimensional deltap from curve into deltaP
201  pdFan = pdFan*pow4(constant::mathematical::pi)*sqr(dm_*rpm_)/1800;
202  }
203 
205  (
206  p0() - dir*pdFan,
207  patch().lookupPatchField<volVectorField, vector>(UName())
208  );
209 }
210 
211 
213 {
215  fanCurve_->writeData(os);
216  os.writeEntry("direction", fanFlowDirectionNames_[direction_]);
217 
218  if (nonDimensional_)
219  {
220  os.writeEntry("nonDimensional", "true");
221  os.writeEntry("rpm", rpm_);
222  os.writeEntry("dm", dm_);
223  }
224 }
225 
226 
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228 
229 namespace Foam
230 {
232  (
235  );
236 };
237 
238 
239 // ************************************************************************* //
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:170
volFields.H
TableFile.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:212
surfaceFields.H
Foam::surfaceFields.
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:86
Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField
fanPressureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
Definition: fanPressureFvPatchScalarField.C:51
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
Foam::Function1Types::TableFile
Templated table container function where data are read from file.
Definition: TableFile.H:75
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
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:381
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:151
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:184
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::fanPressureFvPatchScalarField::fanFlowDirection
fanFlowDirection
Fan flow direction.
Definition: fanPressureFvPatchScalarField.H:177
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54