#============================================================================== def updateApp(): return #============================================================================== def displayFrameMenu(event=None): WIDGETS['frameMenu'].tk_popup(event.x_root + 50, event.y_root, 0) #============================================================================== if (__name__ == "__main__"): import sys if (len(sys.argv) == 2): CTK.FILE = sys.argv[1] try: CTK.t = C.convertFile2PyTree(CTK.FILE) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.display(CTK.t) except: pass # Main window (win, menu, file, tools) = CTK.minimal('tkPaint ' + C.__version__) createApp(win) showApp() # - Main loop - win.mainloop()
def step1(): if CTK.t == []: return # Recupere le profil nzs = CPlot.getSelectedZones() if (nzs == []): CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return if (len(nzs) > 2): CTK.TXT.insert( 'START', 'Input profile must be one curve or two curves (blunt profiles).\n' ) CTK.TXT.insert('START', 'Error: ', 'Error') return if (len(nzs) == 2): culot = 1 else: culot = 0 zones = [] 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) if dim[0] == 'Unstructured': try: z = C.convertBAR2Struct(z) except Exception as e: #print('Error: blader: %s'%str(e)) errors += [0, str(e)] CTK.TXT.insert('START', 'Input profile must be structured.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return zones.append(z) if (len(errors) > 0): Panels.displayErrors(errors, header='Error: blader') CTK.saveTree() # -- Go to array world! import Geom as D import Generator as G import Transform as T import Converter # repere le culot si 2 courbes sont fournies a = C.getAllFields(zones[0], 'nodes')[0] if (culot == 1): ac = C.getAllFields(zones[1], 'nodes')[0] bb1 = G.bbox(a) bb2 = G.bbox(ac) if (bb1[0] > bb2[0]): temp = a a = ac ac = temp # taille de maille trailing edge et culot h = float(VARS[1].get()) # deraffinement par rapport a la distribution initiale h2 = float(VARS[2].get()) # Point de split (pour la ligne medianne), en % de la longeur du profil Nsplit = float(VARS[0].get()) # Creation delta (Ndelta est en nbre de pts sur le profil remaille) Ndelta = int(VARS[3].get()) # Hauteur du maillage Dfar = float(VARS[4].get()) #========================================================================== # Remaille uniforme du profil avec h2 l = D.getLength(a) npts = int(l / h2) + 1 if (npts / 2 == npts * 0.5): npts += 1 distrib = G.cart((0, 0, 0), (1. / (npts - 1.), 1, 1), (npts, 1, 1)) a = G.map(a, distrib) #=========================================================================== # Split du profil en intrados/extrados N = a[2] Ns = int(N * Nsplit) a1 = T.subzone(a, (1, 1, 1), (Ns + 1, 1, 1)) a2 = T.subzone(a, (Ns + 1, 1, 1), (N, 1, 1)) a2 = T.reorder(a2, (-1, 2, 3)) #=========================================================================== # Resserement bord de fuite et bord d'attaque l = D.getLength(a1) s = D.getCurvilinearAbscissa(a1) s[0] = 'x' s = Converter.initVars(s, 'y', 0.) s = Converter.initVars(s, 'z', 0.) N = a1[2] distrib = G.enforcePlusX(s, h / l, N / 10, 1) distrib = G.enforceMoinsX(distrib, h / l, N / 10, 1) a1 = G.map(a1, distrib) l = D.getLength(a2) s = D.getCurvilinearAbscissa(a2) s[0] = 'x' s = Converter.initVars(s, 'y', 0.) s = Converter.initVars(s, 'z', 0.) N = a2[2] distrib = G.enforcePlusX(s, h / l, N / 10, 1) distrib = G.enforceMoinsX(distrib, h / l, N / 10, 1) a2 = G.map(a2, distrib) #========================================================================== # ligne delta #=========================================================================== ni = a1[2] b1 = T.subzone(a1, (1, 1, 1), (Ndelta, 1, 1)) c1 = T.subzone(a1, (Ndelta, 1, 1), (ni, 1, 1)) b2 = T.subzone(a2, (1, 1, 1), (Ndelta, 1, 1)) c2 = T.subzone(a2, (Ndelta, 1, 1), (ni, 1, 1)) P1 = (c1[1][0, 0], c1[1][1, 0], c1[1][2, 0]) P2 = (c2[1][0, 0], c2[1][1, 0], c2[1][2, 0]) NdeltaDelta = Ndelta - 4 delta = D.line(P1, P2, 2 * NdeltaDelta - 1) #=========================================================================== # ligne medianne #=========================================================================== # ligne medianne droite P1 = Converter.getValue(c1, c1[2] - 1) P2 = Converter.getValue(delta, delta[2] / 2) median = D.line(P1, P2, N=10) # ligne medianne moyenne N1 = c1[2] # cree une ligne k2 remaillant c2 avec N1 s = D.getCurvilinearAbscissa(c1) s[0] = 'x' s = Converter.initVars(s, 'y', 0.) s = Converter.initVars(s, 'z', 0.) k2 = G.map(c2, s) # cree la ligne moyenne median = Converter.copy(c1) median[1][0, :] = 0.5 * (c1[1][0, :] + k2[1][0, :]) median[1][1, :] = 0.5 * (c1[1][1, :] + k2[1][1, :]) median[1][2, :] = 0.5 * (c1[1][2, :] + k2[1][2, :]) # Remaillage ligne medianne s = D.getCurvilinearAbscissa(c1) s[0] = 'x' s = Converter.initVars(s, 'y', 0.) s = Converter.initVars(s, 'z', 0.) median = G.map(median, s) median = G.refine(median, 0.9, 1) N1 = c1[2] N2 = median[2] d = N1 - N2 if (d / 2 != d * 0.5): factor = (N2 + 2.) / N2 median = G.refine(median, factor, 1) #=========================================================================== # Maillage TRI au bout if (culot == 0): #Converter.convertArrays2File([b1,b2,delta], 'bout1.plt') m3 = trimesh(b1, b2, delta) if (m3[0] == 0): raise ValueError(m3[1]) #Converter.convertArrays2File([b1,b2,delta]+m3, 'bout1.plt') else: # Dans le cas avec culot, on remaille le culot comme delta l = D.getLength(ac) npts = delta[2] distrib = G.cart((0, 0, 0), (1. / (npts - 1.), 1, 1), (npts, 1, 1)) ac = G.map(ac, distrib) m3 = [G.TFI([b1, delta, b2, ac])] #=========================================================================== # Maillage du reste de l'interieur du profil ni = c1[2] d1 = T.subzone(c1, (1, 1, 1), (ni - NdeltaDelta + 1, 1, 1)) e1 = T.subzone(c1, (ni - NdeltaDelta + 1, 1, 1), (ni, 1, 1)) ni = c2[2] d2 = T.subzone(c2, (1, 1, 1), (ni - NdeltaDelta + 1, 1, 1)) e2 = T.subzone(c2, (ni - NdeltaDelta + 1, 1, 1), (ni, 1, 1)) # remaillage de l'axe median s = D.getCurvilinearAbscissa(d1) s[0] = 'x' s = Converter.initVars(s, 'y', 0.) s = Converter.initVars(s, 'z', 0.) median = G.map(median, s) npt = delta[2] delta1 = T.subzone(delta, (1, 1, 1), (npt / 2 + 1, 1, 1)) delta2 = T.subzone(delta, (npt / 2 + 1, 1, 1), (npt, 1, 1)) #Converter.convertArrays2File([d1,e1,delta1,delta2,median,d2,e2], 'curv1.plt') m1 = G.TFI([d1, e1, delta1, median]) m2 = G.TFI([d2, e2, delta2, median]) #=========================================================================== # Ajout de la ligne arriere P1 = Converter.getValue(a1, 0) P2 = Converter.getValue(a1, 1) P3 = (P1[0] + Dfar, P1[1], P1[2]) line2 = D.line(P1, P3, N=50) N = 50 s = G.cart((0, 0, 0), (1. / (N - 1.), 1, 1), (N, 1, 1)) s = G.enforcePlusX(s, abs(P2[0] - P1[0]) / Dfar, N, 1) line2 = G.map(line2, s) #Converter.convertArrays2File([a1,a2,line2], 'out.plt') if (culot == 0): line2p = Converter.copy(line2) else: P1 = Converter.getValue(a2, 0) P2 = Converter.getValue(a2, 1) P3 = (P1[0] + Dfar, P1[1], P1[2]) line2p = D.line(P1, P3, N=50) s = D.getCurvilinearAbscissa(line2) s[0] = 'x' s = Converter.initVars(s, 'y', 0.) s = Converter.initVars(s, 'z', 0.) line2p = G.map(line2p, s) #=========================================================================== # Add normal layers N = 50 h = abs(P2[0] - P1[0]) N = int(Dfar / (3 * h) / 2) + 1 d = G.cart((0, 0, 0), (3 * h, 1, 1), (N + 1, 1, 1)) # shift line2p[1][1, :] -= 1.e-9 a2[1][1, 0] -= 1.e-9 #Converter.convertArrays2File([a2,line2,a1,line2p], 'curve0.plt') curve0 = T.join([line2, a1, a2, line2p]) curve0 = T.reorder(curve0, (-1, 2, 3)) #Converter.convertArrays2File([curve0], 'curve.plt') m4 = G.addNormalLayers([curve0], d, niter=1000, check=0) m4 = G.close(m4, 1.e-8) #Converter.convertArrays2File([m1,m2]+m3+m4, 'all.plt') # check volume + subzone vol = G.getVolumeMap(m4[0]) nk = vol[4] ni = vol[2] for k in range(nk - 1): sub = T.subzone(vol, (1, 1, k + 1), (ni, 1, k + 2)) volmin = Converter.getMinValue(sub, 'vol') if volmin < 0.: if k > 10: kc = k - 4 else: kc = k - 1 m4[0] = T.subzone(m4[0], (1, 1, 1), (m4[0][2], 1, kc)) break if culot == 1: r1p = T.translate(ac, (Dfar, 0, 0)) Converter.convertArrays2File([ac, line2, r1p, line2p], 'sub.plt') bsup = G.TFI([ac, line2, r1p, line2p]) # interieur M1 = [m1, m2] + m3 # exterieur M2 = m4 M2 = T.reorder(M2, (1, 3, 2)) # split du bloc M2 comme les blocs interieurs (pour connectMatch) a = M2[0] mp = line2[2] + a1[2] - 1 i1 = T.subzone(a, (1, 1, 1), (mp, a[3], a[4])) i2 = T.subzone(a, (mp, 1, 1), (a[2], a[3], a[4])) M2 = [i1, i2] if culot == 1: M2 += [bsup] #========================================================================== # Zones resultantes dans l'arbre meshes = M1 + M2 zones = [] for m in meshes: z = C.convertArrays2ZoneNode('zone', [m]) zones.append(z) base = Internal.getNodesFromName1(CTK.t, 'STEP1') if (base != []): (p, c) = Internal.getParentOfNode(CTK.t, base[0]) del p[2][c] CTK.t = C.addBase2PyTree(CTK.t, 'STEP1', 3) base = Internal.getNodesFromName1(CTK.t, 'STEP1')[0] base[2] += zones CTK.TXT.insert('START', 'Step1 performed.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t)
def step2(): import Transform as T import Generator as G CTK.saveTree() # taille de maille en envergure hp = float(VARS[5].get()) # Hauteur du maillage Dfar = float(VARS[4].get()) # Envergure span = float(VARS[6].get()) # Recupere la base STEP1 base = Internal.getNodesFromName1(CTK.t, 'STEP1') if base == []: return zones = base[0][2] l = len(zones) if l == 7: culot = 0 else: culot = 1 if culot == 0: # 2 zones exterieures, le reste interieur M2 = [ C.getAllFields(zones[l - 2], 'nodes')[0], C.getAllFields(zones[l - 1], 'nodes')[0] ] M1 = [] for z in zones[0:l - 2]: M1.append(C.getAllFields(z, 'nodes')[0]) else: # 3 zones exterieures, le reste interieur M2 = [ C.getAllFields(zones[l - 2], 'nodes')[0], C.getAllFields(zones[l - 1], 'nodes')[0], C.getAllFields(zones[l - 3], 'nodes')[0] ] M1 = [] for z in zones[0:l - 3]: M1.append(C.getAllFields(z, 'nodes')[0]) #========================================================================== # stack + resserement vers les extremites #========================================================================== M1b = T.translate(M1, (0, 0, Dfar)) B1 = [] for i in range(len(M1)): B1.append(G.stack(M1[i], M1b[i])) M1c = T.translate(M1, (0, 0, -span)) M1d = T.translate(M1, (0, 0, -span - Dfar)) B2 = [] for i in range(len(M1c)): B2.append(G.stack(M1c[i], M1d[i])) #C.convertArrays2File(B1+B2, 'bouchon.plt') M2b = T.translate(M2, (0, 0, Dfar)) M2c = T.translate(M2, (0, 0, -span - Dfar)) I = [] for i in range(len(M2b)): I.append(G.stack(M2c[i], M2b[i])) # B1, B2: les bouchons; I le reste #C.convertArrays2File(B1+B2+I, 'all.plt') #========================================================================== # Remaille la surface N = int(Dfar / hp) + 1 distrib = G.cart((0, 0, 0), (1. / (N - 1), 1, 1), (N, 1, 1)) for i in range(len(B1)): B1[i] = G.map(B1[i], distrib, 3) for i in range(len(B2)): B2[i] = G.map(B2[i], distrib, 3) N = int((2 * Dfar + span) / hp) + 1 distrib = G.cart((0, 0, 0), (1. / (N - 1), 1, 1), (N, 1, 1)) for i in range(len(I)): I[i] = G.map(I[i], distrib, 3) # Back to zones zones = [] for b in B1 + B2 + I: zones.append(C.convertArrays2ZoneNode('zone', [b])) base = Internal.getNodesFromName1(CTK.t, 'STEP2') if base != []: (p, c) = Internal.getParentOfNode(CTK.t, base[0]) del p[2][c] CTK.t = C.addBase2PyTree(CTK.t, 'STEP2', 3) base = Internal.getNodesFromName1(CTK.t, 'STEP2')[0] (p, c) = Internal.getParentOfNode(CTK.t, base) base[2] += zones # Add BCs base = X.connectMatch(base, tol=1.e-6) # # Blocs exterieurs if culot == 0: z = base[2][10] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'jmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmin') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'imin') base[2][10] = z z = base[2][11] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'jmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmin') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'imax') base[2][11] = z for i in range(5): z = base[2][i] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') base[2][i] = z for i in range(5): z = base[2][5 + i] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') base[2][5 + i] = z else: z = base[2][6] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'jmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmin') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'imax') base[2][6] = z z = base[2][8] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'jmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmin') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'imin') base[2][8] = z z = base[2][7] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'imax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmin') base[2][7] = z for i in range(3): z = base[2][i] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') base[2][i] = z for i in range(3): z = base[2][3 + i] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') base[2][3 + i] = z base = C.fillEmptyBCWith(base, 'wall', 'BCWall') CTK.t[2][c] = base CTK.TXT.insert('START', 'Step2 performed.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t)
#============================================================================== def hideApp(event=None): WIDGETS['frame'].grid_forget() #============================================================================== def updateApp(): return #============================================================================== def displayFrameMenu(event=None): WIDGETS['frameMenu'].tk_popup(event.x_root+50, event.y_root, 0) #============================================================================== if (__name__ == "__main__"): import sys if len(sys.argv) == 2: FILE = sys.argv[1] try: CTK.t = C.convertFile2PyTree(FILE) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.display(CTK.t, mode=1) except: pass # Main window (win, menu, file, tools) = CTK.minimal('tkReorder'+C.__version__) createApp(win); showApp() # - Main loop - win.mainloop()
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 setNames(event=None): Internal.__GridCoordinates__ = VARS[0].get() Internal.__FlowSolutionNodes__ = VARS[1].get() Internal.__FlowSolutionCenters__ = VARS[2].get() CTK.TXT.insert('START', 'Container names set.\n') CTK.display(CTK.t)
def computeVariables(): if CTK.t == []: return nzs = CPlot.getSelectedZones() varname = VARS[0].get() # Adimensionnement adim = VARS[7].get() nodes = Internal.getNodesFromName(CTK.t, 'ReferenceState') if nodes != []: state = nodes[0] else: CTK.TXT.insert('START', 'ReferenceState is missing (tkState).\n') CTK.TXT.insert('START', 'Error: ', 'Error') return nodes = Internal.getNodesFromName(state, 'Mach') if nodes != []: if isinstance(nodes[0][1], numpy.ndarray): MInf = nodes[0][1][0] else: MInf = nodes[0][1] else: CTK.TXT.insert('START', 'Mach is missing (tkState).\n') CTK.TXT.insert('START', 'Error: ', 'Error') return nodes = Internal.getNodesFromName(state, 'Reynolds') if nodes != []: if isinstance(nodes[0][1], numpy.ndarray): ReInf = nodes[0][1][0] else: ReInf = nodes[0][1] else: ReInf = 1. if adim == 'Adim1 (ro,a,T)': adim = Adim.adim1(MInf, 0., 0., ReInf) elif adim == 'Adim2 (ro,u,T)': adim = Adim.adim2(MInf, 0., 0., ReInf) else: CTK.TXT.insert('START', 'Unknown adim type.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return gamma = adim[11] cv = adim[7] rgp = (gamma - 1) * cv TInf = adim[6] muInf = 1. / ReInf Cs = adim[10] loc = VARS[6].get() CTK.saveTree() if (varname == 'Vorticity' or varname == 'VorticityMagnitude' or varname == 'QCriterion' or varname == 'ShearStress' or varname == 'SkinFriction' or varname == 'SkinFrictionTangential'): # extra variables varloc = loc + ':' + varname if CTK.__MAINTREE__ <= 0 or nzs == []: try: CTK.t = P.computeExtraVariable(CTK.t, varloc, gamma=gamma, rgp=rgp, Cs=Cs, mus=muInf, Ts=TInf) CTK.TXT.insert('START', 'Variable %s computed.\n' % varloc) except Exception as e: Panels.displayErrors([0, str(e)], header='Error: computeExtraVariables') CTK.TXT.insert('START', 'Computation of variable %s failed.\n' % varloc) CTK.TXT.insert('START', 'Error: ', 'Error') else: fail = False errors = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] try: CTK.t[2][nob][2][noz] = \ P.computeExtraVariable(CTK.t[2][nob][2][noz], varloc, gamma=gamma, rgp=rgp, Cs=Cs, mus=muInf, Ts=TInf) except Exception as e: fail = True errors += [0, str(e)] if not fail: CTK.TXT.insert('START', 'Variable %s computed.\n' % varloc) else: Panels.displayErrors(errors, header='Error: computeExtraVariables') CTK.TXT.insert('START', 'Computation of variable %s failed.\n' % varloc) CTK.TXT.insert('START', 'Error: ', 'Error') else: # std variables varloc = loc + ':' + varname if CTK.__MAINTREE__ <= 0 or nzs == []: try: CTK.t = P.computeVariables(CTK.t, [varloc], gamma=gamma, rgp=rgp, Cs=Cs, mus=muInf, Ts=TInf) CTK.TXT.insert('START', 'Variable %s computed.\n' % varloc) except Exception as e: Panels.displayErrors([0, str(e)], header='Error: computeVariables') CTK.TXT.insert('START', 'Computation of variable %s failed.\n' % varloc) CTK.TXT.insert('START', 'Error: ', 'Error') else: fail = False errors = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] try: CTK.t[2][nob][2][noz] = \ P.computeVariables(CTK.t[2][nob][2][noz], [varloc], gamma=gamma, rgp=rgp, Cs=Cs, mus=muInf, Ts=TInf) except Exception as e: fail = True errors += [0, str(e)] if not fail: CTK.TXT.insert('START', 'Variable %s computed.\n' % varloc) else: Panels.displayErrors(errors, header='Error: computeVariables') CTK.TXT.insert('START', 'Computation of variable %s failed.\n' % varloc) CTK.TXT.insert('START', 'Error: ', 'Error') #C._fillMissingVariables(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t) if CTK.TKPLOTXY is not None: CTK.TKPLOTXY.updateApp()