Added script to generate fluid information for web on the fly - just need plots now

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
Ian Bell
2014-10-14 13:55:10 +02:00
parent 199ced3f86
commit 9c4ca15c28
3 changed files with 111 additions and 5 deletions

1
.gitignore vendored
View File

@@ -42,3 +42,4 @@
/dev/all_incompressibles.json
/dev/all_incompressibles_verbose.json
/include/all_incompressibles_JSON.h
fluids

View File

@@ -0,0 +1,98 @@
import CoolProp
import os
fluid_template = """.. _fluid_{fluid:s}:
{fluid_stars:s}
{fluid:s}
{fluid_stars:s}
References
==========
{references:s}
{aliases:s}
Fluid Information
=================
.. csv-table::
:header-rows: 1
:file: {fluid:s}-info.csv
"""
table_template = """ Parameter, Value
Molar mass [kg/mol],{mm:s}
CAS, {CAS:s},,,
ASHRAE, {ASHRAE:s}
Triple point temperature [K],{Tt:s}
Triple point pressure [Pa], {pt:s}
Critical point temperature [K], {Tc:s}
Critical point pressure [Pa], {pc:s}
Critical point density [kg/m3], {rhoc_mass:s}
Critical point density [mol/m3], {rhoc_molar:s}
"""
class FluidInfoTableGenerator(object):
def __init__(self, name):
self.name = name
def write(self, path):
def tos(n):
''' convert number to nicely formatted string '''
n = str(n)
if 'e' in n:
n = n.replace('e',':math:`\times 10^{')
n += '}`'
else:
return n
molar_mass = CoolProp.CoolProp.PropsSI(self.name,'molemass')
Tt = CoolProp.CoolProp.PropsSI(self.name,'Ttriple')
Tc = CoolProp.CoolProp.PropsSI(self.name,'Tcrit')
pc = CoolProp.CoolProp.PropsSI(self.name,'pcrit')
pt = CoolProp.CoolProp.PropsSI(self.name,'ptriple')
rhoc_mass = CoolProp.CoolProp.PropsSI(self.name,'rhomass_critical')
rhoc_molar = CoolProp.CoolProp.PropsSI(self.name,'rhomolar_critical')
CAS = CoolProp.CoolProp.get_fluid_param_string(self.name, "CAS")
ASHRAE = CoolProp.CoolProp.get_fluid_param_string(self.name, "ASHRAE")
args = dict(mm = tos(molar_mass),
Tt = tos(Tt),
pt = tos(pt),
Tc = tos(Tc),
rhoc_mass = tos(rhoc_mass),
rhoc_molar = tos(rhoc_molar),
pc = tos(pc),
CAS = tos(CAS),
ASHRAE = tos(ASHRAE))
out = table_template.format(**args)
with open(os.path.join(path, self.name+'-info.csv'),'w') as fp:
print 'writing', os.path.join(path, self.name+'-info.csv')
fp.write(out)
class FluidGenerator(object):
def __init__(self, fluid):
self.fluid = fluid
def write(self, path):
# Write CSV table data for fluid information
ITG = FluidInfoTableGenerator(self.fluid)
ITG.write(path)
aliases = ', '.join(['``' + a.strip() + '``' for a in CoolProp.CoolProp.get_fluid_param_string(self.fluid, 'aliases').strip().split(',') if a])
if aliases:
aliases = 'Aliases\n=======\n\n'+aliases + '\n'
# Write RST file for fluid
out = fluid_template.format(aliases = aliases,
fluid = self.fluid,
fluid_stars = '*'*len(self.fluid),
references = ''
)
with open(os.path.join(path, self.fluid+'.rst'),'w') as fp:
print 'writing', os.path.join(path, self.fluid+'.rst')
fp.write(out)

View File

@@ -1,5 +1,5 @@
from CPWeb.BibtexTools import getCitationOrAlternative, getBibtexParser
import CoolProp
from CPWeb.SphinxTools import FluidGenerator
import os.path
import CoolProp
@@ -16,7 +16,7 @@ class Dossier:
self.data[key].append(value)
d = Dossier()
from pybtex.database.input import bibtex
parser = bibtex.Parser()
bibdata = parser.parse_file(os.path.join(root_dir,"CoolPropBibTeXLibrary.bib"))
@@ -29,7 +29,16 @@ bibtex_map = {'EOS': 'EOS',
'VISCOSITY': ':math:`\eta`',
'MELTING_LINE': 'melt'}
bibtex_keys = ['EOS','CP0','CONDUCTIVITY','VISCOSITY','MELTING_LINE']
fluids_path = os.path.join(web_dir,'fluid_properties','fluids')
if not os.path.exists(fluids_path):
os.makedirs(fluids_path)
for fluid in CoolProp.__fluids__:
FG = FluidGenerator(fluid)
FG.write(fluids_path)
d.add('name', fluid)
for key in bibtex_keys:
try:
@@ -54,7 +63,7 @@ def build_citation(key):
return ':cite:`'+key+'`'
def fluid_reference(fluid):
return fluid
return ':ref:`{fluid:s} <fluid_{fluid:s}>`'.format(fluid = fluid)
# Write the table
with open(csvfile,'w') as fp:
@@ -63,5 +72,3 @@ with open(csvfile,'w') as fp:
for index, row in df.iterrows():
rowdata = [fluid_reference(row['name'])] + [build_citation(row[key]) for key in bibtex_keys]
fp.write(','.join(rowdata)+'\n')