CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Tabulated fluid thermo model

Register Blogs Community New Posts Updated Threads Search

Like Tree9Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 15, 2015, 05:00
Default Tabulated fluid thermo model
  #1
New Member
 
Luka Denies
Join Date: Oct 2014
Posts: 28
Rep Power: 12
LukaD is on a distinguished road
I have programmed a new thermo model to use tabulated fluid properties instead of the existing models. The model covers an equation of state, the thermodynamic properties as well as transport properties. All of these must be defined by the user in two-dimensional (p,T) tables that are then interpolated.

This feature is especially useful when simulating supercritical fluids that have rapidly changing properties near the critical point. Tabulating the properties avoids real-time calculation with complex equations for each cell.

The first version is available at https://github.com/ldenies/tabulatedProperties Note that the code is not very tidy and still contains some remnants of the perfectGas files that were used as a basis.

One question I have is how to load the table files from the case directory. I am currently loading them directly from my home directory which is neither desirable nor flexible; see beneath.

Code:
cpTable_ ("/home/luka/cp")
I would prefer to put the files in the constant directory and load them from there. I tried to program the following but this failed to compile because runTime was not defined in this scope.

Code:
cpTable_ (runTime.path()/"constant/cp")
Any thoughts on how to implement this?
LukaD is offline   Reply With Quote

Old   June 29, 2015, 14:40
Default
  #2
New Member
 
Peter Bishop
Join Date: Jan 2012
Posts: 20
Rep Power: 14
PeterBishop is on a distinguished road
Hi Luka,
I really appreciate your work, maybe this can help you

http://www.cfd-online.com/Forums/ope...s-library.html

Have you tried just typing ("constant/cp")?
PeterBishop is offline   Reply With Quote

Old   July 1, 2015, 06:16
Default
  #3
New Member
 
Luka Denies
Join Date: Oct 2014
Posts: 28
Rep Power: 12
LukaD is on a distinguished road
Hi Peter,

Thanks a lot for the link! I was not aware of this work, even though I searched the forum for exactly this before starting on programming it myself.

From looking at the code, their approach is indeed to simply put
Code:
"constant/kappa"
etc. I will try this and if successful, implement it in my library.
LukaD is offline   Reply With Quote

Old   July 1, 2015, 06:35
Default
  #4
New Member
 
Peter Bishop
Join Date: Jan 2012
Posts: 20
Rep Power: 14
PeterBishop is on a distinguished road
Hi Luka,
I'm looking at your work and I've compiled this library on my machine with some modifications to your original make files. Can you give me an example of table file format?

Thanks
keep in touch
PeterBishop is offline   Reply With Quote

Old   July 1, 2015, 06:56
Default
  #5
New Member
 
Luka Denies
Join Date: Oct 2014
Posts: 28
Rep Power: 12
LukaD is on a distinguished road
Hi Peter,

I've added two example files in the attachment. I am close to finishing a validation project and will push a tutorial case to the repository soon, but this should get you started.
Attached Files
File Type: gz propertyTables.tar.gz (67.8 KB, 122 views)
LukaD is offline   Reply With Quote

Old   July 1, 2015, 07:31
Default
  #6
Senior Member
 
Join Date: Oct 2013
Posts: 397
Rep Power: 19
chriss85 will become famous soon enough
Hi Luka,

I'm the author of the library which was already linked to. You can indeed use relative paths so you can put the libraries in the case folder.
My library uses an enhanced table class which is also capable of linear extrapolation, should values outside of the table be needed.

Let me know if you have any questions.

By the way, I'm still working on the cpMcv and Z terms right now. Do you think there is a valid case where these can't be derived from the gas constant and the equation of state?
chriss85 is offline   Reply With Quote

Old   July 1, 2015, 07:49
Default
  #7
New Member
 
Luka Denies
Join Date: Oct 2014
Posts: 28
Rep Power: 12
LukaD is on a distinguished road
I think as long as there is a function in place to get the density as rho(p,T), compressibility Z can always be derived from p, T and R. This is because essentially, Z just gives the difference between real gas and ideal gas behaviour. I've implemented it as following:

Code:
Z = p/(rhoTable_(p,T)*this->R()*T);
For cpMcv, I am not so sure. The equation cp - cv = R is only valid for ideal gases; looking at my tables for supercritical methane this equation does not hold; the value of cp - cv varies by a factor of 8 in this data. So if a value of cv is required by the solver, the cpMcv value should be interpolated from a table supplied by the user. Of course, cv is only rarely used in the OpenFOAM solvers as far as I know.
LukaD is offline   Reply With Quote

Old   July 1, 2015, 08:27
Default
  #8
Senior Member
 
Join Date: Oct 2013
Posts: 397
Rep Power: 19
chriss85 will become famous soon enough
This is correct. What I'm wondering is if I can treat the gas constant as a function of p and T instead, so that cp-cv=R stays valid?
chriss85 is offline   Reply With Quote

Old   July 1, 2015, 08:45
Default
  #9
New Member
 
Luka Denies
Join Date: Oct 2014
Posts: 28
Rep Power: 12
LukaD is on a distinguished road
In principle, I think you could. However, it is both at odds with the definition of the gas constant and more difficult to implement because OpenFOAM already offers the cpMcv function to deal with this.

I essence, the cpMcv variable already more or less does what you suggest; it keeps cp - cv equal to some changing property f(p,T). The difference is that now you do not need to directly manipulate the gas constant R. The latter would also interfere with the calculation of Z we discussed earlier.

On another note, I think it would be interesting to merge both our projects to have a single library available for the community. I intend do some test cases with both libraries and compare the performance in terms of calculation time in the near future.
LukaD is offline   Reply With Quote

Old   July 1, 2015, 10:23
Default
  #10
Senior Member
 
Join Date: Oct 2013
Posts: 397
Rep Power: 19
chriss85 will become famous soon enough
I think you might be right, I was under the impression before that cp-cv=R all the time, and that meant for me that I had to use a variable R to make the relation valid. I need to do some reading to make sure this is the correct way to go about this, but I think you might be right.

I wouldn't mind joining them, but I need the extrapolation functionality, because I sometimes get results that lie out of the tables available to me, and extrapolating produces better results than clamping the tables. I guess this could be precomputed, but it's already up and running
chriss85 is offline   Reply With Quote

Old   July 2, 2015, 07:46
Default
  #11
New Member
 
Luka Denies
Join Date: Oct 2014
Posts: 28
Rep Power: 12
LukaD is on a distinguished road
I have updated the library on github. The fluid properties are now read from the constant directory in the way that was suggested here. A tutorial case has been added including fluid property files for supercritical methane. Lastly, some of the code has been cleaned.

Chris, I also think the linear extrapolation is a useful feature. If it turns out that the native interpolation2DTable is faster (which is absolutely not sure), we could still add the extrapolation behaviour to that code instead of clamping.
LukaD is offline   Reply With Quote

Old   July 3, 2015, 11:34
Default
  #12
New Member
 
Gert-Jan Meijn
Join Date: Apr 2015
Posts: 8
Rep Power: 11
GJM1991 is on a distinguished road
Hi LukaD,

I am currently working on a project in which some look-up-tables would be very convenient. Could you tell me how you make the table-files? It seems they need to be structured in a certain way... Do they come directly from a software-package or did you write something yourself?
GJM1991 is offline   Reply With Quote

Old   July 6, 2015, 05:53
Default
  #13
Senior Member
 
Join Date: Oct 2013
Posts: 397
Rep Power: 19
chriss85 will become famous soon enough
Table structure goes like this:
(
(x1 (y11 z11)(y12 z12)...)
(x2 (y21 z21)(y22 z22)...)
...
)

You will have to write these files yourself using a small script. I could provide a python script if you have an input csv file like this:
0 x1 x2 ...
y1 z11 z21 ...
y2 z21 z22 ...
...

I don't remember the exact ordering from my head, you would have to check that yourself.
chriss85 is offline   Reply With Quote

Old   July 7, 2015, 09:59
Default
  #14
New Member
 
Luka Denies
Join Date: Oct 2014
Posts: 28
Rep Power: 12
LukaD is on a distinguished road
Chris is correct, this is the structure of table files in OpenFOAM. I generated the files myself with a Python script, based on equations for the properties reported in literature.

The properties are tabulated according to pressure (p) and temperature (T). The table then becomes

(
( p1 (T1 value11) (T2 value12) (T3 value13))
( p2 (T1 value21) (T2 value22) (T3 value23))
);

where value12 equals the property value at p1 and T2.

If I am not mistaken, the module of Chris has the tables the other way around, with temperature as the first "coordinate" and pressure as the second.
LukaD is offline   Reply With Quote

Old   July 7, 2015, 10:04
Default
  #15
Senior Member
 
Join Date: Oct 2013
Posts: 397
Rep Power: 19
chriss85 will become famous soon enough
As I said, I don't remember everything without looking it up again, but the reason for my ordering was that I use a table for h(p,T) and an inverted table for T(p,h). Due to the nonlinearity here we don't get an orthogonal coordinate grid. The way the table is structured requires one coordinate for one row of entries. The coordinates for the columns may be different though. This is why my order was required. It is also possible to use the method of temperature calculation which is already present in OpenFOAM, but it is much slower (and doesn't guarantee convergence) and I don't suggest to use it.
chriss85 is offline   Reply With Quote

Old   July 22, 2015, 12:20
Default
  #16
New Member
 
Peter Bishop
Join Date: Jan 2012
Posts: 20
Rep Power: 14
PeterBishop is on a distinguished road
Hi Luka,
I downloaded your code and tutorial, I'm giving a deeper look at the tables you created but I'm not able to understand which units have you considered to create every table, in particular with reference to the enthalpy. I'm comparing it with the NIST database but numbers does not match
PeterBishop is offline   Reply With Quote

Old   July 23, 2015, 04:48
Default
  #17
Senior Member
 
Join Date: Oct 2013
Posts: 397
Rep Power: 19
chriss85 will become famous soon enough
Not speaking for Luka, but enthalpy should be in J/kg usually.
chriss85 is offline   Reply With Quote

Old   July 29, 2015, 15:47
Default
  #18
New Member
 
Peter Bishop
Join Date: Jan 2012
Posts: 20
Rep Power: 14
PeterBishop is on a distinguished road
Thank you chriss!
Enthalpy table has to be created in J/kg because in the code it is then multiplied by molar weight. The same is for the cp table.
Instead as I have understood the cpMcv table needs to be created in J/kmol K because it is not multiplied by the molar weight.
Luka you should check the cpMcv table in the tutorial because I think it is created with wrong units, please let me know if I'm wrong! Thanks guys
PeterBishop is offline   Reply With Quote

Old   August 11, 2015, 08:19
Default
  #19
New Member
 
Luka Denies
Join Date: Oct 2014
Posts: 28
Rep Power: 12
LukaD is on a distinguished road
You are both right, the enthalpy table is indeed in J/kg. The reason why the numbers are not the same as NIST is that I used another equation of state (GERG-2004). These do not have the same zero point. However, absolute differences between states are the same for both relations yield the same enthalpy difference.

It is also correct that the cpMcv table ought to be in J/(kmol K). I will change this when I update the repository. Luckily, the tutorial does not use a value for cv and neither have I ever used it in my simulations, so the mistake should not have had an impact.
LukaD is offline   Reply With Quote

Old   January 5, 2016, 05:24
Default
  #20
Member
 
Join Date: May 2015
Posts: 68
Rep Power: 11
hcl734 is on a distinguished road
Great work as far as I can evaluate!

[QUOTE=LukaD;550354]I have programmed a new thermo model to use tabulated fluid properties instead of the existing models. The model covers an equation of state, the thermodynamic properties as well as transport properties. All of these must be defined by the user in two-dimensional (p,T) tables that are then interpolated.
[QUOTE]

Is it also possible to define just one property using the tables and the others let's say using icoPolynomial?

Did you test this Utility with chtMultiRegionSimpleFoam?
I found the myChtSimpleFoam-solver which seems to answer this question but I would like to verify.
hcl734 is offline   Reply With Quote

Reply

Tags
equation of state, supercritical, tabulated, thermo


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to incorporate the temperature of fluid in pressure based cavitation model arindamsantra7 Main CFD Forum 0 September 23, 2014 11:46
Overflow Error in Multiphase Modelling with Two Continuous Fluids ashtonJ CFX 6 August 11, 2014 15:32
Modeling interface of fluid and porous, not with default setting ftab CFX 27 May 20, 2014 07:58
Question about CFX transitional fluid model Anna Tian CFX 1 January 28, 2013 21:14
How to apply negtive pressure to outlet bioman66 CFX 5 June 3, 2006 02:40


All times are GMT -4. The time now is 12:07.