From 99e08bf252f8bb90ed8519bc5b52db5d485cf51d Mon Sep 17 00:00:00 2001 From: jowr Date: Mon, 7 Jul 2014 12:11:46 +0200 Subject: [PATCH] Added conversion function for Melinder solutions --- .../data_incompressible.py | 166 +++++++++++++++++- .../json_incompressible.py | 21 ++- 2 files changed, 179 insertions(+), 8 deletions(-) diff --git a/dev/IncompressibleLiquids/data_incompressible.py b/dev/IncompressibleLiquids/data_incompressible.py index b1892872..5b83fc9a 100644 --- a/dev/IncompressibleLiquids/data_incompressible.py +++ b/dev/IncompressibleLiquids/data_incompressible.py @@ -738,19 +738,19 @@ class SolutionData(object): -class SecCoolData(SolutionData): +class CoefficientData(SolutionData): """ - Ethanol-Water mixture according to Melinder book - Source: SecCool Software + A class to convert parameter arrays from different other sources """ def __init__(self): SolutionData.__init__(self) - self.reference = "SecCool software" + self.reference = "Some other software" def convertSecCoolArray(self, array): if len(array)!=18: raise ValueError("The lenght is not equal to 18!") + self.reference = "SecCool software" array = np.array(array) tmp = np.zeros((4,6)) @@ -785,15 +785,89 @@ class SecCoolData(SolutionData): return tmp -class SecCoolExample(SecCoolData): + def convertMelinderArray(self, array): + if len(array)!=18: + raise ValueError("The lenght is not equal to 18!") + + self.reference = "Melinder Book" + array = np.array(array) + tmp = np.zeros((6,4)) + + tmp[0][0] = array[0] + tmp[0][1] = array[6] + tmp[0][2] = array[11] + tmp[0][3] = array[15] + + tmp[1][0] = array[1] + tmp[1][1] = array[7] + tmp[1][2] = array[12] + tmp[1][3] = array[16] + + tmp[2][0] = array[2] + tmp[2][1] = array[8] + tmp[2][2] = array[13] + tmp[2][3] = array[17] + + tmp[3][0] = array[3] + tmp[3][1] = array[9] + tmp[3][2] = array[14] + + tmp[4][0] = array[4] + tmp[4][1] = array[10] + + tmp[5][0] = array[5] + + # Concentration is no longer handled in per cent! + for i in range(6): + tmp[i] *= 100.0**i + + return tmp.T + + def convertMelinderMatrix(self, array): + """Function to convert the full coefficient array + from the very first CoolProp implementation + based on the book by Melinder""" + if len(array)!=18: + raise ValueError("The lenght is not equal to 18!") + if len(array[0])!=5: + raise ValueError("The lenght is not equal to 5!") + array = np.array(array) + tmp = np.zeros((18,5)) + + for j in range(5): + tmp[ 0][j] = array[ 0][j] + tmp[ 1][j] = array[ 4][j] + tmp[ 2][j] = array[ 8][j] + tmp[ 3][j] = array[12][j] + tmp[ 4][j] = array[15][j] + tmp[ 5][j] = array[17][j] + tmp[ 6][j] = array[ 1][j] + tmp[ 7][j] = array[ 5][j] + tmp[ 8][j] = array[ 9][j] + tmp[ 9][j] = array[13][j] + tmp[10][j] = array[16][j] + tmp[11][j] = array[ 2][j] + tmp[12][j] = array[ 6][j] + tmp[13][j] = array[10][j] + tmp[14][j] = array[14][j] + tmp[15][j] = array[ 3][j] + tmp[16][j] = array[ 7][j] + tmp[17][j] = array[11][j] + + return tmp + + + + +class SecCoolExample(CoefficientData): """ Ethanol-Water mixture according to Melinder book Source: SecCool Software """ def __init__(self): - SecCoolData.__init__(self) + CoefficientData.__init__(self) self.name = "SecCoolExample" - self.description = "Methanol solution" + self.description = "Ethanol solution" #self.reference = "SecCool software" self.Tmax = 20 + 273.15 self.Tmin = -50 + 273.15 @@ -895,6 +969,84 @@ class SecCoolExample(SecCoolData): -1.1040507200, -0.0120762281, -9.343458E-05]) + + +class MelinderExample(CoefficientData): + """ + Methanol-Water mixture according to Melinder book + Source: Book + """ + def __init__(self): + CoefficientData.__init__(self) + self.name = "MelinderExample" + self.description = "Methanol solution" + self.reference = "Melinder-BOOK-2010" + self.Tmax = 40 + 273.15 + self.Tmin = -50 + 273.15 + self.xmax = 0.6 + self.xmin = 0.0 + self.TminPsat = self.Tmax + + self.Tbase = 3.5359 + 273.15; + self.xbase = 30.5128 / 100.0 + + coeffs = np.array([ + [-26.29 , 958.1 ,3887 , 0.4175 , 1.153 ], + [ -0.000002575 , -0.4151 , 7.201 , 0.0007271 , -0.03866 ], + [ -0.000006732 , -0.002261 , -0.08979 , 0.0000002823 , 0.0002779 ], + [ 0.000000163 , 0.0000002998 , -0.000439 , 0.000000009718 , -0.000001543 ], + [ -1.187 , -1.391 , -18.5 , -0.004421 , 0.005448 ], + [ -0.00001609 , -0.0151 , 0.2984 , -0.00002952 , 0.0001008 ], + [ 0.000000342 , 0.0001113 , -0.001865 , 0.00000007336 , -0.000002809 ], + [ 0.0000000005687, -0.0000003264 , -0.00001718 , 0.0000000004328 , 0.000000009811 ], + [ -0.01218 , -0.01105 , -0.03769 , 0.00002044 , -0.0005552 ], + [ 0.0000003865 , 0.0001828 , -0.01196 , 0.0000003413 , 0.000008384 ], + [ 0.000000008768 , -0.000001641 , 0.00009801 , -0.000000003665 , -0.00000003997 ], + [ -0.0000000002095, 0.0000000151 , 0.000000666 , -0.00000000002791 , -0.0000000003466 ], + [ -0.00006823 , -0.0001208 , -0.003776 , 0.0000002943 , 0.000003038 ], + [ 0.00000002137 , 0.000002992 , -0.00005611 , -0.0000000009646 , -0.00000007435 ], + [ -0.0000000004271, 0.000000001455, -0.0000007811, 0.00000000003174 , 0.0000000007442 ], + [ 0.0000001297 , 0.000004927 , -0.0001504 , -0.0000000008666 , 0.00000006669 ], + [ -0.0000000005407, -0.0000001325 , 0.000007373 , -0.0000000000004573, -0.0000000009105 ], + [ 0.00000002363 , -0.00000007727 , 0.000006433 , -0.0000000002033 , -0.0000000008472 ] + ]) + + coeffs = self.convertMelinderMatrix(coeffs).T + + self.T_freeze.type = self.T_freeze.INCOMPRESSIBLE_POLYNOMIAL + self.T_freeze.coeffs = self.convertMelinderArray(coeffs[0]) + + self.density.type = self.density.INCOMPRESSIBLE_POLYNOMIAL + self.density.coeffs = self.convertMelinderArray(coeffs[1]) + + self.specific_heat.type = self.specific_heat.INCOMPRESSIBLE_POLYNOMIAL + self.specific_heat.coeffs = self.convertMelinderArray(coeffs[2]) + + self.conductivity.type = self.conductivity.INCOMPRESSIBLE_POLYNOMIAL + self.conductivity.coeffs = self.convertMelinderArray(coeffs[3]) + + self.viscosity.type = self.viscosity.INCOMPRESSIBLE_POLYNOMIAL + self.viscosity.coeffs = self.convertMelinderArray(coeffs[4]) + + + + + + + + + + + + + + + + + + + + class PureExample(SolutionData): diff --git a/dev/IncompressibleLiquids/json_incompressible.py b/dev/IncompressibleLiquids/json_incompressible.py index e71e5572..00030ba2 100644 --- a/dev/IncompressibleLiquids/json_incompressible.py +++ b/dev/IncompressibleLiquids/json_incompressible.py @@ -130,7 +130,7 @@ class SolutionDataWriter(object): dump = json.dumps(jobj, indent = 2, sort_keys = True) - print dump + #print dump fp = open(jobj['name']+'.json', 'w') fp.write(dump) @@ -172,6 +172,7 @@ if __name__ == '__main__': data = PureExample() print data.Tbase, data.xbase writer.fitAll(data) + writer.toJSON(data) print data.Tbase, data.xbase print data.density.data[0][0] @@ -185,6 +186,7 @@ if __name__ == '__main__': data = SolutionExample() print data.Tbase, data.xbase writer.fitAll(data) + writer.toJSON(data) print data.Tbase, data.xbase print data.density.data[0][0] @@ -194,8 +196,25 @@ if __name__ == '__main__': print np.polynomial.polynomial.polyval2d(data.temperature.data[-1]-data.Tbase, data.concentration.data[-1]-data.xbase, data.density.coeffs) print data.rho(data.temperature.data[-1], 0.0, data.concentration.data[-1]) + data = MelinderExample() + print data.Tbase, data.xbase + #writer.fitAll(data) + writer.toJSON(data) + print data.Tbase, data.xbase + #print data.density.data[0][0] + #print np.polynomial.polynomial.polyval2d(data.temperature.data[0]-data.Tbase, data.concentration.data[0]-data.xbase, data.density.coeffs) + #print data.rho(data.temperature.data[0], 0.0, data.concentration.data[0]) + #print data.density.data[-1][-1] + #print np.polynomial.polynomial.polyval2d(data.temperature.data[-1]-data.Tbase, data.concentration.data[-1]-data.xbase, data.density.coeffs) + #print data.rho(data.temperature.data[-1], 0.0, data.concentration.data[-1]) + import CoolProp.CoolProp as CP + T = data.Tbase + p = 10e5 + #data.xbase = data.xbase*100.0 + x = data.xbase+0.05 + print data.rho(T, p, x), CP.Props('D','T',T,'P',p,'MMA-35.5128%')