mappedFlowRateFvPatchVectorField.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "volFields.H"
33 #include "mappedPatchBase.H"
34 #include "surfaceFields.H"
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
39 (
40  const fvPatch& p,
42 )
43 :
45  nbrPhiName_("none"),
46  phiName_("phi"),
47  rhoName_("rho")
48 {}
49 
50 
52 (
54  const fvPatch& p,
56  const fvPatchFieldMapper& mapper
57 )
58 :
59  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
60  nbrPhiName_(ptf.nbrPhiName_),
61  phiName_(ptf.phiName_),
62  rhoName_(ptf.rhoName_)
63 {}
64 
65 
67 (
68  const fvPatch& p,
70  const dictionary& dict
71 )
72 :
74  nbrPhiName_(dict.getOrDefault<word>("nbrPhi", "phi")),
75  phiName_(dict.getOrDefault<word>("phi", "phi")),
76  rhoName_(dict.getOrDefault<word>("rho", "rho"))
77 {}
78 
79 
81 (
83 )
84 :
86  nbrPhiName_(ptf.nbrPhiName_),
87  phiName_(ptf.phiName_),
88  rhoName_(ptf.rhoName_)
89 {}
90 
91 
93 (
96 )
97 :
99  nbrPhiName_(ptf.nbrPhiName_),
100  phiName_(ptf.phiName_),
101  rhoName_(ptf.rhoName_)
102 {}
103 
104 
105 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106 
108 {
109  if (updated())
110  {
111  return;
112  }
113 
114  // Since we're inside initEvaluate/evaluate there might be processor
115  // comms underway. Change the tag we use.
116  int oldTag = UPstream::msgType();
117  UPstream::msgType() = oldTag+1;
118 
119  // Get the coupling information from the mappedPatchBase
120  const mappedPatchBase& mpp = refCast<const mappedPatchBase>
121  (
122  patch().patch()
123  );
124  const polyMesh& nbrMesh = mpp.sampleMesh();
125  const fvPatch& nbrPatch = refCast<const fvMesh>
126  (
127  nbrMesh
128  ).boundary()[mpp.samplePolyPatch().index()];
129 
130  scalarList phi =
131  nbrPatch.lookupPatchField<surfaceScalarField, scalar>(nbrPhiName_);
132 
133  mpp.distribute(phi);
134 
135 
136  const surfaceScalarField& phiName =
137  db().lookupObject<surfaceScalarField>(phiName_);
138 
139  scalarField U(-phi/patch().magSf());
140 
141  vectorField n(patch().nf());
142 
143  if (phiName.dimensions() == dimVelocity*dimArea)
144  {
145  // volumetric flow-rate
146  operator==(n*U);
147  }
148  else if (phiName.dimensions() == dimDensity*dimVelocity*dimArea)
149  {
150  const fvPatchField<scalar>& rhop =
151  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
152 
153  // mass flow-rate
154  operator==(n*U/rhop);
155 
156  if (debug)
157  {
158  scalar phi = gSum(rhop*(*this) & patch().Sf());
159  Info<< patch().boundaryMesh().mesh().name() << ':'
160  << patch().name() << ':'
161  << this->internalField().name() << " <- "
162  << nbrMesh.name() << ':'
163  << nbrPatch.name() << ':'
164  << this->internalField().name() << " :"
165  << " mass flux[Kg/s]:" << -phi
166  << endl;
167  }
168  }
169  else
170  {
172  << "dimensions of " << phiName_ << " are incorrect" << nl
173  << " on patch " << this->patch().name()
174  << " of field " << this->internalField().name()
175  << " in file " << this->internalField().objectPath()
176  << nl << exit(FatalError);
177  }
178 
179  // Restore tag
180  UPstream::msgType() = oldTag;
181 
183 }
184 
185 
187 (
188  Ostream& os
189 ) const
190 {
192  os.writeEntryIfDifferent<word>("phi", "phi", phiName_);
193  os.writeEntryIfDifferent<word>("rho", "rho", rhoName_);
194  os.writeEntry("nbrPhi", nbrPhiName_);
195  writeEntry("value", os);
196 }
197 
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 namespace Foam
202 {
204  (
206  mappedFlowRateFvPatchVectorField
207  );
208 }
209 
210 
211 // ************************************************************************* //
Foam::surfaceFields.
faceListList boundary
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
dictionary dict
fvPatchField< vector > fvPatchVectorField
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
Describes a volumetric/mass flow normal vector boundary condition by its magnitude as an integral ove...
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:68
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:312
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:806
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:333
Macros for easy insertion into run-time selection tables.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:84
Type gSum(const FieldField< Field, Type > &f)
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
A FieldMapper for finite-volume patch fields.
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:61
Ostream & writeEntryIfDifferent(const word &key, const T &value1, const T &value2)
Write a keyword/value entry only when the two values differ.
Definition: Ostream.H:327
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
const dimensionSet dimDensity
U
Definition: pEqn.H:72
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:270
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
const std::string patch
OpenFOAM patch number as a std::string.
messageStream Info
Information stream (stdout output on master, null elsewhere)
label n
Field< vector > vectorField
Specialisation of Field<T> for vector.
mappedFlowRateFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
volScalarField & p
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:57
Namespace for OpenFOAM.
const dimensionSet dimVelocity