예제 #1
0
    def test_flows_water_09(self):
        # CENGEL P10-35

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.massFR = 12
        flow_a.items = [
            state_1 := StatePure(x=0), pump := Pump(), state_2 :=
            StatePure(P=15000), rhboiler :=
            ReheatBoiler(infer_fixed_exitT=True), state_3 := StatePure(T=500),
            hpt := Turbine(), state_4 := StatePure(), rhboiler, state_5 :=
            StatePure(), lpt := Turbine(), state_6 := StatePure(P=10, x=0.9),
            condenser := Condenser(), state_1
        ]

        cycle = Cycle()
        cycle.flows = [flow_a]
        cycle.solve()

        self.CompareResults(state_2, {'h': 206.95}, 2)
        self.CompareResults(state_5, {
            'P': 2160,
            'h': 3466.61
        }, 2)  # not sure why answers say 2150 - did manually, ~2161
        self.CompareResults(state_4, {'h': 2817.2}, 2)

        self.assertTrue(isWithin(cycle.Q_in, 2, '%', 45039))
        self.assertTrue(isWithin(cycle.netPower / cycle.Q_in, 2, '%', 0.426))

        pass
예제 #2
0
    def test_flows_water_08(self):
        # CENGEL P10-34

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.items = [
            state_1 := StatePure(x=0), pump := Pump(), state_2 :=
            StatePure(P=5000), rhboiler :=
            ReheatBoiler(infer_fixed_exitT=False), state_3 := StatePure(), hpt
            := Turbine(), state_4 := StatePure(P=1200, x=0.96), rhboiler,
            state_5 := StatePure(), lpt := Turbine(), state_6 :=
            StatePure(P=20, x=0.96), condenser := Condenser(), state_1
        ]

        cycle = Cycle()
        cycle.flows = [flow_a]
        cycle.solve()

        self.CompareResults(state_2, {'h': 256.49}, 2)
        self.CompareResults(state_3, {'h': 3006.9, 'T': 327.2}, 2)
        self.CompareResults(state_5, {'h': 3436, 'T': 481.1}, 2)

        self.assertTrue(isWithin(flow_a.get_sHeatSupplied(), 2, '%', 3482))
        self.assertTrue(
            isWithin(
                flow_a.get_net_sWorkExtracted() / flow_a.get_sHeatSupplied(),
                2, '%', 0.35))

        pass
예제 #3
0
    def test_flows_water_11(self):
        # CENGEL P10-38

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.items = [
            state_1 := StatePure(x=0, P=10), pump := Pump(eta_isentropic=1),
            state_2 := StatePure(), rhboiler :=
            ReheatBoiler(infer_fixed_exitT=True), state_3 := StatePure(P=10000,
                                                                       T=500),
            hpt := Turbine(eta_isentropic=1), state_4 := StatePure(), rhboiler,
            state_5 := StatePure(P=1000,
                                 T=500), lpt := Turbine(eta_isentropic=1),
            state_6 := StatePure(), condenser := Condenser(), state_1
        ]

        cycle = Cycle()
        cycle.flows = [flow_a]
        cycle.netPower = 80000
        cycle.solve()

        self.CompareResults(state_6, {'x': 0.949}, 2)

        self.assertTrue(
            isWithin(
                flow_a.get_net_sWorkExtracted() / flow_a.get_sHeatSupplied(),
                2, '%', 0.413))
        self.assertTrue(isWithin(flow_a.massFR, 2, '%', 50))

        pass
예제 #4
0
    def test_flows_water_10(self):
        # CENGEL P10-37

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.items = [
            state_1 := StatePure(x=0, P=10), pump := Pump(eta_isentropic=0.95),
            state_2 := StatePure(), rhboiler :=
            ReheatBoiler(infer_fixed_exitT=True), state_3 := StatePure(P=10000,
                                                                       T=500),
            hpt := Turbine(eta_isentropic=0.8), state_4 := StatePure(),
            rhboiler, state_5 := StatePure(P=1000, T=500), lpt :=
            Turbine(eta_isentropic=0.8), state_6 := StatePure(), condenser :=
            Condenser(), state_1
        ]

        cycle = Cycle()
        cycle.flows = [flow_a]
        cycle.netPower = 80000
        cycle.solve()

        self.CompareResults(state_2, {'h': 202.43}, 2)
        self.CompareResults(state_4, {'h': 2902}, 2)
        self.CompareResults(state_6, {'h': 2664.8, 'T': 88.1}, 2)

        self.assertTrue(
            isWithin(flow_a.get_net_sWorkExtracted(), 2, '%', 1276.8))
        self.assertTrue(isWithin(flow_a.get_sHeatSupplied(), 2, '%', 3749.8))
        self.assertTrue(isWithin(flow_a.massFR, 2, '%', 62.7))

        pass
예제 #5
0
    def test_suphVap_10(self):
        # MECH2201 A8 Q1 State 1

        statePropt = {'P': 8000, 'T': 500}
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)

        expected_h = 3398.3
        expected_s = 6.7240

        self.assertTrue(isWithin(testState.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState.h))

        self.assertTrue(isWithin(testState.s, 3, '%', expected_s))
        print('Expected: {0}'.format(expected_s))
        print('Received: {0}'.format(testState.s))

        # state 2s

        statePropt = {'P': 30, 's': testState.s}
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)

        expected_h = 2276.8
        expected_x = 0.847

        self.assertTrue(isWithin(testState.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState.h))

        self.assertTrue(isWithin(testState.x, 3, '%', expected_x))
        print('Expected: {0}'.format(expected_x))
        print('Received: {0}'.format(testState.x))
예제 #6
0
    def test_flows_water_17(self):
        # CENGEL P10-31

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.massFR = 1.74
        flow_a.items = [
            state_02 := StatePure(), rhboiler :=
            ReheatBoiler(infer_fixed_exitT=True), state_03 :=
            StatePure(T=400, P=6000), hpturbine := Turbine(), state_04 :=
            StatePure(P=2000), rhboiler, state_05 := StatePure(), lpturbine :=
            Turbine(), state_06 := StatePure(P=20), condenser := Condenser(),
            state_01 := StatePure(x=0), pump := Pump(), state_02
        ]

        cycle = Cycle()
        cycle.flows = [flow_a]
        cycle.solve()

        self.CompareResults(state_02, {'h': 257.5}, 2)
        self.CompareResults(state_06, {'h': 2349.7}, 2)

        self.assertTrue(isWithin(cycle.sHeat, 1, '%', 3268))
        self.assertTrue(isWithin(cycle.net_sPower, 1, '%', 1170))
        self.assertTrue(isWithin(cycle.efficiency, 1, '%', 0.358))

        pass
예제 #7
0
    def test_flows_water_12(self):
        # CENGEL P10-45

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.items = [
            ofwh := MixingChamber(), state_3 := StatePure(x=0), pump2 :=
            Pump(), state_4 := StatePure(), boiler := Boiler(), state_5 :=
            StatePure(P=6000, T=450), turbine := Turbine()
        ]

        flow_b = Flow(water)
        flow_b.items = [turbine, state_6 := StatePure(P=400), ofwh]

        flow_c = Flow(water)
        flow_c.items = [
            turbine, state_7 := StatePure(P=20), condenser := Condenser(),
            state_1 := StatePure(x=0), pump1 := Pump(), state_2 := StatePure(),
            ofwh
        ]

        cycle = Cycle()
        cycle.flows = [flow_a, flow_b, flow_c]
        cycle.solve()
        cycle.solve()

        for e in cycle._equations:
            e.update()

        cycle.solve()

        self.assertTrue(isWithin(cycle.net_sPower, 1, '%', 1017))
        self.assertTrue(isWithin(cycle.efficiency, 1, '%', 0.378))

        pass
예제 #8
0
    def test_flows_water_15(self):

        # CENGEL P10-22

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.massFR = 20
        flow_a.items = [
            state_01 := StatePure(P=6000), boiler := Boiler(), state_02 :=
            StatePure(T=450), turbine := Turbine(eta_isentropic=0.94), state_03
            := StatePure(), condenser := Condenser(), state_04 :=
            StatePure(P=50, T=water.define(StatePure(P=50, x=0)).T - 6.3), pump
            := Pump(), state_01
        ]

        cycle = Cycle()
        cycle.flows = [flow_a]
        cycle.solve()

        self.CompareResults(state_04, {'h': 314.03, 'mu': 0.001026}, 2)
        self.CompareResults(state_01, {'h': 320.13}, 2)
        self.CompareResults(state_03, {'h': 2394.4}, 2)

        self.assertTrue(isWithin(cycle.Q_in, 1, '%', 59660))
        self.assertTrue(isWithin(cycle.netPower, 1, '%', 18050))
        self.assertTrue(isWithin(cycle.efficiency, 1, '%', 0.303))

        pass
예제 #9
0
    def test_satVap_01(self):
        # From MECH2201 - A7 Q3 - state 1

        statePropt = {'P': 600, 'x': 1}
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)
        expected_mu = 0.3157
        expected_s = 6.76
        expected_T = 158.85
        expected_u = 2567.4

        self.assertTrue(isWithin(testState.u, 3, '%', expected_u))
        print('Expected: {0}'.format(expected_u))
        print('Received: {0}'.format(testState.u))

        self.assertTrue(isWithin(testState.mu, 3, '%', expected_mu))
        print('Expected: {0}'.format(expected_mu))
        print('Received: {0}'.format(testState.mu))

        self.assertTrue(isWithin(testState.s, 3, '%', expected_s))
        print('Expected: {0}'.format(expected_s))
        print('Received: {0}'.format(testState.s))

        self.assertTrue(isWithin(testState.T, 3, '%', expected_T))
        print('Expected: {0}'.format(expected_T))
        print('Received: {0}'.format(testState.T))
예제 #10
0
    def test_satLiq_03(self):
        # From MECH2201 - A9 Q1 - state 5

        statePropt = {'P': 10, 'x': 0}
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)
        expected_h = 191.83
        expected_mu = 0.001010
        expected_s = 0.6493
        expected_T = 45.81

        self.assertTrue(isWithin(testState.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState.h))

        self.assertTrue(isWithin(testState.mu, 3, '%', expected_mu))
        print('Expected: {0}'.format(expected_mu))
        print('Received: {0}'.format(testState.mu))

        self.assertTrue(isWithin(testState.s, 3, '%', expected_s))
        print('Expected: {0}'.format(expected_s))
        print('Received: {0}'.format(testState.s))

        self.assertTrue(isWithin(testState.T, 3, '%', expected_T))
        print('Expected: {0}'.format(expected_T))
        print('Received: {0}'.format(testState.T))
예제 #11
0
    def test_flows_water_03(self):

        print('CENGEL P10.57')

        # h3 = h11 ? says solutions
        # h4 = h9

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.massFR = 75
        flow_a.items = [
            mixcCond := MixingChamber(), state_i := StatePure(), condenser :=
            Condenser(), state_01 := StatePure(P=20, x=0), pump := Pump(),
            state_02 := StatePure(P=5000), cfwhA :=
            HeatExchanger(infer_common_exitT=True), state_03 := StatePure(),
            cfwhB := HeatExchanger(infer_common_exitT=True), state_04 :=
            StatePure(), boiler := Boiler(), state_05 := StatePure(P=5000,
                                                                   T=700),
            turbine := Turbine()
        ]

        flow_b = Flow(water)
        flow_b.massFF = 0.1446
        flow_b.items = [
            turbine, state_06 := StatePure(P=1400), cfwhB, state_09 :=
            StatePure(x=0), trap := Trap(), state_10 := StatePure(), mixcI :=
            MixingChamber()
        ]

        flow_c = Flow(water)
        flow_c.items = [turbine, state_07 := StatePure(P=245), mixcI]

        flow_e = Flow(water)
        flow_e.items = [
            mixcI, state_i2 := StatePure(), cfwhA, state_11 := StatePure(x=0),
            trapA := Trap(), state_12 := StatePure(), mixcCond
        ]

        flow_d = Flow(water)
        flow_d.items = [turbine, state_08 := StatePure(P=20), mixcCond]

        cycle = Cycle()
        cycle.flows = [flow_a, flow_b, flow_c, flow_d, flow_e]
        cycle.solve()

        # Todo - first 0-1-2 equations are solvable together

        self.CompareResults(state_01, {'h': 251, 'mu': 0.00102}, 3)
        self.CompareResults(state_02, {'h': 256.1}, 3)
        self.CompareResults(state_03, {'h': 533}, 3)
        self.CompareResults(state_11, {'h': state_03.h}, 3)
        self.CompareResults(state_04, {'h': 830}, 3)

        self.assertTrue(isWithin(flow_c.massFF, 3, '%', 0.09810))
        self.assertTrue(isWithin(cycle.netPower, 3, '%', 93000))
        self.assertTrue(isWithin(cycle.netPower / cycle.Q_in, 3, '%', 0.404))

        pass
예제 #12
0
    def test_flows_water_14(self):

        # CENGEL P10-47

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.massFR = 16
        flow_a.items = [
            ofwh2 := MixingChamber(), state_05 := StatePure(x=0), pump3 :=
            Pump(), state_06 := StatePure(), boiler := Boiler(), state_07 :=
            StatePure(P=8000, T=550), turbine := Turbine()
        ]

        flow_b = Flow(water)
        flow_b.items = [turbine, state_08 := StatePure(P=600), ofwh2]

        flow_c = Flow(water)
        flow_c.items = [
            turbine, state_09 := StatePure(P=200), ofwh1 := MixingChamber()
        ]

        flow_d = Flow(water)
        flow_d.items = [
            turbine, state_10 := StatePure(P=10), condenser := Condenser(),
            state_01 := StatePure(x=0), pump1 := Pump(), state_02 :=
            StatePure(), ofwh1
        ]

        flow_e = Flow(water)
        flow_e.items = [
            ofwh1, state_03 := StatePure(x=0), pump2 := Pump(), state_04 :=
            StatePure(), ofwh2
        ]

        cycle = Cycle()
        cycle.flows = [flow_a, flow_b, flow_c, flow_d, flow_e]
        cycle.solve()

        for e in cycle._equations:
            e.update()
        cycle.solve()

        for e in cycle._equations:
            e.update()
        cycle.solve()

        self.CompareResults(state_02, {'h': 192}, 2)
        self.CompareResults(state_04, {'h': 505.13}, 2)
        self.CompareResults(state_06, {'h': 678.52}, 2)
        self.CompareResults(flow_b, {'massFF': 0.07171}, 2)
        self.CompareResults(flow_c, {'massFF': 0.1201}, 2)

        self.assertTrue(isWithin(cycle.netPower, 1, '%', 19800))
        self.assertTrue(isWithin(cycle.efficiency, 1, '%', 0.435))

        pass
예제 #13
0
    def test_flows_water_06(self):
        # CENGEL P10-48
        # diagram in book is not helpful - see solutions

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.items = [
            mixc := MixingChamber(), state_t := StatePure(), condenser :=
            Condenser(), state_1 := StatePure(x=0), pump := Pump(), state_2 :=
            StatePure(), cfwh := HeatExchanger(), state_3 :=
            StatePure(T=water.define(StatePure(P=1000, x=0)).T), boiler :=
            Boiler(), state_4 := StatePure(P=3000,
                                           T=350), turbine := Turbine()
        ]

        flow_b = Flow(water)
        flow_b.items = [
            turbine, state_5 := StatePure(P=1000), cfwh, state_7 :=
            StatePure(x=0), trap := Trap(), state_8 := StatePure(P=20), mixc
        ]

        flow_c = Flow(water)
        flow_c.items = [turbine, state_6 := StatePure(), mixc]

        cycle = Cycle()
        cycle.flows = [flow_a, flow_b, flow_c]
        cycle.solve()

        for e in cycle._equations:
            e.update()
        cycle.solve()
        for e in cycle._equations:
            e.update()
        cycle.solve()

        for f in cycle.flows:  # TODO - Has to solve the flows manually again
            f.solve()

        for e in cycle._equations:
            e.update()
        cycle.solve()

        self.CompareResults(state_2, {'h': 254.45}, 2)
        self.CompareResults(state_4, {'h': 3116.1, 's': 6.7450}, 2)
        self.CompareResults(state_5, {'h': 2851.9}, 2)
        self.CompareResults(state_6, {'h': 2221.7, 'x': 0.8357}, 2)
        self.CompareResults(state_7, {'h': 762.51, 'T': 179.9}, 2)
        self.CompareResults(flow_b, {'massFF': 0.2437}, 2)

        self.assertTrue(isWithin(cycle.sHeat, 2, '%', 2353))
        self.assertTrue(isWithin(cycle.net_sPower, 2, '%', 737.8))
        self.assertTrue(isWithin(cycle.efficiency, 1, '%', 0.3136))

        pass
예제 #14
0
    def test_subcLiq_03(self):
        # From MECH2201 - A9 Q3 - state 4

        s3 = fullyDefine_StatePure(StatePure(P=6, x=0), water_mpDF)
        s4 = fullyDefine_StatePure(StatePure(P=150, s=s3.s), water_mpDF)

        s4_h_alt = 151.67  # manua calculation with vdp
        self.assertTrue(isWithin(s4.h, 3, '%', s4_h_alt))

        s5 = fullyDefine_StatePure(StatePure(P=150, x=0), water_mpDF)
        s6 = fullyDefine_StatePure(StatePure(P=12000, s=s5.s), water_mpDF)

        s6_h_alt = 479.59
        self.assertTrue(isWithin(s6.h, 3, '%', s6_h_alt))
예제 #15
0
    def test_satLiq_02(self):
        # From MECH2201 - A9 Q2 - state 7

        statePropt = {'P': 200, 'x': 0}
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)
        expected_h = 504.7
        expected_mu = 0.001061
        self.assertTrue(isWithin(testState.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState.h))

        self.assertTrue(isWithin(testState.mu, 3, '%', expected_mu))
        print('Expected: {0}'.format(expected_mu))
        print('Received: {0}'.format(testState.mu))
예제 #16
0
    def test_flows_water_05(self):
        # CENGEL P10-53

        flow_a = Flow(workingFluid=water)
        flow_a.massFF = 1
        flow_a.items = [
            ofwh := MixingChamber(), state_03 := StatePure(x=0), pump2 :=
            Pump(), state_04 := StatePure(), cfwh := HeatExchanger(), state_05
            := StatePure(T=water.define(StatePure(x=0, P=1200)).T), boiler :=
            Boiler(), state_08 := StatePure(P=10000,
                                            T=600), turbine := Turbine()
        ]

        flow_b = Flow(water)
        flow_b.items = [
            turbine, state_09 := StatePure(P=1200), cfwh, state_06 :=
            StatePure(x=0), trap := Trap(), state_07 := StatePure(), ofwh
        ]

        flow_c = Flow(water)
        flow_c.items = [turbine, state_10 := StatePure(P=600), ofwh]

        flow_d = Flow(water)
        flow_d.items = [
            turbine, state_11 := StatePure(P=10), condenser := Condenser(),
            state_01 := StatePure(x=0), pump1 := Pump(), state_02 :=
            StatePure(), ofwh
        ]

        cycle = Cycle()
        cycle.flows = [flow_a, flow_b, flow_c, flow_d]
        cycle.netPower = 400000

        cycle.solve()

        for e in cycle._equations:
            e.update()
        cycle.solve()
        for e in cycle._equations:
            e.update()
        cycle.solve()

        self.assertTrue(isWithin(cycle.netPower / cycle.Q_in, 1, '%', 0.452))
        self.assertTrue(isWithin(cycle._get_mainFlow().massFR, 1, '%', 313))
        self.assertTrue(isWithin(flow_b.massFF, 4, '%', 0.05404))
        self.assertTrue(isWithin(flow_c.massFF, 4, '%', 0.1694))

        pass
예제 #17
0
    def test_suphVap_09(self):
        # MECH2201 A7 Q2 State 3 & 1 & 2

        statePropt = {
            'P': 50,
            'T': 100
        }  # P & T above critical values - no saturated mixture exists
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)

        expected_h = 2682.5
        expected_s = 7.6947

        self.assertTrue(isWithin(testState.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState.h))

        self.assertTrue(isWithin(testState.s, 3, '%', expected_s))
        print('Expected: {0}'.format(expected_s))
        print('Received: {0}'.format(testState.s))

        # below is state 1

        statePropt2 = {'P': 3000, 's': testState.s}
        testState2 = StatePure(**statePropt2)
        testState2 = fullyDefine_StatePure(testState2, water_mpDF)

        expected_h = 3854.1

        self.assertTrue(isWithin(testState2.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState2.h))

        self.assertTrue(testState2.x > 1)

        # below is state 2

        statePropt3 = {'P': 500, 's': testState.s}
        testState3 = StatePure(**statePropt3)
        testState3 = fullyDefine_StatePure(testState3, water_mpDF)

        expected_h = 3207.7

        self.assertTrue(isWithin(testState3.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState3.h))

        self.assertTrue(testState2.x > 1)
예제 #18
0
 def set_or_verify(self, setDict: Dict):
     for parameterName in setDict:
         if hasattr(self, parameterName):
             if not isNumeric(getattr(self, parameterName)):
                 setattr(self, parameterName, setDict[parameterName])
             else:
                 assert isWithin(getattr(self, parameterName), 3, '%', setDict[parameterName])
예제 #19
0
    def test_suphVap_02(self):
        # From MECH2201 - A9 Q1 - state 2

        statePropt = {'P': 1000, 's': 6.5966}
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)
        expected_h = 2807.3
        expected_T = 181.80

        self.assertTrue(isWithin(testState.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState.h))

        self.assertTrue(isWithin(testState.T, 3, '%', expected_T))
        print('Expected: {0}'.format(expected_T))
        print('Received: {0}'.format(testState.T))
예제 #20
0
    def test_suphVap_01(self):
        # From MECH2201 - A9 Q1 - state 1

        statePropt = {'P': 10000, 'T': 500}  # should identify as suphVap
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)
        expected_h = 3373.7
        expected_s = 6.5966

        self.assertTrue(isWithin(testState.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState.h))

        self.assertTrue(isWithin(testState.s, 3, '%', expected_s))
        print('Expected: {0}'.format(expected_s))
        print('Received: {0}'.format(testState.s))
예제 #21
0
    def test_satMix_03(self):
        # From MECH2201 - A9 Q1 - state 4

        statePropt = {'P': 10, 'x': 0.9483}
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)
        expected_s = 7.7622
        expected_h = 2460.9

        self.assertTrue(isWithin(testState.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState.h))

        self.assertTrue(isWithin(testState.s, 3, '%', expected_s))
        print('Expected: {0}'.format(expected_s))
        print('Received: {0}'.format(testState.s))
예제 #22
0
    def test_suphVap_06(self):
        # From MECH2201 - A9 Q3 - state 1

        statePropt = {'P': 12000, 'T': 500}
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)
        expected_h = 3347.7
        expected_s = 6.4855

        self.assertTrue(isWithin(testState.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState.h))

        self.assertTrue(isWithin(testState.s, 3, '%', expected_s))
        print('Expected: {0}'.format(expected_s))
        print('Received: {0}'.format(testState.s))
예제 #23
0
 def CompareResults(self, testState: StatePure, expected: Dict, ptolerance: Union[float, int]):
     print('\n')
     for parameter in expected:
         assert hasattr(testState, parameter)
         self.assertTrue(isWithin(getattr(testState, parameter), ptolerance, '%', expected[parameter]))
         print('Expected: {0}'.format(expected[parameter]))
         print('Received: {0}'.format(getattr(testState, parameter)))
예제 #24
0
    def test_satMix_05(self):
        # From MECH2201 - A9 Q3 - state 11

        statePropt = {'P': 150, 's': 6.4855}
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)
        expected_h = 2409.99
        expected_x = 0.8725

        self.assertTrue(isWithin(testState.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState.h))

        self.assertTrue(isWithin(testState.x, 3, '%', expected_x))
        print('Expected: {0}'.format(expected_x))
        print('Received: {0}'.format(testState.x))
예제 #25
0
    def test_satMix_07(self):
        # From MECH2201 - A7 Q3 - state 2

        statePropt = {'P': 100, 'u': 2217.4}
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)
        expected_s = 6.5236
        expected_x = 0.862

        self.assertTrue(isWithin(testState.s, 3, '%', expected_s))
        print('Expected: {0}'.format(expected_s))
        print('Received: {0}'.format(testState.s))

        self.assertTrue(isWithin(testState.x, 3, '%', expected_x))
        print('Expected: {0}'.format(expected_x))
        print('Received: {0}'.format(testState.x))
예제 #26
0
    def test_flows_water_07(self):
        # CENGEL P10-55

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.items = [
            ofwh := MixingChamber(), state_03 := StatePure(x=0), pump2 :=
            Pump(), state_04 := StatePure(), rhboiler := ReheatBoiler(),
            state_05 := StatePure(P=10000, T=550), turba := Turbine(), state_06
            := StatePure(P=800)
        ]

        flow_b = Flow(water)
        flow_b.items = [
            state_06, rhboiler, state_07 := StatePure(T=500), turbineb :=
            Turbine(), state_08 := StatePure(P=10), condenser := Condenser(),
            state_01 := StatePure(x=0), pump1 := Pump(), state_02 :=
            StatePure(), ofwh
        ]

        flow_c = Flow(water)
        flow_c.items = [state_06, ofwh]

        cycle = Cycle()
        cycle.flows = [flow_a, flow_b, flow_c]
        cycle.netPower = 80000

        cycle.solve()

        for e in cycle._equations:
            e.update()
        cycle.solve()

        self.CompareResults(state_02, {'h': 192.61}, 2)
        self.CompareResults(state_03, {'h': 720.87, 'mu': 0.001115}, 2)
        self.CompareResults(state_04, {'h': 731.12}, 2)
        self.CompareResults(state_05, {'h': 3502, 's': 6.7585}, 2)
        self.CompareResults(state_06, {'h': 2812.1}, 2)
        self.CompareResults(state_07, {'h': 3481.3, 's': 7.8692}, 2)
        self.CompareResults(state_08, {'h': 2494.7, 'x': 0.9627}, 2)

        self.CompareResults(flow_c, {'massFF': 0.2017}, 2)

        self.assertTrue(isWithin(flow_a.massFR, 2, '%', 54.5))
        self.assertTrue(isWithin(cycle.netPower / cycle.Q_in, 2, '%', 0.444))

        pass
예제 #27
0
    def test_suphVap_07(self):
        # No saturated state exists at the P&T

        statePropt = {'P': 30000, 'T': 375}  # P & T above critical values - no saturated mixture exists
        testState = StatePure(**statePropt)
        testState = fullyDefine_StatePure(testState, water_mpDF)

        expected_h = 1791.9
        expected_s = 3.9313

        self.assertTrue(isWithin(testState.h, 3, '%', expected_h))
        print('Expected: {0}'.format(expected_h))
        print('Received: {0}'.format(testState.h))

        self.assertTrue(isWithin(testState.s, 3, '%', expected_s))
        print('Expected: {0}'.format(expected_s))
        print('Received: {0}'.format(testState.s))
예제 #28
0
def get_saturationProperties(materialPropertyDF: DataFrame, P: Union[float, int] = float('nan'), T: Union[float, int] = float('nan')) -> Tuple[StatePure, StatePure]:
    """Returns saturated liquid and vapor states at the provided pressure or temperature for the material whose materialPropertyDF is provided."""
    # at least the T or P must be provided

    if isNumeric(P):

        satLiq_atP = materialPropertyDF.query('P == {0} and x == 0'.format(P))
        if satLiq_atP.empty:
            # exact state (saturated liquid at P - state denoted "_f") not found
            satLiq_atP = interpolate_onSaturationCurve(materialPropertyDF, interpolate_by='P', interpolate_at=P, endpoint='f')
            materialPropertyDF.append(satLiq_atP.get_asDict_allProperties(), ignore_index=True)  # append the calculated (interpolated) state to materialProperty table for future use in runtime if needed - won't have to interpolate again
        else:
            # if query found direct match (saturated liquid state at pressure), convert DFRow to a StatePure object
            satLiq_atP = StatePure().init_fromDFRow(satLiq_atP)

        satVap_atP = materialPropertyDF.query('P == {0} and x == 1'.format(P))
        if satVap_atP.empty:
            # exact state (saturated vapor at P - state denoted "_g") not found
            satVap_atP = interpolate_onSaturationCurve(materialPropertyDF, interpolate_by='P', interpolate_at=P, endpoint='g')
            materialPropertyDF.append(satVap_atP.get_asDict_allProperties(), ignore_index=True)  # append the calculated (interpolated) state to materialProperty table for future use in runtime if needed - won't have to interpolate again
        else:
            # if query found direct match (saturated vapor state at pressure), convert DFRow to a StatePure object
            satVap_atP = StatePure().init_fromDFRow(satVap_atP)

        assert satLiq_atP.isFullyDefined() and satVap_atP.isFullyDefined()
        assert satLiq_atP.x == 0 and satVap_atP.x == 1
        assert satLiq_atP.T == satVap_atP.T

        if isNumeric(T):
            assert isWithin(satLiq_atP.T, 3, '%', T), 'InputError: Provided saturation temperature and pressure do not match.'

        return satLiq_atP, satVap_atP

    elif isNumeric(T):

        satLiq_atT = materialPropertyDF.query('T == {0} and x == 0'.format(T))
        if satLiq_atT.empty:
            # exact state (saturated liquid at T - state denoted "_f") not found
            satLiq_atT = interpolate_onSaturationCurve(materialPropertyDF, interpolate_by='T', interpolate_at=T, endpoint='f')
            materialPropertyDF.append(satLiq_atT.get_asDict_allProperties(), ignore_index=True)  # append the calculated (interpolated) state to materialProperty table for future use in runtime if needed - won't have to interpolate again
        else:
            # if query found direct match (saturated liquid state at pressure), convert DFRow to a StatePure object
            satLiq_atT = StatePure().init_fromDFRow(satLiq_atT)

        satVap_atT = materialPropertyDF.query('T == {0} and x == 1'.format(T))
        if satVap_atT.empty:
            # exact state (saturated vapor at T - state denoted "_g") not found
            satVap_atT = interpolate_onSaturationCurve(materialPropertyDF, interpolate_by='T', interpolate_at=T, endpoint='g')
            materialPropertyDF.append(satVap_atT.get_asDict_allProperties(), ignore_index=True)  # append the calculated (interpolated) state to materialProperty table for future use in runtime if needed - won't have to interpolate again
        else:
            # if query found direct match (saturated vapor state at pressure), convert DFRow to a StatePure object
            satVap_atT = StatePure().init_fromDFRow(satVap_atT)

        assert satLiq_atT.isFullyDefined() and satVap_atT.isFullyDefined()
        assert satLiq_atT.x == 0 and satVap_atT.x == 1

        return satLiq_atT, satVap_atT
예제 #29
0
 def set_or_verify(self, setDict: Dict, percentDifference: float = 3):
     for parameterName in setDict:
         if parameterName in self._properties_all:
             if not self.hasDefined(parameterName):
                 setattr(self, parameterName, setDict[parameterName])
             else:
                 assert isWithin(getattr(self,
                                         parameterName), percentDifference,
                                 '%', setDict[parameterName])
예제 #30
0
    def test_flows_water_13(self):
        # CENGEL P10-46

        flow_a = Flow(water)
        flow_a.massFF = 1
        flow_a.items = [
            mixc := MixingChamber(), state_4 := StatePure(), boiler :=
            Boiler(), state_5 := StatePure(P=6000,
                                           T=450), turbine := Turbine()
        ]

        flow_b = Flow(water)
        flow_b.items = [
            turbine, state_6 := StatePure(P=400), cfwh := HeatExchanger(),
            state_3 := StatePure(x=0), pump2 := Pump(), state_9 := StatePure(),
            mixc
        ]

        flow_c = Flow(water)
        flow_c.items = [
            turbine, state_7 := StatePure(), condenser := Condenser(), state_1
            := StatePure(x=0, P=20), pump1 := Pump(), state_2 := StatePure(),
            cfwh, state_8 := StatePure(), mixc
        ]

        # assuming h8 = h9 = h4 - 8 & 9 have same pressure. determine 8's h by vdp (determine out of nowhere)

        cycle = Cycle()
        cycle.flows = [flow_a, flow_b, flow_c]
        cycle.solve()

        wtot = 0
        for f in cycle.flows:
            wtot += f.massFF * f.get_net_sWorkExtracted()

        qtot = 0
        for f in cycle.flows:
            qtot += f.massFF * f.get_sHeatSupplied()

        self.assertTrue(isWithin(wtot, 1, '%', 1016.8))
        self.assertTrue(isWithin(wtot / qtot, 1, '%', 0.378))

        pass