Beispiel #1
0
class DerivativeTest:
    def __init__ (self, fluid):
        self.fluid = fluid
        self.fState = FluidState(self.fluid)

    def numerical_derivative(self, stateVarNum,
                                    stateVarDenom, stateVarDenom_val, 
                                    stateVarConst, stateVarConst_val, delta = 1.000001):
        """
        stateVarNum - name of state variable in numerator of the derivative (name is in style of FluidState properties)
        stateVarDenom - name of state variable in denominator of the derivative (name is in style of FluidState.update arguments)
        stateVarConst - name of constant state variable (name is in style of FluidState.update arguments)
        """
        self.fState.update(stateVarDenom, stateVarDenom_val, stateVarConst, stateVarConst_val)
        stateVarNum_val = getattr(self.fState, stateVarNum)
        stateVarDenom_val_new = stateVarDenom_val * delta
        self.fState.update(stateVarDenom, stateVarDenom_val_new, stateVarConst, stateVarConst_val)
        stateVarNum_val_new = getattr(self.fState, stateVarNum)
        num_derivative = (stateVarNum_val_new - stateVarNum_val) / (stateVarDenom_val_new - stateVarDenom_val)
        return num_derivative
    
    @staticmethod
    def test():
        test_instance = DerivativeTest("Water")
        _drhodT_s = test_instance.numerical_derivative('rho', 
                                                     'T', 633.15,
                                                     'S', 4000)
        print ('Numerical: ' + str(_drhodT_s))
        fState = FluidState("Water")
        fState.update_Ts(633.15, 4000)
        print ('Analytical: ' + str(fState.rho**2 * fState.dsdT_v / fState.dpdT_v))
        print ('q = {}'.format(fState.q))
Beispiel #2
0
def testState():
    s1 = FluidState('ParaHydrogen')
    s1.update('P', 700e5, 'T', 288)
    print("p={0}".format(s1.p()))
    print("T={0}".format(s1.T()))
    print("rho={0}".format(s1.rho()))
    print("h={0}".format(s1.h()))
    print("s={0}".format(s1.s()))
    print("cp={0}".format(s1.cp()))
    print("cv={0}".format(s1.cv()))
    print("gamma={0}".format(s1.gamma()))
    print("dpdt_v={0}".format(s1.dpdt_v()))
    print("dpdv_t={0}".format(s1.dpdv_t()))
    print("beta={0}".format(s1.beta()))
    print("mu={0}".format(s1.mu()))
    print("lambfa={0}".format(s1.cond()))
    print("Pr={0}".format(s1.Pr()))

    s2 = FluidState('ParaHydrogen')
    s2.update_Tp(s1.T(), s1.p())
    print("update_Tp rho={0}".format(s2.rho()))
    s3 = FluidState('ParaHydrogen')
    s3.update_Trho(s1.T(), s1.rho())
    print("update_Trho p={0}".format(s3.p()))
    s4 = FluidState('ParaHydrogen')
    s4.update_prho(s1.p(), s1.rho())
    print("update_prho T={0}".format(s4.T()))
    s5 = FluidState('ParaHydrogen')
    s5.update_ph(s1.p(), s1.h())
    print("update_ph ={0}".format(s5.T()))
    s6 = FluidState('ParaHydrogen')
    s6.update_ps(s1.p(), s1.s())
    print("update_ps T={0}".format(s6.T()))
    s7 = FluidState('ParaHydrogen')
    s7.update_pq(1e5, 0)
    print("update_pq T={0}".format(s7.T()))
    s8 = FluidState('ParaHydrogen')
    s8.update_Tq(25, 0)
    print("update_Tq p={0}".format(s8.p()))
    print('--------------------')
    print('Initialize state from fluid')
    h2 = Fluid('ParaHydrogen')
    s9 = FluidState(h2)
    s9.update_Tp(s1.T(), s1.p())
    print("rho={0}".format(s9.rho()))
Beispiel #3
0
class DerivativeTest:
    def __init__(self, fluid):
        self.fluid = fluid
        self.fState = FluidState(self.fluid)

    def numerical_derivative(self,
                             stateVarNum,
                             stateVarDenom,
                             stateVarDenom_val,
                             stateVarConst,
                             stateVarConst_val,
                             delta=1.000001):
        """
        stateVarNum - name of state variable in numerator of the derivative (name is in style of FluidState properties)
        stateVarDenom - name of state variable in denominator of the derivative (name is in style of FluidState.update arguments)
        stateVarConst - name of constant state variable (name is in style of FluidState.update arguments)
        """
        self.fState.update(stateVarDenom, stateVarDenom_val, stateVarConst,
                           stateVarConst_val)
        stateVarNum_val = getattr(self.fState, stateVarNum)
        stateVarDenom_val_new = stateVarDenom_val * delta
        self.fState.update(stateVarDenom, stateVarDenom_val_new, stateVarConst,
                           stateVarConst_val)
        stateVarNum_val_new = getattr(self.fState, stateVarNum)
        num_derivative = (stateVarNum_val_new - stateVarNum_val) / (
            stateVarDenom_val_new - stateVarDenom_val)
        return num_derivative

    @staticmethod
    def test():
        test_instance = DerivativeTest("Water")
        _drhodT_s = test_instance.numerical_derivative('rho', 'T', 633.15, 'S',
                                                       4000)
        print('Numerical: ' + str(_drhodT_s))
        fState = FluidState("Water")
        fState.update_Ts(633.15, 4000)
        print('Analytical: ' +
              str(fState.rho**2 * fState.dsdT_v / fState.dpdT_v))
        print('q = {}'.format(fState.q))
Beispiel #4
0
    def compute(self):
        fState = FluidState(self.fluidName)
        fState.update(
            self.stateVariable1,
            self.getStateValue(self.stateVariable1, 1),
            self.stateVariable2,
            self.getStateValue(self.stateVariable2, 2),
        )
        self.T = fState.T
        self.p = fState.p
        self.rho = fState.rho
        self.h = fState.h
        self.s = fState.s
        self.q = fState.q
        self.u = fState.u

        self.cp = fState.cp
        self.cv = fState.cv
        self.gamma = fState.gamma
        self.Pr = fState.Pr
        self.cond = fState.cond
        self.mu = fState.mu
        self.dpdT_v = fState.dpdT_v
        self.dpdv_T = fState.dpdv_T

        self.isTwoPhase = fState.isTwoPhase()
        if self.isTwoPhase:
            satL = fState.SatL
            satV = fState.SatV

            self.rho_L = satL.rho
            self.h_L = satL.h
            self.s_L = satL.s

            self.rho_V = satV.rho
            self.h_V = satV.h
            self.s_V = satV.s