/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2016 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 "wallHeatFlux.H" #include "surfaceInterpolate.H" #include "fvcSnGrad.H" #include "wallPolyPatch.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { namespace functionObjects { defineTypeNameAndDebug(wallHeatFlux, 0); addToRunTimeSelectionTable(functionObject, wallHeatFlux, dictionary); } } // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // void Foam::functionObjects::wallHeatFlux::writeFileHeader(const label i) { // Add headers to output data writeHeader(file(), "Wall heat-flux"); writeCommented(file(), "Time"); writeTabbed(file(), "patch"); writeTabbed(file(), "min"); writeTabbed(file(), "max"); writeTabbed(file(), "integral"); file() << endl; } void Foam::functionObjects::wallHeatFlux::calcHeatFlux ( const compressible::turbulenceModel& model, volScalarField& wallHeatFlux ) { surfaceScalarField heatFlux ( fvc::interpolate(model.alphaEff())*fvc::snGrad(model.transport().he()) ); volScalarField::Boundary& wallHeatFluxBf = wallHeatFlux.boundaryFieldRef(); const surfaceScalarField::Boundary& heatFluxBf = heatFlux.boundaryField(); forAll(wallHeatFluxBf, patchi) { wallHeatFluxBf[patchi] = heatFluxBf[patchi]; } if (foundObject("Qr")) { const volScalarField& Qr = lookupObject("Qr"); const volScalarField::Boundary& radHeatFluxBf = Qr.boundaryField(); forAll(wallHeatFluxBf, patchi) { wallHeatFluxBf[patchi] += radHeatFluxBf[patchi]; } } } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::wallHeatFlux::wallHeatFlux ( const word& name, const Time& runTime, const dictionary& dict ) : writeFiles(name, runTime, dict, name), patchSet_() { if (!isA(obr_)) { FatalErrorInFunction << "objectRegistry is not an fvMesh" << exit(FatalError); } const fvMesh& mesh = refCast(obr_); volScalarField* wallHeatFluxPtr ( new volScalarField ( IOobject ( type(), mesh.time().timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedScalar("0", dimMass/pow3(dimTime), 0) ) ); mesh.objectRegistry::store(wallHeatFluxPtr); read(dict); resetName(typeName); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::functionObjects::wallHeatFlux::~wallHeatFlux() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::functionObjects::wallHeatFlux::read(const dictionary& dict) { writeFiles::read(dict); const fvMesh& mesh = refCast(obr_); 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-flux on non-wall boundary " << "type patch: " << pbm[patchi].name() << endl; } } Info<< endl; patchSet_ = filteredPatchSet; } return true; } bool Foam::functionObjects::wallHeatFlux::execute() { volScalarField& wallHeatFlux = const_cast ( lookupObject(type()) ); if ( foundObject ( turbulenceModel::propertiesName ) ) { const compressible::turbulenceModel& turbModel = lookupObject ( turbulenceModel::propertiesName ); calcHeatFlux(turbModel, wallHeatFlux); } else { FatalErrorInFunction << "Unable to find compressible turbulence model in the " << "database" << exit(FatalError); } return true; } bool Foam::functionObjects::wallHeatFlux::write() { writeFiles::write(); const volScalarField& wallHeatFlux = obr_.lookupObject(type()); Log << type() << " " << name() << " write:" << nl << " writing field " << wallHeatFlux.name() << endl; wallHeatFlux.write(); const fvMesh& mesh = refCast(obr_); 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 = wallHeatFlux.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() << token::TAB << pp.name() << token::TAB << minHfp << token::TAB << maxHfp << token::TAB << integralHfp << endl; } Log << " min/max(" << pp.name() << ") = " << minHfp << ", " << maxHfp << ", " << integralHfp << endl; } return true; } // ************************************************************************* //