/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 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 "externalTemperatureFvPatchScalarField.H" #include "thermophysicalTransportModel.H" #include "FunctionalDimensionedField.H" #include "physicoChemicalConstants.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // void Foam::externalTemperatureFvPatchScalarField::addEqOp ( tmp& tf, const scalar d ) const { if (!tf.valid()) { tf = new scalarField(size(), d); } else { tf.ref() += d; } } void Foam::externalTemperatureFvPatchScalarField::addEqOp ( tmp& tf, const tmp& tdf ) const { if (!tdf.valid()) { return; } if (!tf.valid()) { tf = tdf.ptr(); } else { tf.ref() += tdf; } } void Foam::externalTemperatureFvPatchScalarField::getKappa ( scalarField& kappa, tmp& sumKappaTcByDelta, tmp& sumKappaByDelta, tmp& T, tmp& sumq ) const { const thermophysicalTransportModel& ttm = patch().mesh() .lookupType(); kappa = ttm.kappaEff(patch().index()); T = tmp(*this); addEqOp(sumq, ttm.qCorr(patch().index())); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::externalTemperatureFvPatchScalarField:: externalTemperatureFvPatchScalarField ( const fvPatch& p, const DimensionedField& iF, const dictionary& dict ) : mixedFvPatchScalarField(p, iF, dict, false), haveQ_(dict.found("Q")), Q_ ( haveQ_ ? Function1::New("Q", time().userUnits(), dimensions::power, dict) : autoPtr>() ), haveq_(dict.found("q")), q_ ( haveq_ ? Function1::New ( "q", time().userUnits(), dimensions::heatFluxDensity, dict ) : autoPtr>() ), h_ ( dict.found("h") ? new FunctionalDimensionedField ( iF.name(), "h", p, dimensions::heatFluxDensity/dimensions::temperature, dict ) : nullptr ), haveEmissivity_(dict.found("emissivity")), emissivity_ ( haveEmissivity_ ? dict.lookup("emissivity", units::fraction) : NaN ), Ta_ ( h_.valid() || haveEmissivity_ ? Function1::New ( "Ta", time().userUnits(), dimensions::temperature, dict ).ptr() : nullptr ), relax_(dict.lookupOrDefault("relaxation", units::fraction, 1)), qrName_(dict.lookupOrDefault("qr", word::null)), qrRelax_(dict.lookupOrDefault("qrRelaxation", units::fraction, 1)), qrPrevious_ ( qrName_ != word::null ? dict.found("qrPrevious") ? scalarField ( "qrPrevious", dimensions::heatFluxDensity, dict, p.size() ) : scalarField(p.size(), 0) : scalarField() ) { fvPatchScalarField::operator= ( scalarField("value", iF.dimensions(), dict, p.size()) ); if (haveEmissivity_ && (emissivity_ < 0 || emissivity_ > 1)) { FatalIOErrorInFunction(dict) << "Emissivity must be in the range 0 to 1" << exit(FatalIOError); } if (dict.found("refValue")) { // Full restart refValue() = scalarField("refValue", iF.dimensions(), dict, p.size()); refGrad() = scalarField ( "refGradient", iF.dimensions()/dimensions::length, dict, p.size() ); valueFraction() = scalarField("valueFraction", units::fraction, dict, p.size()); } else { // Start from user entered data. Assume fixedValue. refValue() = *this; refGrad() = 0; valueFraction() = 1; } } Foam::externalTemperatureFvPatchScalarField:: externalTemperatureFvPatchScalarField ( const externalTemperatureFvPatchScalarField& ptf, const fvPatch& p, const DimensionedField& iF, const fieldMapper& mapper ) : mixedFvPatchScalarField(ptf, p, iF, mapper), haveQ_(ptf.haveQ_), Q_(ptf.Q_, false), haveq_(ptf.haveq_), q_(ptf.q_, false), h_ ( ptf.h_.valid() ? new FunctionalDimensionedField ( ptf.h_(), p, mapper ) : nullptr ), haveEmissivity_(ptf.haveEmissivity_), emissivity_(ptf.emissivity_), Ta_(ptf.Ta_, false), relax_(ptf.relax_), qrName_(ptf.qrName_), qrRelax_(ptf.qrRelax_), qrPrevious_ ( qrName_ != word::null ? mapper(ptf.qrPrevious_)() : scalarField() ) {} Foam::externalTemperatureFvPatchScalarField:: externalTemperatureFvPatchScalarField ( const externalTemperatureFvPatchScalarField& ptf, const DimensionedField& iF ) : mixedFvPatchScalarField(ptf, iF), haveQ_(ptf.haveQ_), Q_(ptf.Q_, false), haveq_(ptf.haveq_), q_(ptf.q_, false), h_ ( ptf.h_.valid() ? new FunctionalDimensionedField ( ptf.h_() ) : nullptr ), haveEmissivity_(ptf.haveEmissivity_), emissivity_(ptf.emissivity_), Ta_(ptf.Ta_, false), relax_(ptf.relax_), qrName_(ptf.qrName_), qrRelax_(ptf.qrRelax_), qrPrevious_(ptf.qrPrevious_) {} Foam::tmp Foam::externalTemperatureFvPatchScalarField::clone ( const DimensionedField& iF ) const { return tmp ( new externalTemperatureFvPatchScalarField(*this, iF) ); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::externalTemperatureFvPatchScalarField:: ~externalTemperatureFvPatchScalarField() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::externalTemperatureFvPatchScalarField::map ( const fvPatchScalarField& ptf, const fieldMapper& mapper ) { mixedFvPatchScalarField::map(ptf, mapper); const externalTemperatureFvPatchScalarField& etptf = refCast(ptf); if (h_.valid()) { h_->map(etptf.h_(), mapper); } if (qrName_ != word::null) { mapper(qrPrevious_, etptf.qrPrevious_); } } void Foam::externalTemperatureFvPatchScalarField::reset ( const fvPatchScalarField& ptf ) { mixedFvPatchScalarField::reset(ptf); if (h_.valid()) { h_->reset(); } const externalTemperatureFvPatchScalarField& tiptf = refCast(ptf); if (qrName_ != word::null) { qrPrevious_.reset(tiptf.qrPrevious_); } } void Foam::externalTemperatureFvPatchScalarField::updateCoeffs() { if (updated()) { return; } const scalar t = time().value(); // Get thermal conductivities, the patch temperature and any explicit // correction heat flux scalarField kappa; tmp sumKappaTcByDelta, sumKappaByDelta; tmp T; tmp sumq; getKappa(kappa, sumKappaTcByDelta, sumKappaByDelta, T, sumq); // Add any user specified heat fluxes if (haveQ_) { addEqOp(sumq, Q_->value(t)/gSum(patch().magSf())); } if (haveq_) { addEqOp(sumq, q_->value(t)); } // Add the (relaxed) radiative heat flux if (qrName_ != word::null) { const fvPatchScalarField& qrCurrent = patch().lookupPatchField(qrName_); const scalarField qr(qrRelax_*qrCurrent + (1 - qrRelax_)*qrPrevious_); qrPrevious_ = qr; addEqOp(sumq, qr); } // Evaluate the ambient temperature const scalar Ta = h_.valid() || haveEmissivity_ ? Ta_->value(t) : NaN; // Evaluate the combined convective and radiative heat transfer coefficient tmp hEff; if (h_.valid()) { h_->update(); addEqOp(hEff, h_()); } if (haveEmissivity_) { addEqOp ( hEff, emissivity_ *constant::physicoChemical::sigma.value() *(sqr(Ta) + sqr(T())) *(Ta + T()) ); } // If we have a heat transfer coefficient then add it to the kappa sums if (hEff.valid()) { addEqOp(sumKappaByDelta, hEff()); addEqOp(sumKappaTcByDelta, hEff*Ta); } // Set the mixed parameters const scalarField kappaByDelta(kappa*patch().deltaCoeffs()); tmp kappaPlusSumKappaByDelta ( sumKappaByDelta.valid() ? kappaByDelta + sumKappaByDelta() : tmp(kappaByDelta) ); // ... value fraction if (sumKappaByDelta.valid()) { valueFraction() = sumKappaByDelta()/kappaPlusSumKappaByDelta(); } else { valueFraction() = Zero; } // ... reference value tmp trefValue; if (sumKappaByDelta.valid()) { addEqOp ( trefValue, max(sumKappaTcByDelta, small*kappaByDelta*patchInternalField()) /max(sumKappaByDelta, small*kappaByDelta) ); } if (sumq.valid()) { addEqOp(trefValue, sumq()/kappaPlusSumKappaByDelta()); } if (trefValue.valid()) { refValue() = trefValue; } else { refValue() = Zero; } // ... and reference gradient if (sumq.valid()) { refGrad() = sumq*patch().deltaCoeffs()/kappaPlusSumKappaByDelta(); } else { refGrad() = Zero; } // Modify the mixed parameters for under-relaxation if (relax_ != 1) { const scalarField f(valueFraction()); valueFraction() = 1 - relax_*(1 - f); refValue() = (f*relax_*refValue() + (1 - relax_)*T)/valueFraction(); } mixedFvPatchScalarField::updateCoeffs(); if (debug) { const scalar Q = gSum(kappa*patch().magSf()*snGrad()); Info<< patch().mesh().name() << ':' << patch().name() << ':' << this->internalField().name() << " :" << " heat transfer rate:" << Q << " walltemperature " << " min:" << gMin(field()) << " max:" << gMax(field()) << " avg:" << gAverage(field()) << endl; } } void Foam::externalTemperatureFvPatchScalarField::write ( Ostream& os ) const { fvPatchScalarField::write(os); if (haveQ_) { writeEntry(os, time().userUnits(), dimensions::power, Q_()); } if (haveq_) { writeEntry ( os, time().userUnits(), dimensions::heatFluxDensity, q_() ); } if (h_.valid()) { writeEntry(os, h_()); } if (haveEmissivity_) { writeEntry(os, "emissivity", emissivity_); } if (h_.valid() || haveEmissivity_) { writeEntry(os, time().userUnits(), dimensions::temperature, Ta_()); } writeEntryIfDifferent(os, "relaxation", scalar(1), relax_); if (qrName_ != word::null) { writeEntry(os, "qr", qrName_); writeEntry(os, "qrRelaxation", qrRelax_); writeEntry(os, "qrPrevious", qrPrevious_); } writeEntry(os, "refValue", refValue()); writeEntry(os, "refGradient", refGrad()); writeEntry(os, "valueFraction", valueFraction()); writeEntry(os, "value", *this); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { makePatchTypeField ( fvPatchScalarField, externalTemperatureFvPatchScalarField ); addBackwardCompatibleToRunTimeSelectionTable ( fvPatchScalarField, externalTemperatureFvPatchScalarField, patchMapper, externalWallHeatFluxTemperature, "externalWallHeatFluxTemperature" ); addBackwardCompatibleToRunTimeSelectionTable ( fvPatchScalarField, externalTemperatureFvPatchScalarField, dictionary, externalWallHeatFluxTemperature, "externalWallHeatFluxTemperature" ); } // ************************************************************************* //