Esempio n. 1
0
def testState():
    s1 = FluidState('ParaHydrogen')
    s1.update('P', 700e5, 'T', 288)
    print("p={0}".format(s1.p()))
    print("T={0}".format(s1.T()))
    print("rho={0}".format(s1.rho()))
    print("h={0}".format(s1.h()))
    print("s={0}".format(s1.s()))
    print("cp={0}".format(s1.cp()))
    print("cv={0}".format(s1.cv()))
    print("gamma={0}".format(s1.gamma()))
    print("dpdt_v={0}".format(s1.dpdt_v()))
    print("dpdv_t={0}".format(s1.dpdv_t()))
    print("beta={0}".format(s1.beta()))
    print("mu={0}".format(s1.mu()))
    print("lambfa={0}".format(s1.cond()))
    print("Pr={0}".format(s1.Pr()))

    s2 = FluidState('ParaHydrogen')
    s2.update_Tp(s1.T(), s1.p())
    print("update_Tp rho={0}".format(s2.rho()))
    s3 = FluidState('ParaHydrogen')
    s3.update_Trho(s1.T(), s1.rho())
    print("update_Trho p={0}".format(s3.p()))
    s4 = FluidState('ParaHydrogen')
    s4.update_prho(s1.p(), s1.rho())
    print("update_prho T={0}".format(s4.T()))
    s5 = FluidState('ParaHydrogen')
    s5.update_ph(s1.p(), s1.h())
    print("update_ph ={0}".format(s5.T()))
    s6 = FluidState('ParaHydrogen')
    s6.update_ps(s1.p(), s1.s())
    print("update_ps T={0}".format(s6.T()))
    s7 = FluidState('ParaHydrogen')
    s7.update_pq(1e5, 0)
    print("update_pq T={0}".format(s7.T()))
    s8 = FluidState('ParaHydrogen')
    s8.update_Tq(25, 0)
    print("update_Tq p={0}".format(s8.p()))
    print('--------------------')
    print('Initialize state from fluid')
    h2 = Fluid('ParaHydrogen')
    s9 = FluidState(h2)
    s9.update_Tp(s1.T(), s1.p())
    print("rho={0}".format(s9.rho()))
Esempio n. 2
0
    def compute(self):
        R = 8.314462
        mMol = Fluid(self.fluidName).molarMass / 1e3
        self.T = (self.T1 + self.T2) / 2
        state = FluidState(self.fluidName)
        state.update_Tp(self.T, self.p)

        self.rho = state.rho
        self.mu = state.mu
        self.c = np.sqrt(8 * R * state.T / (np.pi * mMol))
        self.l = (2 * self.mu) / (state.rho * self.c)

        self.Kn = self.l / self.d
        self.f = 16. / 15 * (1 / state.Pr) * (state.gamma / (state.gamma + 1))
        self.fct = 1. / (1 + 15. / 4 * self.Kn)  #* self.f

        self.qDot = self.fct * state.cond / self.d * np.abs(self.T1 - self.T2)

        Rg = R / mMol
        self.qDotFM = (state.cp - Rg / 2) * state.p / np.sqrt(
            2 * np.pi * Rg * self.T) * np.abs(self.T1 - self.T2)
Esempio n. 3
0
def testFluid():
    #f = Fluid('R134a')
    f = Fluid('Hydrogen')
    #f = Fluid('Water')
    BibTexKeys = [
        "EOS", "CP0", "VISCOSITY", "CONDUCTIVITY", "ECS_LENNARD_JONES",
        "ECS_FITS", "SURFACE_TENSION"
    ]
    for key in BibTexKeys:
        print("{0} : {1}".format(key, f.BibTeXKey(key)))
    print("Name: {0}".format(f.name()))
    print("Aliases: {0}".format(f.aliases()))
    print("{0} : {1}".format('EOS reference', f.EOSReference()))
    print("{0} : {1}".format('Transpor reference', f.TransportReference()))

    print("{0} : {1} [g/mol]".format('Molar mass', f.molarMass()))
    print("{0} : {1}".format('Accentric factor', f.accentricFactor()))
    print("{0} : {1}".format('Critical point', f.critical()))
    print("{0} : {1}".format('Tripple point', f.tripple()))
    print("{0} : {1}".format('Fluid limits', f.fluidLimits()))
    print("CAS: {0}".format(f.CAS()))
    print("ASHRAE34: {0}".format(f.ASHRAE34()))
    p = (f.critical()['p'] + f.tripple()['p']) / 2
    print("Saturation @ {0} bar {1}".format(p / 1e5, f.saturation_p(p)))

    T = (f.critical()['T'] + f.tripple()['T']) / 2
    print("Saturation @ {0} K {1}".format(T, f.saturation_T(T)))
Esempio n. 4
0
class ThermodynamicalCycle(NumericalModel):
	abstract = True
	#================ Inputs ================#
	# Cycle diagram
	cycleDiagram = F.SubModelGroup(TC.CycleDiagram, 'inputs', label = 'Diagram settings')
	# Solver settings
	solver = F.SubModelGroup(CycleIterator, 'solverSettings', label = 'Solver')
	#================ Results ================#
	#---------------- Fields ----------------#
	cycleStatesTable = F.TableView((
		('T', F.Quantity('Temperature', default = (1, 'degC'))),
		('p', F.Quantity('Pressure', default = (1, 'bar'))),
		('rho', F.Quantity('Density', default = (1, 'kg/m**3'))),
		('h', F.Quantity('SpecificEnthalpy', default = (1, 'kJ/kg'))),
		('s', F.Quantity('SpecificEntropy', default = (1, 'kJ/kg-K'))),
		('q', F.Quantity()),
		('dT', F.Quantity('TemperatureDifference', default = (1, 'degC'))),
		('mDot', F.Quantity('MassFlowRate', default = (1, 'kg/min'))),
		('b', F.Quantity('SpecificEnergy', default = (1, 'kJ/kg')))
		), label="Cycle states")
						
	cycleStates = F.ViewGroup([cycleStatesTable], label = "States")
	resultStates = F.SuperGroup([cycleStates], label="States")
	#---------------- Cycle diagram -----------#
	phDiagram = F.Image(default='')
	cycleDiagramVG = F.ViewGroup([phDiagram], label = "P-H Diagram")
	resultDiagrams = F.SuperGroup([cycleDiagramVG], label = "Diagrams")
	#---------------- Convergence parameters -----------#
	residualPlot = F.PlotView((
	                            ('iteration #', F.Quantity('Dimensionless')),
	                            ('h change', F.Quantity('SpecificEnthalpy'))
	                        	),
								label = 'Residual (plot)', ylog = True)
	iterationTable = F.TableView((
	                            ('h1', F.Quantity('SpecificEnthalpy')),
	                            ('h2', F.Quantity('SpecificEnthalpy')),
	                            ('h3', F.Quantity('SpecificEnthalpy')),
	                            ('h4', F.Quantity('SpecificEnthalpy')),
	                            ('h5', F.Quantity('SpecificEnthalpy')),
	                            ('h6', F.Quantity('SpecificEnthalpy')),
	                            ('h7', F.Quantity('SpecificEnthalpy')),
	                            ('h8', F.Quantity('SpecificEnthalpy')),
	                            ('h9', F.Quantity('SpecificEnthalpy')),
	                            ('h10', F.Quantity('SpecificEnthalpy')),
	                            ('h11', F.Quantity('SpecificEnthalpy')),
	                            ('h12', F.Quantity('SpecificEnthalpy')),
	                            ('h13', F.Quantity('SpecificEnthalpy')),
	                            ('h14', F.Quantity('SpecificEnthalpy')),
	                            ('h15', F.Quantity('SpecificEnthalpy')),
	                            ('h16', F.Quantity('SpecificEnthalpy')),
	                            ('h17', F.Quantity('SpecificEnthalpy')),
	                            ('h18', F.Quantity('SpecificEnthalpy')),
	                            ('h19', F.Quantity('SpecificEnthalpy')),
	                            ('h20', F.Quantity('SpecificEnthalpy')),
	                        	),
								label = 'Residual (table)',
								options = {'formats': (['0.0000E0'] * 20)})
	residualGroup = F.ViewGroup([residualPlot, iterationTable], label = 'Iterations')
	solverStats = F.SuperGroup([residualGroup], label = 'Convergence')

	
	# Info fields
	cycleTranscritical = F.Boolean(default = False)
	cycleSupercritical = F.Boolean(default = False)
	
	def initCompute(self, fluid):
		# Create fluid points
		self.fluid = Fluid(fluid)
		self.fp = [] #[FluidState(fluid) for _ in range(numPoints)]
		self.flows = []
		self.solver.cycle = self

	def connectPorts(self, port1, port2, fluid = None):
		if fluid == None:
			fluid = self.fluid
		fp = FluidState(fluid)
		flow = P.FluidFlow()
		self.fp.append(fp)
		self.flows.append(flow)
		port1.state = fp
		port2.state = fp
		port1.flow = flow
		port2.flow = flow
	
	def solve(self):
		self.solver.run()
		self.residualPlot.resize(len(self.solver.change_hHistory))
		for i in range(len(self.solver.change_hHistory)):
			self.residualPlot[i] = (i + 1, self.solver.change_hHistory[i])
		self.iterationTable.resize(len(self.solver.hHistory))
		v = self.iterationTable.view(dtype = np.float).reshape(-1, len(self.iterationTable.dtype))
		numCols = len(self.solver.hHistory[0])
		for i in range(len(self.solver.hHistory)):
			v[i, :numCols] = self.solver.hHistory[i]
# 		print self.iterationTable
# 		iterRecord = np.zeros(1, dtype = self.iterationTable.dtype)
# 		numCols = len(self.solver.hHistory[0])
# 		for i in range(len(self.solver.hHistory)):
# 			for j in range(numCols):
# 				iterRecord[j] = self.solver.hHistory[i][j]
# 			self.iterationTable[i] = iterRecord
		
	def postProcess(self, TAmbient):
		## State diagram
		if (self.cycleDiagram.enable):
			self.createStateDiagram()
		## Table of states
		self.cycleStatesTable.resize(len(self.fp))
		for i in range(len(self.fp)):
			fp = self.fp[i]
			self.cycleStatesTable[i] = (fp.T, fp.p, fp.rho, fp.h, fp.s, fp.q, fp.dT, self.flows[i].mDot, fp.b(TAmbient))
		# Select the zero for the exergy scale
		fp = FluidState(self.fluid)
		fp.update_Tp(TAmbient, 1e5)
		b0 = fp.b(TAmbient)
		self.cycleStatesTable['b'] -= b0
		
	def createStateDiagram(self):
		ncp = len(self.fp)
		fluidLines = []
		for i in range(ncp):
			fluidLines.append((self.fp[i], self.fp[(i + 1) % ncp]))
		self.phDiagram = self.cycleDiagram.draw(self.fluid, self.fp, fluidLines)	

	def setPLow(self, p):
		if (self.fluid.tripple['p'] < p < self.fluid.critical['p']):
			self.pLow = p
			sat = self.fluid.saturation_p(p)
			self.TEvaporation = sat['TsatL']
		elif (p > self.fluid.critical['p']):
			self.pLow = p
			self.cycleSupercritical = True
		else:
			raise ValueError('PLow  ({} bar) must be between {} bar and {} bar'.format(p/1e5, self.fluid.tripple['p']/1e5, self.fluid.critical['p']/1e5))


	def setPHigh(self, p):
		if (self.fluid.tripple['p'] < p < self.fluid.critical['p']):
			self.pHigh = p
			sat = self.fluid.saturation_p(p)
			self.TCondensation = sat['TsatL']
		elif (p > self.fluid.critical['p']):
			self.pHigh = p
			self.cycleTranscritical = True
		else:
			raise ValueError('PHigh  ({} bar) must be between {} bar and {} bar'.format(p/1e5, self.fluid.tripple['p']/1e5, self.fluid.critical['p']/1e5))
Esempio n. 5
0
	def initCompute(self, fluid):
		# Create fluid points
		self.fluid = Fluid(fluid)
		self.fp = [] #[FluidState(fluid) for _ in range(numPoints)]
		self.flows = []
		self.solver.cycle = self
Esempio n. 6
0
class ThermodynamicalCycle(NumericalModel):
    abstract = True
    #================ Inputs ================#
    # Cycle diagram
    cycleDiagram = F.SubModelGroup(TC.CycleDiagram,
                                   'inputs',
                                   label='Diagram settings')
    # Solver settings
    solver = F.SubModelGroup(CycleIterator, 'solverSettings', label='Solver')
    #================ Results ================#
    #---------------- Fields ----------------#
    cycleStatesTable = F.TableView(
        (('T', F.Quantity('Temperature', default=(1, 'degC'))),
         ('p', F.Quantity('Pressure', default=(1, 'bar'))),
         ('rho', F.Quantity('Density', default=(1, 'kg/m**3'))),
         ('h', F.Quantity('SpecificEnthalpy', default=(1, 'kJ/kg'))),
         ('s', F.Quantity('SpecificEntropy', default=(1, 'kJ/kg-K'))),
         ('q', F.Quantity()),
         ('dT', F.Quantity('TemperatureDifference', default=(1, 'degC'))),
         ('mDot', F.Quantity('MassFlowRate', default=(1, 'kg/min'))),
         ('b', F.Quantity('SpecificEnergy', default=(1, 'kJ/kg')))),
        label="Cycle states")

    cycleStates = F.ViewGroup([cycleStatesTable], label="States")
    resultStates = F.SuperGroup([cycleStates], label="States")
    #---------------- Cycle diagram -----------#
    phDiagram = F.Image(default='')
    cycleDiagramVG = F.ViewGroup([phDiagram], label="P-H Diagram")
    resultDiagrams = F.SuperGroup([cycleDiagramVG], label="Diagrams")
    #---------------- Convergence parameters -----------#
    residualPlot = F.PlotView((('iteration #', F.Quantity('Dimensionless')),
                               ('h change', F.Quantity('SpecificEnthalpy'))),
                              label='Residual (plot)',
                              ylog=True)
    iterationTable = F.TableView((
        ('h1', F.Quantity('SpecificEnthalpy')),
        ('h2', F.Quantity('SpecificEnthalpy')),
        ('h3', F.Quantity('SpecificEnthalpy')),
        ('h4', F.Quantity('SpecificEnthalpy')),
        ('h5', F.Quantity('SpecificEnthalpy')),
        ('h6', F.Quantity('SpecificEnthalpy')),
        ('h7', F.Quantity('SpecificEnthalpy')),
        ('h8', F.Quantity('SpecificEnthalpy')),
        ('h9', F.Quantity('SpecificEnthalpy')),
        ('h10', F.Quantity('SpecificEnthalpy')),
        ('h11', F.Quantity('SpecificEnthalpy')),
        ('h12', F.Quantity('SpecificEnthalpy')),
        ('h13', F.Quantity('SpecificEnthalpy')),
        ('h14', F.Quantity('SpecificEnthalpy')),
        ('h15', F.Quantity('SpecificEnthalpy')),
        ('h16', F.Quantity('SpecificEnthalpy')),
        ('h17', F.Quantity('SpecificEnthalpy')),
        ('h18', F.Quantity('SpecificEnthalpy')),
        ('h19', F.Quantity('SpecificEnthalpy')),
        ('h20', F.Quantity('SpecificEnthalpy')),
    ),
                                 label='Residual (table)',
                                 options={'formats': (['0.0000E0'] * 20)})
    residualGroup = F.ViewGroup([residualPlot, iterationTable],
                                label='Iterations')
    solverStats = F.SuperGroup([residualGroup], label='Convergence')

    # Info fields
    cycleTranscritical = F.Boolean(default=False)
    cycleSupercritical = F.Boolean(default=False)

    def initCompute(self, fluid):
        # Create fluid points
        self.fluid = Fluid(fluid)
        self.fp = []  #[FluidState(fluid) for _ in range(numPoints)]
        self.flows = []
        self.solver.cycle = self

    def connectPorts(self, port1, port2, fluid=None):
        if fluid == None:
            fluid = self.fluid
        fp = FluidState(fluid)
        flow = P.FluidFlow()
        self.fp.append(fp)
        self.flows.append(flow)
        port1.state = fp
        port2.state = fp
        port1.flow = flow
        port2.flow = flow

    def solve(self):
        self.solver.run()
        self.residualPlot.resize(len(self.solver.change_hHistory))
        for i in range(len(self.solver.change_hHistory)):
            self.residualPlot[i] = (i + 1, self.solver.change_hHistory[i])
        self.iterationTable.resize(len(self.solver.hHistory))
        v = self.iterationTable.view(dtype=np.float).reshape(
            -1, len(self.iterationTable.dtype))
        numCols = len(self.solver.hHistory[0])
        for i in range(len(self.solver.hHistory)):
            v[i, :numCols] = self.solver.hHistory[i]


# 		print self.iterationTable
# 		iterRecord = np.zeros(1, dtype = self.iterationTable.dtype)
# 		numCols = len(self.solver.hHistory[0])
# 		for i in range(len(self.solver.hHistory)):
# 			for j in range(numCols):
# 				iterRecord[j] = self.solver.hHistory[i][j]
# 			self.iterationTable[i] = iterRecord

    def postProcess(self, TAmbient):
        ## State diagram
        if (self.cycleDiagram.enable):
            self.createStateDiagram()
        ## Table of states
        self.cycleStatesTable.resize(len(self.fp))
        for i in range(len(self.fp)):
            fp = self.fp[i]
            self.cycleStatesTable[i] = (fp.T, fp.p, fp.rho, fp.h, fp.s, fp.q,
                                        fp.dT, self.flows[i].mDot,
                                        fp.b(TAmbient))
        # Select the zero for the exergy scale
        fp = FluidState(self.fluid)
        fp.update_Tp(TAmbient, 1e5)
        b0 = fp.b(TAmbient)
        self.cycleStatesTable['b'] -= b0

    def createStateDiagram(self):
        ncp = len(self.fp)
        fluidLines = []
        for i in range(ncp):
            fluidLines.append((self.fp[i], self.fp[(i + 1) % ncp]))
        self.phDiagram = self.cycleDiagram.draw(self.fluid, self.fp,
                                                fluidLines)

    def setPLow(self, p):
        if (self.fluid.tripple['p'] < p < self.fluid.critical['p']):
            self.pLow = p
            sat = self.fluid.saturation_p(p)
            self.TEvaporation = sat['TsatL']
        elif (p > self.fluid.critical['p']):
            self.pLow = p
            self.cycleSupercritical = True
        else:
            raise ValueError(
                'PLow  ({} bar) must be between {} bar and {} bar'.format(
                    p / 1e5, self.fluid.tripple['p'] / 1e5,
                    self.fluid.critical['p'] / 1e5))

    def setPHigh(self, p):
        if (self.fluid.tripple['p'] < p < self.fluid.critical['p']):
            self.pHigh = p
            sat = self.fluid.saturation_p(p)
            self.TCondensation = sat['TsatL']
        elif (p > self.fluid.critical['p']):
            self.pHigh = p
            self.cycleTranscritical = True
        else:
            raise ValueError(
                'PHigh  ({} bar) must be between {} bar and {} bar'.format(
                    p / 1e5, self.fluid.tripple['p'] / 1e5,
                    self.fluid.critical['p'] / 1e5))
Esempio n. 7
0
 def initCompute(self, fluid):
     # Create fluid points
     self.fluid = Fluid(fluid)
     self.fp = []  #[FluidState(fluid) for _ in range(numPoints)]
     self.flows = []
     self.solver.cycle = self
Esempio n. 8
0
 def __init__(self, fluidName):
     self.fluidName = fluidName
     self.fluid = Fluid(fluidName)
Esempio n. 9
0
'''
Created on Feb 23, 2015

@author: Atanas Pavlov
'''

import numpy as np
from smo.media.CoolProp.CoolProp import FluidState, Fluid

fluid = Fluid('Water')

dT = 1e-4
dq = 1e-3

f1 = FluidState(fluid)
f2 = FluidState(fluid)

f1.update_Tq(273.15 + 150, 0.5)

# dqdT_v
f2.update_Trho(f1.T + dT, f1.rho)
dqdT_v = (f2.q - f1.q) / (f2.T - f1.T)
print("dqdT_v() numerical: {:e}, analytical: {:e}".format(dqdT_v, f1.dqdT_v))

# dvdT_q
f2.update_Tq(f1.T + dT, f1.q)
dvdT_q = (f2.v - f1.v) / (f2.T - f1.T)
dvdT_q_1 = f1.q * f1.SatV.dvdT + (1 - f1.q) * f1.SatL.dvdT
print("dvdT_q() numerical: {:e}, analytical: {:e}, analytical2: {:e}".format(
    dvdT_q, f1.dvdT_q, dvdT_q_1))