Beispiel #1
0
    def get_sHeatSupplied(self, returnExpression: bool = False):
        """Returns the value of the total specific heat supplied by the HeatDevices of the flow. If returnExpression, returns the expression that gives the value when added in a LinearEquation."""
        self._sHeatSupplied = float('nan')
        expression_LHS = [(-1, (self, '_sHeatSupplied'))]

        for device in set(
                device for device in self.heatDevices
                if isinstance(device, (
                    Boiler, ReheatBoiler, Combustor,
                    GasReheater))):  # if not isinstance(device, HeatExchanger)
            expression_LHS += device.get_sHeatSuppliedExpression(
                forFlow=self, constant_c=self.constant_c)

        expression = LinearEquation(LHS=expression_LHS, RHS=0)
        expression.source = 'Flows.get_sHeatSupplied'

        if expression.isSolvable():
            assert expression.get_unknowns()[0][0] == (self, '_sHeatSupplied')
            # Linear equation is solvable if only there is only one unknown. If there is only one unknown, it must be the self._net_sWorkExtracted since we know it is unknown for sure
            result = list(expression.solve().values())[0]
            return result
        else:
            if returnExpression:
                return expression.isolate([(self, '_sHeatSupplied')])
            else:
                return float('nan')
Beispiel #2
0
 def get_sHeatSupplied(self, returnExpression: bool = False):
     self._sHeatSupplied = float('nan')
     expression_LHS = [ (-1, (self, '_sHeatSupplied')) ]
     for device in set(device for device in self.heatDevices if isinstance(device, Boiler) or isinstance(device, ReheatBoiler)):  # if not isinstance(device, HeatExchanger)
         expression_LHS += device.get_sHeatSuppliedExpression(forFlow=self)
         # expression_LHS += [ (1, (device.state_out, 'h')), (-1, (device.state_in, 'h')) ]
     expression = LinearEquation(LHS=expression_LHS, RHS=0)
     expression.source = 'Flows.get_sHeatSupplied'
     if expression.isSolvable():
         assert expression.get_unknowns()[0][0] == (self, '_sHeatSupplied')
         # Linear equation is solvable if only there is only one unknown. If there is only one unknown, it must be the self._net_sWorkExtracted since we know it is unknown for sure
         result = list(expression.solve().values())[0]
         return result
     else:
         if returnExpression:
             return expression.isolate( [(self, '_sHeatSupplied')] )
         else:
             return float('nan')
Beispiel #3
0
    def get_net_sWorkExtracted(self, returnExpression: bool = False):
        """Returns the value of the total specific work extracted by the WorkDevices of the flow. If returnExpression, returns the expression that gives the value when added in a LinearEquation."""
        self._net_sWorkExtracted = float('nan')
        expression_LHS = [(-1, (self, '_net_sWorkExtracted'))]

        for device in self.workDevices:
            stateBefore, stateAfter = self.get_surroundingItems(
                device, includeNone=True
            )  # returned list will have None values if there is no item in the spot before / after
            if stateBefore is None and isinstance(device, Turbine):
                stateBefore = device.state_in  # A turbine (commonly in steam cycles) may have multiple flows coming out of it. The state_in may not belong to the same flow as the state_out.
            if stateBefore is not None and stateAfter is not None:
                if not self.constant_c:
                    expression_LHS += [
                        (1, (stateBefore, 'h')), (-1, (stateAfter, 'h'))
                    ]  # effectively adds (h_in - h_out) to the equation
                else:  # constant c analysis
                    expression_LHS += [
                        (1, (self.workingFluid.cp), (stateBefore, 'T')),
                        (-1, (self.workingFluid.cp), (stateAfter, 'T'))
                    ]
            else:
                continue
        expression = LinearEquation(
            LHS=expression_LHS, RHS=0
        )  # -1 * self._net_sWorkExtracted + state_in.h - state_out.h = 0
        expression.source = 'Flows.get_net_sWorkExtracted'

        if expression.isSolvable():
            assert expression.get_unknowns()[0][0] == (self,
                                                       '_net_sWorkExtracted')
            # Linear equation is solvable if only there is only one unknown. If there is only one unknown, it must be the self._net_sWorkExtracted since we know it is unknown for sure
            result = list(expression.solve().values())[0]
            return result
        else:
            if returnExpression:
                return expression.isolate([(self, '_net_sWorkExtracted')])
            else:
                return float('nan')
Beispiel #4
0
    def get_net_sWorkExtracted(self, returnExpression: bool = False):
        self._net_sWorkExtracted = float('nan')
        expression_LHS = [ (-1, (self, '_net_sWorkExtracted')) ]
        for device in self.workDevices:
            stateBefore, stateAfter = self.get_surroundingItems(device, includeNone=True)  # returned list will have None values if there is no item in the spot before / after
            if stateBefore is None and isinstance(device, Turbine):
                stateBefore = device.state_in
            if stateBefore is not None and stateAfter is not None:
                expression_LHS += [ (1, (stateBefore, 'h')) , (-1, (stateAfter, 'h')) ]  # effectively adds (h_in - h_out) to the equation
            else:
                continue
        expression = LinearEquation(LHS=expression_LHS, RHS=0)  # -1 * self._net_sWorkExtracted + state_in.h - state_out.h = 0
        expression.source = 'Flows.get_net_sWorkExtracted'

        if expression.isSolvable():
            assert expression.get_unknowns()[0][0] == (self, '_net_sWorkExtracted')
            # Linear equation is solvable if only there is only one unknown. If there is only one unknown, it must be the self._net_sWorkExtracted since we know it is unknown for sure
            result = list(expression.solve().values())[0]
            return result
        else:
            if returnExpression:
                return expression.isolate( [(self, '_net_sWorkExtracted')] )
            else:
                return float('nan')