wallHeatTransferCoeff.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2020-2026 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 
26 #include "wallHeatTransferCoeff.H"
29 #include "fvsPatchField.H"
30 #include "basicThermo.H"
31 #include "wallPolyPatch.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionObjects
39 {
42  (
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
52 
54 (
55  const label i
56 )
57 {
58  // Add headers to output data
59  writeHeader(file(), "Wall heat transfer coefficient");
60  writeCommented(file(), "Time");
61  writeTabbed(file(), "patch");
62  writeTabbed(file(), "min");
63  writeTabbed(file(), "max");
64  writeTabbed(file(), "average");
65  file() << endl;
66 }
67 
68 
69 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
70 
72 (
73  const word& name,
74  const Time& runTime,
75  const dictionary& dict
76 )
77 :
78  fvMeshFunctionObject(name, runTime, dict),
79  logFiles(obr_, name),
80  writeLocalObjects(obr_, log),
81  coeffModel_(wallHeatTransferCoeffModel::New(dict.name(), mesh_, dict)),
82  rho_("rho", dimDensity, Zero),
83  Cp_("Cp", dimArea/sqr(dimTime)/dimTemperature, Zero),
84  runTime_(runTime),
85  patchSet_()
86 {
87  read(dict);
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
92 
94 {}
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
100 {
103 
104  if (!foundObject<basicThermo>(physicalProperties::typeName))
105  {
106  rho_.read(dict);
107  Cp_.read(dict);
108  }
109 
110  const polyBoundaryMesh& pbm = mesh_.poly().boundary();
111 
112  patchSet_ = mesh_.poly().boundary().patchSet(dict, true);
113 
114  if (patchSet_.empty())
115  {
116  forAll(pbm, patchi)
117  {
118  if (isA<wallPolyPatch>(pbm[patchi]))
119  {
120  patchSet_.insert(patchi);
121  }
122  }
123 
124  Info<< indent << "processing all wall patches" << endl;
125  }
126  else
127  {
128  Info<< indent << "processing wall patches: " << nl;
129  labelHashSet filteredPatchSet;
130  forAllConstIter(labelHashSet, patchSet_, iter)
131  {
132  label patchi = iter.key();
133  if (isA<wallPolyPatch>(pbm[patchi]))
134  {
135  filteredPatchSet.insert(patchi);
136  Info<< indent << " " << pbm[patchi].name() << endl;
137  }
138  else
139  {
141  << "Requested wall heat-transferCoeff on non-wall boundary"
142  << " type patch: " << pbm[patchi].name() << endl;
143  }
144  }
145 
146  patchSet_ = filteredPatchSet;
147  }
148 
149  coeffModel_->read(dict);
150 
151  resetName(typeName);
152  resetLocalObjectName(typeName);
153 
154  return true;
155 }
156 
157 
159 {
160  const momentumTransportModel& transport =
161  mesh_.lookupType<momentumTransportModel>();
162 
164  (
165  coeffModel_->htcByRhoCp(transport, patchSet_)
166  );
167 
168  if (!foundObject<basicThermo>(physicalProperties::typeName))
169  {
170  thtc.ref() *= rho_*Cp_;
171  }
172  else
173  {
174  const basicThermo& thermo =
175  lookupObject<basicThermo>(physicalProperties::typeName);
176 
177  thtc.ref() *= thermo.rho()*thermo.Cp();
178  }
179 
180  store("wallHeatTransferCoeff", thtc);
181 
182  return true;
183 }
184 
185 
187 {
188  Log << name() << " write:" << nl;
189 
191  logFiles::write();
192 
193  const volScalarField& htc = obr_.lookupObject<volScalarField>(type());
194 
195  const fvPatchList& patches = mesh_.boundary();
196 
197  const surfaceScalarField::Boundary& magSf =
198  mesh_.magSf().boundaryField();
199 
200  forAllConstIter(labelHashSet, patchSet_, iter)
201  {
202  label patchi = iter.key();
203  const fvPatch& pp = patches[patchi];
204 
205  if (!returnReduce(pp.size(), orOp<bool>())) continue;
206 
207  const scalarField& hfp = htc.boundaryField()[patchi];
208 
209  const scalar minHtcp = gMin(hfp);
210  const scalar maxHtcp = gMax(hfp);
211  const scalar averageHtcp = gSum(magSf[patchi]*hfp)/gSum(magSf[patchi]);
212 
213  if (Pstream::master())
214  {
215  file()
216  << time_.userTimeValue()
217  << tab << pp.name()
218  << tab << minHtcp
219  << tab << maxHtcp
220  << tab << averageHtcp
221  << endl;
222  }
223 
224  Log << " min/max/average(" << pp.name() << ") = "
225  << minHtcp << ", " << maxHtcp << ", " << averageHtcp << endl;
226  }
227 
228  Log << endl;
229 
230  return true;
231 }
232 
233 
234 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Macros for easy insertion into run-time selection tables.
Generic GeometricBoundaryField class.
Generic GeometricField class.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:109
const word & name() const
Return name.
Definition: IOobject.H:307
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
Base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:78
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:60
OFstream & file()
Return access to the file (if only 1)
Definition: logFiles.C:113
virtual bool write()
Write function.
Definition: logFiles.C:173
Calculates the natural logarithm of the specified scalar field.
Definition: log.H:106
virtual bool read(const dictionary &)
Read optional controls.
Calculates and writes the estimated heat transfer coefficient at wall patches as the volScalarField f...
wallHeatTransferCoeff(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, mesh and dict.
virtual void writeFileHeader(const label i)
File header information.
virtual bool execute()
Calculate the wall heat transfer coefficient.
virtual bool write()
Write the wall heat transfer coefficient.
virtual bool read(const dictionary &)
Read the wallHeatTransferCoeffs data.
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:121
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:131
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:110
FunctionObject base class for managing a list of objects on behalf of the inheriting function object,...
virtual bool read(const dictionary &)
Read the list of objects to be written.
virtual bool write()
Write function.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:58
virtual label size() const
Return size.
Definition: fvPatch.H:147
virtual const word & name() const
Return name.
Definition: fvPatch.H:135
Abstract base class for momentum transport models (RAS, LES and laminar).
Foam::polyBoundaryMesh.
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the patch set corresponding to the given names.
A class for managing temporary objects.
Definition: tmp.H:55
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
Abstract base class for run time selection of heat transfer coefficient models.
A class for handling words, derived from string.
Definition: word.H:63
label patchi
const fvPatchList & patches
#define WarningInFunction
Report a warning using Foam::Warning.
#define Log
Report write to Foam::Info if the local log switch is true.
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
Namespace for OpenFOAM.
Type gMin(const UList< Type > &f, const label comm)
static const zero Zero
Definition: zero.H:97
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
static const char tab
Definition: Ostream.H:296
messageStream Info
Type gSum(const UList< Type > &f, const label comm)
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
const dimensionSet & dimTime
Definition: dimensions.C:142
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
const dimensionSet & dimDensity
Definition: dimensions.C:158
Type gMax(const UList< Type > &f, const label comm)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
const dimensionSet & dimArea
Definition: dimensions.C:149
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:243
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
static const char nl
Definition: Ostream.H:297
const dimensionSet & dimTemperature
Definition: dimensions.C:143
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
fluidMulticomponentThermo & thermo
Definition: createFields.H:15