def getEdges2D(zone, factor): dim = Internal.getZoneDim(zone) ni = dim[1]; nj = dim[2]; nk = dim[3] l = CPlot.getActivePointIndex() if l == []: return None i = l[2]; j = l[3]; k = l[4] e1 = T.subzone(zone, (1,1,1), (ni,1,1)) e2 = T.subzone(zone, (1,nj,1), (ni,nj,1)) e3 = T.subzone(zone, (1,1,1), (1,nj,1)) e4 = T.subzone(zone, (ni,1,1), (ni,nj,1)) u = [e1,e2,e3,e4] (i,j,k) = forceIJK(i,j,k,ni,nj,nk) r = [] if i == 1: ind = j-1 m = [e3]; u.remove(e3) if factor != 1.: r = [e4]; u.remove(e4) elif i == ni: ind = j-1 m = [e4]; u.remove(e4) if factor != 1.: r = [e3]; u.remove(e3) elif j == 1: ind = i-1 m = [e1]; u.remove(e1) if factor != 1.: r = [e2]; u.remove(e2) elif j == nj: ind = i-1 m = [e2]; u.remove(e2) if factor != 1.: r = [e1]; u.remove(e1) return m, r, u, ind
def meshTri(P0, P1, P2, N): C01 = (0.5 * (P0[0] + P1[0]), 0.5 * (P0[1] + P1[1]), 0.5 * (P0[2] + P1[2])) C12 = (0.5 * (P1[0] + P2[0]), 0.5 * (P1[1] + P2[1]), 0.5 * (P1[2] + P2[2])) C02 = (0.5 * (P0[0] + P2[0]), 0.5 * (P0[1] + P2[1]), 0.5 * (P0[2] + P2[2])) C = (1. / 3. * (P0[0] + P1[0] + P2[0]), 1. / 3. * (P0[1] + P1[1] + P2[1]), 1. / 3. * (P0[2] + P1[2] + P2[2])) l1 = D.line(P0, C01, N) l2 = D.line(C01, C, N) l3 = D.line(C, C02, N) l4 = D.line(C02, P0, N) m1 = G.TFI([l1, l2, l3, l4]) m1 = T.reorder(m1, (-1, 2, 3)) l1 = D.line(C01, P1, N) l2 = D.line(P1, C12, N) l3 = D.line(C12, C, N) l4 = D.line(C, C01, N) m2 = G.TFI([l1, l2, l3, l4]) m2 = T.reorder(m2, (-1, 2, 3)) l1 = D.line(C, C12, N) l2 = D.line(C12, P2, N) l3 = D.line(P2, C02, N) l4 = D.line(C02, C, N) m3 = G.TFI([l1, l2, l3, l4]) m3 = T.reorder(m3, (-1, 2, 3)) return [m1, m2, m3]
def createTools(): global TOOLS if TOOLS != []: return # deja crees # square P0 = (0, 0, 0) # pointe P0 = (0, 0, 0) P1 = (-1, -1, 1) P2 = (-1, 1, 1) P3 = (-1, 1, -1) P4 = (-1, -1, -1) t1 = D.triangle(P0, P1, P2) t2 = D.triangle(P0, P2, P3) t3 = D.triangle(P0, P3, P4) t4 = D.triangle(P0, P4, P1) t = T.join([t1, t2, t3, t4]) t = G.close(t) TOOLS.append(t) # biseau horizontal P0 = (0, -1, 0) P1 = (0, 1, 0) P1 = (-1, -1, 1) P2 = (-1, 1, 1) P3 = (-1, 1, -1) P4 = (-1, -1, -1) t1 = D.triangle(P0, P1, P2) t2 = D.triangle(P0, P2, P3) t3 = D.triangle(P0, P3, P4) t4 = D.triangle(P0, P4, P1) t = T.join([t1, t2, t3, t4]) t = G.close(t) # biseau vertical # pointe spherique return TOOLS
def submenu(items): import Geom.PyTree as D import Transform.PyTree as T import Converter.PyTree as C nitems = len(items) out = []; c = 0 for i in items: a = D.text2D(i) CPlot._addRender2Zone(a, color='White') T._translate(a, (0,-c,0)) out.append(a) c += 10 t = C.newPyTree(['Base']); t[2][1][2] += out CPlot.display(t, mode='Render') CPlot.setState(activateShortCuts=0) current = 0 go = True; l = '' while go: while l == '': l = CPlot.getKeyboard(); time.sleep(dt) v = ord(l[0]); print(v) if v == 1: # up b = CPlot.addRender2Zone(out[current], color='White') CPlot.replace(t, 1, current, b) current -= 1 if current < 0: current = nitems-1 b = CPlot.addRender2Zone(out[current], color='Red') CPlot.replace(t, 1, current, b) CPlot.render() elif v == 2: # down b = CPlot.addRender2Zone(out[current], color='White') CPlot.replace(t, 1, current, b) current += 1 if current >= nitems: current = 0 b = CPlot.addRender2Zone(out[current], color='Red') CPlot.replace(t, 1, current, b) CPlot.render() elif v == 3: b = CPlot.addRender2Zone(out[current], color='White') CPlot.replace(t, 1, current, b) current -= 1 if current < 0: current = nitems-1 b = CPlot.addRender2Zone(out[current], color='Red') CPlot.replace(t, 1, current, b) CPlot.render() elif v == 4: b = CPlot.addRender2Zone(out[current], color='White') CPlot.replace(t, 1, current, b) current += 1 if current >= nitems: current = 0 b = CPlot.addRender2Zone(out[current], color='Red') CPlot.replace(t, 1, current, b) CPlot.render() elif v == 13: print('returning %s.'%str(current)) return current, items[current] time.sleep(dt) l = ''; v = -1; CPlot.resetKeyboard()
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 createZEllipse(): import Geom.PyTree as D import Transform.PyTree as T alpha = CTK.varsFromWidget(VARS[1].get(), type=2) if len(alpha) == 1: ax = alpha[0] ay = alpha[0] az = alpha[0] bx = alpha[0] by = alpha[0] bz = alpha[0] elif len(alpha) == 3: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[0] by = alpha[1] bz = alpha[2] elif len(alpha) == 6: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[3] by = alpha[4] bz = alpha[5] else: CTK.TXT.insert('START', 'Borders factor incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return try: box = G.bbox(CTK.t) except: box = [0, 0, 0, 1, 1, 1] hx = box[3] - box[0] hy = box[4] - box[1] if hx < 1.e-10: hx = 0.1 if hy < 1.e-10: hy = 0.1 hx = hx * 0.7 * ax hy = hy * 0.7 * ay cx = 0.5 * (box[0] + box[3]) cy = 0.5 * (box[1] + box[4]) if hx < hy: s = D.circle((cx, cy, box[2]), hx, N=50) s = T.contract(s, (cx, cy, box[2]), (1, 0, 0), (0, 0, 1), hy / hx) else: s = D.circle((cx, cy, box[2]), hy, N=50) s = T.contract(s, (cx, cy, box[2]), (0, 1, 0), (0, 0, 1), hx / hy) s = C.convertArray2Tetra(s) s = G.close(s, 1.e-6) p = G.fittingPlaster(s, bumpFactor=0.) s = G.gapfixer(s, p) s = CPlot.addRender2Zone(s, material='Solid', color='White', meshOverlay=0) return [s]
def createText(event=None): CTK.saveTree() text = VARS[0].get() type = VARS[1].get() font = VARS[3].get() smoothness = VARS[2].get() smooth = 0 if smoothness == 'Regular': smooth = 0 elif smoothness == 'Smooth': smooth = 2 elif smoothness == 'Very smooth': smooth = 4 CTK.t = C.addBase2PyTree(CTK.t, 'TEXT', 3) nodes = Internal.getNodesFromName1(CTK.t, 'TEXT') base = nodes[0] if type == '3D': a = D.text3D(text, smooth=smooth, font=font) elif type == '2D': a = D.text2D(text, smooth=smooth, font=font) elif type == '1D': a = D.text1D(text, smooth=smooth, font=font) a = C.convertArray2Tetra(a) a = T.join(a) # Modification de l'angle, de la position et de la taille du texte # en fonction du point de vue posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') dirCam = CPlot.getState('dirCam') BB = G.bbox(a) xc = 0.5 * (BB[3] + BB[0]) yc = 0.5 * (BB[4] + BB[1]) zc = 0.5 * (BB[5] + BB[2]) a = T.translate(a, (posEye[0] - xc, posEye[1] - yc, posEye[2] - zc)) lx = posEye[0] - posCam[0] ly = posEye[1] - posCam[1] lz = posEye[2] - posCam[2] if (lx * lx + ly * ly + lz * lz == 0.): lx = -1 if (dirCam[0] * dirCam[0] + dirCam[1] * dirCam[1] + dirCam[2] * dirCam[2] == 0.): dirCam = (0, 0, 1) ll = math.sqrt(lx * lx + ly * ly + lz * lz) a = T.homothety(a, (posEye[0], posEye[1], posEye[2]), 0.01 * ll) ux = dirCam[1] * lz - dirCam[2] * ly uy = dirCam[2] * lx - dirCam[0] * lz uz = dirCam[0] * ly - dirCam[1] * lx a = T.rotate(a, (posEye[0], posEye[1], posEye[2]), ((1, 0, 0), (0, 1, 0), (0, 0, 1)), ((-ux, -uy, -uz), dirCam, (lx, ly, lz))) nob = C.getNobOfBase(base, CTK.t) CTK.add(CTK.t, nob, -1, a) #C._fillMissingVariables(CTK.t) CTK.TXT.insert('START', 'Text created.\n') (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 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 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 drawCubic(npts): global CURRENTZONE; global CURRENTPOLYLINE if (CTK.t == []): return w = WIDGETS['draw'] if (CTK.__BUSY__ == False): CPlot.unselectAllZones() CTK.saveTree() CTK.__BUSY__ = True TTK.sunkButton(w) CPlot.setState(cursor=1) while (CTK.__BUSY__ == True): l = [] while (l == []): l = CPlot.getActivePoint() CPlot.unselectAllZones() time.sleep(CPlot.__timeStep__) w.update() if (CTK.__BUSY__ == False): break if (CTK.__BUSY__ == True): CURRENTPOLYLINE.append((l[0],l[1],l[2])) if (CURRENTZONE == None): CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1) base = Internal.getNodeFromName1(CTK.t, 'CONTOURS') nob = C.getNobOfBase(base, CTK.t) a = D.polyline(CURRENTPOLYLINE) CURRENTZONE = a CTK.add(CTK.t, nob, -1, a) ret = Internal.getParentOfNode(CTK.t, CURRENTZONE) noz = ret[1] else: a = D.polyline(CURRENTPOLYLINE) CURRENTZONE = a CTK.replace(CTK.t, nob, noz, a) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render() CTK.__BUSY__ = False TTK.raiseButton(w) CPlot.setState(cursor=0) else: CTK.__BUSY__ = False ret = Internal.getParentOfNode(CTK.t, CURRENTZONE) a = D.polyline(CURRENTPOLYLINE) d = G.cart( (0,0,0), (1./(npts-1),1,1), (npts,1,1) ) a = G.map(a, d) surfaces = getSurfaces() if (surfaces != []): a = T.projectOrthoSmooth(a, surfaces) nob = C.getNobOfBase(ret[0], CTK.t) CTK.replace(CTK.t, nob, ret[1], a) #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render() CURRENTZONE = None CURRENTPOLYLINE = [] TTK.raiseButton(w) CPlot.setState(cursor=0)
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 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 orbite(): if CTK.t == []: return if not CTK.__BUSY__: name = VARS[0].get() names = name.split(';') # Get paths paths = [] 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]: paths.append(z) # Keep only 1D arrays path = [] for p in paths: dim = Internal.getZoneDim(p) if (dim[0] == 'Unstructured' and dim[3] == 'BAR'): path.append(p) if (dim[0] == 'Structured' and dim[2] == 1 and dim[3] == 1): path.append(C.convertArray2Tetra(p)) if path == []: return path = T.join(path) path = G.close(path) path = C.convertBAR2Struct(path) dim = Internal.getZoneDim(path) N = dim[1] CTK.__BUSY__ = True TTK.sunkButton(WIDGETS['orbite']) CPlot.setState(cursor=2) i = 0 while CTK.__BUSY__: speed = 100. - WIDGETS['speed'].get() time.sleep(CPlot.__timeStep__ * speed * 0.06) if i > N - 1: i = 0 if i + N / 10 > N - 1: inc = 1 else: inc = N / 10 posCam = C.getValue(path, Internal.__GridCoordinates__, i) posEye = C.getValue(path, Internal.__GridCoordinates__, i + inc) CPlot.setState(posCam=posCam, posEye=posEye) WIDGETS['orbite'].update() i += 1 CTK.__BUSY__ = False TTK.raiseButton(WIDGETS['orbite']) CPlot.setState(cursor=0) else: CTK.__BUSY__ = False TTK.raiseButton(WIDGETS['orbite']) CPlot.setState(cursor=0)
def setCanvas(event=None): dir = VARS[0].get() CTK.saveTree() deleteCanvasBase() CTK.t = C.addBase2PyTree(CTK.t, 'CANVAS', 2) size = CANVASSIZE if dir == 'View': a = G.cart((-size, 0, -size), (2 * size, 2 * size, 2 * size), (2, 1, 2)) a = T.translate(a, (XC, YC, ZC)) a = T.rotate(a, (XC, YC, ZC), ((1, 0, 0), (0, 1, 0), (0, 0, 1)), ((-DIRX, -DIRY, -DIRZ), (LX, LY, LZ), (UX, UY, UZ))) VARS[1].set(str(XC) + ';' + str(YC) + ';' + str(ZC)) elif dir == 'YZ': a = G.cart((0, -size, -size), (2 * size, 2 * size, 2 * size), (1, 2, 2)) a = T.translate(a, (XC, YC, ZC)) VARS[1].set(str(XC)) elif dir == 'XZ': a = G.cart((-size, 0, -size), (2 * size, 2 * size, 2 * size), (2, 1, 2)) a = T.translate(a, (XC, YC, ZC)) VARS[1].set(str(YC)) else: a = G.cart((-size, -size, 0), (2 * size, 2 * size, 2 * size), (2, 2, 1)) a = T.translate(a, (XC, YC, ZC)) VARS[1].set(str(ZC)) nodes = Internal.getNodesFromName1(CTK.t, 'CANVAS') base = nodes[0] nob = C.getNobOfBase(base, CTK.t) CTK.add(CTK.t, nob, -1, a) #C._fillMissingVariables(CTK.t) (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 MONO2TFI(): 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) != 2: CTK.TXT.insert('START', 'MONO2 TFI takes 2 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] [m] = mono2mesh(coords1, coords2) if isinstance(m, str): CTK.TXT.insert('START', m + '\n') CTK.TXT.insert('START', 'Error: ', 'Error') return m = C.convertArrays2ZoneNode('TFI', [m]) if surf != []: m = T.projectOrthoSmooth(m, surf) CTK.saveTree() 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, m) CTK.TXT.insert('START', 'HO-TFI mesh created.\n') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def loadAndSplitSkeleton(self, NParts=None, NProc=None): """Load and split skeleton.""" a = self.loadSkeleton() import Transform.PyTree as T # split on skeleton splitDict = {} if NParts is not None: b = T.splitNParts(a, N=NParts, splitDict=splitDict) else: b = T.splitNParts(a, N=NProc, splitDict=splitDict) self.splitDict = splitDict zones = Internal.getZones(b) if NProc is not None: import Distributor2.PyTree as D2 D2._distribute(b, NProc) # Correction dims en attendant que subzone fonctionne sur un skel for z in zones: j = splitDict[z[0]] ni = j[2] - j[1] + 1 nj = j[4] - j[3] + 1 nk = j[6] - j[5] + 1 d = numpy.empty((3, 3), numpy.int32, order='Fortran') d[0, 0] = ni d[1, 0] = nj d[2, 0] = nk d[0, 1] = ni - 1 d[1, 1] = nj - 1 d[2, 1] = nk - 1 d[0, 2] = 0 d[1, 2] = 0 d[2, 2] = 0 z[1] = d # END correction return a
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 drawLine(npts): CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1) nodes = Internal.getNodesFromName1(CTK.t, 'CONTOURS') nob = C.getNobOfBase(nodes[0], CTK.t) CTK.TXT.insert('START', 'Click first point...\n') prev = [] if CTK.__BUSY__ == False: CTK.__BUSY__ = True TTK.sunkButton(WIDGETS['draw']) CPlot.setState(cursor=1) while CTK.__BUSY__: CPlot.unselectAllZones() CTK.saveTree() surfaces = getSurfaces() l = [] while l == []: l = CPlot.getActivePoint() time.sleep(CPlot.__timeStep__) WIDGETS['draw'].update() if CTK.__BUSY__ == False: break if CTK.__BUSY__: if prev == []: prev = l CTK.TXT.insert('START', 'Click second point...\n') elif (prev != l): line = D.line(prev, l, npts) if surfaces != []: line = T.projectOrthoSmooth(line, surfaces) CTK.add(CTK.t, nob, -1, line) CTK.TXT.insert('START', 'Line created.\n') CTK.__BUSY__ = False TTK.raiseButton(WIDGETS['draw']) #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render() CPlot.setState(cursor=0) prev = [] return CTK.__BUSY__ = False TTK.raiseButton(WIDGETS['draw']) CPlot.setState(cursor=0) else: CTK.__BUSY__ = False TTK.raiseButton(WIDGETS['draw']) CPlot.setState(cursor=0) return
def translate(): 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 v = CTK.varsFromWidget(VARS[0].get(), type=1) if len(v) != 3: CTK.TXT.insert('START', 'Translation vector 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() axis = VARS[6].get() if axis == 'along view': posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') dirCam = CPlot.getState('dirCam') axe1 = (posEye[0] - posCam[0], posEye[1] - posCam[1], posEye[2] - posCam[2]) axe2 = dirCam axe3 = (axe1[1] * axe2[2] - axe1[2] * axe2[1], axe1[2] * axe2[0] - axe1[0] * axe2[2], axe1[0] * axe2[1] - axe1[1] * axe2[0]) axe1 = Vector.normalize(axe1) axe2 = Vector.normalize(axe2) axe3 = Vector.normalize(axe3) ax = v[0] * axe1[0] + v[1] * axe2[0] + v[2] * axe3[0] ay = v[0] * axe1[1] + v[1] * axe2[1] + v[2] * axe3[1] az = v[0] * axe1[2] + v[1] * axe2[2] + v[2] * axe3[2] v[0] = ax v[1] = ay v[2] = az for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] a = T.translate(CTK.t[2][nob][2][noz], (v[0], v[1], v[2])) CTK.replace(CTK.t, nob, noz, a) CTK.TXT.insert('START', 'Zones have been translated.\n') CTK.TKTREE.updateApp() CPlot.render()
def fixGap(): 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 # Contours name = VARS[0].get() names = name.split(';') contours = [] 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]): contours.append(z) # Surfaces name = VARS[1].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) p = G.plaster(contours, surfaces) contours = C.convertArray2Tetra(contours) contours = T.join(contours) contours = G.close(contours) b = G.gapfixer(contours, p) CTK.saveTree() CTK.t[2][1][2].append(b) #C._fillMissingVariables(CTK.t) CTK.TXT.insert('START', 'Gap fixed.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t)
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 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 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 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 getExtCenterSurfaces__(a, walls): dims0 = Internal.getZoneDim(a) ni0 = dims0[1] nj0 = dims0[2] nk0 = dims0[3] indicesI1 = [] indicesI2 = [] indicesJ1 = [] indicesJ2 = [] indicesK1 = [] indicesK2 = [] for w in walls: i1 = int(w[0]) i2 = int(w[1]) j1 = int(w[2]) j2 = int(w[3]) k1 = int(w[4]) k2 = int(w[5]) if i1 == i2: if i1 == 1: indicesI1.append([i1, j1, k1, i2, j2, k2]) else: indicesI2.append([i1, j1, k1, i2, j2, k2]) elif j1 == j2: if j1 == 1: indicesJ1.append([i1, j1, k1, i2, j2, k2]) else: indicesJ2.append([i1, j1, k1, i2, j2, k2]) elif k1 == k2: if k1 == 1: indicesK1.append([i1, j1, k1, i2, j2, k2]) else: indicesK2.append([i1, j1, k1, i2, j2, k2]) surfs = [] if indicesI1 != []: wloc = T.subzone(a, (1, 1, 1), (2, nj0, nk0)) surfs += getExtCenterSubWin(wloc, indicesI1, 1) if indicesI2 != []: wloc = T.subzone(a, (ni0 - 1, 1, 1), (ni0, nj0, nk0)) surfs += getExtCenterSubWin(wloc, indicesI2, 1) if indicesJ1 != []: wloc = T.subzone(a, (1, 1, 1), (ni0, 2, nk0)) surfs += getExtCenterSubWin(wloc, indicesJ1, 2) if indicesJ2 != []: wloc = T.subzone(a, (1, nj0 - 1, 1), (ni0, nj0, nk0)) surfs += getExtCenterSubWin(wloc, indicesJ2, 2) if indicesK1 != []: wloc = T.subzone(a, (1, 1, 1), (ni0, nj0, 2)) surfs += getExtCenterSubWin(wloc, indicesK1, 3) if indicesK2 != []: wloc = T.subzone(a, (1, 1, nk0 - 1), (ni0, nj0, nk0)) surfs += getExtCenterSubWin(wloc, indicesK2, 3) return surfs
def getExtCenterSubWin(wloc, allIndices, dirW=0): wloc = C.node2ExtCenter(wloc) dimsW = Internal.getZoneDim(wloc) niW = dimsW[1] njW = dimsW[2] nkW = dimsW[3] if dirW == 1: wLoc = T.subzone(wloc, (2, 1, 1), (2, njW, nkW)) elif dirW == 2: wLoc = T.subzone(wloc, (1, 2, 1), (niW, 2, nkW)) elif dirW == 3: wLoc = T.subzone(wloc, (1, 1, 2), (niW, njW, 2)) surfs = [] for indices in allIndices: imin = indices[0] imax = indices[3] jmin = indices[1] jmax = indices[4] kmin = indices[2] kmax = indices[5] dimS = Internal.getZoneDim(wLoc) niS = dimS[1] njS = dimS[2] nkS = dimS[3] if dirW == 1: iminL = jmin jminL = kmin imaxL = jmax + 1 jmaxL = kmax + 1 elif dirW == 2: iminL = imin jminL = kmin imaxL = imax + 1 jmaxL = kmax + 1 else: iminL = imin jminL = jmin imaxL = imax + 1 jmaxL = jmax + 1 sLoc = modifyBorders__(wLoc, iminL, imaxL, jminL, jmaxL) if dirW == 1: sLoc = T.subzone(sLoc, (jmin, kmin, 1), (jmax + 1, kmax + 1, 1)) elif dirW == 2: sLoc = T.subzone(sLoc, (imin, kmin, 1), (imax + 1, kmax + 1, 1)) elif dirW == 3: sLoc = T.subzone(sLoc, (imin, jmin, 1), (imax + 1, jmax + 1, 1)) surfs.append(sLoc) return surfs
def meshCircle(center, R, N): coeff = R * math.sqrt(2.) * 0.25 x = center[0] y = center[1] z = center[2] c = D.circle(center, R, tetas=-45., tetae=45., N=N) l1 = D.line((x + coeff, y - coeff, z), (x + coeff, y + coeff, z), N=N) l2 = D.line((x + coeff, y - coeff, z), (x + 2 * coeff, y - 2 * coeff, z), N=N) l3 = D.line((x + coeff, y + coeff, z), (x + 2 * coeff, y + 2 * coeff, z), N=N) m1 = G.TFI([c, l1, l2, l3]) c = D.circle(center, R, tetas=45., tetae=45. + 90., N=N) l1 = D.line((x + coeff, y + coeff, z), (x - coeff, y + coeff, z), N=N) l2 = D.line((x + coeff, y + coeff, z), (x + 2 * coeff, y + 2 * coeff, z), N=N) l3 = D.line((x - coeff, y + coeff, z), (x - 2 * coeff, y + 2 * coeff, z), N=N) m2 = G.TFI([c, l1, l2, l3]) c = D.circle(center, R, tetas=45. + 90, tetae=45. + 180., N=N) l1 = D.line((x - coeff, y + coeff, z), (x - coeff, y - coeff, z), N=N) l2 = D.line((x - coeff, y + coeff, z), (x - 2 * coeff, y + 2 * coeff, z), N=N) l3 = D.line((x - coeff, y - coeff, z), (x - 2 * coeff, y - 2 * coeff, z), N=N) m3 = G.TFI([c, l1, l2, l3]) c = D.circle(center, R, tetas=45. + 180, tetae=45. + 270., N=N) l1 = D.line((x - coeff, y - coeff, z), (x + coeff, y - coeff, z), N=N) l2 = D.line((x - coeff, y - coeff, z), (x - 2 * coeff, y - 2 * coeff, z), N=N) l3 = D.line((x + coeff, y - coeff, z), (x + 2 * coeff, y - 2 * coeff, z), N=N) m4 = G.TFI([c, l1, l2, l3]) h = 2 * coeff / (N - 1) m5 = G.cart((x - coeff, y - coeff, z), (h, h, h), (N, N, 1)) m5 = T.reorder(m5, (-1, 2, 3)) return [m1, m2, m3, m4, m5]
def breakElts(): 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: zones = T.breakElements(z) if (len(zones) > 0): CTK.replace(CTK.t, nob, noz, zones[0]) for zz in zones[1:]: CTK.add(CTK.t, nob, -1, zz) except Exception as e: fail = True errors += [0, str(e)] if not fail: CTK.TXT.insert('START', 'Zones converted to basic elements.\n') else: Panels.displayErrors(errors, header='Error: breakElts') CTK.TXT.insert('START', 'Break elts 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()