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 outCore(): 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 for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] ooc = Internal.getNodesFromName1(z, 'OutOfCore') if (len(ooc) == 0): # Save zone base = CTK.t[2][nob] name = '.' + base[0] + '#' + z[0] + '.cgns' t = C.newPyTree(['Base']) t[2][1][2].append(z) C.convertPyTree2File(t, name) # Replace zone bb = G.BB(z) bb[2].append(['OutOfCore', numpy.array([1]), [], \ 'UserDefinedData_t']) bb = CPlot.addRender2Zone(bb, blending=0.2) CTK.replace(CTK.t, nob, noz, bb) CTK.saveTree() # il est apres pour forcer le flush CTK.TXT.insert('START', 'Selected zones out of core.\n') CTK.t = C.fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() 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 inCore(): 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 for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] ooc = Internal.getNodesFromName1(z, 'OutOfCore') if (len(ooc) != 0): # Read zone base = CTK.t[2][nob] name = '.' + base[0] + '#' + z[0] + '.cgns' t = C.convertFile2PyTree(name) CTK.replace(CTK.t, nob, noz, t[2][1][2][0]) CTK.saveTree() # il est apres pour forcer le flush CTK.TXT.insert('START', 'Selected zones in core.\n') CTK.t = C.fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def extractBodies(): pref = 'BODY#' 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() for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] baseName = CTK.t[2][nob][0] bodyName = pref + baseName CTK.t = C.addBase2PyTree(CTK.t, bodyName, cellDim=2) nodes = Internal.getNodesFromName(CTK.t, bodyName) p = Internal.getParentOfNode(CTK.t, nodes[0]) walls = C.extractBCOfType(z, 'BCWall') walls += C.extractBCOfType(z, 'BCWallInviscid') walls += C.extractBCOfType(z, 'BCWallViscous') CTK.t[2][p[1]][2] = CTK.t[2][p[1]][2] + walls CTK.TXT.insert('START', 'Walls extracted.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t)
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 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 addkplanes(): 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 N = CTK.varsFromWidget(VARS[1].get(), type=2) if len(N) != 1: CTK.TXT.insert('START', 'Number of layers is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return N = N[0] nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() fail = False for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] #try: z = T.addkplane(CTK.t[2][nob][2][noz], N=N) CTK.replace(CTK.t, nob, noz, z) #except Exception as e: fail = True if not fail: CTK.TXT.insert('START', 'K planes added.\n') else: CTK.TXT.insert('START', 'add K planes failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def rmBlock(): 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 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]) CTK.saveTree() CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs) CTK.TXT.insert('START', 'Selected zones deleted.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.delete(deletedZoneNames) CPlot.render()
def pointedHat(): 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() args = VARS[3].get() args = args.split(';') if (len(args) != 3): return x0 = float(args[0]) y0 = float(args[1]) z0 = float(args[2]) if (nzs == []): CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return else: for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] CTK.t[2][nob][2][noz] = G.pointedHat(CTK.t[2][nob][2][noz], (x0, y0, z0)) CTK.TXT.insert('START', 'Pointed hat created.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t) return
def rmBCOfType(): if CTK.t == []: return BCTypes = [] selection = WIDGETS['BCLB'].curselection() for s in selection: t = WIDGETS['BCLB'].get(s) if t not in Internal.KNOWNBCS: t = 'FamilySpecified:' + t BCTypes.append(t) CTK.saveTree() nzs = CPlot.getSelectedZones() if CTK.__MAINTREE__ <= 0 or nzs == []: if 'FamilySpecified:-All BC-' in BCTypes: Internal._rmNodesByType(CTK.t, 'BC_t') else: for t in BCTypes: C._rmBCOfType(CTK.t, t) else: for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] if 'FamilySpecified:-All BC-' in BCTypes: Internal._rmNodesByType(z, 'BC_t') else: for t in BCTypes: C._rmBCOfType(z, t) CTK.TXT.insert('START', 'BCs of type %s have been removed.\n' % type) CTK.TKTREE.updateApp() check()
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 fillEmptyBCWith(): if CTK.t == []: return typeBC = VARS[4].get() if typeBC not in Internal.KNOWNBCS: nameBC = typeBC typeBC = 'FamilySpecified:' + typeBC else: nameBC = typeBC 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 CTK.saveTree() nzs = CPlot.getSelectedZones() if CTK.__MAINTREE__ <= 0 or nzs == []: C._fillEmptyBCWith(CTK.t, nameBC + 'Fill', typeBC, dim=ndim) else: for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] C._fillEmptyBCWith(CTK.t[2][nob][2][noz], nameBC + 'Fill', typeBC, dim=ndim) CTK.TXT.insert('START', 'Empty BCs filled.\n') CTK.TKTREE.updateApp() check()
def extendSurf(): 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) # - Hauteur de chaque maille - dhloc = CTK.varsFromWidget(VARS[1].get(), type=1) dhloc = dhloc[0] N = CTK.varsFromWidget(VARS[2].get(), type=2) N = N[0] dh = G.cart((0., 0., 0.), (dhloc, 1., 1.), (N + 1, 1, 1)) # - nb d'iterations de lissage - nit = CTK.varsFromWidget(VARS[3].get(), type=2) nit = nit[0] # - contour - nzs = CPlot.getSelectedZones() if (nzs == []): CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() contours = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] contour = C.convertBAR2Struct(z) contours.append(contour) # Extension zlist = G.buildExtension(contours, surfaces, dh, niter=nit) c = 0 for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] CTK.t[2][nob][2][noz] = zlist[c] c += 1 CTK.TXT.insert('START', 'Surface extension done.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t)
def getValueFromMouse(): if CTK.t == []: return nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return var = VARS[0].get() if var == 'CoordinateX': point = CPlot.getActivePoint() val = point[0] elif var == 'CoordinateY': point = CPlot.getActivePoint() val = point[1] elif var == 'CoordinateZ': point = CPlot.getActivePoint() val = point[2] else: val = None; c = 0 for i in WIDGETS['field']['values']: if var == i: break c += 1 c = c-3 # a cause des coord values = CPlot.getActivePointF() if values != []: val = values[c] if val != None: VARS[1].set(str(val))
def setVars3(event=None): nzs = CPlot.getSelectedZones() if (nzs == []): CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return name = VARS[0].get() CTK.saveTree() transl_speed = CTK.varsFromWidget(VARS[43].get(), 1) axis_pnt = CTK.varsFromWidget(VARS[44].get(), 1) axis_vct = CTK.varsFromWidget(VARS[45].get(), 1) omega = VARS[46].get() for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] CTK.t[2][nob][2][noz] = RM.setPrescribedMotion3( z, name, transl_speed=transl_speed, axis_pnt=axis_pnt, axis_vct=axis_vct, omega=omega) CTK.TKTREE.updateApp() CTK.TXT.insert('START', 'Motion set in selected zones.\n')
def getData(): if CTK.t == []: return nzs = CPlot.getSelectedZones() if nzs == []: return # get first of selection nz = nzs[0] nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] zone = CTK.t[2][nob][2][noz] if zone is not None: n = Internal.getNodeFromPath(zone, '.RenderInfo/Material') if n is not None: val = Internal.getValue(n) VARS[0].set(val) n = Internal.getNodeFromPath(zone, '.RenderInfo/Color') if n is not None: val = Internal.getValue(n) VARS[1].set(val) n = Internal.getNodeFromPath(zone, '.RenderInfo/Blending') if n is not None: val = Internal.getValue(n) WIDGETS['blending'].set(val * 100) VARS[6].set('Blending [%.2f].' % val) n = Internal.getNodeFromPath(zone, '.RenderInfo/MeshOverlay') if n is not None: val = Internal.getValue(n) VARS[3].set(val) n = Internal.getNodeFromPath(zone, '.RenderInfo/ShaderParameters') if n is not None: val = Internal.getValue(n) WIDGETS['param1'].set(val[0] * 50) VARS[4].set('Shader parameter 1 [%.2f].' % val[0]) WIDGETS['param2'].set(val[1] * 50) VARS[4].set('Shader parameter 2 [%.2f].' % val[1])
def translateClick(): 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 prev = [] w = WIDGETS['translate'] if CTK.__BUSY__ == False: CTK.__BUSY__ = True nzs = CPlot.getSelectedZones() CTK.TXT.insert('START', 'Click start point...\n') TTK.sunkButton(w) while CTK.__BUSY__: CPlot.unselectAllZones() l = [] while l == []: l = CPlot.getActivePoint() time.sleep(CPlot.__timeStep__) w.update() if CTK.__BUSY__ == False: break if CTK.__BUSY__: if prev == []: prev = l if nzs == []: nzs = CPlot.getSelectedZones() CTK.TXT.insert('START', 'Click end point...\n') elif prev != l: CTK.saveTree() vx = l[0] - prev[0] vy = l[1] - prev[1] vz = l[2] - prev[2] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] a = T.translate(z, (vx, vy, vz)) CTK.replace(CTK.t, nob, noz, a) CTK.TKTREE.updateApp() CTK.TXT.insert('START', 'Zones translated.\n') CPlot.render() prev = [] break CTK.__BUSY__ = False TTK.raiseButton(w) else: CTK.__BUSY__ = False TTK.raiseButton(w)
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 compute(): 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 type = VARS[0].get() var1 = VARS[2].get() if (type == 'INT((v1,v2,v3).ndS)' or 'INT((v1,v2,v3)^OMdS)'): var2 = VARS[3].get() var3 = VARS[4].get() vector = [var1, var2, var3] if (type == 'INT((v1,v2,v3)^OMdS)' or type == 'INT(v1n^OMdS)'): center = CTK.varsFromWidget(VARS[1].get(), type=1) if (len(center) != 3): CTK.TXT.insert('START', 'Center for moment integration 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 res1 = 0. res2 = 0. res3 = 0. for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] if (type == 'INT(v1dS)'): res1 += P.integ(z, var1)[0] elif (type == 'INT(v1.ndS)'): res = P.integNorm(z, var1)[0] res1 += res[0] res2 += res[1] res3 += res[2] elif (type == 'INT((v1,v2,v3).ndS)'): res1 += P.integNormProduct(z, vector) elif (type == 'INT((v1,v2,v3)^OMdS)'): res = P.integMoment(z, center, vector) res1 += res[0] res2 += res[1] res3 += res[2] elif (type == 'INT(v1n^OMdS)'): res = P.integMomentNorm(z, center, var1)[0] res1 += res[0] res2 += res[1] res3 += res[2] if (type == 'INT((v1,v2,v3)^OMdS)' or type == 'INT(v1n^OMdS)' or type == 'INT(v1.ndS)'): res = [res1, res2, res3] else: res = res1 CTK.TXT.insert('START', 'Res=' + str(res) + '.\n')
def TRITFI(): 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] z = C.convertBAR2Struct(z) zones.append(z) if len(zones) != 3: CTK.TXT.insert('START', 'TRI TFI takes 3 contours.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return coords1 = C.getFields(Internal.__GridCoordinates__, zones[0])[0] coords2 = C.getFields(Internal.__GridCoordinates__, zones[1])[0] coords3 = C.getFields(Internal.__GridCoordinates__, zones[2])[0] [m1, m2, m3] = trimesh(coords1, coords2, coords3) if (m1 == 0): CTK.TXT.insert('START', m2 + '\n') CTK.TXT.insert('START', 'Error: ', 'Error') return m1 = C.convertArrays2ZoneNode('TFI1', [m1]) m2 = C.convertArrays2ZoneNode('TFI2', [m2]) m3 = C.convertArrays2ZoneNode('TFI3', [m3]) if surf != []: m1 = T.projectOrthoSmooth(m1, surf) m2 = T.projectOrthoSmooth(m2, surf) m3 = T.projectOrthoSmooth(m3, surf) CTK.saveTree() CTK.t = C.addBase2PyTree(CTK.t, 'MESHES') bases = Internal.getNodesFromName1(CTK.t, 'MESHES') nob = C.getNobOfBase(bases[0], CTK.t) for i in [m1, m2, m3]: CTK.add(CTK.t, nob, -1, i) CTK.TXT.insert('START', 'TRI-TFI mesh created.\n') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def chimeraInfo(): if CTK.t == []: return nzs = CPlot.getSelectedZones() typename = VARS[1].get() CTK.saveTree() X._chimeraInfo(CTK.t, typename) CTK.TXT.insert('START', 'Field %s added.\n' % typename) CTK.TKTREE.updateApp() CTK.display(CTK.t)
def find(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 nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return if len(nzs) != 1: CTK.TXT.insert('START', 'Only one block must be selected.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return nz = nzs[0] nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] type = VARS[0].get() if type == 'Node index': inds = CTK.varsFromWidget(VARS[1].get(), type=3) if len(inds) == 0: CTK.TXT.insert('START', 'Invalid index.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return [px, py, pz] = C.getValue(z, Internal.__GridCoordinates__, inds[0]) CTK.TXT.insert('START', 'Node %s found.\n' % VARS[1].get()) elif type == 'Coordinates': vars = CTK.varsFromWidget(VARS[1].get(), type=1) if len(vars) != 3: CTK.TXT.insert('START', 'Invalid coordinates.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return [px, py, pz] = vars CTK.TXT.insert('START', 'Coordinates %s found.\n' % VARS[1].get()) else: # type = element index inds = CTK.varsFromWidget(VARS[1].get(), type=3) if len(inds) == 0: CTK.TXT.insert('START', 'Invalid index.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return zp = Internal.copyRef(z) C._deleteAllBCAndSolutions__(zp) zp = C.node2Center(z) [px, py, pz] = C.getValue(zp, Internal.__GridCoordinates__, inds[0]) CTK.TXT.insert('START', 'Element %s found.\n' % VARS[1].get()) (xeye, yeye, zeye) = CPlot.getState('posEye') (xcam, ycam, zcam) = CPlot.getState('posCam') dx = xcam - xeye dy = ycam - yeye dz = zcam - zeye CPlot.setState(posEye=(px, py, pz)) CPlot.setState(posCam=(px + dx, py + dy, pz + dz)) CPlot.setActivePoint(px, py, pz)
def rotate(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 axis = VARS[2].get() angle = CTK.varsFromWidget(VARS[3].get(), type=1) if len(angle) == 1: angle = angle[0] X = None elif len(angle) == 4: X = (angle[1], angle[2], angle[3]) angle = angle[0] else: CTK.TXT.insert('START', 'Invalid angle or angle+rotation center.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return if axis == 'around X': axe = (1., 0., 0.) elif axis == 'around Y': axe = (0., 1., 0.) elif axis == 'around Z': axe = (0., 0., 1.) elif axis == 'around view': pos = CPlot.getState('posCam') eye = CPlot.getState('posEye') axe = (eye[0] - pos[0], eye[1] - pos[1], eye[2] - pos[2]) else: axe = (0., 0., 1.) try: angle = float(angle) except: angle = 0. nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() if X is None: sel = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] sel.append(z) X = G.barycenter(sel) for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] a = T.rotate(CTK.t[2][nob][2][noz], (X[0], X[1], X[2]), axe, angle) CTK.replace(CTK.t, nob, noz, a) CTK.TXT.insert('START', 'Zones have been rotated.\n') CTK.TKTREE.updateApp() CPlot.render()
def optimize(): 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 dw = 1 if VARS[0].get() == 'inactive': dw = 0 depth = VARS[7].get() depth = int(depth) # Creation de l'arbre temporaire nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return # copie du premier niveau sans les enfants t = ['tree', None, [], 'CGNSTree_t'] for i in CTK.t[2]: t[2].append([i[0], i[1], [], i[3]]) for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] t[2][nob][2].append(z) # Recuperation des priorites dans l'arbre bases = Internal.getBases(CTK.t) prios = [] for b in bases: cont = Internal.getNodesFromName1(b, '.Solver#Chimera') if cont != []: prio = Internal.getNodesFromName3(cont[0], 'Priority') if prio != []: prios.append(b[0]) prios.append(int(prio[0][1][0, 0])) # Optimisation du recouvrement CTK.saveTree() t = X.optimizeOverlap(t, double_wall=dw, priorities=prios) t = X.maximizeBlankedCells(t, depth=depth) c = [0 for x in xrange(len(bases))] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] CTK.t[2][nob][2][noz] = t[2][nob][2][c[nob - 1]] c[nob - 1] += 1 CTK.TXT.insert('START', 'Overlapping optimized.\n') CTK.TKTREE.updateApp() CTK.display(CTK.t)
def importFile(event=None): if CTK.t == []: return s = VARS[4].get() s = s.split(';') try: t1 = [] for filename in s: if filename != '': t2 = C.convertFile2PyTree(filename) # Fusion des bases de t et t2 if t1 == []: t1 = t2 else: t1 = C.mergeTrees(t1, t2) except: CTK.TXT.insert('START', 'Import failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return if t1 == []: CTK.TXT.insert('START', 'Import failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() nzs = CPlot.getSelectedZones() # Essaie de trouver une methode adaptee method = 1 # match by geom import sets zoneNames = sets.Set(C.getZoneNames(CTK.t, prefixByBase=False)) zoneNames1 = sets.Set(C.getZoneNames(t1, prefixByBase=False)) inter = zoneNames & zoneNames1 linter = len(inter) * 1. comp = min(len(zoneNames), len(zoneNames1)) * 1. if linter / comp > 0.9: method = 0 # try match by name (safer) if CTK.__MAINTREE__ <= 0 or nzs == []: CTK.t = P.importVariables(t1, CTK.t, method=method) else: zones = C.newPyTree(['Base']) for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] zone = CTK.t[2][nob][2][noz] zones[2][1][2].append(zone) zones = P.importVariables(t1, zones, method=method) c = 0 for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] CTK.t[2][nob][2][noz] = zones[2][1][2][c] c += 1 CTK.TXT.insert('START', 'Variable file %s imported.\n' % filename) #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t) if CTK.TKPLOTXY is not None: CTK.TKPLOTXY.updateApp()
def getPointCoordinates(): if CTK.t == []: return nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return point = CPlot.getActivePoint() if point != []: VARS[0].set(str(point[0]) + ';' + str(point[1]) + ';' + str(point[2]))
def uniformize(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 nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return type = VARS[2].get() density = -1; npts = 2; factor = -1 if type == 'Density': density = CTK.varsFromWidget(VARS[0].get(), 1) if len(density) != 1: CTK.TXT.insert('START', 'Invalid points density.\n') CTK.TXT.insert('START', 'Error: ', 'Error') density = density[0] elif type == 'Npts': npts = CTK.varsFromWidget(VARS[0].get(), 2) if len(npts) != 1: CTK.TXT.insert('START', 'Invalid number of points.\n') CTK.TXT.insert('START', 'Error: ', 'Error') npts = npts[0] elif type == 'Factor': factor = CTK.varsFromWidget(VARS[0].get(), 1) if len(factor) != 1: CTK.TXT.insert('START', 'Invalid number factor.\n') CTK.TXT.insert('START', 'Error: ', 'Error') CTK.saveTree() # Get first selected zone nz = nzs[0] nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] zone = CTK.t[2][nob][2][noz] dim = Internal.getZoneDim(zone) if dim[0] == 'Structured': if dim[2] != 1 and dim[3] != 1: fail = apply3D(density, npts, factor, ntype=0) elif dim[2] != 1 and dim[3] == 1: fail = apply2D(density, npts, factor, ntype=0) else: fail = uniformize1D(density, npts, factor) else: fail = uniformize1D(density, npts, factor) # all zones if not fail: CTK.TXT.insert('START', 'Uniformize successfull.\n') else: CTK.TXT.insert('START', 'Uniformize edge 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 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()