Exemplo n.º 1
0
def _convert2SkeletonTree(t):
    zones = Internal.getZones(t)
    for z in zones:
        nodes = Internal.getNodesFromType(z, 'DataArray_t')
        for n in nodes:
            n[1] = None
    return None
Exemplo n.º 2
0
def checkUniqueNames(t, type):
    nameServer = {}
    errors = []
    # Register nodes of type
    nodes = Internal.getNodesFromType(t, type)
    for n in nodes:
        name = n[0]
        if not nameServer.has_key(name): nameServer[name] = 0
        else:
            if type == 'CGNSBase_t':
                errors += [n, "Base name %s is already used." % n[0]]
            elif type == 'Zone_t':
                (p, c) = Internal.getParentOfNode(t, n)
                errors += [
                    n,
                    "Zone name %s (base %s) is already used." % (n[0], p[0])
                ]
            elif type == 'BC_t':
                (p, c) = Internal.getParentOfNode(t, n)
                (p, c) = Internal.getParentOfNode(t, p)
                errors += [
                    n,
                    "BC name %s (zone %s) is already used." % (n[0], p[0])
                ]
            elif type == 'GridConnectivity_1to1_t':
                errors += [n, "BCMatch name %s is already used." % n[0]]
            elif type == 'GridConnectivity_t':
                errors += [
                    n, "GridConnectivity name %s is already used." % n[0]
                ]
            else:
                errors += [n, "Node name %s is already used." % n[0]]
    return errors
Exemplo n.º 3
0
def checkBCRanges(t, type):
    errors = []
    zones = Internal.getZones(t)
    for z in zones:
        dim = Internal.getZoneDim(z)
        nodes = Internal.getNodesFromType2(z, type)
        for n in nodes:
            prange = Internal.getNodesFromName1(n, 'PointRange')
            for r in prange:
                if (r[1].shape == (2, 3)):
                    r[1] = numpy.reshape(r[1], (3, 2), order='Fortran')
                if (r[1].shape == (3, 2)):
                    win = Internal.range2Window(r[1])
                else:
                    win = [0, 0, 0, 0, 0, 0]  # pas de check en non structure
                # Check structure uniquement pour l'instant
                error = 0
                if (win[0] < 0 or win[0] > dim[1]): error = 1
                if (win[1] < 0 or win[1] > dim[1]): error = 1
                if (win[2] < 0 or win[2] > dim[2]): error = 1
                if (win[3] < 0 or win[3] > dim[2]): error = 1
                if (win[4] < 0 or win[4] > dim[3]): error = 1
                if (win[5] < 0 or win[5] > dim[3]): error = 1

                if error == 1:
                    errors += [
                        r,
                        "Range of BC %s is invalid for zone %s." % (n[0], z[0])
                    ]
    return errors
Exemplo n.º 4
0
def getProcGlobal__(zoneName, t, procDict):
    if procDict is not None: return procDict[zoneName]
    else:
        z = Internal.getNodeFromName2(t, zoneName)
        proc = Internal.getNodeFromName2(z, 'proc')
        proc = Internal.getValue(proc)
        return proc
Exemplo n.º 5
0
def checkElementNodes(t):
    errors = []
    zones = Internal.getZones(t)
    for z in zones:
        connects = Internal.getElementNodes(z)
        iBE = -1
        iBEMultiple = -1
        iNGon = -1
        iNFace = -1
        i = 0
        for c in connects:
            ctype = c[1][0]
            if (ctype == 22): iNGon = i
            elif (ctype == 23): iNFace = i
            else:
                if (iBE == -1): iBE = i  # first
                else: iBEMultiple = 1
            i += 1

        if (iNGon != -1 and iNFace != -1): pass
        elif (iNGon != -1 and iNFace == -1):
            errors += [z, 'NFace is missing for zone %s.' % z[0]]
        elif (iBEMultiple == 1):
            errors += [z, 'Multiple BE connectivity for zone %s.' % z[0]]
    return errors
Exemplo n.º 6
0
def checkBCFamily(t):
    zones = Internal.getZones(t)
    errors = []
    for z in zones:
        BCs = Internal.getNodesFromType2(z, 'BC_t')
        for b in BCs:
            f = Internal.getNodesFromType1(b, 'FamilyName_t')
            if f != []:  # zone avec BC family
                name = f[0][1]
                if isinstance(name, numpy.ndarray): name = name.tostring()
                # Check for family
                (p, c) = Internal.getParentOfNode(t, z)
                if p is not None:
                    ref = Internal.getNodesFromName1(p, name)
                    if (ref == []):
                        errors += [
                            p,
                            'FamilyBC %s (referenced by zone %s) is not defined in base.'
                            % (name, z[0])
                        ]
                    elif (ref[0][3] != 'Family_t'):
                        errors += [
                            p,
                            'FamilyBC %s (referenced by zone %s) is not defined in base.'
                            % (name, z[0])
                        ]
    return errors
Exemplo n.º 7
0
def _rmXZones(t):
    zones = Internal.getZones(t)
    for z in zones:
        tag = Internal.getNodesFromName1(z, 'XZone')
        if (len(tag) > 0):
            (p, c) = Internal.getParentOfNode(t, z)
            del p[2][c]
    return None
Exemplo n.º 8
0
def _correctOppositRanges(t, type):
    errors = checkOppositRanges(t, type)
    le = len(errors) / 2
    for e in xrange(le):
        node = errors[2 * e]
        (p, c) = Internal.getParentOfNode(t, node)
        if p is not None:
            (p2, c2) = Internal.getParentOfNode(t, p)
            if p2 is not None: del p[2][c]
    return None
Exemplo n.º 9
0
def checkMGForDonorBCRanges(z, type, multigrid, sizemin):
    puiss = 2**(multigrid)
    errors = []
    nodes = Internal.getNodesFromType2(z, type)
    for n in nodes:
        PRS = Internal.getNodesFromName1(n, 'PointRangeDonor')
        for PR in PRS:
            [imin, imax, jmin, jmax, kmin, kmax] = Internal.range2Window(PR[1])
            if imin != imax:
                di = (imax - imin)
                res = (di + 1) / puiss
                if di % puiss != 0:
                    errors += [
                        n,
                        "PointRangeDonor for GC %s of zone %s is not multigrid of level %d in direction i."
                        % (n[0], z[0], multigrid)
                    ]
                elif res < sizemin:
                    errors += [
                        n,
                        "PointRangeDonor for GC %s of zone %s: not enough points on coarse grid in direction i."
                        % (n[0], z[0])
                    ]
            if jmin != jmax:
                dj = (jmax - jmin)
                res = (dj + 1) / puiss
                if dj % puiss != 0:
                    errors += [
                        n,
                        "PointRangeDonor for GC %s of zone %s is not multigrid of level %d in direction j."
                        % (n[0], z[0], multigrid)
                    ]
                elif res < sizemin:
                    errors += [
                        n,
                        "PointRangeDonor for GC %s of zone %s: not enough points on coarse grid in direction j."
                        % (n[0], z[0])
                    ]
            if kmin != kmax:
                dk = (kmax - kmin)
                res = (dk + 1) / puiss
                if dk % puiss != 0:
                    errors += [
                        n,
                        "PointRangeDonor for GC %s of zone %s is not multigrid of level %d in direction k."
                        % (n[0], z[0], multigrid)
                    ]
                elif res < sizemin:
                    errors += [
                        n,
                        "PointRangeDonor for GC %s of zone %s: not enough points on coarse grid in direction i."
                        % (n[0], z[0])
                    ]
    return errors
Exemplo n.º 10
0
def _correctDonors(t, type, zoneDonors):
    zones = Internal.getZones(t)
    for z in zones:
        nodes = Internal.getNodesFromType2(z, type)
        for n in nodes:
            if isinstance(n[1], numpy.ndarray):
                zdonorname = n[1].tostring()
            else:
                zdonorname = n[1]
            for zd in zoneDonors:
                zd1 = numpy.fromstring(zd[1], 'c')
                if zd[0] == zdonorname: n[1] = zd1
    return None
Exemplo n.º 11
0
def isZoneSkeleton__(z):
    cx = Internal.getNodeFromType1(z, 'GridCoordinates_t')
    if cx is not None:
        t1 = Internal.getNodesFromType1(cx, 'DataArray_t')
        for d in t1:
            if d[1] is None: return True
        return False
    cx = Internal.getNodesFromType1(z, 'FlowSolution_t')
    for x in cx:
        t1 = Internal.getNodesFromType1(x, 'DataArray_t')
        for d in t1:
            if d[1] is None: return True
    return False
Exemplo n.º 12
0
def checkBaseZonesDim(t):
    errors = []
    bases = Internal.getBases(t)
    for b in bases:
        dimBase = b[1][0]
        zones = Internal.getNodesFromType1(b, 'Zone_t')
        for z in zones:
            dim = Internal.getZoneDim(z)
            if (dim[4] != dimBase):
                errors += [
                    b,
                    "Zone %s cellDim is inconsistent with base %s cellDim." %
                    (z[0], b[0])
                ]
    return errors
Exemplo n.º 13
0
def _setZonesInTree(t, zones):
    size = len(zones)
    for i in xrange(size):
        for j in xrange(len(zones[i])):
            zone = zones[i][j]
            zoneName = zone[0]
            z = Internal.getNodeFromName2(t, zoneName)
            if z is not None:
                (p, nb) = Internal.getParentOfNode(t, z)
                p[2][nb] = zone
            else:
                # append to given base
                bases = Internal.getBases(t)
                bases[0][2] += [zone]
    return None
Exemplo n.º 14
0
def _convert2PartialTree(t, rank=-1):
    zones = Internal.getZones(t)
    for z in zones:
        crit = False
        if rank == -1: crit = isZoneSkeleton__(z)
        else:
            proc = Internal.getNodeFromName2(z, 'proc')
            if proc is not None:
                proc = Internal.getValue(proc)
                crit = (rank != proc)
        if crit:
            (p, c) = Internal.getParentOfNode(t, z)
            if (Internal.isStdNode(t) == 0 and id(p) == id(t)): del p[c]
            else: del p[2][c]
    return None
Exemplo n.º 15
0
def checkSize(t, sizeMax=100000000):
    errors = []
    for z in Internal.getZones(t):
        dims = Internal.getZoneDim(z)
        if dims[0] == 'Structured':
            npts = dims[1] * dims[2] * dims[3]
        else:
            npts = dims[1]
        if npts > sizeMax:
            errors += [
                z,
                "Zone %s exceeds the maximum number of points (Npts=%d)." %
                (z[0], npts)
            ]
    return errors
Exemplo n.º 16
0
def _setProc(t, nproc):
    zones = Internal.getZones(t)
    for z in zones:
        node = Internal.getNodeFromName1(z, '.Solver#Param')
        if node is not None: param = node
        else:
            param = ['.Solver#Param', None, [], 'UserDefinedData_t']
            z[2].append(param)
        v = numpy.zeros((1, 1), numpy.int32)
        v[0, 0] = nproc
        node = Internal.getNodeFromName(param, 'proc')
        if node is not None: node[1] = v
        else:
            a = ['proc', v, [], 'DataArray_t']
            param[2].append(a)
    return None
Exemplo n.º 17
0
def _correctCGNSVarNames(t):
    errors = checkCGNSVarNames(t)
    for e in xrange(len(errors) / 2):
        node = errors[2 * e]
        n = Internal.getCGNSName(node[0])
        node[0] = n
    return None
Exemplo n.º 18
0
def getProcDict(t):
    proc = {}
    zones = Internal.getZones(t)
    for z in zones:
        nproc = getProc(z)
        proc[z[0]] = nproc
    return proc
Exemplo n.º 19
0
def _correctNames(t, type):
    nameServer = {}
    nodes = Internal.getNodesFromType(t, type)
    zoneDonors = []
    for n in nodes:
        name = n[0]
        if not nameServer.has_key(name): nameServer[name] = 0
        else:  # deja existant
            c = nameServer[name]
            ret = 1
            while (ret == 1):
                name2 = '%s.%d' % (name, c)
                if not nameServer.has_key(name2): ret = 0
                else: ret = 1
                c += 1
            nameServer[name2] = 0
            nameServer[name] = c
            if n[3] == 'Zone_t': zoneDonors.append((n[0], name2))
            n[0] = name2

    # Modifie les zoneDonors
    _correctDonors(t, 'GridConnectivity1to1_t', zoneDonors)
    _correctDonors(t, 'GridConnectivity_t', zoneDonors)

    # Modifie les attachs
    return None
Exemplo n.º 20
0
def _correctNodes(t):
    errors = checkNodes(t)
    le = len(errors) / 2
    for e in xrange(le):
        node = errors[2 * e]
        (p, c) = Internal.getParentOfNode(t, node)
        if p is not None: del p[2][c]
    return None
Exemplo n.º 21
0
def checkCGNSVarNames(t):
    errors = []
    zones = Internal.getZones(t)
    for z in zones:
        # Change on container
        cont = Internal.getNodesFromType1(z, 'FlowSolution_t')
        for c in cont:
            datas = Internal.getNodesFromType1(c, 'DataArray_t')
            for d in datas:
                n = Internal.getCGNSName(d[0])
                if n != d[0]:
                    errors += [
                        d,
                        '%s not a valid CGNS variable name for zone %s.' %
                        (d[0], z[0])
                    ]
        # Change on BCDataSet (if any)
        bcs = Internal.getNodesFromType2(z, 'BC_t')
        for b in bcs:
            datas = Internal.getBCDataSet(z, b)
            for d in datas:
                n = Internal.getCGNSName(d[0])
                if n != d[0]:
                    errors += [
                        d,
                        '%s not a valid CGNS variable name for BCDataSet in zone %s.'
                        % (d[0], z[0])
                    ]
    return errors
Exemplo n.º 22
0
def _correctElementNodes(t):
    errors = checkElementNodes(t)
    le = len(errors) / 2
    for e in xrange(le):
        zone = errors[2 * e]
        msg = errors[2 * e + 1]
        if msg[0:8] == 'Multiple':
            zones = C.breakConnectivity(zone)
            (p, c) = Internal.getParentOfNode(t, zone)
            if p is not None:
                p[2][c] = zones[0]
                p[2] += zones[1:]
        elif msg[0:6] == 'NFace':
            # Look for PE
            PE = Internal.getNodeFromName2(zone, 'ParentElements')
            if PE is not None:
                Internal._adaptPE2NFace(zone, remove=False)
    return None
Exemplo n.º 23
0
def checkNodes(node):
    errors = []
    isStd = Internal.isStdNode(node)
    if (isStd >= 0):
        for c in node[isStd:]:
            checkNode__(c, errors)
    else:
        checkNode__(node, errors)
    return errors
Exemplo n.º 24
0
def _correctZoneFamily(t):
    errors = checkZoneFamily(t)
    le = len(errors) / 2
    for e in xrange(le):
        node = errors[2 * e]
        name = errors[2 * e + 1]
        name = name.split(' ')
        name = name[1]
        (p, c) = Internal.getParentOfNode(t, node)
        if p is not None: C._addFamily2Base(node, name)
    return None
Exemplo n.º 25
0
def checkDonorFaces(t, type):
    errors = []
    zones = Internal.getZones(t)
    for z in zones:
        nodes = Internal.getNodesFromType2(z, type)
        for n in nodes:
            donorName = Internal.getValue(n)
            donors = Internal.getNodesFromName2(t, donorName)
            if donors != []:
                plist = Internal.getNodesFromName1(n, 'PointListDonor')
                for r in plist:
                    faces = r[1]
                    faces1 = faces[faces > nfaces]
                    faces2 = faces[faces < 1]
                    if faces1.size > 0 or faces2.size > 0:
                        errors += [
                            r,
                            "Faces of donor BC %s is invalid for zone %s." %
                            (n[0], z[0])
                        ]
    return errors
Exemplo n.º 26
0
def checkBCFaces(t, type):
    errors = []
    zones = Internal.getZones(t)
    for z in zones:
        dim = Internal.getZoneDim(z)
        r = Internal.getElementRange(z, type="NGON")
        if r is not None: nfaces = r[1] - r[0] + 1
        else: nfaces = 0
        nodes = Internal.getNodesFromType2(z, type)
        for n in nodes:
            plist = Internal.getNodesFromName1(n, 'PointList')
            for r in plist:
                faces = r[1]
                faces1 = faces[faces > nfaces]
                faces2 = faces[faces < 1]
                if faces1.size > 0 or faces2.size > 0:
                    errors += [
                        r,
                        "Faces of BC %s is invalid for zone %s." % (n[0], z[0])
                    ]
    return errors
Exemplo n.º 27
0
def checkVersionNode(t):
    errors = []
    if (len(t) == 4 and t[3] == 'CGNSTree_t'):
        version = Internal.getNodesFromType1(t, 'CGNSLibraryVersion_t')
        if version == []: errors += [None, 'Missing CGNS version node.']
        elif (t[2][0] != version[0]):
            errors += [
                version[0], 'CGNS version node must be first in tree sons.'
            ]
        if len(version) > 1:
            for v in version[1:]:
                errors += [v, 'Only one CGNS version node is allowed.']
    return errors
Exemplo n.º 28
0
def createBBoxTree(t, method='AABB', weighting=0):
    try:
        import Generator.PyTree as G
    except:
        raise ImportError("createBBoxTree requires Generator module.")
    # bounding box des zones locales
    tp = Internal.node2PyTree(t)
    bases = Internal.getBases(t)
    zb = []
    for b in bases:
        zones = Internal.getNodesFromType1(b, 'Zone_t')
        for z in zones:
            if not Distributed.isZoneSkeleton__(z):
                zbb = G.BB(z, method, weighting)
                zb.append(zbb)

    # Echanges des zones locales de bounding box
    # (allgather serialise automatiquement les donnees)
    zones = KCOMM.allgather(zb)

    # On les remplace dans l'arbre (par noms)
    tb = Distributed.setZonesInTree(t, zones)
    return tb
Exemplo n.º 29
0
def _correctBaseZonesDim(t):
    bases = Internal.getBases(t)
    for b in bases:
        dimBase = b[1][0]
        zones = Internal.getNodesFromType1(b, 'Zone_t')
        z1 = []
        z2 = []
        z3 = []  # zones de dim 1,2,3
        for z in zones:
            dim = Internal.getZoneDim(z)
            if (dim[4] <= 1): z1.append(z)
            elif (dim[4] == 2): z2.append(z)
            elif (dim[4] == 3): z3.append(z)
        lz1 = len(z1)
        lz2 = len(z2)
        lz3 = len(z3)
        if (lz1 == 0 and lz2 == 0): Internal.setValue(b, 3)
        elif (lz1 == 0 and lz3 == 0): Internal.setValue(b, 2)
        elif (lz2 == 0 and lz3 == 0): Internal.setValue(b, 1)
        else: print "Bases must be split."

    return None
Exemplo n.º 30
0
def _correctVersionNode(t):
    errors = checkVersionNode(t)
    le = len(errors) / 2
    added = 0
    for e in xrange(le):
        node = errors[2 * e]
        if node is None: t[2].insert(0, Internal.createCGNSVersionNode())
        else:
            c = 0
            for n in t[2]:
                if (n[3] == 'CGNSLibraryVersion_t' and id(n) == id(node)):
                    del t[2][c]
                    break
                c += 1
            if added == 0:
                t[2].insert(0, node)
                added = 1
    return None