From 8d707b48c602fe1c4f97a9e54b61b3784f5aaff6 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Thu, 18 Mar 2021 11:38:13 +0000 Subject: [PATCH] fvModels: Added heatSource model This model applies a heat source. It requires either the power, Q, or the power per unit volume, q, to be specified. Example usage: heatSource { type heatSource; selectionMode cellSet; cellSet heater; Q 1e6; } --- .../functions/Function1/Scale/Scale.C | 26 +++ .../functions/Function1/Scale/Scale.H | 11 +- src/fvModels/Make/files | 1 + src/fvModels/derived/heatSource/heatSource.C | 167 ++++++++++++++++++ src/fvModels/derived/heatSource/heatSource.H | 149 ++++++++++++++++ .../heatedDuct/constant/heater/fvModels | 13 +- 6 files changed, 355 insertions(+), 12 deletions(-) create mode 100644 src/fvModels/derived/heatSource/heatSource.C create mode 100644 src/fvModels/derived/heatSource/heatSource.H diff --git a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C index faa42e4864..7da2befebb 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C +++ b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C @@ -49,6 +49,32 @@ void Foam::Function1s::Scale::read(const dictionary& dict) // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +template +Foam::Function1s::Scale::Scale +( + const word& name, + const Function1& scale, + const Function1& xScale, + const Function1& value +) +: + FieldFunction1>(name), + scale_(scale.clone().ptr()), + xScale_(xScale.clone().ptr()), + value_(value.clone().ptr()), + integrableScale_ + ( + isA>(xScale_()) + && isA>(scale_()) + ), + integrableValue_ + ( + isA>(xScale_()) + && isA>(value_()) + ) +{} + + template Foam::Function1s::Scale::Scale ( diff --git a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H index 5f83dd940a..86b97a35c8 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H +++ b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -169,6 +169,15 @@ public: // Constructors + //- Construct from name and functions + Scale + ( + const word& name, + const Function1& scale, + const Function1& xScale, + const Function1& value + ); + //- Construct from name and dictionary Scale ( diff --git a/src/fvModels/Make/files b/src/fvModels/Make/files index 64f7045328..c3b0484c70 100644 --- a/src/fvModels/Make/files +++ b/src/fvModels/Make/files @@ -27,6 +27,7 @@ derived/accelerationSource/accelerationSource.C derived/volumeFractionSource/volumeFractionSource.C derived/solidEquilibriumEnergySource/solidEquilibriumEnergySource.C derived/massSource/massSource.C +derived/heatSource/heatSource.C derived/heatTransfer/heatTransfer.C interRegion/interRegionModel/interRegionModel.C diff --git a/src/fvModels/derived/heatSource/heatSource.C b/src/fvModels/derived/heatSource/heatSource.C new file mode 100644 index 0000000000..71c19a6df3 --- /dev/null +++ b/src/fvModels/derived/heatSource/heatSource.C @@ -0,0 +1,167 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +\*---------------------------------------------------------------------------*/ + +#include "heatSource.H" +#include "basicThermo.H" +#include "fvModels.H" +#include "fvMatrix.H" +#include "Scale.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace fv +{ + defineTypeNameAndDebug(heatSource, 0); + addToRunTimeSelectionTable + ( + fvModel, + heatSource, + dictionary + ); +} +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::fv::heatSource::readCoeffs() +{ + if (!coeffs().found("q") && !coeffs().found("Q")) + { + FatalIOErrorInFunction(coeffs()) + << "Neither heat source per unit volume, q, or total heat source, " + << "Q, has been specified. One is required." << exit(FatalIOError); + } + + if (coeffs().found("q") && coeffs().found("Q")) + { + FatalIOErrorInFunction(coeffs()) + << "Both heat source per unit volume, q, and total heat source, " + << "Q, have been specified. One is required." + << exit(FatalIOError); + } + + if (coeffs().found("q")) + { + q_.reset(Function1::New("q", coeffs()).ptr()); + } + else + { + q_.reset + ( + new Function1s::Scale + ( + "q", + Function1s::Constant("1/V", 1/set_.V()), + Function1s::Constant("1", 1), + Function1::New("Q", coeffs())() + ) + ); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::fv::heatSource::heatSource +( + const word& name, + const word& modelType, + const dictionary& dict, + const fvMesh& mesh +) +: + fvModel(name, modelType, dict, mesh), + set_(coeffs(), mesh), + q_(nullptr) +{ + readCoeffs(); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::fv::heatSource::~heatSource() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::wordList Foam::fv::heatSource::addSupFields() const +{ + const basicThermo& thermo = + mesh().lookupObject(basicThermo::dictName); + + return wordList(1, thermo.he().name()); +} + + +void Foam::fv::heatSource::addSup +( + fvMatrix& eqn, + const word& fieldName +) const +{ + const labelList& cells = set_.cells(); + + const scalar t = mesh().time().value(); + const scalar q = q_->value(t); + + forAll(cells, i) + { + eqn.source()[cells[i]] -= mesh().V()[cells[i]]*q; + } +} + + +void Foam::fv::heatSource::addSup +( + const volScalarField& rho, + fvMatrix& eqn, + const word& fieldName +) const +{ + addSup(eqn, fieldName); +} + + +bool Foam::fv::heatSource::read(const dictionary& dict) +{ + if (fvModel::read(dict)) + { + readCoeffs(); + return true; + } + else + { + return false; + } +} + + +// ************************************************************************* // diff --git a/src/fvModels/derived/heatSource/heatSource.H b/src/fvModels/derived/heatSource/heatSource.H new file mode 100644 index 0000000000..5080507b29 --- /dev/null +++ b/src/fvModels/derived/heatSource/heatSource.H @@ -0,0 +1,149 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +Class + Foam::fv::heatSource + +Description + Model for applying a heat source. Requires either the power, Q, or the + power per unit volume, q, to be specified. + +Usage + Example usage: + \verbatim + heatSource + { + type heatSource; + + selectionMode cellSet; + cellSet heater; + + Q 1e6; + } + \endverbatim + +\*---------------------------------------------------------------------------*/ + +#ifndef heatSource_H +#define heatSource_H + +#include "fvModel.H" +#include "fvCellSet.H" +#include "Function1.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class heatSource Declaration +\*---------------------------------------------------------------------------*/ + +class heatSource +: + public fvModel +{ + // Private data + + //- The set of cells the model applies to + fvCellSet set_; + + //- The heat source + autoPtr> q_; + + + // Private member functions + + //- Non-virtual read + void readCoeffs(); + + +public: + + //- Runtime type information + TypeName("heatSource"); + + + // Constructors + + //- Construct from dictionary + heatSource + ( + const word& name, + const word& modelType, + const dictionary& dict, + const fvMesh& mesh + ); + + + //- Destructor + virtual ~heatSource(); + + + // Member Functions + + // Checks + + //- Return the list of fields for which the fvModel adds source term + // to the transport equation + virtual wordList addSupFields() const; + + + // Sources + + //- Source term to energy equation + virtual void addSup + ( + fvMatrix& eqn, + const word& fieldName + ) const; + + //- Source term to compressible energy equation + virtual void addSup + ( + const volScalarField& rho, + fvMatrix& eqn, + const word& fieldName + ) const; + + + // IO + + //- Read dictionary + virtual bool read(const dictionary& dict); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/heatedDuct/constant/heater/fvModels b/tutorials/heatTransfer/chtMultiRegionFoam/heatedDuct/constant/heater/fvModels index fe0d16af4b..bbdde2ae10 100644 --- a/tutorials/heatTransfer/chtMultiRegionFoam/heatedDuct/constant/heater/fvModels +++ b/tutorials/heatTransfer/chtMultiRegionFoam/heatedDuct/constant/heater/fvModels @@ -17,20 +17,11 @@ FoamFile energySource { - type semiImplicitSource; + type heatSource; selectionMode all; - volumeMode specific; - - sources - { - e - { - explicit 1e7; // W/m^3 == kg/m/s^3 - implicit 0; - } - } + q 1e7; } // ************************************************************************* //