Exemplo n.º 1
0
def define_StateIGas(state: StateIGas, fluid: 'IdealGas'):
    """Tries to fill in the properties of an ideal gas state by applying the ideal gas law and looking up state on the provided mpDF."""

    if len(available_TDependentProperties := [propertyName for propertyName in fluid.mpDF.mp.availableProperties if propertyName in state._properties_all and isNumeric(getattr(state, propertyName))]) >= 1:
        refPropt_name = available_TDependentProperties[0]

        # Try finding exact state on mpDF
        state_at_refPropt = fluid.mpDF.cq.cQuery({refPropt_name: getattr(state, refPropt_name)})
        try:
            if state_at_refPropt.empty:
                # Interpolate in mpDF
                refPropt_valueBelow, refPropt_valueAbove = get_surroundingValues(fluid.mpDF[refPropt_name], value=getattr(state, refPropt_name))
                state_at_refPropt_valueBelow = StateIGas().init_fromDFRow(fluid.mpDF.cq.cQuery({refPropt_name: refPropt_valueBelow}))
                state_at_refPropt_valueAbove = StateIGas().init_fromDFRow(fluid.mpDF.cq.cQuery({refPropt_name: refPropt_valueAbove}))
                state_at_refPropt = interpolate_betweenPureStates(state_at_refPropt_valueBelow, state_at_refPropt_valueAbove, interpolate_at={refPropt_name: getattr(state, refPropt_name)})

            state.copy_fromState(state_at_refPropt)
        except NeedsExtrapolationError:
            pass
Exemplo n.º 2
0
def fullyDefine_StateIGas(state: StateIGas, fluid: 'IdealGas') -> StateIGas:
    """Tries to fill in the properties of an ideal gas state by applying the ideal gas law and looking up state on the provided mpDF."""
    apply_IGasLaw(state, fluid.R)

    # Do an ideal gas table look-up after applying ideal gas law above. The process above may first determine T and only then this table look-up can be done.
    # if len(available_TDependentProperties := [propertyName for propertyName in state.get_asList_definedPropertiesNames() if propertyName in fluid.mpDF.mp.availableProperties]) >= 1:
    if len(available_TDependentProperties := [propertyName for propertyName in StateIGas._properties_Tdependent if state.hasDefined(propertyName)]) >= 1:
        # Get tabulated T-dependent properties
        refPropt_name = available_TDependentProperties[0]
        state_at_refPropt = fluid.mpDF.cq.cQuery({refPropt_name: getattr(state, refPropt_name)})  # Try finding exact state on mpDF

        if state_at_refPropt.empty:
            try:
                # Interpolate in mpDF - ideal gas properties table
                interpolatedState = interpolate_inIGasTable(mpDF=fluid.mpDF, interpolate_by=refPropt_name, interpolate_at=getattr(state, refPropt_name))
                state.copy_fromState(interpolatedState)
            except NeedsExtrapolationError:
                print('fullyDefine_StateIGas: Extrapolation needed to find state at {0}={1}'.format(refPropt_name, getattr(state, refPropt_name)))
                pass
        else:
            state.init_fromDFRow(state_at_refPropt)  # Found exact match, initialize from DFRow