fanPressureFvPatchScalarField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  template<>
36  const char* NamedEnum
37  <
39  2
40  >::names[] =
41  {
42  "in",
43  "out"
44  };
45 }
46 
47 const Foam::NamedEnum
48 <
50  2
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
57 (
58  const fvPatch& p,
60  const dictionary& dict
61 )
62 :
64  fanCurve_
65  (
66  Function1<scalar>::New
67  (
68  "fanCurve",
70  iF.dimensions(),
71  dict
72  )
73  ),
74  direction_(fanFlowDirectionNames_.read(dict.lookup("direction")))
75 {}
76 
77 
79 (
80  const fanPressureFvPatchScalarField& pfopsf,
81  const fvPatch& p,
83  const fieldMapper& mapper
84 )
85 :
86  totalPressureFvPatchScalarField(pfopsf, p, iF, mapper),
87  fanCurve_(pfopsf.fanCurve_, false),
88  direction_(pfopsf.direction_)
89 {}
90 
91 
93 (
94  const fanPressureFvPatchScalarField& pfopsf,
96 )
97 :
99  fanCurve_(pfopsf.fanCurve_, false),
100  direction_(pfopsf.direction_)
101 {}
102 
103 
104 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
105 
107 {
108  if (updated())
109  {
110  return;
111  }
112 
113  const fvsPatchField<scalar>& phip =
114  patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
115 
116  const fvPatchField<vector>& Up =
117  patch().lookupPatchField<volVectorField, vector>(UName_);
118 
119  const int sign = direction_ ? +1 : -1;
120 
121  // Get the volumetric flow rate
122  scalar volFlowRate = 0;
123  if (phip.internalField().dimensions() == dimVolumetricFlux)
124  {
125  volFlowRate = sign*gSum(phip);
126  }
127  else if
128  (
129  phip.internalField().dimensions() == dimMassFlux
130  )
131  {
132  const scalarField& rhop =
133  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
134 
135  volFlowRate = sign*gSum(phip/rhop);
136  }
137  else
138  {
140  << "dimensions of phi are not correct"
141  << "\n on patch " << patch().name()
142  << " of field " << internalField().name()
143  << " in file " << internalField().objectPath() << nl
144  << exit(FatalError);
145  }
146 
147  // Pressure drop for this flow rate
148  const scalar dp0 = fanCurve_->value(max(volFlowRate, scalar(0)));
149 
151  (
152  p0_ - sign*dp0,
153  -0.5*neg(phip)*magSqr(Up)
154  );
155 }
156 
157 
159 {
161  writeEntry(os, fanCurve_());
162  writeEntry(os, "direction", fanFlowDirectionNames_[direction_]);
163 }
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 namespace Foam
169 {
171  (
174  );
175 };
176 
177 
178 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Run-time selectable general function of one variable.
Definition: Function1.H:125
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:54
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
void updateCoeffs(const scalarField &p0p, const scalarField &K0mKp)
Update the coefficients associated with the patch field.
This boundary condition can be applied to assign either a pressure inlet or outlet total pressure con...
virtual void write(Ostream &) const
Write.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
fanPressureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
static const NamedEnum< fanFlowDirection, 2 > fanFlowDirectionNames_
Fan flow directions names.
Abstract base class for field mapping.
Definition: fieldMapper.H:48
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:88
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:83
const DimensionedField< Type, surfaceMesh > & internalField() const
Return dimensioned internal field reference.
Inflow, outflow and entrainment pressure boundary condition based on a constant total pressure assump...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Type gSum(const FieldField< Field, Type > &f)
VolField< vector > volVectorField
Definition: volFieldsFwd.H:65
dimensionedScalar sign(const dimensionedScalar &ds)
const HashTable< dimensionSet > & dimensions()
Get the table of dimension sets.
Definition: dimensionSets.C:96
const dimensionSet dimMassFlux
const dimensionSet dimVolumetricFlux
SurfaceField< scalar > surfaceScalarField
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:64
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
dimensionedScalar neg(const dimensionedScalar &ds)
error FatalError
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
static const char nl
Definition: Ostream.H:266
dimensioned< scalar > magSqr(const dimensioned< Type > &)
dictionary dict
volScalarField & p
Foam::surfaceFields.