CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [Other] Tabulated thermophysicalProperties library (https://www.cfd-online.com/Forums/openfoam-community-contributions/141821-tabulated-thermophysicalproperties-library.html)

chriss85 September 17, 2014 04:40

Tabulated thermophysicalProperties library
 
1 Attachment(s)
I've finally gotten around to cleaning up my code for using tabulated material properties so I can release it.

Keep in mind that it's still work in progress, so please tell me if you find any problems.

Currently there is support for:
  • Equation of state (rho(T,p))
  • Enthalpy (h(p,T))
  • Heat conductivity (kappa(T,p))
  • Viscosity (mu(T,p))
The properties will be linearly extrapolated outside the ranges of the provided tables.


The code is based on the compressibility based formulation hePsiThermo, so heRhoThermo based solvers may not be supported (or only partially, haven't tried).
Also multiphase flows are currently unsupported. If anyone wants to add them, go ahead! It basically comes down to implementing the operators in the classes properly I think.


If you use the tabulated enthalpy, it is suggested that you provide an inverted T(p,h) table and use heTabularThermo instead of hePsiThermo for much better performance.


An example thermophysicalProperties file may contain these entries:

Code:

thermoType
{
    type            heTabularThermo;
    mixture        pureMixture;
    transport      tabular;
    thermo          hTabular;
    equationOfState tabularEOS;
    specie          specie;
    energy          sensibleInternalEnergy;
}

The tables are placed in the constant directory, using these names:
  • densityTable
  • kappaTable
  • hTable
  • TTable
  • muTable
  • cpTable (if you use the enthalpy model in this library and don't use heTabularThermo model you will need the heat capacity. I strongly suggest using heTabularThermo instead.)
The code produces a libTabularThermophysicalModels library that can be included in solvers directly in code or (probably) through function objects (don't quote me on that, I don't use them).

A table file looks like this:
Code:

(
(temperature1 ((pressure1 value11)(pressure2 value12)...)
(temperature2 ((pressure1 value21)(pressure2 value22)...)
...
)

For hTable and TTable the temperatures and pressures are exchanged, so the rows of the table contain the pressure. This is neccessary because the inverted TTable is not an orthogonal grid of points anymore. Sorry for this inconsistency, feel free to modify it if this bothers you.

wyldckat March 21, 2015 14:21

Greetings Chris,

I've created a basic wiki page to help getting your library known to the community that uses OpenFOAM technology: http://openfoamwiki.net/index.php/Co...erties_library

May you or anyone else feel free to update that wiki page!

Best regards,
Bruno

chriss85 March 24, 2015 07:31

Thanks, that should help making it more visible.

chriss85 May 8, 2015 11:36

I have worked on some performance optimizations for this library (avoiding some unnecessary lookups and using an interpolation search instead of linear search for finding data in the tables), in a real solver I got about 20% more speed. I will post it after some cleanup.

chriss85 May 13, 2015 05:44

1 Attachment(s)
For some reason I find myself unable to edit the first post so I will post the files here.

I have tested both a binary search and an interpolation search with similar results. The binary search was commented out, feel free to use it if it works better for your use case.

PeterBishop June 29, 2015 07:45

Great work! Are there any instructions to compile this library? For which OpenFOAM version is developed?

Thanks

chriss85 June 29, 2015 08:03

You compile this like any other OpenFOAM library, "wmake libso" in the thermophysicalModels\basic directory (afaik). It should work with any recent version I think, I have developed it on 2.3.x. BTW, if you need different gas constant or c_v, I'm currently working on that. See here if you can check check if this is correct: http://www.cfd-online.com/Forums/ope...tml#post552547

wsmith02 July 25, 2015 15:20

1 Attachment(s)
Hi. I was starting to work on my own arbitrary function thermo properties class, but I was pointed this way. Thanks!

I downloaded the original zip that you posted. I think i had to change a few things to get it to work at all with a solve,. unfortunately, i probably dont remember them now. I think I at least added tabularThermo/tabularThermo.C to the Make/files. Anyway, I am attaching a zip with your tabularThermo class, buoyantSimpleFoam which I modified to use the class (now tableBuoyantSimpleFoam) and the constant dir that i created from the buoyant cavity case with made up properties, just to see how it worked.

I pretty much get a seg fault right off the bat when running the solver. Any idea why that might be? The log from the solver run is included.

Is there a good way to use your property functions with either of the buoyant solvers?

Thanks again for posting your work!

chriss85 July 27, 2015 05:40

You need to compile this library as it is, and then add the library to the solver which is supposed to use it under Make/options-> EXE_LIBS.

wsmith02 July 27, 2015 21:27

I am trying to test out the routine and since I am interested in using something like buoyantSimple/PimpleFoam I thought I would try to implement it there.

I really hope that I am not being awfully dense, I have some experience compiling functionObjects and custom solvers, but not thermo-properties.

I have written down exactly what I have done to modify buoyantPimpleFoam into tableBuoyantPimpleFoam and put it here (as chriss85 suggested, i have not modified the thermo stuff at all):

Code:

# Starting from $WM_PROJECT_USER_DIR
mkdir -p applications/solvers/heatTransfer
cd applications/solvers/heatTransfer
cp -R $FOAM_SOLVERS/heatTransfer/buoyantPimpleFoam .
mv buoyantPimpleFoam tableBuoyantPimpleFoam
cd tableBuoyantPimpleFoam
mv buoyantPimpleFoam.C tableBuoyantPimpleFoam.C
sed -i 's/buoyantPimpleFoam/tableBuoyantPimpleFoam/g' *.*
sed -i 's/buoyantPimpleFoam/tableBuoyantPimpleFoam/g' Make/*
sed -i 's/FOAM_APPBIN/FOAM_USER_APPBIN/g' Make/*
sed -i 's/rhoThermo/tabularThermo/g' *.*


################## Manual Edit ##################################
## Add to the end of EXE_INC
" \
    -I$(WM_PROJECT_USER_DIR)/src/thermophysicalModels/basic/lnInclude "

## Add to the end of EXE_LIBS
" \
    -L$(FOAM_USER_LIBBIN) \
    -lTabularThermophysicalModels "
################## /Manual Edit ##################################

the compilation errors that I am getting are something along the lines of :

Code:

pEqn.H: In function ‘int main(int, char**)’:
pEqn.H:6:25: error: no match for ‘operator-=’ in ‘Foam::tabularThermo::rho() -= Foam::operator*(const Foam::GeometricField<double, PatchField, GeoMesh>&, const Foam::GeometricField<double, PatchField, GeoMesh>&) [with PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]((*(const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>*)(& p_rgh)))’
pEqn.H:79:25: error: no match for ‘operator+=’ in ‘Foam::tabularThermo::rho() += Foam::operator*(const Foam::GeometricField<double, PatchField, GeoMesh>&, const Foam::GeometricField<double, PatchField, GeoMesh>&) [with PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]((*(const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>*)(& p_rgh)))’
/opt/openfoam230/src/finiteVolume/lnInclude/readTimeControls.H:38:8: warning: unused variable ‘maxDeltaT’ [-Wunused-variable]
make: *** [Make/linux64GccDPOpt/tableBuoyantPimpleFoam.o] Error 1

So it basically looks like it is complaining about operator "+=" and "-=" definitions that dont seem to exist. These are used in the solver so I thought they would be loaded as part of that compilation and would not be required as part of the thermo-properties.

I know that each thermo-property component (transport/thermo/eos) has its own
Code:

*I.H
file that defines specific operators such as this and yours is no different.

I am using vanilla OF230 (from dpkg) and made a clean $WM_PROJECT_USER_DIR just to test this out.

Any thoughts anyone has as to how i am being so dumb would be appreciated!

Thanks.

chriss85 July 28, 2015 03:59

The library I created is based on psiThermo, not rhoThermo. I think this may be the difference because in psiThermo rho is a function of p and T and may not be writeable as it is the case with rhoThermo. I suggest that you either change my library so that the tables are functions of rho and T, and calculate p from rho and compressibility and have rho be writeable, or use another solver which is based on psiThermo.

rkbagul November 3, 2015 04:11

Implementation problems
 
1 Attachment(s)
Dear All,

This is very interesting thread for me as I am trying to apply tabulated property variation for simulation of flows of supercritical fluids. So, I followed above information.

I could run "wmake libso" based on the files provided by "chriss85". The library "libTabularThermophysicalModels.so" was created in "$FOAM_USER_LIBBIN".

Then I copied the "buoyantSimpleFoam" solver to user area and renamed and modified it to new name "tabsimpleFoam". I modified the Make/options file as below:

Code:

EXE_INC = \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/fvOptions/lnInclude \
    -I$(LIB_SRC)/sampling/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
    -I$(WM_PROJECT_USER_DIR)/src/thermophysicalModels/basic/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/radiationModels/lnInclude \
    -I$(LIB_SRC)/turbulenceModels \
    -I$(LIB_SRC)/turbulenceModels/compressible/RAS/lnInclude \
    -I$(LIB_SRC)/turbulenceModels/RAS \
 

EXE_LIBS = \
    -L$(FOAM_USER_LIBBIN) \
    -lfiniteVolume \
    -lfvOptions \
    -lsampling \
    -lmeshTools \
    -lfluidThermophysicalModels \
    -lspecie \
    -lradiationModels \
    -lcompressibleTurbulenceModel \
    -lcompressibleRASModels \
    -lmeshTools \
    -lTabularThermophysicalModels \

The solver compiled successfully with following message

Code:

SOURCE=tabsimpleFoam.C ;  g++ -m32 -Dlinux -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam231/src/finiteVolume/lnInclude -I/opt/openfoam231/src/fvOptions/lnInclude -I/opt/openfoam231/src/sampling/lnInclude -I/opt/openfoam231/src/meshTools/lnInclude -I/opt/openfoam231/src/thermophysicalModels/basic/lnInclude -I/home/ritesh/OpenFOAM/ritesh-2.3.1/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam231/src/thermophysicalModels/radiationModels/lnInclude -I/opt/openfoam231/src/turbulenceModels -I/opt/openfoam231/src/turbulenceModels/compressible/RAS/lnInclude -I/opt/openfoam231/src/turbulenceModels/RAS  -IlnInclude -I. -I/opt/openfoam231/src/OpenFOAM/lnInclude -I/opt/openfoam231/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linuxGccDPOpt/tabsimpleFoam.o
g++ -m32 -Dlinux -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam231/src/finiteVolume/lnInclude -I/opt/openfoam231/src/fvOptions/lnInclude -I/opt/openfoam231/src/sampling/lnInclude -I/opt/openfoam231/src/meshTools/lnInclude -I/opt/openfoam231/src/thermophysicalModels/basic/lnInclude -I/home/ritesh/OpenFOAM/ritesh-2.3.1/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam231/src/thermophysicalModels/radiationModels/lnInclude -I/opt/openfoam231/src/turbulenceModels -I/opt/openfoam231/src/turbulenceModels/compressible/RAS/lnInclude -I/opt/openfoam231/src/turbulenceModels/RAS  -IlnInclude -I. -I/opt/openfoam231/src/OpenFOAM/lnInclude -I/opt/openfoam231/src/OSspecific/POSIX/lnInclude  -fPIC -Xlinker --add-needed -Xlinker --no-as-needed Make/linuxGccDPOpt/tabsimpleFoam.o -L/opt/openfoam231/platforms/linuxGccDPOpt/lib \
-L/home/ritesh/OpenFOAM/ritesh-2.3.1/platforms/linuxGccDPOpt/lib -lfiniteVolume -lfvOptions -lsampling -lmeshTools -lfluidThermophysicalModels -lspecie -lradiationModels -lcompressibleTurbulenceModel -lcompressibleRASModels -lmeshTools -lTabularThermophysicalModels  -lOpenFOAM -ldl  -lm -o /home/ritesh/OpenFOAM/ritesh-2.3.1/platforms/linuxGccDPOpt/bin/tabsimpleFoam

However, when I used the solver to run a test case, a simple pipe with all walls and fluid at same temperature, constant directory containing the tables describing the tabular properties......it returned following message:

Code:

Create time
Create mesh for time = 0

Reading g
Reading thermophysical properties

Selecting thermodynamics package
{
    type            heTabularThermo;
    mixture        pureMixture;
    transport      tabular;
    thermo          hTabular;
    equationOfState tabularEOS;
    specie          specie;
    energy          sensibleInternalEnergy;
}



--> FOAM FATAL ERROR:
Unknown rhoThermo type
thermoType
{
    type            heTabularThermo;
    mixture        pureMixture;
    transport      tabular;
    thermo          hTabular;
    equationOfState tabularEOS;
    specie          specie;
    energy          sensibleInternalEnergy;
}


Valid rhoThermo types are:

type        mixture                    transport  thermo      equationOfState          specie  energy                 

heRhoThermo  homogeneousMixture        const      hConst      incompressiblePerfectGas  specie  sensibleEnthalpy       
heRhoThermo  homogeneousMixture        const      hConst      perfectGas                specie  sensibleEnthalpy    ..etc....etc...

I am unable to make out why it did not recognise the new thermophysical model....

Attaching the solver files:

Please kindly help :confused:

chriss85 November 3, 2015 11:05

The code I published is currently only suited for the psiThermo model. For rhoThermo you will have to do the adjustments yourself I'm afraid. I would check for all files which mention psiThermo, look up some similar files in the original source and adapt them. If you know C++ this should be a possible task, unfortunately I cannot spend any time on this right now. There was a similar library released which might have used rhoThermo instead, maybe you can use that or use it as a template for the necessary changes.

Best of luck!

user_of_cfx November 10, 2015 04:51

chriss85 thank you for this amazing idea. I am surprised at the relatively limited options in the thermophysical properties tab (or maybe I just don't know how to implement an EoS other than that of perfect fluid).

Shockingly for me, I managed to compile the file properly, but I have some questions of another nature:

1. I just want to use a table to provide an EoS (rho[p,T]) and keep the rest as simple as possible. What would be a good set of parameters to use? Would for example the specifications below work well together?

Code:

thermoType
{
    type            heTabularThermo;
    mixture        pureMixture;
    transport      const;
    thermo          hConst;
    equationOfState tabularEOS;
    specie          specie;
    energy          sensibleInternalEnergy;
}

2. If the specification above is correct, then I suppose I only need to provide densityTable and that's it. Or will I also need cpTable?

I am going to try the good old trial and error to find an answer to my questions of course, but maybe a bit of a guide ("use this type with these tables etc") may be useful to other people as well as me, and save us all some time to do better things with your code :)


UPDATE

I seem to be getting the same error as rkbagul, but with psiThermo.

chriss85 November 10, 2015 11:25

Code:

type            heTabularThermo;
means that the temperature will be determined by a table T(h,p). This is only needed if you also provide h(T,p) as a table with
Code:

thermo          hTabular;
.
I think you should use heThermo instead of heTabularThermo if I recall correctly.

user_of_cfx November 11, 2015 04:42

Thanks for the quick reply, I switched back to hePsiThermo (I will try heThermo as well), and it looks like I am not getting the density table syntax right. I arranged my file like this:

Code:

(
(temperature1 ((pressure1 value11)(pressure2 value12)...)
(temperature2 ((pressure1 value21)(pressure2 value22)...)
...
)

and received error in the very first line of code:

Code:

expected " ( " while reading Tuple2, found on line 3 the label 101325
(101325 being the first pressure point, or pressure1)

Reading through the forum it appears that it's some sort of bug but which was fixed in the meantime? But the posts I've seen refer to time dependent boundary conditions so the fix looks way more complicated than what I am trying to do here. I'm sorry if this is something super silly.

UPDATE Nevermind, it WAS a silly syntax error.. I should have counted the brackets *sigh* a syntax that runs:
Code:

(
(temperature1 ((pressure1 value11)(pressure2 value12)...))
(temperature2 ((pressure1 value21)(pressure2 value22)...))
...
)


AnasCFD April 11, 2016 15:34

TTable
 
Could you please tell me what is TTable which is used in TabularEOS.

Thanks

chriss85 April 12, 2016 04:02

By default OpenFOAM uses Newton's method to find the temperature from the energy and pressure. This means that many evaluations of the h(p,T) function are required. Normally this is not a problem because in the case of polynomials or so this function is very cheap to evaluate. However, when you need to lookup the value in a large table it can impose a performance drop. To avoid this, you can calculate a T(p,h) table yourself in advance which is just the inverted h(p,T) table with coordinates exchanged. If you use the appropriate thermophysical model this method will be used.

By the way, I have updated a few things regarding this library, so I will release a new version soon if I can find the time. Also, please keep in mind that not all solvers are written to account for pressure dependences in h(p,T) and rho(p,T). Some solvers may require additional terms.

qjh888 May 24, 2017 02:49

Build these codes into foam-extend version 3.0
 
Hi Chriss,

Thanks for your excellent work!
Currently I'm trying to build your code into foam-extend version.
However, the foam-extend 3.0 version (even more latest 4.0 version) has no hePsiThermo and fluidThermo module.

So I'm just wondering if you have interest in transfer your work into foam-extend?
That will be helped a lot!

Thanks and waiting for your reply.

Janry

tilasoldo July 12, 2017 05:19

OpenFoam 4.x version
 
Hi chriss85,

First of all thank you for your work, I am amazed by the fact that OpenFoam still doesn't provide a solution for tabulated thermophysical properties, and you implementation is truly wonderful.

I am (also) aiming at adapting it for OpenFOAM 4.x, as some classes have changed since OF 2.3 :) I will publish my code as soon as I get to validate it!

Regards,
Xavier L.


All times are GMT -4. The time now is 08:43.