예제 #1
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)))
예제 #2
0
파일: CycleBases.py 프로젝트: SysMo/SmoWeb
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))
예제 #3
0
파일: CycleBases.py 프로젝트: birdol/SmoWeb
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))