Esempio n. 1
0
    def _set_params_for_two_blocks(self, model, block, iconn, ics,
                                   blockNumber, firstIndex):
        '''Only for one block in pair.'''
        # choice side:
        if (iconn.block1 == blockNumber
            and iconn.block2 != blockNumber):
            # case differ 1
            side_num = iconn.block1Side
        elif (iconn.block2 == blockNumber
              and iconn.block1 != blockNumber):
            # case differ 2
            side_num = iconn.block2Side

        # len(ics for block)
        # firstIndex = len(ics)

        # FOR find equation for block
        Range = (side_num == 1) * block.size.sizeX
        coord = lambda region: ((side_num == 0) * region.xfrom
                                + (side_num == 1) * region.xto)
        side_test = lambda eRegion: coord(eRegion) == Range
        equationNum = self.choice_equation_num(side_test, block)

        equation = model.equations[equationNum].copy()
        # END FOR

        funcName = ("Block" + str(blockNumber)
                    + "Interconnect__Side" + str(side_num)
                    + "_Eqn" + str(equationNum))

        # generate equation:
        parsedValues = self.parse_equations(equation, model.dimension,
                                            blockNumber, side_num,
                                            firstIndex, 0)
        # fill params:
        ic = Params()
        ic.name = "Connection"
        ic.firstIndex = firstIndex
        ic.secondIndex = '0'
        ic.side_num = side_num
        ic.ranges = []
        ic.equationNumber = equationNum
        ic.equation = equation
        ic.funcName = funcName
        ic.boundName = determineNameOfBoundary(side_num)
        ic.blockNumber = blockNumber
        ic.parsedValues = parsedValues
        ic.original = [e.sent for e in equation.eqs]
        
        # each block can connect to many other block
        # let other block discribe interconnect in
        # that case
        return(ic)
Esempio n. 2
0
    def _set_params_for_closed_block(self, model, block, iconn,
                                     blockNumber, srcFirstIndex,
                                     distFirstIndex):

        '''srcFirstIndex and distFirstIndex is first indexes of
        two interconects of same block'''

        # FOR finding equations:
        # choice left or right side of block
        # i.e. 0.0 or block.sizeX
        Range1 = (iconn.block1Side == 1) * block.size.sizeX
        Range2 = (iconn.block2Side == 1) * block.size.sizeX

        # return either xfrom or xto for block
        coord1 = lambda region: ((iconn.block1Side == 0)
                                 * region.xfrom
                                 + (iconn.block1Side == 1)
                                 * region.xto)
        coord2 = lambda region: ((iconn.block2Side == 0)
                                 * region.xfrom
                                 + (iconn.block2Side == 1)
                                 * region.xto)

        # find equation
        # for first block (one side of closed block)
        side_test = lambda eRegion: coord1(eRegion) == Range1
        equationNum1 = self.choice_equation_num(side_test, block)

        # find equation
        # for second block (other side of closed block)
        side_test = lambda eRegion: coord2(eRegion) == Range2
        equationNum2 = self.choice_equation_num(side_test, block)

        equation1 = model.equations[equationNum1].copy()
        equation2 = model.equations[equationNum2].copy()
        # END FOR

        funcName1 = ("Block" + str(blockNumber)
                     + "Interconnect__Side"
                     + str(iconn.block1Side)
                     + "_Eqn" + str(equationNum1))
        funcName2 = ("Block" + str(blockNumber)
                     + "Interconnect__Side"
                     + str(iconn.block2Side)
                     + "_Eqn" + str(equationNum2))

        # FOR equatioin cpp:
        # first equation:
        parsedValues_1 = self.parse_equations(equation1, model.dimension,
                                              blockNumber, iconn.block1Side,
                                              1, 0)

        # second equation:
        parsedValues_2 = self.parse_equations(equation2, model.dimension,
                                              blockNumber, iconn.block2Side,
                                              0, 0)
        # END FOR

        # fill params:
        ic1 = Params()
        ic1.name = "Connection"
        ic1.firstIndex = srcFirstIndex
        ic1.secondIndex = '0'
        ic1.side_num = iconn.block1Side
        ic1.ranges = []
        ic1.equationNumber = equationNum1
        ic1.equation = equation1
        ic1.funcName = funcName1
        ic1.parsedValues = parsedValues_1
        ic1.original = [e.sent for e in equation1.eqs]
        ic1.boundName = determineNameOfBoundary(iconn.block1Side)
        ic1.blockNumber = blockNumber
        
        ic2 = Params()
        ic2.name = "Connection"
        ic2.firstIndex = distFirstIndex
        ic2.secondIndex = '0'
        ic2.side_num = iconn.block2Side
        ic2.ranges = []
        ic2.equationNumber = equationNum2
        ic2.equation = equation2
        ic2.funcName = funcName2
        ic2.parsedValues = parsedValues_2
        ic2.original = [e.sent for e in equation2.eqs]
        ic2.boundName = determineNameOfBoundary(iconn.block2Side)
        ic2.blockNumber = blockNumber

        return((ic1, ic2))
Esempio n. 3
0
    def make_region(self, mainBlockSide, mainBlock, secondBlock,
                    region_num, firstIndex):
        
        '''Make some data for each block in ic.
        
        First it's find side and intervals, in which
        ic to be used. For interval it used ``Interval``
        object with bound and equation numbers set to
        ``None`` (i.e. ``name={'b': None, 'e': None}``).

        Change ``side.intervals`` to add ic intervals
        to it (i.e. first split ic interval at bouds/eq
        regions, then split all ``side.intervals`` at
        that ic_interval).

        Also It create ranges that is rectangle
        ``[xfrom, xto, yfrom, yto]`` where all in cell sizes.

        interval, xfrom, xto, yfrom, yto, lenOfConnection,
        beforeStartLen, ranges is all inteconnect data,
        relative to mainBlock.
        
        It also add first index of current inteconnect
        for created region and increase it global value
        (stored in ``model._ics_firstIndex``)

        It create ``secondIndex`` which is index to be
        used by ``mainBlock`` in order to get according
        ``ics`` data for according side coordinate.

        (ex (what ``secondIndex`` used for):
        
           secondIndex: ic[firstIndex][secondIndex] for mainBlock
              where ic is inteconnects array,
                 firstIndex is index of ic mainBlock and secondBlock
                 secondIndex according mainBlock side (see ex below))

        (ex (how ``secondIndex`` created for side 2 or 3):

           secondIndex = idxX - to_cell(lenBSBSSC)
              where lenBSBSSC is len between start of block side
                 and start of connection)

        Tests:

        >>> from envs.hs.model.model_main import ModelNet as Model
        >>> m = Model()
        >>> m.io.loadFromFile('problems/2dTests/tests_2d_two_blocks0')
        >>> ic = m.interconnects[0]
        >>> icr = ic.regions[1]
        >>> icr.ranges
        [0, 301, 0, 1]

        >>> icr = ic.regions[2]
        >>> icr.ranges
        [150, 451, 700, 701]
        '''

        grid = self.net.model.grid
        den = mainBlock.defaultEquation

        if mainBlockSide == 0:

            xfrom = 0  # mainBlock.size.offsetX
            xto = 0  # mainBlock.size.offsetX
            yfrom = (max([secondBlock.size.offsetY, mainBlock.size.offsetY])
                     - mainBlock.size.offsetY)
            yto = (min([mainBlock.size.offsetY + mainBlock.size.sizeY,
                        secondBlock.size.offsetY + secondBlock.size.sizeY])
                   - mainBlock.size.offsetY)
            interval = Interval([yfrom, yto])

            beforeStartLen = yfrom
            lenOfConnection = yto - yfrom
            sideIndex = 'idxY'
            stepAlongSide = grid.gridStepY

        elif mainBlockSide == 1:

            xfrom = mainBlock.size.sizeX  # + mainBlock.size.offsetX
            xto = mainBlock.size.sizeX  # + mainBlock.size.offsetX
            yfrom = (max([secondBlock.size.offsetY, mainBlock.size.offsetY])
                     - mainBlock.size.offsetY)
            yto = (min([mainBlock.size.offsetY + mainBlock.size.sizeY,
                        secondBlock.size.offsetY + secondBlock.size.sizeY])
                   - mainBlock.size.offsetY)
            interval = Interval([yfrom, yto])

            beforeStartLen = yfrom
            lenOfConnection = yto - yfrom
            sideIndex = 'idxY'
            stepAlongSide = grid.gridStepY

        elif mainBlockSide == 2:

            xfrom = (max([mainBlock.size.offsetX, secondBlock.size.offsetX])
                     - mainBlock.size.offsetX)
            xto = (min([mainBlock.size.offsetX + mainBlock.size.sizeX,
                        secondBlock.size.offsetX + secondBlock.size.sizeX])
                   - mainBlock.size.offsetX)
            yfrom = 0  # mainBlock.size.offsetY
            yto = 0  # mainBlock.size.offsetY
            interval = Interval([xfrom, xto])

            beforeStartLen = xfrom
            lenOfConnection = xto - xfrom
            sideIndex = 'idxX'
            stepAlongSide = grid.gridStepX

        else:

            xfrom = (max([mainBlock.size.offsetX, secondBlock.size.offsetX])
                     - mainBlock.size.offsetX)
            xto = (min([mainBlock.size.offsetX + mainBlock.size.sizeX,
                        secondBlock.size.offsetX + secondBlock.size.sizeX])
                   - mainBlock.size.offsetX)
            yfrom = mainBlock.size.sizeY  # + mainBlock.size.offsetY
            yto = mainBlock.size.sizeY  # + mainBlock.size.offsetY
            interval = Interval([xfrom, xto])

            beforeStartLen = xfrom
            lenOfConnection = xto - xfrom
            sideIndex = 'idxX'
            stepAlongSide = grid.gridStepX

        # FOR collect data:
        out = Params()

        out.firstIndex = firstIndex
        # out.firstIndex = self.net.model._ics_firstIndex
        # self.net.model._ics_firstIndex += 1

        out.side_num = mainBlockSide
        # out.stepAlongSide = stepAlongSide
        # out.beforeStartLen = beforeStartLen
        
        # map: block side index -> second index of ic
        # (ex: idxX -> secondIndex where secondIndex: ic[][secondIndex]):
        startCellIndex = determineCISC2D(beforeStartLen, stepAlongSide)
        out.secondIndex = ('(' + sideIndex + ' - ' + str(startCellIndex)
                           + ') * Block' + str(mainBlock.blockNumber)
                           + 'CELLSIZE')

        out.icLen = lenOfConnection

        side = mainBlock.sides[mainBlockSide]
        logger.debug("side.intervals:")
        logger.debug(side.intervals)
        logger.debug("icr.intervals:")
        logger.debug(interval)

        # add default name:
        interval.name = {'b': None, 'e': den,
                         'i': (lambda _self=self, _region_num=region_num:
                               _self[_region_num])}
        # region_num - is global name
        # while _region_num is local name in lambda
        # that used because otherwise all regions
        # would have same region_num.
        
        # split at equation and bounds regions:
        out.intervals = interval.split_all([copy(interval)
                                            for interval in side.intervals],
                                           [])

        # add ic info into block.side:
        side.intervals = sum([i.split_all(out.intervals, [])
                              for i in side.intervals], [])
        # reset vertexs:
        mainBlock.editor.set_vertexs()

        out.xfrom = xfrom
        out.xto = xto
        out.yfrom = yfrom
        out.yto = yto
        '''
        ranges = getRangesInClosedInterval([xfrom, xto, grid.gridStepX],
                                           [yfrom, yto, grid.gridStepY])
        out.ranges = ranges
        '''
        out.blockNumber = mainBlock.blockNumber
        out.ic = self.net
        out.ic_regions = self
        # END FOR

        return(out)