implementation of a mass flux term with thermodiffusion

27
Implementaon of a mass flux term with thermodiffusion mass transport into the species transport equaon for a compressible solver CFD with Open-Source Soſtware Course Chalmers University of Technology Jose Lorenzo A. Barba University of Leeds 27-28, November, 2019

Upload: others

Post on 28-Feb-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Implementation of a mass flux term with thermodiffusion

Implementation of a mass flux term with thermodiffusion mass transport into the species transport equation for a

compressible solver

CFD with Open-Source Software CourseChalmers University of Technology

Jose Lorenzo A. BarbaUniversity of Leeds

27-28, November, 2019

Page 2: Implementation of a mass flux term with thermodiffusion

2

Thermodiffusion in binary gas mixtures

● Thermodiffusion effect in fluid mixtures: Concentration gradients caused by temperature gradients.

● Mass flux equation:

● In steady state, Ja = 0:

– DT: Thermodiffusion transport coefficient [m2/(kg*K)].

– Dab: Mass diffusivity [m2/kg].

– Ca: Mass fraction of the reference component ‘a’.

– Ca0: Initial value of the component ‘a’ mass fraction.

– T: Temperature [K]

Page 3: Implementation of a mass flux term with thermodiffusion

3

Thermodiffusion in binary gas mixtures

● The mass diffusivity and thermodiffusion coefficient are related by the thermodiffusion ratio:

● The mass flux expression can be rewritten as,

● A transport model that calculates these transport coefficients can be implemented in OpenFOAM trhough the thermophysicalModels library.

Page 4: Implementation of a mass flux term with thermodiffusion

4

The thermophysicalModels library

● The OpenFOAM library that couples:– Specie and mixture models.

– Thermodynamic modelling

– Transport modelling

– Equation of state modelling

Page 5: Implementation of a mass flux term with thermodiffusion

5

The thermophysicalModels library

● Main layer: Where the thermophysical model is defined (e.g. density based model rhoThermo or compressibility model psiThermo). It is constructed with the thermophysical sub-models (mixture, transport, thermo, etc.).

● Second layer: Where the entries of each sub-model are set. The specie, thermo and transport models are contained in the mixture model as entries (with own entries for each sub-model).

Page 6: Implementation of a mass flux term with thermodiffusion

6

Specie and basic libraries

● The specie library contains transport, equation of state and thermodynamic models.

● We can create a new transport model by setting a specie and a basic user libraries.

● Copy the following lines for a user’s specie library:

mkdir -p $WM_PROJECT_USER_DIR/src/thermophysicalModelscd $WM_PROJECT_USER_DIR/src/thermophysicalModelscp -r $FOAM_SRC/thermophysicalModels/specie .sed -i s/"FOAM_LIBBIN"/"FOAM_USER_LIBBIN"/g specie/Make/fileswclean lib specie/wmake libso specie/

Page 7: Implementation of a mass flux term with thermodiffusion

7

cp -r $FOAM_SRC/thermophysicalModels/basic $WM_PROJECT_USER_DIR/src/thermophysicalModels sed -i s/"FOAM_LIBBIN"/"FOAM_USER_LIBBIN"/g basic/Make/files

● Then, open the options file with a text editor and make sure it looks like this: -------------------------------------------------------------------------------------------------------------------------

EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(WM_PROJECT_USER_DIR)/src/thermophysicalModels/specie/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/thermophysicalProperties/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/transportModels/compressible/lnInclude LIB_LIBS = \ -L$(FOAM_USER_LIBBIN) \ -lfiniteVolume \ -lmeshTools \ -lcompressibleTransportModels \ -lspecie \ -lthermophysicalProperties------------------------------------------------------------------------------------------------------------------------

● Finally, compile the new library with the next two commands:wclean lib ./basicwmake libso ./basic

● Copy the following lines to get a user’s basic library:

Page 8: Implementation of a mass flux term with thermodiffusion

8

thermoDiffconstTransport transport model

● The new transport model will be based on the current constTransport model which calculates the thermal conductivity and the thermal diffusivity with two constant entries, the dynamic viscosity and the Prandtl number.

● Copy the following lines in the therminal window to create a new folder for the thermodiffusion transport model, and then move to the include directory located in the specie main folder:

cd $WM_PROJECT_USER_DIR/src/thermophysicalModels/specie/transportcp -r const thermoDiffconstcd thermoDiffconst mv constTransport.C thermoDiffconstTransport.Cmv constTransport.H thermoDiffconstTransport.Hmv constTransportI.H thermoDiffconstTransportI.Hsed -i s/constTransport/thermoDiffconstTransport/g thermoDiffconstTransport*cd ../../include

Page 9: Implementation of a mass flux term with thermodiffusion

9

● At the include folder, open the file thermoPhysicsTypes.H to add the new transport model to the thermoType sets:

--------------------------------------------------------------------//line 51 #include "sutherlandTransport.H" #include "constTransport.H" #include "thermoDiffconstTransport.H" //thermodiffusion transport model header file.

#include "icoPolynomial.H" #include "hPolynomialThermo.H"

Page 10: Implementation of a mass flux term with thermodiffusion

10

● Inside the namespace foam add two typedef declarations (one for thermo physics types based on sensibleEnthalpy and the other for thermophysics types based on internalEnergy

--------------------------------------------------------------------------------------// line 67

// thermo physics types based on sensibleEnthalpy typedef thermoDiffconstTransport //new transport model < species::thermo < hConstThermo < perfectGas<specie> >, sensibleEnthalpy > > thermoDiffconstGasHThermoPhysics;/* * * * * * * * * * * * * * * * * * */

// line 192 // thermo physics types based on sensibleInternalEnergy typedef thermoDiffconstTransport //new transport model < species::thermo < eConstThermo < perfectGas<specie> //thermoDiffperfectGas<specie> >, sensibleInternalEnergy > > thermoDiffconstGasEThermoPhysics; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Page 11: Implementation of a mass flux term with thermodiffusion

11

● Return to the folder specie/transport/thermoDiffconst

cd ../transport/thermoDiffconst

● Open the file thermoDiffconstTransport.H and add the following lines at the indicated line number:

--------------------------------------------------------------------

//- Mass diffusivity [m^2/s] // line 95 scalar Dab_; //- Thermodiffusion ratio [] scalar KT_;… …. …. const scalar Pr, // Add a comma here. const scalar Dab, // line 109 const scalar KT… …. …. // Mass diffusivity [m^2/s] // line 148 inline scalar Dab(const scalar p, const scalar T) const;

// free space // Thermodiffusion coefficient [m^2/K.s] inline scalar DT(const scalar p, const scalar T) const;

Page 12: Implementation of a mass flux term with thermodiffusion

12

● Now, open the file thermoDiffconstTransportI.H where the inline functions are defined, add the following lines at the indicated line number.

-------------------------------------------------------------------------------------

const scalar Pr, // Add a comma here.const scalar Dab, // Line 37 const scalar KT… … …rPr_(1.0/Pr), // Add a comma here.Dab_(Dab), // Line 44KT_(KT)… … … rPr_(ct.rPr_), // Add a comma here. Dab_(ct.Dab_), // Line 59 KT_(ct.KT_)… … …

template<class Thermo> // Line 118inline Foam::scalar Foam::thermoDiffconstTransport<Thermo>::Dab( const scalar p, const scalar T) const{ return Dab_;}

//free space //free spacetemplate<class Thermo>inline Foam::scalar Foam::thermoDiffconstTransport<Thermo>::DT( const scalar p, const scalar T) const{ return (Dab(p, T)*KT_)/T;}

Page 13: Implementation of a mass flux term with thermodiffusion

13

● Continuation…

Dab_ = ct.Dab_; // Line 152.KT_ = ct.KT_;… … …Dab_ = Y1*Dab_ + Y2*st.Dab_; // Line 174.KT_ = Y1*KT_ + Y2*st.KT_;… … …ct1.rPr_, // Add a comma here.ct1.Dab_, // Line 211.ct1.KT_… … …1.0/(Y1/ct1.rPr_ + Y2/ct2.rPr_), // Add a comma here.Y1*ct1.Dab_ + Y2*ct2.Dab_, // Line 224.Y1*ct1.KT_ + Y2*ct2.KT_… … … 1.0/ct.rPr_, // Add a comma here.ct.Dab_, // Line 243.ct.KT_

Page 14: Implementation of a mass flux term with thermodiffusion

14

● Finally, open the file thermoDiffconstTransport.C and add the following lines at the indicated line number:

● Return to the thermophysicalModels folder and recompile the specie library,

cd ../../../../thermophysicalModels

wclean lib specie

wmake libso specie

rPr_(1.0/dict.subDict("transport").get<scalar>("Pr")), // Add a comma hereDab_(dict.subDict("transport").get<scalar>("Dab")), // Line 39KT_(dict.subDict("transport").get<scalar>("KT"))… … …os.writeEntry("Dab", Dab_); // Line 59os.writeEntry("KT", KT_);

Page 15: Implementation of a mass flux term with thermodiffusion

15

thermoDiffrhoThermo thermophysical model● In order to execute the defined functions in the thermoDiffconstTransport

model, it is necessary to create a new thermophysical model that contains the new transport coefficients as data and member functions. Copy the next lines to create a new thermophysical model based in the current rhoThermo model:

cd $WM_PROJECT_USER_DIR/src/thermophysicalModels/basic/cp -r rhoThermo thermoDiffrhoThermocd thermoDiffrhoThermorm liquidThermo*mv rhoThermo.H thermoDiffrhoThermo.Hmv rhoThermo.C thermoDiffrhoThermo.Cmv rhoThermos.C thermoDiffrhoThermos.Cmv heRhoThermo.H thermoDiffheRhoThermo.Hmv heRhoThermo.C thermoDiffheRhoThermo.Csed -i s/rhoThermo/thermoDiffrhoThermo/g thermoDiffrhoThermo*sed -i s/rhoThermo/thermoDiffrhoThermo/g thermoDiffheRhoThermo*sed -i s/heRhoThermo/thermoDiffheRhoThermo/g thermoDiffheRhoThermo*sed -i s/heRhoThermo/thermoDiffheRhoThermo/g thermoDiffrhoThermos.C

Page 16: Implementation of a mass flux term with thermodiffusion

16

● Notice that we removed the liquidThermo.H and liquidThermo.C files, as they are not necessary for the implementation (It’s a code for a liquid properties selector which we don’t need now).

● Open the file thermoDiffrhoThermo.H file to add the following lines:

//- Mass diffusivity [m^2/s] // Line 75.volScalarField Dab_; // free space.//- Thermodiffusion coefficient [m^2/s*K]volScalarField DT_;… …. …//- Mass diffusivity [m^2/s] // Line 202.virtual tmp<volScalarField> Dab() const; // free space.//- Mass diffusivity for patch [m^2/s] virtual tmp<scalarField> Dab(const label patchi) const; // free space.//- Thermodiffusion coefficient [m^2/s*K]virtual tmp<volScalarField> DT() const;

// free space.//- Thermodiffusion coefficient for patch [m^2/s*K] virtual tmp<scalarField> DT(const label patchi) const;

Page 17: Implementation of a mass flux term with thermodiffusion

17

● Open the thermoDiffrhoThermo.C file where the Dab_ and DT_ objects are constructed, notice that these lines have to be added 3 times, add the member functions for each transpor coefficient.

------------------------------------------------------------------------------------- ), // Make sure that each previous Object has a comma

Dab_ // Add in lines 88, 169 and 250 IOobject ( phasePropertyName("thermo:Dab"), mesh.time().timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionSet(0, 2, -1, 0, 0) ), //free space DT_ ( IOobject ( phasePropertyName("thermo:DT"), mesh.time().timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionSet(0, 2, -1, -1, 0) )

Foam::tmp<Foam::volScalarField> Foam::thermoDiffrhoThermo::Dab() const // Line 361{ return Dab_;}

//free space//free space

Foam::tmp<Foam::scalarField> Foam::thermoDiffrhoThermo::Dab(const label patchi) const{ return Dab_.boundaryField()[patchi];}

//free space//free space

Foam::tmp<Foam::volScalarField> Foam::thermoDiffrhoThermo::DT() const{ return DT_;}

//free space//free space

Foam::tmp<Foam::scalarField> Foam::thermoDiffrhoThermo::DT(const label patchi) const{ return DT_.boundaryField()[patchi];}

Page 18: Implementation of a mass flux term with thermodiffusion

18

● Continue with the thermoDiffheRhoThermo.H file,

● And then with the thermoDiffheRhoThermo.C

volScalarField& Dab, // Line 70.volScalarField& DT

volScalarField& Dab, // Line 43.volScalarField& DT,… ... …Dab.oldTime(), // Line 61.DT.oldTime(),… … …scalarField& DabCells = Dab.primitiveFieldRef();// Line 75.scalarField& DTCells = DT.primitiveFieldRef();… … …DabCells[celli] = mixture_.Dab(pCells[celli], Tcells[celli]); // Line 98.DTCells[celli] = mixture_.DT(pCells[celli], Tcells[celli]);… … …volScalarField::Boundary& DabBf = Dab.boundaryFieldRef(); // Line 109.volScalarField::Boundary& DTBf = DT.boundaryFieldRef();… … …fvPatchScalarField& pDab = DabBf[patchi]; // Line 121.fvPatchScalarField& pDT = DTBf[patchi];… … …pDab[facei] = mixture_.Dab(pp[facei], pT[facei]); // Line 137.pDT[facei] = mixture_.DT(pp[facei], pT[facei]);

pDab[facei] = mixture_.Dab(pp[facei], pT[facei]); // Line 158.pDT[facei] = mixture_.DT(pp[facei], pT[facei]);… … … this->Dab_, // Add at lines 184, 210, 240 (3 times) this->DT_,

Page 19: Implementation of a mass flux term with thermodiffusion

19

● Finally, we can procede with the last file thermoDiffrhoThermos.C where the new thermophysical model is constructed. Add the header files of the new transport and the thermophysical models and add just 2 makeThermos definitions inside the Foam namespace.

//All the unnecessary header files are commented. Line#include "thermoDiffrhoThermo.H"#include "makeThermo.H"

#include "specie.H"#include "perfectGas.H"//#include "incompressiblePerfectGas.H"//#include "Boussinesq.H"//#include "rhoConst.H"//#include "perfectFluid.H"//#include "PengRobinsonGas.H"//#include "adiabaticPerfectFluid.H"

#include "hConstThermo.H"#include "eConstThermo.H"//#include "janafThermo.H"#include "sensibleEnthalpy.H"#include "sensibleInternalEnergy.H"#include "thermo.H"

//#include "constTransport.H"#include "thermoDiffconstTransport.H" // New transport model//#include "sutherlandTransport.H"//#include "WLFTransport.H"

//#include "icoPolynomial.H"//#include "hPolynomialThermo.H"//#include "polynomialTransport.H"

//#include "heRhoThermo.H"#include "thermoDiffheRhoThermo.H" // New thermophysical model#include "pureMixture.H"

namespace Foam{

/* * * * * * * * * * * * * * * private static data * * * * * * * * * * * * * */

makeThermos( thermoDiffrhoThermo, // New thermophysical model thermoDiffheRhoThermo, pureMixture, thermoDiffconstTransport, // New transport model sensibleEnthalpy, hconstThermo, //constant enthalpy model perfectGas, specie);

makeThermos( thermoDiffrhoThermo, // New thermophysical model thermoDiffheRhoThermo, pureMixture, thermoDiffconstTransport, // New transport model sensibleInternalEnergy, econstThermo, //constant internal energy mode perfectGas, specie);} // End namespace Foam. Comment or erase all the following lines

Page 20: Implementation of a mass flux term with thermodiffusion

20

● Go back to the basic library folder and open the files file contained in the Make folder (cd ../Make), make sure to add the following lines after the rhoThermo/liquidThermo.C line

thermoDiffrhoThermo/thermoDiffrhoThermo.C

thermoDiffrhoThermo/thermoDiffrhoThermos.C

● Return to the thermophysicalModels folder and reecompile the new basic library :

cd ../../../thermophysicalModels/

wclean lib ./basic

wmake libso ./basic

Page 21: Implementation of a mass flux term with thermodiffusion

21

Testing the new thermophysical model

● Now create a solver to test the new implementations in the thermophysicalModels library.

mkdir -p $WM_PROJECT_USER DIR/applications/solvers/compressible/thermoDiffRhoSimpleFoamcd $FOAM SOLVERS/compressible/rhoSimpleFoamcp -r . $WM_PROJECT_USER_DIR/applications/solvers/compressible/thermoDiffRhoSimpleFoamcd $WM_PROJECT_USER_DIR/applications/solvers/compressible/thermoDiffRhoSimpleFoammv rhoSimpleFoam.C thermoDiffRhoSimpleFoam.Csed -i s/"rhoSimpleFoam"/"thermoDiffRhoSimpleFoam"/g thermoDiffRhoSimpleFoam.Csed -i s/"rhoSimpleFoam"/"thermoDiffRhoSimpleFoam"/g Make/fileswcleanwmake

Page 22: Implementation of a mass flux term with thermodiffusion

22

● Create a file called CaEqn.H and add the next lines

//Species transport equation in terms of the reference component 'Ca' mass fraction.fvScalarMatrix CaEqn( fvm::ddt(rho, Ca) + fvm::div(phi, Ca) - fvm::laplacian(thermo.Dab()*rho, Ca));

solve(CaEqn == fvc::laplacian(thermo.DT()*Ca0*(1-Ca0)*rho, thermo.T()));CaEqn.relax();

Page 23: Implementation of a mass flux term with thermodiffusion

23

● Open the createFields.H file and add the following lines

//After U field definition//Reference component mass fraction volScalarField Ca( IOobject ( "Ca", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE ), mesh);//Second component mass fractionvolScalarField Cb( IOobject ( "Cb", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE ), 1-Ca);

// At the end of the file before the include lines shown below.IOdictionary initialMassFraction( IOobject ( "initialMassFraction", runTime.constant(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE ));

Info<< "Reading initial mass fraction of component 'a'\n" << endl; dimensionedScalar Ca0( "Ca0", dimensionSet(0, 0, 0, 0, 0, 0 ,0), initialMassFraction);

#include "createMRF.H"#include "createFvOptions.H"

Page 24: Implementation of a mass flux term with thermodiffusion

24

● Open the file thermoDiffrhoSimpleFoam.C and add the next lines after the turbulence correction and before the runtime end loop

… … ...turbulence->correct();

U.correctBoundaryConditions(); thermo.T().correctBoundaryConditions(); p.correctBoundaryConditions(); thermo.correct(); #include "CaEqn.H" Cb = 1 - Ca;

Ca.correctBoundaryConditions(); runTime.write();

runTime.printExecutionTime(Info); } … … ...

Page 25: Implementation of a mass flux term with thermodiffusion

25

● Make sure that the options file contains the next lines

EXE_INC = \ -I$(LIB_SRC)/finiteVolume/cfdTools \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \ -I$(LIB_SRC)/transportModels/compressible/lnInclude \ -I$(WM_PROJECT_USER_DIR)/src/thermophysicalModels/basic/lnInclude \ -I$(WM_PROJECT_USER_DIR)/src/thermophysicalModels/specie/lnInclude \ -I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \ -I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude \

EXE_LIBS = \ -L$(FOAM_USER_LIBBIN) \ -lfiniteVolume \ -lfvOptions \ -lmeshTools \ -lsampling \ -lcompressibleTransportModels \ -lturbulenceModels \ -lcompressibleTurbulenceModels \ -latmosphericModels

Page 26: Implementation of a mass flux term with thermodiffusion

26

● Recompile the solver and

cd $WM_PROJECT_USER_DIR/applications/solvers/compressible/thermoDiffRhoSimpleFoam

wclean

wmake

● Test the solver with the provided test case contained in (projectFiles.tgz, save it in your home directory)

cd ~

tar zxvf projectFiles.tgz

run

cp -r ~/projectFiles/thermoDiffusionCell .

cd thermoDiffusionCell

blockMesh

thermoDiffusionSimpleFoam >& log&

Page 27: Implementation of a mass flux term with thermodiffusion

27

● After running the case, open paraview and select the Ca field at the last

timestep. It should look like the following picture: