effectivenessHeatExchangerSource.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) 2013-2015 OpenFOAM Foundation
9  Copyright (C) 2016-2021 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 
30 #include "fvMesh.H"
31 #include "fvMatrix.H"
33 #include "basicThermo.H"
34 #include "coupledPolyPatch.H"
35 #include "surfaceInterpolate.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 namespace fv
42 {
43  defineTypeNameAndDebug(effectivenessHeatExchangerSource, 0);
45  (
46  option,
47  effectivenessHeatExchangerSource,
48  dictionary
49  );
50 }
51 }
52 
53 
54 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
55 
56 void Foam::fv::effectivenessHeatExchangerSource::initialise()
57 {
59 
60  if (zoneID < 0)
61  {
63  << type() << " " << this->name() << ": "
64  << " Unknown face zone name: " << faceZoneName_
65  << ". Valid face zones are: " << mesh_.faceZones().names()
66  << exit(FatalError);
67  }
68 
69  const faceZone& fZone = mesh_.faceZones()[zoneID];
70 
71  faceId_.setSize(fZone.size());
72  facePatchId_.setSize(fZone.size());
73  faceSign_.setSize(fZone.size());
74 
75  label count = 0;
76  forAll(fZone, i)
77  {
78  label facei = fZone[i];
79  label faceId = -1;
80  label facePatchId = -1;
81  if (mesh_.isInternalFace(facei))
82  {
83  faceId = facei;
84  facePatchId = -1;
85  }
86  else
87  {
88  facePatchId = mesh_.boundaryMesh().whichPatch(facei);
89  const polyPatch& pp = mesh_.boundaryMesh()[facePatchId];
90  const auto* cpp = isA<coupledPolyPatch>(pp);
91 
92  if (cpp)
93  {
94  faceId = (cpp->owner() ? pp.whichFace(facei) : -1);
95  }
96  else if (!isA<emptyPolyPatch>(pp))
97  {
98  faceId = pp.whichFace(facei);
99  }
100  else
101  {
102  faceId = -1;
103  facePatchId = -1;
104  }
105  }
106 
107  if (faceId >= 0)
108  {
109  if (fZone.flipMap()[i])
110  {
111  faceSign_[count] = -1;
112  }
113  else
114  {
115  faceSign_[count] = 1;
116  }
117  faceId_[count] = faceId;
118  facePatchId_[count] = facePatchId;
119  count++;
120  }
121  }
125 }
126 
127 
128 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
129 
131 (
132  const word& name,
133  const word& modelType,
134  const dictionary& dict,
135  const fvMesh& mesh
136 )
137 :
138  fv::cellSetOption(name, modelType, dict, mesh),
139  secondaryMassFlowRate_(0),
140  secondaryInletT_(0),
141  primaryInletT_(0),
142  userPrimaryInletT_(false),
143  targetQdotActive_(false),
144  targetQdot_(0),
145  targetQdotCalcInterval_(5),
146  targetQdotRelax_(0.5),
147  eTable_(),
148  UName_("U"),
149  TName_("T"),
150  phiName_("phi"),
151  faceZoneName_("unknown-faceZone"),
152  faceId_(),
153  facePatchId_(),
154  faceSign_()
155 {
156  read(dict);
157 
158  // Set the field name to that of the energy
159  // field from which the temperature is obtained
160 
161  const auto& thermo = mesh_.lookupObject<basicThermo>(basicThermo::dictName);
162 
163  fieldNames_.resize(1, thermo.he().name());
164 
166 
167  eTable_.reset(new interpolation2DTable<scalar>(coeffs_));
168 
169  initialise();
170 }
171 
172 
173 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
174 
176 (
177  const volScalarField& rho,
178  fvMatrix<scalar>& eqn,
179  const label
180 )
181 {
182  const auto& thermo = mesh_.lookupObject<basicThermo>(basicThermo::dictName);
183 
184  const surfaceScalarField Cpf(fvc::interpolate(thermo.Cp()));
185 
186  const auto& phi = mesh_.lookupObject<surfaceScalarField>(phiName_);
187 
188  const auto& T = mesh_.lookupObject<volScalarField>(TName_);
190 
191  scalar sumPhi = 0;
192  scalar sumMagPhi = 0;
193  scalar CpfMean = 0;
194  scalar primaryInletTfMean = 0;
195  forAll(faceId_, i)
196  {
197  label facei = faceId_[i];
198  if (facePatchId_[i] != -1)
199  {
200  label patchi = facePatchId_[i];
201  scalar phii = phi.boundaryField()[patchi][facei]*faceSign_[i];
202 
203  sumPhi += phii;
204 
205  scalar Cpfi = Cpf.boundaryField()[patchi][facei];
206  scalar Tfi = Tf.boundaryField()[patchi][facei];
207  scalar magPhii = mag(phii);
208 
209  sumMagPhi += magPhii;
210  CpfMean += Cpfi*magPhii;
211  primaryInletTfMean += Tfi*magPhii;
212  }
213  else
214  {
215  scalar phii = phi[facei]*faceSign_[i];
216  scalar magPhii = mag(phii);
217 
218  sumPhi += phii;
219  sumMagPhi += magPhii;
220  CpfMean += Cpf[facei]*magPhii;
221  primaryInletTfMean += Tf[facei]*magPhii;
222  }
223  }
224  reduce(CpfMean, sumOp<scalar>());
225  reduce(sumPhi, sumOp<scalar>());
226  reduce(sumMagPhi, sumOp<scalar>());
227  CpfMean /= sumMagPhi + ROOTVSMALL;
228 
229  scalar primaryInletT = primaryInletT_;
230  if (!userPrimaryInletT_)
231  {
232  reduce(primaryInletTfMean, sumOp<scalar>());
233  primaryInletT = primaryInletTfMean/(sumMagPhi + ROOTVSMALL);
234  }
235 
236  const scalar alpha =
237  eTable_()(mag(sumPhi), secondaryMassFlowRate_)
238  *CpfMean*mag(sumPhi);
239 
240  const scalar Qt = alpha*(secondaryInletT_ - primaryInletT);
241 
242  if
243  (
244  targetQdotActive_
245  && (mesh_.time().timeIndex() % targetQdotCalcInterval_ == 0)
246  )
247  {
248  scalar dT = (targetQdot_ - Qt)/(alpha + ROOTVSMALL);
249  secondaryInletT_ += targetQdotRelax_*dT;
250  }
251 
252  const scalarField TCells(T, cells_);
253  scalar Tref = 0;
254  scalarField deltaTCells(cells_.size(), Zero);
255  if (Qt > 0)
256  {
257  Tref = gMax(TCells);
258  forAll(deltaTCells, i)
259  {
260  deltaTCells[i] = max(Tref - TCells[i], 0.0);
261  }
262  }
263  else
264  {
265  Tref = gMin(TCells);
266  forAll(deltaTCells, i)
267  {
268  deltaTCells[i] = max(TCells[i] - Tref, 0.0);
269  }
270  }
271 
272 
273  const auto& U = mesh_.lookupObject<volVectorField>(UName_);
274  const scalarField& V = mesh_.V();
275  scalar sumWeight = 0;
276  forAll(cells_, i)
277  {
278  label celli = cells_[i];
279  sumWeight += V[celli]*mag(U[celli])*deltaTCells[i];
280  }
281  reduce(sumWeight, sumOp<scalar>());
282 
283  if (this->V() > VSMALL && mag(Qt) > VSMALL)
284  {
285  scalarField& heSource = eqn.source();
286 
287  forAll(cells_, i)
288  {
289  label celli = cells_[i];
290  heSource[celli] -=
291  Qt*V[celli]*mag(U[celli])*deltaTCells[i]
292  /(sumWeight + ROOTVSMALL);
293  }
294  }
295 
296  Info<< type() << ": " << name() << nl << incrIndent
297  << indent << "Net mass flux [Kg/s] : " << sumPhi << nl
298  << indent << "Total heat exchange [W] : " << Qt << nl
299  << indent << "Secondary inlet T [K] : " << secondaryInletT_ << nl
300  << indent << "Tref [K] : " << Tref << nl
301  << indent << "Effectiveness : "
302  << eTable_()(mag(sumPhi), secondaryMassFlowRate_) << decrIndent
303  << nl << endl;
304 }
305 
306 
308 {
310  {
311  UName_ = coeffs_.getOrDefault<word>("U", "U");
312  TName_ = coeffs_.getOrDefault<word>("T", "T");
313  phiName_ = coeffs_.getOrDefault<word>("phi", "phi");
314  coeffs_.readEntry("faceZone", faceZoneName_);
315 
316  coeffs_.readEntry("secondaryMassFlowRate", secondaryMassFlowRate_);
317  coeffs_.readEntry("secondaryInletT", secondaryInletT_);
318 
319  if (coeffs_.readIfPresent("primaryInletT", primaryInletT_))
320  {
321  userPrimaryInletT_ = true;
322  Info<< type() << " " << this->name() << ": " << indent << nl
323  << "employing user-specified primary flow inlet temperature: "
324  << primaryInletT_ << endl;
325  }
326  else
327  {
328  Info<< type() << " " << this->name() << ": " << indent << nl
329  << "employing flux-weighted primary flow inlet temperature"
330  << endl;
331  }
332 
333  if (coeffs_.readIfPresent("targetQdot", targetQdot_))
334  {
335  targetQdotActive_ = true;
336  Info<< indent << "employing target heat rejection of "
337  << targetQdot_ << nl;
338 
339  coeffs_.readIfPresent
340  (
341  "targetQdotCalcInterval",
342  targetQdotCalcInterval_
343  );
344 
345  Info<< indent << "updating secondary inlet temperature every "
346  << targetQdotCalcInterval_ << " iterations" << nl;
347 
348  coeffs_.readIfPresent("targetQdotRelax", targetQdotRelax_);
349 
350  Info<< indent << "temperature relaxation: "
351  << targetQdotRelax_ << endl;
352  }
353 
354  return true;
355  }
356 
357  return false;
358 }
359 
360 
361 // ************************************************************************* //
Foam::fv::option::name
const word & name() const noexcept
Return const access to the source name.
Definition: fvOptionI.H:31
basicThermo.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fv::cellSetOption
Intermediate abstract class for handling cell-set options for the derived fvOptions.
Definition: cellSetOption.H:163
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::fv::option::resetApplied
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: fvOption.C:48
Foam::fv::effectivenessHeatExchangerSource::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: effectivenessHeatExchangerSource.C:307
Foam::constant::atomic::alpha
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Definition: readThermalProperties.H:212
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::fv::effectivenessHeatExchangerSource::addSup
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldi)
Add explicit/implicit contribution to momentum equation.
Definition: effectivenessHeatExchangerSource.H:464
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::basicThermo
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:63
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
fvMatrix.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:346
rho
rho
Definition: readInitialConditions.H:88
Foam::fv::option::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:139
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::interpolation2DTable< scalar >
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::fv::effectivenessHeatExchangerSource::faceId_
labelList faceId_
Local list of face IDs.
Definition: effectivenessHeatExchangerSource.H:409
coupledPolyPatch.H
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
faceId
label faceId(-1)
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::fv::cellSetOption::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: cellSetOption.C:255
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::fv::effectivenessHeatExchangerSource::faceSign_
labelList faceSign_
List of +1/-1 representing face flip map (1 use as is, -1 negate)
Definition: effectivenessHeatExchangerSource.H:415
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:486
Foam::polyBoundaryMesh::whichPatch
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
Definition: polyBoundaryMesh.C:812
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::fv::effectivenessHeatExchangerSource::faceZoneName_
word faceZoneName_
Name of the faceZone at the heat exchange inlet.
Definition: effectivenessHeatExchangerSource.H:406
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:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
zoneID
const labelIOList & zoneID
Definition: interpolatedFaces.H:22
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:353
Foam::fvc::interpolate
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
Definition: ZoneMesh.C:519
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:339
Foam::ZoneMesh::names
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:305
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
fv
labelList fv(nPoints)
U
U
Definition: pEqn.H:72
Foam::primitiveMesh::isInternalFace
bool isInternalFace(const label faceIndex) const noexcept
Return true if given face label is internal to the mesh.
Definition: primitiveMeshI.H:103
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
effectivenessHeatExchangerSource.H
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
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::fvMatrix::source
Field< Type > & source()
Definition: fvMatrix.H:445
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
Foam::fv::effectivenessHeatExchangerSource::facePatchId_
labelList facePatchId_
Local list of patch ID per face.
Definition: effectivenessHeatExchangerSource.H:412
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
Foam::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:593
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::fv::effectivenessHeatExchangerSource::effectivenessHeatExchangerSource
effectivenessHeatExchangerSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: effectivenessHeatExchangerSource.C:131
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592
Foam::dictionary::dictName
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:60