def f(u, v, w): return 3 * u * v + 2 * w # test structure m = G.cylinder((0., 0., 0.), 0., 1., 0, 360, 1., (50, 20, 2)) m = C.addBC2Zone(m, 'overlap', 'BCOverlap', 'imin') m = C.fillEmptyBCWith(m, 'nref', 'BCFarfield') m = C.initVars(m, 'F', f, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) m = C.initVars(m, 'centers:G', 3.) #m = T.subzone(m,(1,20,1),(50,20,2)); m = G.close(m) : pb : voir extractPlanePT_t1.py t = C.newPyTree(['Base']) t[2][1] = C.addState(t[2][1], 'Mach', 0.6) t[2][1][2].append(m) t2 = P.extractPlane(t, (0., 0., 1., -0.5)) test.testT(t2, 1) # test non structure tetra m2 = C.convertArray2Tetra(m) m2 = C.initVars(m2, 'F', f, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) m2 = C.initVars(m2, 'centers:G', 3.) t = C.newPyTree(['Base']) t[2][1] = C.addState(t[2][1], 'Mach', 0.6) t[2][1][2].append(m2) t2 = P.extractPlane(t, (0., 0., 1., -0.5)) test.testT(t2, 2) # test non structure hexa m2 = C.convertArray2Hexa(m) m2 = C.initVars(m2, 'F', f, ['CoordinateX', 'CoordinateY', 'CoordinateZ'])
import Transform.PyTree as T import KCore.test as test def f(u, v, w): return 3 * u * v + 2 * w # test structure m = G.cylinder((0., 0., 0.), 0., 1., 0, 360, 1., (50, 20, 2)) C._addBC2Zone(m, 'overlap', 'BCOverlap', 'imin') C._fillEmptyBCWith(m, 'nref', 'BCFarfield') C._initVars(m, 'F', f, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) C._initVars(m, 'centers:G', 3.) #m = T.subzone(m,(1,20,1),(50,20,2)); m = G.close(m) : ne fonctionne pas car center2Node pour une dimension (ni,1,2) -> (ni,1,1) -> (ni+1,1,1) p = P.extractPlane(m, (0., 0., 1., -0.5)) test.testT(p, 1) # test non structure tetra m2 = C.convertArray2Tetra(m) C._initVars(m2, 'F', f, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) C._initVars(m2, 'centers:G', 3.) p = P.extractPlane(m2, (0., 0., 1., -0.5)) test.testT(p, 2) # test non structure hexa m2 = C.convertArray2Hexa(m) C._initVars(m2, 'F', f, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) C._initVars(m2, 'centers:G', 3.) p = P.extractPlane(m2, (0., 0., 1., -0.5)) test.testT(p, 3)
def view(event=None): if CTK.t == []: return pos = float(VARS[1].get()) global VALUE VALUE = pos delta = float(VARS[4].get()) global DELTA DELTA = delta plane = VARS[0].get() order = int(VARS[3].get()) eps = float(VARS[2].get()) algo = VARS[5].get() nzs = CPlot.getSelectedZones() if nzs != []: point = CPlot.getActivePoint() if len(point) == 3: if plane == 'X': pos = point[0] elif plane == 'Y': pos = point[1] elif plane == 'Z': pos = point[2] VARS[1].set(str(pos)) VALUE = pos if plane == 'Mesh': CTK.display(CTK.t) return try: if CTK.__MAINTREE__ == 1: CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones() active = [] tp = Internal.appendBaseName2ZoneName(CTK.t, updateRef=False, separator=Internal.SEP1) for z in CTK.__MAINACTIVEZONES__: active.append(tp[2][CTK.Nb[z] + 1][2][CTK.Nz[z]]) temp = C.newPyTree(['Base']) temp[2][1][2] += active if plane == 'X' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateX', pos) elif plane == 'Y' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateY', pos) elif plane == 'Z' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateZ', pos) elif plane == 'X' and algo == 'Slice2': p = P.extractPlane(active, (1, 0, 0, -pos), order=order, tol=eps) elif plane == 'Y' and algo == 'Slice2': p = P.extractPlane(active, (0, 1, 0, -pos), order=order, tol=eps) elif plane == 'Z' and algo == 'Slice2': p = P.extractPlane(active, (0, 0, 1, -pos), order=order, tol=eps) elif plane == 'X' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateX}>=' + str(VALUE)) elif plane == 'Y' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateY}>=' + str(VALUE)) elif plane == 'Z' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateZ}>=' + str(VALUE)) elif plane == 'X' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateX}<=' + str(VALUE)) elif plane == 'Y' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateY}<=' + str(VALUE)) elif plane == 'Z' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateZ}<=' + str(VALUE)) elif plane == 'X' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateX}>=' + str(VALUE - DELTA) + ') & ({CoordinateX}<=' + str(VALUE + DELTA) + ')') elif plane == 'Y' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateY}>=' + str(VALUE - DELTA) + ') & ({CoordinateY}<=' + str(VALUE + DELTA) + ')') elif plane == 'Z' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateZ}>=' + str(VALUE - DELTA) + ') & ({CoordinateZ}<=' + str(VALUE + DELTA) + ')') CTK.dt = C.newPyTree(['Base']) if algo == 'Slice1': CTK.dt[2][1][2] += p elif algo == 'Slice2': CTK.dt[2][1][2] += [p] else: CTK.dt[2][1][2] += p[2][1][2] CTK.display(CTK.dt, mainTree=CTK.SLICE) if CTK.TKPLOTXY is not None: CTK.TKPLOTXY.updateApp() except ValueError: CTK.TXT.insert('START', 'Intersection is empty.\n') return except Exception as e: Panels.displayErrors([0, str(e)], header='Error: slice') CTK.TXT.insert('START', 'Slice failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return
# - extractPlane (pyTree) - import Converter.PyTree as C import Post.PyTree as P import Transform.PyTree as T import Generator.PyTree as G m = G.cylinder((0, 0, 0), 1, 5, 0., 360., 10., (50, 50, 50)) m = T.rotate(m, (0, 0, 0), (1, 0, 0), 35.) m = C.initVars(m, 'Density', 1) m = C.initVars(m, 'centers:cellN', 1) z = P.extractPlane(m, (0.5, 1., 0., 1), 2) C.convertPyTree2File(z, 'out.cgns')
def extract(event=None): if CTK.t == []: return pos = float(VARS[1].get()) global VALUE VALUE = pos delta = float(VARS[4].get()) global DELTA DELTA = delta plane = VARS[0].get() order = int(VARS[3].get()) eps = float(VARS[2].get()) algo = VARS[5].get() nzs = CPlot.getSelectedZones() if nzs != []: point = CPlot.getActivePoint() if plane == 'X': pos = point[0] elif plane == 'Y': pos = point[1] elif plane == 'Z': pos = point[2] VARS[1].set(str(pos)) VALUE = pos if plane == 'Mesh': return try: CTK.saveTree() if CTK.__MAINTREE__ == 1: CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones() active = [] zones = Internal.getZones(CTK.t) for z in CTK.__MAINACTIVEZONES__: active.append(zones[z]) temp = C.newPyTree(['Base']) temp[2][1][2] += active if plane == 'X' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateX', pos) elif plane == 'Y' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateY', pos) elif plane == 'Z' and algo == 'Slice1': p = P.isoSurfMC(active, 'CoordinateZ', pos) elif plane == 'X' and algo == 'Slice2': p = P.extractPlane(active, (1, 0, 0, -pos), order=order, tol=eps) elif plane == 'Y' and algo == 'Slice2': p = P.extractPlane(active, (0, 1, 0, -pos), order=order, tol=eps) elif plane == 'Z' and algo == 'Slice2': p = P.extractPlane(active, (0, 0, 1, -pos), order=order, tol=eps) elif plane == 'X' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateX}>=' + str(VALUE)) elif plane == 'Y' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateY}>=' + str(VALUE)) elif plane == 'Z' and algo == 'Select+': p = P.selectCells(temp, '{CoordinateZ}>=' + str(VALUE)) elif plane == 'X' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateX}<=' + str(VALUE)) elif plane == 'Y' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateY}<=' + str(VALUE)) elif plane == 'Z' and algo == 'Select-': p = P.selectCells(temp, '{CoordinateZ}<=' + str(VALUE)) elif plane == 'X' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateX}>=' + str(VALUE - DELTA) + ') & ({CoordinateX}<=' + str(VALUE + DELTA) + ')') elif plane == 'Y' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateY}>=' + str(VALUE - DELTA) + ') & ({CoordinateY}<=' + str(VALUE + DELTA) + ')') elif plane == 'Z' and algo == 'Select=': p = P.selectCells( temp, '({CoordinateZ}>=' + str(VALUE - DELTA) + ') & ({CoordinateZ}<=' + str(VALUE + DELTA) + ')') CTK.t = C.addBase2PyTree(CTK.t, 'EXTRACT', 2) base = Internal.getNodeFromName1(CTK.t, 'EXTRACT') if algo == 'Slice1': for i in p: i[0] = C.getZoneName(i[0]) base[2] += p elif algo == 'Slice2': p[0] = C.getZoneName(p[0]) base[2] += [p] else: p = C.deleteEmptyZones(p) for i in p[2][1][2]: i[0] = C.getZoneName(i[0]) base[2] += p[2][1][2] #C._fillMissingVariables(CTK.t) CTK.TXT.insert('START', 'Slice extracted.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t) if CTK.TKPLOTXY is not None: CTK.TKPLOTXY.updateApp() except ValueError: CTK.TXT.insert('START', 'Intersection is empty.\n') return except Exception as e: Panels.displayErrors([0, str(e)], header='Error: slice') CTK.TXT.insert('START', 'Slice failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return