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 | Copyright (C) 2011 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 "mappedPatchBase.H"
31 #include "surfaceFields.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 (
37  const fvPatch& p,
39 )
40 :
42  nbrPhiName_("none"),
43  phiName_("phi"),
44  rhoName_("rho")
45 {}
46 
47 
49 (
51  const fvPatch& p,
53  const fvPatchFieldMapper& mapper
54 )
55 :
56  fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
57  nbrPhiName_(ptf.nbrPhiName_),
58  phiName_(ptf.phiName_),
59  rhoName_(ptf.rhoName_)
60 {}
61 
62 
64 (
65  const fvPatch& p,
67  const dictionary& dict
68 )
69 :
71  nbrPhiName_(dict.lookupOrDefault<word>("nbrPhi", "phi")),
72  phiName_(dict.lookupOrDefault<word>("phi", "phi")),
73  rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
74 {}
75 
76 
78 (
80 )
81 :
83  nbrPhiName_(ptf.nbrPhiName_),
84  phiName_(ptf.phiName_),
85  rhoName_(ptf.rhoName_)
86 {}
87 
88 
90 (
93 )
94 :
96  nbrPhiName_(ptf.nbrPhiName_),
97  phiName_(ptf.phiName_),
98  rhoName_(ptf.rhoName_)
99 {}
100 
101 
102 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
103 
105 {
106  if (updated())
107  {
108  return;
109  }
110 
111  // Since we're inside initEvaluate/evaluate there might be processor
112  // comms underway. Change the tag we use.
113  int oldTag = UPstream::msgType();
114  UPstream::msgType() = oldTag+1;
115 
116  // Get the coupling information from the mappedPatchBase
117  const mappedPatchBase& mpp = refCast<const mappedPatchBase>
118  (
119  patch().patch()
120  );
121  const polyMesh& nbrMesh = mpp.sampleMesh();
122  const fvPatch& nbrPatch = refCast<const fvMesh>
123  (
124  nbrMesh
125  ).boundary()[mpp.samplePolyPatch().index()];
126 
127  scalarList phi =
128  nbrPatch.lookupPatchField<surfaceScalarField, scalar>(nbrPhiName_);
129 
130  mpp.distribute(phi);
131 
132 
133  const surfaceScalarField& phiName =
134  db().lookupObject<surfaceScalarField>(phiName_);
135 
136  scalarField U(-phi/patch().magSf());
137 
138  vectorField n(patch().nf());
139 
140  if (phiName.dimensions() == dimVelocity*dimArea)
141  {
142  // volumetric flow-rate
143  operator==(n*U);
144  }
145  else if (phiName.dimensions() == dimDensity*dimVelocity*dimArea)
146  {
147  const fvPatchField<scalar>& rhop =
148  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
149 
150  // mass flow-rate
151  operator==(n*U/rhop);
152 
153  if (debug)
154  {
155  scalar phi = gSum(rhop*(*this) & patch().Sf());
156  Info<< patch().boundaryMesh().mesh().name() << ':'
157  << patch().name() << ':'
158  << this->dimensionedInternalField().name() << " <- "
159  << nbrMesh.name() << ':'
160  << nbrPatch.name() << ':'
161  << this->dimensionedInternalField().name() << " :"
162  << " mass flux[Kg/s]:" << -phi
163  << endl;
164  }
165  }
166  else
167  {
169  (
170  "mappedFlowRateFvPatchVectorField::updateCoeffs()"
171  ) << "dimensions of " << phiName_ << " are incorrect" << nl
172  << " on patch " << this->patch().name()
173  << " of field " << this->dimensionedInternalField().name()
174  << " in file " << this->dimensionedInternalField().objectPath()
175  << nl << exit(FatalError);
176  }
177 
178  // Restore tag
179  UPstream::msgType() = oldTag;
180 
182 }
183 
184 
186 (
187  Ostream& os
188 ) const
189 {
191  writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
192  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
193  os.writeKeyword("nbrPhi") << nbrPhiName_ << token::END_STATEMENT << nl;
194  writeEntry("value", os);
195 }
196 
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 namespace Foam
201 {
203  (
206  );
207 }
208 
209 
210 // ************************************************************************* //
faceListList boundary(nPatches)
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...
const polyMesh & sampleMesh() const
Get the region mesh.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:301
void distribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
label index() const
Return the index of this patch in the boundaryMesh.
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:57
A class for handling words, derived from string.
Definition: word.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::fvPatchFieldMapper.
messageStream Info
const dimensionSet dimDensity
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.
const word & name() const
Return name.
Definition: fvPatch.H:149
const GeometricField::PatchFieldType & lookupPatchField(const word &name, const GeometricField *=NULL, const Type *=NULL) const
Lookup and return the patchField of the named field from the.
mappedFlowRateFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
Type gSum(const FieldField< Field, Type > &f)
label n
dictionary dict
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const polyPatch & samplePolyPatch() const
Get the patch on the region.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
volScalarField & p
Definition: createFields.H:51
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Describes a volumetric/mass flow normal vector boundary condition by its magnitude as an integral ove...
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:451
Macros for easy insertion into run-time selection tables.
const dimensionSet & dimensions() const
Return dimensions.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
surfaceScalarField & phi
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
rDeltaT dimensionedInternalField()
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
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...
Determines a mapping between patch face centres and mesh cell or face centres and processors they&#39;re ...
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.
const dimensionSet dimVelocity
U
Definition: pEqn.H:82