コード例 #1
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
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
コード例 #2
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
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
コード例 #3
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
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
コード例 #4
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
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
コード例 #5
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
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
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
0
def aWeightedSpectrum(spectrum):
    '''Applies A filter to the noise spectrum and returns the filtered spectrum.
    Args:
        spectrum: dictionary of noise levels in dB at following mean band frequencies in Hz as key:
        f63, f125, f250, f500, f1000, f2000, f4000, f8000
    Returns:
        filtered spectrum as a dictionary of noise levels similar to spectrum above.

    '''
    bands = ["f63", "f125", "f250", "f500", "f1000", "f2000", "f4000", "f8000"]
    spectrum_filtered = {}

    A_filter = {
        "f63": -26.2,
        "f125": -16.1,
        "f250": -8.6,
        "f500": -3.2,
        "f1000": 0,
        "f2000": 1.2,
        "f4000": 1,
        "f8000": -1.1
    }

    for frequency in bands:
        spectrum_filtered[frequency] = roundit(spectrum[frequency] +
                                               A_filter[frequency])

    return spectrum_filtered
コード例 #9
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
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
コード例 #10
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
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
コード例 #11
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
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
コード例 #12
0
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
コード例 #13
0
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
コード例 #14
0
def readDischargeRate(data_file, AH_Rating, time):
    try:
        THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
        data_file_path = os.path.join(THIS_FOLDER, data_file)
        rates_df = pd.read_csv(data_file_path)
        rates_df = rates_df.set_index('Ah')
        #print("AH rating in lookup is {}".format(AH_Rating))
        discharge_rates = rates_df.loc[AH_Rating]
        discharge_rates = discharge_rates.drop(['Model'])
        time_values = discharge_rates.index.tolist()
        current_values = discharge_rates.values.tolist()
        for index, val in enumerate(time_values):
            time_values[index] = float(val)

        time_values.reverse()
        current_values.reverse()

        index_lower, index_higher = getindex(time_values, time)
        t1 = time_values[index_lower]
        t2 = time_values[index_higher]
        A1 = current_values[index_lower]
        A2 = current_values[index_higher]
        A1 = roundit(A1)
        A2 = roundit(A2)
    except KeyError:
        raise Exception(
            'Error occured while reading cell discharge rates. Ah rating not found in cell range selected.'
        )
    except TypeError:
        raise Exception(
            'Error occured while reading cell discharge rates. Time used to obtain cell discharge rate outside defined range for the cell.'
        )
    except FileNotFoundError:
        raise Exception(
            'Error occured while reading cell discharge rates. File for cell range selected could not be found. Check if correct cell range and cell End of Discharge values are used.'
        )
    except Exception as e:
        raise Exception('Error occured while reading cell discharge rates. ' +
                        str(e))

    return t1, A1, t2, A2
コード例 #15
0
ファイル: schema.py プロジェクト: sandeeprah/clappets
 def check_soil_thermal_resistivity(self, data):
     if ('installation_method' not in data):
         return
     if (data['installation_method']['_val'] not in ["D1", "D2"]):
         return
     fName = 'soil_thermal_resistivity'
     vd.xRequired(data, fName, fName)
     value = data[fName]
     vd.xNumber(value, fName)
     value['_val'] = roundit(float(value['_val']))
     item_options = [0.5, 0.7, 1, 1.5, 2, 2.5, 3]
     vd.xChoice(value, item_options, fName)
コード例 #16
0
ファイル: schema.py プロジェクト: sandeeprah/clappets
 def check_cable_section_manual(self, data):
     if ('voltage_drop_calculation' not in data):
         return
     if (data['voltage_drop_calculation']['_val'] != 'yes'):
         return
     fName = 'cable_section_manual'
     vd.xRequired(data, fName, fName)
     value = data[fName]
     vd.xNumber(value, fName)
     value['_val'] = roundit(float(value['_val']))
     item_options = [
         1, 1.5, 2.5, 4, 6, 10, 16, 25, 35, 50, 70, 95, 120, 150, 185, 240,
         300, 400, 500
     ]
     vd.xChoice(value, item_options, fName)
コード例 #17
0
ファイル: schema.py プロジェクト: sandeeprah/clappets
 def check_Tground(self, data):
     if ('installation_method' not in data):
         return
     if (data['installation_method']['_val'] not in ["D1", "D2"]):
         return
     fName = 'Tground'
     vd.xRequired(data, fName, fName)
     value = data[fName]
     vd.xNumber(value, fName)
     value['_val'] = roundit(float(value['_val']))
     item_options = [
         10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90,
         95
     ]
     vd.xChoice(value, item_options, fName)
コード例 #18
0
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
コード例 #19
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
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
コード例 #20
0
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
コード例 #21
0
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
コード例 #22
0
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
コード例 #23
0
ファイル: core.py プロジェクト: sandeeprah/clappets
def motor_params(kW_rating, poles=2, voltage=415, frequency=50):
    if (voltage != 415):
        raise Exception('Database for given voltage not available')

    if (frequency != 50):
        raise Exception('Database for given frequency not available')

    if (poles == 2):
        data_file = "LV_TEFC_415V_50Hz_2Pole.csv"
    elif (poles == 4):
        data_file = "LV_TEFC_415V_50Hz_4Pole.csv"
    elif (poles == 6):
        data_file = "LV_TEFC_415V_50Hz_6Pole.csv"
    else:
        raise Exception("Invalid number of poles")

    try:
        THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
        data_file_path = os.path.join(THIS_FOLDER, data_file)
        motor_df = pd.read_csv(data_file_path)
        motor_df = motor_df.set_index('kW')
        param_dict = {}
        param_dict['Frame_Size'] = roundit(motor_df.loc[kW_rating,
                                                        "Frame_Size"])
        param_dict['Speed'] = roundit(motor_df.loc[kW_rating, "Speed"])
        param_dict['eta_full'] = roundit(motor_df.loc[kW_rating, "eta_full"])
        param_dict['eta_three_fourth'] = roundit(
            motor_df.loc[kW_rating, "eta_three_fourth"])
        param_dict['eta_half'] = roundit(motor_df.loc[kW_rating, "eta_half"])
        param_dict['pf'] = roundit(motor_df.loc[kW_rating, "pf"])
        param_dict['In'] = roundit(motor_df.loc[kW_rating, "In"])
        param_dict['Is_by_In'] = roundit(motor_df.loc[kW_rating, "Is_by_In"])
        param_dict['Tn'] = roundit(motor_df.loc[kW_rating, "Tn"])
        param_dict['Ti_by_Tn'] = roundit(motor_df.loc[kW_rating, "Ti_by_Tn"])
        param_dict['Tb_by_Tn'] = roundit(motor_df.loc[kW_rating, "Tb_by_Tn"])
        param_dict['J'] = roundit(motor_df.loc[kW_rating, "J"])
        param_dict['weight'] = roundit(motor_df.loc[kW_rating, "weight"])
    except Exception as e:
        param_dict = {}
        param_dict['Frame_Size'] = nan
        param_dict['Speed'] = nan
        param_dict['eta_full'] = nan
        param_dict['eta_three_fourth'] = nan
        param_dict['eta_half'] = nan
        param_dict['pf'] = nan
        param_dict['In'] = nan
        param_dict['Is_by_In'] = nan
        param_dict['Tn'] = nan
        param_dict['Ti_by_Tn'] = nan
        param_dict['Tb_by_Tn'] = nan
        param_dict['J'] = nan
        param_dict['weight'] = nan
        raise Exception(
            'Motor rating not in LV motor range. Motor Dimensions not available'
        )

    return param_dict
コード例 #24
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
def calculate(doc_original):
    doc = deepcopy(doc_original)
    treeUnitConvert(doc, doc['units'], SI_UNITS)
    doc['errors'] =[]

    Pset = float(doc['input']['Pset']['_val'])
    Pover = float(doc['input']['Pover']['_val'])
    Psuper = float(doc['input']['Psuper']['_val'])
    Pbuiltup = float(doc['input']['Pbuiltup']['_val'])
    Psuper_is_const = doc['input']['Psuper_is_const']['_val']
    steam_state = doc['input']['steam_state']['_val']

    m = float(doc['input']['m']['_val'])

    valve_design = doc['input']['valve_design']['_val']
    rupture_disc = doc['input']['rupture_disc']['_val']
    Kd_basis = doc['input']['Kd_basis']['_val']
    Kb_basis = doc['input']['Kb_basis']['_val']
    Kc_basis = doc['input']['Kc_basis']['_val']

    Patm = 101325 # atmospheric pressure
    P = Pset + (Pover/100)*Pset + Patm # relieving pressure
    Pback = Psuper + Pbuiltup

    if (steam_state=='superheated'):
        T = float(doc['input']['T']['_val'])
    else:
        T = round(CP.PropsSI('T','P', P, 'Q', 1, 'Water'), 1)
        print(T)


    if (Psuper_is_const == 'Yes'):
        Psuper_variable = 0
    else:
        Psuper_variable = Psuper

    valve_design_remark =""

    if (valve_design=='Conventional'):
        Puncompensated = Psuper_variable + Pbuiltup
        allowable_overpressure = Pset*(Pover/100)
        if (Puncompensated > allowable_overpressure):
            valve_design_remark = 'Not acceptable. Uncompensated backpressure exceeds allowable overpressure'
        else:
            if (Pback > allowable_overpressure):
                valve_design_remark ='Acceptable, subject to compensation of constant superimposed back pressure'
            else:
                valve_design_remark ='Acceptable'

    if (valve_design=='Balanced'):
        Pback_max = 0.5*Pset
        if (Pback > Pback_max):
            valve_design_remark ='Not Acceptable. Total backpressure exceeds 50% of set pressure'
        else:
            valve_design_remark ='Acceptable'

    if (valve_design=='Pilot-Operated'):
        valve_design_remark='Acceptable'

    if (Kd_basis=='Manual'):
        Kd = float(doc['input']['Kd_manual']['_val'])
    else:
        Kd = 0.975

    if (rupture_disc=='No'):
        Kc = 1
    else:
        if (Kc_basis=='Manual'):
            Kc = float(doc['input']['Kc_manual']['_val'])
        else:
            Kc = 0.9


    Pb = Pback + Patm
    Pset_abs = Pset + Patm

    if (valve_design=='Balanced'):
        if (Kb_basis=='Manual'):
            Kb = float(doc['input']['Kb_manual']['_val'])
        else:
            try:
                Kb = API520_B(Pset_abs, Pb, Pover/100)
                Kb = roundit(Kb)
            except Exception as e:
                Kb = math.nan
                doc["errors"].append(str(e))
                doc["errors"].append("Failed to calculated, backpressure. Provide Manual input using manufacturer data")
    else:
        Kb = 1

    try:
        Kn = roundit(API520_N(P1=P))
    except Exception as e:
        Kn = math.nan
        doc["errors"].append(str(e))
        doc["errors"].append("Failed to calculated, Kn.")

    try:
        if (steam_state=='saturated'):
            Ksh  = 1
        else:
            Ksh = roundit(API520_SH(T1 = T, P1 = P))
    except Exception as e:
        Ksh = math.nan
        doc["errors"].append(str(e))
        doc["errors"].append("Failed to calculated, Ksh.")

    try:
        A = API520_A_steam(m, T, P1=P, Kd=0.975, Kb=1, Kc=1)
        A_sel = API520_round_size(A)
        A_letter = API526_letter(A_sel)
    except Exception as e:
        A = math.nan
        A_sel = math.nan
        A_letter = ""
        doc['errors'].append(str(e))
        doc['errors'].append("Failed to calculate discharge Area (A). Check Inputs")


    doc['result'].update({'valve_design_remark':{'_val':str(valve_design_remark)}})
    doc['result'].update({'Kd':{'_val':str(Kd)}})
    doc['result'].update({'Kb':{'_val':str(Kb)}})
    doc['result'].update({'Kc':{'_val':str(Kc)}})
    doc['result'].update({'Kn':{'_val':str(Kn)}})
    doc['result'].update({'Ksh':{'_val':str(Ksh)}})
    doc['result'].update({'A':{'_val':str(A), '_dim':'area'}})
    doc['result'].update({'A_sel':{'_val':str(A_sel), '_dim':'area'}})
    doc['result'].update({'A_letter':{'_val':str(A_letter)}})

    treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True)
    doc_original['result'].update(doc['result'])
    doc_original['errors'] = doc['errors']

    return True
コード例 #25
0
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
コード例 #26
0
def calculate(doc_original):
    doc = deepcopy(doc_original)
    treeUnitConvert(doc, doc['units'], SI_UNITS)
    doc['errors'] = []

    Pset = float(doc['input']['Pset']['_val'])
    Pover = float(doc['input']['Pover']['_val'])
    Psuper = float(doc['input']['Psuper']['_val'])
    Pbuiltup = float(doc['input']['Pbuiltup']['_val'])
    Psuper_is_const = doc['input']['Psuper_is_const']['_val']

    Q = float(doc['input']['Q']['_val'])
    rho = float(doc['input']['rho']['_val'])
    viscosity_basis = doc['input']['viscosity_basis']['_val']

    valve_design = doc['input']['valve_design']['_val']
    rupture_disc = doc['input']['rupture_disc']['_val']
    Kd_basis = doc['input']['Kd_basis']['_val']
    Kw_basis = doc['input']['Kw_basis']['_val']
    Kc_basis = doc['input']['Kc_basis']['_val']

    if (viscosity_basis == 'Dynamic'):
        mu = float(doc['input']['mu']['_val'])
    if (viscosity_basis == 'Kinematic'):
        nu = float(doc['input']['nu']['_val'])
        mu = kin2dynVisc(nu, rho)
    if (viscosity_basis == 'SSU'):
        ssu = float(doc['input']['ssu']['_val'])
        nu_cst = SSU2cSt(ssu)
        nu = unitConvert(nu_cst, 'kinViscosity', 'cSt', 'm2/s')
        mu = kin2dynVisc(nu, rho)

    Patm = 101325  # atmospheric pressure
    P = Pset + (Pover / 100) * Pset + Patm  # relieving pressure
    Pback = Psuper + Pbuiltup

    if (Psuper_is_const == 'Yes'):
        Psuper_variable = 0
    else:
        Psuper_variable = Psuper

    valve_design_remark = ""

    if (valve_design == 'Conventional'):
        Puncompensated = Psuper_variable + Pbuiltup
        allowable_overpressure = Pset * (Pover / 100)
        if (Puncompensated > allowable_overpressure):
            valve_design_remark = 'Not acceptable. Uncompensated backpressure exceeds allowable overpressure'
        else:
            if (Pback > allowable_overpressure):
                valve_design_remark = 'Acceptable, subject to compensation of constant superimposed back pressure'
            else:
                valve_design_remark = 'Acceptable'

    if (valve_design == 'Balanced'):
        Pback_max = 0.5 * Pset
        if (Pback > Pback_max):
            valve_design_remark = 'Not Acceptable. Total backpressure exceeds 50% of set pressure'
        else:
            valve_design_remark = 'Acceptable'

    if (valve_design == 'Pilot-Operated'):
        valve_design_remark = 'Acceptable'

    if (Kd_basis == 'Manual'):
        Kd = float(doc['input']['Kd_manual']['_val'])
    else:
        Kd = 0.65

    if (rupture_disc == 'No'):
        Kc = 1
    else:
        if (Kc_basis == 'Manual'):
            Kc = float(doc['input']['Kc_manual']['_val'])
        else:
            Kc = 0.9

    G = rho / 1000
    Pb = Pback + Patm
    Pset_abs = Pset + Patm

    if (valve_design == 'Balanced'):
        if (Kw_basis == 'Manual'):
            Kw = float(doc['input']['Kw_manual']['_val'])
        else:
            try:
                Kw = API520_W(Pset_abs, Pb)
                Kw = roundit(Kw)
            except Exception as e:
                Kw = math.nan
                doc["errors"].append(str(e))
                doc["errors"].append(
                    "Failed to calculated, backpressure. Provide Manual input using manufacturer data"
                )
    else:
        Kw = 1

    Kv = 1

    try:
        while True:
            A = API520_A_l_cert(Q=Q,
                                G=G,
                                P=P,
                                Pb=Pb,
                                Kd=Kd,
                                Kw=Kw,
                                Kc=Kc,
                                Kv=Kv)
            print(A)
            A_sel = API520_round_size(A)
            R = Reynolds(Q, G, mu, A_sel)
            Kv = API520_Kv(R)
            Kv = roundit(Kv)
            A = A / Kv
            if (A_sel >= A):
                break

        A_letter = API526_letter(A_sel)
    except Exception:
        A = math.nan
        A_sel = math.nan
        Kv = math.nan
        R = math.nan
        A_letter = ""
        doc['errors'].append(
            "Failed to calculate discharge Area (A). Check Inputs")

    doc['result'].update(
        {'valve_design_remark': {
            '_val': str(valve_design_remark)
        }})
    doc['result'].update({'R': {'_val': str(R)}})
    doc['result'].update({'Kd': {'_val': str(Kd)}})
    doc['result'].update({'Kw': {'_val': str(Kw)}})
    doc['result'].update({'Kc': {'_val': str(Kc)}})
    doc['result'].update({'Kv': {'_val': str(Kv)}})
    doc['result'].update({'A': {'_val': str(A), '_dim': 'area'}})
    doc['result'].update({'A_sel': {'_val': str(A_sel), '_dim': 'area'}})
    doc['result'].update({'A_letter': {'_val': str(A_letter)}})

    treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True)
    doc_original['result'].update(doc['result'])
    doc_original['errors'] = doc['errors']

    return True
コード例 #27
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
def calculate(doc_original):
    doc = deepcopy(doc_original)
    treeUnitConvert(doc, doc['units'], SI_UNITS)

#    Get essential data
    P1 = float(doc['input']['P1']['_val'])
    T1 = float(doc['input']['T1']['_val'])
    P2 = float(doc['input']['P2']['_val'])
    m = float(doc['input']['m']['_val'])

# check if gas properties are already defined at inlet and outlet or to be determined from gas mixture.
    kZ_basis = doc['input']['kZ_basis']['_val']


# determine inlet properties MW, k1 and Z1
    if (kZ_basis =='A'):
        MW = float(doc['input']['MW']['_val'])
        k1 = float(doc['input']['k1']['_val'])
        Z1 = float(doc['input']['Z1']['_val'])

    elif (kZ_basis =='B'):
        mixture = doc['input']['mixture']
        try:
            props1 = mixture_props(mixture, P=P1, T=T1)
            MW = props1['MW']
            k1 = props1['k']
            Z1 = props1['Z_PR']
        except Exception as e :
            MW = nan
            k1 = nan
            Z1 = nan
            doc['errors'].append(str(e))
            doc['errors'].append('mixture properties could not be evaluated. check inputs')
    else:
        raise Exception('Invalid option for kZ_basis')

# determine actual volume flow rate at inlet
    Qact = Qactual(MW, P1, T1, Z1, m)


# assume single stage compression

# determine polytropic efficiencies if not given from volumetric flow rate
    predict_etaA = doc['input']['predict_etaA']['_val']
    if (predict_etaA == "No"):
        etaA = float(doc['input']['etaA']['_val'])
    else:
        etaA = polyeff(Qact)

# determine outlet k2, Z2 and discharge temperature T2
    if (kZ_basis =='A'):
        k2 = float(doc['input']['k2']['_val'])
        Z2 = float(doc['input']['Z2']['_val'])
        kavg = (k1+k2)/2
        Zavg = (Z1+Z2)/2
        n = nexp(kavg, etaA)
        T2 = Tdischarge(T1, P1, P2, n=n)

    if (kZ_basis =='B'):
        try:
            T2 = Tdischarge(T1, P1, P2, etap = etaA, mixture=mixture)
            props2 = mixture_props(mixture, P=P2, T=T2)
            k2 = props2['k']
            Z2 = props2['Z_PR']
            kavg = (k1+k2)/2
            Zavg = (Z1+Z2)/2
        except Exception as e:
            T2 = nan
            k2 = nan
            kavg = nan
            Zavg = nan
            doc['errors'].append(str(e))
            doc['errors'].append('mixture properties could not be evaluated. check inputs')


# check if discharge temperature limit is exceeded
    Tlimit = float(doc['input']['Tlimit']['_val'])
    if (T2 > Tlimit):
        intercooling_required = True
    else:
        intercooling_required = False

    #    doc['errors'].append('Discharge temperature limit is exceeded. Add intercooling and/or reduce pressure ratio')

# determine intercooling requirement
    interstage_cooling = doc['input']['interstage_cooling']['_val'] # requirement as specified by user

    if (interstage_cooling=='Yes'):
        perform_intercooling = True
    elif (interstage_cooling =='No'):
        perform_intercooling = False
    else:
        if (intercooling_required):
            perform_intercooling = True
        else:
            perform_intercooling = False



    if (not perform_intercooling):
        stages = 1
        try:
            Hp = Hpolytropic(Zavg, MW, T1, kavg, P1, P2, etaA)
            Pabs = absPower(m, Hp, etaA)
        except Exception as e:
            Hp = nan
            Pabs = nan
            doc['errors'].append(str(e))
            doc['errors'].append('polytropic and head could not be calculated. check inputs')



        Qact = roundit(Qact)
        d2, Nnominal = centframe(Qact)
        th =  theta(MW, k1, Z1, T1)
        hpmax = HpmaxWheel(th, sour='Yes')
        Nimpeller = ceil(Hp/hpmax)
        N = Nnominal*sqrt(Hp/(hpmax*Nimpeller))


        T2 = roundit(T2)
        kavg = roundit(kavg)
        Zavg = roundit(Zavg)
        etaA = roundit(etaA)
        Hp = roundit(Hp)
        Pabs = roundit(Pabs)
        N = roundit(N)

        doc['result'].update({'stages':{'_val' : str(stages)}})
        doc['result'].update({'P1':{'_val' : str(P1), '_dim':'pressure'}})
        doc['result'].update({'T1':{'_val' : str(T1), '_dim':'temperature'}})
        doc['result'].update({'P2':{'_val' : str(P2), '_dim':'pressure'}})
        doc['result'].update({'T2':{'_val' : str(T2), '_dim':'temperature'}})
        doc['result'].update({'m':{'_val' : str(m), '_dim':'massflow'}})
        doc['result'].update({'MW':{'_val' : str(MW), '_dim':'molecularMass'}})
        doc['result'].update({'Qact':{'_val' : str(Qact), '_dim':'flow'}})
        doc['result'].update({'kavg':{'_val' : str(kavg)}})
        doc['result'].update({'Zavg':{'_val' : str(Zavg)}})
        doc['result'].update({'etaA':{'_val' : str(etaA)}})
        doc['result'].update({'Hp':{'_val' : str(Hp)}})
        doc['result'].update({'Pabs':{'_val' : str(Pabs), '_dim':'power'}})
        doc['result'].update({'d2':{'_val' : str(d2), '_dim':'length'}})
        doc['result'].update({'N':{'_val' : str(N)}})
        doc['result'].update({'Nimpeller':{'_val' : str(Nimpeller)}})
    else:
        stages = 2

        # check how the interstage pressure is to be determined
        Pinlet_cooler_basis = doc['input']['Pinlet_cooler_basis']['_val'] # requirement as specified by user

        if (Pinlet_cooler_basis =='as_specified'):
            Pinlet_cooler = float(doc['input']['Pinlet_cooler']['_val'])

        elif (Pinlet_cooler_basis =='geometric_mean'):
            Pinlet_cooler = sqrt(P1*P2)
            Pinlet_cooler = roundit(Pinlet_cooler)
        else:
            raise Exception('Invalid choice for Pinlet_cooler_basis')


        Tcoolant = float(doc['input']['Tcoolant']['_val'])
        Tapproach = float(doc['input']['Tapproach']['_val'])
        deltaP_cooler = float(doc['input']['deltaP_cooler']['_val'])

        P1_1 = P1
        P2_1 = Pinlet_cooler
        P1_2 = Pinlet_cooler - deltaP_cooler
        P2_2 = P2
        T1_1 = T1
        T1_2 = Tcoolant + Tapproach



        # determine first stage properties
        if (kZ_basis =='A'):
            k1_1 = k1
            k2_1 = kavg
            k1_2 = kavg
            k2_2 = k2

            Z1_1 = Z1
            Z2_1 = Zavg
            Z1_2 = Zavg
            Z2_2 = Z2

            kavg_1 = (k1_1+k2_1)/2
            kavg_2 = (k1_2+k2_2)/2
            Zavg_1 = (Z1_1+Z2_2)/2
            Zavg_2 = (Z1_2+Z2_2)/2


            '''
            kavg_1 = 0.75*k1 + 0.25*k2
            kavg_2 = 0.25*k1 + 0.75*k2
            Zavg_1 = 0.75*Z1 + 0.25*Z2
            Zavg_2 = 0.25*Z1 + 0.75*Z2
            '''

            MW_1 = MW
            MW_2 = MW
            Z1_1 = Z1
            Z1_2 = (Z1+Z2)/2
            m_1 = m
            m_2 = m
            Qact_1 = Qactual(MW_1, P1_1, T1_1, Z1_1, m_1)
            Qact_2 = Qactual(MW_2, P1_2, T1_2, Z1_2, m_2)
            if (predict_etaA == "No"):
                etaA_1 = etaA
                etaA_2 = etaA
            else:
                etaA_1 = polyeff(Qact_1)
                etaA_2 = polyeff(Qact_2)


            n_1 = nexp(kavg_1, etaA_1)
            T2_1 = Tdischarge(T1_1, P1_1, P2_1, n=n_1)
            n_2 = nexp(kavg_2, etaA_2)
            T2_2 = Tdischarge(T1_2, P1_2, P2_2, n=n_2)


        if (kZ_basis == 'B'):
            # getting all stage 1 properties
            mixture_1 = mixture
            try:
                props1_1 = mixture_props(mixture_1, P=P1_1, T=T1_1)
                MW_1 = props1_1['MW']
                Z1_1 = props1_1['Z_PR']
                k1_1 = props1_1['k']
            except Exception as e:
                MW_1 = nan
                Z1_1 = nan
                k1_1 = nan
                doc['errors'].append(str(e))
                doc['errors'].append('mixture properties could not be evaluated. check inputs')


            m_1 = m
            Qact_1 = Qactual(MW_1, P1_1, T1_1, Z1_1, m_1)
            if (predict_etaA == "No"):
                etaA_1 = etaA
            else:
                etaA_1 = polyeff(Qact_1)

            try:
                T2_1 = Tdischarge(T1_1, P1_1, P2_1, etap = etaA_1, mixture=mixture_1)
                props2_1 = mixture_props(mixture_1, P=P2_1, T=T2_1)
                k2_1 = props2_1['k']
                Z2_1 = props2_1['Z_PR']
                kavg_1 = (k1_1+k2_1)/2
                Zavg_1 = (Z1_1+Z2_1)/2
            except Exception as e:
                T2_1 = nan
                k2_1 = nan
                Z2_1 = nan
                kavg_1 = nan
                Zavg_1 = nan
                doc['errors'].append(str(e))
                doc['errors'].append('mixture properties could not be evaluated. check inputs')


            # getting all stage 2 properties
            mixture_2 = mixture
            try:
                props1_2 = mixture_props(mixture_2, P=P1_2, T=T1_2)
                MW_2 = props1_2['MW']
                Z1_2 = props1_2['Z_PR']
                k1_2 = props1_2['k']
            except Exception as e:
                MW_2 = nan
                Z1_2 = nan
                k1_2 = nan
                doc['errors'].append(str(e))
                doc['errors'].append('mixture properties could not be evaluated. check inputs')


            m_2 = m
            Qact_2 = Qactual(MW_2, P1_2, T1_2, Z1_2, m_2)
            if (predict_etaA == "No"):
                etaA_2 = etaA
            else:
                etaA_2 = polyeff(Qact_2)

            try:
                T2_2 = Tdischarge(T1_2, P1_2, P2_2, etap = etaA_2, mixture=mixture_2)
                props2_2 = mixture_props(mixture_2, P=P2_2, T=T2_2)
                k2_2 = props2_2['k']
                Z2_2 = props2_2['Z_PR']
                kavg_2 = (k1_2+k2_2)/2
                Zavg_2 = (Z1_2+Z2_2)/2
            except Exception as e:
                T2_2 = nan
                props2_2 = nan
                k2_2 = nan
                Z2_2 = nan
                kavg_2 = nan
                Zavg_2 = nan
                doc['errors'].append(str(e))
                doc['errors'].append('mixture properties could not be evaluated. check inputs')


        try:
            Hp_1 = Hpolytropic(Zavg_1, MW_1, T1_1, kavg_1, P1_1, P2_1, etaA_1)
            Pabs_1 = absPower(m_1, Hp_1, etaA_1)
            Hp_2 = Hpolytropic(Zavg_2, MW_2, T1_2, kavg_2, P1_2, P2_2, etaA_2)
            Pabs_2 = absPower(m_2, Hp_2, etaA_2)
        except Exception as e:
            Hp_1 = nan
            Pabs_1 = nan
            Hp_2 = nan
            Pabs_2 = nan
            doc['errors'].append(str(e))
            doc['errors'].append('polytropic and head could not be calculated. check inputs')


        d2, Nnominal = centframe(Qact_1)
        th =  theta(MW_1, k1_1, Z1_1, T1_1)
        hpmax = HpmaxWheel(th, sour='Yes')
        Nimpeller_1 = ceil(Hp_1/hpmax)
        Nimpeller_2 = ceil(Hp_2/hpmax)
        N_1 = Nnominal*sqrt(Hp_1/(hpmax*Nimpeller_1))
        N_2 = Nnominal*sqrt(Hp_2/(hpmax*Nimpeller_2))
        if (N_1 > N_2):
            N = N_1
        else:
            N = N_2

        N = roundit(N)


        m_1 = roundit(m_1)
        MW_1 = roundit(MW_1)
        Qact_1 = roundit(Qact_1)
        kavg_1 = roundit(kavg_1)
        Zavg_1 = roundit(Zavg_1)
        etaA_1 = roundit(etaA_1)
        Hp_1 = roundit(Hp_1)
        Pabs_1 = roundit(Pabs_1)

        m_2 = roundit(m_2)
        MW_2 = roundit(MW_2)
        Qact_2 = roundit(Qact_2)
        kavg_2 = roundit(kavg_2)
        Zavg_2 = roundit(Zavg_2)
        etaA_2 = roundit(etaA_2)
        Hp_2 = roundit(Hp_2)
        Pabs_2 = roundit(Pabs_2)

        doc['result'].update({'stages':{'_val' : str(stages)}})

        doc['result'].update({'P1_1':{'_val' : str(P1_1), '_dim':'pressure'}})
        doc['result'].update({'T1_1':{'_val' : str(T1_1), '_dim':'temperature'}})
        doc['result'].update({'P2_1':{'_val' : str(P2_1), '_dim':'pressure'}})
        doc['result'].update({'T2_1':{'_val' : str(T2_1), '_dim':'temperature'}})
        doc['result'].update({'m_1':{'_val' : str(m_1), '_dim':'massflow'}})
        doc['result'].update({'MW_1':{'_val' : str(MW_1), '_dim':'molecularMass'}})
        doc['result'].update({'Qact_1':{'_val' : str(Qact_1), '_dim':'flow'}})
        doc['result'].update({'kavg_1':{'_val' : str(kavg_1)}})
        doc['result'].update({'Zavg_1':{'_val' : str(Zavg_1)}})
        doc['result'].update({'etaA_1':{'_val' : str(etaA_1)}})
        doc['result'].update({'Hp_1':{'_val' : str(Hp_1)}})
        doc['result'].update({'Pabs_1':{'_val' : str(Pabs_1), '_dim':'power'}})
        doc['result'].update({'d2':{'_val' : str(d2), '_dim':'length'}})
        doc['result'].update({'N':{'_val' : str(N)}})
        doc['result'].update({'Nimpeller_1':{'_val' : str(Nimpeller_1)}})

        doc['result'].update({'P1_2':{'_val' : str(P1_2), '_dim':'pressure'}})
        doc['result'].update({'T1_2':{'_val' : str(T1_2), '_dim':'temperature'}})
        doc['result'].update({'P2_2':{'_val' : str(P2_2), '_dim':'pressure'}})
        doc['result'].update({'T2_2':{'_val' : str(T2_2), '_dim':'temperature'}})
        doc['result'].update({'m_2':{'_val' : str(m_2), '_dim':'massflow'}})
        doc['result'].update({'MW_2':{'_val' : str(MW_2), '_dim':'molecularMass'}})
        doc['result'].update({'Qact_2':{'_val' : str(Qact_2), '_dim':'flow'}})
        doc['result'].update({'kavg_2':{'_val' : str(kavg_2)}})
        doc['result'].update({'Zavg_2':{'_val' : str(Zavg_2)}})
        doc['result'].update({'etaA_2':{'_val' : str(etaA_2)}})
        doc['result'].update({'Hp_2':{'_val' : str(Hp_2)}})
        doc['result'].update({'Pabs_2':{'_val' : str(Pabs_2), '_dim':'power'}})
        doc['result'].update({'d2':{'_val' : str(d2), '_dim':'length'}})
        doc['result'].update({'N':{'_val' : str(N)}})
        doc['result'].update({'Nimpeller_2':{'_val' : str(Nimpeller_2)}})


# determine polytropic head and power

    treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True)
    doc_original['result'].update(doc['result'])
    doc_original['errors'] = doc['errors']

    return True
コード例 #28
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
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
コード例 #29
0
ファイル: macro.py プロジェクト: sandeeprah/clappets
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
コード例 #30
0
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