From 580fbd15d8df79655dc7de22eec80f05da82cea1 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Tue, 23 Sep 2014 19:07:55 +0200 Subject: [PATCH] Updated some reference state functions, does not work properly at the moment. --- Web/fluid_properties/Incompressibles.rst | 273 +++++++----------- .../CPIncomp/WriterObjects.py | 113 ++++++-- dev/incompressible_liquids/json/AEG.json | 2 +- dev/incompressible_liquids/json/APG.json | 2 +- .../json/ExampleDigital.json | 10 +- dev/incompressible_liquids/json/FRE.json | 8 +- dev/incompressible_liquids/json/GKN.json | 2 +- dev/incompressible_liquids/json/HC20.json | 2 +- dev/incompressible_liquids/json/HC30.json | 2 +- dev/incompressible_liquids/json/HC40.json | 2 +- dev/incompressible_liquids/json/HFE2.json | 4 +- dev/incompressible_liquids/json/LiBr.json | 2 +- dev/incompressible_liquids/json/MEA2.json | 2 +- dev/incompressible_liquids/json/MMG2.json | 24 +- dev/incompressible_liquids/json/MNA2.json | 18 +- dev/incompressible_liquids/json/PK2.json | 2 +- dev/incompressible_liquids/json/PKL.json | 2 +- dev/incompressible_liquids/json/TY10.json | 4 +- dev/incompressible_liquids/json/TY15.json | 4 +- dev/incompressible_liquids/json/TY20.json | 2 +- dev/incompressible_liquids/json/XLT2.json | 2 +- dev/incompressible_liquids/json/ZAC.json | 2 +- dev/incompressible_liquids/json/ZS40.json | 2 +- dev/incompressible_liquids/json/ZS45.json | 2 +- dev/incompressible_liquids/json/ZS55.json | 4 +- .../Incompressible/IncompressibleBackend.cpp | 14 +- .../Incompressible/IncompressibleFluid.cpp | 2 +- 27 files changed, 262 insertions(+), 246 deletions(-) diff --git a/Web/fluid_properties/Incompressibles.rst b/Web/fluid_properties/Incompressibles.rst index d09bcd3c..b4fe47d0 100644 --- a/Web/fluid_properties/Incompressibles.rst +++ b/Web/fluid_properties/Incompressibles.rst @@ -1,6 +1,4 @@ -.. |degC| replace:: :math:`^\circ\!\!` C -.. |degF| replace:: :math:`^\circ\!\!` F .. _Incompressibles: @@ -37,17 +35,27 @@ You can read more about these reports in a dedicated :ref:`section` called :ref:`Fitting Reports` below. All incompressible fluids have an arbitrary reference state for enthalpy and entropy. -During initialisation, the reference state is defined in temperature and pressure -according to the U.S. National Institute of Standards and Technology [NIST](http://www.nist.gov). +During initialisation, the reference state is defined as a temperature of 20 °C +and a pressure of 1 atm according to the U.S. National Institute of Standards and +Technology ([NIST](http://www.nist.gov)). +.. math:: + T_\text{ref} &= 293.15\,\text{K} &= 68\,\text{°F} \\ + p_\text{ref} &= 101325\,\text{Pa} &= 14.696\,\text{psi} \\ + h_\text{ref} &= 0 & \\ + s_\text{ref} &= 0 & \\ + +If you use a mixture, the reference state gets updated each time you change the +composition. Pure Fluid Examples ------------------- Incompressible fluids only allow for a limited subset of input variables. The -following input pairs are supported: :math:`f(p,T)`, :math:`f(h,p)`, :math:`f(\rho,T)`, -:math:`f(p,u)` and :math:`f(p,s)`. All functions iterate on :math:`f(p,T)` calls +following input pairs are supported: :math:`f(p,T)`, :math:`f(p,h)`, :math:`f(p,\rho)`, +:math:`f(p,u)` and :math:`f(p,s)`. Some fluids also provide saturation state +information as :math:`f(Q,T)` with :math:`Q=0`. All functions iterate on :math:`f(p,T)` calls 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. @@ -55,7 +63,7 @@ for then compressible fluids. A call to the top-level function ``PropsSI`` can provide : density, heat capacity, internal energy, enthalpy, entropy, viscosity and thermal conductivity. Hence, the available output keys are: ``D``, ``C``, ``U``, ``H``, ``S``, ``V``, ``L``, -``Tmin``, ``Tmax`` and ``Psat``. +``Tmin`` and ``Tmax``. .. ipython:: @@ -67,20 +75,10 @@ the available output keys are: ``D``, ``C``, ``U``, ``H``, ``S``, ``V``, ``L``, #Specific heat capacity of Downtherm Q at 500 K and 1 atm In [1]: PropsSI('C','T',500,'P',101325,'INCOMP::DowQ') - #Internal energy of Downtherm Q at 500 K and 1 atm - In [1]: PropsSI('U','T',500,'P',101325,'INCOMP::DowQ') + In [1]: PropsSI('C','D',809.0659,'P',101325,'INCOMP::DowQ') - #Enthalpy of Downtherm Q at 500 K and 1 atm - In [1]: PropsSI('H','T',500,'P',101325,'INCOMP::DowQ') - - #Entropy of Downtherm Q at 500 K and 1 atm - In [1]: PropsSI('S','T',500,'P',101325,'INCOMP::DowQ') - - #Viscosity of Downtherm Q at 500 K and 1 atm - In [1]: PropsSI('V','T',500,'P',101325,'INCOMP::DowQ') - - #Thermal conductivity of Downtherm Q at 500 K and 1 atm - In [1]: PropsSI('L','T',500,'P',101325,'INCOMP::DowQ') + #Saturation pressure of Downtherm Q at 500 K + In [1]: PropsSI('P','T',500,'Q',0,'INCOMP::DowQ') #Minimum temperature for Downtherm Q In [1]: PropsSI('Tmin','T',0,'P',0,'INCOMP::DowQ') @@ -89,98 +87,40 @@ the available output keys are: ``D``, ``C``, ``U``, ``H``, ``S``, ``V``, ``L``, In [1]: PropsSI('Tmax','T',0,'P',0,'INCOMP::DowQ') -.. #Vapour pressure of Downtherm Q at 500 K, note the dummy pressure to work around https://github.com/CoolProp/CoolProp/issues/145 - In [1]: PropsSI('Psat','T',500,'P',1e8,'INCOMP::DowQ') - Mixture Examples ---------------- Almost the same syntax can be used for mixtures. Please note that the mixture interface developed for CoolProp 5 has not been ported to the incompressible -fluids, yet. For now, you have to use the `PropsSI` function with a special +fluids, yet. For now, you have to use the ``PropsSI`` function with a special 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 +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 like in `LiBr-0.23` or `LiBr\[0.23\]`. +form of percent, ``LiBr-23%``, or as a fraction like in ``LiBr-0.23`` or +``LiBr[0.23]``, which corresponds to the new mixture syntax in CoolProp5. +.. In addition to the properties available for the pure fluids (``D``, ``C``, + ``U``, ``H``, ``S``, ``V``, ``L``,``Tmin`` and ``Tmax``, some mixtures also + provide the freezing temperature ``Tfreeze`` as a function of composition. - - -All the brines and solutions can be accessed through the Props function. To use them, the fluid name -is something like ``"MEG-20%"`` which is a 20% by mass ethylene glycol solution. Note that these fluids -have an arbitrary reference state: Be careful with enthalpy and entropy calculations. Again, only -temperature and pressure inputs are supported directly to calculate the same subset of thermophysical -properties as above , namely: density, heat capacity, internal energy, enthalpy, entropy, viscosity -and thermal conductivity. Hence, the available output keys for the ``Props`` function are: "D", "C", -"U", "H", "S", "V", "L", "Tmin", Tmax" and "Tfreeze". An internal iteration allows us to use enthalpy -and pressure as inputs, but be aware of the reduced computational efficiency. - .. ipython:: In [1]: from CoolProp.CoolProp import PropsSI - #Specific heat 20% mass ethylene glycol solution at 300 K and 1 atm. - In [1]: PropsSI('C','T',300,'P',101.325,'INCOMP::MEG-20%') + #Density of a lithium bromide solution at 300 K and 1 atm. + In [1]: PropsSI('D','T',300,'P',101325,'INCOMP::LiBr[0.23]') + + #Specific heat capacity of a lithium bromide solution at 300 K and 1 atm + In [1]: PropsSI('C','T',300,'P',101325,'INCOMP::LiBr-0.23%') -The Different Fluids --------------------- - -The fluids implemented in CoolProp cover a wide range of industrial heat -transfer media. This database has initially been developed with refrigeration -systems in mind. That is why the majority of fluids are secondary refrigerants -with application temperatures close to the freezing point of water. Besides those, -there is also incompressible water, high temperature heat transfer oils and a -molten salt mixture for extreme temperatures. - -Besides the different technical data sheets and calculation tools provided by -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 `_ -:cite:`Skovrup2013` software, which contains data compiled by Morten Juel -Skovrup. It is provided free of charge by his employer `IPU `_. -.. _Pure: -.. csv-table:: All incompressible pure fluids included in CoolProp - :widths: 10, 35, 15, 20, 20 - :header-rows: 1 - :file: ../_static/fluid_properties/incompressible/table/pure-fluids.csv - - -There are also a number of water-based mixtures implemented in CoolProp. Most of them -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>`. - - -.. _MassMix: - -.. csv-table:: All incompressible mass-based binary mixtures included in CoolProp - :widths: 10, 30, 12, 12, 12, 12, 12 - :header-rows: 1 - :file: ../_static/fluid_properties/incompressible/table/mass-based-fluids.csv - -.. .. _MoleMix: - -.. .. csv-table:: All incompressible mole-based binary mixtures included in CoolProp - :widths: 10, 30, 12, 12, 12, 12, 12 - :header-rows: 1 - :file: ../_static/fluid_properties/incompressible/table/mole-based-fluids.csv - -.. _VoluMix: - -.. csv-table:: All incompressible volume-based binary mixtures included in CoolProp - :widths: 10, 30, 12, 12, 12, 12, 12 - :header-rows: 1 - :file: ../_static/fluid_properties/incompressible/table/volume-based-fluids.csv @@ -226,85 +166,12 @@ Equations Exp or log for visc, other poly or log poly +.. math:: + x(T) &= \sum_{i=0}^n C[i] \cdot T^i \\ + x(T) &= \exp\left( \frac{C[0]}{T+C[1]} - C[2] \right) \\ + x(T) &= \exp\left( \log \left( \left(T+C[0]\right)^{-1} + \left( T+C[0] \right)^{-2} \right) *C[1]+C[2] \right) \\ -Incompressible Liquids ----------------------- -There is also a selection of incompressible liquids implemented. These only allow for calls with -temperature and pressure as input and provide only a subset of thermophysical properties, namely: -density, heat capacity, internal energy, enthalpy, entropy, viscosity and thermal conductivity. -Hence, the available output keys for the ``Props`` function are: "D", "C", "U", "H", "S", "V", "L", -"Tmin", "Tmax" and "Psat". An internal iteration allows us to use enthalpy and pressure as inputs, -but be aware of the reduced computational efficiency. - -.. ipython:: - - In [1]: from CoolProp.CoolProp import PropsSI - - #Density of HFE-7100 at 300 K and 1 atm. - In [1]: PropsSI('D','T',300,'P',101325,'INCOMP::HFE') - - -For refrigeration applications, 8 fluids were implemented from Aake Melinder "Properties of -Secondary Working Fluids for Indirect Systems" published in 2010 by IIR and coefficients are -obtained from a fit between -80 and +100 degrees Celsius. - -========================== =================================================== -Fluid Name Description -========================== =================================================== -``DEB`` Diethyl Benzene -``HCM`` Hydrocarbon Mixture (Therminol D12 Solutia) -``HFE`` Hydrofluoroether HFE-7100 -``PMS1`` Polydimethylsiloxan 1. -``PMS2`` Polydimethylsiloxan 2. -``SAB`` Synthetic alkyl benzene -``HCB`` Hydrocarbon blend (Dynalene MV) -``TCO`` Terpene from citrus oils -========================== =================================================== - -Some additional secondary cooling fluids are based on data compiled by Morten Juel Skovrup in -his `SecCool software `_ -provided by his employer `IPU `_. Fits have been made according to the manufacturer -data stored in the sodtware. The Aspen Temper fluids are a blend of potassium formate and sodiumpropionate -and the Zitrec S group consists mainly of potassium acetate and potassium formate. - -========================== =================================================== -Fluid Name Description -========================== =================================================== -``AS10`` Aspen Temper -10 (-10 to +27.5 C) -``AS20`` Aspen Temper -20 (-20 to +27.5 C) -``AS30`` Aspen Temper -30 (-30 to +27.5 C) -``AS40`` Aspen Temper -40 (-40 to +27.5 C) -``AS55`` Aspen Temper -55 (-55 to +27.5 C) -``ZS10`` Zitrec S -10 (-10 to +85 C) -``ZS25`` Zitrec S -25 (-25 to +85 C) -``ZS40`` Zitrec S -40 (-40 to +85 C) -``ZS45`` Zitrec S -45 (-45 to +85 C) -``ZS55`` Zitrec S -55 (-55 to +85 C) -========================== =================================================== - -There are also a few high temperature heat transfer fluids with individual temperature ranges. Please -refer to the file IncompLiquid.h for a complete overview. For these fluids, information from commercial -data sheets was used to obtain coefficients. - -========================== =================================================== -Fluid Name Description -========================== =================================================== -``TD12`` Therminol D12 (-85 to +230 C) -``TVP1`` Therminol VP-1 (+12 to +397 C) -``T72`` Therminol 72 (-10 to +380 C) -``T66`` Therminol 66 (0 to +345 C) -``DowJ`` Dowtherm J (-80 to +345 C) -``DowQ`` Dowtherm Q (-35 to +360 C) -``TX22`` Texatherm 22 (0 to +350 C) -``NaK`` Nitrate Salt Blend (+300 to +600 C) -``XLT`` Syltherm XLT (-100 to +260 C) -``HC10`` Dynalene HC-10 (-10 to +218 C) -``HC20`` Dynalene HC-20 (-20 to +210 C) -``HC30`` Dynalene HC-30 (-30 to +210 C) -``HC40`` Dynalene HC-40 (-40 to +200 C) -``HC50`` Dynalene HC-50 (-50 to +210 C) -========================== =================================================== All fluids are implemented with polynomials for density and heat capacity with typically 4 coefficients and hence a third order polynomial. Thermal conductivity is a second order polynomial and viscosity and @@ -325,6 +192,8 @@ vapour pressure are exponential functions. \mu &= \exp\left( \frac{C_{\mu}[0]}{T+C_{\mu}[1]} - C_{\mu}[2] \right) \\ p_{sat} &= \exp\left( \frac{C_{sat}[0]}{T+C_{sat}[1]} - C_{sat}[2] \right) \\ +In some cases, the fit quality for the + Brines and Solutions -------------------- @@ -436,6 +305,76 @@ then yields the final factor :math:`D` to be multiplied with the other coefficie + + + + +The Different Fluids +-------------------- + +The fluids implemented in CoolProp cover a wide range of industrial heat +transfer media. This database has initially been developed with refrigeration +systems in mind. That is why the majority of fluids are secondary refrigerants +with application temperatures close to the freezing point of water. Besides those, +there is also incompressible water, high temperature heat transfer oils and a +molten salt mixture for extreme temperatures. + +Besides the different technical data sheets and calculation tools provided by +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 `_ +:cite:`Skovrup2013` software, which contains data compiled by Morten Juel +Skovrup. It is provided free of charge by his employer `IPU `_. + + +.. _Pure: + +.. csv-table:: All incompressible pure fluids included in CoolProp + :widths: 10, 35, 15, 20, 20 + :header-rows: 1 + :file: ../_static/fluid_properties/incompressible/table/pure-fluids.csv + + +There are also a number of water-based mixtures implemented in CoolProp. Most of them +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>`. + + +.. _MassMix: + +.. csv-table:: All incompressible mass-based binary mixtures included in CoolProp + :widths: 10, 30, 12, 12, 12, 12, 12 + :header-rows: 1 + :file: ../_static/fluid_properties/incompressible/table/mass-based-fluids.csv + +.. .. _MoleMix: + +.. .. csv-table:: All incompressible mole-based binary mixtures included in CoolProp + :widths: 10, 30, 12, 12, 12, 12, 12 + :header-rows: 1 + :file: ../_static/fluid_properties/incompressible/table/mole-based-fluids.csv + +.. _VoluMix: + +.. csv-table:: All incompressible volume-based binary mixtures included in CoolProp + :widths: 10, 30, 12, 12, 12, 12, 12 + :header-rows: 1 + :file: ../_static/fluid_properties/incompressible/table/volume-based-fluids.csv + + +For slurry ice, the concentration :math:`x` refers to the solid content and the +heat capacity includes the heat of fusion. It might be necessary to adjust the +solid content during heat transfer. The implementation is based on the data +available in `SecCool`_, +which was originally recorded at the `Danish Technological Institute (DTI) `_. + + +References +---------- + .. bibliography:: Incompressibles.bib :filter: docname in docnames :style: unsrt diff --git a/dev/incompressible_liquids/CPIncomp/WriterObjects.py b/dev/incompressible_liquids/CPIncomp/WriterObjects.py index 0fcb1f73..03795ecd 100644 --- a/dev/incompressible_liquids/CPIncomp/WriterObjects.py +++ b/dev/incompressible_liquids/CPIncomp/WriterObjects.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# -*- coding: utf8 -*- from __future__ import division, print_function import numpy as np @@ -11,10 +13,73 @@ from matplotlib.ticker import MaxNLocator from matplotlib.backends.backend_pdf import PdfPages import itertools import matplotlib -import csv from CoolProp.BibtexParser import BibTeXerClass from warnings import warn +# See: https://docs.python.org/2/library/csv.html#csv-examples +import csv, codecs, 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) + + + class SolutionDataWriter(object): """ A base class that defines all the variables needed @@ -1126,26 +1191,26 @@ class SolutionDataWriter(object): return rst def table_div(self, max_cols, header_flag=1, indent=2): - out = "" + out = u"" for i in range(indent): - out += " " + out += u" " if header_flag == 1: - style = "=" + style = u"=" else: - style = "-" + style = u"-" for max_col in max_cols: - out += max_col * style + " " - out += "\n" + out += max_col * style + u" " + out += u"\n" return out def normalize_row(self, row, max_cols, indent=2): - r = "" + r = u"" for i in range(indent): - r += " " + r += u" " for i, max_col in enumerate(max_cols): - r += row[i] + (max_col - len(row[i]) + 1) * " " - return r + "\n" + r += row[i] + (max_col - len(row[i]) + 1) * u" " + return r + u"\n" def writeTextToFile(self, path,text): @@ -1153,19 +1218,21 @@ class SolutionDataWriter(object): if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) with open(path, 'w') as f: - f.write(text) + f.write(text.encode('utf-8')) + return True - def writeTxtTableToFile(self, path,table,head=""): - if not head == "": - return self.writeTextToFile(path+".txt", head+"\n\n"+self.make_table(table)) + def writeTxtTableToFile(self, path,table,head=u""): + if not head == u"": + return self.writeTextToFile(path+".txt", head+u"\n\n"+self.make_table(table)) return self.writeTextToFile(path+".txt", self.make_table(table)) def writeCsvTableToFile(self, path,table): if not os.path.exists(os.path.dirname(path+".csv")): os.makedirs(os.path.dirname(path+".csv")) with open(path+".csv", 'wb') as f: - writer = csv.writer(f) + #writer = csv.writer(f) + writer = UnicodeWriter(f) writer.writerows(table) return True @@ -1203,20 +1270,20 @@ class SolutionDataWriter(object): # link = "{0}".format(text) # pass # TODO: Fix this! - link = ":download:`{0}<{1}>`".format(text,target) + link = u":download:`{0}<{1}>`".format(text,target) return link def m(self, math): - text = ":math:`{0}`".format(math) + text = u":math:`{0}`".format(math) return text def c(self, number): #text = "{0:5.2f} |degC|".format(self.checkForNumber(number)-273.15) - text = "{0:5.2f}".format(self.checkForNumber(number)-273.15) + text = u"{0:5.2f}".format(self.checkForNumber(number)-273.15) return text def x(self, number): - text = "{0:3.2f}".format(self.checkForNumber(number)) + text = u"{0:3.2f}".format(self.checkForNumber(number)) return text @@ -1229,9 +1296,9 @@ class SolutionDataWriter(object): if np.any(xmin>0.0) and np.any(xmax<1.0): use_x = True else: use_x = False - header = ['Name', 'Description', 'Reference', \ - self.m('T_{min}')+" (|degC|)", self.m('T_{max}')+" (|degC|)"] - if use_x: header.extend([self.m('x_{min}'), self.m('x_{max}')]) + header = [u'Name', u'Description', u'Reference', \ + self.m(u'T_\\text{min}')+u" (°C)", self.m(u'T_\\text{max}')+u" (°C)"] + if use_x: header.extend([self.m(u'x_\\text{min}'), self.m(u'x_\\text{max}')]) testTable = [] testTable.append(header) # Headline diff --git a/dev/incompressible_liquids/json/AEG.json b/dev/incompressible_liquids/json/AEG.json index 5dbb2abe..4ce8eac2 100644 --- a/dev/incompressible_liquids/json/AEG.json +++ b/dev/incompressible_liquids/json/AEG.json @@ -82,7 +82,7 @@ [ -9.073173e-07, 4.118599e-06, - -4.391163e-06, + -4.391164e-06, 0.000000e+00, 0.000000e+00, 0.000000e+00 diff --git a/dev/incompressible_liquids/json/APG.json b/dev/incompressible_liquids/json/APG.json index cea76439..d37cb1a0 100644 --- a/dev/incompressible_liquids/json/APG.json +++ b/dev/incompressible_liquids/json/APG.json @@ -80,7 +80,7 @@ 0.000000e+00 ], [ - 3.270564e-08, + 3.270563e-08, -2.261472e-07, 3.368862e-07, 0.000000e+00, diff --git a/dev/incompressible_liquids/json/ExampleDigital.json b/dev/incompressible_liquids/json/ExampleDigital.json index 27b0714b..5129879e 100644 --- a/dev/incompressible_liquids/json/ExampleDigital.json +++ b/dev/incompressible_liquids/json/ExampleDigital.json @@ -76,8 +76,8 @@ ], [ -4.117538e-10, - 3.193137e-09, - -3.138206e-09, + 3.193145e-09, + -3.138209e-09, 0.000000e+00, 0.000000e+00, 0.000000e+00 @@ -160,9 +160,9 @@ 0.000000e+00 ], [ - -1.548862e-10, - 8.615137e-10, - -8.067025e-11, + -1.548841e-10, + 8.615147e-10, + -8.067086e-11, 0.000000e+00, 0.000000e+00, 0.000000e+00 diff --git a/dev/incompressible_liquids/json/FRE.json b/dev/incompressible_liquids/json/FRE.json index 171f96e9..b5b23321 100644 --- a/dev/incompressible_liquids/json/FRE.json +++ b/dev/incompressible_liquids/json/FRE.json @@ -86,9 +86,9 @@ 0.000000e+00 ], [ - -6.379647e-08, + -6.379657e-08, 3.363858e-07, - -3.132405e-07, + -3.132406e-07, 0.000000e+00, 0.000000e+00, 0.000000e+00 @@ -124,8 +124,8 @@ ], [ -2.058397e-06, - -3.348859e-10, - 5.467784e-10, + -3.348864e-10, + 5.467785e-10, 0.000000e+00, 0.000000e+00, 0.000000e+00 diff --git a/dev/incompressible_liquids/json/GKN.json b/dev/incompressible_liquids/json/GKN.json index 1d053bcd..ec7a0761 100644 --- a/dev/incompressible_liquids/json/GKN.json +++ b/dev/incompressible_liquids/json/GKN.json @@ -45,7 +45,7 @@ [ 1.059366e-09, -2.212375e-09, - 2.522431e-10, + 2.522430e-10, 0.000000e+00, 0.000000e+00, 0.000000e+00 diff --git a/dev/incompressible_liquids/json/HC20.json b/dev/incompressible_liquids/json/HC20.json index 11541c8f..7ebecfa0 100644 --- a/dev/incompressible_liquids/json/HC20.json +++ b/dev/incompressible_liquids/json/HC20.json @@ -16,7 +16,7 @@ 1.000000e-03 ], [ - 4.945495e-17 + 4.945410e-17 ], [ 4.446923e-20 diff --git a/dev/incompressible_liquids/json/HC30.json b/dev/incompressible_liquids/json/HC30.json index fcd9bfe8..71cfef68 100644 --- a/dev/incompressible_liquids/json/HC30.json +++ b/dev/incompressible_liquids/json/HC30.json @@ -16,7 +16,7 @@ 1.000000e-03 ], [ - 3.613874e-17 + 3.613676e-17 ], [ 3.832824e-20 diff --git a/dev/incompressible_liquids/json/HC40.json b/dev/incompressible_liquids/json/HC40.json index ef768f13..9a2a6a61 100644 --- a/dev/incompressible_liquids/json/HC40.json +++ b/dev/incompressible_liquids/json/HC40.json @@ -16,7 +16,7 @@ 1.000000e-03 ], [ - 9.106767e-17 + 9.107021e-17 ], [ 1.979940e-20 diff --git a/dev/incompressible_liquids/json/HFE2.json b/dev/incompressible_liquids/json/HFE2.json index 80c41f99..28de4644 100644 --- a/dev/incompressible_liquids/json/HFE2.json +++ b/dev/incompressible_liquids/json/HFE2.json @@ -33,7 +33,7 @@ -2.269000e+00 ], [ - -1.492754e-13 + -1.493085e-13 ], [ 1.637145e-16 @@ -65,7 +65,7 @@ 2.000000e+00 ], [ - 1.348892e-13 + 1.348812e-13 ], [ -2.528359e-16 diff --git a/dev/incompressible_liquids/json/LiBr.json b/dev/incompressible_liquids/json/LiBr.json index ed24e075..cf5c685a 100644 --- a/dev/incompressible_liquids/json/LiBr.json +++ b/dev/incompressible_liquids/json/LiBr.json @@ -160,7 +160,7 @@ 0.000000e+00 ], [ - 3.074006e-05, + 3.074005e-05, 4.644860e-04, -4.128601e-04, 0.000000e+00, diff --git a/dev/incompressible_liquids/json/MEA2.json b/dev/incompressible_liquids/json/MEA2.json index 0455b474..6f66cfd6 100644 --- a/dev/incompressible_liquids/json/MEA2.json +++ b/dev/incompressible_liquids/json/MEA2.json @@ -80,7 +80,7 @@ 0.000000e+00 ], [ - -1.261406e-06, + -1.261407e-06, 1.595687e-04, -2.874999e-04, 0.000000e+00, diff --git a/dev/incompressible_liquids/json/MMG2.json b/dev/incompressible_liquids/json/MMG2.json index c916d78a..6771f6ce 100644 --- a/dev/incompressible_liquids/json/MMG2.json +++ b/dev/incompressible_liquids/json/MMG2.json @@ -41,9 +41,9 @@ 0.000000e+00 ], [ - -3.201909e-14, - -8.491526e-14, - 1.265223e-12, + -3.116864e-14, + -8.496811e-14, + 1.264271e-12, 0.000000e+00, 0.000000e+00, 0.000000e+00 @@ -78,9 +78,9 @@ 0.000000e+00 ], [ - 1.986411e-11, - -3.429773e-10, - 7.354027e-10, + 1.984946e-11, + -3.372422e-10, + 7.093277e-10, 0.000000e+00, 0.000000e+00, 0.000000e+00 @@ -130,9 +130,9 @@ 0.000000e+00 ], [ - 5.248779e-11, - -7.030447e-10, - 1.861376e-09, + 5.482548e-11, + -6.893357e-10, + 1.956098e-09, 0.000000e+00, 0.000000e+00, 0.000000e+00 @@ -167,9 +167,9 @@ 0.000000e+00 ], [ - -1.262879e-15, - -4.101099e-13, - 1.456601e-12, + -9.388323e-15, + -4.140820e-13, + 1.454213e-12, 0.000000e+00, 0.000000e+00, 0.000000e+00 diff --git a/dev/incompressible_liquids/json/MNA2.json b/dev/incompressible_liquids/json/MNA2.json index 35d67c0b..419bf94a 100644 --- a/dev/incompressible_liquids/json/MNA2.json +++ b/dev/incompressible_liquids/json/MNA2.json @@ -39,8 +39,8 @@ ], [ 5.963914e-14, - -1.171232e-12, - 3.544925e-12, + -1.171287e-12, + 3.544939e-12, 0.000000e+00, 0.000000e+00, 0.000000e+00 @@ -75,9 +75,9 @@ 0.000000e+00 ], [ - 2.382838e-11, - -4.371017e-10, - 2.078221e-09, + 2.382339e-11, + -4.369353e-10, + 2.078946e-09, 0.000000e+00, 0.000000e+00, 0.000000e+00 @@ -129,7 +129,7 @@ [ -7.407941e-11, 1.506720e-09, - -5.254342e-09, + -5.256161e-09, 0.000000e+00, 0.000000e+00, 0.000000e+00 @@ -164,9 +164,9 @@ 0.000000e+00 ], [ - 1.144571e-14, - -5.037253e-13, - 2.031073e-12, + 1.141968e-14, + -5.033025e-13, + 2.031147e-12, 0.000000e+00, 0.000000e+00, 0.000000e+00 diff --git a/dev/incompressible_liquids/json/PK2.json b/dev/incompressible_liquids/json/PK2.json index 4dd4453d..68197524 100644 --- a/dev/incompressible_liquids/json/PK2.json +++ b/dev/incompressible_liquids/json/PK2.json @@ -80,7 +80,7 @@ 0.000000e+00 ], [ - 7.584600e-07, + 7.584599e-07, -1.681891e-06, 8.927989e-07, 0.000000e+00, diff --git a/dev/incompressible_liquids/json/PKL.json b/dev/incompressible_liquids/json/PKL.json index 3d853e68..a4439993 100644 --- a/dev/incompressible_liquids/json/PKL.json +++ b/dev/incompressible_liquids/json/PKL.json @@ -80,7 +80,7 @@ 0.000000e+00 ], [ - -8.851911e-08, + -8.851905e-08, 8.435685e-07, -1.848113e-06, 0.000000e+00, diff --git a/dev/incompressible_liquids/json/TY10.json b/dev/incompressible_liquids/json/TY10.json index 879c2948..d23f9857 100644 --- a/dev/incompressible_liquids/json/TY10.json +++ b/dev/incompressible_liquids/json/TY10.json @@ -33,10 +33,10 @@ -4.000000e-01 ], [ - -2.441934e-14 + -2.441148e-14 ], [ - 4.087442e-17 + 4.090153e-17 ] ], "type": "polynomial" diff --git a/dev/incompressible_liquids/json/TY15.json b/dev/incompressible_liquids/json/TY15.json index 6405b29b..e9f5f6c1 100644 --- a/dev/incompressible_liquids/json/TY15.json +++ b/dev/incompressible_liquids/json/TY15.json @@ -16,7 +16,7 @@ 7.000000e-04 ], [ - 6.853149e-17 + 6.853806e-17 ], [ -2.456396e-20 @@ -33,7 +33,7 @@ -4.000000e-01 ], [ - -8.005915e-15 + -8.003880e-15 ], [ -3.881444e-17 diff --git a/dev/incompressible_liquids/json/TY20.json b/dev/incompressible_liquids/json/TY20.json index 3a8199a5..4b6364ee 100644 --- a/dev/incompressible_liquids/json/TY20.json +++ b/dev/incompressible_liquids/json/TY20.json @@ -33,7 +33,7 @@ -4.000000e-01 ], [ - 2.591269e-14 + 2.590801e-14 ], [ -5.114724e-17 diff --git a/dev/incompressible_liquids/json/XLT2.json b/dev/incompressible_liquids/json/XLT2.json index 4ee946bd..ec2318af 100644 --- a/dev/incompressible_liquids/json/XLT2.json +++ b/dev/incompressible_liquids/json/XLT2.json @@ -65,7 +65,7 @@ 2.100000e+00 ], [ - 8.650944e-15 + 8.662076e-15 ], [ -1.546072e-16 diff --git a/dev/incompressible_liquids/json/ZAC.json b/dev/incompressible_liquids/json/ZAC.json index dbad0799..4af4b9ad 100644 --- a/dev/incompressible_liquids/json/ZAC.json +++ b/dev/incompressible_liquids/json/ZAC.json @@ -38,7 +38,7 @@ 0.000000e+00 ], [ - 7.748626e-09, + 7.748627e-09, -1.399289e-07, 2.343560e-07, 0.000000e+00, diff --git a/dev/incompressible_liquids/json/ZS40.json b/dev/incompressible_liquids/json/ZS40.json index ea95e2a7..a5efc609 100644 --- a/dev/incompressible_liquids/json/ZS40.json +++ b/dev/incompressible_liquids/json/ZS40.json @@ -36,7 +36,7 @@ -4.200618e-10 ], [ - 4.712469e-13 + 4.712470e-13 ] ], "type": "polynomial" diff --git a/dev/incompressible_liquids/json/ZS45.json b/dev/incompressible_liquids/json/ZS45.json index d7466db8..ce9ad2c3 100644 --- a/dev/incompressible_liquids/json/ZS45.json +++ b/dev/incompressible_liquids/json/ZS45.json @@ -33,7 +33,7 @@ -5.524646e-01 ], [ - -3.713730e-11 + -3.713729e-11 ], [ 3.828340e-14 diff --git a/dev/incompressible_liquids/json/ZS55.json b/dev/incompressible_liquids/json/ZS55.json index 02edaf92..f408acd2 100644 --- a/dev/incompressible_liquids/json/ZS55.json +++ b/dev/incompressible_liquids/json/ZS55.json @@ -33,10 +33,10 @@ -6.044286e-01 ], [ - -2.253584e-12 + -2.253580e-12 ], [ - -3.942105e-15 + -3.942159e-15 ] ], "type": "polynomial" diff --git a/src/Backends/Incompressible/IncompressibleBackend.cpp b/src/Backends/Incompressible/IncompressibleBackend.cpp index ce233d0f..2b49a6af 100644 --- a/src/Backends/Incompressible/IncompressibleBackend.cpp +++ b/src/Backends/Incompressible/IncompressibleBackend.cpp @@ -67,7 +67,7 @@ void IncompressibleBackend::update(CoolProp::input_pairs input_pair, double valu this->_phase = iphase_liquid; if (get_debug_level()>=50) std::cout << format("Incompressible backend: Phase type is %d ",this->_phase) << std::endl; - switch (input_pair) + switch (input_pair) { case PT_INPUTS: { _p = value1; @@ -94,6 +94,12 @@ void IncompressibleBackend::update(CoolProp::input_pairs input_pair, double valu _T = this->HmassP_flash(value1, value2); break; } + case QT_INPUTS: { + if (value1!=0) {throw ValueError("Incompressible fluids can only handle saturated liquid, Q=0.");} + _T = value2; + _p = fluid->psat(value2, _fractions[0]); + break; + } default: { throw ValueError( format("This pair of inputs [%s] is not yet supported", @@ -139,7 +145,11 @@ void IncompressibleBackend::set_mass_fractions(const std::vector &m this->_fractions = std::vector(1,0); if (get_debug_level()>=20) std::cout << format("Incompressible backend: Overwriting fractions for pure fluid with %s -> %s",vec_to_string(mass_fractions).c_str(),vec_to_string(this->_fractions).c_str()) << std::endl; } else if (fluid->getxid()==IFRAC_MASS) { - this->_fractions = mass_fractions; + if (this->_fractions[0]!=mass_fractions[0]) { + if (get_debug_level()>=20) std::cout << format("Incompressible backend: Updating the mass fractions triggered a change in reference state %s -> %s",vec_to_string(mass_fractions).c_str(),vec_to_string(this->_fractions).c_str()) << std::endl; + this->_fractions = mass_fractions; + fluid->set_reference_state(fluid->getTref(), fluid->getpref(), this->_fractions[0], fluid->gethref(), fluid->getsref()); + } } else { this->_fractions.clear(); for (std::size_t i = 0; i < mass_fractions.size(); i++) { diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index bde623cf..bd90541b 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -491,7 +491,7 @@ bool IncompressibleFluid::checkP(double T, double p, double x) { double ps = 0.0; if (p_sat.type!=IncompressibleData::INCOMPRESSIBLE_NOT_SET) ps = psat(T, x); if (p < 0.0) throw ValueError(format("You cannot use negative pressures: %f < %f. ", p, 0.0)); - if (ps>0.0 && p < ps) throw ValueError(format("Equations are valid for liquid phase only: %f < %f (psat). ", p, ps)); + if (ps> 0.0 && p < ps) throw ValueError(format("Equations are valid for liquid phase only: %f < %f (psat). ", p, ps)); return true; }