interRegionHeatTransferModel.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2020-2021 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
30#include "basicThermo.H"
31#include "fvmSup.H"
33#include "fvcVolumeIntegrate.H"
34#include "fvOptionList.H"
35
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37
38namespace Foam
39{
40namespace fv
41{
43}
44}
45
46
47// * * * * * * * * * * * * Protected member functions * * * * * * * * * * * //
48
50{
51 if (!firstIter_)
52 {
53 return;
54 }
55
56 const auto& nbrMesh = mesh_.time().lookupObject<fvMesh>(nbrRegionName_);
57
58 const auto& fvOptions = nbrMesh.lookupObject<optionList>("fvOptions");
59
60 bool nbrModelFound = false;
61
63 {
64 if (fvOptions[i].name() == nbrModelName_)
65 {
67 (
68 refCast<const interRegionHeatTransferModel>(fvOptions[i])
69 );
70 nbrModelFound = true;
71 break;
72 }
73 }
74
75 if (!nbrModelFound)
76 {
78 << "Neighbour model not found" << nbrModelName_
79 << " in region " << nbrMesh.name() << nl
80 << exit(FatalError);
81 }
82
83 firstIter_ = false;
84
85 // Set nbr model's nbr model to avoid construction order problems
87}
88
89
91{
92 if (master_)
93 {
94 if (mesh_.time().timeIndex() != timeIndex_)
95 {
96 calculateHtc();
97 timeIndex_ = mesh_.time().timeIndex();
98 }
99 }
100 else
101 {
102 nbrModel().correct();
103 interpolate(nbrModel().htc(), htc_);
104 }
105}
106
107
108// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
109
111(
112 const word& name,
113 const word& modelType,
114 const dictionary& dict,
115 const fvMesh& mesh
116)
117:
119 (
120 name,
121 modelType,
122 dict,
123 mesh
124 ),
125 nbrModelName_(coeffs_.get<word>("nbrModel")),
126 nbrModel_(nullptr),
127 firstIter_(true),
128 semiImplicit_(false),
129 timeIndex_(-1),
130 htc_
131 (
133 (
134 type() + ":htc",
135 mesh.time().timeName(),
136 mesh,
137 IOobject::NO_READ,
138 IOobject::NO_WRITE
139 ),
140 mesh,
142 zeroGradientFvPatchScalarField::typeName
143 ),
144 TName_(coeffs_.getOrDefault<word>("T", "T")),
145 TNbrName_(coeffs_.getOrDefault<word>("TNbr", "T"))
146{
147 if (active())
148 {
149 coeffs_.readEntry("fields", fieldNames_);
150 coeffs_.readEntry("semiImplicit", semiImplicit_);
152 }
153}
154
155
156// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
157
159(
160 fvMatrix<scalar>& eqn,
161 const label fieldi
162)
163{
164 setNbrModel();
165
166 correct();
167
168 const volScalarField& he = eqn.psi();
169
170 const auto& T = mesh_.lookupObject<volScalarField>(TName_);
171
172 auto tTmapped = tmp<volScalarField>::New
173 (
175 (
176 type() + ":Tmapped",
177 mesh_.time().timeName(),
178 mesh_,
181 ),
182 T
183 );
184
185 auto& Tmapped = tTmapped.ref();
186
187 const auto& nbrMesh = mesh_.time().lookupObject<fvMesh>(nbrRegionName_);
188
189 const auto& Tnbr = nbrMesh.lookupObject<volScalarField>(TNbrName_);
190
191 interpolate(Tnbr, Tmapped.primitiveFieldRef());
192
193 if (debug)
194 {
195 Info<< "Volumetric integral of htc: "
196 << fvc::domainIntegrate(htc_).value()
197 << endl;
198
199 if (mesh_.time().writeTime())
200 {
201 Tmapped.write();
202 htc_.write();
203 }
204 }
205
206 if (semiImplicit_)
207 {
208 if (he.dimensions() == dimEnergy/dimMass)
209 {
210 const auto* thermoPtr =
211 mesh_.findObject<basicThermo>(basicThermo::dictName);
212
213 if (thermoPtr)
214 {
215 const basicThermo& thermo = *thermoPtr;
216
217 volScalarField htcByCpv(htc_/thermo.Cpv());
218
219 eqn += htc_*(Tmapped - T) + htcByCpv*he - fvm::Sp(htcByCpv, he);
220
221 if (debug)
222 {
223 const dimensionedScalar energy =
224 fvc::domainIntegrate(htc_*(he/thermo.Cp() - Tmapped));
225
226 Info<< "Energy exchange from region " << nbrMesh.name()
227 << " To " << mesh_.name() << " : " << energy.value()
228 << endl;
229 }
230 }
231 else
232 {
234 << " on mesh " << mesh_.name()
235 << " could not find object basicThermo."
236 << " The available objects are: "
237 << mesh_.names()
238 << exit(FatalError);
239 }
240 }
241 else if (he.dimensions() == dimTemperature)
242 {
243 eqn += htc_*Tmapped - fvm::Sp(htc_, he);
244 }
245 }
246 else
247 {
248 eqn += htc_*(Tmapped - T);
249 }
250}
251
252
254(
255 const volScalarField& rho,
256 fvMatrix<scalar>& eqn,
257 const label fieldi
258)
259{
260 addSup(eqn, fieldi);
261}
262
263
265{
267 {
268 return true;
269 }
270
271 return false;
272}
273
274
275// ************************************************************************* //
volScalarField & he
Definition: YEEqn.H:52
fv::options & fvOptions
Internal & ref(const bool updateAccessTime=true)
Return a reference to the dimensioned internal field.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const Time & time() const
Return Time associated with the objectRegistry.
Definition: IOobject.C:506
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
virtual bool read()
Re-read model coefficients if they have changed.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:66
static const word dictName
Definition: basicThermo.H:256
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
const Type & value() const
Return const reference to value.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:121
const GeometricField< Type, fvPatchField, volMesh > & psi(const label i=0) const
Return psi.
Definition: fvMatrix.H:412
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
Intermediate class for handling inter-region heat exchanges.
void correct()
Correct to calculate the inter-region heat transfer coefficient.
void setNbrModel()
Set the neighbour interRegionHeatTransferModel.
virtual void addSup(fvMatrix< scalar > &eqn, const label fieldi)
Source term to energy equation.
word nbrModelName_
Name of the model in the neighbour mesh.
interRegionHeatTransferModel * nbrModel_
Pointer to neighbour interRegionHeatTransferModel.
bool semiImplicit_
Flag to activate semi-implicit coupling.
bool firstIter_
Flag to determine the first iteration.
Intermediate class for handling inter-region exchanges.
word nbrRegionName_
Name of the neighbour region to map.
List of finite volume options.
Definition: fvOptionList.H:72
const word & name() const noexcept
Return const access to the source name.
Definition: fvOptionI.H:31
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:139
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: fvOption.H:148
bool active() const noexcept
True if source is active.
Definition: fvOptionI.H:49
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:145
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: fvOption.C:48
const Type & lookupObject(const word &name, const bool recursive=false) const
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
thermo correct()
const volScalarField & T
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Volume integrate volField creating a volField.
Calculate the finiteVolume matrix for implicit and explicit sources.
word timeName
Definition: getTimeIndex.H:3
dimensioned< Type > domainIntegrate(const GeometricField< Type, fvPatchField, volMesh > &vf)
zeroField Sp(const Foam::zero, const GeometricField< Type, fvPatchField, volMesh > &)
A no-op source.
Namespace for OpenFOAM.
const dimensionSet dimEnergy
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:53
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
const dimensionSet dimTemperature(0, 0, 0, 1, 0, 0, 0)
Definition: dimensionSets.H:54
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
error FatalError
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:60
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:51
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
labelList fv(nPoints)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333