Ejemplo n.º 1
0
def computeGraph(t,
                 type='bbox',
                 t2=None,
                 procDict=None,
                 rank=0,
                 intersectionsDict=None):
    zones = Internal.getZones(t)
    graph = {}
    if type == 'bbox':  # zone de t de P0 intersectent une zone de t de P1
        if not intersectionsDict:
            try:
                import Connector.PyTree as X
            except:
                raise ImportError("computeGraph: requires Connector module.")
            intersectionsDict = X.getIntersectingDomains(t)
        for z in zones:
            proc = getProcLocal__(z, procDict)
            for z2 in zones:
                if z[0] in intersectionsDict[z2[0]]:
                    popp = getProcGlobal__(z2[0], t, procDict)
                    updateGraph__(graph, proc, popp, z[0])
        #import Connector.PyTree as X
        #for z in zones:
        #    proc = getProcLocal__(z, procDict)
        #    doms = X.getBBIntersectingDomains(t, z, tol=1.e-12)
        #    for d in doms:
        #        popp = getProcGlobal__(d[0], t, procDict)
        #        updateGraph__(graph, proc, popp, z[0])

    elif type == 'bbox2':  # zone de t de P0 qui intersecte une zone de t de P1 mais qui n'est pas sur la meme base
        if not intersectionsDict:
            try:
                import Connector.PyTree as X
            except:
                raise ImportError("computeGraph: requires Connector module.")
            intersectionsDict = X.getIntersectingDomains(t)
        for z in zones:
            (p, c) = Internal.getParentOfNode(t, z)
            base = p[0]
            proc = getProcLocal__(z, procDict)
            for z2 in zones:
                if z[0] in intersectionsDict[z2[0]]:
                    (p, c) = Internal.getParentOfNode(t, z2)
                    based = p[0]
                    popp = getProcGlobal__(z2[0], t, procDict)
                    if (popp != proc and base != based):
                        if proc not in graph: graph[proc] = {popp: [z[0]]}
                        else:
                            if popp not in graph[proc]:
                                graph[proc][popp] = [z[0]]
                            else:
                                if z[0] not in graph[proc][popp]:
                                    graph[proc][popp].append(z[0])
        # import Connector.PyTree as X
        # for z in zones:
        #     (p, c) = Internal.getParentOfNode(t, z)
        #     base = p[0]
        #     proc = getProcLocal__(z, procDict)
        #     doms = X.getBBIntersectingDomains(t, z, tol=1.e-12)
        #     for d in doms:
        #         (p, c) = Internal.getParentOfNode(t, d)
        #         based = p[0]
        #         popp = getProcGlobal__(d[0], t, procDict)
        #         if (popp != proc and base != based):
        #             if proc not in graph: graph[proc] = {popp:[z[0]]}
        #             else:
        #                 if popp not in graph[proc]: graph[proc][popp] = [z[0]]
        #                 else:
        #                     if z[0] not in graph[proc][popp]:
        #                         graph[proc][popp].append(z[0])

    elif type == 'bbox3':  # zone de t sur P0 qui intersecte une zone de t2 sur P1
        #if not t2: raise ValueError("computeGraph: type bbox3 requires a t2.")
        zones2 = Internal.getZones(t2)
        if not intersectionsDict:
            try:
                import Connector.PyTree as X
            except:
                raise ImportError("computeGraph: requires Connector module.")
            intersectionsDict = X.getIntersectingDomains(t, t2)
        for z in zones:
            proc = getProcLocal__(z, procDict)
            for z2 in zones2:
                if z2[0] in intersectionsDict[z[0]]:
                    popp = getProcGlobal__(z2[0], t2, None)
                    updateGraph__(graph, proc, popp, z[0])
        #import Connector.PyTree as X
        #for z in zones:
        #    proc = getProcLocal__(z, procDict)
        #    doms = X.getBBIntersectingDomains(t2, z, tol=1.e-12)
        #    for d in doms:
        #        popp = getProcGlobal__(d[0], t2, None)
        #        updateGraph__(graph, proc, popp, z[0])

    elif type == 'ID':  # base sur les interpolations data
        for z in zones:
            proc = getProcLocal__(z, procDict)
            subRegions2 = Internal.getNodesFromType1(z, 'ZoneSubRegion_t')
            subRegions = []
            for s in subRegions2:
                sname = s[0]
                if sname.split('_')[0] == 'ID': subRegions.append(s)
            for s in subRegions:
                donor = Internal.getValue(s)
                idn = Internal.getNodesFromName1(s, 'InterpolantsDonor')
                if idn != []:  # la subRegion decrit des interpolations
                    popp = getProcGlobal__(donor, t, procDict)
                    updateGraph__(graph, proc, popp, z[0])

    elif type == 'IBCD':  # base sur les IBC data
        for z in zones:
            proc = getProcLocal__(z, procDict)
            subRegions2 = Internal.getNodesFromType1(z, 'ZoneSubRegion_t')
            subRegions = []
            for s in subRegions2:
                sname = s[0]
                if sname.split('_')[0] == 'IBCD': subRegions.append(s)
            for s in subRegions:
                donor = Internal.getValue(s)
                idn = Internal.getNodesFromName1(s, 'InterpolantsDonor')
                if idn != []:  # la subRegion decrit des IBC
                    popp = getProcGlobal__(donor, t, procDict)
                    updateGraph__(graph, proc, popp, z[0])

    elif type == 'ALLD':  # base sur les Interpolations+IBC data
        for z in zones:
            proc = getProcLocal__(z, procDict)
            subRegions = Internal.getNodesFromType1(z, 'ZoneSubRegion_t')
            for s in subRegions:
                donor = Internal.getValue(s)
                idn = Internal.getNodesFromName1(s, 'InterpolantsDonor')
                if idn != []:  # la subRegion decrit des interpolations/IBC
                    popp = getProcGlobal__(donor, t, procDict)
                    updateGraph__(graph, proc, popp, z[0])

    elif type == 'match':  # base sur les raccords matchs
        for z in zones:
            proc = getProcLocal__(z, procDict)
            GC = Internal.getNodesFromType2(z, 'GridConnectivity1to1_t')
            for c in GC:
                donor = Internal.getValue(c)
                popp = getProcGlobal__(donor, t, procDict)
                updateGraph__(graph, proc, popp, z[0])

    elif type == 'proc':
        for z in zones:
            if not isZoneSkeleton__(z):
                popp = getProcLocal__(z, procDict)
                proc = rank
                updateGraph__(graph, proc, popp, z[0])
    return graph
Ejemplo n.º 2
0
# - getIntersectingDomains (pyTree) -
import Generator.PyTree as G
import Connector.PyTree as X
import Converter.PyTree as C

t = C.newPyTree(['Base1'])
Ni = 4
Nj = 4
Nk = 4
dx = 0.
for i in xrange(10):
    z = G.cart((dx, dx, dx), (1. / (Ni - 1), 1. / (Nj - 1), 1. / (Nk - 1)),
               (Ni, Nj, Nk))
    t[2][1][2] += [z]
    dx += 0.3

interDict = X.getIntersectingDomains(t, method='hybrid')
print 'Does cart.1 intersect cart.2 ?', 'cart.1' in interDict['cart.2']
print 'List of zones intersecting cart.2:', interDict['cart.2']
Ejemplo n.º 3
0
def computeGraph(t,
                 type='bbox',
                 t2=None,
                 procDict=None,
                 rank=0,
                 intersectionsDict=None,
                 exploc=False):
    """Return the communication graph for different block relation types."""
    zones = Internal.getZones(t)
    graph = {}
    if type == 'bbox':  # zone de t de P0 intersectent une zone de t de P1
        if not intersectionsDict:
            try:
                import Connector.PyTree as X
            except:
                raise ImportError("computeGraph: requires Connector module.")
            intersectionsDict = X.getIntersectingDomains(t)
        for z in zones:
            proc = getProcLocal__(z, procDict)
            for z2 in zones:
                if z[0] in intersectionsDict[z2[0]]:
                    popp = getProcGlobal__(z2[0], t, procDict)
                    updateGraph__(graph, proc, popp, z[0])
        #import Connector.PyTree as X
        #for z in zones:
        #    proc = getProcLocal__(z, procDict)
        #    doms = X.getBBIntersectingDomains(t, z, tol=1.e-12)
        #    for d in doms:
        #        popp = getProcGlobal__(d[0], t, procDict)
        #        updateGraph__(graph, proc, popp, z[0])

    elif type == 'bbox2':  # zone de t de P0 qui intersecte une zone de t de P1 mais qui n'est pas sur la meme base
        if not intersectionsDict:
            try:
                import Connector.PyTree as X
            except:
                raise ImportError("computeGraph: requires Connector module.")
            intersectionsDict = X.getIntersectingDomains(t)
        for z in zones:
            (p, c) = Internal.getParentOfNode(t, z)
            base = p[0]
            proc = getProcLocal__(z, procDict)
            for z2 in zones:
                if z[0] in intersectionsDict[z2[0]]:
                    (p, c) = Internal.getParentOfNode(t, z2)
                    based = p[0]
                    popp = getProcGlobal__(z2[0], t, procDict)
                    if popp != proc and base != based:
                        if proc not in graph: graph[proc] = {popp: [z[0]]}
                        else:
                            if popp not in graph[proc]:
                                graph[proc][popp] = [z[0]]
                            else:
                                if z[0] not in graph[proc][popp]:
                                    graph[proc][popp].append(z[0])
        # import Connector.PyTree as X
        # for z in zones:
        #     (p, c) = Internal.getParentOfNode(t, z)
        #     base = p[0]
        #     proc = getProcLocal__(z, procDict)
        #     doms = X.getBBIntersectingDomains(t, z, tol=1.e-12)
        #     for d in doms:
        #         (p, c) = Internal.getParentOfNode(t, d)
        #         based = p[0]
        #         popp = getProcGlobal__(d[0], t, procDict)
        #         if (popp != proc and base != based):
        #             if proc not in graph: graph[proc] = {popp:[z[0]]}
        #             else:
        #                 if popp not in graph[proc]: graph[proc][popp] = [z[0]]
        #                 else:
        #                     if z[0] not in graph[proc][popp]:
        #                         graph[proc][popp].append(z[0])

    elif type == 'bbox3':  # zone de t sur P0 qui intersecte une zone de t2 sur P1
        #if not t2: raise ValueError("computeGraph: type bbox3 requires a t2.")
        zones2 = Internal.getZones(t2)
        if not intersectionsDict:
            try:
                import Connector.PyTree as X
            except:
                raise ImportError("computeGraph: requires Connector module.")
            intersectionsDict = X.getIntersectingDomains(t, t2)
        for z in zones:
            proc = getProcLocal__(z, procDict)
            for z2 in zones2:
                if z2[0] in intersectionsDict[z[0]]:
                    popp = getProcGlobal__(z2[0], t2, None)
                    updateGraph__(graph, proc, popp, z[0])
        #import Connector.PyTree as X
        #for z in zones:
        #    proc = getProcLocal__(z, procDict)
        #    doms = X.getBBIntersectingDomains(t2, z, tol=1.e-12)
        #    for d in doms:
        #        popp = getProcGlobal__(d[0], t2, None)
        #        updateGraph__(graph, proc, popp, z[0])

    elif type == 'ID':  # base sur les interpolations data
        if not exploc:
            for z in zones:
                proc = getProcLocal__(z, procDict)
                subRegions2 = Internal.getNodesFromType1(z, 'ZoneSubRegion_t')
                subRegions = []
                for s in subRegions2:
                    sname = s[0][0:2]
                    if sname == 'ID': subRegions.append(s)
                for s in subRegions:
                    donor = Internal.getValue(s)
                    idn = Internal.getNodesFromName1(s, 'InterpolantsDonor')
                    if idn != []:  # la subRegion decrit des interpolations
                        popp = getProcGlobal__(donor, t, procDict)
                        updateGraph__(graph, proc, popp, z[0])
        else:
            maxlevel = 1
            for z in zones:
                subRegions2 = Internal.getNodesFromType1(z, 'ZoneSubRegion_t')
                for s in subRegions2:
                    levrcv_ = Internal.getNodesFromName1(s, 'LevelZRcv')
                    levrcv = int(levrcv_[0][1][0])
                    levdnr_ = Internal.getNodesFromName1(s, 'LevelZDnr')
                    levdnr = int(levdnr_[0][1][0])
                    maximum = max(levrcv, levdnr)
                    if (maximum > maxlevel): maxlevel = maximum
            nssiter = 4 * maxlevel

            list_graph_ = []
            for ssiter in range(1, 2 * nssiter + 1):
                graph_ = {}
                for z in zones:
                    proc = getProcLocal__(z, procDict)
                    subRegions2 = Internal.getNodesFromType1(
                        z, 'ZoneSubRegion_t')
                    subRegions = []
                    for s in subRegions2:
                        sname = s[0][0:2]
                        if sname == 'ID': subRegions.append(s)
                    for s in subRegions:
                        donor = Internal.getValue(s)
                        levdnr_ = Internal.getNodesFromName1(s, 'LevelZDnr')
                        levdnr = int(levdnr_[0][1][0])
                        levrcv_ = Internal.getNodesFromName1(s, 'LevelZRcv')
                        levrcv = int(levrcv_[0][1][0])
                        idn = Internal.getNodesFromName1(
                            s, 'InterpolantsDonor')
                        cycl = nssiter / levdnr
                        if levdnr > levrcv and ssiter <= nssiter:
                            if ssiter % cycl == cycl - 1 or ssiter % cycl == cycl / 2 and (
                                    ssiter / cycl) % 2 == 1:
                                if idn != []:  # la subRegion decrit des interpolations
                                    popp = getProcGlobal__(donor, t, procDict)
                                    updateGraph__(graph_, proc, popp, z[0])
                        if levdnr < levrcv and ssiter <= nssiter:
                            if (ssiter % cycl == 1 or ssiter % cycl == cycl / 4
                                    or ssiter % cycl == cycl / 2 - 1
                                    or ssiter % cycl == cycl / 2 + 1
                                    or ssiter % cycl == cycl / 2 + cycl / 4
                                    or ssiter % cycl == cycl - 1):
                                if idn != []:  # la subRegion decrit des interpolations
                                    popp = getProcGlobal__(donor, t, procDict)
                                    updateGraph__(graph_, proc, popp, z[0])
                        if levdnr == levrcv and ssiter <= nssiter:
                            if (ssiter % cycl == cycl / 2 - 1
                                    or (ssiter % cycl == cycl / 2 and
                                        (ssiter / cycl) % 2 == 0)
                                    or ssiter % cycl == cycl - 1):
                                if idn != []:  # la subRegion decrit des interpolations
                                    popp = getProcGlobal__(donor, t, procDict)
                                    updateGraph__(graph_, proc, popp, z[0])
                        if levdnr == levrcv and ssiter > nssiter:
                            #if (ssiter%8==6):
                            ssiter_ = ssiter - nssiter
                            if ssiter_ % 2 == 0 and ssiter_ % cycl == cycl / 2 and (
                                    ssiter_ / cycl) % 2 == 1:
                                if idn != []:  # la subRegion decrit des interpolations
                                    popp = getProcGlobal__(donor, t, procDict)
                                    updateGraph__(graph_, proc, popp, z[0])
                list_graph_.append(graph_)

    elif type == 'IBCD':  # base sur les IBC data
        if not exploc:
            for z in zones:
                proc = getProcLocal__(z, procDict)
                subRegions2 = Internal.getNodesFromType1(z, 'ZoneSubRegion_t')
                subRegions = []
                for s in subRegions2:
                    sname = s[0][0:2]
                    if sname == 'IB': subRegions.append(s)
                for s in subRegions:
                    donor = Internal.getValue(s)
                    idn = Internal.getNodesFromName1(s, 'InterpolantsDonor')
                    if idn != []:  # la subRegion decrit des IBC
                        popp = getProcGlobal__(donor, t, procDict)
                        updateGraph__(graph, proc, popp, z[0])

        else:
            maxlevel = 1
            for z in zones:
                subRegions2 = Internal.getNodesFromType1(z, 'ZoneSubRegion_t')
                for s in subRegions2:
                    levrcv_ = Internal.getNodesFromName1(s, 'LevelZRcv')
                    levrcv = int(levrcv_[0][1][0])
                    levdnr_ = Internal.getNodesFromName1(s, 'LevelZDnr')
                    levdnr = int(levdnr_[0][1][0])
                    maximum = max(levrcv, levdnr)
                    if maximum > maxlevel: maxlevel = maximum
            nssiter = 4 * maxlevel

            list_graph_ = []
            for ssiter in range(1, 2 * nssiter + 1):
                graph_ = {}
                for z in zones:
                    proc = getProcLocal__(z, procDict)
                    subRegions2 = Internal.getNodesFromType1(
                        z, 'ZoneSubRegion_t')
                    subRegions = []
                    for s in subRegions2:
                        sname = s[0][0:2]
                        if sname == 'IB': subRegions.append(s)
                    for s in subRegions:
                        donor = Internal.getValue(s)
                        levdnr_ = Internal.getNodesFromName1(s, 'LevelZDnr')
                        levdnr = int(levdnr_[0][1][0])
                        levrcv_ = Internal.getNodesFromName1(s, 'LevelZRcv')
                        levrcv = int(levrcv_[0][1][0])
                        idn = Internal.getNodesFromName1(
                            s, 'InterpolantsDonor')
                        cycl = nssiter / levdnr
                        if (levdnr > levrcv and ssiter <= nssiter):
                            if (ssiter % cycl == cycl - 1
                                    or ssiter % cycl == cycl / 2 and
                                (ssiter / cycl) % 2 == 1):
                                if idn != []:  # la subRegion decrit des interpolations
                                    popp = getProcGlobal__(donor, t, procDict)
                                    updateGraph__(graph_, proc, popp, z[0])
                        if levdnr < levrcv and ssiter <= nssiter:
                            if (ssiter % cycl == 1 or ssiter % cycl == cycl / 4
                                    or ssiter % cycl == cycl / 2 - 1
                                    or ssiter % cycl == cycl / 2 + 1
                                    or ssiter % cycl == cycl / 2 + cycl / 4
                                    or ssiter % cycl == cycl - 1):
                                if idn != []:  # la subRegion decrit des interpolations
                                    popp = getProcGlobal__(donor, t, procDict)
                                    updateGraph__(graph_, proc, popp, z[0])
                        if levdnr == levrcv and ssiter <= nssiter:
                            if ssiter % cycl == cycl / 2 - 1 or ssiter % cycl == cycl / 2 or ssiter % cycl == cycl - 1:
                                if idn != []:  # la subRegion decrit des interpolations
                                    popp = getProcGlobal__(donor, t, procDict)
                                    updateGraph__(graph_, proc, popp, z[0])
                        if levdnr == levrcv and ssiter > nssiter:
                            if ssiter % 8 == 6:
                                if idn != []:  # la subRegion decrit des interpolations
                                    popp = getProcGlobal__(donor, t, procDict)
                                    updateGraph__(graph_, proc, popp, z[0])
                list_graph_.append(graph_)

    elif type == 'ALLD':  # base sur les Interpolations+IBC data
        for z in zones:
            proc = getProcLocal__(z, procDict)
            subRegions = Internal.getNodesFromType1(z, 'ZoneSubRegion_t')
            for s in subRegions:
                donor = Internal.getValue(s)
                idn = Internal.getNodesFromName1(s, 'InterpolantsDonor')
                if idn != []:  # la subRegion decrit des interpolations/IBC
                    popp = getProcGlobal__(donor, t, procDict)
                    updateGraph__(graph, proc, popp, z[0])

    elif type == 'match':  # base sur les raccords matchs
        for z in zones:
            proc = getProcLocal__(z, procDict)
            GC = Internal.getNodesFromType2(z, 'GridConnectivity1to1_t')
            for c in GC:
                donor = Internal.getValue(c)
                popp = getProcGlobal__(donor, t, procDict)
                updateGraph__(graph, proc, popp, z[0])

    elif type == 'proc':
        for z in zones:
            if not isZoneSkeleton__(z):
                popp = getProcLocal__(z, procDict)
                proc = rank
                updateGraph__(graph, proc, popp, z[0])

    if not exploc: return graph
    else: return list_graph_