diff --git a/etc/caseDicts/functions/fields/specieAdvectiveFlux b/etc/caseDicts/functions/fields/specieAdvectiveFlux new file mode 100644 index 0000000000..47b0908a94 --- /dev/null +++ b/etc/caseDicts/functions/fields/specieAdvectiveFlux @@ -0,0 +1,22 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Calculate the specie-flux and write it as a surfaceScalarField + 'specieAdvectiveFlux()'. + +\*---------------------------------------------------------------------------*/ + +type specieAdvectiveFlux; +libs ("libfieldFunctionObjects.so"); + +field ; + +executeControl writeTime; +writeControl writeTime; + +// ************************************************************************* // diff --git a/etc/caseDicts/functions/fields/specieDiffusiveFlux b/etc/caseDicts/functions/fields/specieDiffusiveFlux new file mode 100644 index 0000000000..3603e406e4 --- /dev/null +++ b/etc/caseDicts/functions/fields/specieDiffusiveFlux @@ -0,0 +1,22 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Calculate the specie-flux and write it as a surfaceScalarField + 'specieDiffusiveFlux()'. + +\*---------------------------------------------------------------------------*/ + +type specieDiffusiveFlux; +libs ("libfieldFunctionObjects.so"); + +field ; + +executeControl writeTime; +writeControl writeTime; + +// ************************************************************************* // diff --git a/etc/caseDicts/functions/fields/specieFlux b/etc/caseDicts/functions/fields/specieFlux new file mode 100644 index 0000000000..e853c983da --- /dev/null +++ b/etc/caseDicts/functions/fields/specieFlux @@ -0,0 +1,22 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Calculate the specie-flux and write it as a surfaceScalarField + 'specieFlux()'. + +\*---------------------------------------------------------------------------*/ + +type specieFlux; +libs ("libfieldFunctionObjects.so"); + +field ; + +executeControl writeTime; +writeControl writeTime; + +// ************************************************************************* // diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index 0646343b49..804d1b48d7 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -54,6 +54,7 @@ yPlus/yPlus.C turbulenceIntensity/turbulenceIntensity.C wallShearStress/wallShearStress.C wallHeatFlux/wallHeatFlux.C +specieFlux/specieFlux.C wallHeatTransferCoeff/wallHeatTransferCoeff.C wallHeatTransferCoeff/wallHeatTransferCoeffModels/wallHeatTransferCoeffModel/wallHeatTransferCoeffModel.C diff --git a/src/functionObjects/field/Make/options b/src/functionObjects/field/Make/options index a400da0420..9a114f11f6 100644 --- a/src/functionObjects/field/Make/options +++ b/src/functionObjects/field/Make/options @@ -6,8 +6,10 @@ EXE_INC = \ -I$(LIB_SRC)/sampling/lnInclude \ -I$(LIB_SRC)/surfMesh/lnInclude \ -I$(LIB_SRC)/physicalProperties/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/solidThermo/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/multicomponentThermo/lnInclude \ -I$(LIB_SRC)/physicalProperties/lnInclude \ -I$(LIB_SRC)/MomentumTransportModels/momentumTransportModels/lnInclude \ -I$(LIB_SRC)/MomentumTransportModels/incompressible/lnInclude \ @@ -25,6 +27,8 @@ LIB_LIBS = \ -lincompressibleMomentumTransportModels \ -lcompressibleMomentumTransportModels \ -lfluidThermoThermophysicalTransportModels \ + -lmulticomponentThermophysicalModels \ + -lfluidThermophysicalTransportModel \ -lsolidThermophysicalTransportModels \ -lmeshTools \ -lsurfMesh \ diff --git a/src/functionObjects/field/specieFlux/specieFlux.C b/src/functionObjects/field/specieFlux/specieFlux.C new file mode 100644 index 0000000000..71b9e0ffe0 --- /dev/null +++ b/src/functionObjects/field/specieFlux/specieFlux.C @@ -0,0 +1,209 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2024 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 "specieFlux.H" +#include "fluidThermophysicalTransportModel.H" +#include "fvcFlux.H" +#include "multicomponentThermo.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(specieFlux, 0); + addToRunTimeSelectionTable(functionObject, specieFlux, dictionary); + + defineTypeNameAndDebug(specieAdvectiveFlux, 0); + addToRunTimeSelectionTable(functionObject, specieAdvectiveFlux, dictionary); + + defineTypeNameAndDebug(specieDiffusiveFlux, 0); + addToRunTimeSelectionTable(functionObject, specieDiffusiveFlux, dictionary); +} +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::functionObjects::specieFluxBase::calc() +{ + const word thermoName = + IOobject::groupName + ( + physicalProperties::typeName, + IOobject::group(fieldName_) + ); + + const word ttmName = + IOobject::groupName + ( + fluidThermophysicalTransportModel::typeName, + IOobject::group(fieldName_) + ); + + if + ( + !foundObject(thermoName) + || !foundObject(ttmName) + ) + { + return false; + } + + const multicomponentThermo& thermo = + lookupObject(thermoName); + + const fluidThermophysicalTransportModel& ttm = + lookupObject(ttmName); + + const volScalarField& Yi = thermo.Y(fieldName_); + + return store(resultName_, calc(ttm, Yi)); +} + + +Foam::tmp +Foam::functionObjects::specieFlux::calc +( + const fluidThermophysicalTransportModel& ttm, + const volScalarField& Yi +) +{ + return calcPhiYif(ttm, Yi) + calcJ(ttm, Yi); +} + + +Foam::tmp +Foam::functionObjects::specieAdvectiveFlux::calc +( + const fluidThermophysicalTransportModel& ttm, + const volScalarField& Yi +) +{ + return calcPhiYif(ttm, Yi); +} + + +Foam::tmp +Foam::functionObjects::specieDiffusiveFlux::calc +( + const fluidThermophysicalTransportModel& ttm, + const volScalarField& Yi +) +{ + return calcJ(ttm, Yi); +} + + +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // + +Foam::tmp +Foam::functionObjects::specieFluxBase::calcPhiYif +( + const fluidThermophysicalTransportModel& ttm, + const volScalarField& Yi +) const +{ + const surfaceScalarField& phi = ttm.momentumTransport().alphaRhoPhi(); + + return + fvc::flux + ( + phi, + Yi, + "div(" + phi.name() + "," + schemesField_ + ")" + )/Yi.mesh().magSf(); +} + + +Foam::tmp +Foam::functionObjects::specieFluxBase::calcJ +( + const fluidThermophysicalTransportModel& ttm, + + const volScalarField& Yi +) const +{ + return ttm.j(Yi); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::specieFluxBase::specieFluxBase +( + const word& name, + const Time& runTime, + const dictionary& dict, + const word& typeName +) +: + fieldExpression(name, runTime, dict, typeName), + schemesField_(dict.lookupOrDefault("schemesField", "Yi")) +{} + + +Foam::functionObjects::specieFlux::specieFlux +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + specieFluxBase(name, runTime, dict, typeName) +{} + + +Foam::functionObjects::specieAdvectiveFlux::specieAdvectiveFlux +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + specieFluxBase(name, runTime, dict, typeName) +{} + + +Foam::functionObjects::specieDiffusiveFlux::specieDiffusiveFlux +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + specieFluxBase(name, runTime, dict, typeName) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::specieFluxBase::~specieFluxBase() +{} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/specieFlux/specieFlux.H b/src/functionObjects/field/specieFlux/specieFlux.H new file mode 100644 index 0000000000..4dda4c01eb --- /dev/null +++ b/src/functionObjects/field/specieFlux/specieFlux.H @@ -0,0 +1,272 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2024 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::specieFlux + +Description + These functions calculate the specie-flux and write it as a + surfaceScalarField called 'specieFlux()'. There are + three such functions; specieAdvectiveFlux and specieDiffusiveFlux return + the advective and diffusive parts of the flux, respectively, and + specieFlux returns the total combined flux. + + Example of function object specification: + \verbatim + specieFlux + { + type specieFlux; // specieAdvectiveFlux, specieDiffusiveFlux + libs ("libfieldFunctionObjects.so"); + field NH3; + } + \endverbatim + + Or, using the standard configuration: + \verbatim + #includeFunc specieFlux(NH3) + \endverbatim + +Usage + \table + Property | Description | Required | Default value + type | Type name: specieFlux, \\ + specieAdvectiveFlux, or \\ + specieDiffusiveFlux | yes | + field | Name of the specie/mass \\ + fraction field | yes | + schemesField | Name of the field from \\ + which schemes are taken | no | Yi + region | Region to be evaluated | no | default region + \endtable + +SourceFiles + specieFlux.C + +\*---------------------------------------------------------------------------*/ + +#ifndef specieFlux_H +#define specieFlux_H + +#include "fieldExpression.H" +#include "volFieldsFwd.H" +#include "surfaceFieldsFwd.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class fluidThermophysicalTransportModel; + +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class specieFluxBase Declaration +\*---------------------------------------------------------------------------*/ + +class specieFluxBase +: + public fieldExpression +{ + // Protected Data + + //- Name of field from which schemes are taken + const word schemesField_; + + + // Private Member Functions + + //- Calculate the specie flux field and return true if successful + virtual bool calc(); + + //- Calculate the specie flux field + virtual tmp calc + ( + const fluidThermophysicalTransportModel& ttm, + const volScalarField& Yi + ) = 0; + + +protected: + + // Protected Member Functions + + //- Return the advective flux + tmp calcPhiYif + ( + const fluidThermophysicalTransportModel& ttm, + const volScalarField& Yi + ) const; + + //- Return the diffusive flux + tmp calcJ + ( + const fluidThermophysicalTransportModel& ttm, + const volScalarField& Yi + ) const; + +public: + + + // Constructors + + //- Construct from Time and dictionary + specieFluxBase + ( + const word& name, + const Time& runTime, + const dictionary& dict, + const word& typeName + ); + + + //- Destructor + virtual ~specieFluxBase(); +}; + + +/*---------------------------------------------------------------------------*\ + Class specieFlux Declaration +\*---------------------------------------------------------------------------*/ + +class specieFlux +: + public specieFluxBase +{ +private: + + // Private Member Functions + + //- Calculate the specie flux field + virtual tmp calc + ( + const fluidThermophysicalTransportModel& ttm, + const volScalarField& Yi + ); + + +public: + + //- Runtime type information + TypeName("specieFlux"); + + + // Constructors + + //- Construct from Time and dictionary + specieFlux + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); +}; + + +/*---------------------------------------------------------------------------*\ + Class specieAdvectiveFlux Declaration +\*---------------------------------------------------------------------------*/ + +class specieAdvectiveFlux +: + public specieFluxBase +{ +private: + + // Private Member Functions + + //- Calculate the specie flux field + virtual tmp calc + ( + const fluidThermophysicalTransportModel& ttm, + const volScalarField& Yi + ); + + +public: + + //- Runtime type information + TypeName("specieAdvectiveFlux"); + + + // Constructors + + //- Construct from Time and dictionary + specieAdvectiveFlux + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); +}; + + +/*---------------------------------------------------------------------------*\ + Class specieDiffusiveFlux Declaration +\*---------------------------------------------------------------------------*/ + +class specieDiffusiveFlux +: + public specieFluxBase +{ +private: + + // Private Member Functions + + //- Calculate the specie flux field + virtual tmp calc + ( + const fluidThermophysicalTransportModel& ttm, + const volScalarField& Yi + ); + + +public: + + //- Runtime type information + TypeName("specieDiffusiveFlux"); + + + // Constructors + + //- Construct from Time and dictionary + specieDiffusiveFlux + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/tutorials/multicomponentFluid/membrane/Allclean b/tutorials/multicomponentFluid/membrane/Allclean new file mode 100755 index 0000000000..f11ee62dbf --- /dev/null +++ b/tutorials/multicomponentFluid/membrane/Allclean @@ -0,0 +1,9 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +# Source tutorial clean functions +. $WM_PROJECT_DIR/bin/tools/CleanFunctions + +cleanCase && rm -rf 0/specieFlux* 0/uniform + +#------------------------------------------------------------------------------ diff --git a/tutorials/multicomponentFluid/membrane/system/functions b/tutorials/multicomponentFluid/membrane/system/functions new file mode 100644 index 0000000000..45724fc601 --- /dev/null +++ b/tutorials/multicomponentFluid/membrane/system/functions @@ -0,0 +1,41 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "system"; + object functions; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#includeFunc specieFlux(O2, schemesField=Yi_h, executeControl=timeStep) + +#includeFunc specieFlux(CH4, schemesField=Yi_h, executeControl=timeStep) + +#includeFunc specieFlux(N2, schemesField=Yi_h, executeControl=timeStep) + +#includeFunc patchIntegrate +( + name=membraneSleeveSpecieFluxes, + patch=membraneSleeve, + specieFlux(O2), + specieFlux(CH4), + specieFlux(N2) +) + +#includeFunc patchIntegrate +( + name=membranePipeSpecieFluxes, + patch=membranePipe, + specieFlux(O2), + specieFlux(CH4), + specieFlux(N2) +) + +// ************************************************************************* //