Example #1
0
    def make_bounds_for_vertex(self, vertex, params_edges):
        '''
        DESCRIPTION:

        If vertex left edge closest region has ic value
        (i.e. this region donot exist in params_edges)
        then
        if right edge closest region has no ic value,
        use this region
        else
        use ic data (todo).

        Collect this parameters for template:

        - ``vParams.name``
        - ``vParams.sides_nums``
        - ``vParams.blockNumber``
        - ``vParams.boundNumber``
        - ``vParams.equationNumber``

        - ``vParams.funcName``
        - ``vParams.bound_side``
        - ``vParams.btype``
        - ``vParams.equation`` -- equation from left
        edge.

        - ``vParams.parsedValues``
        - ``vParams.original``

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

        - ``vertex`` -- is ``Vertex`` object::
            
        vertex:
        
        - ``boundNumber`` -- of left edge (side)
        - ``equationNumber`` -- of left edge (side)
        - ``sides_nums`` -- like [0, 2]
        - ``interval`` -- of left edge (side)

        - ``params_edges`` -- out of make_bounds_for_edges.
        Used for side data for vertex.
        '''
        # find bound for left edge:
        left_edges = [
            bParams for bParams in params_edges
            if bParams.side_num == vertex.sides_nums[0]
            and bParams.blockNumber == vertex.block.blockNumber
            and bParams.interval == vertex.left_interval
        ]
        # if interconnect exist for left edges
        # (so there is no region in params_edges)
        # use right:
        try:
            vertex_edge = left_edges[0]
        except IndexError:
            right_edges = [
                bParams for bParams in params_edges
                if bParams.side_num == vertex.sides_nums[1]
                and bParams.blockNumber == vertex.block.blockNumber
                and bParams.interval == vertex.right_interval
            ]
            # if interconnect exist for left and right
            # (so there is no region in params_edges)
            try:
                vertex_edge = right_edges[0]
            except IndexError:
                # TODO: add ic to vertex
                raise (BaseException("Case when vertex has ic regions" +
                                     " from both sides is not" +
                                     " implemented yet"))
                return (None)
        # END FOR

        vParams = Params()
        vParams.name = 'vertex bound'
        vParams.sides_nums = vertex.sides_nums
        vParams.blockNumber = vertex.block.blockNumber

        # data of left side (with index 0)
        vParams.boundNumber = vertex.boundNumber
        vParams.equationNumber = vertex.equationNumber

        # for make funcName for defaults
        funcName = self.get_vertex_funcName(vertex)

        vParams.funcName = funcName
        vParams.bound_side = vertex_edge
        vParams.btype = vertex_edge.btype

        eSystem = vertex_edge.equation.copy()
        parsedValues, bv_parsed = self.parse_equations_vertex(
            vertex, vertex_edge, eSystem)
        vParams.parsedValues = parsedValues
        vParams.border_values_parsed = bv_parsed
        # vParams.parsedValues = vertex_edge.parsedValues

        vParams.equation = eSystem

        logger.debug("parsedValues:")
        logger.debug(vParams.parsedValues)
        vParams.original = vertex_edge.original

        return (vParams)
Example #2
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)
Example #3
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)