Exemplo n.º 1
0
 def consistencyCheckP4(self, state):
     """
     This consistency rule checks that the voltage and current at the start of a line is the same as at the end.
     :param state: State object (observed or calculated)
     :return: True if consistency rule holds, False otherwise (violation)
     """
     logCheckDescription("P4", indentation=3)
     passed = True
     for l in self.getAllConnectedLines():
         try:
             localVoltage = l.retrieveValue(state, self, "local", "voltage")
             localCurrent = l.retrieveValue(state, self, "local", "current")
             remoteVoltage = l.retrieveValue(state, self, "remote",
                                             "voltage")
             remoteCurrent = l.retrieveValue(state, self, "remote",
                                             "current")
             currentPassed = isClose(localVoltage,
                                     remoteVoltage) and isClose(
                                         localCurrent, remoteCurrent)
             passed = False if not currentPassed else passed
             logDebugCheckValues(
                 "Line %s. Local: V=%f,A=%f (==) Remote: V=%f,A=%f." %
                 (l.name, localVoltage, localCurrent, remoteVoltage,
                  remoteCurrent),
                 currentPassed,
                 indentation=3)
         except ValueNotStoredException, e:
             logDebugUnknownValues(e.message, l.name, indentation=3)
Exemplo n.º 2
0
 def consistencyCheckP2(self, state):
     """
     This consistency rule checks whether the voltage equals on all meters of a bus.
     Meters with V=0 are excluded as they might be disconnected.
     :param state: State object (observed or calculated)
     :return: True if consistency rule holds, False otherwise (violation)
     """
     logCheckDescription("P2", indentation=3)
     passed = True
     try:
         # check if all measured voltages on bus are approximately equal (or 0 V)
         allMeasuredVoltages = [
             l.retrieveValue(state, self, "local", "voltage")
             for l in self.getAllConnectedLines()
         ]
         relevantMeasuredVoltages = [
             v for v in allMeasuredVoltages if not isClose(v, 0.00)
         ]
         passed = isClose(min(relevantMeasuredVoltages),
                          max(relevantMeasuredVoltages))
         logDebugCheckValues(
             "Minimum V: %f (==) Maximum V: %f." %
             (min(relevantMeasuredVoltages), max(relevantMeasuredVoltages)),
             passed,
             indentation=3)
     except ValueNotStoredException, e:
         logDebugUnknownValues(e.message, indentation=3)
Exemplo n.º 3
0
 def consistencyCheckP1(self, state):
     """
     This consistency rule checks whether Kirchhoff's current law holds at the bus.
     :param state: State object (observed or calculated)
     :return: True if consistency rule holds, False otherwise (violation)
     """
     logCheckDescription("P1", indentation=3)
     passed = True
     try:
         # compare sum of ingoing current with sum of outgoing current
         sumOfIngoingCurrent = sum([
             l.retrieveValue(state, self, "local", "current")
             for l in self.linesIn
         ])
         sumOfOutgoingCurrent = sum([
             l.retrieveValue(state, self, "local", "current")
             for l in self.linesOut
         ])
         passed = isClose(sumOfIngoingCurrent, sumOfOutgoingCurrent)
         logDebugCheckValues(
             "Ingoing current: %f (==) Outgoing current: %f." %
             (sumOfIngoingCurrent, sumOfOutgoingCurrent),
             passed,
             indentation=3)
     except ValueNotStoredException, e:
         logDebugUnknownValues(e.message, indentation=3)
Exemplo n.º 4
0
 def consistencyCheckP6b(self, state):
     """
     This consistency rule checks whether the transformation rate is consistent with the current measurement.
     :param state: State object (observed or calculated)
     :return: True if consistency rule holds, False otherwise (violation)
     """
     logCheckDescription("P6b", indentation=3)
     passed = True
     if callable(self.rateFunction):
         try:
             measuredInCurrent = self.linesIn[0].retrieveValue(
                 state, self, "local", "current")
             measuredOutCurrent = self.linesOut[0].retrieveValue(
                 state, self, "local", "current")
             currentTapPosition = state.retrieveValue(self.tapPositionKey)
             if isZero(measuredInCurrent):
                 passed = True
                 logDebugCheckValues(
                     "Transformer %s. No incoming or outgoing current." %
                     (self.name),
                     passed,
                     indentation=3)
             else:
                 try:
                     currentTransformerRate = self.rateFunction(
                         currentTapPosition)
                     expectedMeasuredTransformedOutCurrent = measuredInCurrent * float(
                         currentTransformerRate)
                     if isClose(expectedMeasuredTransformedOutCurrent,
                                measuredOutCurrent):
                         passed = True
                     else:
                         passed = False
                     logDebugCheckValues(
                         "Transformer %s. Measured input current: %fA. Measured output current: %fA. Expected output current: %fA."
                         %
                         (self.name, measuredInCurrent, measuredOutCurrent,
                          expectedMeasuredTransformedOutCurrent),
                         passed,
                         indentation=3)
                 except IndexError:
                     passed = False
                     logDebugCheckValues(
                         "Transformer %s. Discrete tap function, tap position %d has no rate defined."
                         % (self.name, int(round(currentTapPosition))),
                         passed,
                         indentation=3)
                 except ZeroDivisionError:
                     passed = False
                     logDebugCheckValues(
                         "Transformer %s. Measured input current: %fA. Measured output current: %fA. (Division by zero, not consistent)."
                         %
                         (self.name, measuredInCurrent, measuredOutCurrent),
                         passed,
                         indentation=3)
         except ValueNotStoredException, e:
             passed = True
             logDebugUnknownValues(e.message, indentation=3)
Exemplo n.º 5
0
 def consistencyCheckP6a(self, state):
     """
     This consistency rule checks whether the transformation rate is consistent with the voltage measurement.
     :param state: State object (observed or calculated)
     :return: True if consistency rule holds, False otherwise (violation)
     """
     logCheckDescription("P6a", indentation=3)
     passed = True
     if callable(self.rateFunction):
         try:
             measuredInVoltage = self.linesIn[0].retrieveValue(
                 state, self, "local", "voltage")
             measuredOutVoltage = self.linesOut[0].retrieveValue(
                 state, self, "local", "voltage")
             currentTapPosition = state.retrieveValue(self.tapPositionKey)
             if isZero(measuredOutVoltage):
                 passed = True
                 logDebugCheckValues(
                     "Transformer %s. Measured input voltage: %fV. Measured output voltage: %fV. Output voltage zero!"
                     % (self.name, measuredInVoltage, measuredOutVoltage),
                     passed,
                     indentation=3)
             else:
                 try:
                     currentTransformerRate = self.rateFunction(
                         currentTapPosition)
                     expectedMeasuredTransformedOutVoltage = measuredInVoltage / float(
                         currentTransformerRate)
                     if isClose(expectedMeasuredTransformedOutVoltage,
                                measuredOutVoltage):
                         passed = True
                     else:
                         passed = False
                     logDebugCheckValues(
                         "Transformer %s. Measured input voltage: %fV. Measured output voltage: %fV. Expected output voltage: %fV."
                         %
                         (self.name, measuredInVoltage, measuredOutVoltage,
                          expectedMeasuredTransformedOutVoltage),
                         passed,
                         indentation=3)
                 except IndexError:
                     passed = False
                     logDebugCheckValues(
                         "Transformer %s. Discrete tap function, tap position %d has no rate defined. "
                         % (self.name, int(round(currentTapPosition))),
                         passed,
                         indentation=3)
         except ValueNotStoredException, e:
             passed = True
             logDebugUnknownValues(e.message, indentation=3)
Exemplo n.º 6
0
 def safetyCheckR7(self, state):
     """
     This safety rule checks whether the global generated power equals the global consumed power
     :param state: State object (observed or calculated)
     :return: True if safety rule holds, False otherwise (violation)
     """
     logCheckDescription("R7", indentation=2)
     passed = True
     try:
         sumOfGeneratedPower = sum(
             [state.retrieveValue(g.generatedPowerKey) for g in getAllComponentsOfType(Generator)])
         sumOfConsumedPower = (-1) * sum(
             [state.retrieveValue(c.consumedPowerKey) for c in getAllComponentsOfType(Consumer)])
         passed = isClose(sumOfGeneratedPower, sumOfConsumedPower)
         logDebugCheckValues("Global Generated power: %f (==) Global Consumed power: %f." % (sumOfGeneratedPower, sumOfConsumedPower), passed, indentation=3)
     except ValueNotStoredException, e:
         logDebugUnknownValues(e.message, indentation=3)
Exemplo n.º 7
0
 def consistencyCheckP5b(self, state):
     """
     This consistency rule checks whether P = I * V holds for the consumer.
     :param state: State object (observed or calculated)
     :return: True if consistency rule holds, False otherwise (violation)
     """
     logCheckDescription("P5b", indentation=3)
     passed = True
     try:
         l = self.linesIn[0]
         localVoltage = l.retrieveValue(state, self, "local", "voltage")
         localCurrent = l.retrieveValue(state, self, "local", "current")
         calculatedPower = localVoltage * localCurrent
         consumedPower = (-1) * state.retrieveValue(self.consumedPowerKey)
         passed = isClose(calculatedPower, consumedPower)
         logDebugCheckValues("Consumer %s. V=%f,A=%f. V*A=%f (==) P=%f." %
                             (self.name, localVoltage, localCurrent,
                              calculatedPower, consumedPower),
                             passed,
                             indentation=3)
     except ValueNotStoredException, e:
         logDebugUnknownValues(e.message, indentation=3)