def makeDirect(): 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 nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return CTK.saveTree() fail = False; errors = [] for nz in nzs: nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] try: a = T.makeDirect(z) CTK.replace(CTK.t, nob, noz, a) except Exception as e: fail = True; errors += [0,str(e)] if not fail: CTK.TXT.insert('START', 'Zones made direct.\n') else: Panels.displayErrors(errors, header='Error: makeDirect') CTK.TXT.insert('START', 'MakeDirect fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') CTK.TKTREE.updateApp() CPlot.render()
def convert2Tetra(): 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 nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() fail = False errors = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] try: a = C.convertArray2Tetra(CTK.t[2][nob][2][noz]) CTK.replace(CTK.t, nob, noz, a) except Exception as e: fail = True errors += [0, str(e)] if not fail: CTK.TXT.insert('START', 'Zones converted to tetra.\n') else: Panels.displayErrors(errors, header='Error: convert2Tetra') CTK.TXT.insert('START', 'Tetra conversion fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def setAll(): 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 material = VARS[0].get() color = VARS[1].get() blending = WIDGETS['blending'].get() / 100. VARS[6].set('Blending [%.2f].' % blending) meshOverlay = VARS[3].get() shaderParameter2 = (WIDGETS['param2'].get()) / 50. shaderParameter1 = (WIDGETS['param1'].get()) / 50. 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] a = CPlot.addRender2Zone( CTK.t[2][nob][2][noz], material=material, color=color, blending=blending, shaderParameters=[shaderParameter1, shaderParameter2]) CTK.replace(CTK.t, nob, noz, a) CTK.TKTREE.updateApp() Panels.updateRenderPanel() CPlot.render()
def setShaderParameter(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 shaderParameter2 = (WIDGETS['param2'].get()) / 50. shaderParameter1 = (WIDGETS['param1'].get()) / 50. VARS[4].set('Shader parameter 1 [%.2f].' % shaderParameter1) VARS[5].set('Shader parameter 2 [%.2f].' % shaderParameter2) 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] a = CPlot.addRender2Zone( CTK.t[2][nob][2][noz], shaderParameters=[shaderParameter1, shaderParameter2]) CTK.replace(CTK.t, nob, noz, a) CTK.TKTREE.updateApp() Panels.updateRenderPanel() CPlot.render()
def smooth1D(niter, eps): fail = False nzs = CPlot.getSelectedZones() for nz in nzs: nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] dims = Internal.getZoneDim(z) try: if dims[0] == 'Unstructured': a = C.convertBAR2Struct(z) else: a = z a = D.getCurvilinearAbscissa(a) distrib = C.cpVars(a, 's', a, 'CoordinateX') C._initVars(distrib, 'CoordinateY', 0.) C._initVars(distrib, 'CoordinateZ', 0.) distrib = C.rmVars(distrib, 's') bornes = P.exteriorFaces(distrib) distrib = T.smooth(distrib, eps=eps, niter=niter, fixedConstraints=[bornes]) b = G.map(a, distrib) CTK.replace(CTK.t, nob, noz, b) except Exception as e: fail = True Panels.displayErrors([0,str(e)], header='Error: smooth1D') return fail
def streamRibbon(): if CTK.t == []: return npts = CTK.varsFromWidget(VARS[0].get(), type=2) if len(npts) != 1: CTK.TXT.insert('START', 'Number of points in stream incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return npts = npts[0] v1 = VARS[1].get() v2 = VARS[2].get() v3 = VARS[3].get() CTK.TXT.insert('START', 'Click to select starting point...\n') l = [] while (l == []): l = CPlot.getActivePoint() time.sleep(0.1) print('Ribbon: starting point %d' % l) CTK.saveTree() CTK.t = C.addBase2PyTree(CTK.t, 'STREAMS', 2) b = Internal.getNodesFromName1(CTK.t, 'STREAMS') nob = C.getNobOfBase(b[0], CTK.t) try: stream = P.streamRibbon(CTK.t, (l[0], l[1], l[2]), (0, 0, 0.01), [v1, v2, v3], N=npts) CTK.add(CTK.t, nob, -1, stream) CTK.TXT.insert('START', 'Stream ribbon created.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: streamRibbon') CTK.TXT.insert('START', 'Stream ribbon fails.\n') CTK.TXT.insert('START', 'Error: ', 'Error') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t)
def compute(): if CTK.t == []: return nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return surf = 0 walls = [] name = VARS[1].get() if name == '': names = [] else: names = name.split(';') for v in names: surf = 1 v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) if bases != []: nodes = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in nodes: if z[0] == sname[1]: walls.append(z) if surf == 0: walls = C.extractBCOfType(CTK.t, 'BCWall') walls += C.extractBCOfType(CTK.t, 'BCWallViscous') walls += C.extractBCOfType(CTK.t, 'BCWallInviscid') tp = C.newPyTree(['Base']) for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] tp[2][1][2].append(z) try: if (VARS[2].get() == 'absolute'): signed = 0 else: signed = 1 tp = DTW.distance2Walls(tp, walls, type=VARS[0].get(), loc=VARS[3].get(), signed=signed) c = 0 for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] CTK.t[2][nob][2][noz] = tp[2][1][2][c] c += 1 #C._fillMissingVariables(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t) CTK.TXT.insert('START', 'Distance to walls computed.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: dist2Walls') CTK.TXT.insert('START', 'Distance to walls failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error')
def connectNearMatch(): if CTK.t == []: return eps = VARS[2].get() eps = float(eps) ratio = VARS[3].get() ratio = CTK.varsFromWidget(ratio, type=2) if len(ratio) != 1 and len(ratio) != 3: CTK.TXT.insert('START', 'Invalid ratio for nearmatch.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return if len(ratio) == 1: ratio = ratio[0] node = Internal.getNodeFromName(CTK.t, 'EquationDimension') if node is not None: ndim = Internal.getValue(node) else: CTK.TXT.insert('START', 'EquationDimension not found (tkState). Using 3D.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') ndim = 3 nzs = CPlot.getSelectedZones() CTK.saveTree() if CTK.__MAINTREE__ <= 0 or nzs == []: try: CTK.t = X.connectNearMatch(CTK.t, ratio=ratio, tol=eps, dim=ndim) CTK.TKTREE.updateApp() CTK.TXT.insert('START', 'n/m matching BCs successfully set.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: connectNearMatch') CTK.TXT.insert('START', 'n/m matching BCs failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') else: sel = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] sel.append(z) try: sel = X.connectNearMatch(sel, ratio=ratio, tol=eps, dim=ndim) c = 0 for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] CTK.t[2][nob][2][noz] = sel[c] c += 1 CTK.TKTREE.updateApp() CTK.TXT.insert('START', 'n/m matching BCs successfully set.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: connectNearMatch') CTK.TXT.insert('START', 'n/m matching BCs failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') check()
def extrudeWCurve(mode=0): 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 # - curve - name = VARS[3].get() names = name.split(';') curve = [] for v in names: v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) if bases != []: nodes = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in nodes: if z[0] == sname[1]: curve.append(z) if len(curve) == 0: CTK.TXT.insert('START', 'Curve is incorrect.\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 CTK.saveTree() fail = False errors = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] try: if mode == 0: z = D.lineDrive(z, curve) else: z = D.orthoDrive(z, curve) CTK.replace(CTK.t, nob, noz, z) except Exception as e: fail = True errors += [0, str(e)] if not fail: CTK.TXT.insert('START', 'Mesh extruded with curve(s).\n') else: Panels.displayErrors(errors, header='Error: extrusion') CTK.TXT.insert('START', 'Extrusion fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def union(): 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 nzs = CPlot.getSelectedZones() if len(nzs) < 2: CTK.TXT.insert('START', 'Please, select two or more surfaces.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return tol = CTK.varsFromWidget(VARS[0].get(), type=1) if len(tol) != 1: CTK.TXT.insert('START', 'Tolerance is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return tol = tol[0] CTK.saveTree() zlist = [] deletedZoneNames = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] deletedZoneNames.append(CTK.t[2][nob][0] + Internal.SEP1 + CTK.t[2][nob][2][noz][0]) z = CTK.t[2][nob][2][noz] zlist.append(z) try: j = XOR.booleanUnion(zlist[0], zlist[1], tol=tol) except Exception as e: Panels.displayErrors([0, str(e)], header='Error: union') CTK.TXT.insert('START', 'Union failed\n') return for nz in range(len(zlist) - 2): try: j = XOR.booleanUnion(j, zlist[nz + 2], tol=tol) except Exception as e: Panels.displayErrors([0, str(e)], header='Error: union') CTK.TXT.insert('START', 'Union failed.\n') return CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs) CPlot.delete(deletedZoneNames) CTK.add(CTK.t, CTK.Nb[0] + 1, -1, j) CTK.TXT.insert('START', 'Union performed.\n') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def dirProject(): 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 # surfaces name = VARS[0].get() names = name.split(';') surfaces = [] for v in names: v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) if (bases != []): nodes = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in nodes: if (z[0] == sname[1]): surfaces.append(z) if (surfaces == []): CTK.TXT.insert('START', 'Projection surface is empty.\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 eye = CPlot.getState('posEye') cam = CPlot.getState('posCam') dir = (eye[0] - cam[0], eye[1] - cam[1], eye[2] - cam[2]) CTK.saveTree() fail = False errors = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] try: a = T.projectDir(z, surfaces, dir) CTK.replace(CTK.t, nob, noz, a) except Exception as e: fail = True errors += [0, str(e)] if (fail == False): CTK.TXT.insert('START', 'Zones projected.\n') else: Panels.displayErrors(errors, header='Error: projectDir') CTK.TXT.insert('START', 'Projection fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') CTK.TKTREE.updateApp() CPlot.render()
def extractIsoLine(): 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 field = VARS[0].get() value = VARS[2].get() try: value = float(value) except: value = 1. nzs = CPlot.getSelectedZones() CTK.saveTree() if nzs == []: z = Internal.getZones(CTK.t) else: z = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z.append(CTK.t[2][nob][2][noz]) isos = [] fail = False errors = [] for zone in z: try: i = P.isoLine(zone, field, value) isos.append(i) except Exception as e: fail = True errors += [0, str(e)] CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1) bases = Internal.getNodesFromName1(CTK.t, 'CONTOURS') nob = C.getNobOfBase(bases[0], CTK.t) for i in isos: CTK.add(CTK.t, nob, -1, i) if (fail == False): CTK.TXT.insert('START', 'Isolines extracted.\n') else: Panels.displayErrors(errors, header='Error: Isolines') CTK.TXT.insert('START', 'Isolines fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def streamSurface(): 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 npts = CTK.varsFromWidget(VARS[0].get(), type=2) if (len(npts) != 1): CTK.TXT.insert('START', 'Number of points in stream incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return npts = npts[0] nzs = CPlot.getSelectedZones() if (nzs == []): CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return v1 = VARS[1].get() v2 = VARS[2].get() v3 = VARS[3].get() streams = [] fail = False errors = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] z = C.convertArray2Tetra(z) try: stream = P.streamSurf(CTK.t, z, [v1, v2, v3], N=npts) streams.append(stream) except Exception as e: fail = True errors += [0, str(e)] CTK.saveTree() CTK.t = C.addBase2PyTree(CTK.t, 'STREAMS', 2) b = Internal.getNodesFromName1(CTK.t, 'STREAMS') nob = C.getNobOfBase(b[0], CTK.t) for i in streams: CTK.add(CTK.t, nob, -1, i) if (fail == False): CTK.TXT.insert('START', 'Stream surface created.\n') else: Panels.displayErrors(errors, header='Error: streamSurf') CTK.TXT.insert('START', 'Sream surface fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def splitAndDistribute(event=None): global STATS if CTK.t == []: return try: NProc = int(VARS[0].get()) except: CTK.TXT.insert('START', 'distribute: NProc is invalid.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return try: comSpeed = float(VARS[1].get()) except: CTK.TXT.insert('START', 'distribute: ComSpeed is invalid.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return algo = VARS[2].get() useCom = VARS[3].get() level = int(VARS[5].get()) CTK.saveTree() try: #CTK.t = T.splitNParts(CTK.t, NProc, multigrid=level) CTK.t = T.splitSize(CTK.t, N=0, multigrid=level, R=NProc, type=2) # no need to check inconsistant match (they have been deleted) node = Internal.getNodeFromName(CTK.t, 'EquationDimension') if node is not None: ndim = Internal.getValue(node) # Manque le reglage de la tol else: CTK.TXT.insert( 'START', 'EquationDimension not found (tkState). Using 3D.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') ndim = 3 CTK.t = X.connectMatch(CTK.t, dim=ndim) CTK.display(CTK.t) except Exception as e: Panels.displayErrors([0, str(e)], header='Error: distribute/split') CTK.TXT.insert('START', 'splitSize fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.t, STATS = D.distribute(CTK.t, NProc, perfo=(1., 0., comSpeed), useCom=useCom, algorithm=algo) CTK.TXT.insert('START', 'Blocks split and distributed.\n') CTK.TKTREE.updateApp() updateStats()
def computeNormGrad(): if CTK.t == []: return varname = VARS[2].get() CTK.saveTree() try: CTK.t = P.computeNormGrad(CTK.t, varname) except Exception as e: Panels.displayErrors([0, str(e)], header='Error: computeNormGrad') CTK.TXT.insert('START', 'Gradient\'s norm computation failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.TXT.insert('START', 'Gradient\'s norm of %s computed.\n' % varname) CTK.TKTREE.updateApp() CTK.display(CTK.t) if CTK.TKPLOTXY is not None: CTK.TKPLOTXY.updateApp()
def copyDistrib1D(source): fail = False nzs = CPlot.getSelectedZones() errors = [] for nz in nzs: nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] try: zp = G.map(z, source, 1) CTK.replace(CTK.t, nob, noz, zp) except Exception as e: fail = True; errors += [0,str(e)] if len(errors)>0: Panels.displayErrors(errors, header='Error: copyDistrib1D') return fail
def generatePLM(): 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 nzs = CPlot.getSelectedZones() if len(nzs) == 0: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return hf = CTK.varsFromWidget(VARS[1].get(), type=1) if (len(hf) != 1): CTK.TXT.insert('START', 'First cell height is incorrect.\n') return hf = hf[0] h = CTK.varsFromWidget(VARS[0].get(), type=1) if (len(h) != 1): CTK.TXT.insert('START', 'Mesh height is incorrect.\n') return h = h[0] density = CTK.varsFromWidget(VARS[2].get(), type=1) if (len(density) != 1): CTK.TXT.insert('START', 'Grid point density is incorrect.\n') return density = density[0] try: CTK.saveTree() CTK.t = C.addBase2PyTree(CTK.t, 'MESHES') bases = Internal.getNodesFromName1(CTK.t, 'MESHES') gnob = C.getNobOfBase(bases[0], CTK.t) for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] B = G.polyLineMesher(z, h, hf, density) for i in B[0]: CTK.add(CTK.t, gnob, -1, i) CTK.TXT.insert('START', 'PLM mesh created.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render() except Exception, e: Panels.displayErrors([0, str(e)], header='Error: PLM') CTK.TXT.insert('START', 'PLM mesh failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error')
def difference2(): 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 nzs = CPlot.getSelectedZones() if len(nzs) != 2: CTK.TXT.insert('START', 'Please, select two surfaces.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return tol = CTK.varsFromWidget(VARS[0].get(), type=1) if len(tol) != 1: CTK.TXT.insert('START', 'Tolerance is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return tol = tol[0] CTK.saveTree() deletedZoneNames = [] nz = nzs[0] nob1 = CTK.Nb[nz] + 1 noz1 = CTK.Nz[nz] deletedZoneNames.append(CTK.t[2][nob1][0] + Internal.SEP1 + CTK.t[2][nob1][2][noz1][0]) z1 = CTK.t[2][nob1][2][noz1] nz = nzs[1] nob2 = CTK.Nb[nz] + 1 noz2 = CTK.Nz[nz] deletedZoneNames.append(CTK.t[2][nob2][0] + Internal.SEP1 + CTK.t[2][nob2][2][noz2][0]) z2 = CTK.t[2][nob2][2][noz2] try: j = XOR.booleanMinus(z2, z1, tol=tol) CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs) CPlot.delete(deletedZoneNames) CTK.add(CTK.t, nob1, -1, j) CTK.TXT.insert('START', 'Difference performed.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: difference') CTK.TXT.insert('START', 'Difference failed.\n') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def initWallDistance(): if CTK.t == []: return bodies = C.extractBCOfType(CTK.t, 'BCWall') for c in range(len(bodies)): try: bodies[c] = C.node2ExtCenter(bodies[c]) except: pass tb = C.newPyTree(['Base', 2]); tb[2][1][2] += bodies CTK.saveTree() try: CTK.t = DW.distance2Walls(CTK.t, tb, loc='centers', type='ortho') CTK.TXT.insert('START', 'Distance to wall computed.\n') except Exception as e: Panels.displayErrors([0,str(e)], header='Error: wallDistance') CTK.TXT.insert('START', 'Wall distance fails.\n') CTK.TXT.insert('START', 'Error: ', 'Error') CTK.TKTREE.updateApp() CTK.display(CTK.t)
def computeCurl(): if CTK.t == []: return vars = VARS[3].get() vars = vars.replace(' ', '') vars = vars.split(';') CTK.saveTree() try: CTK.t = P.computeCurl(CTK.t, vars) except Exception as e: Panels.displayErrors([0, str(e)], header='Error: computeCurl') CTK.TXT.insert('START', 'Curl computation failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.TXT.insert('START', 'Curl computed.\n') CTK.TKTREE.updateApp() CTK.display(CTK.t) if CTK.TKPLOTXY is not None: CTK.TKPLOTXY.updateApp()
def setDegeneratedBC(): if CTK.t == []: return eps = VARS[2].get() eps = float(eps) node = Internal.getNodeFromName(CTK.t, 'EquationDimension') if node is not None: ndim = Internal.getValue(node) else: CTK.TXT.insert('START', 'EquationDimension not found (tkState). Using 3D.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') ndim = 3 nzs = CPlot.getSelectedZones() CTK.saveTree() if CTK.__MAINTREE__ <= 0 or nzs == []: try: CTK.t = X.setDegeneratedBC(CTK.t, tol=eps, dim=ndim) CTK.TKTREE.updateApp() CTK.TXT.insert('START', 'Degenerated BCs successfully set.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: setDegenratedBC') CTK.TXT.insert('START', 'Degenerated BCs failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') else: sel = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] sel.append(z) try: sel = X.setDegeneratedBC(sel, tol=eps, dim=ndim) c = 0 for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] CTK.t[2][nob][2][noz] = sel[c] c += 1 CTK.TKTREE.updateApp() CTK.TXT.insert('START', 'Degenerated BCs successfully set.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: setDegeneratedBC') CTK.TXT.insert('START', 'Degenerated BCs failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') check()
def reorderAll(): 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 ii = VARS[0].get() if (ii == 'I -> I'): i1 = 1 elif (ii == 'I -> -I'): i1 = -1 try: CTK.saveTree() CTK.t = T.reorderAll(CTK.t, i1) CTK.TKTREE.updateApp() CTK.display(CTK.t) CTK.TXT.insert('START', 'All blocks reordered.\n') except Exception as e: Panels.displayErrors([0,str(e)], header='Error: reorderAll') CTK.TXT.insert('START', 'Reorder all fails.\n') CTK.TXT.insert('START', 'Error: ', 'Error')
def close(): 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 eps = float(VARS[1].get()) nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() fail = False zones = [] errors = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] zones.append(z) try: zones = G.close(zones, eps) except Exception as e: fail = True errors += [0, str(e)] if not fail: c = 0 for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] a = zones[c] c += 1 CTK.replace(CTK.t, nob, noz, a) CTK.TXT.insert('START', 'Zones closed.\n') else: Panels.displayErrors(errors, header='Error: close') CTK.TXT.insert('START', 'Close fails at least for one zone.\n') CTK.TXT.insert('START', 'Error: ', 'Error') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def extractIsoSurf(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 field = VARS[0].get() value = VARS[1].get() try: value = float(value) except: value = 1. nzs = CPlot.getSelectedZones() CTK.saveTree() if nzs == []: z = Internal.getZones(CTK.t) else: z = [] for nz in nzs: nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] z.append(CTK.t[2][nob][2][noz]) isos = [] try: iso = P.isoSurfMC(z, field, value) isos += iso except Exception as e: Panels.displayErrors([0,str(e)], header='Error: isoSurf') if isos == []: CTK.TXT.insert('START', 'isoSurf failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') else: CTK.TXT.insert('START', 'isoSurf of '+field+'=' +str(value)+' computed.\n') for i in isos: i[0] = C.getZoneName(i[0]) # unique name CTK.t = C.addBase2PyTree(CTK.t, 'SURFACES', 2) base = Internal.getNodeFromName1(CTK.t, 'SURFACES') nob = C.getNobOfBase(base, CTK.t) for i in isos: CTK.add(CTK.t, nob, -1, i) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def refine1D(density, npts, factor): fail = False nzs = CPlot.getSelectedZones() for nz in nzs: nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] dims = Internal.getZoneDim(z) try: if dims[0] == 'Unstructured': a = C.convertBAR2Struct(z); np = dims[1] else: a = z; np = dims[1]*dims[2]*dims[3] if factor < 0: factor = (npts-1.)/(np-1) b = G.refine(a, factor, 1) CTK.replace(CTK.t, nob, noz, b) except Exception as e: fail = True Panels.displayErrors([0,str(e)], header='Error: refine1D') return fail
def oneovern(): 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 nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return args = VARS[0].get() args = args.split(';') if (len(args) != 3): CTK.TXT.insert('START', 'oneovern requires 3 steps.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return ni = int(args[0]) nj = int(args[1]) nk = int(args[2]) CTK.saveTree() fail = False errors = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] try: a = T.oneovern(CTK.t[2][nob][2][noz], (ni, nj, nk)) CTK.replace(CTK.t, nob, noz, a) except Exception as e: fail = True errors += [0, str(e)] if not fail: CTK.TXT.insert('START', 'oneovern done.\n') else: Panels.displayErrors(errors, header='Error: oneovern') CTK.TXT.insert('START', 'oneovern fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') CTK.TKTREE.updateApp() CPlot.render()
def convert2Hexa(): 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 nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() list = [] fail = False errors = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] dim = Internal.getZoneDim(z) try: if (dim[0] == 'Unstructured' and dim[3] == 'TRI'): a, b = C.convertTri2Quad(z) CTK.replace(CTK.t, nob, noz, a) CTK.add(CTK.t, nob, -1, b) else: a = C.convertArray2Hexa(z) CTK.replace(CTK.t, nob, noz, a) except Exception as e: fail = True errors += [0, str(e)] if not fail: CTK.TXT.insert('START', 'Zones converted to hexa.\n') else: Panels.displayErrors(errors, header='Error: convert2Hexa') CTK.TXT.insert('START', 'Hexa conversion fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def exteriorFaces(): 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 nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1) p = Internal.getNodesFromName1(CTK.t, 'CONTOURS') gnob = C.getNobOfBase(p[0], CTK.t) fail = False errors = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] try: ext = P.exteriorFaces(CTK.t[2][nob][2][noz]) ext = T.splitConnexity(ext) for i in ext: CTK.add(CTK.t, gnob, -1, i) except TypeError as e: # type d'element non reconnu fail = True errors += [0, str(e)] except ValueError: # empty set pass #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() if not fail: CTK.TXT.insert('START', 'Exterior faces done.\n') else: Panels.displayErrors(errors, header='Error: exteriorFaces') CTK.TXT.insert('START', 'Exterior faces fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') CPlot.render()
def TFI(): 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 nzs = CPlot.getSelectedZones() if len(nzs) == 0: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return surf = getSurfaces() zones = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] dim = Internal.getZoneDim(z) if dim[3] == 'BAR': zp = C.convertBAR2Struct(z) zones.append(zp) else: zones.append(z) try: CTK.saveTree() mesh = G.TFI(zones) if surf != []: mesh = T.projectOrthoSmooth(mesh, surf) CTK.t = C.addBase2PyTree(CTK.t, 'MESHES') bases = Internal.getNodesFromName1(CTK.t, 'MESHES') nob = C.getNobOfBase(bases[0], CTK.t) CTK.add(CTK.t, nob, -1, mesh) CTK.TXT.insert('START', 'TFI mesh created.\n') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render() except Exception as e: Panels.displayErrors([0, str(e)], header='Error: TFI') CTK.TXT.insert('START', 'TFI mesh failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error')
def expandLayer(): 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 level = CTK.varsFromWidget(VARS[4].get(), type=2) if level == []: CTK.TXT.insert('START', 'Invalid level.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return else: level = level[0] CTK.saveTree() nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return fail = False errors = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] try: z = G.expandLayer(z, level=level) CTK.replace(CTK.t, nob, noz, z) except Exception as e: fail = True errors += [0, str(e)] #C._fillMissingVariables(CTK.t) if not fail: CTK.TXT.insert('START', 'Level %d expanded.\n' % level) else: Panels.displayErrors(errors, header='Error: expandLayers') CTK.TXT.insert('START', 'Expand layer fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()