Ejemplo n.º 1
0
def region_prho(p, rho):
    """
    # Section 3.5 Regions as a function of p and rho
    # function region_prho = region_prho(p,rho)
    """
    v = 1 / rho
    if (p < 0.000611657) or (p > 100):
        # region_prho = 0;
        logger.warning('Preasure outside valid area')
        return 0

    if p < 16.5292:  #  %Bellow region 3, Check region 1,4,2
        if v < Region1.v1_pT(
                p, 273.15
        ):  # %Observe that this is not actually min of v. Not valid Water of 4???C is ligther.
            # region_prho = 0;
            logger.warning('Specific volume outside valid area')
            return 0
        if v <= Region1.v1_pT(p, Region4.T4_p(p)):
            # region_prho = 1;
            return 1
        if v < Region2.v2_pT(p, Region4.T4_p(p)):
            # region_prho = 4;
            return 4
        if v <= Region2.v2_pT(p, 1073.15):
            # region_prho = 2;
            return 2
        if p > 10:  # %Above region 5
            # region_prho = 0;
            logger.warning('Preasure outside valid area')
            return 0
        if v <= Region5.v5_pT(p, 2073.15):
            # region_prho = 5;
            return 5
    else:  # %Check region 1,3,4,3,2 (Above the lowest point of region 3.)
        if v < Region1.v1_pT(
                p, 273.15
        ):  # %Observe that this is not actually min of v. Not valid Water of 4???C is ligther.
            # region_prho = 0;
            logger.warning('Specific volume outside valid area')
            return 0
        if v < Region1.v1_pT(p, 623.15):
            # region_prho = 1;
            return 1
        # %Check if in region 3 or 4 (Bellow Reg 2)
        if v < Region2.v2_pT(p, RegionBorders.B23T_p(p)):
            # %Region 3 or 4
            if p > 22.064:  # %Above region 4
                # region_prho = 3;
                return 3
            if (v < Region3.v3_ph(p, Region4.h4L_p(p))) or (v > Region3.v3_ph(
                    p, Region4.h4V_p(p))):  # %Uses iteration!!
                # region_prho = 3;
                return 3
            else:
                # region_prho = 4;
                return 4
        # %Check if region 2
        if v < Region2.v2_pT(p, 1073.15):
            # region_prho = 2;
            return 2
    # region_prho = 0;
    logger.warning('Preasure and Density outside valid area')
    return 0
Ejemplo n.º 2
0
def my_AllRegions_ph(p, h):
    """ function my_AllRegions_ph = my_AllRegions_ph(p, h) """
    h0 = [0.5132047, 0.3205656, 0, 0, -0.7782567, 0.1885447]
    h1 = [0.2151778, 0.7317883, 1.241044, 1.476783, 0, 0]
    h2 = [-0.2818107, -1.070786, -1.263184, 0, 0, 0]
    h3 = [0.1778064, 0.460504, 0.2340379, -0.4924179, 0, 0]
    h4 = [-0.0417661, 0, 0, 0.1600435, 0, 0]
    h5 = [0, -0.01578386, 0, 0, 0, 0]
    h6 = [0, 0, 0, -0.003629481, 0, 0]

    # % Calcualte density.
    # switch region_ph(p, h)
    if RegionSelection.region_ph(p, h) == 1:
        Ts = Region1.T1_ph(p, h)
        T = Ts
        rho = 1 / Region1.v1_pT(p, Ts)
    elif RegionSelection.region_ph(p, h) == 2:
        Ts = Region2.T2_ph(p, h)
        T = Ts
        rho = 1 / Region2.v2_pT(p, Ts)
    elif RegionSelection.region_ph(p, h) == 3:
        rho = 1 / Region3.v3_ph(p, h)
        T = Region3.T3_ph(p, h)
    elif RegionSelection.region_ph(p, h) == 4:
        xs = Region4.x4_ph(p, h)
        if p < 16.529:
            v4v = Region2.v2_pT(p, Region4.T4_p(p))
            v4L = Region1.v1_pT(p, Region4.T4_p(p))
        else:
            v4v = Region3.v3_ph(p, Region4.h4V_p(p))
            v4L = Region3.v3_ph(p, Region4.h4L_p(p))
        rho = 1 / (xs * v4v + (1 - xs) * v4L)
        T = Region4.T4_p(p)
    elif RegionSelection.region_ph(p, h) == 5:
        Ts = Region5.T5_ph(p, h)
        T = Ts
        rho = 1 / Region5.v5_pT(p, Ts)
    else:
        # my_AllRegions_ph = NaN;
        logger.warning('Region switch returned unknown value')
        return float("NaN")

    rhos = rho / 317.763
    Ts = T / 647.226
    # ps = p / 22.115
    # % Check valid area
    if (T > (900 + 273.15)) or (T > (600 + 273.15) and
                                (p > 300)) or (T > (150 + 273.15) and
                                               (p > 350)) or (p > 500):
        # my_AllRegions_ph = NaN;
        return float("NaN")

    my0 = Ts**0.5 / (1 + 0.978197 / Ts + 0.579829 / (Ts**2) - 0.202354 /
                     (Ts**3))

    Sum = 0
    # TODO:vvvv Check for mistake vvvvv
    # Original Code: for i = 0 : 5
    # Same Problem as in my_AllRegions_pT, see there for explanation
    for i in range(0, 6):
        # Sum = Sum + h0(i + 1) * (1 / Ts - 1) ** i + h1(i + 1) * (1 / Ts - 1) ** i * (rhos - 1) ** 1 + h2(i + 1) * (1 / Ts - 1) ** i * (rhos - 1) ** 2 + h3(i + 1) * (1 / Ts - 1) ** i * (rhos - 1) ** 3 + h4(i + 1) * (1 / Ts - 1) ** i * (rhos - 1) ** 4 + h5(i + 1) * (1 / Ts - 1) ** i * (rhos - 1) ** 5 + h6(i + 1) * (1 / Ts - 1) ** i * (rhos - 1) ** 6;
        Sum = Sum + h0[i] * (1 / Ts - 1) ** i + \
            h1[i] * (1 / Ts - 1) ** i * (rhos - 1) ** 1 + \
            h2[i] * (1 / Ts - 1) ** i * (rhos - 1) ** 2 + \
            h3[i] * (1 / Ts - 1) ** i * (rhos - 1) ** 3 + \
            h4[i] * (1 / Ts - 1) ** i * (rhos - 1) ** 4 + \
            h5[i] * (1 / Ts - 1) ** i * (rhos - 1) ** 5 + \
            h6[i] * (1 / Ts - 1) ** i * (rhos - 1) ** 6

    my1 = math.exp(rhos * Sum)
    mys = my0 * my1
    return mys * 0.000055071