From 2f67422591c7451e7bde967af3255d952569737a Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Fri, 26 Sep 2014 11:31:09 +0200 Subject: [PATCH 1/2] Changed Melinder coefficients, fixes #161 --- Web/fluid_properties/Incompressibles.rst | 10 +++++----- .../CPIncomp/MelinderFluids.py | 16 ++++++++-------- dev/incompressible_liquids/json/DEB.json | 4 ++-- dev/incompressible_liquids/json/HCB.json | 4 ++-- dev/incompressible_liquids/json/HCM.json | 4 ++-- dev/incompressible_liquids/json/HFE.json | 4 ++-- dev/incompressible_liquids/json/PMS1.json | 4 ++-- dev/incompressible_liquids/json/PMS2.json | 4 ++-- dev/incompressible_liquids/json/SAB.json | 4 ++-- dev/incompressible_liquids/json/TCO.json | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Web/fluid_properties/Incompressibles.rst b/Web/fluid_properties/Incompressibles.rst index 33ce3588..d7d92968 100644 --- a/Web/fluid_properties/Incompressibles.rst +++ b/Web/fluid_properties/Incompressibles.rst @@ -32,7 +32,7 @@ specific fluid. To get an overview over all the fits, there are also combined documents with all the :download:`pure fluids and all the aqueous solutions`. You can read more about these reports in a dedicated -:ref:`section` called :ref:`Fitting Reports` below. +:ref:`section` called :ref:`Fitting Reports`. All incompressible fluids have an arbitrary reference state for enthalpy and entropy. During initialisation, the reference state is defined as a temperature of 20 °C @@ -146,10 +146,10 @@ A file with all fitting reports for the incompressible fluids can be obtained from :download:`here`. These reports help you to get an overview over the different incompressible fluids included in CoolProp. The reports start with some basic information about -the fluid. There is the name by which it can be accessed through the -interface in the title "Fitting Report for *FluidName*" as well as a description -of what the fluid actually is, this could also be a trade name or a commonly -used non-scientific name. The next item tells you where we got the data from. This +the fluid. The fluid name used in CoolProp is in the title "Fitting Report for *FluidName*" +and there is also a description of what the fluid actually is. The latter +could also be a trade name or a commonly used non-scientific name. The next item +tells you where we got the data from. This would typically be a data sheet from a manufacturers homepage, some other software database, a scientific publication or experimental data. diff --git a/dev/incompressible_liquids/CPIncomp/MelinderFluids.py b/dev/incompressible_liquids/CPIncomp/MelinderFluids.py index 9e150e7f..55a55946 100644 --- a/dev/incompressible_liquids/CPIncomp/MelinderFluids.py +++ b/dev/incompressible_liquids/CPIncomp/MelinderFluids.py @@ -30,7 +30,7 @@ class DEBLiquidClass(CoefficientData,PureData): _,_,self.viscosity.coeffs = IncompressibleFitter.shapeArray(np.array([3.5503,-0.0566396,7.03331e-05])) self.conductivity.type = self.conductivity.INCOMPRESSIBLE_POLYNOMIAL - _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0.000189132,-2.06364e-07])) + _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0000.189132,-2.06364e-04])) self.density.source = self.density.SOURCE_COEFFS self.specific_heat.source = self.specific_heat.SOURCE_COEFFS @@ -64,7 +64,7 @@ class HCMLiquidClass(CoefficientData,PureData): _,_,self.viscosity.coeffs = IncompressibleFitter.shapeArray(np.array([18.3237,-0.14706,0.000209096])) self.conductivity.type = self.conductivity.INCOMPRESSIBLE_POLYNOMIAL - _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0.000153716,-1.51212e-07])) + _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0000.153716,-1.51212e-04])) self.density.source = self.density.SOURCE_COEFFS self.specific_heat.source = self.specific_heat.SOURCE_COEFFS @@ -98,7 +98,7 @@ class HFELiquidClass(CoefficientData,PureData): _,_,self.viscosity.coeffs = IncompressibleFitter.shapeArray(np.array([-4.22878,-0.0114765,7.39823e-06])) self.conductivity.type = self.conductivity.INCOMPRESSIBLE_POLYNOMIAL - _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([9.92958e-05,-8.33333e-08])) + _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([9.92958e-01,-8.33333e-05])) self.density.source = self.density.SOURCE_COEFFS self.specific_heat.source = self.specific_heat.SOURCE_COEFFS @@ -132,7 +132,7 @@ class PMS1LiquidClass(CoefficientData,PureData): _,_,self.viscosity.coeffs = IncompressibleFitter.shapeArray(np.array([6.36183,-0.0636352,7.51428e-05])) self.conductivity.type = self.conductivity.INCOMPRESSIBLE_POLYNOMIAL - _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0.000207526,-2.84167e-07])) + _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0000.207526,-2.84167e-04])) self.density.source = self.density.SOURCE_COEFFS self.specific_heat.source = self.specific_heat.SOURCE_COEFFS @@ -166,7 +166,7 @@ class PMS2LiquidClass(CoefficientData,PureData): _,_,self.viscosity.coeffs = IncompressibleFitter.shapeArray(np.array([5.66926,-0.065582,8.09988e-05])) self.conductivity.type = self.conductivity.INCOMPRESSIBLE_POLYNOMIAL - _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0.000172305,-2.11212e-07])) + _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0000.172305,-2.11212e-04])) self.density.source = self.density.SOURCE_COEFFS self.specific_heat.source = self.specific_heat.SOURCE_COEFFS @@ -200,7 +200,7 @@ class SABLiquidClass(CoefficientData,PureData): _,_,self.viscosity.coeffs = IncompressibleFitter.shapeArray(np.array([5.21288,-0.0665792,8.5066e-05])) self.conductivity.type = self.conductivity.INCOMPRESSIBLE_POLYNOMIAL - _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0.000208374,-2.61667e-07])) + _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0000.208374,-2.61667e-04])) self.density.source = self.density.SOURCE_COEFFS self.specific_heat.source = self.specific_heat.SOURCE_COEFFS @@ -234,7 +234,7 @@ class HCBLiquidClass(CoefficientData,PureData): _,_,self.viscosity.coeffs = IncompressibleFitter.shapeArray(np.array([7.16819,-0.0863212,0.000130604])) self.conductivity.type = self.conductivity.INCOMPRESSIBLE_POLYNOMIAL - _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0.000203186,-2.3869e-07])) + _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0000.203186,-2.3869e-04])) self.density.source = self.density.SOURCE_COEFFS self.specific_heat.source = self.specific_heat.SOURCE_COEFFS @@ -268,7 +268,7 @@ class TCOLiquidClass(CoefficientData,PureData): _,_,self.viscosity.coeffs = IncompressibleFitter.shapeArray(np.array([-3.47971,-0.0107031,1.14086e-06])) self.conductivity.type = self.conductivity.INCOMPRESSIBLE_POLYNOMIAL - _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0.000174156,-1.85052e-07])) + _,_,self.conductivity.coeffs = IncompressibleFitter.shapeArray(np.array([0000.174156,-1.85052e-04])) self.density.source = self.density.SOURCE_COEFFS self.specific_heat.source = self.specific_heat.SOURCE_COEFFS diff --git a/dev/incompressible_liquids/json/DEB.json b/dev/incompressible_liquids/json/DEB.json index 414a7d4e..d88fdc3f 100644 --- a/dev/incompressible_liquids/json/DEB.json +++ b/dev/incompressible_liquids/json/DEB.json @@ -10,10 +10,10 @@ "conductivity": { "coeffs": [ [ - 1.891320e-04 + 1.891320e-01 ], [ - -2.063640e-07 + -2.063640e-04 ] ], "type": "polynomial" diff --git a/dev/incompressible_liquids/json/HCB.json b/dev/incompressible_liquids/json/HCB.json index 5abfd214..0fdf69aa 100644 --- a/dev/incompressible_liquids/json/HCB.json +++ b/dev/incompressible_liquids/json/HCB.json @@ -10,10 +10,10 @@ "conductivity": { "coeffs": [ [ - 2.031860e-04 + 2.031860e-01 ], [ - -2.386900e-07 + -2.386900e-04 ] ], "type": "polynomial" diff --git a/dev/incompressible_liquids/json/HCM.json b/dev/incompressible_liquids/json/HCM.json index c12209a2..9804f709 100644 --- a/dev/incompressible_liquids/json/HCM.json +++ b/dev/incompressible_liquids/json/HCM.json @@ -10,10 +10,10 @@ "conductivity": { "coeffs": [ [ - 1.537160e-04 + 1.537160e-01 ], [ - -1.512120e-07 + -1.512120e-04 ] ], "type": "polynomial" diff --git a/dev/incompressible_liquids/json/HFE.json b/dev/incompressible_liquids/json/HFE.json index 7aa16acb..15ebae77 100644 --- a/dev/incompressible_liquids/json/HFE.json +++ b/dev/incompressible_liquids/json/HFE.json @@ -10,10 +10,10 @@ "conductivity": { "coeffs": [ [ - 9.929580e-05 + 9.929580e-01 ], [ - -8.333330e-08 + -8.333330e-05 ] ], "type": "polynomial" diff --git a/dev/incompressible_liquids/json/PMS1.json b/dev/incompressible_liquids/json/PMS1.json index a2314b8d..0b7f0815 100644 --- a/dev/incompressible_liquids/json/PMS1.json +++ b/dev/incompressible_liquids/json/PMS1.json @@ -10,10 +10,10 @@ "conductivity": { "coeffs": [ [ - 2.075260e-04 + 2.075260e-01 ], [ - -2.841670e-07 + -2.841670e-04 ] ], "type": "polynomial" diff --git a/dev/incompressible_liquids/json/PMS2.json b/dev/incompressible_liquids/json/PMS2.json index c16cad12..3a2e933c 100644 --- a/dev/incompressible_liquids/json/PMS2.json +++ b/dev/incompressible_liquids/json/PMS2.json @@ -10,10 +10,10 @@ "conductivity": { "coeffs": [ [ - 1.723050e-04 + 1.723050e-01 ], [ - -2.112120e-07 + -2.112120e-04 ] ], "type": "polynomial" diff --git a/dev/incompressible_liquids/json/SAB.json b/dev/incompressible_liquids/json/SAB.json index afb767f6..4f21395c 100644 --- a/dev/incompressible_liquids/json/SAB.json +++ b/dev/incompressible_liquids/json/SAB.json @@ -10,10 +10,10 @@ "conductivity": { "coeffs": [ [ - 2.083740e-04 + 2.083740e-01 ], [ - -2.616670e-07 + -2.616670e-04 ] ], "type": "polynomial" diff --git a/dev/incompressible_liquids/json/TCO.json b/dev/incompressible_liquids/json/TCO.json index 86f8ff6f..1e16142c 100644 --- a/dev/incompressible_liquids/json/TCO.json +++ b/dev/incompressible_liquids/json/TCO.json @@ -10,10 +10,10 @@ "conductivity": { "coeffs": [ [ - 1.741560e-04 + 1.741560e-01 ], [ - -1.850520e-07 + -1.850520e-04 ] ], "type": "polynomial" From b5ba07be78f8a41bc3141755ee1017a5f57767ec Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Fri, 26 Sep 2014 18:32:24 +0200 Subject: [PATCH 2/2] Reworked the documentation generator scripts and the binary mixture table --- Web/conf.py | 11 ++- Web/fluid_properties/Incompressibles.rst | 20 +++--- Web/fluid_properties/Mixtures.rst | 14 +++- .../make_binary_pairs_table.py | 32 --------- Web/scripts/CPWeb/BibtexTools.py | 54 +++++++++++++++ Web/scripts/CPWeb/UnicodeTools.py | 69 +++++++++++++++++++ Web/scripts/CPWeb/__init__.py | 21 ++++++ Web/scripts/fluid_properties.Mixtures.py | 68 ++++++++++++++++++ 8 files changed, 244 insertions(+), 45 deletions(-) delete mode 100644 Web/fluid_properties/make_binary_pairs_table.py create mode 100644 Web/scripts/CPWeb/BibtexTools.py create mode 100644 Web/scripts/CPWeb/UnicodeTools.py create mode 100644 Web/scripts/CPWeb/__init__.py create mode 100644 Web/scripts/fluid_properties.Mixtures.py diff --git a/Web/conf.py b/Web/conf.py index 0816a38a..a02e9706 100644 --- a/Web/conf.py +++ b/Web/conf.py @@ -13,6 +13,7 @@ # serve to show the default. import sys, os + sys.path.insert(0, os.path.abspath('_ext')) try: import sphinxcontrib.doxylink @@ -20,8 +21,16 @@ except ImportError: print('Unable to import sphinxcontrib.doxylink; try to run "pip install sphinxcontrib-doxylink"') + +import glob import subprocess -subprocess.call('python make_binary_pairs_table.py', cwd = 'fluid_properties', shell = True) + +# This part finds all scripts and runs them +scripts = glob.glob(os.path.join('scripts','*.py')) +for script in scripts: + subprocess.call('python {0}'.format(os.path.basename(script)), cwd='scripts', shell=True) + + #~ # If your extensions are in another directory, add it here. If the directory #~ # is relative to the documentation root, use os.path.abspath to make it diff --git a/Web/fluid_properties/Incompressibles.rst b/Web/fluid_properties/Incompressibles.rst index d7d92968..af66c76a 100644 --- a/Web/fluid_properties/Incompressibles.rst +++ b/Web/fluid_properties/Incompressibles.rst @@ -66,7 +66,7 @@ internally, which makes this combination by far the fastest. However, also the other inputs should be fast compared to the full Helmholtz-based EOS implemented for then compressible fluids. -A call to the top-level function ``PropsSI`` can provide : temperature, pressure, +A call to the top-level function ``PropsSI`` can provide: temperature, pressure, density, heat capacity, internal energy, enthalpy, entropy, viscosity and thermal conductivity. Hence, the available output keys are: ``T``, ``P``, ``D``, ``C``, ``U``, ``H``, ``S``, ``V``, ``L``, ``Tmin`` and ``Tmax``. @@ -104,7 +104,7 @@ composition notation. Depending on your fluid, you have to supply either the :ref:`mass fraction` or the :ref:`volume fraction` as additional parameter. This is done via the fluid name by appending a dash and the fraction of the substance other than water. The fraction notation can be in the -form of percent, ``LiBr-23%``, or as a fraction ``LiBr[0.23]``, which +form of percent, ``LiBr-23%``, or as a fraction, ``LiBr[0.23]``, which corresponds to the new mixture syntax in CoolProp5. .. In addition to the properties available for the pure fluids (``D``, ``C``, @@ -147,10 +147,10 @@ from :download:`here` of the reports side by side. -If all data is available, there is a graphs for each of the basic quantities +If all data are available, there is a graph for each of the basic quantities: density :math:`\rho`, specific heat capacity :math:`c`, thermal conductivity :math:`\lambda`, dynamic viscosity :math:`\mu`, saturation pressure :math:`p_\text{sat}`, and freezing temperature :math:`T_\text{freeze}`. These graphs show @@ -190,14 +190,14 @@ properties of incompressible fluids in CoolProp: Only the last two are suitable for mixtures with the input parameter :math:`x` denoting the fraction of component other than water. Following the works of -Melinder :cite:`Melinder2010` and Skovrup :cite:`Skovrup2013`, the exponents are +Melinder :cite:`Melinder2010` and Skovrup :cite:`Skovrup2013`, the exponents for the polynomials are arranged in a triangular matrix to avoid overfitting. These conditions satisfy :math:`0 \leq i \leq n`, :math:`0 \leq j \leq m` and :math:`i + j \leq \max(n,m)`. It is only for the freezing temperature calculation that the implemented procedures differ from what is presented in Melinder's book :cite:`Melinder2010`. Freezing temperature is only a function of concentration -and the dependency on the fluid temperature has been removed. For mixtures, the -default values for :math:`m=5` and :math:`n=3` are chosen. +and the dependency on the fluid temperature has been removed. For mixtures, +:math:`m=5` and :math:`n=3` are assigned as default values. Omitting the composition term with :math:`n=0` yields the pure fluid formulations for which we selected :math:`l=1` and :math:`m=4`. @@ -280,7 +280,7 @@ manufactures, two specific publications provided a lot of data used for the incompressible fluids: Åke Melinder's book *Properties of Secondary Working Fluids for Indirect Systems* :cite:`Melinder2010` has inspired both, the work on pure fluids and aqueous solutions. The second major source of inspiration is the -`SecCool software `_ +`SecCool `_ :cite:`Skovrup2013` software, which contains data compiled by Morten Juel Skovrup. It is provided free of charge by his employer `IPU `_. @@ -297,7 +297,7 @@ There are also a number of water-based mixtures implemented in CoolProp. Most of are secondary heat transfer fluids, but there are also aqueous solutions of ammonia :cite:`Melinder2010`, :download:`MAM<../_static/fluid_properties/incompressible/report/MAM_fitreport.pdf>`, and lithium bromide :cite:`Patek2006`, :download:`LiBr<../_static/fluid_properties/incompressible/report/LiBr_fitreport.pdf>`, -which can be used to calculated absorption chillers. +which can be used to model absorption chillers. .. _MassMix: diff --git a/Web/fluid_properties/Mixtures.rst b/Web/fluid_properties/Mixtures.rst index 6abfa405..6b3b352c 100644 --- a/Web/fluid_properties/Mixtures.rst +++ b/Web/fluid_properties/Mixtures.rst @@ -20,11 +20,21 @@ The only types of inputs that are allowed for mixtures right now are - Temperature/quality - Temperature/pressure +.. Used in Python script later on +.. role:: raw-html(raw) + :format: html + Binary pairs ------------ + +.. note:: + Please hover the mouse pointer over the coefficients to get the full accuracy + for the listed coefficients. You can also get more information on references + that are not in bibliography. + .. csv-table:: All binary pairs included in CoolProp :header-rows: 1 - :file: mixture_binary_pairs.csv + :file: mixture_binary_pairs.csv Phase Envelope -------------- @@ -46,7 +56,7 @@ Phase Envelope plt.xlabel('Temperature [K]') plt.ylabel('Pressure [Pa]') plt.tight_layout() - + References ---------- diff --git a/Web/fluid_properties/make_binary_pairs_table.py b/Web/fluid_properties/make_binary_pairs_table.py deleted file mode 100644 index b8f5cdea..00000000 --- a/Web/fluid_properties/make_binary_pairs_table.py +++ /dev/null @@ -1,32 +0,0 @@ -import CoolProp - -class Dossier: - def __init__(self): - self.data = {} - def add(self, key, value): - if key not in self.data: - self.data[key] = [] - self.data[key].append(value) - -d = Dossier() - -pairs = CoolProp.get('mixture_binary_pairs_list') -for pair in pairs.split(','): - CAS1, CAS2 = pair.split('&') - d.add('CAS1', CAS1) - d.add('CAS2', CAS2) - for key in ['name1','name2','F','function','BibTeX','xi','zeta','betaT','betaV','gammaT','gammaV']: - try: - d.add(key, CoolProp.CoolProp.get_mixture_binary_pair_data(CAS1, CAS2, key)) - except BaseException as BE: - d.add(key, '') - -import pandas -df = pandas.DataFrame(d.data) -df = df.sort(['BibTeX','name1'], ascending = [0, 1]) - -with open('mixture_binary_pairs.csv','w') as fp: - fp.write('Ref.,Name1,Name2,function,F,xi,zeta,betaT,betaV,gammaT,gammaV\n') - for index, row in df.iterrows(): - text = ','.join([':cite:`'+row['BibTeX']+'`', row['name1'], row['name2'], row['function'], row['F'], row['xi'], row['zeta'], row['betaT'], row['betaV'], row['gammaT'], row['gammaV']])+'\n' - fp.write(text) \ No newline at end of file diff --git a/Web/scripts/CPWeb/BibtexTools.py b/Web/scripts/CPWeb/BibtexTools.py new file mode 100644 index 00000000..0e09bb17 --- /dev/null +++ b/Web/scripts/CPWeb/BibtexTools.py @@ -0,0 +1,54 @@ +''' +Created on 26 Sep 2014 + +@author: jowr +''' +import os +from CoolProp.BibtexParser import BibTeXerClass + +def getPath(filename, search=True): + # Path to root + coolprop_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),'..','..')) + # Test for file + fname = filename + if os.path.exists(fname): return os.path.abspath(fname) + # Test relative to this file + fname = os.path.join(os.path.dirname(__file__),filename) + if os.path.exists(fname): return os.path.abspath(fname) + # Test relative to root notation + fname = os.path.join(coolprop_dir,filename) + if os.path.exists(fname): return os.path.abspath(fname) + # Search in root tree + fname = os.path.basename(filename) + if search: + result = [] + for root, dirs, files in os.walk(coolprop_dir): + if fname in files: + result.append(os.path.join(root, fname)) + if len(result)==1: + return os.path.abspath(result[0]) + elif len(result)>1: + print "Found multiple files with the name {0}. Try to specify the path as well.".format(fname) + print result + return os.path.abspath(result[0]) + + raise ValueError("Found no file with the name {0}. Try to specify the path as well.".format(fname)) + + +def getBibtexParser(filename = '../../../CoolPropBibTeXLibrary.bib'): + """Create a parser object that can be used to extract entries from a + library in Bibtex format.""" + fpath = getPath(filename) + bibtexer = BibTeXerClass(fpath) + return bibtexer + + +def getCitationOrAlternative(bibtexer, bibtex_key): + """Find the key in the library and convert to a citation, if it is not found, + we return a footnote string for sphinx.""" + bibtex_key = bibtex_key.strip() + + if bibtex_key in bibtexer.library.entries: + return u':cite:`{0}`'.format(bibtex_key) + else: + return u':raw-html:`Source`'.format(bibtex_key) diff --git a/Web/scripts/CPWeb/UnicodeTools.py b/Web/scripts/CPWeb/UnicodeTools.py new file mode 100644 index 00000000..7be24171 --- /dev/null +++ b/Web/scripts/CPWeb/UnicodeTools.py @@ -0,0 +1,69 @@ +''' +Created on 26 Sep 2014 + +@author: jowr +''' +import codecs +import csv +import cStringIO + +class UTF8Recoder: + """ + Iterator that reads an encoded stream and reencodes the input to UTF-8 + """ + def __init__(self, f, encoding): + self.reader = codecs.getreader(encoding)(f) + + def __iter__(self): + return self + + def next(self): + return self.reader.next().encode("utf-8") + +class UnicodeReader: + """ + A CSV reader which will iterate over lines in the CSV file "f", + which is encoded in the given encoding. + """ + + def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds): + f = UTF8Recoder(f, encoding) + self.reader = csv.reader(f, dialect=dialect, **kwds) + + def next(self): + row = self.reader.next() + return [unicode(s, "utf-8") for s in row] + + def __iter__(self): + return self + +class UnicodeWriter: + """ + A CSV writer which will write rows to CSV file "f", + which is encoded in the given encoding. + """ + + def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds): + # Redirect output to a queue + self.queue = cStringIO.StringIO() + self.writer = csv.writer(self.queue, dialect=dialect, **kwds) + self.stream = f + self.encoder = codecs.getincrementalencoder(encoding)() + + def writerow(self, row): + self.writer.writerow([s.encode("utf-8") for s in row]) + # Fetch UTF-8 output from the queue ... + data = self.queue.getvalue() + data = data.decode("utf-8") + # ... and reencode it into the target encoding + data = self.encoder.encode(data) + # write to the target stream + self.stream.write(data) + # empty queue + self.queue.truncate(0) + + def writerows(self, rows): + for row in rows: + self.writerow(row) + + diff --git a/Web/scripts/CPWeb/__init__.py b/Web/scripts/CPWeb/__init__.py new file mode 100644 index 00000000..a67290f7 --- /dev/null +++ b/Web/scripts/CPWeb/__init__.py @@ -0,0 +1,21 @@ +""" +CPWeb - A collection of commonly used routines to produce CoolProp's online documentation +===== + +""" +from __future__ import division, absolute_import, print_function + +import codecs +import csv +import cStringIO + + + + + +def get_version(): + return 5.0 + +if __name__ == "__main__": + print('You are using version %s of the Python package for creating CoolProp\' online documentation.'%(get_version())) + print() diff --git a/Web/scripts/fluid_properties.Mixtures.py b/Web/scripts/fluid_properties.Mixtures.py new file mode 100644 index 00000000..024aaab9 --- /dev/null +++ b/Web/scripts/fluid_properties.Mixtures.py @@ -0,0 +1,68 @@ + + +from CPWeb.BibtexTools import getCitationOrAlternative, getBibtexParser +import CoolProp +import os.path + +web_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),'..')) +csvfile = os.path.join(web_dir,'fluid_properties','mixture_binary_pairs.csv') + +def merge_args(*args): + return " :raw-html:`
` ".join(list(args)) + +def printCoeff(number): + if number is None or \ + len(str(number).strip())<1: + return " " + number = float(number) + short = "{0:.4e}".format(number) + long = "{0:.14e}".format(number) + return u':raw-html:`{0}`'.format(short,long) + +class Dossier: + def __init__(self): + self.data = {} + def add(self, key, value): + if key not in self.data: + self.data[key] = [] + self.data[key].append(value) + +d = Dossier() + +pairs = CoolProp.get('mixture_binary_pairs_list') +for pair in pairs.split(','): + CAS1, CAS2 = pair.split('&') + d.add('CAS1', CAS1) + d.add('CAS2', CAS2) + for key in ['name1','name2','F','function','BibTeX','xi','zeta','betaT','betaV','gammaT','gammaV']: + try: + d.add(key, CoolProp.CoolProp.get_mixture_binary_pair_data(CAS1, CAS2, key)) + except BaseException as BE: + d.add(key, '') + +import pandas +df = pandas.DataFrame(d.data) +df = df.sort(['BibTeX','name1'], ascending = [0, 1]) + +bibtexer = getBibtexParser()#filename = '../../../CoolPropBibTeXLibrary.bib') + +with open(csvfile,'w') as fp: + header = 'Ref.,Name1,Name2,function,F,' + header += merge_args("xi","zeta,") + header += merge_args("betaT","betaV,") + header += merge_args("gammaT","gammaV") + header += '\n' + fp.write(header) + + for index, row in df.iterrows(): + text = ','.join([ \ + getCitationOrAlternative(bibtexer,row['BibTeX']), + row['name1'], + row['name2'], + row['function'], + row['F'], + merge_args(printCoeff(row['xi']),printCoeff(row['zeta'])), + merge_args(printCoeff(row['betaT']),printCoeff(row['betaV'])), + merge_args(printCoeff(row['gammaT']),printCoeff(row['gammaV'])) + ])+'\n' + fp.write(text) \ No newline at end of file