functionObjects::specieFlux: New functions to calculate specie fluxes

These functions calculate the specie-flux and write it as a
surfaceScalarField called 'specie<Type>Flux(<specieName>)'. 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:

    specieFlux
    {
        type    specieFlux; // specieAdvectiveFlux, specieDiffusiveFlux
        libs    ("libfieldFunctionObjects.so");
        field   NH3;
    }

Or, using the standard configuration:

    #includeFunc specieFlux(NH3)
This commit is contained in:
Will Bainbridge
2024-07-04 14:30:36 +01:00
parent 71dd72fef4
commit dab3104d4c
9 changed files with 602 additions and 0 deletions

View File

@ -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(<specieName>)'.
\*---------------------------------------------------------------------------*/
type specieAdvectiveFlux;
libs ("libfieldFunctionObjects.so");
field <specieName>;
executeControl writeTime;
writeControl writeTime;
// ************************************************************************* //

View File

@ -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(<specieName>)'.
\*---------------------------------------------------------------------------*/
type specieDiffusiveFlux;
libs ("libfieldFunctionObjects.so");
field <specieName>;
executeControl writeTime;
writeControl writeTime;
// ************************************************************************* //

View File

@ -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(<specieName>)'.
\*---------------------------------------------------------------------------*/
type specieFlux;
libs ("libfieldFunctionObjects.so");
field <specieName>;
executeControl writeTime;
writeControl writeTime;
// ************************************************************************* //

View File

@ -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

View File

@ -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 \

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#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<multicomponentThermo>(thermoName)
|| !foundObject<fluidThermophysicalTransportModel>(ttmName)
)
{
return false;
}
const multicomponentThermo& thermo =
lookupObject<multicomponentThermo>(thermoName);
const fluidThermophysicalTransportModel& ttm =
lookupObject<fluidThermophysicalTransportModel>(ttmName);
const volScalarField& Yi = thermo.Y(fieldName_);
return store(resultName_, calc(ttm, Yi));
}
Foam::tmp<Foam::surfaceScalarField>
Foam::functionObjects::specieFlux::calc
(
const fluidThermophysicalTransportModel& ttm,
const volScalarField& Yi
)
{
return calcPhiYif(ttm, Yi) + calcJ(ttm, Yi);
}
Foam::tmp<Foam::surfaceScalarField>
Foam::functionObjects::specieAdvectiveFlux::calc
(
const fluidThermophysicalTransportModel& ttm,
const volScalarField& Yi
)
{
return calcPhiYif(ttm, Yi);
}
Foam::tmp<Foam::surfaceScalarField>
Foam::functionObjects::specieDiffusiveFlux::calc
(
const fluidThermophysicalTransportModel& ttm,
const volScalarField& Yi
)
{
return calcJ(ttm, Yi);
}
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
Foam::tmp<Foam::surfaceScalarField>
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::surfaceScalarField>
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<word>("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()
{}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::specieFlux
Description
These functions calculate the specie-flux and write it as a
surfaceScalarField called 'specie<Type>Flux(<specieName>)'. 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<surfaceScalarField> calc
(
const fluidThermophysicalTransportModel& ttm,
const volScalarField& Yi
) = 0;
protected:
// Protected Member Functions
//- Return the advective flux
tmp<surfaceScalarField> calcPhiYif
(
const fluidThermophysicalTransportModel& ttm,
const volScalarField& Yi
) const;
//- Return the diffusive flux
tmp<surfaceScalarField> 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<surfaceScalarField> 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<surfaceScalarField> 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<surfaceScalarField> 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
// ************************************************************************* //

View File

@ -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
#------------------------------------------------------------------------------

View File

@ -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)
)
// ************************************************************************* //