fvModels: interRegionHeatTransfer: Rationalisation

There is now just one inter-region heat transfer model, and heat
transfer coefficient models are selected as sub-models. This has been
done to permit usage of the heat transfer models in other contexts.

Example usage:

    interRegionHeatTransfer
    {
        type            interRegionHeatTransfer;

        interRegionHeatTransferCoeffs
        {
            nbrRegion       other;

            interpolationMethod cellVolumeWeight;
            master          true;

            semiImplicit    no;

            type            constant;

            AoV             200;
            htc             10;
        }
    }
This commit is contained in:
Will Bainbridge
2021-03-17 16:31:52 +00:00
parent de39bb45ca
commit 4442ce54a5
23 changed files with 1404 additions and 722 deletions

View File

@ -1,5 +1,3 @@
interRegionModel/interRegionModel.C
general/codedFvModel/codedFvModel.C
general/semiImplicitSource/semiImplicitSource.C
@ -30,10 +28,13 @@ derived/volumeFractionSource/volumeFractionSource.C
derived/solidEquilibriumEnergySource/solidEquilibriumEnergySource.C
derived/massSource/massSource.C
interRegion/interRegionHeatTransfer/interRegionHeatTransferModel/interRegionHeatTransferModel.C
interRegion/interRegionHeatTransfer/constantHeatTransfer/constantHeatTransfer.C
interRegion/interRegionHeatTransfer/function2HeatTransfer/function2HeatTransfer.C
interRegion/interRegionHeatTransfer/variableHeatTransfer/variableHeatTransfer.C
interRegion/interRegionModel/interRegionModel.C
interRegion/interRegionExplicitPorositySource/interRegionExplicitPorositySource.C
interRegion/interRegionHeatTransfer/interRegionHeatTransfer.C
interRegion/interRegionHeatTransfer/heatTransferModels/heatTransferModel/heatTransferModel.C
interRegion/interRegionHeatTransfer/heatTransferModels/constant/constant.C
interRegion/interRegionHeatTransfer/heatTransferModels/function1/function1.C
interRegion/interRegionHeatTransfer/heatTransferModels/function2/function2.C
interRegion/interRegionHeatTransfer/heatTransferModels/variable/variable.C
LIB = $(FOAM_LIBBIN)/libfvModels

View File

@ -0,0 +1,152 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "constant.H"
#include "zeroGradientFvPatchFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
namespace heatTransferModels
{
defineTypeNameAndDebug(constant, 0);
addToRunTimeSelectionTable(heatTransferModel, constant, mesh);
addToRunTimeSelectionTable(heatTransferModel, constant, model);
}
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fv::heatTransferModels::constant::readCoeffs()
{
IOobject htcIO
(
"htc",
mesh().time().constant(),
mesh(),
IOobject::MUST_READ,
IOobject::NO_WRITE
);
if (coeffs().found("htc"))
{
htc_ =
dimensionedScalar
(
"htc",
dimPower/dimTemperature/dimArea,
coeffs()
);
htcPtr_.clear();
}
else if (htcIO.typeHeaderOk<volScalarField>(false))
{
htc_ = dimensionedScalar("htc", dimPower/dimTemperature/dimArea, NaN);
htcPtr_.set(new volScalarField(htcIO, mesh()));
}
else
{
FatalIOErrorInFunction(coeffs())
<< "Heat transfer coefficient (htc) not found. A uniform htc "
<< "value should be specified, or a non-uniform field should "
<< "exist at " << htcIO.objectPath()
<< exit(FatalIOError);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::heatTransferModels::constant::constant
(
const dictionary& dict,
const fvMesh& mesh
)
:
heatTransferModel(typeName, dict, mesh),
htc_("htc", dimPower/dimTemperature/dimArea, NaN),
htcPtr_(nullptr)
{
readCoeffs();
}
Foam::fv::heatTransferModels::constant::constant
(
const dictionary& dict,
const interRegionModel& model
)
:
constant(dict, model.mesh())
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fv::heatTransferModels::constant::~constant()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::tmp<Foam::volScalarField>
Foam::fv::heatTransferModels::constant::htc() const
{
if (!htcPtr_.valid())
{
return volScalarField::New(type() + ":htc", mesh(), htc_);
}
else
{
return htcPtr_();
}
}
void Foam::fv::heatTransferModels::constant::correct()
{}
bool Foam::fv::heatTransferModels::constant::read(const dictionary& dict)
{
if (heatTransferModel::read(dict))
{
readCoeffs();
return true;
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -22,19 +22,31 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::fv::constantHeatTransfer
Foam::fv::heatTransferModels::constant
Description
Constant heat transfer model. A heat transfer coefficieqt [W/m^2/K] field
(htcConst) and area-per-unit-volume [1/m] field (AoV) must be provided in
Constant heat transfer model. The heat transfer coefficient [W/m^2/K] (htc)
must be provided as a value in the coefficients dictionary or as a field in
constant.
Usage
Example usage:
\verbatim
{
type constant;
AoV 1e3;
htc 1e5;
}
\endverbatim
\*---------------------------------------------------------------------------*/
#ifndef constantHeatTransfer_H
#define constantHeatTransfer_H
#ifndef constant_H
#define constant_H
#include "interRegionHeatTransferModel.H"
#include "heatTransferModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -42,45 +54,59 @@ namespace Foam
{
namespace fv
{
namespace heatTransferModels
{
/*---------------------------------------------------------------------------*\
Class constantHeatTransfer Declaration
Class constant Declaration
\*---------------------------------------------------------------------------*/
class constantHeatTransfer
class constant
:
public interRegionHeatTransferModel
public heatTransferModel
{
// Private Data
//- Heat transfer coefficient [W/m^2/K]
dimensionedScalar htc_;
//- Heat transfer coefficient [W/m^2/K]
autoPtr<volScalarField> htcPtr_;
// Private Member Functions
//- Correct the heat transfer coefficient
virtual void correctHtc() const;
//- Non-virtual read
void readCoeffs();
public:
//- Runtime type information
TypeName("constantHeatTransfer");
TypeName("constant");
// Constructors
//- Construct from dictionary
constantHeatTransfer
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
);
//- Construct from dictionary and mesh
constant(const dictionary& dict, const fvMesh& mesh);
//- Construct from dictionary and model
constant(const dictionary& dict, const interRegionModel& model);
//- Destructor
virtual ~constantHeatTransfer();
virtual ~constant();
// Member Functions
//- Get the heat transfer coefficient
virtual tmp<volScalarField> htc() const;
//- Correct the heat transfer coefficient
virtual void correct();
//- Read dictionary
virtual bool read(const dictionary& dict);
};
@ -88,6 +114,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace heatTransferModels
} // End namespace fv
} // End namespace Foam

View File

@ -23,7 +23,8 @@ License
\*---------------------------------------------------------------------------*/
#include "constantHeatTransfer.H"
#include "function1.H"
#include "zeroGradientFvPatchFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -32,80 +33,89 @@ namespace Foam
{
namespace fv
{
defineTypeNameAndDebug(constantHeatTransfer, 0);
addToRunTimeSelectionTable
(
fvModel,
constantHeatTransfer,
dictionary
);
namespace heatTransferModels
{
defineTypeNameAndDebug(function1, 0);
addToRunTimeSelectionTable(heatTransferModel, function1, mesh);
addToRunTimeSelectionTable(heatTransferModel, function1, model);
}
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fv::constantHeatTransfer::correctHtc() const
{}
void Foam::fv::heatTransferModels::function1::readCoeffs()
{
UName_ = coeffs().lookupOrDefault<word>("U", "U");
htcFunc_.reset(Function1<scalar>::New("htcFunc", coeffs()).ptr());
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::constantHeatTransfer::constantHeatTransfer
Foam::fv::heatTransferModels::function1::function1
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
)
:
interRegionHeatTransferModel(name, modelType, dict, mesh)
heatTransferModel(typeName, dict, mesh),
UName_(word::null),
htcFunc_(nullptr)
{
if (master())
{
const volScalarField htcConst
(
IOobject
(
"htcConst",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
const volScalarField AoV
(
IOobject
(
"AoV",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
htc_ = htcConst*AoV;
}
readCoeffs();
}
Foam::fv::heatTransferModels::function1::function1
(
const dictionary& dict,
const interRegionModel& model
)
:
function1(dict, model.mesh())
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fv::constantHeatTransfer::~constantHeatTransfer()
Foam::fv::heatTransferModels::function1::~function1()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fv::constantHeatTransfer::read(const dictionary& dict)
Foam::tmp<Foam::volScalarField>
Foam::fv::heatTransferModels::function1::htc() const
{
if (interRegionHeatTransferModel::read(dict))
const volVectorField& U = mesh().lookupObject<volVectorField>(UName_);
tmp<volScalarField> tHtc =
volScalarField::New
(
type() + ":htc",
mesh(),
dimPower/dimTemperature/dimArea,
zeroGradientFvPatchScalarField::typeName
);
tHtc->primitiveFieldRef() = htcFunc_->value(mag(U));
tHtc->correctBoundaryConditions();
return tHtc;
}
void Foam::fv::heatTransferModels::function1::correct()
{}
bool Foam::fv::heatTransferModels::function1::read(const dictionary& dict)
{
if (heatTransferModel::read(dict))
{
readCoeffs();
return true;
}
else

View File

@ -0,0 +1,129 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::fv::heatTransferModels::function1
Description
Function1 heat transfer model. The 1D function returns the heat transfer
coefficient as a function of the local velocity magnitude.
Usage
Example usage:
\verbatim
{
type function1;
AoV 1e3;
htcFunc
{
type constant;
value 1e5;
}
}
\endverbatim
\*---------------------------------------------------------------------------*/
#ifndef function1_H
#define function1_H
#include "heatTransferModel.H"
#include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
namespace heatTransferModels
{
/*---------------------------------------------------------------------------*\
Class function1 Declaration
\*---------------------------------------------------------------------------*/
class function1
:
public heatTransferModel
{
// Private Data
//- Name of velocity field; default = U
word UName_;
//- Heat transfer coefficient [W/m^2/K]
autoPtr<Function1<scalar>> htcFunc_;
// Private Member Functions
//- Non-virtual read
void readCoeffs();
public:
//- Runtime type information
TypeName("function1");
// Constructors
//- Construct from dictionary and mesh
function1(const dictionary& dict, const fvMesh& mesh);
//- Construct from dictionary and model
function1(const dictionary& dict, const interRegionModel& model);
//- Destructor
virtual ~function1();
// Member Functions
//- Get the heat transfer coefficient
virtual tmp<volScalarField> htc() const;
//- Correct the heat transfer coefficient
virtual void correct();
//- Read dictionary
virtual bool read(const dictionary& dict);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace heatTransferModels
} // End namespace fv
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -23,7 +23,8 @@ License
\*---------------------------------------------------------------------------*/
#include "function2HeatTransfer.H"
#include "function2.H"
#include "zeroGradientFvPatchFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -32,20 +33,18 @@ namespace Foam
{
namespace fv
{
defineTypeNameAndDebug(function2HeatTransfer, 0);
addToRunTimeSelectionTable
(
fvModel,
function2HeatTransfer,
dictionary
);
namespace heatTransferModels
{
defineTypeNameAndDebug(function2, 0);
addToRunTimeSelectionTable(heatTransferModel, function2, model);
}
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fv::function2HeatTransfer::readCoeffs()
void Foam::fv::heatTransferModels::function2::readCoeffs()
{
UName_ = coeffs().lookupOrDefault<word>("U", "U");
UNbrName_ = coeffs().lookupOrDefault<word>("UNbr", "U");
@ -54,51 +53,32 @@ void Foam::fv::function2HeatTransfer::readCoeffs()
}
void Foam::fv::function2HeatTransfer::correctHtc() const
{
const volVectorField& U = mesh().lookupObject<volVectorField>(UName_);
const fvMesh& nbrMesh = mesh().time().lookupObject<fvMesh>(nbrRegionName());
const volVectorField& UNbr =
nbrMesh.lookupObject<volVectorField>(UNbrName_);
const scalarField UMagNbr(mag(UNbr));
const scalarField UMagNbrMapped(interpolate(UMagNbr));
htc_.primitiveFieldRef() = htcFunc_->value(mag(U()), UMagNbrMapped)*AoV_();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::function2HeatTransfer::function2HeatTransfer
Foam::fv::heatTransferModels::function2::function2
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
const interRegionModel& model
)
:
interRegionHeatTransferModel(name, modelType, dict, mesh),
heatTransferModel(typeName, dict, model),
model_(model),
UName_(word::null),
UNbrName_(word::null),
htcFunc_(),
AoV_
(
master()
? new volScalarField
htc_
(
IOobject
(
"AoV",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
type() + ":htc",
model.mesh().time().timeName(),
model.mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh
)
: nullptr
model.mesh(),
dimensionedScalar(dimPower/dimTemperature/dimArea, 0),
zeroGradientFvPatchScalarField::typeName
)
{
readCoeffs();
@ -107,15 +87,32 @@ Foam::fv::function2HeatTransfer::function2HeatTransfer
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fv::function2HeatTransfer::~function2HeatTransfer()
Foam::fv::heatTransferModels::function2::~function2()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fv::function2HeatTransfer::read(const dictionary& dict)
void Foam::fv::heatTransferModels::function2::correct()
{
if (interRegionHeatTransferModel::read(dict))
const fvMesh& mesh = model_.mesh();
const fvMesh& nbrMesh = model_.nbrMesh();
const volVectorField& U = mesh.lookupObject<volVectorField>(UName_);
const volVectorField& UNbr =
nbrMesh.lookupObject<volVectorField>(UNbrName_);
const scalarField UMagNbr(mag(UNbr));
const scalarField UMagNbrMapped(model_.interpolate(UMagNbr));
htc_.primitiveFieldRef() = htcFunc_->value(mag(U()), UMagNbrMapped);
htc_.correctBoundaryConditions();
}
bool Foam::fv::heatTransferModels::function2::read(const dictionary& dict)
{
if (heatTransferModel::read(dict))
{
readCoeffs();
return true;

View File

@ -22,7 +22,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::fv::function2HeatTransfer
Foam::fv::heatTransferModels::function2
Description
Function2 heat transfer model. The 2D function returns the heat transfer
@ -30,12 +30,28 @@ Description
magnitudes. An area-per-unit-volume [1/m] field (AoV) must be provided in
constant.
Usage
Example usage:
\verbatim
{
type function2;
AoV 1e3;
htcFunc
{
type constant;
value 1e5;
}
}
\endverbatim
\*---------------------------------------------------------------------------*/
#ifndef function2HeatTransfer_H
#define function2HeatTransfer_H
#ifndef function2_H
#define function2_H
#include "interRegionHeatTransferModel.H"
#include "heatTransferModel.H"
#include "Function2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -44,17 +60,22 @@ namespace Foam
{
namespace fv
{
namespace heatTransferModels
{
/*---------------------------------------------------------------------------*\
Class function2HeatTransfer Declaration
Class function2 Declaration
\*---------------------------------------------------------------------------*/
class function2HeatTransfer
class function2
:
public interRegionHeatTransferModel
public heatTransferModel
{
// Private Data
//- Reference to the inter region model
const interRegionModel& model_;
//- Name of velocity field; default = U
word UName_;
@ -62,13 +83,10 @@ class function2HeatTransfer
word UNbrName_;
//- Heat transfer coefficient function ptr
mutable autoPtr<Function2<scalar>> htcFunc_;
autoPtr<Function2<scalar>> htcFunc_;
//- Area per unit volume of heat exchanger
mutable autoPtr<volScalarField> AoV_;
//- Start time name
const word startTimeName_;
//- Heat transfer coefficient [W/m^2/K]
volScalarField htc_;
// Private Member Functions
@ -76,34 +94,34 @@ class function2HeatTransfer
//- Non-virtual read
void readCoeffs();
//- Calculate the heat transfer coefficient
virtual void correctHtc() const;
public:
//- Runtime type information
TypeName("function2HeatTransfer");
TypeName("function2");
// Constructors
//- Construct from dictionary
function2HeatTransfer
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
);
//- Construct from dictionary and model
function2(const dictionary& dict, const interRegionModel& model);
//- Destructor
virtual ~function2HeatTransfer();
virtual ~function2();
// Member Functions
//- Get the heat transfer coefficient
virtual tmp<volScalarField> htc() const
{
return htc_;
}
//- Correct the heat transfer coefficient
virtual void correct();
//- Read dictionary
virtual bool read(const dictionary& dict);
};
@ -111,6 +129,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace heatTransferModels
} // End namespace fv
} // End namespace Foam

View File

@ -0,0 +1,191 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "heatTransferModel.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
defineTypeNameAndDebug(heatTransferModel, 0);
defineRunTimeSelectionTable(heatTransferModel, mesh);
defineRunTimeSelectionTable(heatTransferModel, model);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fv::heatTransferModel::readCoeffs()
{
IOobject AoVIO
(
"AoV",
mesh().time().constant(),
mesh(),
IOobject::MUST_READ,
IOobject::NO_WRITE
);
if (coeffs().found("AoV"))
{
AoV_ = dimensionedScalar("AoV", dimless/dimLength, coeffs());
AoVPtr_.clear();
}
else if (AoVIO.typeHeaderOk<volScalarField>(false))
{
AoV_ = dimensionedScalar("AoV", dimless/dimLength, NaN);
AoVPtr_.set(new volScalarField(AoVIO, mesh()));
}
else
{
FatalIOErrorInFunction(coeffs())
<< "Area per unit volume (AoV) not found. A uniform AoV "
<< "value should be specified, or a non-uniform field should "
<< "exist at " << AoVIO.objectPath()
<< exit(FatalIOError);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::heatTransferModel::heatTransferModel
(
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
)
:
mesh_(mesh),
coeffs_(dict.optionalSubDict(modelType + "Coeffs")),
AoV_("AoV", dimless/dimLength, NaN),
AoVPtr_(nullptr)
{
readCoeffs();
}
Foam::fv::heatTransferModel::heatTransferModel
(
const word& modelType,
const dictionary& dict,
const interRegionModel& model
)
:
heatTransferModel(modelType, dict, model.mesh())
{}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::fv::heatTransferModel>
Foam::fv::heatTransferModel::New(const dictionary& dict, const fvMesh& mesh)
{
word heatTransferModelType(dict.lookup("type"));
Info<< "Selecting heatTransferModel "
<< heatTransferModelType << endl;
meshConstructorTable::iterator cstrIter =
meshConstructorTablePtr_->find(heatTransferModelType);
if (cstrIter == meshConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown heatTransferModelType type "
<< heatTransferModelType << endl << endl
<< "Valid heatTransferModel types are : " << endl
<< meshConstructorTablePtr_->sortedToc()
<< exit(FatalError);
}
return cstrIter()(dict, mesh);
}
Foam::autoPtr<Foam::fv::heatTransferModel>
Foam::fv::heatTransferModel::New
(
const dictionary& dict,
const interRegionModel& model
)
{
word heatTransferModelType(dict.lookup("type"));
Info<< "Selecting heatTransferModel "
<< heatTransferModelType << endl;
modelConstructorTable::iterator cstrIter =
modelConstructorTablePtr_->find(heatTransferModelType);
if (cstrIter == modelConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown heatTransferModelType type "
<< heatTransferModelType << endl << endl
<< "Valid heatTransferModel types are : " << endl
<< modelConstructorTablePtr_->sortedToc()
<< exit(FatalError);
}
return cstrIter()(dict, model);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fv::heatTransferModel::~heatTransferModel()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::tmp<Foam::volScalarField> Foam::fv::heatTransferModel::AoV() const
{
if (!AoVPtr_.valid())
{
return volScalarField::New(type() + ":AoV", mesh_, AoV_);
}
else
{
return AoVPtr_();
}
}
bool Foam::fv::heatTransferModel::read(const dictionary& dict)
{
coeffs_ = dict.optionalSubDict(type() + "Coeffs");
readCoeffs();
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,191 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::fv::heatTransferModel
Description
Base class for heat transfer coefficient modelling used in heat transfer
fvModels. Area per unit volume [1/m] (AoV) must be provided as a value in
the coefficients dictionary or as a field in constant.
SourceFiles
heatTransferModel.C
\*---------------------------------------------------------------------------*/
#ifndef heatTransferModel_H
#define heatTransferModel_H
#include "volFields.H"
#include "interRegionModel.H"
#include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
/*---------------------------------------------------------------------------*\
Class heatTransferModel Declaration
\*---------------------------------------------------------------------------*/
class heatTransferModel
{
// Private Member Data
//- Reference to the mesh
const fvMesh& mesh_;
//- Dictionary containing source coefficients
dictionary coeffs_;
//- Area per unit volume [1/m]
dimensionedScalar AoV_;
//- Area per unit volume [1/m]
autoPtr<volScalarField> AoVPtr_;
// Private Member Functions
//- Non-virtual read
void readCoeffs();
public:
//- Runtime type information
TypeName("heatTransferModel");
// Declare runtime construction
declareRunTimeSelectionTable
(
autoPtr,
heatTransferModel,
mesh,
(
const dictionary& dict,
const fvMesh& mesh
),
(dict, mesh)
);
declareRunTimeSelectionTable
(
autoPtr,
heatTransferModel,
model,
(
const dictionary& dict,
const interRegionModel& model
),
(dict, model)
);
// Constructors
//- Construct from dictionary and mesh
heatTransferModel
(
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
);
//- Construct from dictionary and model
heatTransferModel
(
const word& modelType,
const dictionary& dict,
const interRegionModel& model
);
//- Disallow default bitwise copy construction
heatTransferModel(const heatTransferModel&) = delete;
// Selectors
//- Select from dictionary and mesh
static autoPtr<heatTransferModel> New
(
const dictionary& dict,
const fvMesh& mesh
);
//- Select from dictionary and model
static autoPtr<heatTransferModel> New
(
const dictionary& dict,
const interRegionModel& model
);
//- Destructor
virtual ~heatTransferModel();
// Member Functions
//- Return reference to the mesh
inline const fvMesh& mesh() const
{
return mesh_;
}
//- Return coeffs dictionary
inline const dictionary& coeffs() const
{
return coeffs_;
}
//- Get the area per unit volume
tmp<volScalarField> AoV() const;
//- Get the heat transfer coefficient
virtual tmp<volScalarField> htc() const = 0;
//- Correct the heat transfer coefficient
virtual void correct() = 0;
//- Read dictionary
virtual bool read(const dictionary& dict);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fv
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -23,8 +23,9 @@ License
\*---------------------------------------------------------------------------*/
#include "variableHeatTransfer.H"
#include "variable.H"
#include "thermophysicalTransportModel.H"
#include "zeroGradientFvPatchFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -33,111 +34,108 @@ namespace Foam
{
namespace fv
{
defineTypeNameAndDebug(variableHeatTransfer, 0);
addToRunTimeSelectionTable
(
fvModel,
variableHeatTransfer,
dictionary
);
namespace heatTransferModels
{
defineTypeNameAndDebug(variable, 0);
addToRunTimeSelectionTable(heatTransferModel, variable, mesh);
addToRunTimeSelectionTable(heatTransferModel, variable, model);
}
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fv::variableHeatTransfer::readCoeffs()
void Foam::fv::heatTransferModels::variable::readCoeffs()
{
UNbrName_ = coeffs().lookupOrDefault<word>("UNbr", "U");
UName_ = coeffs().lookupOrDefault<word>("U", "U");
a_ = coeffs().lookup<scalar>("a");
b_ = coeffs().lookup<scalar>("b");
c_ = coeffs().lookup<scalar>("c");
ds_ = coeffs().lookup<scalar>("ds");
Pr_ = coeffs().lookup<scalar>("Pr");
}
void Foam::fv::variableHeatTransfer::correctHtc() const
{
const fvMesh& nbrMesh =
mesh().time().lookupObject<fvMesh>(nbrRegionName());
const thermophysicalTransportModel& nbrTtm =
nbrMesh.lookupObject<thermophysicalTransportModel>
(
thermophysicalTransportModel::typeName
);
const compressibleMomentumTransportModel& nbrTurb =
nbrTtm.momentumTransport();
const fluidThermo& nbrThermo = nbrTtm.thermo();
const volVectorField& UNbr =
nbrMesh.lookupObject<volVectorField>(UNbrName_);
const volScalarField ReNbr(mag(UNbr)*ds_*nbrThermo.rho()/nbrTurb.mut());
const volScalarField NuNbr(a_*pow(ReNbr, b_)*pow(Pr_, c_));
const scalarField htcNbr(NuNbr*nbrTtm.kappaEff()/ds_);
const scalarField htcNbrMapped(interpolate(htcNbr));
htc_.primitiveFieldRef() = htcNbrMapped*AoV_;
L_ = dimensionedScalar("L", dimLength, coeffs());
Pr_ = dimensionedScalar("Pr", dimless, coeffs());
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::variableHeatTransfer::variableHeatTransfer
Foam::fv::heatTransferModels::variable::variable
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
)
:
interRegionHeatTransferModel(name, modelType, dict, mesh),
UNbrName_(word::null),
heatTransferModel(typeName, dict, mesh),
UName_(word::null),
a_(NaN),
b_(NaN),
c_(NaN),
ds_(NaN),
Pr_(NaN),
AoV_
(
master()
? new volScalarField
L_("L", dimLength, NaN),
Pr_("Pr", dimless, NaN),
htc_
(
IOobject
(
"AoV",
mesh.time().constant(),
type() + ":htc",
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh
)
: nullptr
mesh,
dimensionedScalar(dimPower/dimTemperature/dimArea, 0),
zeroGradientFvPatchScalarField::typeName
)
{
readCoeffs();
}
Foam::fv::heatTransferModels::variable::variable
(
const dictionary& dict,
const interRegionModel& model
)
:
variable(dict, model.mesh())
{
readCoeffs();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fv::variableHeatTransfer::~variableHeatTransfer()
Foam::fv::heatTransferModels::variable::~variable()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fv::variableHeatTransfer::read(const dictionary& dict)
void Foam::fv::heatTransferModels::variable::correct()
{
if (interRegionHeatTransferModel::read(dict))
const thermophysicalTransportModel& ttm =
mesh().lookupObject<thermophysicalTransportModel>
(
thermophysicalTransportModel::typeName
);
const compressibleMomentumTransportModel& mtm =
ttm.momentumTransport();
const volVectorField& U =
mesh().lookupObject<volVectorField>(UName_);
const volScalarField Re(mag(U)*L_/mtm.nuEff());
const volScalarField Nu(a_*pow(Re, b_)*pow(Pr_, c_));
htc_ = Nu*ttm.kappaEff()/L_;
htc_.correctBoundaryConditions();
}
bool Foam::fv::heatTransferModels::variable::read(const dictionary& dict)
{
if (heatTransferModel::read(dict))
{
readCoeffs();
return true;

View File

@ -22,11 +22,11 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::fv::variableHeatTransfer
Foam::fv::heatTransferModels::variable
Description
Variable heat transfer model depending on local values. The Nu number is
calculated as:
Variable heat transfer model depending on local values. The Nusselt number
is calculated as:
\f[
Nu = a*Re^b*Pr^c
@ -35,23 +35,38 @@ Description
And the heat transfer coefficient is calculated as:
\f[
htc = Nu*K/ds
htc = Nu*\kappa/L
\f]
where:
Where:
\vartable
K | Conductivity
ds | Strut diameter
\kappa | Conductivity
L | Length scale
\endvartable
An area-per-unit-volume [1/m] field (AoV) must be provided in constant.
Usage
Example usage:
\verbatim
{
type variable;
AoV 1e3;
a 1;
b 2;
c 3;
Pr 0.7;
L 1e-3;
}
\endverbatim
\*---------------------------------------------------------------------------*/
#ifndef variableHeatTransfer_H
#define variableHeatTransfer_H
#ifndef heatTransferModels_variable_H
#define heatTransferModels_variable_H
#include "interRegionHeatTransferModel.H"
#include "heatTransferModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -59,19 +74,21 @@ namespace Foam
{
namespace fv
{
namespace heatTransferModels
{
/*---------------------------------------------------------------------------*\
Class variableHeatTransfer Declaration
Class variable Declaration
\*---------------------------------------------------------------------------*/
class variableHeatTransfer
class variable
:
public interRegionHeatTransferModel
public heatTransferModel
{
// Private Data
//- Name of neighbour velocity field; default = U
word UNbrName_;
word UName_;
//- Model constant
scalar a_;
@ -82,14 +99,14 @@ class variableHeatTransfer
//- Model constant
scalar c_;
//- Strut diameter
scalar ds_;
//- Length scale
dimensionedScalar L_;
//- Fluid Prandtl number
scalar Pr_;
dimensionedScalar Pr_;
//- Area per unit volume of heat exchanger
autoPtr<volScalarField> AoV_;
//- Heat transfer coefficient [W/m^2/K]
volScalarField htc_;
// Private Member Functions
@ -97,34 +114,37 @@ class variableHeatTransfer
//- Non-virtual read
void readCoeffs();
//- Correct the heat transfer coefficient
virtual void correctHtc() const;
public:
//- Runtime type information
TypeName("variableHeatTransfer");
TypeName("variable");
// Constructors
//- Construct from dictionary
variableHeatTransfer
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
);
//- Construct from dictionary and mesh
variable(const dictionary& dict, const fvMesh& mesh);
//- Construct from dictionary and model
variable(const dictionary& dict, const interRegionModel& model);
//- Destructor
virtual ~variableHeatTransfer();
virtual ~variable();
// Member Functions
//- Get the heat transfer coefficient
virtual tmp<volScalarField> htc() const
{
return htc_;
}
//- Correct the heat transfer coefficient
virtual void correct();
//- Read dictionary
virtual bool read(const dictionary& dict);
};
@ -132,6 +152,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace heatTransferModels
} // End namespace fv
} // End namespace Foam

View File

@ -0,0 +1,229 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "interRegionHeatTransfer.H"
#include "basicThermo.H"
#include "fvmSup.H"
#include "zeroGradientFvPatchFields.H"
#include "fvcVolumeIntegrate.H"
#include "fvModels.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
defineTypeNameAndDebug(interRegionHeatTransfer, 0);
addToRunTimeSelectionTable
(
fvModel,
interRegionHeatTransfer,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fv::interRegionHeatTransfer::readCoeffs()
{
semiImplicit_ = coeffs().lookup<bool>("semiImplicit");
TName_ = coeffs().lookupOrDefault<word>("T", "T");
TNbrName_ = coeffs().lookupOrDefault<word>("TNbr", "T");
if (master())
{
heatTransferModel_ = heatTransferModel::New(coeffs(), *this);
}
}
const Foam::fv::heatTransferModel&
Foam::fv::interRegionHeatTransfer::nbrHeatTransferModel() const
{
return
refCast<const interRegionHeatTransfer>(nbrModel()).heatTransferModel_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::interRegionHeatTransfer::interRegionHeatTransfer
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
)
:
interRegionModel(name, modelType, dict, mesh),
semiImplicit_(false),
TName_(word::null),
TNbrName_(word::null),
heatTransferModel_(nullptr)
{
readCoeffs();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fv::interRegionHeatTransfer::~interRegionHeatTransfer()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::wordList Foam::fv::interRegionHeatTransfer::addSupFields() const
{
const basicThermo& thermo =
mesh().lookupObject<basicThermo>(basicThermo::dictName);
return wordList(1, thermo.he().name());
}
void Foam::fv::interRegionHeatTransfer::addSup
(
fvMatrix<scalar>& eqn,
const word& fieldName
) const
{
const volScalarField& he = eqn.psi();
const volScalarField& T =
mesh().lookupObject<volScalarField>(TName_);
const volScalarField& Tnbr =
nbrMesh().lookupObject<volScalarField>(TNbrName_);
tmp<volScalarField> tTnbrMapped =
volScalarField::New(TName_ + "nbrMapped", T);
interpolate(Tnbr, tTnbrMapped->primitiveFieldRef());
volScalarField& TnbrMapped = tTnbrMapped.ref();
// Get the heat transfer coefficient field
tmp<volScalarField> tHtcAoV;
if (master())
{
tmp<volScalarField> mask =
volScalarField::New
(
"mask",
mesh(),
dimensionedScalar(dimless, 0)
);
tmp<volScalarField> oneNbr =
volScalarField::New
(
"one",
nbrMesh(),
dimensionedScalar(dimless, 1)
);
interpolate(oneNbr(), mask.ref().primitiveFieldRef());
tHtcAoV =
mask
*heatTransferModel_->htc()
*heatTransferModel_->AoV();
}
else
{
tmp<volScalarField> tHtcNbr =
nbrHeatTransferModel().htc()
*nbrHeatTransferModel().AoV();
tHtcAoV =
volScalarField::New
(
tHtcNbr().name(),
mesh(),
dimensionedScalar(tHtcNbr().dimensions(), 0)
);
interpolate(tHtcNbr(), tHtcAoV.ref().primitiveFieldRef());
}
const volScalarField& htcAoV = tHtcAoV();
if (semiImplicit_)
{
if (he.dimensions() == dimEnergy/dimMass)
{
const basicThermo& thermo =
mesh().lookupObject<basicThermo>(basicThermo::dictName);
const volScalarField htcAoVByCpv(htcAoV/thermo.Cpv());
eqn +=
htcAoV*(TnbrMapped - T)
+ htcAoVByCpv*he - fvm::Sp(htcAoVByCpv, he);
}
else if (he.dimensions() == dimTemperature)
{
eqn += htcAoV*TnbrMapped - fvm::Sp(htcAoV, he);
}
}
else
{
eqn += htcAoV*(TnbrMapped - T);
}
}
void Foam::fv::interRegionHeatTransfer::addSup
(
const volScalarField& rho,
fvMatrix<scalar>& eqn,
const word& fieldName
) const
{
addSup(eqn, fieldName);
}
void Foam::fv::interRegionHeatTransfer::correct()
{
if (master())
{
heatTransferModel_->correct();
}
}
bool Foam::fv::interRegionHeatTransfer::read(const dictionary& dict)
{
if (interRegionModel::read(dict))
{
readCoeffs();
return true;
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -22,23 +22,60 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::fv::interRegionHeatTransferModel
Foam::fv::interRegionHeatTransfer
Description
Base class for inter region heat exchange. The derived classes must
provide the heat transfer coefficient (htc) which is used as follows
in the energy equation:
Model for inter-region heat exchange. Requires specification of a model for
the heat transfer coefficient (htc) and the area per unit volume (AoV).
These are then used to apply the following source to the energy equation:
\f[
-htc*T_{mapped} + Sp(htc, T)
-htc*AoV*(T_{nbr,mapped} - T)
\f]
If the semiImplicit option is set, then this becomes:
\f[
-htc*AoV*(T_{nbr,mapped} - T) + htc*AoV/Cp*h - Sp(htc*AoV/Cp, h);
\f]
Usage
Example usage:
\verbatim
interRegionHeatTransfer
{
type interRegionHeatTransfer;
interRegionHeatTransferCoeffs
{
nbrRegion other;
interpolationMethod cellVolumeWeight;
master true;
semiImplicit no;
type constant;
AoV 200;
htc 10;
}
}
\endverbatim
See also
fv::heatTransferModel
SourceFiles
interRegionHeatTransfer.C
\*---------------------------------------------------------------------------*/
#ifndef interRegionHeatTransferModel_H
#define interRegionHeatTransferModel_H
#ifndef interRegionHeatTransfer_H
#define interRegionHeatTransfer_H
#include "interRegionModel.H"
#include "volFields.H"
#include "heatTransferModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -48,21 +85,15 @@ namespace fv
{
/*---------------------------------------------------------------------------*\
Class interRegionHeatTransferModel Declaration
Class interRegionHeatTransfer Declaration
\*---------------------------------------------------------------------------*/
class interRegionHeatTransferModel
class interRegionHeatTransfer
:
public interRegionModel
{
// Private data
//- Name of the model in the neighbour mesh
word nbrModelName_;
//- Time index - used for updating htc
mutable label timeIndex_;
//- Flag to activate semi-implicit coupling
bool semiImplicit_;
@ -72,75 +103,34 @@ class interRegionHeatTransferModel
//- Name of neighbour temperature field; default = "T"
word TNbrName_;
//- The heat transfer model
autoPtr<heatTransferModel> heatTransferModel_;
// Private member functions
//- Non-virtual read
void readCoeffs();
//- Get the neighbour interRegionHeatTransferModel
interRegionHeatTransferModel& nbrModel() const;
//- Correct to calculate the inter-region heat transfer coefficient
void correct() const;
//- Correct heat transfer coefficient
virtual void correctHtc() const = 0;
protected:
// Protected data
// Protected member functions
//- Heat transfer coefficient [W/m^2/k] times area/volume [1/m]
mutable volScalarField htc_;
// Protected Member Functions
//- Interpolate field with nbrModel specified
template<class Type>
tmp<Field<Type>> interpolate
(
const interRegionHeatTransferModel& nbrModel,
const Field<Type>& field
) const;
//- Interpolate field without nbrModel specified
template<class Type>
tmp<Field<Type>> interpolate
(
const Field<Type>& field
) const;
//- Interpolate field with nbrModel specified
template<class Type>
void interpolate
(
const interRegionHeatTransferModel& nbrModel,
const Field<Type>& field,
Field<Type>& result
) const;
//- Interpolate field without nbrModel specified
template<class Type>
void interpolate
(
const Field<Type>& field,
Field<Type>& result
) const;
//- Get the neighbour heat transfer model
const heatTransferModel& nbrHeatTransferModel() const;
public:
//- Runtime type information
TypeName("interRegionHeatTransferModel");
TypeName("interRegionHeatTransfer");
// Constructors
//- Construct from dictionary
interRegionHeatTransferModel
interRegionHeatTransfer
(
const word& name,
const word& modelType,
@ -150,7 +140,7 @@ public:
//- Destructor
virtual ~interRegionHeatTransferModel();
virtual ~interRegionHeatTransfer();
// Member Functions
@ -188,8 +178,8 @@ public:
// Correction
//- Inherit base class correct method to avoid clang warning
using interRegionModel::correct;
//- Correct the model
virtual void correct();
// IO
@ -206,16 +196,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "interRegionHeatTransferModelI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "interRegionHeatTransferModelTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,267 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "interRegionHeatTransferModel.H"
#include "basicThermo.H"
#include "fvmSup.H"
#include "zeroGradientFvPatchFields.H"
#include "fvcVolumeIntegrate.H"
#include "fvModels.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
defineTypeNameAndDebug(interRegionHeatTransferModel, 0);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fv::interRegionHeatTransferModel::readCoeffs()
{
nbrModelName_ = coeffs().lookup<word>("nbrModel");
semiImplicit_ = coeffs().lookup<bool>("semiImplicit");
TName_ = coeffs().lookupOrDefault<word>("T", "T");
TNbrName_ = coeffs().lookupOrDefault<word>("TNbr", "T");
}
Foam::fv::interRegionHeatTransferModel&
Foam::fv::interRegionHeatTransferModel::nbrModel() const
{
const fvMesh& nbrMesh = mesh().time().lookupObject<fvMesh>(nbrRegionName());
const PtrListDictionary<fvModel>& fvModels =
nbrMesh.lookupObject<Foam::fvModels>("fvModels");
if (fvModels.found(nbrModelName_))
{
return const_cast<interRegionHeatTransferModel&>
(
refCast<const interRegionHeatTransferModel>
(
fvModels[nbrModelName_]
)
);
}
else
{
FatalErrorInFunction
<< "Neighbour model not found" << nbrModelName_
<< " in region " << nbrMesh.name() << nl
<< exit(FatalError);
return const_cast<interRegionHeatTransferModel&>
(
NullObjectRef<interRegionHeatTransferModel>()
);
}
}
void Foam::fv::interRegionHeatTransferModel::correct() const
{
if (master())
{
if (mesh().time().timeIndex() != timeIndex_)
{
correctHtc();
timeIndex_ = mesh().time().timeIndex();
}
}
else
{
nbrModel().correctHtc();
interpolate(nbrModel().htc(), htc_);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::interRegionHeatTransferModel::interRegionHeatTransferModel
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
)
:
interRegionModel
(
name,
modelType,
dict,
mesh
),
nbrModelName_(word::null),
timeIndex_(-1),
semiImplicit_(false),
TName_(word::null),
TNbrName_(word::null),
htc_
(
IOobject
(
type() + ":htc",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar
(
dimEnergy/dimTime/dimTemperature/dimVolume,
0
),
zeroGradientFvPatchScalarField::typeName
)
{
readCoeffs();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fv::interRegionHeatTransferModel::~interRegionHeatTransferModel()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::wordList Foam::fv::interRegionHeatTransferModel::addSupFields() const
{
const basicThermo& thermo =
mesh().lookupObject<basicThermo>(basicThermo::dictName);
return wordList(1, thermo.he().name());
}
void Foam::fv::interRegionHeatTransferModel::addSup
(
fvMatrix<scalar>& eqn,
const word& fieldName
) const
{
correct();
const volScalarField& he = eqn.psi();
const volScalarField& T = mesh().lookupObject<volScalarField>(TName_);
tmp<volScalarField> tTmapped
(
volScalarField::New(type() + ":Tmapped", T)
);
volScalarField& Tmapped = tTmapped.ref();
const fvMesh& nbrMesh = mesh().time().lookupObject<fvMesh>(nbrRegionName());
const volScalarField& Tnbr =
nbrMesh.lookupObject<volScalarField>(TNbrName_);
interpolate(Tnbr, Tmapped.primitiveFieldRef());
if (debug)
{
Info<< "Volumetric integral of htc: "
<< fvc::domainIntegrate(htc_).value()
<< endl;
if (mesh().time().writeTime())
{
Tmapped.write();
htc_.write();
}
}
if (semiImplicit_)
{
if (he.dimensions() == dimEnergy/dimMass)
{
const basicThermo& thermo =
mesh().lookupObject<basicThermo>(basicThermo::dictName);
const volScalarField htcByCpv(htc_/thermo.Cpv());
eqn += htc_*(Tmapped - T) + htcByCpv*he - fvm::Sp(htcByCpv, he);
if (debug)
{
const dimensionedScalar energy =
fvc::domainIntegrate(htc_*(Tmapped - T));
Info<< "Energy exchange from region " << nbrMesh.name()
<< " To " << mesh().name() << " : " << energy.value()
<< endl;
}
}
else if (he.dimensions() == dimTemperature)
{
eqn += htc_*Tmapped - fvm::Sp(htc_, he);
}
}
else
{
eqn += htc_*(Tmapped - T);
}
}
void Foam::fv::interRegionHeatTransferModel::addSup
(
const volScalarField& rho,
fvMatrix<scalar>& eqn,
const word& fieldName
) const
{
addSup(eqn, fieldName);
}
bool Foam::fv::interRegionHeatTransferModel::read(const dictionary& dict)
{
if (interRegionModel::read(dict))
{
readCoeffs();
return true;
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -1,35 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline const Foam::volScalarField&
Foam::fv::interRegionHeatTransferModel::htc() const
{
return htc_;
}
// ************************************************************************* //

View File

@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "interRegionModel.H"
#include "fvModels.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -42,7 +43,12 @@ void Foam::fv::interRegionModel::readCoeffs()
{
master_ = coeffs().lookupOrDefault<bool>("master", true);
nbrRegionName_ = coeffs().lookup<word>("nbrRegionName");
nbrRegionName_ =
coeffs().lookupBackwardsCompatible<word>
({
"nbrRegion",
"nbrRegionName"
});
interpolationMethod_ =
meshToMesh::interpolationMethodNames_.read
@ -60,27 +66,24 @@ void Foam::fv::interRegionModel::setMapper() const
{
Info<< indent << "- selecting inter region mapping" << endl;
const fvMesh& nbrMesh =
mesh().time().lookupObject<fvMesh>(nbrRegionName_);
if (mesh().name() == nbrMesh.name())
if (mesh().name() == nbrMesh().name())
{
FatalErrorInFunction
<< "Inter-region model selected, but local and "
<< "neighbour regions are the same: " << nl
<< " local region: " << mesh().name() << nl
<< " secondary region: " << nbrMesh.name() << nl
<< " secondary region: " << nbrMesh().name() << nl
<< exit(FatalError);
}
if (mesh().bounds().overlaps(nbrMesh.bounds()))
if (mesh().bounds().overlaps(nbrMesh().bounds()))
{
meshInterpPtr_.reset
(
new meshToMesh
(
mesh(),
nbrMesh,
nbrMesh(),
interpolationMethod_,
false // not interpolating patches
)
@ -90,7 +93,7 @@ void Foam::fv::interRegionModel::setMapper() const
{
FatalErrorInFunction
<< "regions " << mesh().name() << " and "
<< nbrMesh.name() << " do not intersect"
<< nbrMesh().name() << " do not intersect"
<< exit(FatalError);
}
}
@ -99,6 +102,34 @@ void Foam::fv::interRegionModel::setMapper() const
}
const Foam::fv::interRegionModel& Foam::fv::interRegionModel::nbrModel() const
{
const fvMesh& nbrMesh = mesh().time().lookupObject<fvMesh>(nbrRegionName());
const PtrListDictionary<fvModel>& fvModels =
nbrMesh.lookupObject<Foam::fvModels>("fvModels");
forAll(fvModels, fvModeli)
{
if (isA<interRegionModel>(fvModels[fvModeli]))
{
const interRegionModel& model =
refCast<const interRegionModel>(fvModels[fvModeli]);
if (model.nbrRegionName() == mesh().name())
{
return model;
}
}
}
FatalErrorInFunction
<< "Neighbour model not found in region " << nbrMesh.name() << nl
<< exit(FatalError);
return NullObjectRef<interRegionModel>();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::interRegionModel::interRegionModel

View File

@ -77,6 +77,14 @@ class interRegionModel
void setMapper() const;
protected:
// Protected member functions
//- Get the neighbour interRegionModel
const interRegionModel& nbrModel() const;
public:
//- Runtime type information
@ -109,10 +117,48 @@ public:
//- Return const access to the neighbour region name
inline const word& nbrRegionName() const;
//- Return const access to the neighbour mesh
inline const fvMesh& nbrMesh() const;
//- Return const access to the mapToMap pointer
inline const meshToMesh& meshInterp() const;
// Interpolation
//- Interpolate field with nbrModel specified
template<class Type>
tmp<Field<Type>> interpolate
(
const interRegionModel& nbrModel,
const Field<Type>& field
) const;
//- Interpolate field without nbrModel specified
template<class Type>
tmp<Field<Type>> interpolate
(
const Field<Type>& field
) const;
//- Interpolate field with nbrModel specified
template<class Type>
void interpolate
(
const interRegionModel& nbrModel,
const Field<Type>& field,
Field<Type>& result
) const;
//- Interpolate field without nbrModel specified
template<class Type>
void interpolate
(
const Field<Type>& field,
Field<Type>& result
) const;
// IO
//- Read dictionary
@ -129,6 +175,10 @@ public:
#include "interRegionModelI.H"
#ifdef NoRepository
#include "interRegionModelTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif

View File

@ -23,7 +23,7 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::fv::interRegionModel::master() const
{
@ -31,15 +31,19 @@ inline bool Foam::fv::interRegionModel::master() const
}
inline const Foam::word&
Foam::fv::interRegionModel::nbrRegionName() const
inline const Foam::word& Foam::fv::interRegionModel::nbrRegionName() const
{
return nbrRegionName_;
}
inline const Foam::meshToMesh&
Foam::fv::interRegionModel::meshInterp() const
inline const Foam::fvMesh& Foam::fv::interRegionModel::nbrMesh() const
{
return mesh().time().lookupObject<fvMesh>(nbrRegionName_);
}
inline const Foam::meshToMesh& Foam::fv::interRegionModel::meshInterp() const
{
if (!meshInterpPtr_.valid())
{

View File

@ -23,11 +23,15 @@ License
\*---------------------------------------------------------------------------*/
#include "interRegionModel.H"
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::fv::interRegionHeatTransferModel::interpolate
Foam::fv::interRegionModel::interpolate
(
const interRegionHeatTransferModel& nbrModel,
const interRegionModel& nbrModel,
const Field<Type>& field
) const
{
@ -44,7 +48,7 @@ Foam::fv::interRegionHeatTransferModel::interpolate
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::fv::interRegionHeatTransferModel::interpolate
Foam::fv::interRegionModel::interpolate
(
const Field<Type>& field
) const
@ -54,9 +58,9 @@ Foam::fv::interRegionHeatTransferModel::interpolate
template<class Type>
void Foam::fv::interRegionHeatTransferModel::interpolate
void Foam::fv::interRegionModel::interpolate
(
const interRegionHeatTransferModel& nbrModel,
const interRegionModel& nbrModel,
const Field<Type>& field,
Field<Type>& result
) const
@ -73,7 +77,7 @@ void Foam::fv::interRegionHeatTransferModel::interpolate
template<class Type>
void Foam::fv::interRegionHeatTransferModel::interpolate
void Foam::fv::interRegionModel::interpolate
(
const Field<Type>& field,
Field<Type>& result

View File

@ -17,14 +17,17 @@ FoamFile
airToporous
{
type constantHeatTransfer;
type interRegionHeatTransfer;
interRegionHeatTransferCoeffs
{
nbrRegion porous;
interpolationMethod cellVolumeWeight;
nbrRegionName porous;
master false;
nbrModel porousToair;
semiImplicit no;
}
}
porosityBlockage
@ -33,8 +36,9 @@ porosityBlockage
interRegionExplicitPorositySourceCoeffs
{
nbrRegion porous;
interpolationMethod cellVolumeWeight;
nbrRegionName porous;
type DarcyForchheimer;

View File

@ -1,31 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "constant";
object AoV;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 -1 0 0 0 0 0];
internalField uniform 200;
boundaryField
{
".*"
{
type zeroGradient;
}
}
// ************************************************************************* //

View File

@ -17,14 +17,22 @@ FoamFile
porousToair
{
type constantHeatTransfer;
type interRegionHeatTransfer;
interRegionHeatTransferCoeffs
{
nbrRegion air;
interpolationMethod cellVolumeWeight;
nbrRegionName air;
master true;
nbrModel airToporous;
semiImplicit no;
type constant;
htc 10;
AoV 200;
}
}

View File

@ -1,31 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "constant";
object htcConst;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [1 0 -3 -1 0 0 0];
internalField uniform 10;
boundaryField
{
".*"
{
type zeroGradient;
}
}
// ************************************************************************* //