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-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 
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),
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 
127 (
129 )
130 :
131  fixedGradientFvPatchScalarField(atmpsf),
132  heatSource_(atmpsf.heatSource_),
133  alphaEffName_(atmpsf.alphaEffName_),
134  Cp0_(atmpsf.Cp0_),
135  q_(atmpsf.q_.clone(this->patch().patch()))
136 {}
137 
138 
141 (
144 )
145 :
146  fixedGradientFvPatchScalarField(atmpsf, iF),
147  heatSource_(atmpsf.heatSource_),
148  alphaEffName_(atmpsf.alphaEffName_),
149  Cp0_(atmpsf.Cp0_),
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 {
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 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
volFields.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::atmTurbulentHeatFluxTemperatureFvPatchScalarField::atmTurbulentHeatFluxTemperatureFvPatchScalarField
atmTurbulentHeatFluxTemperatureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
Definition: atmTurbulentHeatFluxTemperatureFvPatchScalarField.C:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Field< scalar >::autoMap
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Map from self.
Definition: Field.C:403
Foam::dictionary::found
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
Foam::atmTurbulentHeatFluxTemperatureFvPatchScalarField::autoMap
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: atmTurbulentHeatFluxTemperatureFvPatchScalarField.C:157
fvPatchFieldMapper.H
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
atmTurbulentHeatFluxTemperatureFvPatchScalarField.H
Foam::Field< scalar >
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
dict
dictionary dict
Definition: searchingEngine.H:14
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
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::PatchFunction1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: PatchFunction1.H:60
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::atmTurbulentHeatFluxTemperatureFvPatchScalarField
This boundary condition provides a fixed heat constraint on temperature (i.e. T) to specify temperatu...
Definition: atmTurbulentHeatFluxTemperatureFvPatchScalarField.H:143
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::atmTurbulentHeatFluxTemperatureFvPatchScalarField::write
virtual void write(Ostream &) const
Write.
Definition: atmTurbulentHeatFluxTemperatureFvPatchScalarField.C:231
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< label >
Foam::atmTurbulentHeatFluxTemperatureFvPatchScalarField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: atmTurbulentHeatFluxTemperatureFvPatchScalarField.C:181
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::makePatchTypeField
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
Foam::fvPatchField::operator=
virtual void operator=(const UList< Type > &)
Definition: fvPatchField.C:404
turbulenceModel.H
Foam::atmTurbulentHeatFluxTemperatureFvPatchScalarField::rmap
virtual void rmap(const fvPatchScalarField &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
Definition: atmTurbulentHeatFluxTemperatureFvPatchScalarField.C:167
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54