示例#1
0
def process_fluid_state(fluid_ref, fractions='mole'):
    """Check input for state object or fluid string

    Parameters
    ----------
        fluid_ref : str, CoolProp.AbstractState
        fractions : str, switch to set mass, volu or mole fractions

    Returns
    -------
        CoolProp.AbstractState
    """
    # Process the fluid and set self._state
    if is_string(fluid_ref):
        backend, fluids   = extract_backend(fluid_ref)
        fluids, fractions = extract_fractions(fluids)
        state = AbstractState(backend, '&'.join(fluids))
        if len(fluids) > 1 and len(fluids) == len(fractions):
            if fractions=='mass': state.set_mass_fractions(fractions)
            elif fractions=='volu': state.set_volu_fractions(fractions)
            else: state.set_mole_fractions(fractions)
        return state
    elif isinstance(fluid_ref, AbstractState):
        return fluid_ref
    raise TypeError("Invalid fluid_ref input, expected a string or an abstract state instance.")
示例#2
0
def process_fluid_state(fluid_ref, fractions='mole'):
    """Check input for state object or fluid string

    Parameters
    ----------
        fluid_ref : str, CoolProp.AbstractState
        fractions : str, switch to set mass, volu or mole fractions

    Returns
    -------
        CoolProp.AbstractState
    """
    # Process the fluid and set self._state
    if is_string(fluid_ref):
        backend, fluids = extract_backend(fluid_ref)
        fluids, fractions = extract_fractions(fluids)
        state = AbstractState(backend, '&'.join(fluids))
        if len(fluids) > 1 and len(fluids) == len(fractions):
            if fractions == 'mass': state.set_mass_fractions(fractions)
            elif fractions == 'volu': state.set_volu_fractions(fractions)
            else: state.set_mole_fractions(fractions)
        return state
    elif isinstance(fluid_ref, AbstractState):
        return fluid_ref
    raise TypeError(
        "Invalid fluid_ref input, expected a string or an abstract state instance."
    )
示例#3
0
def get_critical_point(state):
    crit_state = PyCriticalState() 
    crit_state.T = np.nan
    crit_state.p = np.nan
    crit_state.rhomolar = np.nan
    crit_state.stable = False
    try:
        crit_state.T = state.T_critical()
        crit_state.p = state.p_critical()
        crit_state.rhomolar = state.rhomolar_critical()
        crit_state.stable = True
    except:
        try:
            for crit_state_tmp in state.all_critical_points():
                if crit_state_tmp.stable and (crit_state_tmp.T > crit_state.T or not np.isfinite(crit_state.T)):
                    crit_state.T = crit_state_tmp.T
                    crit_state.p = crit_state_tmp.p
                    crit_state.rhomolar = crit_state_tmp.rhomolar
                    crit_state.stable = crit_state_tmp.stable
        except:
            raise ValueError("Could not calculate the critical point data.")    
    new_state = AbstractState(state.backend_name(), '&'.join(state.fluid_names()))
    masses = state.get_mass_fractions()
    if len(masses)>1: 
        new_state.set_mass_fractions(masses) # Uses mass fraction to work with incompressibles
        #try: new_state.build_phase_envelope("dummy")
        #except: pass
    if np.isfinite(crit_state.p) and np.isfinite(crit_state.T):
        try: new_state.specify_phase(CoolProp.iphase_critical_point)
        except: pass 
        new_state.update(CoolProp.PT_INPUTS, crit_state.p, crit_state.T)
        #new_state.update(CoolProp.DmolarT_INPUTS, crit_state.rhomolar, crit_state.T)
        return new_state
    raise ValueError("Could not calculate the critical point data.")
示例#4
0
文件: Common.py 项目: xunyun/CoolProp
def get_critical_point(state):
    crit_state = PyCriticalState() 
    crit_state.T = np.nan
    crit_state.p = np.nan
    crit_state.rhomolar = np.nan
    crit_state.rhomolar = np.nan
    crit_state.stable = False
    try:
        crit_state.T = state.T_critical()
        crit_state.p = state.p_critical()
        crit_state.rhomolar = state.rhomolar_critical()
        crit_state.stable = True
    except:
        try:
            for crit_state_tmp in state.all_critical_points():
                if crit_state_tmp.stable and (crit_state_tmp.T > crit_state.T or not np.isfinite(crit_state.T)):
                    crit_state.T = crit_state_tmp.T
                    crit_state.p = crit_state_tmp.p
                    crit_state.rhomolar = crit_state_tmp.rhomolar
                    crit_state.stable = crit_state_tmp.stable
        except:
            raise ValueError("Could not calculate the critical point data.")    
    new_state = AbstractState(state.backend_name(), '&'.join(state.fluid_names()))
    masses = state.get_mass_fractions()
    if len(masses)>1: 
        new_state.set_mass_fractions(masses) # Uses mass fraction to work with incompressibles
        #try: new_state.build_phase_envelope("dummy")
        #except: pass
    msg = ""
    if np.isfinite(crit_state.p) and np.isfinite(crit_state.T):
        try: 
            new_state.specify_phase(CoolProp.iphase_critical_point)
            new_state.update(CoolProp.PT_INPUTS, crit_state.p, crit_state.T)
            return new_state
        except Exception as e:
            msg += str(e)+" - "
            pass
        try:
            new_state.update(CoolProp.PT_INPUTS, crit_state.p, crit_state.T)
            return new_state
        except Exception as e:
            msg += str(e)+" - "
            pass 
    if np.isfinite(crit_state.rhomolar) and np.isfinite(crit_state.T):
        try:
            new_state.specify_phase(CoolProp.iphase_critical_point)
            new_state.update(CoolProp.DmolarT_INPUTS, crit_state.rhomolar, crit_state.T)
            return new_state
        except Exception as e:
            msg += str(e)+" - "
            pass
        try:
            new_state.update(CoolProp.DmolarT_INPUTS, crit_state.rhomolar, crit_state.T)
            return new_state
        except Exception as e:
            msg += str(e)+" - "
            pass
    raise ValueError("Could not calculate the critical point data. "+msg)