Exemple #1
0
def _addXZones(t, graph, variables=None, cartesian=False):
    if graph == {}: return t
    reqs = []
    if rank in graph:
        g = graph[rank]  # graph du proc courant
        for oppNode in g:
            # Envoie les zones necessaires au noeud oppose
            #print '%d: On envoie a %d: %s'%(rank,oppNode,g[oppNode])
            names = g[oppNode]
            data = []  # data est une liste de zones
            for n in names:
                zone = Internal.getNodeFromName2(t, n)
                if variables is not None:
                    v = C.getVarNames(zone, excludeXYZ=True)[0]
                    for i in variables:
                        v.remove(i)
                    zonep = C.rmVars(zone, v)
                    if cartesian: Compressor._compressCartesian(zonep)
                    data.append(zonep)
                else:
                    if cartesian:
                        zonep = Compressor._compressCartesian(zonep)
                        data.append(zonep)
                    else:
                        data.append(zone)
            s = KCOMM.isend(data, dest=oppNode)
            reqs.append(s)

    # Reception
    for node in graph:
        #print rank, graph[node].keys()
        if rank in graph[node]:
            #print '%d: On doit recevoir de %d: %s'%(rank,node,graph[node][rank])
            data = KCOMM.recv(source=node)

            for z in data:  # data est une liste de zones
                if cartesian: Compressor._uncompressCartesian(z)
                #print '%d: recoit la zone %s.'%(rank,z[0])
                # tag z
                Internal.createChild(z, 'XZone', 'UserDefinedData_t')
                # Existe deja?
                zone = Internal.getNodeFromName2(t, z[0])
                if zone is not None:  # replace
                    bases = Internal.getBases(t)
                    for b in bases:
                        c = Internal.getNodePosition(zone, b)
                        if c != -1: b[2][c] = z
                else:  # append to first base
                    bases = Internal.getBases(t)
                    bases[0][2].append(z)
    MPI.Request.Waitall(reqs)
    return t
# - deltaInterpolations -
import numpy
import Compressor.PyTree as Compressor

# Liste des donnees d interpolations de reference
rcvIndices = numpy.array([1,2,3], dtype='int32')
donorIndices = numpy.array([1,5,6], dtype='int32')
periodicity = numpy.array([100,100,100], dtype='int32')
coefs1 = numpy.array([0.,0.,0.,0.,0.5,0.5,0.5], dtype='float')
coefs2 = numpy.array([0.,0.,0.,0.,0.5,0.5,0.5], dtype='float')
coefs3 = numpy.array([0.,0.,0.,0.,0.5,0.5,0.5], dtype='float')
coefficients = [coefs1,coefs2,coefs3]
indRef = [rcvIndices,donorIndices,periodicity,coefficients]

# Liste des donnees d interpolations a comparer a la reference
rcvIndices = numpy.array([2,3,4], dtype='int32')
donorIndices = numpy.array([5,6,7], dtype='int32')
periodicity = numpy.array([101,100,100], dtype='int32')
coefs2 = numpy.array([0.,0.,0.,0.,0.5,0.5,0.5], dtype='float')
coefs3 = numpy.array([0.,0.,0.,0.,0.5,0.5,0.5], dtype='float')
coefs4 = numpy.array([0.,0.,0.,0.,0.5,0.5,0.5], dtype='float')
coefficients = [coefs2,coefs3,coefs4]
index = [rcvIndices,donorIndices,periodicity,coefficients]

# Liste des indexes a comparer a la reference
delta = Compressor.deltaInterpolations(index, indRef, loc='cell')
print(delta)
Exemple #3
0
# - compressCartesian (pyTree) -
import Compressor.PyTree as Compressor
import Generator.PyTree as G
import Converter.Internal as Internal

a = G.cart((0,0,0), (1,1,1), (10,10,10))
Compressor._compressCartesian(a)
Internal.printTree(a)
def computeUnsteadyInterp(tp, hook, ite,loc='cell', nGhostCells=2):
    if loc == 'cell':
        ListDonor = 'PointListDonor'
        ListExtC = 'PointListExtC'
        InterpolantsDonor = 'InterpolantsDonor'
        InterpolantsType = 'InterpolantsType'
        FaceDirection=None
        iteration = hook[1]
        listInterpData = hook[4]
        ref = hook[7]
    else:
        ListDonor = 'FaceListDonor'
        ListExtC = 'FaceListExtC'
        InterpolantsDonor = 'FaceInterpolantsDonor'
        InterpolantsType = 'FaceInterpolantsType'
        FaceDirection='FaceDirection'
        iteration = hook[2]
        listInterpData = hook[5]
        ref = hook[8]
    zones = Internal.getNodesFromType(tp,'Zone_t')
    for z in zones:
        donorName = z[0]
        dim = Internal.getZoneDim(z)
        subRegions = Internal.getNodesFromType(z, 'ZoneSubRegion_t')
        interpolations=[]
        interpData = {}
        for s in subRegions:
            if 'ID_' in s[0]:interpolations.append(s)
        # la zone a une ou plusieurs interpolations
        if interpolations != []:
            if donorName not in iteration:
                iteration[donorName] = ite+1
                listInterpData[donorName] = []
                ref[donorName] = {}
            for interp in interpolations:
                rcvName = '_'.join(interp[0].split('_')[1:])
                rcvId = hook[9][rcvName]
                # cells
                if Internal.getNodeFromName1(interp, ListExtC) is not None :
                    donorIndices = Internal.getNodeFromName1(interp, ListExtC)[1]; 
                    donorIndices = donorIndices.reshape((donorIndices.shape[0]))
                    if donorIndices.shape[0] != 0: # avoid interpolation regions with only orphan points
                        coefs = Internal.getNodeFromName1(interp, InterpolantsDonor)[1][:,0:7]
                        rcvIndices = Internal.getNodeFromName1(interp, ListDonor)[1]; rcvIndices = rcvIndices.reshape((rcvIndices.shape[0]))
                        
                        periodicity =  Internal.getNodeFromName1(interp, InterpolantsType)[1]; periodicity= periodicity.reshape((periodicity.shape[0]))
                        if FaceDirection != None:
                            faceDir = Internal.getNodeFromName1(interp, FaceDirection)[1]; faceDir= faceDir.reshape((faceDir.shape[0]))
                        # cell index => faceIndex
                        if FaceDirection != None:
                            zRcv = Internal.getNodeFromName2(tp,rcvName) 
                            dimrcv = Internal.getZoneDim(zRcv)
                            imr = dimrcv[1];jmr = dimrcv[2];kmr = dimrcv[3]
                            imrg = imr-1 + 2*nGhostCells
                            jmrg = jmr-1 + 2*nGhostCells
                            kmrg = kmr-1 + 2*nGhostCells
                            nbintByDir = imrg*jmrg*kmrg
                            for i in xrange(len(rcvIndices)):
                                rk = rcvIndices[i]/((imr-1)*(jmr-1))
                                rj = (rcvIndices[i] - rk*(imr-1)*(jmr-1))/(imr-1)
                                ri = rcvIndices[i] - rk*(imr-1)*(jmr-1) - rj*(imr-1)+1
                                rj = rj+1; rk = rk+1
                                if faceDir[i] == 0: # imax (interface a droite)
                                    rcvIndices[i] = (rk-1 + nGhostCells)*imrg*jmrg+(rj-1 + nGhostCells)*imrg+ ri-1 + nGhostCells+1
                                elif faceDir[i] == 1: # imin (interface a gauche)
                                    rcvIndices[i] = (rk-1 + nGhostCells)*imrg*jmrg+(rj-1 + nGhostCells)*imrg+ ri-1 + nGhostCells
                                elif faceDir[i] == 2: # jmax
                                    rcvIndices[i] = (rk-1 + nGhostCells)*imrg*jmrg+(rj-1 + nGhostCells+1)*imrg+ ri-1 + nGhostCells + nbintByDir
                                elif faceDir[i] == 3: # jmin
                                    rcvIndices[i] = (rk-1 + nGhostCells)*imrg*jmrg+(rj-1 + nGhostCells)*imrg+ ri-1 + nGhostCells + nbintByDir
                                elif faceDir[i] == 4: # kmax
                                    rcvIndices[i] = (rk-1 + nGhostCells+1)*imrg*jmrg+(rj-1 + nGhostCells)*imrg+ ri-1 + nGhostCells + 2*nbintByDir
                                elif faceDir[i] == 5: # kmin
                                    rcvIndices[i] = (rk-1 + nGhostCells)*imrg*jmrg+(rj-1 + nGhostCells)*imrg+ ri-1 + nGhostCells + 2*nbintByDir
                        # First iteration of storage: full storage
                        if ite == 0 or listInterpData[donorName] == [] or rcvId not in listInterpData[donorName][-1].keys(): 
                            interpData[rcvId]={}
                            flag=0; i=0
                            if FaceDirection == None: # cell
                                for rcvIndex in rcvIndices:
                                    interpData[rcvId][(int)(rcvIndex)]=[flag,(int)(donorIndices[i]),(int)(periodicity[i])]+[(float)(c) for c in coefs[i]]; i = i+1
                            else: # face
                               for rcvIndex in rcvIndices:
                                    interpData[rcvId][(int)(rcvIndex)]=[flag,(int)(donorIndices[i]),(int)(periodicity[i])]+[(float)(c) for c in coefs[i]]+[(int)(faceDir[i])]; i = i+1                                
                        # delta storage
                        else: 
                            if FaceDirection == None: data=[rcvIndices,donorIndices,periodicity,coefs]
                            else: data=[rcvIndices,donorIndices,periodicity,coefs,faceDir]
                            delta = Co.deltaInterpolations(data, ref[donorName][rcvId],loc)
                            interpData[rcvId]=delta
                        # set reference of current iteration for next iteration
                        if FaceDirection == None: ref[donorName][rcvId] = [rcvIndices,donorIndices,periodicity, coefs]
                        else: ref[donorName][rcvId] = [rcvIndices,donorIndices,periodicity, coefs,faceDir]
            # Deals with rcv zones which have disappeared from interpolations
            for rcvId in ref[donorName].keys():
                if rcvId not in interpData.keys():
                    if FaceDirection ==None:
                        data=[numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.float64)]
                    else:
                        data=[numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.float64), numpy.array([], dtype= numpy.int32)]
                    delta = Co.deltaInterpolations(data, ref[donorName][rcvId],loc)
                    interpData[rcvId]=delta
                    ref[donorName][rcvId] = data
            listInterpData[donorName].append(interpData)
        # la zone a aucune interpolation
        elif donorName in listInterpData.keys():
            for rcvId in ref[donorName].keys():
                if FaceDirection ==None:
                    data=[numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.float64)]
                else:
                    data=[numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.int32), numpy.array([], dtype= numpy.float64), numpy.array([], dtype= numpy.int32)]
                delta = Co.deltaInterpolations(data, ref[donorName][rcvId],loc)
                interpData[rcvId]=delta
                ref[donorName][rcvId] = data
            listInterpData[donorName].append(interpData)
    return