atmTurbulentHeatFluxTemperatureFvPatchScalarField.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) 2020 ENERCON GmbH
9  Copyright (C) 2020-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 
31 #include "fvPatchFieldMapper.H"
32 #include "volFields.H"
33 #include "turbulenceModel.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 const Foam::Enum
38 <
39  Foam::atmTurbulentHeatFluxTemperatureFvPatchScalarField::heatSourceType
40 >
41 Foam::atmTurbulentHeatFluxTemperatureFvPatchScalarField::heatSourceTypeNames
42 ({
43  { heatSourceType::POWER , "power" },
44  { heatSourceType::FLUX , "flux" }
45 });
46 
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
57 (
58  const fvPatch& p,
60 )
61 :
62  fixedGradientFvPatchScalarField(p, iF),
63  heatSource_(heatSourceType::POWER),
64  alphaEffName_("undefinedAlphaEff"),
65  Cp0_(nullptr),
66  q_(nullptr)
67 {}
68 
69 
72 (
74  const fvPatch& p,
76  const fvPatchFieldMapper& mapper
77 )
78 :
79  fixedGradientFvPatchScalarField(ptf, p, iF, mapper),
80  heatSource_(ptf.heatSource_),
81  alphaEffName_(ptf.alphaEffName_),
82  Cp0_(ptf.Cp0_.clone()),
83  q_(ptf.q_.clone(p.patch()))
84 {}
85 
86 
89 (
90  const fvPatch& p,
92  const dictionary& dict
93 )
94 :
95  fixedGradientFvPatchScalarField(p, iF), // Bypass dictionary constructor
96  heatSource_
97  (
98  heatSourceTypeNames.getOrDefault
99  (
100  "heatSource",
101  dict,
102  heatSourceType::POWER
103  )
104  ),
105  alphaEffName_(dict.get<word>("alphaEff")),
106  Cp0_(Function1<scalar>::New("Cp0", dict, &db())),
107  q_(PatchFunction1<scalar>::New(p.patch(), "q", dict))
108 {
109  if (!this->readGradientEntry(dict) || !this->readValueEntry(dict))
110  {
111  extrapolateInternal();
112  gradient() = Zero;
113  }
114 }
115 
116 
119 (
120  const atmTurbulentHeatFluxTemperatureFvPatchScalarField& atmpsf
121 )
122 :
123  fixedGradientFvPatchScalarField(atmpsf),
124  heatSource_(atmpsf.heatSource_),
125  alphaEffName_(atmpsf.alphaEffName_),
126  Cp0_(atmpsf.Cp0_.clone()),
127  q_(atmpsf.q_.clone(this->patch().patch()))
128 {}
129 
130 
133 (
136 )
137 :
138  fixedGradientFvPatchScalarField(atmpsf, iF),
139  heatSource_(atmpsf.heatSource_),
140  alphaEffName_(atmpsf.alphaEffName_),
141  Cp0_(atmpsf.Cp0_.clone()),
142  q_(atmpsf.q_.clone(this->patch().patch()))
143 {}
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
149 (
150  const fvPatchFieldMapper& m
151 )
152 {
154  q_->autoMap(m);
155 }
156 
157 
159 (
160  const fvPatchScalarField& ptf,
161  const labelList& addr
162 )
163 {
164  fixedGradientFvPatchScalarField::rmap(ptf, addr);
165 
167  refCast<const atmTurbulentHeatFluxTemperatureFvPatchScalarField>(ptf);
168 
169  q_->rmap(atmptf.q_(), addr);
170 }
171 
172 
174 {
175  if (updated())
176  {
177  return;
178  }
179 
180  const scalarField& alphaEffp =
181  patch().lookupPatchField<volScalarField>(alphaEffName_);
182 
183  const scalar t = db().time().timeOutputValue();
184  const scalar Cp0 = Cp0_->value(t);
185 
186  if (Cp0 < SMALL)
187  {
189  << "Cp0 = " << Cp0 << " must be positive."
190  << exit(FatalError);
191  }
192 
193  const scalarField q(q_->value(t));
194 
195  switch (heatSource_)
196  {
197  case heatSourceType::POWER:
198  {
199  const scalar Ap = gSum(patch().magSf());
200  gradient() = q/(Ap*Cp0*alphaEffp + SMALL);
201  break;
202  }
203 
204  case heatSourceType::FLUX:
205  {
206  gradient() = q/(Cp0*alphaEffp + SMALL);
207  break;
208  }
209 
210  default:
211  {
213  << "Unknown heat source type. Valid types are: "
214  << heatSourceTypeNames << nl
215  << exit(FatalError);
216  }
217  }
218 
219  fixedGradientFvPatchScalarField::updateCoeffs();
220 }
221 
222 
224 {
226  os.writeEntry("heatSource", heatSourceTypeNames[heatSource_]);
227  os.writeEntry("alphaEff", alphaEffName_);
228  Cp0_->writeData(os);
229  q_->writeData(os);
231 }
232 
233 
234 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 
237 (
239  atmTurbulentHeatFluxTemperatureFvPatchScalarField
240 );
241 
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 } // End namespace Foam
246 
247 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
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:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
Definition: fvPatchField.H:375
Macros for easy insertion into run-time selection tables.
This boundary condition provides a fixed heat constraint on temperature (i.e. T) to specify temperatu...
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:81
virtual void write(Ostream &) const
Write.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Type gSum(const FieldField< Field, Type > &f)
fvPatchField< scalar > fvPatchScalarField
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
A FieldMapper for finite-volume patch fields.
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition: IOobject.C:456
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
OBJstream os(runTime.globalPath()/outputName)
virtual void rmap(const fvPatchScalarField &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Map from self.
Definition: Field.C:466
scalar timeOutputValue() const
Return the current user-time value. (ie, after applying any timeToUserTime() conversion) ...
Definition: TimeStateI.H:24
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
atmTurbulentHeatFluxTemperatureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
const std::string patch
OpenFOAM patch number as a std::string.
volScalarField & p
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127