def selectCells(event=None): if CTK.t == []: return if CTK.__MAINTREE__ <= 0: CTK.TXT.insert('START', 'Fail on a temporary tree.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return formula = VARS[0].get() strict = VARS[1].get() strict = int(strict) nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] z = P.selectCells(z, formula, strict=strict) CTK.replace(CTK.t, nob, noz, z) #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TXT.insert('START', 'Cells selected.\n') CTK.TKTREE.updateApp() CPlot.render()
def selectWithFormula(zones, formula): res = findVar('cellN') if res == 0: res = findVar('cellnf') if res == 0: return None if res == 1: formula = formula.replace('cellN', 'cellnf') if res == 2: formula = formula.replace('cellN', 'centers:cellnf') elif res == 2: formula = formula.replace('cellN', 'centers:cellN') if res == 1: # cellN en noeuds Z = P.selectCells(zones, formula) else: # cellN en centres Z = P.selectCells(zones, formula) for z in Z: z[0] = C.getZoneName(z[0]) return Z
def view(): if CTK.t == []: return type = VARS[0].get() if type == 'Mesh': CTK.display(CTK.t) return if CTK.__MAINTREE__ == 1: CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones() tp = Internal.appendBaseName2ZoneName(CTK.t, separator=Internal.SEP1) active = [] zones = Internal.getZones(tp) for z in CTK.__MAINACTIVEZONES__: active.append(zones[z]) Z = None if type == 'cf>1': Z = P.selectCells(active, Filter1, [ 'interpCoefs1', 'interpCoefs2', 'interpCoefs3', 'interpCoefs4', 'interpCoefs5', 'interpCoefs6', 'interpCoefs7', 'interpCoefs8' ]) elif type == 'cellN=-99999': Z = selectWithFormula(active, '{cellN} == -99999') elif type == 'cellN=1': Z = selectWithFormula(active, '{cellN} == 1') elif type == 'cellN=0': Z = selectWithFormula(active, '{cellN} == 0') elif type == 'cellN=2': Z = selectWithFormula(active, '{cellN} == 2') elif type == 'cellN<0': Z = selectWithFormula(active, '{cellN} < 0') elif type == '0<cellN<1': Z = selectWithFormula(active, '({cellN}>0) & ({cellN}<1)') elif type == 'Orphan points': Z = X.extractChimeraInfo(active, 'orphan') elif type == 'Extrapolated points': Z = X.extractChimeraInfo(active, 'extrapolated') if Z is not None: CTK.TXT.insert('START', 'Filter ' + type + ' displayed.\n') CTK.dt = C.newPyTree(['Base']) CTK.dt[2][1][2] += Z CTK.display(CTK.dt, mainTree=CTK.CELLN) else: CTK.TXT.insert('START', 'Nothing to display.\n') CTK.TXT.insert('START', 'Error: ', 'Error')
import Post.PyTree as P import KCore.test as test def F(x, y, z): if (x + 2 * y + z > 20.): return True else: return False # CAS 1D a = G.cart((0, 9, 0), (1, 1, 1), (11, 1, 1)) C._addVars(a, 'Density') C._addVars(a, 'centers:cellN') t = C.newPyTree(['Base', 1, a]) t[2][1] = C.addState(t[2][1], 'Mach', 0.6) t = P.selectCells(t, F, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) test.testT(t, 1) # CAS 2D a = G.cart((0, 0, 0), (1, 1, 1), (11, 11, 1)) C._addVars(a, 'Density') C._addVars(a, 'centers:cellN') a = C.addBC2Zone(a, 'ov', 'BCOverlap', 'imin') t = C.newPyTree(['Base', 2, a]) t[2][1] = C.addState(t[2][1], 'Mach', 0.6) t = P.selectCells(t, F, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) test.testT(t, 2) # CAS 3D a = G.cart((0, 0, 0), (1, 1, 1), (11, 11, 11)) C._addVars(a, 'Density')
# - selectCells (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Post.PyTree as P def F(x, y, z): if (x + 2 * y + z > 20.): return True else: return False a = G.cart((0, 0, 0), (1, 1, 1), (11, 11, 11)) a = P.selectCells(a, F, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) C.convertPyTree2File(a, 'out.cgns')
# - deleteEmptyZones (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Post.PyTree as P import KCore.test as test a = G.cart((0, 0, 0), (1, 1, 1), (3, 3, 3)) b = P.selectCells(a, '{CoordinateX} > 12') # Sur un pyTree tp = C.newPyTree(['Base', a, b]) tp = C.deleteEmptyZones(tp) test.testT(tp, 1) # Sur une liste de zones l = C.deleteEmptyZones([a, b]) print len(l)
(0, 1, 0), (0, 0, 1))) if coord=='CoordinateY': surf[2][1][2].append(T.symetrize(zone, (0., dico[coord], 0.), (1, 0, 0), (0, 0, 1))) if coord=='CoordinateZ': surf[2][1][2].append(T.symetrize(zone, (0., 0., dico[coord]), (1, 0, 0), (0, 1, 0))) snear+=snear octr = G.octree(surf, snear, dfar=5.) # select cells below X/Y/Z planes (can be modified for cells beyond planes) for coord in dico.keys(): octr = P.selectCells(octr, '{%s}<=%s'%(coord,dico[coord]), strict=1) octr=G.octree2Struct(octr, vmin=11, ext=0, optimized=0, merged=1, sizeMax=250000) carttree=C.newPyTree(['Cart', 3]) carttree[2][1][2]+=octr C.convertPyTree2File(carttree,'cart.cgns')
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
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
def display1D(event=None): if CTK.t == []: return # Get slot try: slot = int(VARS[5].get()) except: slot = 0 # Get grid size try: gridSize = VARS[1].get() grids = gridSize.split(';') if (len(grids) == 1): gridSize = (int(grids[0]), 1) else: gridSize = (int(grids[0]), int(grids[1])) except: gridSize = (1, 1) CPlot.setState(gridSize=gridSize) # Get grid pos try: gridPos = VARS[2].get() grids = gridPos.split(';') if (len(grids) == 1): gridPos = (int(grids[0]), 1) else: gridPos = (int(grids[0]), int(grids[1])) except: gridPos = (0, 0) # Recupere la direction pour la coupe ou 'Elements' dir = VARS[0].get() if dir == 'None': CPlot.display1D([], slot=slot) return # clear # Recupere le pt pour la coupe ou les elements 1D if dir == 'Elements': # elements -> recupere les elements if CTK.__MAINTREE__ <= 0: CTK.TXT.insert('START', 'Fail on a temporary tree.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return points = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] selected = CTK.t[2][nob][0] + '/' + z[0] points.append(selected) elif (dir == 'I' or dir == 'J' or dir == 'K'): # indice -> recupere les indices + la zone if (CTK.__MAINTREE__ <= 0): CTK.TXT.insert('START', 'Fail on a temporary tree.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return nz = CPlot.getSelectedZone() if (nz == -1): CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return points = [] nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] selected = CTK.t[2][nob][0] + '/' + z[0] index = CPlot.getActivePointIndex() points = (selected, index) else: # les coupes -> recupere les coord du pt point = CPlot.getActivePoint() if point == []: point = (0., 0., 0.) # Recupere les variables a afficher var1 = VARS[3].get() var1 = var1.replace('centers:', '') var2 = VARS[4].get() var2 = var2.replace('centers:', '') # Recupere les zones actives actives = [] zones = Internal.getZones(CTK.t) if CTK.__MAINTREE__ == 1: nzs = CPlot.getActiveZones() for nz in nzs: actives.append(zones[nz]) else: actives = zones if actives == []: return if (dir == 'X (Y)'): elts = P.isoSurfMC(actives, 'CoordinateY', point[1]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateZ', point[2]) if (elts2 != []): elts = elts2 elif (dir == 'Y (X)'): elts = P.isoSurfMC(actives, 'CoordinateX', point[0]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateZ', point[2]) if (elts2 != []): elts = elts2 elif (dir == 'Z (X)'): elts = P.isoSurfMC(actives, 'CoordinateX', point[0]) if (elts != []): elts2 = P.isoSurfMC(elts, 'CoordinateY', point[1]) if (elts2 != []): elts = elts2 elif (dir == 'X (Z)'): elts = P.isoSurfMC(actives, 'CoordinateZ', point[2]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateY', point[1]) if (elts2 != []): elts = elts2 elif (dir == 'Y (Z)'): elts = P.isoSurfMC(actives, 'CoordinateZ', point[2]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateX', point[0]) if (elts2 != []): elts = elts2 elif (dir == 'Z (Y)'): elts = P.isoSurfMC(actives, 'CoordinateY', point[1]) if (elts != []): elts2 = P.isoSurfMC(elts, 'CoordinateX', point[0]) if (elts2 != []): elts = elts2 elif (dir == 'I'): v = points[0] ind = points[1] v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) elts = [] if bases != []: zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): try: zp = C.center2Node(z, Internal.__FlowSolutionCenters__) zp = T.subzone(zp, (1, ind[3], ind[4]), (-1, ind[3], ind[4])) elts.append(zp) except: pass elif (dir == 'J'): v = points[0] ind = points[1] v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) elts = [] if bases != []: zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): try: zp = C.center2Node(z, Internal.__FlowSolutionCenters__) zp = T.subzone(zp, (ind[2], 1, ind[4]), (ind[2], -1, ind[4])) elts.append(zp) except: pass elif (dir == 'K'): v = points[0] ind = points[1] v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) elts = [] if bases != []: zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): try: zp = C.center2Node(z, Internal.__FlowSolutionCenters__) zp = T.subzone(zp, (ind[2], ind[3], 1), (ind[2], ind[3], -1)) elts.append(zp) except: pass elif (dir == 'Elements'): elts = [] for v in points: v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) if (bases != []): zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): elts.append(z) if elts == []: CTK.TXT.insert('START', 'Nothing to display.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return try: elts = D.getCurvilinearAbscissa(elts) except: pass # Fit first axis pos = WIDGETS['rangePos'].get() / 50. - 1. zoom = WIDGETS['rangeZoom'].get() / 120. minv1 = C.getMinValue(elts, var1) maxv1 = C.getMaxValue(elts, var1) if (maxv1 - minv1 < 1.e-6): maxv1 += 5.e-7 minv1 -= 5.e-7 # active point localisation nz = CPlot.getSelectedZone() if (nz != -1): ind = CPlot.getActivePointIndex() nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] f1 = C.getValue(z, var1, ind[0]) try: r1min = (f1 - minv1) * zoom + minv1 + pos * (1. - zoom) * (maxv1 - minv1) r1max = (f1 - maxv1) * zoom + maxv1 + pos * (1. - zoom) * (maxv1 - minv1) except: # var1 not found in z, le cherche dans elts xf1 = C.getValue(z, 'CoordinateX', ind[0]) yf1 = C.getValue(z, 'CoordinateY', ind[0]) zf1 = C.getValue(z, 'CoordinateZ', ind[0]) f1 = minv1 + 0.5 * (maxv1 - minv1) r1min = 0.5 * (maxv1 - minv1) * zoom + minv1 + pos * ( 1. - zoom) * (maxv1 - minv1) r1max = -0.5 * (maxv1 - minv1) * zoom + maxv1 + pos * ( 1. - zoom) * (maxv1 - minv1) else: f1 = minv1 + 0.5 * (maxv1 - minv1) r1min = 0.5 * (maxv1 - minv1) * zoom + minv1 + pos * (1. - zoom) * ( maxv1 - minv1) r1max = -0.5 * (maxv1 - minv1) * zoom + maxv1 + pos * (1. - zoom) * ( maxv1 - minv1) # Fit second axis p = P.selectCells( elts, '({%s} < %20.16g) & ({%s} > %20.16g)' % (var1, r1max, var1, r1min)) minv2 = C.getMinValue(p, var2) maxv2 = C.getMaxValue(p, var2) # display CPlot.display1D(p, slot=slot, bgBlend=0., gridPos=gridPos, var1=var1, var2=var2, r1=(r1min, r1max), r2=(minv2, maxv2)) CTK.TXT.insert('START', 'Plot displayed.\n')