diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index 52687a2bf2..d40d9aa8bd 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -50,6 +50,7 @@ turbulenceFields/turbulenceFields.C yPlus/yPlus.C wallShearStress/wallShearStress.C wallHeatFlux/wallHeatFlux.C +wallHeatTransferCoeff/wallHeatTransferCoeff.C writeCellCentres/writeCellCentres.C writeCellVolumes/writeCellVolumes.C diff --git a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H index a890ccdbfa..006f0165c0 100644 --- a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H +++ b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H @@ -25,7 +25,7 @@ Class Foam::functionObjects::wallHeatFlux Group - grpForcesFunctionObjects + grpFieldFunctionObjects Description Calculates and write the heat-flux at wall patches as the @@ -63,7 +63,6 @@ See also Foam::functionObjects::fvMeshFunctionObject Foam::functionObjects::logFiles Foam::functionObjects::writeLocalObjects - Foam::functionObjects::pressureTools Foam::functionObjects::timeControl SourceFiles @@ -77,8 +76,8 @@ SourceFiles #include "fvMeshFunctionObject.H" #include "logFiles.H" #include "writeLocalObjects.H" -#include "volFieldsFwd.H" #include "HashSet.H" +#include "volFieldsFwd.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/functionObjects/field/wallHeatTransferCoeff/wallHeatTransferCoeff.C b/src/functionObjects/field/wallHeatTransferCoeff/wallHeatTransferCoeff.C new file mode 100644 index 0000000000..2354b92bfe --- /dev/null +++ b/src/functionObjects/field/wallHeatTransferCoeff/wallHeatTransferCoeff.C @@ -0,0 +1,283 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 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 "wallHeatTransferCoeff.H" +#include "turbulentTransportModel.H" +#include "wallPolyPatch.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(wallHeatTransferCoeff, 0); + addToRunTimeSelectionTable + ( + functionObject, + wallHeatTransferCoeff, + dictionary + ); +} +} + + +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // + +void Foam::functionObjects::wallHeatTransferCoeff::writeFileHeader +( + const label i +) +{ + // Add headers to output data + writeHeader(file(), "Wall heat transfer coefficient"); + writeCommented(file(), "Time"); + writeTabbed(file(), "patch"); + writeTabbed(file(), "min"); + writeTabbed(file(), "max"); + writeTabbed(file(), "integral"); + file() << endl; +} + + +void Foam::functionObjects::wallHeatTransferCoeff::calcHeatTransferCoeff +( + const volScalarField& nu, + const volScalarField& nut, + volScalarField& wallHeatTransferCoeff +) +{ + volScalarField::Boundary& wallHeatTransferCoeffBf = + wallHeatTransferCoeff.boundaryFieldRef(); + + const volScalarField::Boundary& nuBf = nu.boundaryField(); + const volScalarField::Boundary& nutBf = nut.boundaryField(); + + forAll(wallHeatTransferCoeffBf, patchi) + { + if (!wallHeatTransferCoeffBf[patchi].coupled()) + { + wallHeatTransferCoeffBf[patchi] = + rho_*Cp_*(nuBf[patchi]/Prl_ + nutBf[patchi]/Prt_); + } + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::wallHeatTransferCoeff::wallHeatTransferCoeff +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fvMeshFunctionObject(name, runTime, dict), + logFiles(obr_, name), + writeLocalObjects(obr_, log), + patchSet_() +{ + volScalarField* wallHeatTransferCoeffPtr + ( + new volScalarField + ( + IOobject + ( + type(), + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedScalar("0", dimMass/pow3(dimTime)/dimTemperature, 0) + ) + ); + + mesh_.objectRegistry::store(wallHeatTransferCoeffPtr); + + read(dict); + resetName(typeName); + resetLocalObjectName(typeName); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::wallHeatTransferCoeff::~wallHeatTransferCoeff() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::wallHeatTransferCoeff::read(const dictionary& dict) +{ + fvMeshFunctionObject::read(dict); + writeLocalObjects::read(dict); + + 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(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(pbm[patchi])) + { + filteredPatchSet.insert(patchi); + Info<< " " << pbm[patchi].name() << endl; + } + else + { + WarningInFunction + << "Requested wall heat-transferCoeff on non-wall boundary " + << "type patch: " << pbm[patchi].name() << endl; + } + } + + Info<< endl; + + patchSet_ = filteredPatchSet; + } + + dict.lookup("rho") >> rho_; + dict.lookup("Cp") >> Cp_; + dict.lookup("Prl") >> Prl_; + dict.lookup("Prt") >> Prt_; + + return true; +} + + +bool Foam::functionObjects::wallHeatTransferCoeff::execute() +{ + volScalarField& wallHeatTransferCoeff = + lookupObjectRef(type()); + + if + ( + foundObject + ( + turbulenceModel::propertiesName + ) + ) + { + const incompressible::turbulenceModel& turbModel = + lookupObject + ( + turbulenceModel::propertiesName + ); + + calcHeatTransferCoeff + ( + turbModel.nu(), + turbModel.nut(), + wallHeatTransferCoeff + ); + } + else + { + FatalErrorInFunction + << "Unable to find incompressible turbulence model in the " + << "database" << exit(FatalError); + } + + return true; +} + + +bool Foam::functionObjects::wallHeatTransferCoeff::write() +{ + Log << type() << " " << name() << " write:" << nl; + + writeLocalObjects::write(); + + logFiles::write(); + + const volScalarField& wallHeatTransferCoeff = + obr_.lookupObject(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 = wallHeatTransferCoeff.boundaryField()[patchi]; + + const scalar minHtcp = gMin(hfp); + const scalar maxHtcp = gMax(hfp); + const scalar integralHtcp = gSum(magSf[patchi]*hfp); + + if (Pstream::master()) + { + file() + << mesh_.time().value() + << tab << pp.name() + << tab << minHtcp + << tab << maxHtcp + << tab << integralHtcp + << endl; + } + + Log << " min/max/integ(" << pp.name() << ") = " + << minHtcp << ", " << maxHtcp << ", " << integralHtcp << endl; + } + + Log << endl; + + return true; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/wallHeatTransferCoeff/wallHeatTransferCoeff.H b/src/functionObjects/field/wallHeatTransferCoeff/wallHeatTransferCoeff.H new file mode 100644 index 0000000000..68b119506a --- /dev/null +++ b/src/functionObjects/field/wallHeatTransferCoeff/wallHeatTransferCoeff.H @@ -0,0 +1,198 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 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::functionObjects::wallHeatTransferCoeff + +Group + grpFieldFunctionObjects + +Description + Calculates and write the estimated incompressible flow heat transfer + coefficient at wall patches as the volScalarField field + 'wallHeatTransferCoeff'. + + 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 + wallHeatTransferCoeff1 + { + type wallHeatTransferCoeff; + libs ("libfieldFunctionObjects.so"); + ... + region fluid; + patches (".*Wall"); + rho 1.225; + Cp 1005; + Prl 0.707; + Prt 0.9; + } + \endverbatim + +Usage + \table + Property | Description | Required | Default value + type | Type name: wallHeatTransferCoeff | yes | + patches | List of patches to process | no | all wall patches + region | Region to be evaluated | no | default region + rho | Fluid density | yes | + Cp | Fluid heat capacity | yes | + Prl | Fluid laminar Prandtl number | yes | + Prt | Fluid turbulent Prandtl number| yes | + \endtable + +Note + Writing field 'wallHeatTransferCoeff' 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 + wallHeatTransferCoeff.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_wallHeatTransferCoeff_H +#define functionObjects_wallHeatTransferCoeff_H + +#include "fvMeshFunctionObject.H" +#include "logFiles.H" +#include "writeLocalObjects.H" +#include "HashSet.H" +#include "volFieldsFwd.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class wallHeatTransferCoeff Declaration +\*---------------------------------------------------------------------------*/ + +class wallHeatTransferCoeff +: + public fvMeshFunctionObject, + public logFiles, + public writeLocalObjects +{ + +protected: + + // Protected data + + //- Optional list of patches to process + labelHashSet patchSet_; + + //- Fluid density + scalar rho_; + + //- Fluid heat capacity + scalar Cp_; + + //- Fluid laminar Prandtl number + scalar Prl_; + + //- Fluid turbulent Prandtl number + scalar Prt_; + + + // Protected Member Functions + + //- File header information + virtual void writeFileHeader(const label i); + + //- Calculate the heat transfer coefficient + void calcHeatTransferCoeff + ( + const volScalarField& nu, + const volScalarField& nut, + volScalarField& wallHeatTransferCoeff + ); + + +private: + + // Private member functions + + //- Disallow default bitwise copy construct + wallHeatTransferCoeff(const wallHeatTransferCoeff&); + + //- Disallow default bitwise assignment + void operator=(const wallHeatTransferCoeff&); + + +public: + + //- Runtime type information + TypeName("wallHeatTransferCoeff"); + + + // Constructors + + //- Construct from Time and dictionary + wallHeatTransferCoeff + ( + const word& name, + const Time& runTime, + const dictionary& + ); + + + //- Destructor + virtual ~wallHeatTransferCoeff(); + + + // Member Functions + + //- Read the wallHeatTransferCoeff data + virtual bool read(const dictionary&); + + //- Calculate the wall heat transfer coefficient + virtual bool execute(); + + //- Write the wall heat transfer coefficient + virtual bool write(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //