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"
32 #include "fvPatchFieldMapper.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  (
207  );
208 }
209 
210 
211 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::fvPatchField< scalar >
volFields.H
Foam::fvPatchField::write
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:384
Foam::Ostream::writeEntryIfDifferent
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:248
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::dimVelocity
const dimensionSet dimVelocity
Foam::dimDensity
const dimensionSet dimDensity
Foam::mappedFlowRateFvPatchVectorField::write
virtual void write(Ostream &) const
Write.
Definition: mappedFlowRateFvPatchVectorField.C:187
Foam::mappedPatchBase::samplePolyPatch
const polyPatch & samplePolyPatch() const
Get the patch on the region.
Definition: mappedPatchBase.C:1662
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
surfaceFields.H
Foam::surfaceFields.
fvPatchFieldMapper.H
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
Foam::fvPatch::name
virtual const word & name() const
Return name.
Definition: fvPatch.H:167
Foam::mappedPatchBase
Determines a mapping between patch face centres and mesh cell or face centres and processors they're ...
Definition: mappedPatchBase.H:112
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::fixedValueFvPatchField
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
Definition: fixedValueFvPatchField.H:80
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::mappedPatchBase::sampleMesh
const polyMesh & sampleMesh() const
Get the region mesh.
Definition: mappedPatchBase.C:1649
Foam::dimArea
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:59
Foam::Field< scalar >
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::mappedPatchBase::distribute
void distribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
Definition: mappedPatchBaseTemplates.C:30
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
Foam::mappedFlowRateFvPatchVectorField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: mappedFlowRateFvPatchVectorField.C:107
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::fvPatch::lookupPatchField
const GeometricField::Patch & lookupPatchField(const word &name, const GeometricField *=nullptr, const Type *=nullptr) const
Definition: fvPatchFvMeshTemplates.C:34
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
mappedFlowRateFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
Definition: mappedFlowRateFvPatchVectorField.C:39
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::patchIdentifier::index
label index() const noexcept
The index of this patch in the boundaryMesh.
Definition: patchIdentifier.H:147
Foam::fvPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:321
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
U
U
Definition: pEqn.H:72
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::UPstream::msgType
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:540
Foam::mappedFlowRateFvPatchVectorField
Describes a volumetric/mass flow normal vector boundary condition by its magnitude as an integral ove...
Definition: mappedFlowRateFvPatchVectorField.H:99
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::surfaceScalarField
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Definition: surfaceFieldsFwd.H:54
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< scalar >
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:236
mappedFlowRateFvPatchVectorField.H
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::makePatchTypeField
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
Foam::GeometricField< scalar, fvsPatchField, surfaceMesh >
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
mappedPatchBase.H