outletMappedUniformInletHeatAdditionFvPatchField.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) 2016-2020 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
30#include "volFields.H"
31#include "surfaceFields.H"
32#include "basicThermo.H"
33
34// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35
36Foam::outletMappedUniformInletHeatAdditionFvPatchField::
37outletMappedUniformInletHeatAdditionFvPatchField
38(
39 const fvPatch& p,
41)
42:
43 fixedValueFvPatchScalarField(p, iF),
44 outletPatchName_(),
45 phiName_("phi"),
46 Q_(0),
47 TMin_(0),
48 TMax_(5000)
49{}
50
51
52Foam::outletMappedUniformInletHeatAdditionFvPatchField::
53outletMappedUniformInletHeatAdditionFvPatchField
54(
56 const fvPatch& p,
58 const fvPatchFieldMapper& mapper
59)
60:
61 fixedValueFvPatchScalarField(ptf, p, iF, mapper),
62 outletPatchName_(ptf.outletPatchName_),
63 phiName_(ptf.phiName_),
64 Q_(ptf.Q_),
65 TMin_(ptf.TMin_),
66 TMax_(ptf.TMax_)
67{}
68
69
70Foam::outletMappedUniformInletHeatAdditionFvPatchField::
71outletMappedUniformInletHeatAdditionFvPatchField
72(
73 const fvPatch& p,
75 const dictionary& dict
76)
77:
78 fixedValueFvPatchScalarField(p, iF, dict),
79 outletPatchName_(dict.get<word>("outletPatch")),
80 phiName_(dict.getOrDefault<word>("phi", "phi")),
81 Q_(dict.get<scalar>("Q")),
82 TMin_(dict.getOrDefault<scalar>("TMin", 0)),
83 TMax_(dict.getOrDefault<scalar>("TMax", 5000))
84{}
85
86
87
88Foam::outletMappedUniformInletHeatAdditionFvPatchField::
89outletMappedUniformInletHeatAdditionFvPatchField
90(
92)
93:
94 fixedValueFvPatchScalarField(ptf),
95 outletPatchName_(ptf.outletPatchName_),
96 phiName_(ptf.phiName_),
97 Q_(ptf.Q_),
98 TMin_(ptf.TMin_),
99 TMax_(ptf.TMax_)
100{}
101
102
103
104Foam::outletMappedUniformInletHeatAdditionFvPatchField::
105outletMappedUniformInletHeatAdditionFvPatchField
106(
109)
110:
111 fixedValueFvPatchScalarField(ptf, iF),
112 outletPatchName_(ptf.outletPatchName_),
113 phiName_(ptf.phiName_),
114 Q_(ptf.Q_),
115 TMin_(ptf.TMin_),
116 TMax_(ptf.TMax_)
117{}
118
119
120// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121
122
124{
125 if (this->updated())
126 {
127 return;
128 }
129
130 const volScalarField& vsf =
131 (
132 dynamic_cast<const volScalarField&>(this->internalField())
133 );
134
135 const fvPatch& fvp = this->patch();
136
137 label outletPatchID =
138 fvp.patch().boundaryMesh().findPatchID(outletPatchName_);
139
140 if (outletPatchID < 0)
141 {
143 << "Unable to find outlet patch " << outletPatchName_
144 << abort(FatalError);
145 }
146
147 const fvPatch& outletPatch = fvp.boundaryMesh()[outletPatchID];
148
149 const fvPatchField<scalar>& outletPatchField =
150 vsf.boundaryField()[outletPatchID];
151
152 const surfaceScalarField& phi =
153 db().lookupObject<surfaceScalarField>(phiName_);
154
155 const scalarField& outletPatchPhi = phi.boundaryField()[outletPatchID];
156 scalar sumOutletPatchPhi = gSum(outletPatchPhi);
157
158 if (sumOutletPatchPhi > SMALL)
159 {
160 const basicThermo& thermo =
161 db().lookupObject<basicThermo>(basicThermo::dictName);
162
163 const scalarField& pp = thermo.p().boundaryField()[outletPatchID];
164 const scalarField& pT = thermo.T().boundaryField()[outletPatchID];
165
166 scalar averageOutletField =
167 gSum(outletPatchPhi*outletPatchField)/sumOutletPatchPhi;
168
169 const scalarField Cpf(thermo.Cp(pp, pT, outletPatchID));
170
171 scalar totalPhiCp = gSum(outletPatchPhi)*gAverage(Cpf);
172
173 operator==(min(max(averageOutletField + Q_/totalPhiCp, TMin_), TMax_));
174 }
175 else
176 {
177 scalar averageOutletField =
178 gSum(outletPatch.magSf()*outletPatchField)
179 /gSum(outletPatch.magSf());
180
181 operator==(averageOutletField);
182 }
183
184 fixedValueFvPatchScalarField::updateCoeffs();
185}
186
187
189(
190 Ostream& os
191) const
192{
194 os.writeEntry("outletPatch", outletPatchName_);
195 os.writeEntryIfDifferent<word>("phi", "phi", phiName_);
196 os.writeEntry("Q", Q_);
197 os.writeEntry("TMin", TMin_);
198 os.writeEntry("TMax", TMax_);
199
200 this->writeEntry("value", os);
201}
202
203
204// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205
206namespace Foam
207{
209 (
212 );
213}
214
215
216// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
surfaceScalarField & phi
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const Boundary & boundaryField() const
Return const-reference to the boundary field.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:239
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:251
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:66
static const word dictName
Definition: basicThermo.H:256
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
virtual bool write()
Write the output fields.
A FieldMapper for finite-volume patch fields.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:82
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
const scalarField & magSf() const
Return face area magnitudes.
Definition: fvPatch.C:156
const fvBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: fvPatch.H:209
const polyPatch & patch() const
Return the polyPatch.
Definition: fvPatch.H:167
This temperature boundary condition averages the temperature over the "outlet" patch specified by nam...
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
label findPatchID(const word &patchName, const bool allowNotFound=true) const
Find patch index given a name, return -1 if not found.
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:315
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
#define makePatchTypeField(PatchTypeField, typePatchTypeField)
Definition: fvPatchField.H:676
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Type gSum(const FieldField< Field, Type > &f)
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Type gAverage(const FieldField< Field, Type > &f)
error FatalError
dictionary dict
Foam::surfaceFields.