outletMappedUniformInletFvPatchField.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"
31 #include "surfaceFields.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 template<class Type>
38 (
39  const fvPatch& p,
41 )
42 :
44  outletPatchName_(),
45  phiName_("phi")
46 {}
47 
48 
49 template<class Type>
52 (
53  const fvPatch& p,
55  const dictionary& dict
56 )
57 :
59  outletPatchName_(dict.lookup("outletPatch")),
60  phiName_(dict.getOrDefault<word>("phi", "phi"))
61 {}
62 
63 
64 template<class Type>
67 (
69  const fvPatch& p,
71  const fvPatchFieldMapper& mapper
72 )
73 :
74  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
75  outletPatchName_(ptf.outletPatchName_),
76  phiName_(ptf.phiName_)
77 {}
78 
79 
80 template<class Type>
83 (
85 )
86 :
88  outletPatchName_(ptf.outletPatchName_),
89  phiName_(ptf.phiName_)
90 {}
91 
92 
93 
94 template<class Type>
97 (
100 )
101 :
103  outletPatchName_(ptf.outletPatchName_),
104  phiName_(ptf.phiName_)
105 {}
106 
107 
108 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109 
110 template<class Type>
112 {
113  if (this->updated())
114  {
115  return;
116  }
117 
119  (
121  (
122  this->internalField()
123  )
124  );
125 
126  const fvPatch& p = this->patch();
127  label outletPatchID =
128  p.patch().boundaryMesh().findPatchID(outletPatchName_);
129 
130  if (outletPatchID < 0)
131  {
133  << "Unable to find outlet patch " << outletPatchName_
134  << abort(FatalError);
135  }
136 
137  const fvPatch& outletPatch = p.boundaryMesh()[outletPatchID];
138 
139  const fvPatchField<Type>& outletPatchField =
140  f.boundaryField()[outletPatchID];
141 
142  const surfaceScalarField& phi =
143  this->db().objectRegistry::template lookupObject<surfaceScalarField>
144  (phiName_);
145 
146  const scalarField& outletPatchPhi = phi.boundaryField()[outletPatchID];
147  scalar sumOutletPatchPhi = gSum(outletPatchPhi);
148 
149  if (sumOutletPatchPhi > SMALL)
150  {
151  Type averageOutletField =
152  gSum(outletPatchPhi*outletPatchField)
153  /sumOutletPatchPhi;
154 
155  this->operator==(averageOutletField);
156  }
157  else
158  {
159  Type averageOutletField =
160  gSum(outletPatch.magSf()*outletPatchField)
161  /gSum(outletPatch.magSf());
162 
163  this->operator==(averageOutletField);
164  }
165 
167 }
168 
169 
170 template<class Type>
172 {
174  os.writeEntry("outletPatch", outletPatchName_);
175  os.writeEntryIfDifferent<word>("phi", "phi", phiName_);
176  this->writeEntry("value", os);
177 }
178 
179 
180 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
volFields.H
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:244
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::outletMappedUniformInletFvPatchField::write
virtual void write(Ostream &) const
Write.
Definition: outletMappedUniformInletFvPatchField.C:171
surfaceFields.H
Foam::surfaceFields.
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
Foam::fixedValueFvPatchField
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
Definition: fixedValueFvPatchField.H:80
Foam::outletMappedUniformInletFvPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: outletMappedUniformInletFvPatchField.C:111
Foam::Field< scalar >
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
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:121
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::outletMappedUniformInletFvPatchField
This boundary condition averages the field over the "outlet" patch specified by name "outletPatch" an...
Definition: outletMappedUniformInletFvPatchField.H:92
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:372
f
labelList f(nPoints)
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
outletMappedUniformInletFvPatchField.H
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
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::outletMappedUniformInletFvPatchField::outletMappedUniformInletFvPatchField
outletMappedUniformInletFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: outletMappedUniformInletFvPatchField.C:38
Foam::fvPatch::magSf
const scalarField & magSf() const
Return face area magnitudes.
Definition: fvPatch.C:150
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54