View Issue Details

IDProjectCategoryView StatusLast Update
0003446OpenFOAMContributionpublic2020-02-07 20:44
ReporterDaveD Assigned Tohenry  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionno change required 
PlatformGNU/LinuxOSUbuntuOS Version18.04
Summary0003446: Function object for calculation wall heat transfer coefficient based on constant reference temperature
DescriptionDear all,
I have implemented a new field functionObject called "myWallHeatTransferCoeff". In contrast to the exisiting wallHeatTransferCoeff object, it calculates the wall heat transfer coefficient not from Reynolds analogy but from the wall heat flux, the wall temperature and a constant reference temperature:

    \f[
            h = \frac{q}{T_{ref} - T_W}
    \f]

I used the "wallHeatFlux" functionObject as template for implementation. Please merge with existent wallHeatTransferCoeff object or implement as new functionObject.
Thanks, DaveD
TagsNo tags attached.

Activities

DaveD

2020-02-07 12:07

reporter  

myWallHeatTransferCoeff.C (8,241 bytes)   
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Copyright (C) 2016-2018 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 "myWallHeatTransferCoeff.H"
#include "turbulentFluidThermoModel.H"
#include "solidThermo.H"
#include "surfaceInterpolate.H"
#include "fvcSnGrad.H"
#include "wallPolyPatch.H"
#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
namespace functionObjects
{
    defineTypeNameAndDebug(myWallHeatTransferCoeff, 0);
    addToRunTimeSelectionTable(functionObject, myWallHeatTransferCoeff, dictionary);
}
}

// * * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * //

void Foam::functionObjects::myWallHeatTransferCoeff::writeFileHeader(const label i)
{
    // Add headers to output data
    writeHeader(file(), "Wall HTC");
    writeCommented(file(), "Time");
    writeTabbed(file(), "patch");
    writeTabbed(file(), "min");
    writeTabbed(file(), "max");
    writeTabbed(file(), "integral");
    file() << endl;
}


Foam::tmp<Foam::volScalarField>
Foam::functionObjects::myWallHeatTransferCoeff::calcMyWallHeatTransferCoeff
(
    const volScalarField& alpha,
    const volScalarField& he,
    const volScalarField& T,
    scalar Tref
)
{
    tmp<volScalarField> tmyWallHeatTransferCoeff
    (
        volScalarField::New
        (
            type(),
            mesh_,
            dimensionedScalar(dimMass/(pow3(dimTime)*dimTemperature), 0)
        )
    );

    volScalarField::Boundary& myWallHeatTransferCoeffBf =
        tmyWallHeatTransferCoeff.ref().boundaryFieldRef();

    const volScalarField::Boundary& heBf =
        he.boundaryField();

    const volScalarField::Boundary& alphaBf =
        alpha.boundaryField();

    const volScalarField::Boundary& TBf =
        T.boundaryField();

    forAll(myWallHeatTransferCoeffBf, patchi)
    {
        if (!myWallHeatTransferCoeffBf[patchi].coupled())
        {
            myWallHeatTransferCoeffBf[patchi] = alphaBf[patchi]*heBf[patchi].snGrad()/(TBf[patchi]-Tref+ROOTVSMALL);
        }
    }

    if (foundObject<volScalarField>("qr"))
    {
        const volScalarField& qr = lookupObject<volScalarField>("qr");

        const volScalarField::Boundary& radHeatFluxBf =
            qr.boundaryField();

        forAll(myWallHeatTransferCoeffBf, patchi)
        {
            if (!myWallHeatTransferCoeffBf[patchi].coupled())
            {
                myWallHeatTransferCoeffBf[patchi]= (alphaBf[patchi]*heBf[patchi].snGrad()-radHeatFluxBf[patchi])/(TBf[patchi]-Tref+ROOTVSMALL);
            }
        }
    }

    return tmyWallHeatTransferCoeff;
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::functionObjects::myWallHeatTransferCoeff::myWallHeatTransferCoeff
(
    const word& name,
    const Time& runTime,
    const dictionary& dict
)
:
    fvMeshFunctionObject(name, runTime, dict),
    logFiles(obr_, name),
    writeLocalObjects(obr_, log),
    patchSet_()
{
    read(dict);
    resetName(typeName);
    resetLocalObjectName(typeName);
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::functionObjects::myWallHeatTransferCoeff::~myWallHeatTransferCoeff()
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

bool Foam::functionObjects::myWallHeatTransferCoeff::read(const dictionary& dict)
{
    fvMeshFunctionObject::read(dict);
    writeLocalObjects::read(dict);

    Tref = dict.lookupOrDefault<scalar>("Tref", 0);

    const polyBoundaryMesh& pbm = mesh_.boundaryMesh();

    patchSet_ =
        mesh_.boundaryMesh().patchSet
        (
            wordReList(dict.lookupOrDefault("patches", wordReList()))
        );

    Info<< type() << " " << name() << ":" << nl;

    if (patchSet_.empty())
    {
        forAll(pbm, patchi)
        {
            if (isA<wallPolyPatch>(pbm[patchi]))
            {
                patchSet_.insert(patchi);
            }
        }

        Info<< "    processing all wall patches" << nl << endl;
    }
    else
    {
        Info<< "    processing wall patches: " << nl;
        labelHashSet filteredPatchSet;
        forAllConstIter(labelHashSet, patchSet_, iter)
        {
            label patchi = iter.key();
            if (isA<wallPolyPatch>(pbm[patchi]))
            {
                filteredPatchSet.insert(patchi);
                Info<< "        " << pbm[patchi].name() << endl;
            }
            else
            {
                WarningInFunction
                    << "Requested wall HTC on non-wall boundary "
                    << "type patch: " << pbm[patchi].name() << endl;
            }
        }

        Info<< endl;

        patchSet_ = filteredPatchSet;
    }

    return true;
}


bool Foam::functionObjects::myWallHeatTransferCoeff::execute()
{
    word name(type());

    if
    (
        foundObject<compressible::turbulenceModel>
        (
            turbulenceModel::propertiesName
        )
    )
    {
        const compressible::turbulenceModel& turbModel =
            lookupObject<compressible::turbulenceModel>
            (
                turbulenceModel::propertiesName
            );

        return store
        (
            name,
            calcMyWallHeatTransferCoeff(turbModel.alphaEff(), turbModel.transport().he(), turbModel.transport().T(), Tref)
        );
    }
    else if (foundObject<solidThermo>(solidThermo::dictName))
    {
        const solidThermo& thermo =
            lookupObject<solidThermo>(solidThermo::dictName);

        return store(name, calcMyWallHeatTransferCoeff(thermo.alpha(), thermo.he(), thermo.T(), Tref));
    }
    else
    {
        FatalErrorInFunction
            << "Unable to find compressible turbulence model in the "
            << "database" << exit(FatalError);
    }

    return true;
}


bool Foam::functionObjects::myWallHeatTransferCoeff::write()
{
    Log << type() << " " << name() << " write:" << nl;

    writeLocalObjects::write();

    logFiles::write();

    const volScalarField& myWallHeatTransferCoeff =
        obr_.lookupObject<volScalarField>(type());

    const fvPatchList& patches = mesh_.boundary();

    const surfaceScalarField::Boundary& magSf =
        mesh_.magSf().boundaryField();

    forAllConstIter(labelHashSet, patchSet_, iter)
    {
        label patchi = iter.key();
        const fvPatch& pp = patches[patchi];

        const scalarField& hfp = myWallHeatTransferCoeff.boundaryField()[patchi];

        const scalar minHfp = gMin(hfp);
        const scalar maxHfp = gMax(hfp);
        const scalar integralHfp = gSum(magSf[patchi]*hfp);

        if (Pstream::master())
        {
            file()
                << mesh_.time().value()
                << tab << pp.name()
                << tab << minHfp
                << tab << maxHfp
                << tab << integralHfp
                << endl;
        }

        Log << "    min/max/integ(" << pp.name() << ") = "
            << minHfp << ", " << maxHfp << ", " << integralHfp << endl;
    }

    Log << endl;

    return true;
}


// ************************************************************************* //
myWallHeatTransferCoeff.C (8,241 bytes)   
myWallHeatTransferCoeff.H (5,224 bytes)   
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Copyright (C) 2016-2019 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::functionObjects::myWallHeatTransferCoeff

Description
    Calculates and write the HTC based on a fixed reference temperature

    \f[
            h = \frac{q}{T_{ref} - T_W}
    \f]

    at wall patches as the volScalarField field 'myWallHeatTransferCoeff'.

    All wall patches are included by default; to restrict the calculation to
    certain patches, use the optional 'patches' entry.

    Example of function object specification:
    \verbatim
    myWallHeatTransferCoeff1
    {
        type        myWallHeatTransferCoeff;
        libs        ("libfieldFunctionObjects.so");
        ...
        Tref        293;
        region      fluid;
        patches     (".*Wall");
    }
    \endverbatim

Usage
    \table
        Property | Description                        | Required   | Default value
        type     | type name: myWallHeatTransferCoeff | yes        |
        Tref     | reference temperature              | no         | 0
        patches  | list of patches to process         | no         | all wall patches
        region   | region to be evaluated             | no         | default region
    \endtable

Note
    Writing field 'myWallHeatTransferCoeff' is done by default, but it can be overridden by
    defining an empty \c objects list. For details see writeLocalObjects.

See also
    Foam::functionObject
    Foam::functionObjects::fvMeshFunctionObject
    Foam::functionObjects::logFiles
    Foam::functionObjects::writeLocalObjects
    Foam::functionObjects::timeControl

SourceFiles
    myWallHeatTransferCoeff.C

\*---------------------------------------------------------------------------*/

#ifndef functionObjects_myWallHeatTransferCoeff_H
#define functionObjects_myWallHeatTransferCoeff_H

#include "fvMeshFunctionObject.H"
#include "logFiles.H"
#include "writeLocalObjects.H"
#include "HashSet.H"
#include "volFieldsFwd.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
namespace functionObjects
{

/*---------------------------------------------------------------------------*\
                       Class myWallHeatTransferCoeff Declaration
\*---------------------------------------------------------------------------*/

class myWallHeatTransferCoeff
:
    public fvMeshFunctionObject,
    public logFiles,
    public writeLocalObjects
{
    // Private Data

    //- Optional Tref (default is 0)
    scalar Tref;

protected:

    // Protected data

        //- Optional list of patches to process
        labelHashSet patchSet_;


    // Protected Member Functions

        //- File header information
        virtual void writeFileHeader(const label i);

        //- Calculate the HTC
        tmp<volScalarField> calcMyWallHeatTransferCoeff
        (
            const volScalarField& alpha,
            const volScalarField& he,
            const volScalarField& T,
            scalar Tref
        );


public:

    //- Runtime type information
    TypeName("myWallHeatTransferCoeff");


    // Constructors

        //- Construct from Time and dictionary
        myWallHeatTransferCoeff
        (
            const word& name,
            const Time& runTime,
            const dictionary&
        );

        //- Disallow default bitwise copy construction
        myWallHeatTransferCoeff(const myWallHeatTransferCoeff&) = delete;


    //- Destructor
    virtual ~myWallHeatTransferCoeff();


    // Member Functions

        //- Read the myWallHeatTransferCoeff data
        virtual bool read(const dictionary&);

        //- Calculate the wall HTC
        virtual bool execute();

        //- Write the wall HTC
        virtual bool write();


    // Member Operators

        //- Disallow default bitwise assignment
        void operator=(const myWallHeatTransferCoeff&) = delete;
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace functionObjects
} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //
myWallHeatTransferCoeff.H (5,224 bytes)   

henry

2020-02-07 14:30

manager   ~0011148

It is not clear under what conditions this would be useful and is not well defined when the temperature is equal to the reference temperature. This may be useful for your current needs but it is not something we would want to include, maintain and support in OpenFOAM releases unless there is general interest in this functionality. I will close this report for now and users that are interested in testing this functionality can download and try the code you have provided and if we receive sufficient interest from sponsors of OpenFOAM we will plan a more general integrated implementation.

Issue History

Date Modified Username Field Change
2020-02-07 12:07 DaveD New Issue
2020-02-07 12:07 DaveD File Added: myWallHeatTransferCoeff.C
2020-02-07 12:07 DaveD File Added: myWallHeatTransferCoeff.H
2020-02-07 14:30 henry Assigned To => henry
2020-02-07 14:30 henry Status new => closed
2020-02-07 14:30 henry Resolution open => no change required
2020-02-07 14:30 henry Note Added: 0011148