/*---------------------------------------------------------------------------*\ ========= | \\ / 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 "BasicThermo.H" #include "gradientEnergyFvPatchScalarField.H" #include "mixedEnergyFvPatchScalarField.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // template template Foam::tmp Foam::BasicThermo::volScalarFieldProperty ( const word& psiName, const dimensionSet& psiDim, Mixture mixture, Method psiMethod, const Args& ... args ) const { tmp tPsi ( volScalarField::New ( IOobject::groupName(psiName, this->group()), this->mesh(), psiDim ) ); volScalarField& psi = tPsi.ref(); auto Yslicer = this->Yslicer(); forAll(psi, celli) { auto composition = this->cellComposition(Yslicer, celli); psi[celli] = ((this->*mixture)(composition).*psiMethod)(args[celli] ...); } volScalarField::BoundaryField& psiBf = psi.boundaryFieldRef(); forAll(psiBf, patchi) { forAll(psiBf[patchi], patchFacei) { auto composition = this->patchFaceComposition(Yslicer, patchi, patchFacei); psiBf[patchi][patchFacei] = ((this->*mixture)(composition).*psiMethod) ( args.boundaryField()[patchi][patchFacei] ... ); } } return tPsi; } template template Foam::tmp Foam::BasicThermo::volScalarFieldMixtureProperty ( const word& psiName, const dimensionSet& psiDim, Method mixtureMethod, const Args& ... args ) const { tmp tPsi ( volScalarField::New ( IOobject::groupName(psiName, this->group()), this->mesh(), psiDim ) ); volScalarField& psi = tPsi.ref(); auto Yslicer = this->Yslicer(); forAll(psi, celli) { auto composition = this->cellComposition(Yslicer, celli); psi[celli] = (this->*mixtureMethod)(composition, args ...); } volScalarField::BoundaryField& psiBf = psi.boundaryFieldRef(); forAll(psiBf, patchi) { forAll(psiBf[patchi], patchFacei) { auto composition = this->patchFaceComposition(Yslicer, patchi, patchFacei); psiBf[patchi][patchFacei] = (this->*mixtureMethod) ( composition, args.boundaryField()[patchi][patchFacei] ... ); } } return tPsi; } template template Foam::tmp Foam::BasicThermo::volInternalScalarFieldProperty ( const word& psiName, const dimensionSet& psiDim, Mixture mixture, Method psiMethod, const Args& ... args ) const { tmp tPsi ( volInternalScalarField::New ( IOobject::groupName(psiName, this->group()), this->mesh(), psiDim ) ); volInternalScalarField& psi = tPsi.ref(); auto Yslicer = this->Yslicer(); forAll(psi, celli) { auto composition = this->cellComposition(Yslicer, celli); psi[celli] = ((this->*mixture)(composition).*psiMethod)(args[celli] ...); } return tPsi; } template template Foam::tmp Foam::BasicThermo::cellSetProperty ( Mixture mixture, Method psiMethod, const labelList& cells, const Args& ... args ) const { // Note: Args are fields for the set, not for the mesh as a whole. The // cells list is only used to get the mixture. tmp tPsi(new scalarField(cells.size())); scalarField& psi = tPsi.ref(); auto Yslicer = this->Yslicer(); forAll(cells, i) { auto composition = this->cellComposition(Yslicer, cells[i]); psi[i] = ((this->*mixture)(composition).*psiMethod)(args[i] ...); } return tPsi; } template template Foam::tmp Foam::BasicThermo::patchFieldProperty ( Mixture mixture, Method psiMethod, const label patchi, const Args& ... args ) const { tmp tPsi ( new scalarField(this->T_.boundaryField()[patchi].size()) ); scalarField& psi = tPsi.ref(); auto Yslicer = this->Yslicer(); forAll(psi, patchFacei) { auto composition = this->patchFaceComposition(Yslicer, patchi, patchFacei); psi[patchFacei] = ((this->*mixture)(composition).*psiMethod)(args[patchFacei] ...); } return tPsi; } template template Foam::tmp Foam::BasicThermo::fieldSourceProperty ( const word& psiName, const dimensionSet& psiDim, Mixture mixture, Method psiMethod, const fvSource& model, const volInternalScalarField& source, const Args& ... args ) const { tmp tPsi ( volInternalScalarField::New ( IOobject::groupName(psiName, this->group()), this->mesh(), psiDim ) ); volInternalScalarField& psi = tPsi.ref(); auto Yslicer = this->Yslicer(model, source); forAll(psi, celli) { auto composition = this->sourceCellComposition(Yslicer, celli); psi[celli] = ((this->*mixture)(composition).*psiMethod)(args[celli] ...); } return tPsi; } template template Foam::tmp Foam::BasicThermo::fieldSourceProperty ( Mixture mixture, Method psiMethod, const fvSource& model, const scalarField& source, const labelUList& cells, const Args& ... args ) const { tmp tPsi(new scalarField(cells.size())); scalarField& psi = tPsi.ref(); auto Yslicer = this->Yslicer(model, source, cells); forAll(cells, i) { auto composition = this->sourceCellComposition(Yslicer, i); psi[i] = ((this->*mixture)(composition).*psiMethod)(args[i] ...); } return tPsi; } template Foam::UIndirectList Foam::BasicThermo::cellSetScalarList ( const volScalarField& psi, const labelUList& cells ) { return UIndirectList(psi, cells); } template Foam::UniformField Foam::BasicThermo::cellSetScalarList ( const uniformGeometricScalarField& psi, const labelUList& ) { return psi.primitiveField(); } template void Foam::BasicThermo::heBoundaryCorrection ( volScalarField& h ) { volScalarField::BoundaryField& hBf = h.boundaryFieldRef(); forAll(hBf, patchi) { if (isA(hBf[patchi])) { refCast(hBf[patchi]).gradient() = hBf[patchi].fvPatchField::snGrad(); } else if (isA(hBf[patchi])) { refCast(hBf[patchi]).refGrad() = hBf[patchi].fvPatchField::snGrad(); } } } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::BasicThermo::BasicThermo ( const fvMesh& mesh, const word& phaseName ) : physicalProperties(mesh, phaseName), MixtureType(properties()), BasicThermoType ( properties(), static_cast(*this), mesh, phaseName ), he_ ( IOobject ( BasicThermoType::phasePropertyName ( MixtureType::thermoType::heName(), phaseName ), mesh.time().name(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), volScalarFieldProperty ( "he", dimensions::specificEnergy, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::he, this->p_, this->T_ ), this->heBoundaryTypes(), this->heBoundaryBaseTypes(), this->heSourcesTypes(), this->T_.sources().errorLocation() ), Cp_ ( IOobject ( BasicThermoType::phasePropertyName("Cp", phaseName), mesh.time().name(), mesh ), mesh, dimensionedScalar(dimensions::specificHeatCapacity, Zero) ), Cv_ ( IOobject ( BasicThermoType::phasePropertyName("Cv", phaseName), mesh.time().name(), mesh ), mesh, dimensionedScalar(dimensions::specificHeatCapacity, Zero) ) { heBoundaryCorrection(he_); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template Foam::BasicThermo::~BasicThermo() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template Foam::tmp Foam::BasicThermo::W() const { return volScalarFieldProperty ( "W", dimensions::mass/dimensions::moles, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::W ); } template Foam::tmp Foam::BasicThermo::W ( const label patchi ) const { return patchFieldProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::W, patchi ); } template const Foam::volScalarField& Foam::BasicThermo::Cpv() const { if (MixtureType::thermoType::enthalpy()) { return Cp_; } else { return Cv_; } } template Foam::tmp Foam::BasicThermo::he ( const volScalarField& p, const volScalarField& T ) const { return volScalarFieldProperty ( "he", dimensions::specificEnergy, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::he, p, T ); } template Foam::tmp Foam::BasicThermo::he ( const volInternalScalarField& p, const volInternalScalarField& T ) const { return volInternalScalarFieldProperty ( "he", dimensions::specificEnergy, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::he, p, T ); } template Foam::tmp Foam::BasicThermo::he ( const scalarField& T, const labelList& cells ) const { return cellSetProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::he, cells, cellSetScalarList(this->p_, cells), T ); } template Foam::tmp Foam::BasicThermo::he ( const scalarField& T, const label patchi ) const { return patchFieldProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::he, patchi, this->p_.boundaryField()[patchi], T ); } template Foam::tmp Foam::BasicThermo::he ( const volInternalScalarField& T, const fvSource& model, const volInternalScalarField& source ) const { return fieldSourceProperty ( "he", dimensions::specificEnergy, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::he, model, source, this->p_.internalField(), T ); } template Foam::tmp Foam::BasicThermo::he ( const scalarField& T, const fvSource& model, const scalarField& source, const labelUList& cells ) const { return fieldSourceProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::he, model, source, cells, cellSetScalarList(this->p_, cells), T ); } template Foam::tmp Foam::BasicThermo::hs() const { return volScalarFieldProperty ( "hs", dimensions::specificEnergy, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::hs, this->p_, this->T_ ); } template Foam::tmp Foam::BasicThermo::hs ( const volScalarField& p, const volScalarField& T ) const { return volScalarFieldProperty ( "hs", dimensions::specificEnergy, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::hs, p, T ); } template Foam::tmp Foam::BasicThermo::hs ( const volInternalScalarField& p, const volInternalScalarField& T ) const { return volInternalScalarFieldProperty ( "hs", dimensions::specificEnergy, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::hs, p, T ); } template Foam::tmp Foam::BasicThermo::hs ( const scalarField& T, const labelList& cells ) const { return cellSetProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::hs, cells, cellSetScalarList(this->p_, cells), T ); } template Foam::tmp Foam::BasicThermo::hs ( const scalarField& T, const label patchi ) const { return patchFieldProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::hs, patchi, this->p_.boundaryField()[patchi], T ); } template Foam::tmp Foam::BasicThermo::ha() const { return volScalarFieldProperty ( "ha", dimensions::specificEnergy, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::ha, this->p_, this->T_ ); } template Foam::tmp Foam::BasicThermo::ha ( const volScalarField& p, const volScalarField& T ) const { return volScalarFieldProperty ( "ha", dimensions::specificEnergy, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::ha, p, T ); } template Foam::tmp Foam::BasicThermo::ha ( const volInternalScalarField& p, const volInternalScalarField& T ) const { return volInternalScalarFieldProperty ( "ha", dimensions::specificEnergy, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::ha, p, T ); } template Foam::tmp Foam::BasicThermo::ha ( const scalarField& T, const labelList& cells ) const { return cellSetProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::ha, cells, cellSetScalarList(this->p_, cells), T ); } template Foam::tmp Foam::BasicThermo::ha ( const scalarField& T, const label patchi ) const { return patchFieldProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::ha, patchi, this->p_.boundaryField()[patchi], T ); } template Foam::tmp Foam::BasicThermo::Cp ( const scalarField& T, const label patchi ) const { return patchFieldProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::Cp, patchi, this->p_.boundaryField()[patchi], T ); } template Foam::tmp Foam::BasicThermo::Cv ( const scalarField& T, const label patchi ) const { return patchFieldProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::Cv, patchi, this->p_.boundaryField()[patchi], T ); } template Foam::tmp Foam::BasicThermo::Cpv ( const scalarField& T, const label patchi ) const { if (MixtureType::thermoType::enthalpy()) { return Cp(T, patchi); } else { return Cv(T, patchi); } } template Foam::tmp Foam::BasicThermo::The ( const volScalarField& h, const volScalarField& p, const volScalarField& T0 ) const { return volScalarFieldProperty ( "T", dimensions::temperature, &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::The, h, p, T0 ); } template Foam::tmp Foam::BasicThermo::The ( const scalarField& h, const scalarField& T0, const labelList& cells ) const { return cellSetProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::The, cells, h, cellSetScalarList(this->p_, cells), T0 ); } template Foam::tmp Foam::BasicThermo::The ( const scalarField& h, const scalarField& T0, const label patchi ) const { return patchFieldProperty ( &MixtureType::thermoMixture, &MixtureType::thermoMixtureType::The, patchi, h, this->p_.boundaryField()[patchi], T0 ); } template bool Foam::BasicThermo::read() { if (physicalProperties::read()) { MixtureType::read(*this); BasicThermoType::read(*this); return true; } else { return false; } } // ************************************************************************* //