gradientEnergyFvPatchScalarField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
30 #include "fieldMapper.H"
31 #include "volFields.H"
32 #include "basicThermo.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
37 (
38  const fvPatch& p,
40 )
41 :
42  fixedGradientFvPatchScalarField(p, iF)
43 {
44  gradient() = scalar(0);
45 }
46 
47 
49 (
50  const fvPatch& p,
52  const dictionary& dict
53 )
54 :
55  fixedGradientFvPatchScalarField(p, iF, dict)
56 {}
57 
58 
60 (
62  const fvPatch& p,
64  const fieldMapper& mapper
65 )
66 :
67  fixedGradientFvPatchScalarField(ptf, p, iF, mapper, false)
68 {
69  map(ptf, mapper);
70 }
71 
72 
74 (
77 )
78 :
79  fixedGradientFvPatchScalarField(tppsf, iF)
80 {}
81 
82 
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
84 
86 (
88  const fieldMapper& mapper
89 )
90 {
91  // Unmapped faces are considered zero-gradient/adiabatic
92  // until they are corrected later
93  mapper(*this, ptf, [&](){ return this->patchInternalField(); });
94  mapper(gradient(), ptf.gradient(), scalar(0));
95 }
96 
97 
99 (
100  const fvPatchScalarField& ptf,
101  const fieldMapper& mapper
102 )
103 {
104  map(refCast<const gradientEnergyFvPatchScalarField>(ptf), mapper);
105 }
106 
107 
109 {
110  if (updated())
111  {
112  return;
113  }
114 
116  const label patchi = patch().index();
117 
118  fvPatchScalarField& Tp =
119  const_cast<fvPatchScalarField&>(thermo.T().boundaryField()[patchi]);
120 
121  Tp.evaluate();
122 
123  if
124  (
125  isA<zeroGradientFvPatchScalarField>(Tp)
126  || isA<fixedGradientFvPatchScalarField>(Tp)
127  )
128  {
129  gradient() =
130  thermo.Cpv(Tp, patchi)*Tp.snGrad()
131  + patch().deltaCoeffs()*
132  (
133  thermo.he(Tp, patchi)
134  - thermo.he(Tp, patch().faceCells())
135  );
136  }
137  else if (isA<gradientEnergyCalculatedTemperatureFvPatchScalarField>(Tp))
138  {
140  refCast<gradientEnergyCalculatedTemperatureFvPatchScalarField>(Tp);
141 
142  gradient() = Tg.heGradient();
143  }
144  else
145  {
147  << "Temperature boundary condition not recognised."
148  << "A " << typeName << " condition for energy must be used with a "
149  << zeroGradientFvPatchScalarField::typeName << ", "
150  << fixedGradientFvPatchScalarField::typeName << " or "
151  << gradientEnergyCalculatedTemperatureFvPatchScalarField::typeName
152  << " condition for temperature."
153  << exit(FatalError);
154  }
155 
156  fixedGradientFvPatchScalarField::updateCoeffs();
157 }
158 
159 
161 {
163  writeEntry(os, "value", *this);
164 }
165 
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 namespace Foam
170 {
172  (
175  );
176 }
177 
178 // ************************************************************************* //
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...
const Boundary & boundaryField() const
Return const-reference to the boundary field.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:78
static const basicThermo & lookupThermo(const FieldType &f)
Lookup the thermo associated with the given field.
virtual const volScalarField & T() const =0
Temperature [K].
virtual const volScalarField & Cpv() const =0
Heat capacity at constant pressure/volume [J/kg/K].
virtual const volScalarField & he() const =0
Enthalpy/Internal energy [J/kg].
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:91
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:217
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:170
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
Base class for temperature boundary conditions in which the parameters of the gradient energy conditi...
This boundary condition provides a gradient condition for energy. This is selected when the correspon...
void map(const gradientEnergyFvPatchScalarField &, const fieldMapper &)
Map the given fvPatchField onto this fvPatchField.
gradientEnergyFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
makeNullConstructablePatchTypeField(fvPatchVectorField, noSlipFvPatchVectorField)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
error FatalError
dictionary dict
volScalarField & p
fluidMulticomponentThermo & thermo
Definition: createFields.H:31