Example #1
0
    def loadAndSplitSkeleton(self, NParts=None, NProc=None):
        """Load and split skeleton."""
        a = self.loadSkeleton()
        import Transform.PyTree as T
        # split on skeleton
        splitDict = {}
        if NParts is not None:
            b = T.splitNParts(a, N=NParts, splitDict=splitDict)
        else:
            b = T.splitNParts(a, N=NProc, splitDict=splitDict)
        self.splitDict = splitDict

        zones = Internal.getZones(b)
        if NProc is not None:
            import Distributor2.PyTree as D2
            D2._distribute(b, NProc)

        # Correction dims en attendant que subzone fonctionne sur un skel
        for z in zones:
            j = splitDict[z[0]]
            ni = j[2] - j[1] + 1
            nj = j[4] - j[3] + 1
            nk = j[6] - j[5] + 1
            d = numpy.empty((3, 3), numpy.int32, order='Fortran')
            d[0, 0] = ni
            d[1, 0] = nj
            d[2, 0] = nk
            d[0, 1] = ni - 1
            d[1, 1] = nj - 1
            d[2, 1] = nk - 1
            d[0, 2] = 0
            d[1, 2] = 0
            d[2, 2] = 0
            z[1] = d
            # END correction
        return a
Example #2
0
#!/usr/bin/env python
# coding: utf-8
r"""<TBC>"""

import Generator.PyTree as G
import Converter.PyTree as C
import Transform.PyTree as T
import Geom.PyTree as D

N = 4

# Donor mesh
a = G.cart((-2, -2, -2), (0.04, 0.04, 0.04), (200, 100, 100))
a = C.initVars(a, '{Density} = {CoordinateX}')
a = T.splitNParts(a, N=3 * N)
t = C.newPyTree(['Base'])
t[2][1][2] += a
C.convertPyTree2File(t, 'donor.cgns')

# Receiver mesh
b = D.sphere((1, 1, 1), 0.5, N=100)
b = T.splitNParts(b, N=N)
t = C.newPyTree(['Base'])
t[2][1][2] += b
C.convertPyTree2File(t, 'receiver.cgns')
# - splitNParts (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.PyTree as C
import KCore.test as test

# Structure + Champs + CL
a = G.cart((0, 0, 0), (1, 1, 1), (50, 20, 10))
a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin')
a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmin')
a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2, 3])
C._addVars(a, 'Density')
C._initVars(a, 'centers:cellN', 1)
t = C.newPyTree(['Base', a])
t = T.splitNParts(t, 4, multigrid=0, dirs=[1, 2, 3])
test.testT(t, 1)

# 2D Structure + Champs + CL
a = G.cart((0, 0, 0), (1, 1, 1), (50, 20, 2))
a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin')
a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmin')
a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2])
C._addVars(a, 'Density')
C._initVars(a, 'centers:cellN', 1)
t = C.newPyTree(['Base', 3, a])
t = T.splitNParts(t, 4, multigrid=0, dirs=[1, 2, 3])
test.testT(t, 2)

a = G.cart((0, 0, 0), (1, 1, 1), (81, 81, 81))
b = G.cart((80, 0, 0), (1, 1, 1), (41, 81, 41))
t = C.newPyTree(['Base', a, b])
Example #4
0
# - adapts a cells with respect to b points (PyTree) -
#
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.PyTree as C
import Converter.Internal as I
import Intersector.PyTree as XOR
import KCore.test as test

mesh = G.cart((0, 0, 0), (1, 1, 1), (20, 20, 20))
source = G.cart((8, 8, 8), (0.2, 0.2, 0.2), (20, 20, 20))
#C.convertPyTree2File(mesh, 'm.cgns')
#C.convertPyTree2File(source, 's.cgns')

t = C.newPyTree(['Base', mesh])
t = T.splitNParts(t, 2, multigrid=0, dirs=[1, 2, 3])

zones = I.getZones(t)
p1 = zones[0]
p1 = C.convertArray2Tetra(p1, split='withBarycenters')
p1 = C.convertArray2NGon(p1)

p2 = C.convertArray2NGon(zones[1])

mesh = XOR.booleanUnion(p1, p2)  #conformize the join
#C.convertPyTree2File(mesh, 'u.cgns')

m1 = XOR.adaptCells(mesh, source, sensor_type=0)
m1 = XOR.closeOctalCells(m1)
#C.convertPyTree2File(m1, 'out.cgns')
test.testT(m1, 1)
import Post.PyTree as P
import Post.Mpi as Pmpi
import Distributor2.PyTree as Distributor2
import Generator.PyTree as G
import Transform.PyTree as T
import KCore.test as test

# Create case
if Cmpi.rank == 0:
    ni = 100
    nj = 100
    nk = 100
    m = G.cart((0, 0, 0), (10. / (ni - 1), 10. / (nj - 1), 1), (ni, nj, nk))
    m = C.initVars(m, 'Density', 2.)
    m = C.initVars(m, 'centers:cellN', 1)
    m = T.splitNParts(m, 4)
    C.convertPyTree2File(m, 'in.cgns')

    # Extraction mesh
    a = G.cart((0., 0., 0.5), (1., 0.1, 1.), (20, 20, 1))
    a[0] = 'extraction'
    a = T.splitNParts(a, 2)
    C.convertPyTree2File(a, 'in2.cgns')
Cmpi.barrier()

# Extract solution on extraction mesh
m = Cmpi.convertFile2SkeletonTree('in.cgns')
(m, dic) = Distributor2.distribute(m, NProc=Cmpi.size, algorithm='fast')
m = Cmpi.readZones(m, 'in.cgns', rank=Cmpi.rank)

a = Cmpi.convertFile2SkeletonTree('in2.cgns')
Example #6
0
# - setDoublyDefinedBC (pyTree) -
import Converter.PyTree as C
import Connector.PyTree as X
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.Internal as Internal
a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 10))
b = G.cart((2.5, 2.5, -2.5), (0.5, 0.5, 0.5), (10, 10, 30))
b[0] = 'fente'
b = T.splitNParts(b, 2)
C._addBC2Zone(a,
              'overlap1',
              'BCOverlap',
              'kmin',
              zoneDonor=['FamilySpecified:FENTE'],
              rangeDonor='doubly_defined')
t = C.newPyTree(['Base1', 'Base2'])
t[2][1][2].append(a)
t[2][2][2] += b
C._addFamily2Base(t[2][2], 'FENTE')
for z in Internal.getZones(t[2][2]):
    C._tagWithFamily(z, 'FENTE')
C._initVars(t, 'centers:cellN', 1)
t = X.applyBCOverlaps(t)
t = X.setDoublyDefinedBC(t)
C.convertPyTree2File(t, 'out.cgns')
Example #7
0
# - adapt2FastP2 (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.PyTree as C
import Converter.Internal as Internal
import Connector.PyTree as X
import Converter.GhostCells as GC
import KCore.test as test

a = G.cartNGon((0, 0, 0), (1, 1, 1), (6, 6, 3))
b = T.splitNParts(a, N=3)
t = C.newPyTree(['Base', b])
t = X.connectMatch(t)
t = C.fillEmptyBCWith(t, 'wall', 'BCWall', dim=3)
Internal._adaptNFace2PE(t, remove=False)
# Test avec deux couches
t = GC.adapt2FastP2(t, nlayers=2)  # creation parentElement du NGon
test.testT(t, 1)
Example #8
0
def loadAndSplit(fileName,
                 NParts=None,
                 noz=None,
                 NProc=None,
                 rank=None,
                 variables=[]):
    if NParts is None: NParts = NProc
    if NProc is None: NProc = NParts
    import Transform.PyTree as T
    a = convertFile2SkeletonTree(fileName)
    # split on skeleton
    splitDict = {}
    b = T.splitNParts(a, N=NParts, splitDict=splitDict)

    zones = Internal.getZones(b)
    if rank is not None:
        import Distributor2.PyTree as D2
        D2._distribute(b, NProc)
        noz = []
        for i, z in enumerate(zones):
            p = D2.getProc(z)
            if p == rank: noz.append(i)

    f = {}
    for i in noz:
        z = zones[i]
        j = splitDict[z[0]]
        # Correction de dimension en attendant que subzone fonctionne sur un skel
        ni = j[2] - j[1] + 1
        nj = j[4] - j[3] + 1
        nk = j[6] - j[5] + 1
        ni1 = max(ni - 1, 1)
        nj1 = max(nj - 1, 1)
        nk1 = max(nk - 1, 1)
        d = numpy.empty((3, 3), numpy.int32, order='Fortran')
        d[0, 0] = ni
        d[1, 0] = nj
        d[2, 0] = nk
        d[0, 1] = ni1
        d[1, 1] = nj1
        d[2, 1] = nk1
        d[0, 2] = 0
        d[1, 2] = 0
        d[2, 2] = 0
        z[1] = d
        # END correction

        zname = z[0]  # zone name in b
        pname = zname.rsplit('.', 1)[0]  # parent name (guessed)
        (base, c) = Internal.getParentOfNode(b, z)
        bname = base[0]

        f = {}
        # Node fields
        path = []
        cont = Internal.getNodeFromName2(z, Internal.__GridCoordinates__)
        if cont is not None:
            for c in cont[2]:
                if c[3] == 'DataArray_t':
                    path += ['/%s/%s/%s/%s' % (bname, pname, cont[0], c[0])]
        cont = Internal.getNodeFromName2(z, Internal.__FlowSolutionNodes__)
        if cont is not None:
            for c in cont[2]:
                if c[3] == 'DataArray_t' and c[0] in variables:
                    path += ['/%s/%s/%s/%s' % (bname, pname, cont[0], c[0])]

        DataSpaceMMRY = [[0, 0, 0], [1, 1, 1], [ni, nj, nk], [1, 1, 1]]
        DataSpaceFILE = [[j[1] - 1, j[3] - 1, j[5] - 1], [1, 1, 1],
                         [ni, nj, nk], [1, 1, 1]]
        DataSpaceGLOB = [[0]]

        for p in path:
            f[p] = DataSpaceMMRY + DataSpaceFILE + DataSpaceGLOB

        # Center fields
        path = []
        cont = Internal.getNodeFromName2(z, Internal.__FlowSolutionCenters__)
        if cont is not None:
            for c in cont[2]:
                if c[3] == 'DataArray_t' and 'centers:' + c[0] in variables:
                    path += ['/%s/%s/%s/%s' % (bname, pname, cont[0], c[0])]

        DataSpaceMMRY = [[0, 0, 0], [1, 1, 1], [ni1, nj1, nk1], [1, 1, 1]]
        DataSpaceFILE = [[j[1] - 1, j[3] - 1, j[5] - 1], [1, 1, 1],
                         [ni1, nj1, nk1], [1, 1, 1]]
        DataSpaceGLOB = [[0]]

        for p in path:
            f[p] = DataSpaceMMRY + DataSpaceFILE + DataSpaceGLOB

        r = readNodesFromFilter(fileName, f)

        # Repositionne les chemins
        for k in r:
            k2 = k.replace(pname, zname)
            n = Internal.getNodeFromPath(b, k2)
            n[1] = r[k]

    b = convert2PartialTree(b)
    return b
Example #9
0
# - recoverGlobalIndex (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T

a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 10))
C._createGlobalIndex(a)

b = T.splitNParts(a, 2)
C._initVars(b[0], 'f=1')
C._initVars(b[1], 'f=2')

C._recoverGlobalIndex(a, b[0])
C._recoverGlobalIndex(a, b[1])
C._rmVars(a, 'globalIndex')

C.convertPyTree2File(a, 'out.cgns')
Example #10
0
# - splitNParts (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.PyTree as C
import KCore.test as test

# BC are not recovered
# Structure + Champs + CL
a = G.cart((0, 0, 0), (1, 1, 1), (50, 20, 10))
a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin')
a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmin')
a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2, 3])
C._initVars(a, 'centers:cellN', 1.)
t = C.newPyTree(['Base', a])
t = T.splitNParts(t, 4, multigrid=0, dirs=[1, 2, 3], recoverBC=0)
test.testT(t, 1)

# 2D Structure + Champs + CL
a = G.cart((0, 0, 0), (1, 1, 1), (50, 20, 2))
a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin')
a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmin')
a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2])
C._initVars(a, 'centers:cellN', 1)
t = C.newPyTree(['Base', a])
t = T.splitNParts(t, 4, multigrid=0, dirs=[1, 2, 3], recoverBC=0)
test.testT(t, 2)

a = G.cart((0, 0, 0), (1, 1, 1), (81, 81, 81))
b = G.cart((80, 0, 0), (1, 1, 1), (41, 81, 41))
t = C.newPyTree(['Base'])
t[2][1][2] = [a, b]