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-2014 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 
27 #include "volFields.H"
29 #include "fvPatchFieldMapper.H"
30 #include "surfaceFields.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
36 (
37  const fvPatch& p,
39 )
40 :
42  flowRate_(),
43  volumetric_(false),
44  rhoName_("rho"),
45  rhoInlet_(0.0)
46 {}
47 
48 
51 (
53  const fvPatch& p,
55  const fvPatchFieldMapper& mapper
56 )
57 :
58  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
59  flowRate_(ptf.flowRate_().clone().ptr()),
60  volumetric_(ptf.volumetric_),
61  rhoName_(ptf.rhoName_),
62  rhoInlet_(ptf.rhoInlet_)
63 {}
64 
65 
68 (
69  const fvPatch& p,
71  const dictionary& dict
72 )
73 :
75  rhoInlet_(dict.lookupOrDefault<scalar>("rhoInlet", -VGREAT))
76 {
77  if (dict.found("volumetricFlowRate"))
78  {
79  volumetric_ = true;
80  flowRate_ = DataEntry<scalar>::New("volumetricFlowRate", dict);
81  rhoName_ = "rho";
82  }
83  else if (dict.found("massFlowRate"))
84  {
85  volumetric_ = false;
86  flowRate_ = DataEntry<scalar>::New("massFlowRate", dict);
87  rhoName_ = word(dict.lookupOrDefault<word>("rho", "rho"));
88  }
89  else
90  {
92  (
93  "flowRateInletVelocityFvPatchVectorField::"
94  "flowRateInletVelocityFvPatchVectorField"
95  "(const fvPatch&, const DimensionedField<vector, volMesh>&,"
96  " const dictionary&)",
97  dict
98  ) << "Please supply either 'volumetricFlowRate' or"
99  << " 'massFlowRate' and 'rho'" << exit(FatalIOError);
100  }
101 
102  // Value field require if mass based
103  if (dict.found("value"))
104  {
106  (
107  vectorField("value", dict, p.size())
108  );
109  }
110  else
111  {
112  evaluate(Pstream::blocking);
113  }
114 }
115 
116 
119 (
121 )
122 :
124  flowRate_(ptf.flowRate_().clone().ptr()),
125  volumetric_(ptf.volumetric_),
126  rhoName_(ptf.rhoName_),
127  rhoInlet_(ptf.rhoInlet_)
128 {}
129 
130 
133 (
136 )
137 :
139  flowRate_(ptf.flowRate_().clone().ptr()),
140  volumetric_(ptf.volumetric_),
141  rhoName_(ptf.rhoName_),
142  rhoInlet_(ptf.rhoInlet_)
143 {}
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
149 {
150  if (updated())
151  {
152  return;
153  }
154 
155  const scalar t = db().time().timeOutputValue();
156 
157  // a simpler way of doing this would be nice
158  const scalar avgU = -flowRate_->value(t)/gSum(patch().magSf());
159 
160  tmp<vectorField> n = patch().nf();
161 
162  if (volumetric_ || rhoName_ == "none")
163  {
164  // volumetric flow-rate or density not given
165  operator==(n*avgU);
166  }
167  else
168  {
169  // mass flow-rate
170  if (db().foundObject<volScalarField>(rhoName_))
171  {
172  const fvPatchField<scalar>& rhop =
173  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
174 
175  operator==(n*avgU/rhop);
176  }
177  else
178  {
179  // Use constant density
180  if (rhoInlet_ < 0)
181  {
183  (
184  "flowRateInletVelocityFvPatchVectorField::updateCoeffs()"
185  ) << "Did not find registered density field " << rhoName_
186  << " and no constant density 'rhoInlet' specified"
187  << exit(FatalError);
188  }
189  operator==(n*avgU/rhoInlet_);
190  }
191  }
192 
193  fixedValueFvPatchVectorField::updateCoeffs();
194 }
195 
196 
198 {
200  flowRate_->writeData(os);
201  if (!volumetric_)
202  {
203  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
204  writeEntryIfDifferent<scalar>(os, "rhoInlet", -VGREAT, rhoInlet_);
205  }
206  writeEntry("value", os);
207 }
208 
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 namespace Foam
213 {
215  (
218  );
219 }
220 
221 
222 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
Foam::surfaceFields.
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
This boundary condition provides a velocity boundary condition, derived from the flux (volumetric or ...
A class for handling words, derived from string.
Definition: word.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::fvPatchFieldMapper.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:354
Namespace for OpenFOAM.
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Type gSum(const FieldField< Field, Type > &f)
label n
IOerror FatalIOError
volVectorField vectorField(fieldObject, mesh)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
volScalarField & p
Definition: createFields.H:51
Macros for easy insertion into run-time selection tables.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
flowRateInletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
error FatalError
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
makePatchTypeField(fvPatchVectorField, SRFFreestreamVelocityFvPatchVectorField)
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
A class for managing temporary objects.
Definition: PtrList.H:118
virtual tmp< fvPatchField< Type > > clone() const
Construct and return a clone.