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-2018 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 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 namespace functionObjects
43 {
44  defineTypeNameAndDebug(wallHeatFlux, 0);
45  addToRunTimeSelectionTable(functionObject, wallHeatFlux, dictionary);
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
51 
53 {
54  // Add headers to output data
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  forAll(wallHeatFluxBf, patchi)
79  {
80  if (!wallHeatFluxBf[patchi].coupled())
81  {
82  wallHeatFluxBf[patchi] = alphaBf[patchi]*heBf[patchi].snGrad();
83  }
84  }
85 
86  if (foundObject<volScalarField>(qrName_))
87  {
88  const volScalarField& qr = lookupObject<volScalarField>(qrName_);
89 
90  const volScalarField::Boundary& radHeatFluxBf = qr.boundaryField();
91 
92  forAll(wallHeatFluxBf, patchi)
93  {
94  if (!wallHeatFluxBf[patchi].coupled())
95  {
96  wallHeatFluxBf[patchi] -= radHeatFluxBf[patchi];
97  }
98  }
99  }
100 }
101 
102 
103 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
104 
105 Foam::functionObjects::wallHeatFlux::wallHeatFlux
106 (
107  const word& name,
108  const Time& runTime,
109  const dictionary& dict
110 )
111 :
113  writeFile(obr_, name, typeName, dict),
114  patchSet_(),
115  qrName_("qr")
116 {
117  volScalarField* wallHeatFluxPtr
118  (
119  new volScalarField
120  (
121  IOobject
122  (
123  type(),
124  mesh_.time().timeName(),
125  mesh_,
128  ),
129  mesh_,
131  )
132  );
133 
134  mesh_.objectRegistry::store(wallHeatFluxPtr);
135 
136  read(dict);
137 
138  writeFileHeader(file());
139 }
140 
141 
142 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
143 
145 {}
146 
147 
148 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
149 
151 {
154 
155  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
156 
157  patchSet_ =
158  mesh_.boundaryMesh().patchSet
159  (
160  wordReList(dict.lookupOrDefault("patches", wordReList()))
161  );
162 
163  dict.readIfPresent("qr", qrName_);
164 
165  Info<< type() << " " << name() << ":" << nl;
166 
167  if (patchSet_.empty())
168  {
169  forAll(pbm, patchi)
170  {
171  if (isA<wallPolyPatch>(pbm[patchi]))
172  {
173  patchSet_.insert(patchi);
174  }
175  }
176 
177  Info<< " processing all wall patches" << nl << endl;
178  }
179  else
180  {
181  Info<< " processing wall patches: " << nl;
182  labelHashSet filteredPatchSet;
183  for (const label patchi : patchSet_)
184  {
185  if (isA<wallPolyPatch>(pbm[patchi]))
186  {
187  filteredPatchSet.insert(patchi);
188  Info<< " " << pbm[patchi].name() << endl;
189  }
190  else
191  {
193  << "Requested wall heat-flux on non-wall boundary "
194  << "type patch: " << pbm[patchi].name() << endl;
195  }
196  }
197 
198  Info<< endl;
199 
200  patchSet_ = filteredPatchSet;
201  }
202 
203  return true;
204 }
205 
206 
208 {
209  volScalarField& wallHeatFlux = lookupObjectRef<volScalarField>(type());
210 
211  if
212  (
213  foundObject<compressible::turbulenceModel>
214  (
216  )
217  )
218  {
219  const compressible::turbulenceModel& turbModel =
220  lookupObject<compressible::turbulenceModel>
221  (
223  );
224 
225  calcHeatFlux
226  (
227  turbModel.alphaEff()(),
228  turbModel.transport().he(),
230  );
231  }
232  else if (foundObject<fluidThermo>(fluidThermo::dictName))
233  {
234  const fluidThermo& thermo =
235  lookupObject<fluidThermo>(fluidThermo::dictName);
236 
237  calcHeatFlux
238  (
239  thermo.alpha(),
240  thermo.he(),
242  );
243  }
244  else if (foundObject<solidThermo>(solidThermo::dictName))
245  {
246  const solidThermo& thermo =
247  lookupObject<solidThermo>(solidThermo::dictName);
248 
249  calcHeatFlux(thermo.alpha(), thermo.he(), wallHeatFlux);
250  }
251  else
252  {
254  << "Unable to find compressible turbulence model in the "
255  << "database" << exit(FatalError);
256  }
257 
258  return true;
259 }
260 
261 
263 {
264  const volScalarField& wallHeatFlux = lookupObject<volScalarField>(type());
265 
266  Log << type() << " " << name() << " write:" << nl
267  << " writing field " << wallHeatFlux.name() << endl;
268 
270 
271  const fvPatchList& patches = mesh_.boundary();
272 
273  const surfaceScalarField::Boundary& magSf =
274  mesh_.magSf().boundaryField();
275 
276  for (const label patchi : patchSet_)
277  {
278  const fvPatch& pp = patches[patchi];
279 
280  const scalarField& hfp = wallHeatFlux.boundaryField()[patchi];
281 
282  const scalar minHfp = gMin(hfp);
283  const scalar maxHfp = gMax(hfp);
284  const scalar integralHfp = gSum(magSf[patchi]*hfp);
285 
286  if (Pstream::master())
287  {
288  writeCurrentTime(file());
289 
290  file()
291  << token::TAB << pp.name()
292  << token::TAB << minHfp
293  << token::TAB << maxHfp
294  << token::TAB << integralHfp
295  << endl;
296  }
297 
298  Log << " min/max/integ(" << pp.name() << ") = "
299  << minHfp << ", " << maxHfp << ", " << integralHfp << endl;
300  }
301 
302  return true;
303 }
304 
305 
306 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::functionObjects::wallHeatFlux
Calculates and write the heat-flux at wall patches as the volScalarField field 'wallHeatFlux'.
Definition: wallHeatFlux.H:116
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
wallHeatFlux.H
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:46
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::constant::atomic::alpha
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Definition: readThermalProperties.H:212
Foam::functionObjects::wallHeatFlux::calcHeatFlux
void calcHeatFlux(const volScalarField &alpha, const volScalarField &he, volScalarField &wallHeatFlux)
Calculate the heat-flux.
Definition: wallHeatFlux.C:66
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
fvcSnGrad.H
Calculate the snGrad of the given volField.
Foam::wordReList
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:52
Foam::turbulenceModel::propertiesName
static const word propertiesName
Default name of the turbulence properties dictionary.
Definition: turbulenceModel.H:100
wallPolyPatch.H
Foam::fluidThermo
Fundamental fluid thermodynamic properties.
Definition: fluidThermo.H:52
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::functionObjects::wallHeatFlux::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
File header information.
Definition: wallHeatFlux.C:52
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
Foam::fvPatch::name
virtual const word & name() const
Return name.
Definition: fvPatch.H:151
Foam::HashSet< label, Hash< label > >
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, add, dictionary)
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
solidThermo.H
Foam::functionObjects::wallHeatFlux::execute
virtual bool execute()
Calculate the wall heat-flux.
Definition: wallHeatFlux.C:207
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:284
Foam::solidThermo
Fundamental solid thermodynamic properties.
Definition: solidThermo.H:52
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:54
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:212
Foam::label
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:62
Foam::Field< scalar >
Foam::pow3
dimensionedScalar pow3(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:89
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:65
Foam::dictionary::dictName
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionary.H:458
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::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:166
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::dimMass
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:52
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:438
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::functionObjects::wallHeatFlux::~wallHeatFlux
virtual ~wallHeatFlux()
Destructor.
Definition: wallHeatFlux.C:144
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:258
he
volScalarField & he
Definition: YEEqn.H:52
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::ThermalDiffusivity::alphaEff
virtual tmp< volScalarField > alphaEff() const
Return the effective turbulent thermal diffusivity for enthalpy.
Definition: ThermalDiffusivity.H:160
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
Foam::ThermalDiffusivity
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
Definition: phaseCompressibleTurbulenceModelFwd.H:47
Foam::List< wordRe >
Foam::token::TAB
Tab [isspace].
Definition: token.H:113
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::polyBoundaryMesh::patchSet
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.
Definition: polyBoundaryMesh.C:857
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:182
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::functionObjects::wallHeatFlux::write
virtual bool write()
Write the wall heat-flux.
Definition: wallHeatFlux.C:262
Foam::functionObjects::writeFile
functionObject base class for writing single files
Definition: writeFile.H:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:593
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:123
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::functionObjects::writeFile::writeTabbed
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:274
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592
turbulentFluidThermoModel.H
Log
#define Log
Report write to Foam::Info if the local log switch is true.
Definition: messageStream.H:332
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62
Foam::functionObjects::wallHeatFlux::read
virtual bool read(const dictionary &)
Read the wallHeatFlux data.
Definition: wallHeatFlux.C:150