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 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 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 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)
# - deformMesh (pyTree) - import Transform.PyTree as T import Converter.PyTree as C import Geom.PyTree as D a1 = D.sphere6((0,0,0),1,20) a1 = C.convertArray2Tetra(a1); a1 = T.join(a1) point = C.getValue(a1, 'GridCoordinates', 0) a2 = T.deformPoint(a1, point, (0.1,0.05,0.2), 0.5, 2.) delta = C.diffArrays(a2,a1) deltax = C.getField('DCoordinateX',delta) deltay = C.getField('DCoordinateY',delta) deltaz = C.getField('DCoordinateZ',delta) for noz in range(len(deltax)): deltax[noz][0] = 'dx' deltay[noz][0] = 'dy' deltaz[noz][0] = 'dz' a1 = C.setFields(deltax,a1,'nodes') a1 = C.setFields(deltay,a1,'nodes') a1 = C.setFields(deltaz,a1,'nodes') m = D.sphere6((0,0,0),2,20) m = T.deformMesh(m, a1) C.convertPyTree2File(m, "out.cgns")
def drawRectangle(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 left/lower corner...\n') w = WIDGETS['draw'] prev = []; second = [] if (CTK.__BUSY__ == False): CTK.__BUSY__ = True TTK.sunkButton(w) CPlot.setState(cursor=1) while (CTK.__BUSY__ == True): CPlot.unselectAllZones() CTK.saveTree() surfaces = getSurfaces() l = [] while (l == []): l = CPlot.getActivePoint() time.sleep(CPlot.__timeStep__) w.update() if (CTK.__BUSY__ == False): break if (CTK.__BUSY__ == True): if (prev == []): prev = l CTK.TXT.insert('START', 'Click right/up corner...\n') elif (prev != l): e1,e2 = getVectorsFromCanvas() e1n = Vector.norm(e1) e2n = Vector.norm(e2) if (e2n > e1n): e1 = e2 P1 = l; P2 = prev P1P2 = Vector.sub(P2, P1) P1P2n = Vector.norm(P1P2) Q = Vector.norm(Vector.cross(e1, P1P2)) L = math.sqrt( P1P2n*P1P2n - Q*Q ) sign = Vector.dot(e1, P1P2) if (sign > 0): e1 = Vector.mul(L, e1) else: e1 = Vector.mul(-L, e1) P3 = Vector.add(P1, e1) P4 = Vector.sub(P2, e1) l1 = D.line(P1, P3, npts) l2 = D.line(P3, P2, npts) l3 = D.line(P2, P4, npts) l4 = D.line(P4, P1, npts) rect = T.join([l1,l2,l3,l4]) if (surfaces != []): rect = T.projectOrthoSmooth(rect, surfaces) CTK.add(CTK.t, nob, -1, rect) CTK.TXT.insert('START', 'Rectangle created.\n') CTK.__BUSY__ = False TTK.raiseButton(w) CPlot.setState(cursor=0) #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(w) CPlot.setState(cursor=0) else: CTK.__BUSY__ = False TTK.raiseButton(w) CPlot.setState(cursor=0)
# - deformMesh (pyTree) - import Generator.PyTree as G import Transform.PyTree as T import Converter.PyTree as C import Geom.PyTree as D a1 = D.sphere6((0, 0, 0), 1, 20) a1 = C.convertArray2Tetra(a1) a1 = T.join(a1) point = C.getValue(a1, 'GridCoordinates', 0) a2 = T.deformPoint(a1, point, (0.1, 0.05, 0.2), 0.5, 2.) delta = C.diffArrays(a2, a1) deltax = C.getField('DCoordinateX', delta) deltay = C.getField('DCoordinateY', delta) deltaz = C.getField('DCoordinateZ', delta) for noz in xrange(len(deltax)): deltax[noz][0] = 'dx' deltay[noz][0] = 'dy' deltaz[noz][0] = 'dz' a1 = C.setFields(deltax, a1, 'nodes') a1 = C.setFields(deltay, a1, 'nodes') a1 = C.setFields(deltaz, a1, 'nodes') m = D.sphere6((0, 0, 0), 2, 20) m = T.deformMesh(m, a1) C.convertPyTree2File(m, "out.cgns")
import Converter.Internal as Internal import Generator.PyTree as G import Connector.PyTree as X import Geom.PyTree as D import Post.PyTree as P import numpy as N import Dist2Walls.PyTree as DTW import Transform.PyTree as T import Initiator.PyTree as I import KCore.test as test import sys a = G.cart((-1, -1, -1), (0.04, 0.04, 1), (51, 51, 3)) s = G.cylinder((0, 0, -1), 0, 0.4, 360, 0, 4, (30, 30, 5)) s = C.convertArray2Tetra(s) s = T.join(s) s = P.exteriorFaces(s) t = C.newPyTree(['Base']) t[2][1][2] = [a] # Blanking bodies = [[s]] BM = N.array([[1]], N.int32) t = X.blankCells(t, bodies, BM, blankingType='center_in') t = X.setHoleInterpolatedPoints(t, depth=-2) # Dist2Walls t = DTW.distance2Walls(t, [s], type='ortho', loc='centers', signed=1) t = C.center2Node(t, 'centers:TurbulentDistance') # Gradient de distance localise en centres => normales t = P.computeGrad(t, 'TurbulentDistance') t = I.initConst(t, MInf=0.2, loc='centers') tc = C.node2Center(t)
# - checkDelaunay (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Geom.PyTree as D import Transform.PyTree as T A = D.text1D('STEPHANIE') A = C.convertArray2Tetra(A) a = T.join(A) # Triangulation respecting given contour tri = G.constrainedDelaunay(a) res = G.checkDelaunay(a, tri) C.convertPyTree2File(res, "out.cgns")
# - addNormalLayers (pyTree) - import Generator.PyTree as G import Converter.PyTree as C import Transform.PyTree as T import Geom.PyTree as D d = G.cart((0.1, 0., 0.), (0.1, 1, 1), (2, 1, 1)) a = D.sphere((0, 0, 0), 1, 50) a = D.line((0, 0, 0), (1, 1, 0), 3) b = G.addNormalLayers(a, d) d = G.cart((0.1, 0., 0.), (-0.1, 1, 1), (2, 1, 1)) c = G.addNormalLayers(a, d) a = T.join(b, c) C.convertPyTree2File(a, 'out.cgns')
# - getSmoothNormalMap (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T import Geom.PyTree as D a = G.cart((0.,0.,0.),(1.,1.,1.),(10,10,1)) b = G.cart((0.,0.,0.),(1.,1.,1.),(1,10,10)) b = T.rotate(b,(0.,0.,0.),(0.,1.,0.),45.) c = C.convertArray2Hexa([a,b]) c = T.join(c); c = T.reorder(c,(1,)) c = T.rotate(c,(0.,0.,0.),(0.,1.,0.),15.) c = G.getSmoothNormalMap(c,niter=4) C.convertPyTree2File(c, "out.cgns")
# - join (pyTree) - import Generator.PyTree as G import Geom.PyTree as D import Transform.PyTree as T import Converter.PyTree as C import KCore.test as test # Join 2 NON-STRUCT TETRA a1 = G.cartTetra((0.,0.,0.), (1.,1.,1), (11,11,10)) a2 = G.cartTetra((10.,0.,0.), (1.,1.,1), (10,10,10)) a1 = C.initVars(a1, 'F', 2); a1 = C.initVars(a1, 'centers:G', 1) a2 = C.initVars(a2, 'F', 3); a2 = C.initVars(a2, 'centers:G', 3) t = C.newPyTree(['Base',3]) a = T.join(a1, a2); t[2][1][2].append(a) test.testT(t, 1) # mix struct 3D + HEXA a1 = G.cart((0.,0.,0.), (1.,1.,1), (11,11,10)) a1 = C.addBC2Zone(a1,'wall','BCWall','imin') a1 = C.addBC2Zone(a1,'ov','BCOverlap','imax') a1 = C.addBC2Zone(a1,'match1','BCMatch','jmin',a1, 'jmax') a2 = G.cartHexa((10.,0.,0.), (1.,1.,1), (11,11,10)) a1 = C.initVars(a1, 'F', 2); a1 = C.initVars(a1, 'centers:G', 1) a2 = C.initVars(a2, 'F', 3); a2 = C.initVars(a2, 'centers:G', 3) t = C.newPyTree(['Base',3]) a = T.join(a1, a2); t[2][1][2].append(a) test.testT(t, 2) # Join 2 NON-STRUCT PENTA a1 = G.cartPenta((0.,0.,0.), (1.,1.,1), (11,11,10)) a2 = G.cartPenta((10.,0.,0.), (1.,1.,1), (10,10,10))
# - setInterpTransfers IBC + extraction (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Connector.PyTree as X import Geom.PyTree as D import Post.PyTree as P import numpy as N import Dist2Walls.PyTree as DTW import Transform.PyTree as T import Initiator.PyTree as I import Converter.Internal as Internal import KCore.test as test a = G.cart((-1,-1,-1),(0.04,0.04,1),(51,51,3)) s = G.cylinder((0,0,-1), 0, 0.4, 360, 0, 4, (30,30,5)) s = C.convertArray2Tetra(s); s = T.join(s); s = P.exteriorFaces(s) t = C.newPyTree(['Base']); t[2][1][2] = [a] # Blanking bodies = [[s]] BM = N.array([[1]],N.int32) t = X.blankCells(t,bodies,BM,blankingType='center_in') t = X.setHoleInterpolatedPoints(t,depth=-2) # Dist2Walls t = DTW.distance2Walls(t,[s],type='ortho',loc='centers',signed=1) t = C.center2Node(t,'centers:TurbulentDistance') # Gradient de distance localise en centres => normales t = P.computeGrad(t, 'TurbulentDistance') t = I.initConst(t,MInf=0.2,loc='centers') tc = C.node2Center(t) t = X.setIBCData(t, tc, loc='centers', storage='direct') no = 1
# - getSharpestAngle (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T import Geom.PyTree as D N = 10 d1 = G.cart((0.,0.,0.), (0.05,1,1),(N,1,4)) d2 = G.cart((0.,0.,0.), (1.,0.001,1),(1,10*N,4)) d2 = T.rotate(d2,(0.,0.,0.),(0.,0.,1.),30.) s = T.join(d1,d2) s = C.convertArray2Hexa(s) s = T.reorder(s,(-1,)) s = D.getSharpestAngle(s) ts = C.newPyTree(['Base',2]); ts[2][1][2] +=[s] C.convertPyTree2File(ts,"out.cgns")
# - boolean difference (array) - import Intersector.PyTree as XOR import Converter.PyTree as C import Transform.PyTree as T M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M1 = C.conformizeNGon(M1) M1 = XOR.closeOctalCells(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) M2 = C.conformizeNGon(M2) M2 = XOR.closeOctalCells(M2) tol = -0.5e-3 M = T.join(M1,M2) M = XOR.selfX(M) C.convertPyTree2File(M, 'out.cgns')
# - connectMatch sur meme bloc (pyTree)- import Generator.PyTree as G import Converter.PyTree as C import Connector.PyTree as X import Geom.PyTree as D import Transform.PyTree as T import KCore.test as test a = G.cylinder((0.,0.,0.), 0.5, 1., 360., 0., 10., (50,50,30)) t = C.newPyTree(['Base', a]) t = X.connectMatch(t) test.testT(t,1) # 3D raccord i = 1 partiel profil NACA a = D.naca(12., 5001) a2 = D.line((1.,0.,0.),(2.,0.,0.),5001); a = T.join(a, a2) a2 = D.line((2.,0.,0.),(1.,0.,0.),5001); a = T.join(a2, a) Ni = 300; Nj = 50 distrib = G.cart((0,0,0), (1./(Ni-1), 0.5/(Nj-1),1), (Ni,Nj,1)) naca = G.hyper2D(a, distrib, "C") a = T.addkplane(naca) # --- champ aux centres C._initVars(a, 'centers:Density', 1.) # --- champ aux noeuds C._initVars(a, 'cellN', 2.) t = C.newPyTree(['Base', a]) # --- Equation state t[2][1] = C.addState(t[2][1], 'EquationDimension', 3) t = X.connectMatch(t) test.testT(t,2)
import Converter.PyTree as C import Transform.PyTree as T import Geom.PyTree as D import Converter.Internal as Internal import KCore.test as test a = D.sphere6((0.,0.,0.),1.,N=10) C._initVars(a,'Fx=1.') C._initVars(a,'Fy=2.') C._initVars(a,'Fz=3.') C._initVars(a[1],'toto=0.') noz = 0 for z in Internal.getZones(a): if noz != 1: C._initVars(z,'{centers:Gx}=2.') C._initVars(z,'{centers:Gy}=1.') else: C._initVars(z,'{centers:Gy}=1.') C._initVars(z,'{centers:Gx}=2.') GC = Internal.getNodeFromType(z,'GridCoordinates_t') Internal._rmNodesFromName(z,GC[0]) if noz == 1: XA = Internal.getNodeFromName(GC,'CoordinateX') Internal._rmNodesFromName(GC,'CoordinateX') GC[2].append(XA) z[2].append(GC) noz+=1 res = T.join(a[0:2]) test.testT(res,1)
# - projectCloudSolution(pyTree) - import Converter.PyTree as C import Geom.PyTree as D import Post.PyTree as P import Transform.PyTree as T import Generator.PyTree as G import KCore.test as test a = D.sphere((0,0,0),1.,N=20) a = C.convertArray2Tetra(a); a = G.close(a) b = D.sphere6((0,0,0),1.,N=15) b = C.convertArray2Tetra(b); b = T.join(b) pts = C.convertArray2Node(b) C._initVars(pts, '{F}={CoordinateX}*{CoordinateY}') C._initVars(a, 'F', 0.) a = P.projectCloudSolution(pts,a) test.testT(a)
# - getSmoothNormalMap (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T import KCore.test as test a = G.cart((0., 0., 0.), (1., 1., 1.), (10, 10, 1)) b = G.cart((0., 0., 0.), (1., 1., 1.), (1, 10, 10)) b = T.rotate(b, (0., 0., 0.), (0., 1., 0.), 45.) #QUAD c = C.convertArray2Hexa([a, b]) c = T.join(c) c = T.reorder(c, (1, )) c = T.rotate(c, (0., 0., 0.), (0., 1., 0.), 15.) c = G.getSmoothNormalMap(c, niter=4) test.testT(c, 1) #QUAD c = C.convertArray2Tetra([a, b]) c = T.join(c) c = T.reorder(c, (1, )) c = T.rotate(c, (0., 0., 0.), (0., 1., 0.), 15.) c = G.getSmoothNormalMap(c, niter=4) test.testT(c, 2)
def smooth(): 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 smooth = CTK.varsFromWidget(VARS[0].get(), type=2) if len(smooth) != 1: CTK.TXT.insert('START', 'Smooth iter is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return smooth = smooth[0] eps = CTK.varsFromWidget(VARS[4].get(), type=1) if len(eps) != 1: CTK.TXT.insert('START', 'Eps is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return eps = eps[0] ntype = VARS[8].get() if ntype == 'Volume': ntype = 0 elif ntype == 'Scale': ntype = 1 elif ntype == 'Taubin': ntype = 2 else: ntype = 0 # Constraint strength strength = CTK.varsFromWidget(VARS[2].get(), type=1) if len(strength) != 1: CTK.TXT.insert('START', 'Constraint strength is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return strength = strength[0] # Constraints fixedConstraints = []; projConstraints = [] name = VARS[1].get() names = name.split(';') for v in names: v = v.lstrip(); v = v.rstrip() sname = v.split('/', 1) base = Internal.getNodeFromName1(CTK.t, sname[0]) if base is not None: nodes = Internal.getNodesFromType1(base, 'Zone_t') for z in nodes: if (z[0] == sname[1]): fixedConstraints.append(z) CTK.saveTree() # Get all zones zones = [] for nz in nzs: nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] zones.append(z) # Mesh unique try: A = C.convertArray2Tetra(zones) A = T.join(A); A = G.close(A) except Exception as e: Panels.displayErrors([0,str(e)], header='Error: smooth') CTK.TXT.insert('START', 'Some zones are invalid for smoothing.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return # pb surfacique ou volumique? dims = Internal.getZoneDim(A) pbDim = 3 if dims[3] == 'TRI': pbDim = 2 # Keep external faces if VARS[3].get() == 1 or pbDim == 3: try: ext = P.exteriorFaces(A) except: ext = [] if VARS[3].get() == 1 and ext != []: fixedConstraints.append(ext) # Keep sharp edges if VARS[5].get() == 1: angle = CTK.varsFromWidget(VARS[6].get(), type=1) if len(angle) != 1: CTK.TXT.insert('START', 'Sharp edges angle is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return angle = angle[0] if pbDim == 2: try: sharp = P.sharpEdges(A, angle) fixedConstraints += sharp except: pass else: try: sharp = P.sharpEdges(ext, angle) fixedConstraints += sharp except: pass # Project on surface Pj = VARS[7].get() if pbDim == 2: projSurf = A else: # projSurf = ext # Pour l'instant, on ne sait pas projeter un maillage volumique # sur une surface Pj = 0 # Smooth fail = False try: if Pj == 0: zones = T.smooth(zones, eps=eps, niter=smooth, type=ntype, fixedConstraints=fixedConstraints, projConstraints=projConstraints, delta=strength) else: for s in xrange(smooth): zones = T.smooth(zones, eps=eps, niter=2, type=ntype, fixedConstraints=fixedConstraints, projConstraints=projConstraints, delta=strength) zones = T.projectOrtho(zones, [projSurf]) except Exception as e: fail = True Panels.displayErrors([0,str(e)], header='Error: smooth') if fail == False: c = 0 for nz in nzs: nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] a = zones[c]; c += 1 CTK.replace(CTK.t, nob, noz, a) CTK.TXT.insert('START', 'Mesh smoothed.\n') else: CTK.TXT.insert('START', 'Smooth fails.\n') CTK.TXT.insert('START', 'Error: ', 'Error') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
# - join (pyTree) - import Transform.PyTree as T import Converter.PyTree as C import Generator.PyTree as G import KCore.test as test # Join 2 NGON avec TETRA : 2 zones a1 = G.cartTetra((0., 0., 0.), (1., 1., 1), (11, 11, 10)) a1 = C.convertArray2NGon(a1) a1 = C.initVars(a1, 'F', 2.) a1 = C.initVars(a1, 'centers:G', 1) a2 = G.cartTetra((10., 0., 0.), (1., 1., 1), (10, 10, 10)) a2 = C.convertArray2NGon(a2) a2 = C.initVars(a2, 'F', 3.) a2 = C.initVars(a2, 'centers:G', 3) a = T.join(a1, a2) t = C.newPyTree(['Base']) t[2][1][2].append(a) test.testT(t, 1) # # Join sur une liste de zones # t = C.newPyTree(['Base']) t[2][1][2].append(a1) t[2][1][2].append(a2) t[2][1][2].append(T.join(t[2][1][2])) test.testT(t, 2) # # Join sur un arbre # t = C.newPyTree(['Base'])
def OTFI(): 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.convertArray2Hexa(z) zones.append(z) zones = T.join(zones) zones = G.close(zones) a = C.convertBAR2Struct(z) weight = CTK.varsFromWidget(VARS[1].get(), type=1) weight = weight[0] # Nombre de pts Nt = Internal.getZoneDim(a)[1] if Nt / 2 - Nt * 0.5 == 0: CTK.TXT.insert('START', 'Number of points of countour must be odd.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return coords = C.getFields(Internal.__GridCoordinates__, a)[0] optWeight = 0 optOffset = 0 optScore = 1.e6 Nt = coords[2] for j in range(-Nt // 4, Nt // 4 + 1): for i in range(3, 10): try: [m, m1, m2, m3, m4] = TFIs.TFIO__(coords, i, j) score = quality([m, m1, m2, m3]) if score < optScore: optWeight = i optOffset = j optScore = score except: pass print('resulting weight=%g, offset=%g.' % (optWeight, optOffset)) print('resulting score=%g.' % optScore) [m, m1, m2, m3, m4] = TFIs.TFIO__(coords, optWeight, optOffset) m = C.convertArrays2ZoneNode('TFI1', [m]) m1 = C.convertArrays2ZoneNode('TFI2', [m1]) m2 = C.convertArrays2ZoneNode('TFI3', [m2]) m3 = C.convertArrays2ZoneNode('TFI4', [m3]) m4 = C.convertArrays2ZoneNode('TFI5', [m4]) if surf != []: m = T.projectOrtho(m, surf) m1 = T.projectOrthoSmooth(m1, surf) m2 = T.projectOrthoSmooth(m2, surf) m3 = T.projectOrthoSmooth(m3, surf) m4 = T.projectOrthoSmooth(m4, 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 [m, m1, m2, m3, m4]: CTK.add(CTK.t, nob, -1, i) CTK.TXT.insert('START', 'O-TFI mesh created.\n') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
# - checkDelaunay (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Geom.PyTree as D import Transform.PyTree as T A = D.text1D('STEPHANIE') A = C.convertArray2Tetra(A); a = T.join(A) # Triangulation respecting given contour tri = G.constrainedDelaunay(a) res = G.checkDelaunay(a, tri) C.convertPyTree2File(res, "out.cgns")
# - breakElements (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T a = G.cartTetra((0, 0, 0), (1, 1, 1), (3, 3, 2)) a = C.convertArray2NGon(a) a = G.close(a) b = G.cartNGon((2, 0, 0), (1, 1, 1), (3, 3, 1)) res = T.join(a, b) res = T.breakElements(res) C.convertPyTree2File(res, 'out.cgns')
# - quad2Pyra (pyTree) - import Generator.PyTree as G import Converter.PyTree as C import Geom.PyTree as D import Transform.PyTree as T a = D.sphere6((0,0,0), 1, N=10) a = C.convertArray2Hexa(a) a = T.join(a) a = G.close(a) b = G.quad2Pyra(a, hratio=1.) C.convertPyTree2File(b, 'out.cgns')
import Transform.PyTree as T import KCore.test as test a = G.cylinder((0., 0., 0.), 0.5, 1., 360., 0., 10., (50, 51, 30)) a1 = T.subzone(a, (1, 1, 1), (25, 51, 30)) a2 = T.subzone(a, (25, 1, 1), (50, 51, 30)) a2 = T.oneovern(a2, (1, 2, 1)) t = C.newPyTree(['Base']) t[2][1][2] += [a1, a2] t = X.connectNearMatch(t) test.testT(t, 1) # 3D raccord i = 1 partiel profil NACA a = D.naca(12., 5001) a2 = D.line((1., 0., 0.), (2., 0., 0.), 5001) a = T.join(a, a2) a2 = D.line((2., 0., 0.), (1., 0., 0.), 5001) a = T.join(a2, a) Ni = 301 Nj = 51 distrib = G.cart((0, 0, 0), (1. / (Ni - 1), 0.5 / (Nj - 1), 1), (Ni, Nj, 1)) naca = G.hyper2D(a, distrib, "C") a = T.addkplane(naca) a1 = T.subzone(a, (1, 1, 1), (151, Nj, 2)) a2 = T.subzone(a, (151, 1, 1), (Ni, Nj, 2)) a2 = T.oneovern(a2, (2, 2, 1)) t = C.newPyTree(['Base']) t[2][1][2] += [a1, a2] # --- Equation state t[2][1] = C.addState(t[2][1], 'EquationDimension', 2) # --- champ aux centres
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()
# - join (pyTree) - import Generator.PyTree as G import Geom.PyTree as D import Transform.PyTree as T import Converter.PyTree as C import KCore.test as test # Join 2 NON-STRUCT TETRA a1 = G.cartTetra((0., 0., 0.), (1., 1., 1), (11, 11, 10)) a2 = G.cartTetra((10., 0., 0.), (1., 1., 1), (10, 10, 10)) a1 = C.initVars(a1, 'F', 2) a1 = C.initVars(a1, 'centers:G', 1) a2 = C.initVars(a2, 'F', 3) a2 = C.initVars(a2, 'centers:G', 3) t = C.newPyTree(['Base', 3]) a = T.join(a1, a2) t[2][1][2].append(a) test.testT(t, 1) # mix struct 3D + HEXA a1 = G.cart((0., 0., 0.), (1., 1., 1), (11, 11, 10)) a1 = C.addBC2Zone(a1, 'wall', 'BCWall', 'imin') a1 = C.addBC2Zone(a1, 'ov', 'BCOverlap', 'imax') a1 = C.addBC2Zone(a1, 'match1', 'BCMatch', 'jmin', a1, 'jmax') a2 = G.cartHexa((10., 0., 0.), (1., 1., 1), (11, 11, 10)) a1 = C.initVars(a1, 'F', 2) a1 = C.initVars(a1, 'centers:G', 1) a2 = C.initVars(a2, 'F', 3) a2 = C.initVars(a2, 'centers:G', 3) t = C.newPyTree(['Base', 3]) a = T.join(a1, a2)
# Extraction de lignes x = cste bb = G.bbox(a) xmin = bb[0] ymin = bb[1] zmin = bb[2] xmax = bb[3] ymax = bb[4] zmax = bb[5] bands = [] dx = 1. / 10 for i in range(10): x = i / 10. b = G.cart((x, ymin - 1, zmin - 1), (dx, ymax - ymin + 2, zmax - zmin + 2), (2, 2, 2)) b = P.exteriorFaces(b) b = C.convertArray2Tetra(b) b = T.join(b) b = G.close(b) b = T.reorder(b, (-1, )) band = G.booleanIntersection(a, b) bands += [band] # Boolean operators do not keep field bands = P.extractMesh(a, bands) # Sortie t = C.newPyTree(['Base']) t[2][1][2] += bands C.convertPyTree2File(t, 'out.cgns')
# - refine (pyTree) - import Geom.PyTree as D import Transform.PyTree as T import Converter.PyTree as C a = D.line((0,0,0), (1,0,0), N=10) b = D.line((1,0,0), (2,1,0), N=30) a = T.join([a,b]) a = D.refine(a, N=30) C.convertPyTree2File(a, 'out.cgns')