# cas 2D
c1 = G.cart((0, 0, 0), (0.01, 0.01, 1), (201, 101, 2))
c1 = C.addBC2Zone(c1, 'wall1', 'BCWall', 'imin')
c1 = C.addBC2Zone(c1, 'match1', 'BCMatch', 'imax', c1, 'imin', [1, 2, 3])
c1 = C.addBC2Zone(c1, 'overlap1', 'BCOverlap', 'jmax')
c1 = C.initVars(c1, 'centers:celln', 1.)
c1 = C.initVars(c1, 'Density', dens, ['CoordinateX', 'CoordinateY'])

c2 = G.cart((0, 0, 0), (0.01, 0.01, 1), (51, 81, 2))
c2 = T.rotate(c2, (0, 0, 0), (0, 0, 1), 0.2)
c2 = C.addBC2Zone(c2, 'wall1', 'BCWall', 'imin')
c2 = C.addBC2Zone(c2, 'overlap1', 'BCOverlap', 'imax')
c2 = C.initVars(c2, 'centers:celln', 1.)
c2 = C.initVars(c2, 'Density', dens, ['CoordinateX', 'CoordinateY'])
a = T.patch(c1, c2, (1, 1, 1))
t = C.newPyTree(['Base', 3])
t[2][1][2].append(a)
test.testT(t, 1)

# multizone
a = D.sphere6((0, 0, 0), 1, N=20)
t = C.newPyTree(['Base', 3])
t[2][1][2] += a
k = 0
t2 = T.subzone(t, (1, 1, k + 1), (-1, -1, k + 1))
t2 = T.smooth(t2,
              eps=0.5,
              niter=20,
              projConstraints=Internal.getNodesFromType(t2, 'Zone_t'))
t = T.patch(t, t2, (1, 1, k + 1))
# - patch (pyTree) -
import Transform.PyTree as T
import Generator.PyTree as G
import Converter.PyTree as C

c1 = G.cart((0, 0, 0), (0.01, 0.01, 1), (201, 101, 1))
c2 = G.cart((0, 0, 0), (0.01, 0.01, 1), (51, 81, 1))
a = T.patch(c1, c2, (1, 1, 1))
C.convertPyTree2File(a, 'out.cgns')
import Post.PyTree as P
import Generator.PyTree as G
import Transform.PyTree as T
import KCore.test as test

# cylindre
ni = 30
nj = 40
nk = 1
m1 = G.cylinder((0, 0, 0), 1, 5, 0., 360., 10., (50, 50, 1))
m1 = C.initVars(m1, 'cellN', 1.)
m1 = C.initVars(m1, 'centers:ichim', 1.)

# Set cellN = 2 (interpolated points) to boundary
s = T.subzone(m1, (1, nj, 1), (ni, nj, nk))
s = C.initVars(s, 'cellN', 2)
m1 = T.patch(m1, s, (1, nj, 1))

ni1 = m1[1][0][0]
nj1 = m1[1][0][1]
nk1 = nk
s = T.subzone(m1, (1, 1, 1), (ni1, 1, nk1))
s = C.initVars(s, 'cellN', 2)
m1 = T.patch(m1, s, (1, 1, 1))

# carre
m2 = G.cart((0, 0, 0), (10. / (ni - 1), 10. / (nj - 1), -1), (ni, nj, 1))
m2 = C.initVars(m2, 'cellN', 1.)
m2 = C.initVars(m2, 'Density', 1.2)
test.testT(m2)
im2 = 201
jm2 = 101
km2 = 2  # dimensions de la zone a patcher
# nodes: tableau des noeuds globaux correspondant au patch sur c1 en (1,1,1)
ip = 1
jp = 1
kp = 1
indp = (kp - 1) * im2 * jm2 + (jp - 1) * im2 + ip - 1
nodes = numpy.arange((im1 * jm1 * km1), dtype=numpy.int32)
c = 0
for k in xrange(0, km1):
    for j in xrange(0, jm1):
        for i in xrange(0, im1):
            nodes[c] = indp + k * im2 * jm2 + j * im2 + i + 1
            c += 1
a = T.patch(c1, c2, nodes=nodes)
t = C.newPyTree(['Base', 3])
t[2][1][2].append(a)
test.testT(t, 1)

# cas 3D
c1 = G.cart((0, 0, 0), (0.01, 0.01, 1), (201, 101, 20))
c1 = C.addBC2Zone(c1, 'wall1', 'BCWall', 'imin')
c1 = C.addBC2Zone(c1, 'match1', 'BCMatch', 'imax', c1, 'imin', [1, 2, 3])
c1 = C.addBC2Zone(c1, 'overlap1', 'BCOverlap', 'jmax')
c1 = C.initVars(c1, 'centers:celln', 1.)
c1 = C.initVars(c1, 'Density', dens, ['CoordinateX', 'CoordinateY'])

c2 = G.cart((0, 0, 0), (0.01, 0.01, 1), (51, 81, 20))
c2 = T.rotate(c2, (0, 0, 0), (0, 0, 1), 0.2)
c2 = C.addBC2Zone(c2, 'wall1', 'BCWall', 'imin')