wallHeatFlux.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-2017 OpenFOAM Foundation
9  Copyright (C) 2016-2022 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 
29 #include "wallHeatFlux.H"
31 #include "solidThermo.H"
32 #include "surfaceInterpolate.H"
33 #include "fvcSnGrad.H"
34 #include "wallPolyPatch.H"
37 #include "multiphaseInterSystem.H"
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 namespace functionObjects
44 {
45  defineTypeNameAndDebug(wallHeatFlux, 0);
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
52 
54 {
55  writeHeader(os, "Wall heat-flux");
56  writeCommented(os, "Time");
57  writeTabbed(os, "patch");
58  writeTabbed(os, "min");
59  writeTabbed(os, "max");
60  writeTabbed(os, "integral");
61  os << endl;
62 }
63 
64 
66 (
67  const volScalarField& alpha,
68  const volScalarField& he,
70 )
71 {
72  volScalarField::Boundary& wallHeatFluxBf = wallHeatFlux.boundaryFieldRef();
73 
74  const volScalarField::Boundary& heBf = he.boundaryField();
75 
76  const volScalarField::Boundary& alphaBf = alpha.boundaryField();
77 
78  for (const label patchi : patchSet_)
79  {
80  wallHeatFluxBf[patchi] = alphaBf[patchi]*heBf[patchi].snGrad();
81  }
82 
83 
84  const auto* qrPtr = cfindObject<volScalarField>(qrName_);
85 
86  if (qrPtr)
87  {
88  const volScalarField::Boundary& radHeatFluxBf = qrPtr->boundaryField();
89 
90  for (const label patchi : patchSet_)
91  {
92  wallHeatFluxBf[patchi] -= radHeatFluxBf[patchi];
93  }
94  }
95 }
96 
97 
98 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
99 
101 (
102  const word& name,
103  const Time& runTime,
104  const dictionary& dict
105 )
106 :
107  fvMeshFunctionObject(name, runTime, dict),
108  writeFile(obr_, name, typeName, dict),
109  patchSet_(),
110  qrName_("qr")
111 {
112  volScalarField* wallHeatFluxPtr
113  (
114  new volScalarField
115  (
116  IOobject
117  (
118  scopedName(typeName),
119  mesh_.time().timeName(),
120  mesh_,
123  ),
124  mesh_,
126  )
127  );
128 
129  mesh_.objectRegistry::store(wallHeatFluxPtr);
130 
131  read(dict);
134 }
135 
136 
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 
140 {
143 
144  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
145 
146  patchSet_ =
147  mesh_.boundaryMesh().patchSet
148  (
149  dict.getOrDefault<wordRes>("patches", wordRes())
150  );
151 
152  dict.readIfPresent("qr", qrName_);
153 
154  Info<< type() << " " << name() << ":" << nl;
155 
156  if (patchSet_.empty())
157  {
158  forAll(pbm, patchi)
159  {
160  if (isA<wallPolyPatch>(pbm[patchi]))
161  {
162  patchSet_.insert(patchi);
163  }
164  }
165 
166  Info<< " processing all wall patches" << nl << endl;
167  }
168  else
169  {
170  Info<< " processing wall patches: " << nl;
171  labelHashSet filteredPatchSet;
172  for (const label patchi : patchSet_)
173  {
174  if (isA<wallPolyPatch>(pbm[patchi]))
175  {
176  filteredPatchSet.insert(patchi);
177  Info<< " " << pbm[patchi].name() << endl;
178  }
179  else
180  {
182  << "Requested wall heat-flux on non-wall boundary "
183  << "type patch: " << pbm[patchi].name() << endl;
184  }
185  }
186 
187  Info<< endl;
188 
189  patchSet_ = filteredPatchSet;
190  }
191 
192  return true;
193 }
194 
195 
197 {
198  auto& wallHeatFlux = lookupObjectRef<volScalarField>(scopedName(typeName));
199 
200  if
201  (
202  foundObject<compressible::turbulenceModel>
203  (
205  )
206  )
207  {
208  const compressible::turbulenceModel& turbModel =
209  lookupObject<compressible::turbulenceModel>
210  (
212  );
213 
214  calcHeatFlux
215  (
216  turbModel.alphaEff()(),
217  turbModel.transport().he(),
218  wallHeatFlux
219  );
220  }
221  else if (foundObject<fluidThermo>(fluidThermo::dictName))
222  {
223  const fluidThermo& thermo =
224  lookupObject<fluidThermo>(fluidThermo::dictName);
225 
226  calcHeatFlux
227  (
228  thermo.alpha(),
229  thermo.he(),
230  wallHeatFlux
231  );
232  }
233  else if (foundObject<solidThermo>(solidThermo::dictName))
234  {
235  const solidThermo& thermo =
236  lookupObject<solidThermo>(solidThermo::dictName);
237 
238  calcHeatFlux(thermo.alpha(), thermo.he(), wallHeatFlux);
239  }
240  else if
241  (
242  foundObject<multiphaseInterSystem>
244  )
245  {
246  const auto& thermo = lookupObject<multiphaseInterSystem>
247  (
249  );
250 
251  calcHeatFlux(thermo.kappaEff()(), thermo.T(), wallHeatFlux);
252  }
253  else
254  {
256  << "Unable to find compressible turbulence model in the "
257  << "database" << exit(FatalError);
258  }
259 
260  const fvPatchList& patches = mesh_.boundary();
261 
262  const surfaceScalarField::Boundary& magSf = mesh_.magSf().boundaryField();
263 
264  for (const label patchi : patchSet_)
265  {
266  const fvPatch& pp = patches[patchi];
267 
268  const scalarField& hfp = wallHeatFlux.boundaryField()[patchi];
269 
270  const scalar minHfp = gMin(hfp);
271  const scalar maxHfp = gMax(hfp);
272  const scalar integralHfp = gSum(magSf[patchi]*hfp);
273 
274  if (Pstream::master())
275  {
276  writeCurrentTime(file());
277 
278  file()
279  << token::TAB << pp.name()
280  << token::TAB << minHfp
281  << token::TAB << maxHfp
282  << token::TAB << integralHfp
283  << endl;
284  }
285 
286  Log << " min/max/integ(" << pp.name() << ") = "
287  << minHfp << ", " << maxHfp << ", " << integralHfp << endl;
288 
289  this->setResult("min(" + pp.name() + ")", minHfp);
290  this->setResult("max(" + pp.name() + ")", maxHfp);
291  this->setResult("int(" + pp.name() + ")", integralHfp);
292  }
293 
294 
295  return true;
296 }
297 
298 
300 {
301  const auto& wallHeatFlux =
302  lookupObject<volScalarField>(scopedName(typeName));
303 
304  Log << type() << " " << name() << " write:" << nl
305  << " writing field " << wallHeatFlux.name() << endl;
306 
307  wallHeatFlux.write();
308 
309  return true;
310 }
311 
312 
313 // ************************************************************************* //
volScalarField & he
Definition: YEEqn.H:52
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:53
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:264
dictionary dict
defineTypeNameAndDebug(ObukhovLength, 0)
wallHeatFlux(const word &name, const Time &runTime, const dictionary &)
Construct from Time and dictionary.
Definition: wallHeatFlux.C:94
virtual bool execute()
Calculate the wall heat-flux.
Definition: wallHeatFlux.C:189
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:339
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
static const word phasePropertiesName
Default name of the phase properties dictionary.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
Type gMin(const FieldField< Field, Type > &f)
Tab [isspace].
Definition: token.H:126
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:150
virtual void writeFileHeader(Ostream &os) const
File header information.
Definition: wallHeatFlux.C:46
virtual bool write()
Write the wall heat-flux.
Definition: wallHeatFlux.C:292
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
Calculate the snGrad of the given volField.
GeometricBoundaryField< scalar, fvsPatchField, surfaceMesh > Boundary
Type of boundary fields.
Ignore writing from objectRegistry::writeObject()
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:361
Abstract base-class for Time/database function objects.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:227
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
virtual tmp< volScalarField > alphaEff() const
Return the effective turbulent thermal diffusivity for enthalpy.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
psiReactionThermo & thermo
Definition: createFields.H:28
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:752
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:313
Type gSum(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
static const word propertiesName
Default name of the turbulence properties dictionary.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:47
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time formatted with the given precision.
Definition: Time.C:760
Type gMax(const FieldField< Field, Type > &f)
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:241
void calcHeatFlux(const volScalarField &alpha, const volScalarField &he, volScalarField &wallHeatFlux)
Calculate the heat-flux.
Definition: wallHeatFlux.C:59
dimensionedScalar pow3(const dimensionedScalar &ds)
#define WarningInFunction
Report a warning using Foam::Warning.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
static bool master(const label communicator=worldComm)
Am I the master rank.
Definition: UPstream.H:672
const polyBoundaryMesh & patches
Nothing to be read.
#define Log
Definition: PDRblock.C:28
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool read(const dictionary &dict)
Read optional controls.
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
Computes the wall-heat flux at selected wall patches.
Definition: wallHeatFlux.H:156
virtual bool read(const dictionary &dict)
Read the wallHeatFlux data.
Definition: wallHeatFlux.C:132
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:49
virtual bool write(const bool valid=true) const
Write using setting from DB.
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
word scopedName(const word &name) const
Return a scoped (prefixed) name.
const fvMesh & mesh_
Reference to the fvMesh.
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
Namespace for OpenFOAM.
PtrList< fvPatch > fvPatchList
Store lists of fvPatch as a PtrList.
Definition: fvPatch.H:57
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:157
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:329