lumpedMassWallTemperatureFvPatchScalarField.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-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
30 #include "fvPatchFieldMapper.H"
31 #include "volFields.H"
32 #include "mappedPatchBase.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
38 (
39  const fvPatch& p,
41 )
42 :
43  parent_bctype(p, iF),
44  temperatureCoupledBase(patch()), // default method (fluidThermo)
45  Cp_(0.0),
46  mass_(0.0),
47  curTimeIndex_(-1)
48 {
49  refValue() = 0.0;
50  refGrad() = 0.0;
51  valueFraction() = 1.0;
52 }
53 
54 
57 (
58  const this_bctype& ptf,
59  const fvPatch& p,
61  const fvPatchFieldMapper& mapper
62 )
63 :
64  parent_bctype(ptf, p, iF, mapper),
66  Cp_(ptf.Cp_),
67  mass_(ptf.mass_),
68  curTimeIndex_(-1)
69 {}
70 
71 
74 (
75  const fvPatch& p,
77  const dictionary& dict
78 )
79 :
80  parent_bctype(p, iF),
82  Cp_(dict.get<scalar>("Cp")),
83  mass_(dict.get<scalar>("mass")),
84  curTimeIndex_(-1)
85 {
87  this->readValueEntry(dict, IOobjectOption::MUST_READ);
88  refValue() = *this;
89  refGrad() = Zero;
90  valueFraction() = 1.0;
91 }
92 
93 
96 (
97  const this_bctype& tppsf,
99 )
100 :
101  parent_bctype(tppsf, iF),
102  temperatureCoupledBase(patch(), tppsf),
103  Cp_(tppsf.Cp_),
104  mass_(tppsf.mass_),
105  curTimeIndex_(-1)
106 {}
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
112 (
113  const fvPatchFieldMapper& mapper
114 )
115 {
116  this->parent_bctype::autoMap(mapper);
118 }
119 
120 
122 (
123  const fvPatchField<scalar>& ptf,
124  const labelList& addr
125 )
126 {
127  this->parent_bctype::rmap(ptf, addr);
129  const auto& tiptf = refCast<const this_bctype>(ptf);
130 
131  temperatureCoupledBase::rmap(tiptf, addr);
132 }
133 
134 
136 {
137  if (updated() || (curTimeIndex_ == this->db().time().timeIndex()))
138  {
139  return;
140  }
141 
142  // Calculate heat flux in or out the wall
143  scalarField& Tp(*this);
144  const scalarField& magSf = patch().magSf();
145 
146  const scalar deltaT(db().time().deltaTValue());
147 
148  tmp<scalarField> tkappa(kappa(Tp));
149 
150  const scalarField q(tkappa.ref()*snGrad());
151 
152  // Total heat in or out of the wall
153  const scalar Q = gWeightedSum(magSf, q);
154 
155  Tp += -(Q/mass_/Cp_)*deltaT;
156 
157  refGrad() = 0.0;
158  refValue() = Tp;
159  valueFraction() = 1.0;
160 
161  this->parent_bctype::updateCoeffs();
162 
163  if (debug)
164  {
165  scalar Qin(0);
166  scalar Qout(0);
167 
168  forAll(q, facei)
169  {
170  if (q[facei] > 0.0) // out the wall
171  {
172  Qout += q[facei]*magSf[facei];
173  }
174  else if (q[facei] < 0.0) // into the wall
175  {
176  Qin += q[facei]*magSf[facei];
177  }
178  }
179 
180  auto limits = gMinMax(*this);
181  auto avg = gAverage(*this);
182 
183  Info<< patch().boundaryMesh().mesh().name() << ':'
184  << patch().name() << ':'
185  << this->internalField().name() << " :"
186  << " heat transfer rate:" << Q
187  << " wall temperature "
188  << " min:" << limits.min()
189  << " max:" << limits.max()
190  << " avg:" << avg
191  << " Qin [W]:" << Qin
192  << " Qout [W]:" << Qout
193  << endl;
194  }
195 
196  curTimeIndex_ = this->db().time().timeIndex();
197 }
198 
199 
201 (
202  Ostream& os
203 ) const
204 {
207 
208  os.writeEntry("Cp", Cp_);
209  os.writeEntry("mass", mass_);
210 }
211 
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 namespace Foam
216 {
218  (
220  lumpedMassWallTemperatureFvPatchScalarField
221  );
222 }
223 
224 // ************************************************************************* //
dictionary dict
virtual void readDict(const dictionary &dict)
Read dictionary entries.
Type gWeightedSum(const UList< scalar > &weights, const UList< Type > &fld, const label comm)
The global weighted sum (integral) of a field, using the mag() of the weights.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:518
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
virtual void rmap(const fvPatchField< scalar > &, const labelList &)=0
Reverse map the given fvPatchField onto this fvPatchField.
virtual void autoMap(const fvPatchFieldMapper &)=0
Map (and resize as needed) from self given a mapping object.
void write(Ostream &os) const
Write.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
const dimensionedScalar kappa
Coulomb constant: default SI units: [N.m2/C2].
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:400
auto limits
Definition: setRDeltaT.H:186
fvPatchField< scalar > fvPatchScalarField
constexpr T & get(FixedList< T, N > &list) noexcept
Definition: FixedList.H:887
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
A FieldMapper for finite-volume patch fields.
virtual void write(Ostream &) const
Write.
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
virtual void rmap(const fvPatchField< scalar > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
int debug
Static debugging option.
Type gAverage(const FieldField< Field, Type > &f, const label comm)
The global arithmetic average of a FieldField.
Common functions used in temperature coupled boundaries.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const std::string patch
OpenFOAM patch number as a std::string.
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
messageStream Info
Information stream (stdout output on master, null elsewhere)
volScalarField & p
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:40
Namespace for OpenFOAM.
label timeIndex
Definition: getTimeIndex.H:24
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127
lumpedMassWallTemperatureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.