def test_HeatCapacityLiquidMixture(): from thermo import Mixture from thermo.heat_capacity import HeatCapacityLiquidMixture, SIMPLE m = Mixture(['water', 'sodium chloride'], ws=[.9, .1], T=301.5) obj = HeatCapacityLiquidMixture(MWs=m.MWs, CASs=m.CASs, HeatCapacityLiquids=m.HeatCapacityLiquids) Cp = obj(m.T, m.P, m.zs, m.ws) assert_allclose(Cp, 72.29643435124115) Cp = obj.calculate(m.T, m.P, m.zs, m.ws, SIMPLE) assert_allclose(Cp, 78.90470515935154) m = Mixture(['toluene', 'decane'], ws=[.9, .1], T=300) obj = HeatCapacityLiquidMixture(CASs=m.CASs, HeatCapacityLiquids=m.HeatCapacityLiquids) assert_allclose(obj(m.T, m.P, m.zs, m.ws), 168.29157865567112, rtol=1E-4) # Unhappy paths with pytest.raises(Exception): obj.calculate(m.T, m.P, m.zs, m.ws, 'BADMETHOD') with pytest.raises(Exception): obj.test_method_validity(m.T, m.P, m.zs, m.ws, 'BADMETHOD')
def checkState(self): T = float(self.form.editTemperature.text()) + 273.16 P = float(self.form.editPressure.text()) * 1e5 try: fluid = Chemical(self.form.comboFluid.currentText(), T=T, P=P) except: fluid = Mixture(self.form.comboFluid.currentText(), T=T, P=P) #if fluid.rhol and fluid.rhog: #self.form.radioLiquid.show() #self.form.radioGas.show() if fluid.rhol: self.isLiquid = True self.form.labState.setText('*** LIQUID ***') self.form.labQ.setText('Flow (m3/h)') self.Rho = fluid.rhol self.Mu = fluid.mul elif fluid.rhog: self.isLiquid = False self.form.labState.setText('*** GAS/VAPOUR ***') self.form.labQ.setText('Flow (kg/h)') self.Rho = fluid.rhog self.Mu = fluid.mug else: self.form.labState.setText('*** SOLID (no flow) ***') self.form.editFlow.setText('0') FreeCAD.Console.PrintMessage('Rho: %.2f\n' % self.Rho)
def checkFluid(self): T=float(self.form.editTemperature.text())+273.16 P=float(self.form.editPressure.text())*1e5 self.isMixture=True if self.form.comboFluid.currentText()!='<custom fluid>': self.form.editDensity.setEnabled(False) self.form.editViscosity.setEnabled(False) try: self.fluid=Chemical(self.form.comboFluid.currentText(),T=T,P=P) self.isMixture=False except: self.fluid=Mixture(self.form.comboFluid.currentText(),T=T,P=P) if self.fluid.rhol and self.fluid.mul: self.setLiquid() self.form.radioLiquid.setChecked(True) elif self.fluid.rhog and self.fluid.mug: self.setGas() self.form.radioGas.setChecked(True) else: self.form.labState.setText('*** SOLID (no flow) ***') self.form.editFlow.setText('0') if not self.isMixture: CAS=identifiers.CAS_from_any(self.form.comboFluid.currentText()) IUPAC=identifiers.IUPAC_name(CAS) formula=identifiers.formula(CAS) self.form.labName.setText('CAS = %s\nIUPAC = %s\nformula = %s'%(CAS,IUPAC,formula)) else: self.form.labName.setText(self.form.comboFluid.currentText()+'\n(mixture)') else: # in progress custom fluid self.fluid=None self.form.labName.setText('*** CUSTOM FLUID ***') self.form.editDensity.setEnabled(True) self.form.editViscosity.setEnabled(True) self.form.labResult.setText('---')
def set_of_const(P_amb, T_amb): P_amb = P_amb * mmHg # Pressure in Pa T_amb = T_amb + zero_Celsius # T in K # Here we calculate all what it is important with the air at the ambient pressure air = Mixture('air', T=T_amb, P=P_amb) k = air.isentropic_exponent mu = air.mu rho = air.rho return P_amb, T_amb, air, k, mu, rho
def test_HeatCapacityGasMixture(): from thermo import Mixture from thermo.heat_capacity import HeatCapacityGasMixture m = Mixture(['oxygen', 'nitrogen'], ws=[.4, .6], T=350, P=1E6) obj = HeatCapacityGasMixture(CASs=m.CASs, HeatCapacityGases=m.HeatCapacityGases) Cp = obj(m.T, m.P, m.zs, m.ws) assert_allclose(Cp, 29.361044582498046) # Unhappy paths with pytest.raises(Exception): obj.calculate(m.T, m.P, m.zs, m.ws, 'BADMETHOD') with pytest.raises(Exception): obj.test_method_validity(m.T, m.P, m.zs, m.ws, 'BADMETHOD')
def test_HeatCapacitySolidMixture(): from thermo import Mixture from thermo.heat_capacity import HeatCapacitySolidMixture m = Mixture(['silver', 'platinum'], ws=[0.95, 0.05]) obj = HeatCapacitySolidMixture(CASs=m.CASs, HeatCapacitySolids=m.HeatCapacitySolids) Cp = obj(m.T, m.P, m.zs, m.ws) assert_allclose(Cp, 25.32745719036059) # Unhappy paths with pytest.raises(Exception): obj.calculate(m.T, m.P, m.zs, m.ws, 'BADMETHOD') with pytest.raises(Exception): obj.test_method_validity(m.T, m.P, m.zs, m.ws, 'BADMETHOD')
def mdot_f(mdot_p, mesures1, mesures2, DeltaP, DeltaT, mesuresT, D1, D2): # Experimental setup taps = 'flange' meter_type = 'ISO 5167 orifice' # meter_type = 'ISA 1932 nozzle' # First we have to initialize the vector mdot = uarray(zeros(len(mesures1)), zeros(len(mesures1))) # Here we inicialize the vectors with their uncertainties p1 = uarray(mesures1, DeltaP * ones(len(mesures1))) p2 = uarray(mesures2, DeltaP * ones(len(mesures2))) T1 = uarray(mesuresT, DeltaT * ones(len(mesures1))) # Here we start to carry the units as we need them T1 = T1 + zero_Celsius # Temperature in KELVIN p1 = (p1 + 1) * 1e5 # Pressió en Pa, absoluts p2 = (p2 + 1) * 1e5 for i in range(len(mesures1)): # l'aire es calcula amb cada valor de P i de T. IMPORTANT: el nominal_value aconsegueix fer-hi passar només el valor correcte. air = Mixture('air', T=float(nominal_value(T1[i])), P=float(nominal_value(p1[i]))) r = sci.constants.R / air.MW * 1000 k = air.isentropic_exponent mu = air.mu rho = p1[i] / (r * T1[i]) # Here is where we write the vector mdot mdot[i] = wrappedFlowMeter(D=D1, D2=D2, P1=p1[i], P2=p2[i], rho=rho, mu=mu, k=k, meter_type=meter_type, taps=taps) mdot_p['mdot_p'] = mdot mdot_p['QN_p'] = mdot_p.mdot_p * 60000 / rhoN mdot_p['mu'] = mdot_p.QN_s / mdot_p.QN_p
import uncertainties from uncertainties import * from uncertainties.unumpy import * import uncertainties as unumpy from numpy import * from pandas import * import pandas as pd import matplotlib.pyplot as plt import pickle # In[2]: # For the calculation of flow rate with uncertainties: wrappedFlowMeter = uncertainties.wrap(differential_pressure_meter_solver) # Firsts definitions airN = Mixture('air', T=293, P=101325) rhoN = airN.rho # In[3]: #Here it is defined all our ambi def set_of_const(P_amb, T_amb): P_amb = P_amb * mmHg # Pressure in Pa T_amb = T_amb + zero_Celsius # T in K # Here we calculate all what it is important with the air at the ambient pressure air = Mixture('air', T=T_amb, P=P_amb) k = air.isentropic_exponent
pressure_from_mach_p0 = solve( - p0 + x * (1 + a * M*M /2 ) ** b , x ) just = (1 + a * M*M /2 ) ** - b return pressure_from_mach_p0, just # In[35]: # In[22]: airN = Mixture( 'air' , T = 273.15 , P = atmosphere ) rhoN = airN.rho # Variables geometriques d_chicle = 2.75e-3 #m d_sortidaChicle = 7e-3 #m # Parametres de fluids p_0 = 6e5 #pa temperatura_entrada = 25 #ºC gamma = 1.40 # Parametres calculables area_coll = area(d_chicle) area_sortidaChicle = area (d_sortidaChicle)