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 generate(event=None): CTK.saveTree() N = CTK.varsFromWidget(VARS[0].get(), type=2) if len(N) != 1: CTK.TXT.insert('START', 'NPts is incorrect.\n') return N = N[0] eltType = VARS[1].get() surfType = VARS[2].get() if surfType == 'Sphere': s = D.sphere6((0, 0, 0), 0.5, N=N) xc = 0 yc = 0 zc = 0 elif surfType == 'Plane': h = 1. / (N - 1) s1 = G.cart((-0.5, -0.5, -0.5), (h, h, h), (N, 1, N)) s = [s1] xc = 0 yc = 0 zc = 0 elif surfType == 'Cube': h = 1. / (N - 1) s1 = G.cart((-0.5, -0.5, -0.5), (h, h, h), (N, N, 1)) s1 = T.reorder(s1, (-1, 2, 3)) s2 = G.cart((-0.5, -0.5, 0.5), (h, h, h), (N, N, 1)) s3 = G.cart((-0.5, -0.5, -0.5), (h, h, h), (N, 1, N)) s4 = G.cart((-0.5, 0.5, -0.5), (h, h, h), (N, 1, N)) s4 = T.reorder(s4, (-1, 2, 3)) s5 = G.cart((-0.5, -0.5, -0.5), (h, h, h), (1, N, N)) s5 = T.reorder(s5, (1, -2, 3)) s6 = G.cart((0.5, -0.5, -0.5), (h, h, h), (1, N, N)) s = [s1, s2, s3, s4, s5, s6] xc = 0 yc = 0 zc = 0 elif surfType == 'Tetra': m1 = meshTri([0, 0, 0], [1, 0, 0], [0, 1, 0], N=N) m1 = T.reorder(m1, (-1, 2, 3)) m2 = meshTri([0, 0, 0], [1, 0, 0], [0, 0, 1], N=N) m3 = meshTri([0, 0, 0], [0, 1, 0], [0, 0, 1], N=N) m3 = T.reorder(m3, (-1, 2, 3)) m4 = meshTri([1, 0, 0], [0, 1, 0], [0, 0, 1], N=N) s = m1 + m2 + m3 + m4 xc = 0.5 yc = 0.5 zc = 0.5 elif surfType == 'Pyramid': h = 1. / (2 * N - 2) m0 = G.cart((-0.5, -0.5, -0.5), (h, h, h), (2 * N - 1, 2 * N - 1, 1)) m0 = T.reorder(m0, (-1, 2, 3)) m1 = meshTri([-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [0, 0, 0.5], N=N) m2 = meshTri([-0.5, -0.5, -0.5], [-0.5, 0.5, -0.5], [0, 0, 0.5], N=N) m2 = T.reorder(m2, (-1, 2, 3)) m3 = meshTri([-0.5, 0.5, -0.5], [0.5, 0.5, -0.5], [0, 0, 0.5], N=N) m3 = T.reorder(m3, (-1, 2, 3)) m4 = meshTri([0.5, -0.5, -0.5], [0.5, 0.5, -0.5], [0, 0, 0.5], N=N) s = [m0] + m1 + m2 + m3 + m4 xc = 0. yc = 0. zc = 0. elif surfType == 'Cylinder': m0 = meshCircle((0, 0, -0.5), 0.5, N) m1 = meshCircle((0, 0, 0.5), 0.5, N) m1 = T.reorder(m1, (-1, 2, 3)) m2 = D.circle((0, 0, -0.5), 0.5, tetas=-45, tetae=-45 + 360, N=4 * N - 3) l = D.line((0, 0, -0.5), (0, 0, 0.5), N=N) m2 = D.lineDrive(m2, l) s = m0 + m1 + [m2] xc = 0. yc = 0. zc = 0. elif surfType == 'Cone': s = [D.cone((0., 0, 0), 1, 0.1, 1, N=N)] (xc, yc, zc) = G.barycenter(s) else: # Geom parametrics surfaces formula = base[surfType] if formula.replace('{u}', '') == formula: # curve s = D.curve(base[surfType], N) else: s = D.surface(base[surfType], N) (xc, yc, zc) = G.barycenter(s) s = [s] if eltType == 'TRI': s = C.convertArray2Tetra(s) s = T.join(s) s = G.close(s) elif eltType == 'QUAD': s = C.convertArray2Hexa(s) s = T.join(s) s = G.close(s) posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') dirCam = CPlot.getState('dirCam') s = T.translate(s, (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 < 1.e-10: 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) s = T.homothety(s, (posEye[0], posEye[1], posEye[2]), 0.5 * ll) ux = dirCam[1] * lz - dirCam[2] * ly uy = dirCam[2] * lx - dirCam[0] * lz uz = dirCam[0] * ly - dirCam[1] * lx s = T.rotate(s, (posEye[0], posEye[1], posEye[2]), ((1, 0, 0), (0, 1, 0), (0, 0, 1)), ((-ux, -uy, -uz), (lx, ly, lz), dirCam)) CTK.t = C.addBase2PyTree(CTK.t, 'SURFACES', 2) b = Internal.getNodeFromName1(CTK.t, 'SURFACES') if eltType == 'TRI' or eltType == 'QUAD': nob = C.getNobOfBase(b, CTK.t) CTK.add(CTK.t, nob, -1, s) else: nob = C.getNobOfBase(b, CTK.t) if CP.__slot__ is None: CTK.t[2][nob][2] += s CTK.display(CTK.t) else: for i in s: CTK.add(CTK.t, nob, -1, i) #C._fillMissingVariables(CTK.t) CTK.TXT.insert('START', 'Surface created.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
# - collarMesh (pyTree) import Converter.PyTree as C import Geom.PyTree as D import Transform.PyTree as T import Generator.PyTree as G s1 = D.sphere((0., 0., 0.), 1, 20) s2 = T.translate(s1, (1.2, 0., 0.)) s2 = T.homothety(s2, (0, 0, 0), 0.5) dhj = G.cart((0., 0., 0.), (1.e-2, 1, 1), (21, 1, 1)) dhk = G.cart((0., 0., 0.), (1.e-2, 1, 1), (11, 1, 1)) a = G.collarMesh(s1, s2, dhj, dhk, niterj=100, niterk=100, type='union') C.convertPyTree2File(a, "out.cgns")
# - homothety (pyTree) - # traitement par zone import Transform.PyTree as T import Generator.PyTree as G import Converter.PyTree as C import KCore.test as test # Structure 3D + champs + CL a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 3)) a = C.addVars(a, 'Density') a = C.initVars(a, 'centers:cellN', 1) a = C.addBC2Zone(a, 'wall', 'BCWall', 'imin') a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2, 3]) a = T.homothety(a, (0., 0., 0.), 2.) test.testT(a, 1) # Structure 2D a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 1)) a = C.addVars(a, 'Density') a = C.initVars(a, 'centers:cellN', 1) a = C.addBC2Zone(a, 'wall', 'BCWall', 'imin') a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'jmin') a = T.homothety(a, (0., 0., 0.), 2.) test.testT(a, 2) # TETRA a = G.cartTetra((0, 0, 0), (1, 1, 1), (10, 10, 3)) a = C.addVars(a, 'Density') a = C.initVars(a, 'centers:cellN', 1) a = T.homothety(a, (0., 0., 0.), 2.)
def scale(): 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[1].get(), type=1) if len(v) != 1 and len(v) != 3 and len(v) != 6: CTK.TXT.insert('START', 'Scale factor is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return axis = VARS[5].get() if axis == 'along XYZ': axe1 = (1, 0, 0) axe2 = (0, 1, 0) axe3 = (0, 0, 1) else: # 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]) nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() selection = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] selection.append(z) if len(v) == 6: # center is given X = [v[3], v[4], v[5]] else: X = G.barycenter(selection) if len(v) == 1 and v[0] == 0.: # scale unitaire bbox = G.bbox(selection) dx = bbox[3] - bbox[0] dy = bbox[4] - bbox[1] dz = bbox[5] - bbox[2] if dx >= dy and dx >= dz: v[0] = 1. / dx if dy >= dx and dy >= dz: v[0] = 1. / dy if dz >= dy and dz >= dx: v[0] = 1. / dz list = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] list.append((nob, noz, nz)) z = CTK.t[2][nob][2][noz] if len(v) == 1: a = T.homothety(z, (X[0], X[1], X[2]), v[0]) else: z = T.contract(z, (X[0], X[1], X[2]), axe2, axe3, v[0]) z = T.contract(z, (X[0], X[1], X[2]), axe1, axe3, v[1]) a = T.contract(z, (X[0], X[1], X[2]), axe1, axe2, v[2]) CTK.replace(CTK.t, nob, noz, a) CTK.TXT.insert('START', 'Zones have been scaled.\n') CTK.TKTREE.updateApp() CPlot.render()
import Transform.PyTree as T import Generator.PyTree as G import Converter.PyTree as C import KCore.test as test # Structure 3D + champs + CL a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 3)) a = C.addVars(a, 'Density') a = C.initVars(a, 'centers:cellN', 1) a = C.addBC2Zone(a, 'wall', 'BCWall', 'imin') a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2, 3]) t = C.newPyTree(['Base']) t[2][1][2].append(a) t[2][1] = C.addState(t[2][1], 'EquationDimension', 3) t = T.homothety(t, (0., 0., 0.), 2.) test.testT(t, 1) # Structure 2D a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 1)) a = C.addVars(a, 'Density') a = C.initVars(a, 'centers:cellN', 1) a = C.addBC2Zone(a, 'wall', 'BCWall', 'imin') a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'jmin') t = C.newPyTree(['Base', 2]) t[2][1][2].append(a) t[2][1] = C.addState(t[2][1], 'EquationDimension', 2) t = T.homothety(t, (0., 0., 0.), 2.) test.testT(t, 2) # TETRA
# - homothety (PyTree) - import Generator.PyTree as G import Transform.PyTree as T import Converter.PyTree as C a = G.cart((0,0,0), (1,1,1), (10,10,10)) b = T.homothety(a, (0.,0.,0.), 2.); b[0] = 'cart2' C.convertPyTree2File([a,b], "out.cgns")
# - polyC1Mesher (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T tb = C.convertFile2PyTree('curve1.svg', nptsCurve=100, nptsLine=400) z = T.homothety(tb[2][1][2][0], (0., 0., 0.), 0.01) z = T.reorder(z, (-1, 2, 3)) h = 0.1 hf = 0.001 density = 100 splitCrit = 10. res = G.polyC1Mesher(z, h, hf, density, splitCrit) zones = res[0] h = res[1] density = res[2] t = C.newPyTree(['Base']) t[2][1][2] += zones C.convertPyTree2File(t, 'out.cgns')
def replaceText(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 CTK.saveTree() # Recupere l'OBB de la selection Z = [] dels = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] Z.append(CTK.t[2][nob][2][noz]) dels.append(CTK.t[2][nob][0] + Internal.SEP1 + CTK.t[2][nob][2][noz][0]) nob0 = CTK.Nb[nzs[0]] + 1 try: a = T.join(Z) except: a = Z[0] OBB = G.BB(a, method='OBB') P0 = C.getValue(OBB, 'GridCoordinates', 0) P1 = C.getValue(OBB, 'GridCoordinates', 1) P2 = C.getValue(OBB, 'GridCoordinates', 2) P3 = C.getValue(OBB, 'GridCoordinates', 4) v1 = Vector.sub(P1, P0) n1 = Vector.norm(v1) v2 = Vector.sub(P2, P0) n2 = Vector.norm(v2) v3 = Vector.sub(P3, P0) n3 = Vector.norm(v3) v1p = v1 v2p = v2 v3p = v3 if abs(n1) < 1.e-12: v1 = Vector.cross(v2, v3) v1p = (0., 0., 0.) elif abs(n2) < 1.e-12: v2 = Vector.cross(v1, v3) v2p = (0., 0., 0.) elif abs(n3) < 1.e-12: v3 = Vector.cross(v2, v3) v3p = (0., 0., 0.) # Essaie de matcher les vecteur sur la vue p1,p2,p3 # On suppose que dirCam doit etre e2, ... posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') dirCam = CPlot.getState('dirCam') e2 = dirCam e3 = Vector.sub(posCam, posEye) e1 = Vector.cross(e2, e3) f1 = None f2 = None f3 = None Pt = P0 s1 = Vector.dot(e1, v1) s2 = Vector.dot(e1, v2) s3 = Vector.dot(e1, v3) if abs(s1) > abs(s2) and abs(s1) > abs(s3): if s1 > 0: f1 = v1 else: f1 = Vector.mul(-1., v1) Pt = Vector.add(Pt, v1p) elif abs(s2) > abs(s1) and abs(s2) > abs(s3): if s2 > 0: f1 = v2 else: f1 = Vector.mul(-1., v2) Pt = Vector.add(Pt, v2p) elif abs(s3) > abs(s1) and abs(s3) > abs(s2): if s3 > 0: f1 = v3 else: f1 = Vector.mul(-1., v3) Pt = Vector.add(Pt, v3p) s1 = Vector.dot(e2, v1) s2 = Vector.dot(e2, v2) s3 = Vector.dot(e2, v3) if abs(s1) > abs(s2) and abs(s1) > abs(s3): if s1 > 0: f2 = v1 else: f2 = Vector.mul(-1., v1) Pt = Vector.add(Pt, v1p) elif abs(s2) > abs(s1) and abs(s2) > abs(s3): if s2 > 0: f2 = v2 else: f2 = Vector.mul(-1., v2) Pt = Vector.add(Pt, v2p) elif abs(s3) > abs(s1) and abs(s3) > abs(s2): if s3 > 0: f2 = v3 else: f2 = Vector.mul(-1., v3) Pt = Vector.add(Pt, v3p) s1 = Vector.dot(e3, v1) s2 = Vector.dot(e3, v2) s3 = Vector.dot(e3, v3) if abs(s1) > abs(s2) and abs(s1) > abs(s3): if s1 > 0: f3 = v1 else: f3 = Vector.mul(-1., v1) Pt = Vector.add(Pt, v1p) elif abs(s2) > abs(s1) and abs(s2) > abs(s3): if s2 > 0: f3 = v2 else: f3 = Vector.mul(-1., v2) Pt = Vector.add(Pt, v2p) elif abs(s3) > abs(s1) and abs(s3) > abs(s2): if s3 > 0: f3 = v3 else: f3 = Vector.mul(-1., v3) Pt = Vector.add(Pt, v3p) (x0, y0, z0) = Pt n2 = Vector.norm(f2) # Cree le texte 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 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) BB = G.bbox(a) h2 = BB[4] - BB[1] # Scale, positionne le texte factor = n2 / h2 a = T.homothety(a, (BB[0], BB[1], BB[2]), factor) a = T.translate(a, (x0 - BB[0], y0 - BB[1], z0 - BB[2])) a = T.rotate(a, (x0, y0, z0), ((1, 0, 0), (0, 1, 0), (0, 0, 1)), ((f1, f2, f3))) CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs) CPlot.delete(dels) CTK.add(CTK.t, nob0, -1, a) #C._fillMissingVariables(CTK.t) CTK.TXT.insert('START', 'Text replaced.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
# - collarMesh (pyTree) import Converter.PyTree as C import Geom.PyTree as D import Transform.PyTree as T import Generator.PyTree as G s1 = D.sphere((0.,0.,0.),1,20) s2 = T.translate(s1,(1.2,0.,0.)); s2 = T.homothety(s2,(0,0,0),0.5) dhj = G.cart((0.,0.,0.),(1.e-2,1,1),(21,1,1)) dhk = G.cart((0.,0.,0.),(1.e-2,1,1),(11,1,1)) a = G.collarMesh(s1,s2, dhj,dhk,niterj=100,niterk=100,type='union') C.convertPyTree2File(a,"out.cgns")