pressurePIDControlInletVelocityFvPatchVectorField.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2015 OpenCFD Ltd.
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 Class
25  Foam::pressurePIDControlInletVelocityFvPatchVectorField
26 
27 Group
28  grpInletBoundaryConditions
29 
30 Description
31  This boundary condition tries to generate an inlet velocity that maintains
32  a specified pressure drop between two face zones downstream. The zones
33  should fully span a duct through which all the inlet flow passes.
34 
35  An incompressible, lossless analysis of the flow between the inlet and the
36  two face-zones is performed. An ideal inlet velocity is thereby calculated
37  from the user-specified pressure drop. This analysis can include the
38  transient effect of the inlet velocity change. In this case, a shape factor
39  is included to represent non-linearity in the duct cross section.
40 
41  The average pressure drop between the two face zones is measured. The same
42  incompressible, lossless analysis is performed using this pressure drop.
43  The difference between the two computed velocities is considered as an
44  error. The ideal inlet is modified so as to drive this error to zero. This
45  is accomplished by means of a PID control algorithm, for which
46  non-dimensional gains are specified by the user.
47 
48  The shape factor takes a value of 0 for a linear change in cross sectional
49  area between the two face zones. A value of 1 represents a step change in
50  area at the mid-point between the zones. A smooth cubic or cosine profile
51  between two zones with zero divergence is typically represented by a factor
52  of between 0.2 and 0.25.
53 
54  \heading Patch usage
55 
56  \table
57  Property | Description | Required | Default value
58  upstream | upstream face zone name | yes |
59  downstream | downstream face zone name | yes |
60  deltaP | desired pressure drop | yes |
61  shapeFactor | non-linearity in the nozzle | no | 0
62  p | pressure field name | no | p
63  phi | flux field name | yes | phi
64  rho | density field name | no | none
65  P | proportional gain | yes |
66  I | integral gain | yes |
67  D | differential gain | yes |
68  \endtable
69 
70  Example of the boundary condition specification:
71 
72  \verbatim
73  myPatch
74  {
75  type pressurePIDControlInletVelocity;
76  upstream upstream;
77  downstream downstream;
78  deltaP 200;
79  shapeFactor 0;
80  p p;
81  phi phi;
82  rho none;
83  P 0.5;
84  I 0.5;
85  D 0.1;
86  value uniform (0 0 0);
87  }
88 
89 SeeAlso
90  Foam::fixedValueFvPatchField
91 
92 SourceFiles
93  pressurePIDControlInletVelocityFvPatchVectorField.C
94 
95 \*---------------------------------------------------------------------------*/
96 
97 #ifndef pressurePIDControlInletVelocityFvPatchVectorField_H
98 #define pressurePIDControlInletVelocityFvPatchVectorField_H
99 
100 #include "fixedValueFvPatchFields.H"
101 #include "Switch.H"
102 
103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 
105 namespace Foam
106 {
107 /*---------------------------------------------------------------------------*\
108  Class pressurePIDControlInletVelocityFvPatchVectorField Declaration
109 \*---------------------------------------------------------------------------*/
110 
111 class pressurePIDControlInletVelocityFvPatchVectorField
112 :
113  public fixedValueFvPatchVectorField
114 {
115  // Private data
116 
117  //- Name of the upstream face zone
118  const word upstreamName_;
119 
120  //- Name of the downstream face zone
121  const word downstreamName_;
122 
123  //- Desired pressure difference between upstream and downstream
124  const scalar deltaP_;
125 
126  //- Nozzle shape factor
127  const scalar shapeFactor_;
128 
129  //- Name of the pressure field
130  const word pName_;
131 
132  //- Name of the flux field
133  const word phiName_;
134 
135  //- Name of the density field (if any)
136  const word rhoName_;
137 
138  //- Proportional gain
139  const scalar P_;
140 
141  //- Integral gain
142  const scalar I_;
143 
144  //- Derivative gain
145  const scalar D_;
146 
147  //- Volumetric flow rate
148  scalar Q_;
149 
150  //- Error
151  scalar error_;
152 
153  //- Error integral w.r.t. time
154  scalar errorIntegral_;
155 
156  //- Old volumetric flow rate
157  scalar oldQ_;
158 
159  //- Old error
160  scalar oldError_;
161 
162  //- Old error integral w.r.t. time
163  scalar oldErrorIntegral_;
164 
165  //- Time index of the last update
166  label timeIndex_;
167 
168 
169  // Private member functions
170 
171  //- Return the pressure interpolated to the faces
172  const surfaceScalarField& facePressure() const;
173 
174  //- Calculate the average on a face zone
175  template <class Type>
176  void faceZoneAverage
177  (
178  const word& name,
179  const GeometricField<Type, fvsPatchField, surfaceMesh>& field,
180  scalar& area,
181  Type& average
182  ) const;
183 
184 
185 public:
186 
187  //- Runtime type information
188  TypeName("pressurePIDControlInletVelocity");
189 
190 
191  // Constructors
192 
193  //- Construct from patch and internal field
194  pressurePIDControlInletVelocityFvPatchVectorField
195  (
196  const fvPatch&,
197  const DimensionedField<vector, volMesh>&
198  );
199 
200  //- Construct from patch, internal field and dictionary
201  pressurePIDControlInletVelocityFvPatchVectorField
202  (
203  const fvPatch&,
204  const DimensionedField<vector, volMesh>&,
205  const dictionary&
206  );
207 
208  //- Construct by mapping given
209  // flowRateInletVelocityFvPatchVectorField
210  // onto a new patch
211  pressurePIDControlInletVelocityFvPatchVectorField
212  (
213  const pressurePIDControlInletVelocityFvPatchVectorField&,
214  const fvPatch&,
215  const DimensionedField<vector, volMesh>&,
216  const fvPatchFieldMapper&
217  );
218 
219  //- Construct as copy
220  pressurePIDControlInletVelocityFvPatchVectorField
221  (
222  const pressurePIDControlInletVelocityFvPatchVectorField&
223  );
224 
225  //- Construct and return a clone
226  virtual tmp<fvPatchVectorField> clone() const
227  {
228  return tmp<fvPatchVectorField>
229  (
230  new pressurePIDControlInletVelocityFvPatchVectorField
231  (
232  *this
233  )
234  );
235  }
236 
237  //- Construct as copy setting internal field reference
238  pressurePIDControlInletVelocityFvPatchVectorField
239  (
240  const pressurePIDControlInletVelocityFvPatchVectorField&,
241  const DimensionedField<vector, volMesh>&
242  );
243 
244  //- Construct and return a clone setting internal field reference
245  virtual tmp<fvPatchVectorField> clone
246  (
247  const DimensionedField<vector, volMesh>& iF
248  ) const
249  {
250  return tmp<fvPatchVectorField>
251  (
252  new pressurePIDControlInletVelocityFvPatchVectorField
253  (
254  *this,
255  iF
256  )
257  );
258  }
259 
260 
261  // Member functions
262 
263  //- Update the coefficients associated with the patch field
264  virtual void updateCoeffs();
265 
266  //- Write
267  virtual void write(Ostream&) const;
268 };
269 
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 } // End namespace Foam
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 #ifdef NoRepository
279 #endif
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 #endif
284 
285 // ************************************************************************* //
TypeName
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:70
pressurePIDControlInletVelocityFvPatchVectorFieldTemplates.C
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Switch.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::surfaceScalarField
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Definition: surfaceFieldsFwd.H:52
fixedValueFvPatchFields.H
write
Tcoeff write()
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::average
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:335