import Geom.PyTree as D
import Generator.PyTree as G
import numpy
import KCore.test as test
DEPTH = 2
snear = 0.4
vmin = 21

# Init wall
body = D.circle((0, 0, 0), 1., N=60)
res = G.octree([body], [snear], dfar=5., balancing=1)
res = G.octree2Struct(res, vmin=vmin, ext=DEPTH + 1, merged=1)
t = C.newPyTree(['Base', res])

# Mark solid and fluid points
X._applyBCOverlaps(t, depth=DEPTH, loc='nodes')
tc = Internal.copyRef(t)
tc = X.setInterpData(t, tc, loc='nodes', storage="inverse")
C._initVars(t, "cellN", 1.)
t = X.blankCells(t, [[body]], numpy.array([[1]]), blankingType='node_in')
X._setHoleInterpolatedPoints(t, depth=1, loc='nodes')
C._initVars(t, '{flag}=({cellN}>1.)')
t = DTW.distance2WallsEikonal(t, body, tc=tc, DEPTH=DEPTH, nitmax=10)
test.testT(t, 1)
# aux centres
t = C.newPyTree(['Base'])
t[2][1][2] = res
Internal._rmNodesFromName(t, "FlowSolution")
# Mark solid and fluid points
X._applyBCOverlaps(t, depth=DEPTH, loc='centers')
tc = C.node2Center(t)
a = G.cylinder((0, 0, 0), 1., 1.5, 360., 0., 1., (30, 30, 10))
# --- CL
a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmin')
# --- champ aux noeuds
C._initVars(a, 'Density', 1.)
t = C.newPyTree(['Base', a])
# --- Equation state
t[2][1] = C.addState(t[2][1], 'EquationDimension', 3)
# --- Apply on PyTree
t1 = X.applyBCOverlaps(t, depth=1, loc='centers')
test.testT(t1, 1)

# in place
C._initVars(t, "centers:cellN=1")
X._applyBCOverlaps(t, depth=1, loc='centers', checkCellN=False)
test.testT(t, 1)

# --- Apply on a zone
a2 = X.applyBCOverlaps(a, depth=1, loc='centers')
t2 = C.newPyTree(['Base', a2])
test.testT(t2, 2)

# depth = 2
t = C.newPyTree(['Base', a])
# --- Equation state
t[2][1] = C.addState(t[2][1], 'EquationDimension', 3)
# --- CL
t2 = X.applyBCOverlaps(t, depth=2, loc='centers')
test.testT(t2, 3)