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  fraction_(1),
47  offset_(Zero)
48 {}
49 
50 
51 template<class Type>
54 (
55  const fvPatch& p,
57  const dictionary& dict
58 )
59 :
61  outletPatchName_(dict.get<word>("outletPatch")),
62  phiName_(dict.getOrDefault<word>("phi", "phi")),
63  fraction_(dict.getOrDefault<scalar>("fraction", 1)),
64  offset_(dict.getOrDefault<Type>("offset", Zero))
65 {}
66 
67 
68 template<class Type>
71 (
73  const fvPatch& p,
75  const fvPatchFieldMapper& mapper
76 )
77 :
78  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
79  outletPatchName_(ptf.outletPatchName_),
80  phiName_(ptf.phiName_),
81  fraction_(ptf.fraction_),
82  offset_(ptf.offset_)
83 {}
84 
85 
86 template<class Type>
89 (
91 )
92 :
94  outletPatchName_(ptf.outletPatchName_),
95  phiName_(ptf.phiName_),
96  fraction_(ptf.fraction_),
97  offset_(ptf.offset_)
98 {}
99 
100 
101 template<class Type>
104 (
107 )
108 :
110  outletPatchName_(ptf.outletPatchName_),
111  phiName_(ptf.phiName_),
112  fraction_(ptf.fraction_),
113  offset_(ptf.offset_)
114 {}
115 
116 
117 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118 
119 template<class Type>
121 {
122  if (this->updated())
123  {
124  return;
125  }
126 
128  (
130  (
131  this->internalField()
132  )
133  );
134 
135  const fvPatch& p = this->patch();
136  const label outletPatchID =
137  p.patch().boundaryMesh().findPatchID(outletPatchName_);
138 
139  if (outletPatchID < 0)
140  {
142  << "Unable to find outlet patch " << outletPatchName_
143  << abort(FatalError);
144  }
145 
146  const fvPatch& outletPatch = p.boundaryMesh()[outletPatchID];
147 
148  const fvPatchField<Type>& outletPatchField =
149  f.boundaryField()[outletPatchID];
150 
151  const auto& phi =
152  this->db().objectRegistry::template lookupObject<surfaceScalarField>
153  (phiName_);
154 
155  const scalarField& outletPatchPhi = phi.boundaryField()[outletPatchID];
156  const scalar sumOutletPatchPhi = gSum(outletPatchPhi);
157 
158  if (sumOutletPatchPhi > SMALL)
159  {
160  Type averageOutletField =
161  gSum(outletPatchPhi*outletPatchField)
162  /sumOutletPatchPhi;
163 
164  this->operator==(averageOutletField*fraction_ + offset_);
165  }
166  else
167  {
168  Type averageOutletField =
169  gSum(outletPatch.magSf()*outletPatchField)
170  /gSum(outletPatch.magSf());
171 
172  this->operator==(averageOutletField);
173  }
174 
176 }
177 
178 
179 template<class Type>
181 {
183  os.writeEntry("outletPatch", outletPatchName_);
184  os.writeEntryIfDifferent<word>("phi", "phi", phiName_);
185  os.writeEntry("fraction", fraction_);
186  os.writeEntry("offset", offset_);
187  this->writeEntry("value", os);
188 }
189 
190 
191 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
volFields.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::outletMappedUniformInletFvPatchField::write
virtual void write(Ostream &) const
Write.
Definition: outletMappedUniformInletFvPatchField.C:180
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
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:120
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:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::outletMappedUniformInletFvPatchField
The outletMappedUniformInlet is an inlet boundary condition that.
Definition: outletMappedUniformInletFvPatchField.H:163
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
f
labelList f(nPoints)
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
outletMappedUniformInletFvPatchField.H
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:36
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:156
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