Esempio n. 1
0
def apply_isentropicEfficiency(state_in: StatePure, state_out_ideal: StatePure, eta_isentropic: float, fluid: 'Fluid'):
    """Returns a new state_out based on the provided one, with all fields filled out based on the isentropic efficiency of the process between the state_in and state_out."""

    assert state_out_ideal.hasDefined('P')
    state_out_ideal.set_or_verify({'s': state_in.s})
    try:
        state_out_ideal.copy_fromState(fluid.define(state_out_ideal))
    except NeedsExtrapolationError:
        # For pumps dealing with subcooled liquids no data may be available. w = mu*dP relation can be used to get at least the h.
        if all(state.x <= 0 for state in [state_in, state_out_ideal]):
            apply_incompressibleWorkRelation(state_in=state_in, state_out=state_out_ideal)

    assert all(state.hasDefined('h') for state in [state_in, state_out_ideal])  # state_in & state_out should have *h* defined
    work_ideal = state_out_ideal.h - state_in.h

    state_out_actual = StatePure(P=state_out_ideal.P)

    if work_ideal >= 0:
        # work provided to flow from device -> eta_s = w_ideal / w_actual
        work_actual = work_ideal / eta_isentropic
        state_out_actual.h = work_actual + state_in.h
    elif work_ideal < 0:
        # work extracted from flow by device -> eta_s = w_actual / w_ideal
        work_ideal = abs(work_ideal)
        work_actual = eta_isentropic * work_ideal
        state_out_actual.h = state_in.h - work_actual

    return fluid.defineState_ifDefinable(state_out_actual)
Esempio n. 2
0
 def defineState_ifDefinable(self, state: StatePure):
     if not state.isFullyDefined() and state.isFullyDefinable():
         try:
             state.copy_fromState(self.define(state))
         except NeedsExtrapolationError:
             print(
                 'Fluid.defineState_ifDefinable: Leaving state @ {0} not fully defined'
                 .format(state))
     return state
Esempio n. 3
0
def apply_isentropicEfficiency(constant_c: bool, state_in: StatePure, state_out_ideal: StatePure, eta_isentropic: float, fluid: 'Fluid'):
    """Returns a new state_out based on the provided one, with all fields filled out based on the isentropic efficiency of the process between the state_in and state_out."""

    if not constant_c:  # Variable c analysis - will use tabulated data for fluids other than ideal gases
        if state_out_ideal.hasDefined('P'):

            if fluid.stateClass is StatePure:  # if not an IGas flow - ideally should check if fluid is IGas but cannot as ThprOps do not know fluids.
                state_out_ideal.set_or_verify({'s': state_in.s})
                try:
                    state_out_ideal.copy_fromState(fluid.define(state_out_ideal))
                except NeedsExtrapolationError:
                    # For pumps dealing with subcooled liquids no data may be available. w = mu*dP relation can be used to get at least the h.
                    if all(state.x <= 0 for state in [state_in, state_out_ideal]):
                        apply_incompressibleWorkRelation(state_in=state_in, state_out=state_out_ideal)

            assert all(state.hasDefined('h') for state in [state_in, state_out_ideal])  # state_in & state_out should have *h* defined
            work_ideal = state_out_ideal.h - state_in.h

            state_out_actual = fluid.stateClass(P=state_out_ideal.P)

            if work_ideal >= 0:  # work provided to flow from device -> eta_s = w_ideal / w_actual
                work_actual = work_ideal / eta_isentropic
                state_out_actual.h = work_actual + state_in.h
            elif work_ideal < 0:  # work extracted from flow by device -> eta_s = w_actual / w_ideal
                work_ideal = abs(work_ideal)
                work_actual = eta_isentropic * work_ideal
                state_out_actual.h = state_in.h - work_actual

            return fluid.defineState_ifDefinable(state_out_actual)

    else:  # Constant c analysis
        if all(state.hasDefined('T') for state in [state_in, state_out_ideal]):
            work_ideal = fluid.cp*(state_out_ideal.T - state_in.T)

            state_out_actual = fluid.stateClass()
            state_out_actual.copy_fromState(state_out_ideal)  # accessing __class__ like this, to use the same class as state_out - could be StatePure or StateIGas

            if work_ideal >= 0:
                work_actual = work_ideal / eta_isentropic
                state_out_actual.T = (work_actual/fluid.cp) + state_in.T
                state_out_actual.mu = float('nan')  # mu of state_out_ideal no longer valid, needs to be recalculated with IGasLaw
            elif work_ideal <= 0:
                work_ideal = abs(work_ideal)
                work_actual = eta_isentropic * work_ideal
                state_out_actual.T = state_in.T - (work_actual/fluid.cp)
                state_out_actual.mu = float('nan')  # mu of state_out_ideal no longer valid, needs to be recalculated with IGasLaw
            return state_out_actual