コード例 #1
0
    def set_params_for_side(self, model, side):
        
        ics = []

        for interval in side.intervals:
            
            # if no interconnect then continue:
            try:
                interval.name['i']
            except KeyError:
                continue

            equationNumber = interval.name['e']
            equation = model.equations[equationNumber].copy()
        
            icRegion = interval.name['i']()

            blockNumber = icRegion.blockNumber
            side_num = icRegion.side_num

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

            # generate equation:
            parsedValues = self.parse_equations(equation, model.dimension,
                                                blockNumber, side_num,
                                                icRegion.firstIndex,
                                                icRegion.secondIndex)
            # fill params:
            ic = Params()
            ic.name = "Connection"
            # ic.firstIndex = icRegion.firstIndex
            # ic.secondIndex = icRegion.secondIndex
            ic.side_num = side_num
            # ic.ranges = icRegion.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]

            # for functionMaps:
            interval.name['fm'] = ic

            # for cpp:
            # each block can connect to many other block
            # let other block discribe interconnect in
            # that case
            ics.append(ic)

        return(ics)
コード例 #2
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)
コード例 #3
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))
コード例 #4
0
    def make_bound_param(self, model, vertex):
        '''Fill this parameters for block bound border
        (vertex in case of 1d)::

        Collect this parameters for template:

             - ``bParams.dim``
             - ``bParams.values`` -- border_values
             - ``bParams.btype``
             - ``bParams.side_num``
             - ``bParams.boundNumber``
             - ``bParams.equationNumber``
             - ``bParams.equation`` -- system of equations
             - ``bParams.funcName``
             - ``bParams.block``
             - ``bParams.blockNumber``
             - ``bParams.boundName`` -- for comment
             - ``bParams.parsedValues``
             - ``bParams.original`` -- for comment

        This parameters also collected for dom:
    
             - ``bound.side``
             - ``bound.blockNumber``
             - ``bParams.funcName``
        '''
        block = vertex.block
        blockNumber = vertex.block.blockNumber

        # for 1d there is only one side:
        side_num = vertex.sides_nums[0]

        # find equation number for side or use default
        equationNum = vertex.equationNumber
        '''
        regsEqNums = [eqReg.equationNumber
                      for eqReg in block.equationRegions
                      if self.test(block, eqReg, side_num)]
        equationNum = (regsEqNums[0] if len(regsEqNums) > 0
                       else block.defaultEquation)
        '''
        eSystem = model.equations[equationNum].copy()

        # find bound region for side or use default
        boundNumber = vertex.boundNumber
        '''
        regionsForSide = [bRegion
                          for k in block.boundRegions
                          for bRegion in block.boundRegions[k]
                          if bRegion.side_num == side_num]
        '''

        # if exist special region for that side
        # if len(regionsForSide) > 0:
        if boundNumber is not None:
            # region = block.boundsRegions[boundNumber]
            # region = regionsForSide[0]
            # boundNumber = region.boundNumber

            bound = model.bounds[boundNumber]

            args = (model, blockNumber, side_num, boundNumber, equationNum)

            # for Dirichlet bound
            if bound.btype == 0:
                func = self.get_func_for_dirichlet(*args)

            # for Neumann bound
            elif bound.btype == 1:
                func = self.get_func_for_neumann(*args)

            funcName = func[0]
            border_values = list(func[1])
            btype = bound.btype
        else:
            # if not, use default

            args = (eSystem, blockNumber, side_num, equationNum)
            func = self.get_func_default(*args)

            funcName = func[0]
            border_values = func[1]
            btype = 1
            boundNumber = -1

        args = (eSystem, model, blockNumber, btype, side_num, border_values)
        parsed = self.parse_equations(*args)
        # print("bound bug debug:")
        # print(parsed)

        # FOR collect template data:
        bParams = Params()
        bParams.dim = model.dimension
        bParams.values = border_values
        bParams.btype = btype
        bParams.side_num = side_num
        bParams.boundNumber = boundNumber
        bParams.equationNumber = equationNum
        bParams.equation = eSystem
        bParams.funcName = funcName
        bParams.block = block
        bParams.blockNumber = blockNumber
        logger.debug("bParams.funcName")
        logger.debug(bParams.funcName)
        logger.debug("bParams.side_num")
        logger.debug(bParams.side_num)
        # in comment
        bParams.boundName = determineNameOfBoundary(side_num)
        bParams.parsedValues = parsed[0]
        bParams.border_values_parsed = parsed[1]
        bParams.original = [e.sent for e in eSystem.eqs]
        # END FOR

        vertex.fm = bParams
        return (bParams)
コード例 #5
0
    def make_bounds_for_edges(self, model, side):
        '''
        DESCRIPTION:

        Collect this parameters for template:
        
        - ``bParams.name``
        - ``bParams.side_num``
        - ``bParams.blockNumber``
        - ``bParams.boundNumber``
        - ``bParams.equationNumber``
        
        - ``bParams.funcName`` -- func name in cpp
        - ``bParams.btype`` -- Dirichlet 0, Neumann 1
        - ``bParams.equation`` -- system of equations
        SysNet object
        - ``bParams.parsedValues``
        - ``bParams.original`` -- original for comment
        - ``bParams.boundName`` -- bound name for comment

        This parameters also collected for dom:
        
        - ``bParams.blockNumber``
        - ``bParams.side_num``
        - ``bParams.funcName`` -- for defining func index in
        namesAndNumbers dict.
        - ``bParams.region``
        
        Inputs:

        - ``side`` -- is ``Side`` object::

        side:

         - ``side_num``,

         - ``block.blockNumber``,

         - ``interval`` -- of type oIntervals

           where oIntervals =
                 [Interval([x, y], name={'b': bval, 'e', eval})]
        '''
        bounds = []
        for interval in side.intervals:

            # if interconnect then continue:
            try:
                interval.name['i']
                continue
            except KeyError:
                pass

            bParams = Params()
            bParams.name = 'sides bound'
            bParams.side_num = side.side_num
            bParams.blockNumber = side.block.blockNumber
            bParams.boundNumber = interval.name['b']
            bParams.equationNumber = interval.name['e']
            bParams.interval = interval

            eSystem = model.equations[bParams.equationNumber].copy()

            if bParams.boundNumber is not None:

                # FOR set up funcName and border values:
                args = (model, bParams.blockNumber, bParams.side_num,
                        bParams.boundNumber, bParams.equationNumber)

                btype = model.bounds[bParams.boundNumber].btype

                # for Dirichlet bound
                if btype == 0:
                    func = self.get_func_for_dirichlet(*args)

                # for Neumann bound
                elif btype == 1:
                    func = self.get_func_for_neumann(*args)

                funcName = func[0]
                border_values = list(func[1])

            else:

                btype = 0
                args = (eSystem, bParams.blockNumber, bParams.side_num,
                        bParams.equationNumber)
                func = self.get_func_default(*args)

                funcName = func[0]
                border_values = func[1]

            args = (eSystem, model, bParams.blockNumber, btype,
                    bParams.side_num, border_values)
            parsed, bv_parsed = self.parse_equations(*args)

            bParams.funcName = funcName
            bParams.btype = btype
            bParams.equation = eSystem
            bParams.parsedValues = parsed
            bParams.border_values_parsed = bv_parsed
            bParams.original = [e.sent for e in eSystem.eqs]

            # for comment
            bParams.boundName = determineNameOfBoundary(bParams.side_num)

            # collect for functionMaps:
            interval.name['fm'] = bParams

            bounds.append(bParams)
        return (bounds)