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-------------------------------------------------------------------------------
11License
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
37const Foam::Enum
38<
39 Foam::atmTurbulentHeatFluxTemperatureFvPatchScalarField::heatSourceType
40>
41Foam::atmTurbulentHeatFluxTemperatureFvPatchScalarField::heatSourceTypeNames
42({
43 { heatSourceType::POWER , "power" },
44 { heatSourceType::FLUX , "flux" }
45});
46
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50namespace Foam
51{
52
53// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54
55atmTurbulentHeatFluxTemperatureFvPatchScalarField::
56atmTurbulentHeatFluxTemperatureFvPatchScalarField
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
70atmTurbulentHeatFluxTemperatureFvPatchScalarField::
71atmTurbulentHeatFluxTemperatureFvPatchScalarField
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
87atmTurbulentHeatFluxTemperatureFvPatchScalarField::
88atmTurbulentHeatFluxTemperatureFvPatchScalarField
89(
90 const fvPatch& p,
92 const dictionary& dict
93)
94:
95 fixedGradientFvPatchScalarField(p, iF),
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 (dict.found("value") && dict.found("gradient"))
110 {
112 (
113 Field<scalar>("value", dict, p.size())
114 );
115 gradient() = Field<scalar>("gradient", dict, p.size());
116 }
117 else
118 {
119 fvPatchField<scalar>::operator=(patchInternalField());
120 gradient() = 0.0;
121 }
122}
123
124
125atmTurbulentHeatFluxTemperatureFvPatchScalarField::
126atmTurbulentHeatFluxTemperatureFvPatchScalarField
127(
129)
130:
131 fixedGradientFvPatchScalarField(atmpsf),
132 heatSource_(atmpsf.heatSource_),
133 alphaEffName_(atmpsf.alphaEffName_),
134 Cp0_(atmpsf.Cp0_.clone()),
135 q_(atmpsf.q_.clone(this->patch().patch()))
136{}
137
138
139atmTurbulentHeatFluxTemperatureFvPatchScalarField::
140atmTurbulentHeatFluxTemperatureFvPatchScalarField
141(
144)
145:
146 fixedGradientFvPatchScalarField(atmpsf, iF),
147 heatSource_(atmpsf.heatSource_),
148 alphaEffName_(atmpsf.alphaEffName_),
149 Cp0_(atmpsf.Cp0_.clone()),
150 q_(atmpsf.q_.clone(this->patch().patch()))
151{}
152
153
154// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
155
157(
158 const fvPatchFieldMapper& m
159)
160{
162 q_->autoMap(m);
163}
164
165
167(
168 const fvPatchScalarField& ptf,
169 const labelList& addr
170)
171{
172 fixedGradientFvPatchScalarField::rmap(ptf, addr);
173
175 refCast<const atmTurbulentHeatFluxTemperatureFvPatchScalarField>(ptf);
176
177 q_->rmap(atmptf.q_(), addr);
178}
179
180
182{
183 if (updated())
184 {
185 return;
186 }
187
188 const scalarField& alphaEffp =
189 patch().lookupPatchField<volScalarField, scalar>(alphaEffName_);
190
191 const scalar t = db().time().timeOutputValue();
192 const scalar Cp0 = Cp0_->value(t);
193
194 if (Cp0 < SMALL)
195 {
197 << "Cp0 = " << Cp0 << " must be positive."
198 << exit(FatalError);
199 }
200
201 const scalarField q(q_->value(t));
202
203 switch (heatSource_)
204 {
205 case heatSourceType::POWER:
206 {
207 const scalar Ap = gSum(patch().magSf());
208 gradient() = q/(Ap*Cp0*alphaEffp + SMALL);
209 break;
210 }
211
212 case heatSourceType::FLUX:
213 {
214 gradient() = q/(Cp0*alphaEffp + SMALL);
215 break;
216 }
217
218 default:
219 {
221 << "Unknown heat source type. Valid types are: "
222 << heatSourceTypeNames << nl
223 << exit(FatalError);
224 }
225 }
226
227 fixedGradientFvPatchScalarField::updateCoeffs();
228}
229
230
232{
233 fixedGradientFvPatchScalarField::write(os);
234 os.writeEntry("heatSource", heatSourceTypeNames[heatSource_]);
235 os.writeEntry("alphaEff", alphaEffName_);
236 Cp0_->writeData(os);
237 q_->writeData(os);
238 writeEntry("value", os);
239}
240
241
242// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243
245(
248);
249
250
251// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252
253} // End namespace Foam
254
255// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
Generic templated field type.
Definition: Field.H:82
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Map from self.
Definition: Field.C:403
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:96
const Time & time() const
Return Time associated with the objectRegistry.
Definition: IOobject.C:506
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:239
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
scalar timeOutputValue() const
Return current time value.
Definition: TimeStateI.H:31
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
This boundary condition provides a fixed heat constraint on temperature (i.e. T) to specify temperatu...
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
virtual void rmap(const fvPatchScalarField &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
virtual bool write()
Write the output fields.
A FieldMapper for finite-volume patch fields.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:82
virtual void operator=(const UList< Type > &)
Definition: fvPatchField.C:408
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
#define makePatchTypeField(PatchTypeField, typePatchTypeField)
Definition: fvPatchField.H:676
Namespace for OpenFOAM.
Type gSum(const FieldField< Field, Type > &f)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:82
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict