flowRateInletVelocityFvPatchVectorField.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 | Copyright (C) 2011-2016 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 "one.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
35 (
36  const fvPatch& p,
38 )
39 :
41  flowRate_(),
42  volumetric_(false),
43  rhoName_("rho"),
44  rhoInlet_(0.0),
45  extrapolateProfile_(false)
46 {}
47 
48 
51 (
52  const fvPatch& p,
54  const dictionary& dict
55 )
56 :
58  rhoInlet_(dict.lookupOrDefault<scalar>("rhoInlet", -VGREAT)),
59  extrapolateProfile_
60  (
61  dict.lookupOrDefault<Switch>("extrapolateProfile", false)
62  )
63 {
64  if (dict.found("volumetricFlowRate"))
65  {
66  volumetric_ = true;
67  flowRate_ = Function1<scalar>::New("volumetricFlowRate", dict);
68  rhoName_ = "rho";
69  }
70  else if (dict.found("massFlowRate"))
71  {
72  volumetric_ = false;
73  flowRate_ = Function1<scalar>::New("massFlowRate", dict);
74  rhoName_ = word(dict.lookupOrDefault<word>("rho", "rho"));
75  }
76  else
77  {
79  (
80  dict
81  ) << "Please supply either 'volumetricFlowRate' or"
82  << " 'massFlowRate' and 'rho'" << exit(FatalIOError);
83  }
84 
85  // Value field require if mass based
86  if (dict.found("value"))
87  {
89  (
90  vectorField("value", dict, p.size())
91  );
92  }
93  else
94  {
95  evaluate(Pstream::blocking);
96  }
97 }
98 
99 
102 (
104  const fvPatch& p,
106  const fvPatchFieldMapper& mapper
107 )
108 :
109  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
110  flowRate_(ptf.flowRate_, false),
111  volumetric_(ptf.volumetric_),
112  rhoName_(ptf.rhoName_),
113  rhoInlet_(ptf.rhoInlet_),
114  extrapolateProfile_(ptf.extrapolateProfile_)
115 {}
116 
117 
120 (
122 )
123 :
125  flowRate_(ptf.flowRate_, false),
126  volumetric_(ptf.volumetric_),
127  rhoName_(ptf.rhoName_),
128  rhoInlet_(ptf.rhoInlet_),
129  extrapolateProfile_(ptf.extrapolateProfile_)
130 {}
131 
132 
135 (
138 )
139 :
141  flowRate_(ptf.flowRate_, false),
142  volumetric_(ptf.volumetric_),
143  rhoName_(ptf.rhoName_),
144  rhoInlet_(ptf.rhoInlet_),
145  extrapolateProfile_(ptf.extrapolateProfile_)
146 {}
147 
148 
149 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
150 
151 template<class RhoType>
152 void Foam::flowRateInletVelocityFvPatchVectorField::updateValues
153 (
154  const RhoType& rho
155 )
156 {
157  const scalar t = db().time().timeOutputValue();
158 
159  tmp<vectorField> n = patch().nf();
160 
161  if (extrapolateProfile_)
162  {
163  vectorField newValues(this->patchInternalField());
164 
165  scalar flowRate = flowRate_->value(t);
166  scalar estimatedFlowRate = -gSum(rho*(this->patch().Sf() & newValues));
167 
168  if (estimatedFlowRate/flowRate > 0.5)
169  {
170  newValues *= (mag(flowRate)/mag(estimatedFlowRate));
171  }
172  else
173  {
174  newValues -=
175  ((flowRate - estimatedFlowRate)/gSum(rho*patch().magSf()))*n;
176  }
177 
178  this->operator==(newValues);
179  }
180  else
181  {
182  const scalar avgU = -flowRate_->value(t)/gSum(rho*patch().magSf());
183  operator==(n*avgU);
184  }
185 }
186 
187 
189 {
190  if (updated())
191  {
192  return;
193  }
194 
195  if (volumetric_ || rhoName_ == "none")
196  {
197  updateValues(one());
198  }
199  else
200  {
201  // Mass flow-rate
202  if (db().foundObject<volScalarField>(rhoName_))
203  {
204  const fvPatchField<scalar>& rhop =
205  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
206 
207  updateValues(rhop);
208  }
209  else
210  {
211  // Use constant density
212  if (rhoInlet_ < 0)
213  {
215  << "Did not find registered density field " << rhoName_
216  << " and no constant density 'rhoInlet' specified"
217  << exit(FatalError);
218  }
219 
220  updateValues(rhoInlet_);
221  }
222  }
223 
224  fixedValueFvPatchVectorField::updateCoeffs();
225 }
226 
227 
229 {
231  flowRate_->writeData(os);
232  if (!volumetric_)
233  {
234  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
235  writeEntryIfDifferent<scalar>(os, "rhoInlet", -VGREAT, rhoInlet_);
236  }
237  os.writeKeyword("extrapolateProfile")
238  << extrapolateProfile_ << token::END_STATEMENT << nl;
239  writeEntry("value", os);
240 }
241 
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 namespace Foam
246 {
248  (
251  );
252 }
253 
254 
255 // ************************************************************************* //
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void size(const label)
Override size to be inconsistent with allocated storage.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
volVectorField vectorField(fieldObject, mesh)
Macros for easy insertion into run-time selection tables.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
makePatchTypeField(fvPatchVectorField, SRFFreestreamVelocityFvPatchVectorField)
Type gSum(const FieldField< Field, Type > &f)
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
A class for handling words, derived from string.
Definition: word.H:59
flowRateInletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
Foam::fvPatchFieldMapper.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
This boundary condition provides a velocity boundary condition, derived from the flux (volumetric or ...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
dimensioned< scalar > mag(const dimensioned< Type > &)
label n
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:54
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Namespace for OpenFOAM.
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:363
A class representing the concept of 1 (scalar(1.0)) used to avoid unnecessary manipulations for objec...
Definition: one.H:50
IOerror FatalIOError