Ejemplo n.º 1
0
    def get_pump_energy_usage_statistics(self):
        """ Read pump energy usage statistics for all pumps.
            Returns: dictionary (keyed by each pump's link name) of PumpEnergy instances """
        all_pump_energy = {}
        pump_count = self._call_int(_lib.ENR_getNetSize, _lib.ENR_pumpCount)
        if pump_count:
            link_index_return = c_int()
            returned_length = c_int()
            error_new = c_int()
            array_pointer = _lib.ENR_newOutValueArray(self.ptrapi,
                                                      _lib.ENR_getEnergy,
                                                      _lib.ENR_link,
                                                      byref(returned_length),
                                                      byref(error_new))
            if error_new.value != 0:
                print("Error " + str(error_new.value) +
                      " calling ENR_newOutValueArray for getEnergy")
                self._raise_error(error_new.value)

            for pump_index in range(1, pump_count + 1):
                self.call(_lib.ENR_getEnergyUsage, pump_index,
                          byref(link_index_return), array_pointer)
                link_index = link_index_return.value
                for link in self.links.itervalues():
                    if link.index == link_index:
                        all_pump_energy[link.name] = PumpEnergy(
                            link.name, array_pointer[1], array_pointer[2],
                            array_pointer[3], array_pointer[4],
                            array_pointer[5], array_pointer[6])
                        break
            _lib.ENR_free(array_pointer)
        return all_pump_energy
Ejemplo n.º 2
0
    def get_attribute_for_all_at_time(cls, output, attribute, time_index):
        """ Purpose: For all items of this type (nodes or links) at given time, get a particular attribute.
            Args
            output: OutputObject that already has the desired output file open.
            attribute: attribute to get values of - must be an ENR_attribute from self.Attributes.
            time_index: time index to retrieve, 0 is the first time index.
            Examples
            for node in output.nodes:
                values = node.get_all_attributes_at_time(output, time_index)
                for attribute in (node.AttributeDemand, node.AttributeHead):
                    print(attribute.name, attribute.str(values[attribute.index]))

        """
        returned_length = c_int()
        error_new = c_int()
        array_pointer = _lib.ENR_newOutValueArray(output.ptrapi,
                                                  _lib.ENR_getAttribute,
                                                  cls._elementType,
                                                  byref(returned_length),
                                                  byref(error_new))
        if error_new.value != 0:
            print("Error " + str(error_new.value) +
                  " calling ENR_newOutValueArray for " + cls.TypeLabel)
            output._raise_error(error_new.value)

        error_get = cls._get_attribute(output.ptrapi, time_index,
                                       attribute.index, array_pointer)
        if error_get != 0:
            print("Error reading " + str(attribute.name) + " for all " +
                  cls.TypeLabel + "s at " + str(time_index))
            output._raise_error(error_get)

        BldArray = [array_pointer[i] for i in range(returned_length.value)]
        _lib.ENR_free(array_pointer)
        return BldArray
 def get_LinkResult(self, LinkInd, TimeInd):
     """
     Purpose: For a link at given time, get all attributes
     """
     alength = c_int()
     ErrNo1 = c_int()
     ValArrayPtr = _lib.ENR_newOutValueArray(self.enrapi,
                                             _lib.ENR_getResult,
                                             _lib.ENR_link, byref(alength),
                                             byref(ErrNo1))
     ErrNo2 = _lib.ENR_getLinkResult(self.enrapi, TimeInd, LinkInd,
                                     ValArrayPtr)
     BldArray = [ValArrayPtr[i] for i in range(alength.value)]
     _lib.ENR_free(ValArrayPtr)
     return BldArray
 def get_LinkAttribute(self, LinkAttr, TimeInd):
     """
     Purpose: For all links at given time, get a particular attribute
     """
     alength = c_int()
     ErrNo1 = c_int()
     ValArrayPtr = _lib.ENR_newOutValueArray(self.enrapi,
                                             _lib.ENR_getAttribute,
                                             _lib.ENR_link, byref(alength),
                                             byref(ErrNo1))
     ErrNo2 = _lib.ENR_getLinkAttribute(self.enrapi, TimeInd, LinkAttr,
                                        ValArrayPtr)
     BldArray = [ValArrayPtr[i] for i in range(alength.value)]
     _lib.ENR_free(ValArrayPtr)
     return BldArray
Ejemplo n.º 5
0
    def get_reaction_summary(self):
        """ Read reaction summary (network-wide average reaction rates and average source mass inflow)
            Returns: four floating-point numbers: bulk, wall, tank, source """
        returned_length = c_int()
        error_new = c_int()
        array_pointer = _lib.ENR_newOutValueArray(self.ptrapi,
                                                  _lib.ENR_getReacts,
                                                  _lib.ENR_link,
                                                  byref(returned_length),
                                                  byref(error_new))
        if error_new.value != 0:
            print("Error " + str(error_new.value) +
                  " calling ENR_newOutValueArray for getReacts")
            self._raise_error(error_new.value)

        self.call(_lib.ENR_getNetReacts, array_pointer)
        bulk = array_pointer[1]
        wall = array_pointer[2]
        tank = array_pointer[3]
        source = array_pointer[4]
        _lib.ENR_free(array_pointer)
        return bulk, wall, tank, source
Ejemplo n.º 6
0
    def get_all_attributes_at_time(self, output, time_index):
        """
        For one location at one time, get all attributes.

        Returns: List of attribute values in the same order as self.attributes.

        Examples

        output = ENOutputWrapper.OutputObject("Net1.out")
        for time_index in range(0, output.num_periods):
            for node in output.nodes:
                attribute_values = node.get_all_attributes_at_time(output, time_index)
                for value, definition in zip(attribute_values, node.attributes):
                    print("At node " + node.name + ", attribute " + definition.name +
                          " has value " + str(value) + " at time step " + time_index)
        """

        returned_length = c_int()
        error_new = c_int()
        array_pointer = _lib.ENR_newOutValueArray(output.ptrapi,
                                                  _lib.ENR_getResult,
                                                  self._elementType,
                                                  byref(returned_length),
                                                  byref(error_new))
        if error_new.value != 0:
            print("Error " + str(error_new.value) +
                  " calling ENR_newOutValueArray for " + self.TypeLabel)
            output._raise_error(error_new.value)

        error_get = self._get_result(output.ptrapi, time_index, self.index,
                                     array_pointer)
        if error_get != 0:
            print("Error reading all attributes for " + self.name + " at " +
                  str(time_index))
            output._raise_error(error_get)
        BldArray = [array_pointer[i] for i in range(returned_length.value)]
        _lib.ENR_free(array_pointer)
        return BldArray