swirlFlowRateInletVelocityFvPatchVectorField.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-2023 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 #include "mathematicalConstants.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
37 (
38  const fvPatch& p,
40  const dictionary& dict
41 )
42 :
44  phiName_(dict.lookupOrDefault<word>("phi", "phi")),
45  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
46  origin_
47  (
48  dict.lookupOrDefault
49  (
50  "origin",
51  returnReduce(patch().size(), sumOp<label>())
52  ? gSum(patch().Cf()*patch().magSf())/gSum(patch().magSf())
53  : Zero
54  )
55  ),
56  axis_
57  (
58  dict.lookupOrDefault
59  (
60  "axis",
61  returnReduce(patch().size(), sumOp<label>())
62  ? -gSum(patch().Sf())/gSum(patch().magSf())
63  : Zero
64  )
65  ),
66  flowRate_(Function1<scalar>::New("flowRate", dict)),
67  rpm_(Function1<scalar>::New("rpm", dict))
68 {}
69 
70 
73 (
75  const fvPatch& p,
77  const fvPatchFieldMapper& mapper
78 )
79 :
80  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
81  phiName_(ptf.phiName_),
82  rhoName_(ptf.rhoName_),
83  origin_(ptf.origin_),
84  axis_(ptf.axis_),
85  flowRate_(ptf.flowRate_, false),
86  rpm_(ptf.rpm_, false)
87 {}
88 
89 
92 (
95 )
96 :
98  phiName_(ptf.phiName_),
99  rhoName_(ptf.rhoName_),
100  origin_(ptf.origin_),
101  axis_(ptf.axis_),
102  flowRate_(ptf.flowRate_, false),
103  rpm_(ptf.rpm_, false)
104 {}
105 
106 
107 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
108 
110 {
111  if (updated())
112  {
113  return;
114  }
115 
116  const scalar t = this->db().time().userTimeValue();
117  const scalar flowRate = flowRate_->value(t);
118  const scalar rpm = rpm_->value(t);
119 
120  const scalar totArea = gSum(patch().magSf());
121  const scalar avgU = -flowRate/totArea;
122 
123  const vector axisHat = axis_/mag(axis_);
124 
125  // Update angular velocity - convert [rpm] to [rad/s]
126  tmp<vectorField> tangentialVelocity
127  (
128  axisHat ^ (rpm*constant::mathematical::pi/30.0)*(patch().Cf() - origin_)
129  );
130 
131  tmp<vectorField> n = patch().nf();
132 
133  const surfaceScalarField& phi =
134  db().lookupObject<surfaceScalarField>(phiName_);
135 
136  if (phi.dimensions() == dimFlux)
137  {
138  // volumetric flow-rate
139  operator==(tangentialVelocity + n*avgU);
140  }
141  else if (phi.dimensions() == dimMassFlux)
142  {
143  const fvPatchField<scalar>& rhop =
144  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
145 
146  // mass flow-rate
147  operator==(tangentialVelocity + n*avgU/rhop);
148  }
149  else
150  {
152  << "dimensions of " << phiName_ << " are incorrect" << nl
153  << " on patch " << this->patch().name()
154  << " of field " << this->internalField().name()
155  << " in file " << this->internalField().objectPath()
156  << nl << exit(FatalError);
157  }
158 
160 }
161 
162 
164 (
165  Ostream& os
166 ) const
167 {
169  writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
170  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
171  writeEntry(os, "origin", origin_);
172  writeEntry(os, "axis", axis_);
173  writeEntry(os, flowRate_());
174  writeEntry(os, rpm_());
175  writeEntry(os, "value", *this);
176 }
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 namespace Foam
182 {
184  (
187  );
188 }
189 
190 
191 // ************************************************************************* //
label n
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...
const dimensionSet & dimensions() const
Return dimensions.
Run-time selectable general function of one variable.
Definition: Function1.H:64
Generic GeometricField class.
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:160
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
Foam::fvPatchFieldMapper.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:87
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:231
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:204
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
This boundary condition provides a volumetric- OR mass-flow normal vector boundary condition by its m...
swirlFlowRateInletVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
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
static const zero Zero
Definition: zero.H:97
Type gSum(const FieldField< Field, Type > &f)
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
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
const dimensionSet dimMassFlux
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:61
dimensioned< scalar > mag(const dimensioned< Type > &)
error FatalError
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
static const char nl
Definition: Ostream.H:260
const dimensionSet dimFlux
dictionary dict
volScalarField & p
Foam::surfaceFields.