wallHeatFlux.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) 2016-2018 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 "wallHeatFlux.H"
28 #include "solidThermo.H"
29 #include "surfaceInterpolate.H"
30 #include "fvcSnGrad.H"
31 #include "wallPolyPatch.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionObjects
39 {
40  defineTypeNameAndDebug(wallHeatFlux, 0);
41  addToRunTimeSelectionTable(functionObject, wallHeatFlux, dictionary);
42 }
43 }
44 
45 
46 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
47 
49 {
50  // Add headers to output data
51  writeHeader(file(), "Wall heat-flux");
52  writeCommented(file(), "Time");
53  writeTabbed(file(), "patch");
54  writeTabbed(file(), "min");
55  writeTabbed(file(), "max");
56  writeTabbed(file(), "integral");
57  file() << endl;
58 }
59 
60 
63 (
64  const volScalarField& alpha,
65  const volScalarField& he
66 )
67 {
68  tmp<volScalarField> twallHeatFlux
69  (
71  (
72  type(),
73  mesh_,
75  )
76  );
77 
78  volScalarField::Boundary& wallHeatFluxBf =
79  twallHeatFlux.ref().boundaryFieldRef();
80 
81  const volScalarField::Boundary& heBf =
82  he.boundaryField();
83 
84  const volScalarField::Boundary& alphaBf =
85  alpha.boundaryField();
86 
87  forAll(wallHeatFluxBf, patchi)
88  {
89  if (!wallHeatFluxBf[patchi].coupled())
90  {
91  wallHeatFluxBf[patchi] = alphaBf[patchi]*heBf[patchi].snGrad();
92  }
93  }
94 
95  if (foundObject<volScalarField>("qr"))
96  {
97  const volScalarField& qr = lookupObject<volScalarField>("qr");
98 
99  const volScalarField::Boundary& radHeatFluxBf =
100  qr.boundaryField();
101 
102  forAll(wallHeatFluxBf, patchi)
103  {
104  if (!wallHeatFluxBf[patchi].coupled())
105  {
106  wallHeatFluxBf[patchi] -= radHeatFluxBf[patchi];
107  }
108  }
109  }
110 
111  return twallHeatFlux;
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
116 
118 (
119  const word& name,
120  const Time& runTime,
121  const dictionary& dict
122 )
123 :
124  fvMeshFunctionObject(name, runTime, dict),
125  logFiles(obr_, name),
126  writeLocalObjects(obr_, log),
127  patchSet_()
128 {
129  read(dict);
130  resetName(typeName);
131  resetLocalObjectName(typeName);
132 }
133 
134 
135 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
136 
138 {}
139 
140 
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 
144 {
147 
148  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
149 
150  patchSet_ =
151  mesh_.boundaryMesh().patchSet
152  (
153  wordReList(dict.lookupOrDefault("patches", wordReList()))
154  );
155 
156  Info<< type() << " " << name() << ":" << nl;
157 
158  if (patchSet_.empty())
159  {
160  forAll(pbm, patchi)
161  {
162  if (isA<wallPolyPatch>(pbm[patchi]))
163  {
164  patchSet_.insert(patchi);
165  }
166  }
167 
168  Info<< " processing all wall patches" << nl << endl;
169  }
170  else
171  {
172  Info<< " processing wall patches: " << nl;
173  labelHashSet filteredPatchSet;
174  forAllConstIter(labelHashSet, patchSet_, iter)
175  {
176  label patchi = iter.key();
177  if (isA<wallPolyPatch>(pbm[patchi]))
178  {
179  filteredPatchSet.insert(patchi);
180  Info<< " " << pbm[patchi].name() << endl;
181  }
182  else
183  {
185  << "Requested wall heat-flux on non-wall boundary "
186  << "type patch: " << pbm[patchi].name() << endl;
187  }
188  }
189 
190  Info<< endl;
191 
192  patchSet_ = filteredPatchSet;
193  }
194 
195  return true;
196 }
197 
198 
200 {
201  word name(type());
202 
203  if
204  (
205  foundObject<compressible::turbulenceModel>
206  (
208  )
209  )
210  {
211  const compressible::turbulenceModel& turbModel =
212  lookupObject<compressible::turbulenceModel>
213  (
215  );
216 
217  return store
218  (
219  name,
220  calcWallHeatFlux(turbModel.alphaEff(), turbModel.transport().he())
221  );
222  }
223  else if (foundObject<solidThermo>(solidThermo::dictName))
224  {
225  const solidThermo& thermo =
226  lookupObject<solidThermo>(solidThermo::dictName);
227 
228  return store(name, calcWallHeatFlux(thermo.alpha(), thermo.he()));
229  }
230  else
231  {
233  << "Unable to find compressible turbulence model in the "
234  << "database" << exit(FatalError);
235  }
236 
237  return true;
238 }
239 
240 
242 {
243  Log << type() << " " << name() << " write:" << nl;
244 
246 
247  logFiles::write();
248 
251 
252  const fvPatchList& patches = mesh_.boundary();
253 
254  const surfaceScalarField::Boundary& magSf =
255  mesh_.magSf().boundaryField();
256 
257  forAllConstIter(labelHashSet, patchSet_, iter)
258  {
259  label patchi = iter.key();
260  const fvPatch& pp = patches[patchi];
261 
262  const scalarField& hfp = wallHeatFlux.boundaryField()[patchi];
263 
264  const scalar minHfp = gMin(hfp);
265  const scalar maxHfp = gMax(hfp);
266  const scalar integralHfp = gSum(magSf[patchi]*hfp);
267 
268  if (Pstream::master())
269  {
270  file()
271  << mesh_.time().value()
272  << tab << pp.name()
273  << tab << minHfp
274  << tab << maxHfp
275  << tab << integralHfp
276  << endl;
277  }
278 
279  Log << " min/max/integ(" << pp.name() << ") = "
280  << minHfp << ", " << maxHfp << ", " << integralHfp << endl;
281  }
282 
283  Log << endl;
284 
285  return true;
286 }
287 
288 
289 // ************************************************************************* //
virtual bool write()
Write function.
Calculates the natural logarithm of the specified scalar field.
Definition: log.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual bool write()
Write function.
Definition: logFiles.C:180
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
const word & name() const
Return name.
Definition: IOobject.H:295
wallHeatFlux(const word &name, const Time &runTime, const dictionary &)
Construct from Time and dictionary.
Definition: wallHeatFlux.C:118
virtual bool execute()
Calculate the wall heat-flux.
Definition: wallHeatFlux.C:199
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const char tab
Definition: Ostream.H:264
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Type gMin(const FieldField< Field, Type > &f)
const Boundary & boundaryField() const
Return const-reference to the boundary field.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
virtual bool write()
Write the wall heat-flux.
Definition: wallHeatFlux.C:241
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
virtual ~wallHeatFlux()
Destructor.
Definition: wallHeatFlux.C:137
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
virtual const volScalarField & alpha() const
Thermal diffusivity for enthalpy of mixture [kg/m/s].
Definition: basicThermo.C:501
Calculate the snGrad of the given volField.
patches[0]
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
rhoReactionThermo & thermo
Definition: createFields.H:28
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:108
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the set of patch IDs corresponding to the given names.
const ObjectType & lookupObject(const word &fieldName) const
Lookup object from the objectRegistry.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
virtual volScalarField & he()=0
Enthalpy/Internal energy [J/kg].
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:123
static tmp< GeometricField< scalar, fvPatchField, volMesh > > New(const word &name, const Mesh &, const dimensionSet &, const word &patchFieldType=fvPatchField< scalar >::calculatedType())
Return a temporary field constructed from name, mesh, dimensionSet.
virtual tmp< volScalarField > alphaEff() const
Effective thermal turbulent diffusivity of mixture [kg/m/s].
tmp< volScalarField > calcWallHeatFlux(const volScalarField &alpha, const volScalarField &he)
Calculate the heat-flux.
Definition: wallHeatFlux.C:63
virtual bool read(const dictionary &)
Read optional controls.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
Type gSum(const FieldField< Field, Type > &f)
static const word propertiesName
Default name of the turbulence properties dictionary.
A class for handling words, derived from string.
Definition: word.H:59
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
Foam::polyBoundaryMesh.
static const char nl
Definition: Ostream.H:265
Type gMax(const FieldField< Field, Type > &f)
virtual void writeFileHeader(const label i)
File header information.
Definition: wallHeatFlux.C:48
Fundamental solid thermodynamic properties.
Definition: solidThermo.H:48
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
defineTypeNameAndDebug(Qdot, 0)
dimensionedScalar pow3(const dimensionedScalar &ds)
label patchi
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
#define WarningInFunction
Report a warning using Foam::Warning.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
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.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
#define Log
Report write to Foam::Info if the local log switch is true.
messageStream Info
virtual bool read(const dictionary &)
Read the wallHeatFlux data.
Definition: wallHeatFlux.C:143
virtual const word & name() const
Return name.
Definition: fvPatch.H:143
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Calculates and write the heat-flux at wall patches as the volScalarField field &#39;wallHeatFlux&#39;.
Definition: wallHeatFlux.H:109
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:49
A class for managing temporary objects.
Definition: PtrList.H:53
Namespace for OpenFOAM.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57