Thermodynamics and Python

Hello. I wanted a python module by which I could access thermodynamic properties of steam. On googling I came across this module called thermopy

http://packages.python.org/thermopy/  .  But the range of temperatures and pressure  which I could use was very limited.  Then I came across this library , called freesteam , which I couldn’t install , though I tried really hard. So I thought I would write my own mini- module to access the properties of steam .

Step 1:

I needed an online data – book which I could scrape steam data . My friend Tejas helped me out , when I had almost lost hope.  http://www.ohio.edu/mechanical/thermo/property_tables/H2O/H2O_PresSat1.html  , this was the link I used . If one examines the html of the page , it isnt tough to scrape the required date. BeautifulSoup (Ive forgotten most of it , thats a different issue) , a simple regular expression would do.

import re
raw_string = 'ALIGN=RIGHT>(.*)<'
for line in file.readlines():
 a = re.search(line , raw_string)
 if a:
 print a.group(1)

Step 2:

After extracting the data storing it in a .dat file . This can be quite easily done with the help of the shelve module . For example in the previous code , if one replaces a couple of lines it would get stored in a .dat file as a dictionary.


import re
<pre>import shelve
a = shelve.open('a.dat')
raw_string = 'ALIGN=RIGHT>(.*)<'
for line in file.readlines():
    b = re.search(line , raw_string)
    if b:
        a['pressure'] = b.group(1)
a.close()

Step 3:
Using the .dat files to use access various properties.This can be really confusing at times. Since there are multiple
lists. It took some time before I could finally implement it.

So here is the sourcecode.

https://gist.github.com/3747669
Couldnt upload the .py file , ill put it on git soon. I will also improve the documentation and try to improvise it.

This is how the module should be used.

import thermo
a = thermo.State(T = 300 , h = 2354)
print a.GetQuality()
0.7183539797807206
print a.GetEnthalpy()
2354.0

P.S : You need not be an awesome coder like many people in my college to write simple apps like these , you just need to
spend a lot of time.

Advertisements

7 comments

  1. I do not even understand how I ended up right here, but I believed this submit was good.

    I do not recognize who you might be but certainly you are going to a famous blogger in the event you aren’t already. Cheers!

  2. PRO!!!

  3. Marcos · · Reply

    Cool!

    1. What is cool?

  4. DC_energia · · Reply

    Simply: THANKS!

  5. bapossatto · · Reply

    you might be interested in CoolProp …

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: