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) 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) 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) 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'] = [] 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'] = [] 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) 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) 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'] = [] 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'] = [] specie = doc['input']['specie']['_val'] concentration_measured = parseFloat(doc['input']['concentration_measured']['_val']) from_units = doc['input']['from_units']['_val'] sampling_basis = doc['input']['sampling_basis']['_val'] oxygen_correction = doc['input']['oxygen_correction']['_val'] to_units = doc['input']['to_units']['_val'] # Let base units be mg/Nm3. Convert from from_units to base unit and then from base_unit to to_unit if (specie=='NOx'): MW = 46.0 elif (specie=='SOx'): MW = 64.1 elif (specie=='CO'): MW = 28.01 elif (specie=='Other'): MW = parseFloat(doc['input']['MW']['_val'])*1000 else: raise Exception('Unknown specie of pollutant. Molecular weight not found') Vmolar = 22.41 #volume occupied by one mole of gas at NTP conditions Ku = MW/Vmolar if (from_units != to_units): if (from_units=='ppmv'): concentration_base = concentration_measured*Ku if (from_units=='mg/Nm3'): concentration_base = concentration_measured if (from_units=='mg/Sm3'): Ts = parseFloat(doc['input']['Ts']['_val']) Ps = parseFloat(doc['input']['Ps']['_val']) Tn = 273.15 Pn = 101325 Ft = Ts/Tn Fp = Pn/Ps concentration_base = concentration_measured*Ft*Fp if (to_units=='ppmv'): concentration_wet = concentration_base/Ku if (to_units=='mg/Nm3'): concentration_wet = concentration_base if (to_units=='mg/Sm3'): Ts = parseFloat(doc['input']['Ts']['_val']) Ps = parseFloat(doc['input']['Ps']['_val']) Tn = 273.15 Pn = 101325 Ft = Tn/Ts Fp = Ps/Pn concentration_wet = concentration_base*Ft*Fp else: concentration_wet = concentration_measured # check if moisture correction is to be applied if (sampling_basis=='wet'): H2O_measured = parseFloat(doc['input']['H2O_measured']['_val']) Fm = 100/(100-H2O_measured) else: Fm = 1 concentration_dry = concentration_wet*Fm # check if oxygen correction is to be applied try: if (oxygen_correction=='yes'): O2_measured = parseFloat(doc['input']['O2_measured']['_val']) O2_reference = parseFloat(doc['input']['O2_reference']['_val']) O2_measured_dry = O2_measured*Fm Fo = (20.9 - O2_reference)/(20.9 - O2_measured_dry) else: O2_measured_dry = nan Fo = 1 except Exception as e: Fo = nan O2_measured_dry = nan concentration_dry_corrected = concentration_dry*Fo doc['result'].update({'concentration_wet':{'_val' : str(roundit(concentration_wet))}}) doc['result'].update({'units':{'_val' : to_units}}) doc['result'].update({'Fm':{'_val' : str(roundit(Fm))}}) doc['result'].update({'concentration_dry':{'_val' : str(roundit(concentration_dry))}}) doc['result'].update({'O2_measured_dry':{'_val' : str(roundit(O2_measured_dry))}}) doc['result'].update({'Fo':{'_val' : str(roundit(Fo))}}) doc['result'].update({'concentration_dry_corrected':{'_val' : str(roundit(concentration_dry_corrected))}}) 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'] = [] calculation_option = doc['input']['calculation_option']['_val'] ''' ''' try: if (calculation_option == 'NPS'): NPS = parseFloat(doc['input']['NPS']['_val']) Schedule = doc['input']['Schedule']['_val'] NPS, d, D, tn = nearest_pipe(NPS=NPS, schedule=Schedule) if (calculation_option == 'd'): d = parseFloat(doc['input']['d']['_val']) Schedule = doc['input']['Schedule']['_val'] NPS, d, D, tn = nearest_pipe(Di=d, schedule=Schedule) if (calculation_option == 'D'): D = parseFloat(doc['input']['D']['_val']) Schedule = doc['input']['Schedule']['_val'] NPS, d, D, tn = nearest_pipe(Do=D, schedule=Schedule) except Exception as e: doc['errors'].append(str(e)) NPS = math.nan d = math.nan D = math.nan tn = math.nan P = parseFloat(doc['input']['P']['_val']) Tdesign = parseFloat(doc['input']['Tdesign']['_val']) materialSpec = doc['input']['materialSpec']['_val'] weldType = doc['input']['weldType']['_val'] W = parseFloat(doc['input']['W']['_val']) ca = parseFloat(doc['input']['ca']['_val']) h = parseFloat(doc['input']['h']['_val']) ut = parseFloat(doc['input']['ut']['_val']) t_ut = tn * ut / 100 # thickness lost due to undertolerance T = tn - t_ut # guaranteed thickness available as a minimum c = ca + h # get sum total of all corrosion and threading allowance S = getS(materialSpec, Tdesign) Y = getY(materialSpec, Tdesign) E = getE(weldType) t = t_pressure(P, D, S, E, W, Y) # pressure design thickness tm = t + c # min required thickness if (T >= tm): acceptability = "OK" else: acceptability = "Not OK" doc['result'].update({'NPS': {'_val': str(roundit(NPS))}}) doc['result'].update({'d': {'_val': str(roundit(d)), '_dim': 'length'}}) doc['result'].update({'D': {'_val': str(roundit(D)), '_dim': 'length'}}) doc['result'].update({'tn': {'_val': str(roundit(tn)), '_dim': 'length'}}) doc['result'].update( {'t_ut': { '_val': str(roundit(t_ut)), '_dim': 'length' }}) doc['result'].update({'T': {'_val': str(roundit(T)), '_dim': 'length'}}) doc['result'].update({'S': {'_val': str(roundit(S)), '_dim': 'pressure'}}) doc['result'].update({'Y': {'_val': str(roundit(Y))}}) doc['result'].update({'E': {'_val': str(E)}}) doc['result'].update({'t': {'_val': str(roundit(t)), '_dim': 'length'}}) doc['result'].update({'c': {'_val': str(roundit(c)), '_dim': 'length'}}) doc['result'].update({'tm': {'_val': str(roundit(tm)), '_dim': 'length'}}) doc['result'].update({'acceptability': {'_val': acceptability}}) 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'] = [] calculation_option = doc['input']['calculation_option']['_val'] Tdb = parseFloat(doc['input']['Tdb']['_val']) P = parseFloat(doc['input']['P']['_val']) try: if (calculation_option == 'Tdb_RH_P'): RH = parseFloat(doc['input']['RH']['_val']) if (calculation_option == 'Tdb_Twb_P'): Twb = parseFloat(doc['input']['Twb']['_val']) RH = CP.HAPropsSI('R', 'Tdb', Tdb, 'P', P, 'Twb', Twb) if (calculation_option == 'Tdb_Tdp_P'): Tdp = parseFloat(doc['input']['Tdp']['_val']) RH = CP.HAPropsSI('R', 'Tdb', Tdb, 'P', P, 'Tdp', Tdp) if (calculation_option == 'Tdb_Tdp_P'): Tdp = parseFloat(doc['input']['Tdp']['_val']) RH = CP.HAPropsSI('R', 'Tdb', Tdb, 'P', P, 'Tdp', Tdp) if (calculation_option == 'Tdb_W_P'): W = parseFloat(doc['input']['W']['_val']) RH = CP.HAPropsSI('R', 'Tdb', Tdb, 'P', P, 'W', W) if (calculation_option == 'Tdb_h_P'): h = parseFloat(doc['input']['h']['_val']) RH = CP.HAPropsSI('R', 'Tdb', Tdb, 'P', P, 'H', h) except Exception: RH = math.nan try: Twb = CP.HAPropsSI('Twb', 'Tdb', Tdb, 'P', P, 'R', RH) Tdp = CP.HAPropsSI('Tdp', 'Tdb', Tdb, 'P', P, 'R', RH) except Exception: Twb = math.nan Tdp = math.nan try: v = CP.HAPropsSI('Vha', 'Tdb', Tdb, 'P', P, 'R', RH) rho = 1 / v except Exception: v = math.nan rho = math.nan try: W = CP.HAPropsSI('W', 'Tdb', Tdb, 'P', P, 'R', RH) except Exception: W = math.nan try: h = CP.HAPropsSI('H', 'Tdb', Tdb, 'P', P, 'R', RH) u = CP.HAPropsSI('U', 'Tdb', Tdb, 'P', P, 'R', RH) s = CP.HAPropsSI('S', 'Tdb', Tdb, 'P', P, 'R', RH) except Exception: h = math.nan u = math.nan s = math.nan try: Cp = CP.HAPropsSI('cp', 'Tdb', Tdb, 'P', P, 'R', RH) Cp_ha = CP.HAPropsSI('cp_ha', 'Tdb', Tdb, 'P', P, 'R', RH) except Exception: Cp = math.nan Cp_ha = math.nan RH = roundit(RH, 4) Twb = roundit(Twb, 1) Tdp = roundit(Tdp, 1) W = roundit(W, 4) rho = roundit(rho, 4) v = roundit(v, 4) h = roundit(h, 4) u = roundit(u, 4) s = roundit(s, 4) Cp = roundit(Cp, 4) Cp_ha = roundit(Cp_ha, 4) doc['result'].update({'RH': {'_val': str(RH)}}) doc['result'].update({'Twb': {'_val': str(Twb), '_dim': 'temperature'}}) doc['result'].update({'Tdp': {'_val': str(Tdp), '_dim': 'temperature'}}) doc['result'].update({'W': {'_val': str(W)}}) 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'}}) doc['result'].update({'Cp': {'_val': str(Cp), '_dim': 'specificHeat'}}) doc['result'].update( {'Cp_ha': { '_val': str(Cp_ha), '_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) doc['errors'] = [] qm = parseFloat(doc['input']['qm']['_val']) MW = parseFloat(doc['input']['MW']['_val']) T = parseFloat(doc['input']['T']['_val']) Z = parseFloat(doc['input']['Z']['_val']) LHV = parseFloat(doc['input']['LHV']['_val']) p2 = parseFloat(doc['input']['p2']['_val']) Uinf = parseFloat(doc['input']['Uinf']['_val']) Ma2 = parseFloat(doc['input']['Ma2']['_val']) d_basis = doc['input']['d_basis']['_val'] if (d_basis == 'manual'): d = parseFloat(doc['input']['d_manual']['_val']) else: d = flareDia(qm, p2, Ma2, Z, T, MW) R = parseFloat(doc['input']['R']['_val']) tau = parseFloat(doc['input']['tau']['_val']) F = parseFloat(doc['input']['F']['_val']) K = parseFloat(doc['input']['K']['_val']) ''' ''' try: Q = heatRelease(qm, LHV) L = flameLength(Q) q_vap = vaporFlowrate(qm, MW, T) Uj = tipVelocity(q_vap, d) Uinf_by_Uj = Uinf / Uj Sdy_by_L, Sdx_by_L = flameDistortion(Uinf_by_Uj) Sdy = Sdy_by_L * L Sdx = Sdx_by_L * L D = D = sqrt(tau * F * Q / (4 * pi * K)) R_prime = R - 0.5 * Sdx H_prime = sqrt(D**2 - R_prime**2) H = H_prime - 0.5 * Sdy except Exception as e: doc['errors'].append(str(e)) doc['errors'].append( 'Flare Height could not be calculated. Check Inputs') d = nan Q = nan L = nan rho = nan Uj = nan Uinf_by_Uj = nan Sdy_by_L = nan Sdx_by_L = nan Sdy = nan Sdx = nan R_prime = nan H_prime = nan H = nan doc['result'].update({'d': {'_val': str(roundit(d)), '_dim': 'length'}}) doc['result'].update({'Q': {'_val': str(roundit(Q)), '_dim': 'power'}}) doc['result'].update({'L': {'_val': str(roundit(L)), '_dim': 'length'}}) doc['result'].update( {'q_vap': { '_val': str(roundit(q_vap)), '_dim': 'flow' }}) doc['result'].update({'Uj': {'_val': str(roundit(Uj)), '_dim': 'speed'}}) doc['result'].update({'Uinf_by_Uj': {'_val': str(roundit(Uinf_by_Uj))}}) doc['result'].update({'Sdy_by_L': {'_val': str(roundit(Sdy_by_L))}}) doc['result'].update({'Sdx_by_L': {'_val': str(roundit(Sdx_by_L))}}) doc['result'].update( {'Sdy': { '_val': str(roundit(Sdy)), '_dim': 'length' }}) doc['result'].update( {'Sdx': { '_val': str(roundit(Sdx)), '_dim': 'length' }}) doc['result'].update({'D': {'_val': str(roundit(D)), '_dim': 'length'}}) doc['result'].update( {'R_prime': { '_val': str(roundit(R_prime)), '_dim': 'length' }}) doc['result'].update( {'H_prime': { '_val': str(roundit(H_prime)), '_dim': 'length' }}) doc['result'].update({'H': {'_val': str(roundit(H)), '_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'] = [] Td = 273.15 + 15.6 Ta = parseFloat(doc['input']['Ta']['_val']) RH = parseFloat(doc['input']['RH']['_val']) flue_O2 = parseFloat(doc['input']['flue_O2']['_val']) sampling_basis = doc['input']['sampling_basis']['_val'] loss_radiation = parseFloat(doc['input']['loss_radiation']['_val']) composition_type = doc['input']['composition_type']['_val'] gasfuel = doc['input']['gasfuel'] Tf = parseFloat(doc['input']['Tf']['_val']) MW, h_L, Cp_f, air_reqd, CO2_formed, H2O_formed, N2_formed = gasfuelProperties( gasfuel, composition_type) MW_str = format(MW, '0.6f') MW = float(MW_str) print("MW is {}".format(MW)) X_wet = airMoistureContent(Ta, RH) air_reqd_RHcorrected = wetAirRequired(air_reqd, X_wet) moisture = air_reqd_RHcorrected - air_reqd H2O_formed_RHcorrected = H2O_formed + moisture excess_Air = excessAir(flue_O2, air_reqd, N2_formed, CO2_formed, H2O_formed_RHcorrected, moisture, sampling_basis) excess_Air_pc = excessAir_pc(excess_Air, air_reqd) total_air = air_reqd_RHcorrected + excess_Air H2O_formed_EAcorrected = H2OformedEAcorrected(excess_Air_pc, moisture, H2O_formed_RHcorrected) Texit_flue = 273 + 148.9 Patm = 101325 h_CO2 = getEnthalphy('CarbonDioxide', Texit_flue) H_CO2 = h_CO2 * CO2_formed h_H2O = getEnthalphy('Water', Texit_flue) H_H2O = h_H2O * H2O_formed_EAcorrected h_N2 = getEnthalphy('Nitrogen', Texit_flue) H_N2 = h_N2 * N2_formed h_EA = getEnthalphy('Air', Texit_flue) H_EA = h_EA * excess_Air h_s = flueMassicHeatContent(CO2_formed, H2O_formed_EAcorrected, N2_formed, excess_Air, Texit_flue) h_r = radiationLoss(loss_radiation, h_L) Cp_a = 1005 delh_a = Cp_a * (Ta - Td) * total_air delh_f = Cp_f * (Tf - Td) delh_m = 0 # as steam atomisation not applicable e = netThermalEfficiency(h_L, delh_a, delh_f, delh_m, h_r, h_s) e_f = fuelEfficiency(h_L, delh_a, delh_f, delh_m, h_r, h_s) h_H = getHHV(h_L, H2O_formed) e_g = grossThermalEfficiency(h_L, h_H, delh_a, delh_f, delh_m, h_r, h_s) doc['result'].update( {'MW': { '_val': format(MW, '0.5f'), '_dim': 'molecularMass' }}) doc['result'].update( {'h_L': { '_val': str(roundit(h_L)), '_dim': 'specificEnergy' }}) doc['result'].update( {'h_H': { '_val': str(roundit(h_H)), '_dim': 'specificEnergy' }}) doc['result'].update( {'Cp_f': { '_val': str(roundit(Cp_f)), '_dim': 'specificHeat' }}) 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({'N2_formed': {'_val': str(roundit(N2_formed))}}) doc['result'].update({'X_wet': {'_val': str(roundit(X_wet))}}) doc['result'].update( {'air_reqd_RHcorrected': { '_val': str(roundit(air_reqd_RHcorrected)) }}) doc['result'].update({'moisture': {'_val': str(roundit(moisture))}}) doc['result'].update({ 'H2O_formed_RHcorrected': { '_val': str(roundit(H2O_formed_RHcorrected)) } }) doc['result'].update({'excess_Air': {'_val': str(roundit(excess_Air))}}) doc['result'].update({'total_air': {'_val': str(roundit(total_air))}}) doc['result'].update( {'excess_Air_pc': { '_val': str(roundit(excess_Air_pc)) }}) doc['result'].update({ 'H2O_formed_EAcorrected': { '_val': str(roundit(H2O_formed_EAcorrected)) } }) doc['result'].update( {'h_CO2': { '_val': str(roundit(h_CO2)), '_dim': 'specificEnergy' }}) doc['result'].update( {'H_CO2': { '_val': str(roundit(H_CO2)), '_dim': 'energy' }}) doc['result'].update( {'h_H2O': { '_val': str(roundit(h_H2O)), '_dim': 'specificEnergy' }}) doc['result'].update( {'H_H2O': { '_val': str(roundit(H_H2O)), '_dim': 'energy' }}) doc['result'].update( {'h_N2': { '_val': str(roundit(h_N2)), '_dim': 'specificEnergy' }}) doc['result'].update( {'H_N2': { '_val': str(roundit(H_N2)), '_dim': 'energy' }}) doc['result'].update( {'h_EA': { '_val': str(roundit(h_EA)), '_dim': 'specificEnergy' }}) doc['result'].update( {'H_EA': { '_val': str(roundit(H_EA)), '_dim': 'energy' }}) doc['result'].update( {'h_s': { '_val': str(roundit(h_s)), '_dim': 'energy' }}) doc['result'].update( {'h_r': { '_val': str(roundit(h_r)), '_dim': 'specificEnergy' }}) doc['result'].update( {'delh_a': { '_val': str(roundit(delh_a)), '_dim': 'specificEnergy' }}) doc['result'].update( {'delh_f': { '_val': str(roundit(delh_f)), '_dim': 'specificEnergy' }}) doc['result'].update({'e': {'_val': str(roundit(e))}}) doc['result'].update({'e_g': {'_val': str(roundit(e_g))}}) doc['result'].update({'e_f': {'_val': str(roundit(e_f))}}) 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'] = [] Vmin = parseFloat(doc['input']['Vmin']['_val']) Vmax = parseFloat(doc['input']['Vmax']['_val']) Vnominal = parseFloat(doc['input']['Vnominal']['_val']) loads_known = doc['input']['loads_known'] loads_random = doc['input']['loads_random'] Vc_max = parseFloat(doc['input']['Vc_max']['_val']) Tmin = parseFloat(doc['input']['Tmin']['_val']) Tmax = parseFloat(doc['input']['Tmax']['_val']) Tnominal = parseFloat(doc['input']['Tnominal']['_val']) design_margin = parseFloat(doc['input']['design_margin']['_val']) aging_factor = parseFloat(doc['input']['aging_factor']['_val']) cell_range = doc['input']['cell_range']['_val'] Ncell_basis = doc['input']['Ncell_basis']['_val'] Veod_max = 1.14 Veod_min = 1.0 Ncell_max = floor(Vmax / Vc_max) Ncell_min = ceil(Vmin / Veod_max) if (Ncell_basis == 'manual'): Ncell = parseFloat(doc['input']['Ncell_manual']['_val']) else: Ncell = Ncell_max Vmax_attained = Vc_max * Ncell Veod = Vmin / Ncell if (Veod < Veod_min): Veod = Veod_min if (Ncell_min > Ncell_max): doc['errors'].append( 'The system minimum voltage is too high for making economic selection. Check if the same can be lowered. Also try lowering the maximum charging voltage if possible.' ) if (Ncell > Ncell_max): doc['errors'].append( 'No. of cells selected above max. Please choose withing range.') if (Ncell < Ncell_min): doc['errors'].append( 'No. of cells selected below min. Please choose withing range.') Vmin_attained = Veod * Ncell amp_data_known = getAmpDataKnown(loads_known, Vmin) print(amp_data_known) amp_data_random = getAmpDataRandom(loads_random, Vmin) try: Fs_max, Fs_random, Fs_uncorrected, Fs_corrected, cell_selected, strings = getCellSize( amp_data_known, amp_data_random, cell_range, Veod, Tmin, design_margin, aging_factor) except Exception as e: doc['errors'].append(str(e)) Fs_max = nan Fs_random = nan Fs_uncorrected = nan Fs_corrected = nan cell_selected = "" strings = nan doc['result'].update({'Ncell_max': {'_val': str(int(Ncell_max))}}) doc['result'].update({'Ncell_min': {'_val': str(int(Ncell_min))}}) doc['result'].update({'Ncell': {'_val': str(int(Ncell))}}) doc['result'].update({'Veod': {'_val': str(roundit(Veod))}}) doc['result'].update( {'Vmax_attained': { '_val': str(roundit(Vmax_attained)) }}) doc['result'].update( {'Vmin_attained': { '_val': str(roundit(Vmin_attained)) }}) doc['result'].update({'Fs_max': {'_val': str(roundit(Fs_max))}}) doc['result'].update({'Fs_random': {'_val': str(roundit(Fs_random))}}) doc['result'].update( {'Fs_uncorrected': { '_val': str(roundit(Fs_uncorrected)) }}) doc['result'].update( {'Fs_corrected': { '_val': str(roundit(Fs_corrected)) }}) doc['result'].update({'cell_selected': {'_val': cell_selected}}) doc['result'].update({'strings': {'_val': str(strings)}}) treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True) doc_original['result'].update(doc['result']) doc_original['errors'] = doc['errors'] return True