def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] Pi = parseFloat(doc['input']['Pi']['_val']) Pe = parseFloat(doc['input']['Pe']['_val']) Ti = parseFloat(doc['input']['Ti']['_val']) MW = parseFloat(doc['input']['MW']['_val']) k = parseFloat(doc['input']['k']['_val']) A = parseFloat(doc['input']['A']['_val']) Cd = parseFloat(doc['input']['Cd']['_val']) r = Pe / Pi f = k / (k - 1) rho0 = orf.density(Pi, Ti, MW) v, G, isChoked = orf.mflow_reservoir_orifice(Pi, Ti, Pe, MW, k, A, Cd) Q = A * v doc['result'].update({'v': {'_val': str(roundit(v)), '_dim': 'speed'}}) doc['result'].update({'Q': {'_val': str(roundit(Q)), '_dim': 'flow'}}) doc['result'].update({'G': {'_val': str(roundit(G)), '_dim': 'massflow'}}) doc['result'].update({'isChoked': {'_val': isChoked}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) source_option = doc['input']['source_option']['_val'] SPL1 = parseFloat(doc['input']['SPL1']['_val']) R1 = parseFloat(doc['input']['R1']['_val']) R2 = parseFloat(doc['input']['R2']['_val']) if (source_option == 'point'): SPL2 = noise_utils.distAttenPoint(SPL1=SPL1, R1=R1, R2=R2) elif (source_option == 'line'): SPL2 = noise_utils.distAttenLine(SPL1=SPL1, R1=R1, R2=R2) elif (source_option == 'wall'): width = abs(parseFloat(doc['input']['width']['_val'])) height = abs(parseFloat(doc['input']['height']['_val'])) SPL2 = noise_utils.distAttenWall(SPL1=SPL1, R1=R1, R2=R2, width=width, height=height) else: SPL2 = math.nan doc['result'].update({'SPL2': {'_val': str(SPL2)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) # Get essential data Pambient = float(doc['input']['Pambient']['_val']) Tambient = float(doc['input']['Tambient']['_val']) RHambient = float(doc['input']['RHambient']['_val']) Flow = float(doc['input']['Flow']['_val']) X = humidityRatio(Pambient, Tambient, RHambient) FAD = Flow * (1 + X) * (298.0 / 273.15) Pnormal = 101325 Tnormal = 273.15 rho_normal = moistAirDensity(Pnormal, Tnormal, RH=0) mass_dryair = Flow * rho_normal mass_moistair = mass_dryair * (1 + X) rho_moistair = moistAirDensity(Pambient, Tambient, RHambient) FAD = mass_moistair / rho_moistair rho = roundit(rho_moistair) doc['result'].update({'FAD': {'_val': str(FAD), '_dim': 'flow'}}) doc['result'].update( {'rho': { '_val': str(rho_moistair), '_dim': 'density' }}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] try: Nr = float(doc['input']['Nr']['_val']) Jm = float(doc['input']['Jm']['_val']) Cs = float(doc['input']['Cs']['_val']) Cm = float(doc['input']['Cm']['_val']) load_type = doc['input']['load_type']['_val'] Cl = float(doc['input']['Cl']['_val']) Jl = float(doc['input']['Jl']['_val']) Tacc = motor_starting_time(Nr, Jm, Jl, Cs, Cm, Cl, load_type) except Exception as e: Tacc = nan doc['errors'].append(str(e)) doc['errors'].append( "Failed to calculate phase parameters. Check Inputs") Tacc = roundit(Tacc) doc['result'].update({'Tacc': {'_val': str(Tacc)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) correction_option = doc['input']['correction_option']['_val'] if (correction_option == 'spectrum'): totalSpectrum = doc['input']['totalSpectrum'] backgroundSpectrum = doc['input']['backgroundSpectrum'] sourceSpectrum = noise_utils.correctSpectrum( totalSpectrum=totalSpectrum, backgroundSpectrum=backgroundSpectrum) for key, value in sourceSpectrum.items(): sourceSpectrum[key] = str(value) doc['result']['sourceSpectrum'] = sourceSpectrum else: totalNoise = parseFloat(doc['input']['totalNoise']['_val']) backgroundNoise = parseFloat(doc['input']['backgroundNoise']['_val']) sourceNoise = noise_utils.correctBackNoise( noiseTotal=totalNoise, noiseBackground=backgroundNoise) doc['result']['sourceNoise']['_val'] = str(sourceNoise) treeUnitConvert(doc, SI_UNITS, doc['units']) doc_original['result'].update(doc['result']) return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] rho = float(doc['input']['rho']['_val']) Psat = float(doc['input']['Psat']['_val']) Pc = float(doc['input']['Pc']['_val']) mu = float(doc['input']['mu']['_val']) P1 = float(doc['input']['P1']['_val']) P2 = float(doc['input']['P2']['_val']) Q = float(doc['input']['Q']['_val']) D1 = float(doc['input']['D1']['_val']) D2 = float(doc['input']['D2']['_val']) d = float(doc['input']['d']['_val']) FL = float(doc['input']['FL']['_val']) Fd = float(doc['input']['Fd']['_val']) Cmetric = size_control_valve_l(rho, Psat, Pc, mu, P1, P2, Q, D1, D2, d, FL, Fd) Cmetric = roundit(Cmetric) doc['result'].update({'Cmetric': {'_val': str(Cmetric)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] T = float(doc['input']['T']['_val']) MW = float(doc['input']['MW']['_val']) mu = float(doc['input']['mu']['_val']) gamma = float(doc['input']['gamma']['_val']) Z = float(doc['input']['Z']['_val']) P1 = float(doc['input']['P1']['_val']) P2 = float(doc['input']['P2']['_val']) Q = float(doc['input']['Q']['_val']) D1 = float(doc['input']['D1']['_val']) D2 = float(doc['input']['D2']['_val']) d = float(doc['input']['d']['_val']) FL = float(doc['input']['FL']['_val']) Fd = float(doc['input']['Fd']['_val']) xT = float(doc['input']['xT']['_val']) MW_ = MW * 1000 try: Cmetric = size_control_valve_g(T, MW_, mu, gamma, Z, P1, P2, Q, D1, D2, d, FL, Fd, xT) except Exception: Cmetric = math.nan Cmetric = roundit(Cmetric) doc['result'].update({'Cmetric': {'_val': str(Cmetric)}}) treeUnitConvert(doc, SI_UNITS, doc['units']) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] try: P = float(doc['input']['P']['_val']) pf_actual = float(doc['input']['pf_actual']['_val']) pf_desired = float(doc['input']['pf_desired']['_val']) kVAr_comp = PFC_compensation(P, pf_actual, pf_desired) except Exception as e: kVAr_comp = nan doc['errors'].append(str(e)) doc['errors'].append( "Failed to calculate phase parameters. Check Inputs") kVAr_comp = roundit(kVAr_comp) doc['result'].update({'kVAr_comp': {'_val': str(kVAr_comp)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] =[] emissionPoints = doc['input']['emissionPoints']['_list'] mapArea = doc['input']['mapArea'] x1 = float(mapArea['x1']['_val']) x2 = float(mapArea['x2']['_val']) x_step = float(mapArea['x_step']['_val']) y1 = float(mapArea['y1']['_val']) y2 = float(mapArea['y2']['_val']) y_step = float(mapArea['y_step']['_val']) x_list = [] x = x1 while x < x2 : x_list.append(x) x = x + x_step y_list = [] y = y1 while y < y2 : y_list.append(y) y = y + y_step immisionPoints = [] for x in x_list : for y in y_list: immisionPoints.append({'x':x, 'y':y}) noiseField_list = noise_utils.noiseMap(emissionPoints=emissionPoints, immisionPoints=immisionPoints) for np in noiseField_list: np['x'] = str(np['x']) np['y'] = str(np['y']) np['noise'] = str(np['noise']) noiseField = { "_coldim":{ "x":"length", "y":"length" }, "_list" : [] } noiseField['_list']= noiseField_list # doc['result']['noiseField']['_list'] = noiseField doc['result'].update({'noiseField':noiseField}) treeUnitConvert(doc, SI_UNITS, doc['units']) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] fuel_as = doc['input']['fuel_as']['_val'] flue_as = doc['input']['flue_as']['_val'] gasfuel = doc['input']['gasfuel'] emission_units = doc['input']['emission_units']['_val'] Tair = parseFloat(doc['input']['Tair']['_val']) Pair = parseFloat(doc['input']['Pair']['_val']) RH = parseFloat(doc['input']['RH']['_val']) excess_air = parseFloat(doc['input']['excess_air']['_val']) Ts = parseFloat(doc['input']['Ts']['_val']) Ps = parseFloat(doc['input']['Ps']['_val']) O2_reference = parseFloat(doc['input']['O2_reference']['_val']) MW_fuel, air_reqd, CO2_formed, H2O_formed, SO2_formed, N2_formed, O2_formed = gasCombustion( gasfuel, fuel_as, flue_as, excess_air, Pair, Tair, RH) SOx_concentration = FlueGasSOx_concentration(CO2_formed, H2O_formed, SO2_formed, N2_formed, O2_formed, flue_as=flue_as, units=emission_units, O2_reference=O2_reference, Ps=Ps, Ts=Ts) doc['result'].update( {'MW_fuel': { '_val': str(roundit(MW_fuel)), '_dim': 'molecularMass' }}) doc['result'].update({'flue_as': {'_val': str(roundit(flue_as))}}) doc['result'].update({'air_reqd': {'_val': str(roundit(air_reqd))}}) doc['result'].update({'CO2_formed': {'_val': str(roundit(CO2_formed))}}) doc['result'].update({'H2O_formed': {'_val': str(roundit(H2O_formed))}}) doc['result'].update({'SO2_formed': {'_val': str(roundit(SO2_formed))}}) doc['result'].update({'N2_formed': {'_val': str(roundit(N2_formed))}}) doc['result'].update({'O2_formed': {'_val': str(roundit(O2_formed))}}) doc['result'].update( {'SOx_concentration': { '_val': str(roundit(SOx_concentration)) }}) doc['result'].update({'emission_units': {'_val': emission_units}}) doc['result'].update( {'O2_reference': { '_val': str(roundit(O2_reference)) }}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] Pu = parseFloat(doc['input']['Pu']['_val']) Pl = parseFloat(doc['input']['Pl']['_val']) Qout = parseFloat(doc['input']['Qout']['_val']) Tmax = parseFloat(doc['input']['Tmax']['_val']) margin = parseFloat(doc['input']['margin']['_val']) sizing_basis = doc['input']['sizing_basis']['_val'] if (sizing_basis == 'buffer_time'): t = parseFloat(doc['input']['t']['_val']) V = st.receiverVolumeHoldUp(Qout=Qout, t=t, Pu=Pu, Pl=Pl, Tmax=Tmax, margin=margin) elif (sizing_basis == 'switching_frequency'): Qin = parseFloat(doc['input']['Qin']['_val']) fs = parseFloat(doc['input']['fs']['_val']) chi = (Qout / Qin) Qout_worst = 0.5 * Qin V = st.receiverVolumeSwitching(fs=fs, Qin=Qin, Qout=Qout, Pu=Pu, Pl=Pl, Tmax=Tmax, margin=margin) Vrec = st.receiverVolumeSwitching(fs=fs, Qin=Qin, Qout=Qout_worst, Pu=Pu, Pl=Pl, Tmax=Tmax, margin=margin) doc['result'].update({'chi': {'_val': str(roundit(chi))}}) doc['result'].update( {'Vrec': { '_val': str(roundit(Vrec)), '_dim': 'volume' }}) else: doc[errors].append('Invalid value for "Sizing Basis"') doc['result'].update({'V': {'_val': str(roundit(V)), '_dim': 'volume'}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] convert = doc['input']['convert']['_val'] if (convert == 'nu2mu'): nu = float(doc['input']['nu']['_val']) rho = float(doc['input']['rho']['_val']) mu = kin2dynVisc(nu, rho) ssu = "" elif (convert == 'nu2ssu'): nu = float(doc['input']['nu']['_val']) nu_cSt = unitConvert(nu, 'kinViscosity', 'm2/s', 'cSt') ssu = cSt2SSU(nu_cSt) mu = "" elif (convert == 'mu2nu'): mu = float(doc['input']['mu']['_val']) rho = float(doc['input']['rho']['_val']) nu = dyn2kinVisc(mu, rho) nu_cSt = unitConvert(nu, 'kinViscosity', 'm2/s', 'cSt') ssu = cSt2SSU(nu_cSt) elif (convert == 'mu2ssu'): mu = float(doc['input']['mu']['_val']) rho = float(doc['input']['rho']['_val']) nu = dyn2kinVisc(mu, rho) nu_cSt = unitConvert(nu, 'kinViscosity', 'm2/s', 'cSt') ssu = cSt2SSU(nu_cSt) elif (convert == 'ssu2nu'): ssu = float(doc['input']['ssu']['_val']) nu_cSt = SSU2cSt(ssu) nu = unitConvert(nu_cSt, 'kinViscosity', 'cSt', 'm2/s') mu = "" elif (convert == 'ssu2mu'): ssu = float(doc['input']['ssu']['_val']) rho = float(doc['input']['rho']['_val']) nu_cSt = SSU2cSt(ssu) nu = unitConvert(nu_cSt, 'kinViscosity', 'cSt', 'm2/s') mu = kin2dynVisc(nu, rho) nu = roundit(nu) mu = roundit(mu) ssu = roundit(ssu) doc['result'].update({'nu': {'_val': str(nu), '_dim': 'kinViscosity'}}) doc['result'].update({'mu': {'_val': str(mu), '_dim': 'dynViscosity'}}) doc['result'].update({'ssu': {'_val': str(ssu)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) noiseLevelList = doc['input']['noiseLevelList'] noiseTotal = noise_utils.addNoise(noiseLevelList=noiseLevelList) doc['result'].update({'noiseTotal': {'_val': str(noiseTotal)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] Qvis = float(doc['input']['Qvis']['_val']) Hvis = float(doc['input']['Hvis']['_val']) viscosity_basis = doc['input']['viscosity_basis']['_val'] if (viscosity_basis == 'kinematic'): nu = float(doc['input']['nu']['_val']) else: mu = float(doc['input']['mu']['_val']) rho = float(doc['input']['rho']['_val']) nu = dyn2kinVisc(mu, rho) try: Cq, Ch, Ceta = viscSel(Qvis, Hvis, nu) Cq = roundit(Cq) Ch = roundit(Ch) Ceta = roundit(Ceta) except Exception as e: doc['errors'].append(str(e)) doc['errors'].append( 'Failed to calculate correction factors. Check Inputs') Cq = math.nan Ch = math.nan Ceta = math.nan doc['result'].update({'nu': {'_val': str(nu), '_dim': 'kinViscosity'}}) doc['result'].update({'Cq': {'_val': str(Cq)}}) doc['result'].update({'Ch': {'_val': str(Ch)}}) doc['result'].update({'Ceta': {'_val': str(Ceta)}}) try: Qw = roundit(Qvis / Cq) doc['result'].update({'Qw': {'_val': str(Qw), '_dim': 'flow'}}) except Exception: doc['result'].update({'Qw': {'_val': ' ', '_dim': 'flow'}}) try: Hw = roundit(Hvis / Ch) doc['result'].update({'Hw': {'_val': str(Hw), '_dim': 'length'}}) except Exception: doc['result'].update({'Hvis': {'_val': ' ', '_dim': 'length'}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] solve_using = doc['input']['solve_using']['_val'] VLL = float(doc['input']['VLL']['_val']) pf = float(doc['input']['pf']['_val']) I = nan kW = nan kVA = nan kVAr = nan try: if (solve_using == 'current'): I = float(doc['input']['I']['_val']) I, kW, kVA, kVAr = phase_parameters(VLL, pf, I=I) elif (solve_using == 'active_power'): kW = float(doc['input']['kW']['_val']) I, kW, kVA, kVAr = phase_parameters(VLL, pf, kW=kW) elif (solve_using == 'apparent_power'): kVA = float(doc['input']['kVA']['_val']) I, kW, kVA, kVAr = phase_parameters(VLL, pf, kVA=kVA) elif (solve_using == 'reactive_power'): kVAr = float(doc['input']['kVAr']['_val']) I, kW, kVA, kVAr = phase_parameters(VLL, pf, kVAr=kVAr) else: raise Exception("Invalid Option for Solving") except Exception as e: doc['errors'].append(str(e)) doc['errors'].append( "Failed to calculate phase parameters. Check Inputs") I = roundit(I) kW = roundit(kW) kVA = roundit(kVA) kVAr = roundit(kVAr) doc['result'].update({'I': {'_val': str(I)}}) doc['result'].update({'kW': {'_val': str(kW)}}) doc['result'].update({'kVA': {'_val': str(kVA)}}) doc['result'].update({'kVAr': {'_val': str(kVAr)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) unfilteredSpectrum = doc['input']['unfilteredSpectrum'] filteredSpectrum = noise_utils.aWeightedSpectrum( spectrum=unfilteredSpectrum) totalAudibleNoise = noise_utils.spectrumTotal(filteredSpectrum) doc['result']['filteredSpectrum'] = filteredSpectrum doc['result'].update( {'totalAudibleNoise': { '_val': str(totalAudibleNoise) }}) treeUnitConvert(doc, SI_UNITS, doc['units']) doc_original['result'].update(doc['result']) return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) mixture = doc['input']['mixture'] P = float(doc['input']['P']['_val']) T = float(doc['input']['T']['_val']) mixprops = mixture_props(mixture,P=P,T=T) MW = mixprops['MW'] Pcritical = mixprops['Pcritical'] Tcritical = mixprops['Tcritical'] Pr = mixprops['Pr'] Tr = mixprops['Tr'] acentric = mixprops['acentric'] Z_PR = mixprops['Z_PR'] Z_LKP = mixprops['Z_LKP'] Z_NO = mixprops['Z_NO'] Cp0mass = mixprops['Cp0mass'] Cv0mass = mixprops['Cv0mass'] Cp0molar = mixprops['Cp0molar'] Cv0molar = mixprops['Cv0molar'] doc['result'].update({'MW':{'_val' : str(MW), '_dim':'molecularMass'}}) doc['result'].update({'Pcritical':{'_val' : str(Pcritical), '_dim':'pressure'}}) doc['result'].update({'Tcritical':{'_val' : str(Tcritical), '_dim':'temperature'}}) doc['result'].update({'Pr':{'_val' : str(Pr)}}) doc['result'].update({'Tr':{'_val' : str(Tr)}}) doc['result'].update({'acentric':{'_val' : str(acentric)}}) doc['result'].update({'Z_PR':{'_val' : str(Z_PR)}}) doc['result'].update({'Z_LKP':{'_val' : str(Z_LKP)}}) doc['result'].update({'Z_NO':{'_val' : str(Z_NO)}}) doc['result'].update({'Cp0mass':{'_val' : str(Cp0mass), '_dim':'specificHeat'}}) doc['result'].update({'Cv0mass':{'_val' : str(Cv0mass), '_dim':'specificHeat'}}) doc['result'].update({'Cp0molar':{'_val' : str(Cp0molar), '_dim':'specificHeatMolar'}}) doc['result'].update({'Cv0molar':{'_val' : str(Cv0molar), '_dim':'specificHeatMolar'}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] convert = doc['input']['convert']['_val'] area_basis = doc['input']['area_basis']['_val'] luminous_efficacy = float(doc['input']['luminous_efficacy']['_val']) if (convert == 'watts2lux'): watts = float(doc['input']['watts']['_val']) lumens = watts2lumens(watts, luminous_efficacy) lumens = roundit(lumens) if (area_basis == 'radius'): radius = float(doc['input']['radius']['_val']) lux = lumens2lux(lumens, radius=radius) else: area = float(doc['input']['area']['_val']) lux = lumens2lux(lumens, area=area) lux = roundit(lux) doc['result'].update({'lux': {'_val': str(lux)}}) else: lux = float(doc['input']['lux']['_val']) if (area_basis == 'radius'): radius = float(doc['input']['radius']['_val']) lumens = lux2lumens(lux, radius=radius) else: area = float(doc['input']['area']['_val']) lumens = lux2lumens(lux, area=area) watts = lumens2watts(lumens, luminous_efficacy) watts = roundit(watts) doc['result'].update({'watts': {'_val': str(watts)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] ups_load_kW = parseFloat(doc['input']['ups_load_kW']['_val']) lagging_pf = parseFloat(doc['input']['lagging_pf']['_val']) ups_efficiency = parseFloat(doc['input']['ups_efficiency']['_val']) design_margin = parseFloat(doc['input']['design_margin']['_val']) ups_load_kVA = ups_load_kW / lagging_pf ups_rating_kVA = (ups_load_kVA * 100) / ups_efficiency ups_rating_kVA = ups_rating_kVA * (1 + design_margin / 100) doc['result'].update( {'ups_rating_kVA': { '_val': str(roundit(ups_rating_kVA)) }}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) calculation_option = doc['input']['calculation_option']['_val'] if (calculation_option=='calcSPL'): PWL = parseFloat(doc['input']['PWL']['_val']) distance = parseFloat(doc['input']['distance']['_val']) Q = parseFloat(doc['input']['Q']['_val']) SPL = noise_utils.getSPL(PWL,distance,Q) SPL = roundit(SPL) doc['result'].update({'SPL':{'_val' : str(SPL)}}) if (calculation_option=='calcPWL'): SPL = parseFloat(doc['input']['SPL']['_val']) distance = parseFloat(doc['input']['distance']['_val']) Q = parseFloat(doc['input']['Q']['_val']) PWL = noise_utils.getPWL(SPL,distance,Q) doc['result'].update({'PWL':{'_val' : str(PWL)}}) if (calculation_option=='calcDistance'): PWL = parseFloat(doc['input']['PWL']['_val']) SPL = parseFloat(doc['input']['SPL']['_val']) Q = parseFloat(doc['input']['Q']['_val']) distance = noise_utils.getDistance(PWL,SPL,Q) doc['result'].update({'distance':{'_val' : str(distance), '_dim':'length'}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] calculation_option = doc['input']['calculation_option']['_val'] try: if (calculation_option == 'NPS'): NPS = parseFloat(doc['input']['NPS']['_val']) Schedule = doc['input']['Schedule']['_val'] nps, di, do, t = nearest_pipe(NPS=NPS, schedule=Schedule) if (calculation_option == 'Di'): Di = parseFloat(doc['input']['Di']['_val']) Schedule = doc['input']['Schedule']['_val'] nps, di, do, t = nearest_pipe(Di=Di, schedule=Schedule) if (calculation_option == 'Do'): Do = parseFloat(doc['input']['Do']['_val']) Schedule = doc['input']['Schedule']['_val'] nps, di, do, t = nearest_pipe(Do=Do, schedule=Schedule) except Exception as e: doc['errors'].append(str(e)) nps = math.nan di = math.nan do = math.nan t = math.nan doc['result'].update({'NPS': {'_val': str(roundit(nps))}}) doc['result'].update({'Di': {'_val': str(roundit(di)), '_dim': 'length'}}) doc['result'].update({'Do': {'_val': str(roundit(do)), '_dim': 'length'}}) doc['result'].update({'t': {'_val': str(roundit(t)), '_dim': 'length'}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] =[] convert = doc['input']['convert']['_val'] apex_angle = float(doc['input']['apex_angle']['_val']) if (convert=='cd2lm'): candela = float(doc['input']['candela']['_val']) lumens = candela2lumens(candela, apex_angle) lumens = roundit(lumens) doc['result'].update({'lumens':{'_val':str(lumens)}}) else: lumens = float(doc['input']['lumens']['_val']) candela = lumens2candela(lumens, apex_angle) candela = roundit(candela) doc['result'].update({'candela':{'_val':str(candela)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] =[] convert = doc['input']['convert']['_val'] distance = float(doc['input']['distance']['_val']) if (convert=='cd2lux'): candela = float(doc['input']['candela']['_val']) lux = candela2lux(candela, distance) lux = roundit(lux) doc['result'].update({'lux':{'_val':str(lux)}}) else: lux = float(doc['input']['lux']['_val']) candela = lux2candela(lux, distance) candela = roundit(candela) doc['result'].update({'candela':{'_val':str(candela)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] Prated = float(doc['input']['Prated']['_val']) print(Prated) Fuel_rate_specific = float(doc['input']['Fuel_rate_specific']['_val']) print(Fuel_rate_specific) Fuel_flow_rate = Fuel_rate_specific * Prated print(Fuel_flow_rate) # Fuel_flow_rate = roundit(Fuel_flow_rate) #Fuel_flow_rate = 1 doc['result'].update( {'Fuel_flow_rate': { '_val': str(Fuel_flow_rate), '_dim': 'flow' }}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] =[] state = doc['input']['state']['_val'] try: if (state=='Saturated_P'): P = float(doc['input']['P']['_val']) Q = float(doc['input']['Q']['_val']) phase = CP.PhaseSI('P', P, 'Q', Q, 'Water') Tsat = round(CP.PropsSI('T','P', P, 'Q', Q, 'Water'),1) rho = round(CP.PropsSI('D','P', P, 'Q', Q, 'Water'),4) v = round(1/rho,4) h = round(CP.PropsSI('H','P', P, 'Q', Q, 'Water'),1) u = round(CP.PropsSI('U','P', P, 'Q', Q, 'Water'),1) s = round(CP.PropsSI('S','P', P, 'Q', Q, 'Water'),1) doc['result'].update({'Psat':{'_val' : '', '_dim':'pressure'}}) doc['result'].update({'Tsat':{'_val' : str(Tsat), '_dim':'temperature'}}) if (state=='Saturated_T'): T = float(doc['input']['T']['_val']) Q = float(doc['input']['Q']['_val']) phase = CP.PhaseSI('T', T, 'Q', Q, 'Water') Psat = round(CP.PropsSI('P','T', T, 'Q', Q, 'Water'),1) rho = round(CP.PropsSI('D','T', T, 'Q', Q, 'Water'),4) v = round(1/rho,4) h = round(CP.PropsSI('H','T', T, 'Q', Q, 'Water'),1) u = round(CP.PropsSI('U','T', T, 'Q', Q, 'Water'),1) s = round(CP.PropsSI('S','T', T, 'Q', Q, 'Water'),1) doc['result'].update({'Psat':{'_val' : str(Psat), '_dim':'pressure'}}) doc['result'].update({'Tsat':{'_val' : '', '_dim':'temperature'}}) if (state=='Superheated_or_Compressed'): T = float(doc['input']['T']['_val']) P = float(doc['input']['P']['_val']) phase = CP.PhaseSI('T', T, 'P', P, 'Water') rho = round(CP.PropsSI('D','T', T, 'P', P, 'Water'),4) v = round(1/rho,1) h = round(CP.PropsSI('H','T', T, 'P', P, 'Water'),1) u = round(CP.PropsSI('U','T', T, 'P', P, 'Water'),1) s = round(CP.PropsSI('S','T', T, 'P', P, 'Water'),1) doc['result'].update({'Psat':{'_val' : '', '_dim':'pressure'}}) doc['result'].update({'Tsat':{'_val' : '', '_dim':'temperature'}}) except Exception as e: raise e doc['errors'].append(str(e)) doc['errors'].append('Failed to calculate Water/Steam Properties. Check Inputs') phase = "" Psat = math.nan Tsat = math.nan rho = math.nan v = math.nan h = math.nan u = math.nan s = math.nan doc['result'].update({'phase':{'_val' : str(phase)}}) doc['result'].update({'rho':{'_val' : str(rho), '_dim':'density'}}) doc['result'].update({'v':{'_val' : str(v), '_dim':'specificVolume'}}) doc['result'].update({'h':{'_val' : str(h), '_dim':'specificEnergy'}}) doc['result'].update({'u':{'_val' : str(u), '_dim':'specificEnergy'}}) doc['result'].update({'s':{'_val' : str(s), '_dim':'specificHeat'}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) K_pipe = 0 K_fittings = 0 K_entry = 0 K_exit = 0 K_fixed = 0 K_LbyD = 0 K_total = 0 LbyD_total = 0 deltaP_fixed = 0 deltaP_total = 0 size_definition = doc['input']['pipe']['size_definition']['_val'] if (size_definition == "NPS"): nps = float(doc['input']['pipe']['NPS']['_val']) schedule = doc['input']['pipe']['schedule']['_val'] NPS, Di, Do, t = nearest_pipe(NPS=nps, schedule=schedule) else: Di = float(doc['input']['pipe']['Dia_inner']['_val']) NPS = math.nan Do = math.nan t = math.nan doc['result'].update({'Di': {'_val': str(Di), '_dim': 'length_mili'}}) doc['result'].update({'Do': {'_val': str(Do), '_dim': 'length_mili'}}) doc['result'].update({'t': {'_val': str(t), '_dim': 'length_mili'}}) area = math.pi * pow(Di / 2, 2) Q = float(doc['input']['fluidData']['Q']['_val']) V = roundit(Q / area) doc['result'].update({'V': {'_val': str(V), '_dim': 'speed'}}) mu = float(doc['input']['fluidData']['mu']['_val']) rho = float(doc['input']['fluidData']['rho']['_val']) Re = roundit(Reynolds(V=V, D=Di, rho=rho, mu=mu)) doc['result'].update({'Re': {'_val': str(Re)}}) Hdyn = roundit(rho * pow(V, 2) / 2) doc['result'].update({'Hdyn': {'_val': str(Hdyn), '_dim': 'length'}}) #K calculation for straigth pipe roughness_basis = doc['input']['pipe']['roughness_basis']['_val'] if (roughness_basis == "Material"): material = doc['input']['pipe']['material']['_val'] roughness = get_roughness(material) else: roughness = float(doc['input']['pipe']['roughness']['_val']) eD = roughness / Di doc['result'].update({'eD': {'_val': str(eD)}}) fd = roundit(friction_factor(Re=Re, eD=eD, Method="Moody")) doc['result'].update({'fd_Moody': {'_val': str(fd)}}) length = float(doc['input']['pipe']['length']['_val']) K_pipe = roundit(K_from_f(fd=fd, L=length, D=Di)) doc['result'].update({'K_pipe': {'_val': str(K_pipe)}}) deltaP_pipe = roundit(dP_from_K(K_pipe, rho, V)) doc['result'].update( {'deltaP_pipe': { '_val': str(deltaP_pipe), '_dim': 'pressure' }}) #calculating pressure drop for entrance entry_type = doc['input']['entrance']['entry_type']['_val'] print('entry type is') print(entry_type) if entry_type == 'none': K_entry = 0 elif entry_type == 'Sharp': K_entry = fluids.fittings.entrance_sharp() elif entry_type == 'Rounded': Rc = float(doc['input']['entrance']['Rc']['_val']) K_entry = fluids.fittings.entrance_rounded(Di, Rc) elif entry_type == 'Angled': angle_radians = float(doc['input']['entrance']['angle']['_val']) angle = angle_radians * 57.2958 K_entry = fluids.fittings.entrance_angled(angle) elif entry_type == 'Projecting': wall_thickness = float( doc['input']['entrance']['wall_thickness']['_val']) K_entry = fluids.fittings.entrance_distance(Di, wall_thickness) K_entry = roundit(K_entry) doc['result'].update({'K_entry': {'_val': str(K_entry)}}) deltaP_entry = roundit(dP_from_K(K_entry, rho, V)) doc['result'].update( {'deltaP_entry': { '_val': str(deltaP_entry), '_dim': 'pressure' }}) #calculating pressure drop for exit exit_type = doc['input']['exit']['exit_type']['_val'] print('exit_type') print(exit_type) if (exit_type == 'Normal'): K_exit = exit_normal() else: K_exit = 0 K_exit = roundit(K_exit) doc['result'].update({'K_exit': {'_val': str(K_exit)}}) deltaP_exit = roundit(dP_from_K(K_exit, rho, V)) doc['result'].update( {'deltaP_exit': { '_val': str(deltaP_exit), '_dim': 'pressure' }}) #calculating pressure drop for fittings fittings_list = doc['input']['fittings'] for fitting in fittings_list: name = get_hooper_list()[fitting['index']] Di_inch = Di * 39.3701 K_fitting = Hooper2K(Di_inch, Re, name=name) K_fittings += K_fitting * fitting['quantity'] K_fittings = roundit(K_fittings) doc['result'].update({'K_fittings': {'_val': str(K_fittings)}}) deltaP_fittings = dP_from_K(K_fittings, rho, V) deltaP_fittings = roundit(deltaP_fittings) doc['result'].update({ 'deltaP_fittings': { '_val': str(deltaP_fittings), '_dim': 'pressure' } }) #calculating pressure drop for sharp contractions deltaP_contractions_sharp = 0 contractions_sharp = doc['input']['contractions_sharp']['_list'] for contraction in contractions_sharp: D1 = contraction['D1'] D2 = contraction['D2'] A2 = 3.1416 * (D2**2) / 4 V2 = Q / A2 K_contraction = fluids.fittings.contraction_sharp(D1, D2) deltaP = dP_from_K(K_contraction, rho, V2) deltaP_contractions_sharp += deltaP deltaP_contractions_sharp = roundit(deltaP_contractions_sharp) doc['result'].update({ 'deltaP_contractions_sharp': { '_val': str(deltaP_contractions_sharp), '_dim': 'pressure' } }) #calculating pressure drop for rounded contractions deltaP_contractions_rounded = 0 contractions_rounded = doc['input']['contractions_rounded']['_list'] for contraction in contractions_rounded: D1 = contraction['D1'] D2 = contraction['D2'] Rc = contraction['Rc'] A2 = 3.1416 * (D2**2) / 4 V2 = Q / A2 K_contraction = fluids.fittings.contraction_round(D1, D2, Rc) deltaP = dP_from_K(K_contraction, rho, V2) deltaP_contractions_rounded += deltaP deltaP_contractions_rounded = roundit(deltaP_contractions_rounded) doc['result'].update({ 'deltaP_contractions_rounded': { '_val': str(deltaP_contractions_rounded), '_dim': 'pressure' } }) #calculating pressure drop for conical contractions deltaP_contractions_conical = 0 contractions_conical = doc['input']['contractions_conical']['_list'] for contraction in contractions_conical: D1 = contraction['D1'] D2 = contraction['D2'] L = contraction['L'] A2 = 3.1416 * (D2**2) / 4 V2 = Q / A2 K_contraction = fluids.fittings.contraction_conical(D1, D2, fd=fd, l=L) deltaP = dP_from_K(K_contraction, rho, V2) deltaP_contractions_conical += deltaP deltaP_contractions_conical = roundit(deltaP_contractions_conical) doc['result'].update({ 'deltaP_contractions_conical': { '_val': str(deltaP_contractions_conical), '_dim': 'pressure' } }) #calculating pressure drop for pipe reducers contractions deltaP_contractions_reducer = 0 contractions_reducer = doc['input']['contractions_reducer']['_list'] for contraction in contractions_reducer: reducer_size = contraction['reducer_size'] D1, D2, L = reducer_dimensions(reducer_size) A2 = 3.1416 * (D2**2) / 4 V2 = Q / A2 K_contraction = fluids.fittings.contraction_conical(D1, D2, fd=fd, l=L) deltaP = dP_from_K(K_contraction, rho, V2) deltaP_contractions_reducer += deltaP deltaP_contractions_reducer = roundit(deltaP_contractions_reducer) doc['result'].update({ 'deltaP_contractions_reducer': { '_val': str(deltaP_contractions_reducer), '_dim': 'pressure' } }) # calculating total pressure drop in all contractions deltaP_contractions = deltaP_contractions_sharp + deltaP_contractions_rounded + deltaP_contractions_conical + deltaP_contractions_reducer deltaP_contractions = roundit(deltaP_contractions) doc['result'].update({ 'deltaP_contractions': { '_val': str(deltaP_contractions), '_dim': 'pressure' } }) #calculating pressure drop for sharp expansions deltaP_expansions_sharp = 0 expansions_sharp = doc['input']['expansions_sharp']['_list'] for contraction in expansions_sharp: D1 = contraction['D1'] D2 = contraction['D2'] A1 = 3.1416 * (D1**2) / 4 V1 = Q / A1 K_contraction = fluids.fittings.diffuser_sharp(D1, D2) deltaP = dP_from_K(K_contraction, rho, V1) deltaP_expansions_sharp += deltaP deltaP_expansions_sharp = roundit(deltaP_expansions_sharp) doc['result'].update({ 'deltaP_expansions_sharp': { '_val': str(deltaP_expansions_sharp), '_dim': 'pressure' } }) #calculating pressure drop for conical expansions deltaP_expansions_conical = 0 expansions_conical = doc['input']['expansions_conical']['_list'] for contraction in expansions_conical: D1 = contraction['D1'] D2 = contraction['D2'] L = contraction['L'] A1 = 3.1416 * (D1**2) / 4 V1 = Q / A1 K_contraction = fluids.fittings.diffuser_conical(D1, D2, fd=fd, l=L) deltaP = dP_from_K(K_contraction, rho, V1) deltaP_expansions_conical += deltaP deltaP_expansions_conical = roundit(deltaP_expansions_conical) doc['result'].update({ 'deltaP_expansions_conical': { '_val': str(deltaP_expansions_conical), '_dim': 'pressure' } }) #calculating pressure drop for pipe reducer expansions deltaP_expansions_reducer = 0 expansions_reducer = doc['input']['expansions_reducer']['_list'] for contraction in expansions_reducer: reducer_size = contraction['reducer_size'] D2, D1, L = reducer_dimensions(reducer_size) A1 = 3.1416 * (D1**2) / 4 V1 = Q / A1 K_contraction = fluids.fittings.diffuser_conical(D1, D2, fd=fd, l=L) deltaP = dP_from_K(K_contraction, rho, V1) deltaP_expansions_reducer += deltaP deltaP_expansions_reducer = roundit(deltaP_expansions_reducer) doc['result'].update({ 'deltaP_expansions_reducer': { '_val': str(deltaP_expansions_reducer), '_dim': 'pressure' } }) # calculating total pressure drop in all expansions deltaP_expansions = deltaP_expansions_sharp + deltaP_expansions_conical + deltaP_expansions_reducer doc['result'].update( {'deltaP_expansions': { '_val': deltaP_expansions, '_dim': 'pressure' }}) fixed_K_loss = doc['input']['fixed_K_losses']['_list'] for loss in fixed_K_loss: K_fixed += loss['K'] * loss['quantity'] deltaP_fixed_K = dP_from_K(K_fixed, rho, V) fixed_LbyD_loss = doc['input']['fixed_LbyD_losses']['_list'] for loss in fixed_LbyD_loss: L_D = loss['LbyD'] K_LbyD += K_from_L_equiv(L_D=L_D, fd=fd) * loss['quantity'] deltaP_fixed_LbyD = dP_from_K(K_LbyD, rho, V) fixed_deltaP_loss = doc['input']['fixed_deltaP_losses']['_list'] for loss in fixed_deltaP_loss: deltaP_fixed += loss['deltaP'] * loss['quantity'] deltaP_fixed_deltaP = deltaP_fixed deltaP_fixed_all = deltaP_fixed_K + deltaP_fixed_LbyD + deltaP_fixed_deltaP deltaP_fixed_all = roundit(deltaP_fixed_all) doc['result'].update({ 'deltaP_fixed_all': { '_val': str(deltaP_fixed_all), '_dim': 'pressure' } }) deltaP_total = deltaP_pipe + deltaP_entry + deltaP_exit + deltaP_fittings + deltaP_contractions + deltaP_expansions + deltaP_fixed_all deltaP_total = roundit(deltaP_total) doc['result'].update( {'deltaP_total': { '_val': str(deltaP_total), '_dim': 'pressure' }}) # doc_original['input'].update(doc['input']) doc_original['result'].update(doc['result']) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] =[] fluid = doc['input']['fluid']['_val'] P = float(doc['input']['P']['_val']) T = float(doc['input']['T']['_val']) result = {} try: phase = CP.PhaseSI('T',T, 'P',P, fluid) except Exception as e: phase = "" doc['errors'].append("Failed to calculate 'phase' . Check Inputs") finally: doc['result'].update({'phase':{'_val' : phase}}) try: MW = round(CP.PropsSI('M', fluid),5) except Exception as e: MW = math.nan doc['errors'].append("Failed to calculate 'MW' . Check Inputs") finally: doc['result'].update({'MW':{'_val' : str(MW), '_dim':'molecularMass'}}) try: Pcritical = round(CP.PropsSI('Pcrit', 'T',T, 'P',P, fluid),1) except: Pcritical = math.nan doc['errors'].append("Failed to calculate 'Pcritical' . Check Inputs") finally: doc['result'].update({'Pcritical':{'_val' : str(Pcritical), '_dim':'pressure'}}) try: Tcritical = round(CP.PropsSI('Tcrit', 'T',T, 'P',P, fluid),1) except: Tcritical = math.nan doc['errors'].append("Failed to calculate 'Tcritical' . Check Inputs") finally: doc['result'].update({'Tcritical':{'_val' : str(Tcritical), '_dim':'temperature'}}) try: Ptriple = round(CP.PropsSI('P_TRIPLE', 'T',T, 'P',P, fluid),1) except: Ptriple = math.nan doc['errors'].append("Failed to calculate 'Ptriple' . Check Inputs") finally: doc['result'].update({'Ptriple':{'_val' : str(Ptriple), '_dim':'pressure'}}) try: Ttriple = round(CP.PropsSI('T_TRIPLE', 'T',T, 'P',P, fluid),1) except: Ttriple = math.nan doc['errors'].append("Failed to calculate 'Ttriple' . Check Inputs") finally: doc['result'].update({'Ttriple':{'_val' : str(Ttriple), '_dim':'temperature'}}) try: acentric = round(CP.PropsSI('acentric', 'T',T, 'P',P, fluid),4) except: acentric = math.nan doc['errors'].append("Failed to calculate 'acentric' . Check Inputs") finally: doc['result'].update({'acentric':{'_val' : str(acentric)}}) try: Z = round(CP.PropsSI('Z', 'T',T, 'P',P, fluid),4) except: Z = math.nan doc['errors'].append("Failed to calculate 'Z' . Check Inputs") finally: doc['result'].update({'Z':{'_val' : str(Z)}}) try: rho = round(CP.PropsSI('D', 'T',T, 'P',P, fluid),4) v = round(1/rho,4) except: rho = math.nan v = math.nan doc['errors'].append("Failed to calculate 'Density' and 'Specific Volume' . Check Inputs") finally: doc['result'].update({'rho':{'_val' : str(rho), '_dim':'density'}}) doc['result'].update({'v':{'_val' : str(v), '_dim':'specificVolume'}}) try: h = round(CP.PropsSI('H', 'T',T, 'P',P, fluid),1) except: h = math.nan doc['errors'].append("Failed to calculate 'Enthalphy' . Check Inputs") finally: doc['result'].update({'h':{'_val' : str(h), '_dim':'specificEnergy'}}) try: u = round(CP.PropsSI('U', 'T',T, 'P',P, fluid),1) except: u = math.nan doc['errors'].append("Failed to calculate 'Specific Internal Energy' . Check Inputs") finally: doc['result'].update({'u':{'_val' : str(u), '_dim':'specificEnergy'}}) try: s = round(CP.PropsSI('S', 'T',T, 'P',P, fluid),1) except: s = math.nan doc['errors'].append("Failed to calculate 'Specific Entropy' . Check Inputs") finally: doc['result'].update({'s':{'_val' : str(s), '_dim':'specificHeat'}}) try: gibbs = round(CP.PropsSI('G', 'T',T, 'P',P, fluid),1) except: gibbs = math.nan doc['errors'].append("Failed to calculate 'Gibbs Free Energy' . Check Inputs") finally: doc['result'].update({'gibbs':{'_val' : str(gibbs), '_dim':'specificEnergy'}}) try: helmholtz = round(CP.PropsSI('Helmholtzmass', 'T',T, 'P',P, fluid),1) except: helmholtz = math.nan doc['errors'].append("Failed to calculate 'Helmholtz Energy' . Check Inputs") finally: doc['result'].update({'helmholtz':{'_val' : str(helmholtz), '_dim':'specificEnergy'}}) try: Cp = round(CP.PropsSI('Cpmass', 'T',T, 'P',P, fluid),1) except: Cp = math.nan doc['errors'].append("Failed to calculate 'Cp' . Check Inputs") finally: doc['result'].update({'Cp':{'_val' : str(Cp), '_dim':'specificHeat'}}) try: Cv = round(CP.PropsSI('Cvmass', 'T',T, 'P',P, fluid),1) except: Cv = math.nan doc['errors'].append("Failed to calculate 'Cv' . Check Inputs") finally: doc['result'].update({'Cv':{'_val' : str(Cv), '_dim':'specificHeat'}}) try: Cp_molar = round(CP.PropsSI('Cpmolar', 'T',T, 'P',P, fluid),1) except: Cp_molar = math.nan doc['errors'].append("Failed to calculate 'Cp_molar' . Check Inputs") finally: doc['result'].update({'Cp_molar':{'_val' : str(Cp_molar), '_dim':'specificHeatMolar'}}) try: Cv_molar = round(CP.PropsSI('Cvmolar', 'T',T, 'P',P, fluid),1) except: Cv_molar = math.nan doc['errors'].append("Failed to calculate 'Cv_molar' . Check Inputs") finally: doc['result'].update({'Cv_molar':{'_val' : str(Cv_molar), '_dim':'specificHeatMolar'}}) try: Cp0 = round(CP.PropsSI('Cp0mass', 'T',T, 'P',P, fluid),1) except: Cp0 = math.nan doc['errors'].append("Failed to calculate 'Cp0' . Check Inputs") finally: doc['result'].update({'Cp0':{'_val' : str(Cp0), '_dim':'specificHeat'}}) try: Prandtl = round(CP.PropsSI('Prandtl', 'T',T, 'P',P, fluid),4) except: Prandtl = math.nan doc['errors'].append("Failed to calculate 'Prandtl' . Check Inputs") finally: doc['result'].update({'Prandtl':{'_val' : str(Prandtl)}}) try: dynViscosity = round(CP.PropsSI('viscosity', 'T',T, 'P',P, fluid),8) except: dynViscosity = math.nan doc['errors'].append("Failed to calculate 'Dynamic Viscosity' . Check Inputs") finally: doc['result'].update({'dynViscosity':{'_val' : str(dynViscosity), '_dim':'dynViscosity'}}) try: conductivity = round(CP.PropsSI('conductivity', 'T',T, 'P',P, fluid),8) except: conductivity = math.nan doc['errors'].append("Failed to calculate 'Thermal Conductivity' . Check Inputs") finally: doc['result'].update({'conductivity':{'_val' : str(conductivity), '_dim':'thermalConductivity'}}) try: HH = CP.PropsSI('HH', 'T',T, 'P',P, fluid) except: HH="" finally: doc['result'].update({'HH':{'_val' : str(HH)}}) try: PH = CP.PropsSI('PH', 'T',T, 'P',P, fluid) except: PH = "" finally: doc['result'].update({'PH':{'_val' : str(PH)}}) try: GWP = CP.PropsSI('GWP100', 'T',T, 'P',P, fluid) except: GWP = "" finally: doc['result'].update({'GWP':{'_val' : str(GWP)}}) try: ODP = CP.PropsSI('ODP', 'T',T, 'P',P, fluid) except: ODP = "" finally: doc['result'].update({'ODP':{'_val' : str(ODP)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] D = None tn = parseFloat(doc['input']['tn']['_val']) Z = parseFloat(doc['input']['Z']['_val']) Pi = parseFloat(doc['input']['Pi']['_val']) Ti = parseFloat(doc['input']['Ti']['_val']) Tt = parseFloat(doc['input']['Tt']['_val']) ca = parseFloat(doc['input']['ca']['_val']) MOC = doc['input']['MOC']['_val'] D_basis = doc['input']['D_basis']['_val'] if (D_basis=='inner'): D = parseFloat(doc['input']['D']['_val']) Do = D+2*tn elif(D_basis=='outer'): Do = parseFloat(doc['input']['Do']['_val']) D = Do - 2*tn else: doc[errors].append('Invalid value for "Shell Diameter given as"') doc['result'].update({'D':{'_val' : str(roundit(D)), '_dim':'length'}}) doc['result'].update({'Do':{'_val' : str(roundit(Do)), '_dim':'length'}}) # get inner radius and outer radius R = D/2 Ro = Do/2 # get inner radius in corroded condition Dcor = D + 2*ca Rcor = R + ca doc['result'].update({'Rcor':{'_val' : str(roundit(Rcor)), '_dim':'length'}}) # set the available thickness after deducting corrosion tcor = tn - ca doc['result'].update({'tcor':{'_val' : str(roundit(tcor)), '_dim':'length'}}) # determine the value of allowable stress if (MOC=='Other'): S = parseFloat(doc['input']['S']['_val']) St = parseFloat(doc['input']['St']['_val']) else: S = pv.getAllowableStress(MOC, Ti) St = pv.getAllowableStress(MOC, Tt) doc['result'].update({'S':{'_val' : str(roundit(S)), '_dim':'pressure'}}) doc['result'].update({'St':{'_val' : str(roundit(St)), '_dim':'pressure'}}) density = 7850 # set the minimum required thickness as per UG-15 tu = 1.5/1000 doc['result'].update({'tu':{'_val' : str(roundit(tu)), '_dim':'length'}}) # check whether the geometry is sphere or cylinder Shape = doc['input']['Shape']['_val'] if (Shape=='cylindrical'): Ec = parseFloat(doc['input']['Ec']['_val']) El = parseFloat(doc['input']['El']['_val']) # Circumferential Stress Evaluation try: tc, condn_Pc, eqn_ref_tc = pv.thicknessCylinderCircumStress(S, El, Pi, Rcor) except Exception as e: tc = nan condn_Pc = "" eqn_ref_tc = "" error_message = "Failed to calculate thickness(circumferential stress) for cylindrical shell" + " " + str(e) doc['errors'].append(error_message) doc['result'].update({'tc':{'_val' : str(roundit(tc)), '_dim':'length'}}) doc['result'].update({'condn_Pc':{'_val' : condn_Pc}}) doc['result'].update({'eqn_ref_tc':{'_val' : eqn_ref_tc}}) # Longitudinal Stress Evaluation try: tl, condn_Pl, eqn_ref_tl = pv.thicknessCylinderLongStress(S, Ec, Pi, Rcor) except Exception as e: tl = nan condn_Pl = "" eqn_ref_tl = "" error_message = "Failed to calculate thickness(longitudinal stress) for cylindrical shell" + " " + str(e) doc['errors'].append(error_message) doc['result'].update({'tl':{'_val' : str(roundit(tl)), '_dim':'length'}}) doc['result'].update({'condn_Pl':{'_val' : condn_Pl}}) doc['result'].update({'eqn_ref_tl':{'_val' : eqn_ref_tl}}) # get the highest of the shell thickness determined as per circumferential analysis, longitudinal analysis and UG-15 requirement t = max([tu,tc,tl]) try: MAWPc, condn_tc, eqn_ref_pc = pv.pressureCylinderCircumStress(S, El, tcor, Rcor) except Exception as e: MAWPc = nan condn_tc = "" eqn_ref_pc = "" error_message = "Failed to calculate MAWP(circumferential stress) for cylindrical shell" + " " + str(e) doc['errors'].append(error_message) doc['result'].update({'MAWPc':{'_val' : str(roundit(MAWPc)), '_dim':'pressure'}}) doc['result'].update({'condn_tc' :{'_val' : condn_tc}}) doc['result'].update({'eqn_ref_pc':{'_val' : eqn_ref_pc}}) try: MAWPl, condn_tl, eqn_ref_pl = pv.pressureCylinderLongStress(S, Ec, tcor, Rcor) except Exception as e: MAWPl = nan condn_tl = "" eqn_ref_pl = "" error_message = "Failed to calculate MAWP(longitudinal stress) for cylindrical shell" + " " + str(e) doc['errors'].append(error_message) doc['result'].update({'MAWPl':{'_val' : str(roundit(MAWPl)), '_dim':'pressure'}}) doc['result'].update({'condn_tl' :{'_val' : condn_tl}}) doc['result'].update({'eqn_ref_pl':{'_val' : eqn_ref_pl}}) # get the least of the MAWP from circumferential and longitudinal analysis to get governing MAWP MAWPsh = min([MAWPc,MAWPl]) doc['result'].update({'MAWPsh':{'_val' : str(roundit(MAWPsh)), '_dim':'pressure'}}) try: shell_volume, shell_matlVolume = pv.cylindricalShellVolume(tn, Z, D=D) except Exception as e: shell_volume = nan shell_matlVolume = nan error_message = "Failed to calculate volume for cylindrical shell" + " " + str(e) doc['errors'].append(error_message) # carry out head evaluation Head1 = doc['input']['Head1']['_val'] tn1 = parseFloat(doc['input']['tn1']['_val']) D1 = D Do1 = D1 + 2*tn1 R1 = D1/2 Dcor1 = D1 + 2*ca Rcor1 = Dcor1/2 tcor1 = tn1 - ca doc['result'].update({'D1':{'_val' : str(roundit(D1)), '_dim':'length'}}) doc['result'].update({'Do1':{'_val' : str(roundit(Do1)), '_dim':'length'}}) doc['result'].update({'tcor1':{'_val' : str(roundit(tcor1)), '_dim':'length'}}) t1 = nan tcone1 = nan tknuckle1 = nan MAWP1 = nan Pcone1 = nan Pknuckle1 = nan L1 = nan Kcor1 = nan Mcor1 = nan condn_P1 = "" condn_t1 = "" eqn_ref_t1 = "" eqn_ref_p1 = "" eqn_refconet1 = "" eqn_ref_knucklet1 = "" eqn_ref_coneP1 = "" eqn_ref_knuckleP1 = "" V1 = nan Vm1 = nan if (Head1=='ellipsoidal'): beta1 = parseFloat(doc['input']['beta1']['_val']) h1 = D1/(2*beta1) hcor1 = h1 + ca betacor1 = Dcor1/(2*hcor1) try: th1, Kcor1, eqn_ref_t1 = pv.thicknessEllipsoidalHead(S, Ec, P=Pi, D=Dcor1, ar = betacor1) except Exception as e: doc['errors'].append("Failed to calculate thickness for ellipsoidal head, Side 1." + " " + str(e)) try: MAWP1, Kcor1, eqn_ref_p1 = pv.pressureEllipsoidalHead(S, Ec, t=tcor1, D=Dcor1, ar = betacor1) except Exception as e: doc['errors'].append("Failed to calculate MAWP for ellipsoidal head, Side 1." + " " + str(e)) try: V1, Vm1 = pv.volumeEllipsoidalHead(tn1, beta1, D=D1) except Exception as e: doc['errors'].append("Failed to calculate ellipsoidal Head volume, Side 1." + " " + str(e)) doc['result'].update({'Kcor1':{'_val' : str(roundit(Kcor1))}}) elif (Head1=='torispherical'): L1 = parseFloat(doc['input']['L1']['_val']) r1 = parseFloat(doc['input']['r1']['_val']) Lcor1 = L1 + ca rcor1 = r1 + ca try: th1, Mcor1, eqn_ref_t1 = pv.thicknessTorisphericalHead(S, Ec, P=Pi, Do=Do1, L=Lcor1, r=rcor1) except Exception as e: doc['errors'].append("Failed to calculate thickness for torispherical head, Side 1." + " " + str(e)) try: MAWP1, Mcor1, eqn_ref_p1 = pv.pressureTorisphericalHead(S, Ec, t=tcor1, Do=Do1, L=Lcor1, r=rcor1) except Exception as e: doc['errors'].append("Failed to calculate MAWP for torispherical head, Side 1." + " " + str(e)) try: V1, Vm1 = pv.volumeTorisphericalHead(tn1, L=L1, r=r1, D=D1) except Exception as e: doc['errors'].append("Failed to calculate torispherical Head volume, Side 1." + " " + str(e)) doc['result'].update({'Mcor1':{'_val' : str(roundit(Mcor1))}}) elif (Head1=='hemispherical'): try: th1, condn_P1, eqn_ref_t1 = pv.thicknessSphere(S, Ec, P=Pi, R=Rcor1) except Exception as e: doc['errors'].append("Failed to calculate thickness for head, Side 1." + " " + str(e)) try: MAWP1, condn_t1, eqn_ref_p1 = pv.pressureSphere(S, Ec, t=tcor1, R=Rcor1) except Exception as e: doc['errors'].append("Failed to calculate MAWP for hemispherical head, Side 1." + " " + str(e)) try: V1, Vm1 = pv.volumeHemisphericalHead(tn1, D=D1) except Exception as e: doc['errors'].append("Failed to calculate volume for hemispherical Head, Side 1." + " " + str(e)) doc['result'].update({'condn_P1':{'_val' : condn_P1}}) doc['result'].update({'condn_t1':{'_val' : condn_t1}}) elif (Head1=='conical'): alpha1 = parseFloat(doc['input']['alpha1']['_val']) try: th1, eqn_ref_t1 = pv.thicknessConicalHead(S, Ec, P=Pi, D=Dcor1, alpha=alpha1) except Exception as e: doc['errors'].append("Failed to calculate thickness for conical Head, Side 1." + " " + str(e)) try: MAWP1, eqn_ref_p1 = pv.pressureConicalHead(S, Ec, t=tcor1, D=D1, alpha=alpha1) except Exception as e: doc['errors'].append("Failed to calculate MAWP for conical Head, Side 1." + " " + str(e)) try: V1, Vm1 = pv.volumeConicalHead(tn1, alpha1, D=D1) except Exception as e: doc['errors'].append("Failed to calculate volume for conical Head, Side 1." + " " + str(e)) elif (Head1=='toriconical'): r1 = parseFloat(doc['input']['r1']['_val']) alpha1 = parseFloat(doc['input']['alpha1']['_val']) rcor1 = r1 + ca Dicor1 = Dcor1 - 2*rcor1*(2-cos(alpha1)) try: th1, tcone1, eqn_ref_conet1, tknuckle1, Lcor1, Mcor1, eqn_ref_knucklet1 = pv.thicknessToriConicalHead(S, Ec, P=Pi, Do=Do1, tn=tn1, Di=Dicor1, r=rcor1, alpha=alpha1) except Exception as e: doc['errors'].append("Failed to calculate thickness for toriconical head, Side 1." + " " + str(e)) try: MAWP1, Pcone1, eqn_ref_coneP1, Pknuckle1, Lcor1, Mcor1, eqn_ref_knuckleP1 = pv.pressureToriConicalHead(S, Ec, t=tcor1, Do=Do1, tn=tn1, Di=Dicor1, r=rcor1, alpha=alpha1) except Exception as e: doc['errors'].append("Failed to calculate MAWP for toriconical head, Side 1." + " " + str(e)) eqn_ref_t1 = "" eqn_ref_p1 = "" try: V1, Vm1 = pv.volumeToriconicalHead(tn1, r1, alpha1, D=D1) except Exception as e: doc['errors'].append("Failed to calculate volume for toriconical Head, Side 1." + " " + str(e)) doc['result'].update({'Dicor1':{'_val' : str(roundit(Dicor1)), '_dim':'length'}}) doc['result'].update({'Lcor1':{'_val' : str(roundit(Lcor1)), '_dim':'length'}}) doc['result'].update({'Mcor1':{'_val' : str(roundit(Mcor1))}}) doc['result'].update({'tcone1':{'_val' : str(roundit(tcone1)), '_dim':'length'}}) doc['result'].update({'eqn_ref_conet1':{'_val' : eqn_ref_conet1}}) doc['result'].update({'tknuckle1':{'_val' : str(roundit(tknuckle1)), '_dim':'length'}}) doc['result'].update({'eqn_ref_knucklet1':{'_val' : eqn_ref_knucklet1}}) doc['result'].update({'Pcone1':{'_val' : str(roundit(Pcone1)), '_dim':'pressure'}}) doc['result'].update({'eqn_ref_coneP1':{'_val' : eqn_ref_coneP1}}) doc['result'].update({'Pknuckle1':{'_val' : str(roundit(Pknuckle1)), '_dim':'pressure'}}) doc['result'].update({'eqn_ref_knuckleP1':{'_val' : eqn_ref_knuckleP1}}) else: doc['errors'].append('Invalid input for Head - Side 1') t1 = max([th1,tu]) tr1 = t1 + ca if (tn1>=tr1): tn1_adequate = "Yes" else: tn1_adequate = "No" head1_weight = density*Vm1 doc['result'].update({'th1':{'_val' : str(roundit(th1)), '_dim':'length'}}) doc['result'].update({'t1':{'_val' : str(roundit(t1)), '_dim':'length'}}) doc['result'].update({'eqn_ref_t1':{'_val' : eqn_ref_t1}}) doc['result'].update({'tr1':{'_val' : str(roundit(tr1)), '_dim':'length'}}) doc['result'].update({'tn1_adequate':{'_val' : tn1_adequate}}) doc['result'].update({'MAWP1':{'_val' : str(roundit(MAWP1)), '_dim':'pressure'}}) doc['result'].update({'eqn_ref_p1':{'_val' : eqn_ref_p1}}) doc['result'].update({'head1_weight':{'_val' : str(roundit(head1_weight)), '_dim':'mass'}}) doc['result'].update({'V1':{'_val' : str(roundit(V1)), '_dim':'volume'}}) Head2 = doc['input']['Head2']['_val'] tn2 = parseFloat(doc['input']['tn2']['_val']) D2 = D Do2 = D2 + 2*tn2 R2 = D2/2 Dcor2 = D2 + 2*ca Rcor2 = Dcor2/2 tcor2 = tn2 - ca doc['result'].update({'D2':{'_val' : str(roundit(D2)), '_dim':'length'}}) doc['result'].update({'Do2':{'_val' : str(roundit(Do2)), '_dim':'length'}}) doc['result'].update({'tcor2':{'_val' : str(roundit(tcor2)), '_dim':'length'}}) t2 = nan tcone2 = nan tknuckle2 = nan MAWP2 = nan Pcone2 = nan Pknuckle2 = nan L2 = nan Kcor2 = nan Mcor2 = nan condn_P2 = "" condn_t2 = "" eqn_ref_t2 = "" eqn_ref_p2 = "" eqn_refconet2 = "" eqn_ref_knucklet2 = "" eqn_ref_coneP2 = "" eqn_ref_knuckleP2 = "" V2 = nan Vm2 = nan if (Head2=='ellipsoidal'): beta2 = parseFloat(doc['input']['beta2']['_val']) h2 = D2/(2*beta2) hcor2 = h2 + ca betacor2 = Dcor2/(2*hcor2) try: th2, Kcor2, eqn_ref_t2 = pv.thicknessEllipsoidalHead(S, Ec, P=Pi, D=Dcor2, ar = betacor2) except Exception as e: doc['errors'].append("Failed to calculate thickness for ellipsoidal head, Side 2." + " " + str(e)) try: MAWP2, Kcor2, eqn_ref_p2 = pv.pressureEllipsoidalHead(S, Ec, t=tcor2, D=Dcor2, ar = betacor2) except Exception as e: doc['errors'].append("Failed to calculate MAWP for ellipsoidal head, Side 2." + " " + str(e)) try: V2, Vm2 = pv.volumeEllipsoidalHead(tn2, beta2, D=D2) except Exception as e: doc['errors'].append("Failed to calculate ellipsoidal Head volume, Side 2." + " " + str(e)) doc['result'].update({'Kcor2':{'_val' : str(roundit(Kcor2))}}) elif (Head2=='torispherical'): L2 = parseFloat(doc['input']['L2']['_val']) r2 = parseFloat(doc['input']['r2']['_val']) Lcor2 = L2 + ca rcor2 = r2 + ca try: th2, Mcor2, eqn_ref_t2 = pv.thicknessTorisphericalHead(S, Ec, P=Pi, Do=Do2, L=Lcor2, r=rcor2) except Exception as e: doc['errors'].append("Failed to calculate thickness for torispherical head, Side 2." + " " + str(e)) try: MAWP2, Mcor2, eqn_ref_p2 = pv.pressureTorisphericalHead(S, Ec, t=tcor2, Do=Do2, L=Lcor2, r=rcor2) except Exception as e: doc['errors'].append("Failed to calculate MAWP for torispherical head, Side 2." + " " + str(e)) try: V2, Vm2 = pv.volumeTorisphericalHead(tn2, L=L2, r=r2, D=D2) except Exception as e: doc['errors'].append("Failed to calculate torispherical Head volume, Side 2." + " " + str(e)) doc['result'].update({'Mcor2':{'_val' : str(roundit(Mcor2))}}) elif (Head2=='hemispherical'): try: th2, condn_P2, eqn_ref_t2 = pv.thicknessSphere(S, Ec, P=Pi, R=Rcor2) except Exception as e: doc['errors'].append("Failed to calculate thickness for head, Side 2." + " " + str(e)) try: MAWP2, condn_t2, eqn_ref_p2 = pv.pressureSphere(S, Ec, t=tcor2, R=Rcor2) except Exception as e: doc['errors'].append("Failed to calculate MAWP for hemispherical head, Side 2." + " " + str(e)) try: V2, Vm2 = pv.volumeHemisphericalHead(tn2, D=D2) except Exception as e: doc['errors'].append("Failed to calculate volume for hemispherical Head, Side 2." + " " + str(e)) doc['result'].update({'condn_P2':{'_val' : condn_P2}}) doc['result'].update({'condn_t2':{'_val' : condn_t2}}) elif (Head2=='conical'): alpha2 = parseFloat(doc['input']['alpha2']['_val']) try: th2, eqn_ref_t2 = pv.thicknessConicalHead(S, Ec, P=Pi, D=Dcor2, alpha=alpha2) except Exception as e: doc['errors'].append("Failed to calculate thickness for conical Head, Side 2." + " " + str(e)) try: MAWP2, eqn_ref_p2 = pv.pressureConicalHead(S, Ec, t=tcor2, D=Dcor2, alpha=alpha2) except Exception as e: doc['errors'].append("Failed to calculate MAWP for conical Head, Side 2." + " " + str(e)) try: V2, Vm2 = pv.volumeConicalHead(tn2, alpha2, D=D2) except Exception as e: doc['errors'].append("Failed to calculate volume for conical Head, Side 2." + " " + str(e)) elif (Head2=='toriconical'): r2 = parseFloat(doc['input']['r2']['_val']) alpha2 = parseFloat(doc['input']['alpha2']['_val']) rcor2 = r2 + ca Dicor2 = Dcor2 - 2*rcor2*(2-cos(alpha2)) try: th2, tcone2, eqn_ref_conet2, tknuckle2, L2, Mcor2, eqn_ref_knucklet2 = pv.thicknessToriConicalHead(S, Ec, P=Pi, Do=Do2, tn=tn2, Di=Dicor2, r=rcor2, alpha=alpha2) except Exception as e: doc['errors'].append("Failed to calculate thickness for toriconical head, Side 2." + " " + str(e)) try: MAWP2, Pcone2, eqn_ref_coneP2, Pknuckle2, Lcor2, Mcor2, eqn_ref_knuckleP2 = pv.pressureToriConicalHead(S, Ec, t=tcor2, Do=Do2, tn=tn2, Di=Dicor2, r=rcor2, alpha=alpha2) except Exception as e: doc['errors'].append("Failed to calculate MAWP for toriconical head, Side 2." + " " + str(e)) eqn_ref_t2 = "" eqn_ref_p2 = "" try: V2, Vm2 = pv.volumeToriconicalHead(tn2, r2, alpha2, D=D2) except Exception as e: doc['errors'].append("Failed to calculate volume for toriconical Head, Side 2." + " " + str(e)) doc['result'].update({'Dicor2':{'_val' : str(roundit(Dicor2)), '_dim':'length'}}) doc['result'].update({'Lcor2':{'_val' : str(roundit(Lcor2)), '_dim':'length'}}) doc['result'].update({'Mcor2':{'_val' : str(roundit(Mcor2))}}) doc['result'].update({'tcone2':{'_val' : str(roundit(tcone2)), '_dim':'length'}}) doc['result'].update({'eqn_ref_conet2':{'_val' : eqn_ref_conet2}}) doc['result'].update({'tknuckle2':{'_val' : str(roundit(tknuckle2)), '_dim':'length'}}) doc['result'].update({'eqn_ref_knucklet2':{'_val' : eqn_ref_knucklet2}}) doc['result'].update({'Pcone2':{'_val' : str(roundit(Pcone2)), '_dim':'pressure'}}) doc['result'].update({'eqn_ref_coneP2':{'_val' : eqn_ref_coneP2}}) doc['result'].update({'Pknuckle2':{'_val' : str(roundit(Pknuckle2)), '_dim':'pressure'}}) doc['result'].update({'eqn_ref_knuckleP2':{'_val' : eqn_ref_knuckleP2}}) else: doc['errors'].append('Invalid input for Head - Side 2') t2 = max([th2,tu]) tr2 = t2 + ca if (tn2>=tr2): tn2_adequate = "Yes" else: tn2_adequate = "No" head2_weight = density*Vm2 doc['result'].update({'th2':{'_val' : str(roundit(th2)), '_dim':'length'}}) doc['result'].update({'t2':{'_val' : str(roundit(t2)), '_dim':'length'}}) doc['result'].update({'eqn_ref_t2':{'_val' : eqn_ref_t2}}) doc['result'].update({'tr2':{'_val' : str(roundit(tr2)), '_dim':'length'}}) doc['result'].update({'tn2_adequate':{'_val' : tn2_adequate}}) doc['result'].update({'MAWP2':{'_val' : str(roundit(MAWP2)), '_dim':'pressure'}}) doc['result'].update({'eqn_ref_p2':{'_val' : eqn_ref_p2}}) doc['result'].update({'head2_weight':{'_val' : str(roundit(head2_weight)), '_dim':'mass'}}) doc['result'].update({'V2':{'_val' : str(roundit(V2)), '_dim':'volume'}}) # get the least of the MAWP from circumferential and longitudinal analysis to get governing MAWP MAWP = min([MAWPc,MAWPl, MAWP1, MAWP2]) shell_weight = density*shell_matlVolume vessel_volume = shell_volume + V1 + V2 vslhd_weight = shell_weight + head1_weight + head2_weight elif (Shape=='spherical'): # Spherical Stress Evaluation E = parseFloat(doc['input']['E']['_val']) if (R is not None): ts, condn_Ps, eqn_ref_ts = pv.thicknessSphere(S, E, Pi, R) MAWPs, condn_ts, eqn_ref_ps = pv.pressureSphere(S, E, tcor, R) else: ts, condn_Ps, eqn_ref_ts = pv.thicknessSphere(S, E, Pi, Ro) MAWPs, condn_ts, eqn_ref_ps = pv.pressureSphere(S, E, tcor, Ro) # get the highest of the shell thickness determined as per circumferential analysis, longitudinal analysis and UG-15 requirement t = max([tu,ts]) # get the least of the MAWP from circumferential and longitudinal analysis to get governing MAWP MAWPsh = MAWPs doc['result'].update({'MAWPsh':{'_val' : str(roundit(MAWPsh)), '_dim':'pressure'}}) if (D is not None): shell_volume, shell_matlVolume = pv.sphericalShellVolume(tn, D=D) else: shell_volume, shell_matlVolume = pv.sphericalShellVolume(tn, Do=Do) shell_weight = density*shell_matlVolume vessel_volume = shell_volume vslhd_weight = shell_weight MAWP = MAWPsh doc['result'].update({'ts':{'_val' : str(roundit(ts)), '_dim':'length'}}) doc['result'].update({'condn_Ps':{'_val' : condn_Ps}}) doc['result'].update({'eqn_ref_ts':{'_val' : eqn_ref_ts}}) doc['result'].update({'MAWPs':{'_val' : str(roundit(MAWPs)), '_dim':'pressure'}}) doc['result'].update({'condn_ts' :{'_val' : condn_ts}}) doc['result'].update({'eqn_ref_ps':{'_val' : eqn_ref_ps}}) else: doc['errors'].append('Invalid Shape') # add the corrosion allowance to get minimum thickness requirement tr = t + ca if (tn >= tr): tn_adequate = "Yes" else: tn_adequate = "No" Pt = pv.pressureHydroUG99(MAWP=MAWP, S=S,St=St) zeta = parseFloat(doc['input']['zeta']['_val']) vessel_weight = vslhd_weight*(1 + (zeta/100)) vessel_weight_hydrotest = vessel_weight + 1000*vessel_volume doc['result'].update({'t' :{'_val' : str(roundit(t)), '_dim':'length'}}) doc['result'].update({'tr':{'_val' : str(roundit(tr)), '_dim':'length'}}) doc['result'].update({'tn_adequate':{'_val' : tn_adequate}}) doc['result'].update({'shell_weight':{'_val' : str(roundit(shell_weight)), '_dim':'mass'}}) doc['result'].update({'shell_volume':{'_val' : str(roundit(shell_volume)), '_dim':'volume'}}) doc['result'].update({'MAWP' :{'_val' : str(roundit(MAWP)), '_dim':'pressure'}}) doc['result'].update({'Pt' :{'_val' : str(roundit(Pt)), '_dim':'pressure'}}) doc['result'].update({'vslhd_weight':{'_val' : str(roundit(vslhd_weight)), '_dim':'mass'}}) doc['result'].update({'vessel_weight':{'_val' : str(roundit(vessel_weight)), '_dim':'mass'}}) doc['result'].update({'vessel_volume':{'_val' : str(roundit(vessel_volume)), '_dim':'volume'}}) doc['result'].update({'vessel_weight_hydrotest':{'_val' : str(roundit(vessel_weight_hydrotest)), '_dim':'mass'}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] Qbep = float(doc['input']['Qbep']['_val']) Hbep = float(doc['input']['Hbep']['_val']) speed = float(doc['input']['speed']['_val']) viscosity_basis = doc['input']['viscosity_basis']['_val'] if (viscosity_basis == 'kinematic'): nu = float(doc['input']['nu']['_val']) else: mu = float(doc['input']['mu']['_val']) rho = float(doc['input']['rho']['_val']) nu = dyn2kinVisc(mu, rho) Q = float(doc['input']['Q']['_val']) try: Qratio = Q / Qbep Cq, Ch, Ceta = viscCorr(Qbep, Hbep, nu, speed, Qratio) Cq = roundit(Cq) Ch = roundit(Ch) Ceta = roundit(Ceta) except Exception as e: doc['errors'].append(str(e)) doc['errors'].append( 'Failed to calculate correction factors. Check Inputs') Cq = math.nan Ch = math.nan Ceta = math.nan doc['result'].update({'nu': {'_val': str(nu), '_dim': 'kinViscosity'}}) doc['result'].update({'Cq': {'_val': str(Cq)}}) doc['result'].update({'Ch': {'_val': str(Ch)}}) doc['result'].update({'Ceta': {'_val': str(Ceta)}}) try: Qvis = roundit(Q * Cq) doc['result'].update({'Qvis': {'_val': str(Qvis), '_dim': 'flow'}}) except Exception: doc['result'].update({'Qvis': {'_val': ' ', '_dim': 'flow'}}) try: H = float(doc['input']['H']['_val']) Hvis = roundit(H * Ch) doc['result'].update({'Hvis': {'_val': str(Hvis), '_dim': 'length'}}) except Exception: doc['result'].update({'Hvis': {'_val': ' ', '_dim': 'length'}}) try: eta = float(doc['input']['eta']['_val']) etavis = roundit(eta * Ceta) doc['result'].update({'etavis': {'_val': str(etavis)}}) except Exception: doc['result'].update({'etavis': {'_val': ' '}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True
def calculate(doc_original): doc = deepcopy(doc_original) treeUnitConvert(doc, doc['units'], SI_UNITS) doc['errors'] = [] solve_for = doc['input']['solve_for']['_val'] inlet_definition = doc['input']['inlet_definition']['_val'] P_inlet = float(doc['input']['P_inlet']['_val']) # Determine Inlet Properties if (inlet_definition == "P-T"): T_inlet = float(doc['input']['T_inlet']['_val']) try: h_inlet = round( CP.PropsSI('H', 'P', P_inlet, 'T', T_inlet, 'Water'), 1) s_inlet = round( CP.PropsSI('S', 'P', P_inlet, 'T', T_inlet, 'Water'), 1) phase_inlet = CP.PhaseSI('P', P_inlet, 'T', T_inlet, 'Water') except Exception as e: doc['errors'].append( 'Failed to calculate steam inlet conditions, check inputs') h_inlet = math.nan s_inlet = math.nan phase_inlet = "" elif (inlet_definition == 'P-h'): h_inlet = float(doc['input']['h_inlet']['_val']) try: T_inlet = round( CP.PropsSI('T', 'P', P_inlet, 'H', h_inlet, 'Water'), 1) s_inlet = round( CP.PropsSI('S', 'P', P_inlet, 'H', h_inlet, 'Water'), 1) phase_inlet = CP.PhaseSI('P', P_inlet, 'H', h_inlet, 'Water') except Exception as e: # doc['errors'].append(str(e)) doc['errors'].append( 'Failed to calculate steam inlet conditions, check inputs') T_inlet = math.nan s_inlet = math.nan phase_inlet = "" elif (inlet_definition == 'P-s'): s_inlet = float(doc['input']['s_inlet']['_val']) try: T_inlet = round( CP.PropsSI('T', 'P', P_inlet, 'S', s_inlet, 'Water'), 1) h_inlet = round( CP.PropsSI('H', 'P', P_inlet, 'S', s_inlet, 'Water'), 1) phase_inlet = CP.PhaseSI('P', P_inlet, 'S', s_inlet, 'Water') except Exception as e: # doc['errors'].append(str(e)) doc['errors'].append( 'Failed to calculate steam inlet conditions, check inputs') T_inlet = math.nan h_inlet = math.nan phase_inlet = "" elif (inlet_definition == 'P-Q'): Q_inlet = float(doc['input']['Q_inlet']['_val']) try: T_inlet = round( CP.PropsSI('T', 'P', P_inlet, 'Q', Q_inlet, 'Water'), 1) s_inlet = round( CP.PropsSI('S', 'P', P_inlet, 'Q', Q_inlet, 'Water'), 1) h_inlet = round( CP.PropsSI('H', 'P', P_inlet, 'Q', Q_inlet, 'Water'), 1) phase_inlet = CP.PhaseSI('P', P_inlet, 'Q', Q_inlet, 'Water') except Exception as e: # doc['errors'].append(str(e)) doc['errors'].append( 'Failed to calculate steam inlet conditions, check inputs') T_inlet = math.nan s_inlet = math.nan phase_inlet = "" outlet_definition = doc['input']['outlet_definition']['_val'] P_outlet = float(doc['input']['P_outlet']['_val']) s_outlet_ideal = s_inlet try: h_outlet_ideal = round( CP.PropsSI('H', 'P', P_outlet, 'S', s_outlet_ideal, 'Water'), 1) except Exception as e: # doc['errors'].append(str(e)) doc['errors'].append( 'Failed to calculate steam ideal outlet conditions, check inputs') h_outlet_ideal = math.nan if (solve_for == 'outlet_properties'): isentropic_efficiency = float( doc['input']['isentropic_efficiency']['_val']) try: h_outlet = h_inlet - (isentropic_efficiency / 100) * (h_inlet - h_outlet_ideal) h_outlet = round(h_outlet, 1) T_outlet = round( CP.PropsSI('T', 'P', P_outlet, 'H', h_outlet, 'Water'), 1) s_outlet = round( CP.PropsSI('S', 'P', P_outlet, 'H', h_outlet, 'Water'), 1) phase_outlet = CP.PhaseSI('P', P_outlet, 'H', h_outlet, 'Water') except Exception as e: # doc['errors'].append(str(e)) doc['errors'].append( 'Failed to calculate steam outlet conditions, check inputs') h_outlet = math.nan T_outlet = math.nan s_outlet = math.nan phase_outlet = "" else: try: if (outlet_definition == "P-T"): T_outlet = float(doc['input']['T_outlet']['_val']) h_outlet = round( CP.PropsSI('H', 'P', P_outlet, 'T', T_outlet, 'Water'), 1) s_outlet = round( CP.PropsSI('S', 'P', P_outlet, 'T', T_outlet, 'Water'), 1) elif (outlet_definition == 'P-h'): h_outlet = float(doc['input']['h_outlet']['_val']) T_outlet = round( CP.PropsSI('H', 'P', P_outlet, 'H', h_outlet, 'Water'), 1) s_outlet = round( CP.PropsSI('S', 'P', P_outlet, 'H', h_outlet, 'Water'), 1) elif (outlet_definition == 'P-s'): s_outlet = float(doc['input']['s_outlet']['_val']) h_outlet = float(doc['input']['h_outlet']['_val']) T_outlet = round( CP.PropsSI('H', 'P', P_outlet, 'H', h_outlet, 'Water'), 1) elif (outlet_definition == 'P-Q'): Q_outlet = float(doc['input']['Q_outlet']['_val']) T_outlet = round( CP.PropsSI('T', 'P', P_outlet, 'Q', Q_outlet, 'Water'), 1) h_outlet = round( CP.PropsSI('H', 'P', P_outlet, 'Q', Q_outlet, 'Water'), 1) s_outlet = round( CP.PropsSI('S', 'P', P_outlet, 'Q', Q_outlet, 'Water'), 1) except Exception as e: # doc['errors'].append(str(e)) doc['errors'].append( 'Failed to calculate steam outlet conditions, check inputs') h_outlet = math.nan T_outlet = math.nan s_outlet = math.nan try: isentropic_efficiency = (h_inlet - h_outlet) * 100 / ( h_inlet - h_outlet_ideal) isentropic_efficiency = round(isentropic_efficiency, 1) except Exception as e: # doc['errors'].append(str(e)) doc['errors'].append( 'Failed to Isentropic Efficiency, check inputs') isentropic_efficiency = math.nan phase_outlet = CP.PhaseSI('P', P_outlet, 'H', h_outlet, 'Water') turbine_definition = doc['input']['turbine_definition']['_val'] generator_efficiency = float(doc['input']['generator_efficiency']['_val']) if (turbine_definition == 'mass_flow'): mass_flow = float(doc['input']['mass_flow']['_val']) try: energy_output = (h_inlet - h_outlet) * mass_flow energy_output = roundit(energy_output) power_output = energy_output * generator_efficiency / 100 power_output = roundit(power_output) except Exception as e: # doc['errors'].append(str(e)) doc['errors'].append( 'Failed to calculate Turbine Parameters, check inputs') energy_output = math.nan power_output = math.nan else: try: power_output = float(doc['input']['power_output']['_val']) energy_output = power_output * 100 / generator_efficiency mass_flow = energy_output / (h_inlet - h_outlet) mass_flow = roundit(mass_flow) except Exception as e: # doc['errors'].append(str(e)) doc['errors'].append( 'Failed to calculate Turbine Parameters, check inputs') energy_output = math.nan mass_flow = math.nan doc['result'].update( {'P_inlet': { '_val': str(P_inlet), '_dim': 'pressure' }}) doc['result'].update( {'T_inlet': { '_val': str(T_inlet), '_dim': 'temperature' }}) doc['result'].update( {'h_inlet': { '_val': str(h_inlet), '_dim': 'specificEnergy' }}) doc['result'].update( {'s_inlet': { '_val': str(s_inlet), '_dim': 'specificHeat' }}) doc['result'].update({'phase_inlet': {'_val': str(phase_inlet)}}) doc['result'].update({ 'h_outlet_ideal': { '_val': str(h_outlet_ideal), '_dim': 'specificEnergy' } }) doc['result'].update( {'P_outlet': { '_val': str(P_outlet), '_dim': 'pressure' }}) doc['result'].update( {'T_outlet': { '_val': str(T_outlet), '_dim': 'temperature' }}) doc['result'].update( {'h_outlet': { '_val': str(h_outlet), '_dim': 'specificEnergy' }}) doc['result'].update( {'s_outlet': { '_val': str(s_outlet), '_dim': 'specificHeat' }}) doc['result'].update({'phase_outlet': {'_val': str(phase_outlet)}}) doc['result'].update( {'isentropic_efficiency': { '_val': str(isentropic_efficiency) }}) doc['result'].update( {'generator_efficiency': { '_val': str(generator_efficiency) }}) doc['result'].update( {'mass_flow': { '_val': str(mass_flow), '_dim': 'massflow' }}) doc['result'].update( {'energy_output': { '_val': str(energy_output), '_dim': 'power' }}) doc['result'].update( {'power_output': { '_val': str(power_output), '_dim': 'power' }}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True