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 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 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()
# - getArgMax (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T import KCore.test as test # test sur une zone a = G.cart((0, 0, 0), (1., 1., 1.), (10, 10, 10)) a = C.initVars(a, 'F', 1.) a = C.initVars(a, 'centers:G', 2.) a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin') a = T.rotate(a, (0, 0, 0), (0, 0, 1), 5.) a = T.rotate(a, (0, 0, 0), (1, 0, 0), 5.) a = T.rotate(a, (0, 0, 0), (0, 1, 0), 5.) argmax = C.getArgMax(a, 'CoordinateX') test.testO(argmax, 1) # Sur un arbre b = G.cart((1., 0.2, 0.), (0.1, 0.1, 0.1), (11, 21, 2)) b = C.addBC2Zone(b, 'wall1', 'BCWall', 'imax') t = C.newPyTree(['Base']) t[2][1][2] += [a, b] t = C.initVars(t, 'F', 1.) t = C.initVars(t, 'centers:G', 2.) t[2][1] = C.addState(t[2][1], 'Mach', 0.6) t = T.rotate(t, (0, 0, 0), (0, 0, 1), 5.) t = T.rotate(t, (0, 0, 0), (1, 0, 0), 5.) t = T.rotate(t, (0, 0, 0), (0, 1, 0), 5.) argmax = C.getArgMax(t, 'CoordinateX') test.testO(argmax, 2)
# test maskXRay : points de percage (pyTree) import Connector.PyTree as X import Generator.PyTree as G import Geom.PyTree as D import Transform.PyTree as T import Converter.PyTree as C # retourne les pierce pts sous forme de 'NODE' surf = D.sphere((0, 0, 0), 0.5, 20) surf = T.rotate(surf, (0., 0., 0.), (0., 1., 0.), 90.) xray = X.maskXRay__(surf)
# - send (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T a = G.cart((0, 0, 0), (1, 1, 1), (100, 100, 30)) C.send(a, 'localhost') for i in range(30): a = T.rotate(a, (0, 0, 0), (0, 0, 1), 10.) C.send(a, 'localhost')
a = G.cart((0., 0., 0.), (0.1, 0.1, 0.2), (10, 11, 12)) b = G.cart((1.5, 0., 0.), (0.1, 0.1, 0.2), (15, 15, 8)) a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'imax') b = C.addBC2Zone(b, 'overlap', 'BCOverlap', 'imin') b = C.addBC2Zone(b, 'overlap', 'BCOverlap', 'kmax') # 1 seule base, pas d'extrapolation t = C.newPyTree(['Base']) t[2][1][2].append(a) t[2][1][2].append(b) t = X.applyBCOverlaps(t, depth=2) t = X.setInterpolations(t, loc='cell', storage='direct', sameBase=1) test.testT(t, 1) # 1 seule base, extrapolations a2 = T.rotate(a, (1.5, 0., 0.), (0., 1., 0.), 15.) b2 = T.rotate(b, (1.5, 0., 0.), (0., 1., 0.), -15.) t = C.newPyTree(['Base']) t[2][1][2].append(a2) t[2][1][2].append(b2) t = X.applyBCOverlaps(t, depth=2) t = X.setInterpolations(t, loc='cell', storage='direct', sameBase=1) test.testT(t, 2) # 2 bases differentes, pas d'extrapolation t = C.newPyTree(['Base1', 'Base2']) t[2][1][2].append(a) t[2][2][2].append(b) t = X.applyBCOverlaps(t, depth=2) t = X.setInterpolations(t, loc='cell', storage='direct', sameBase=1) test.testT(t, 3)
# - 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")
'BCOverlap', rangel, zoneDonor=[a], rangeDonor='doubly_defined') # t = C.newPyTree(['Base', 'Base2']) t[2][1][2] = [a] t[2][2][2] = [b] t = C.initVars(t, 'Density', 1.) t = C.initVars(t, 'centers:cellN', 1) t = X.setDoublyDefinedBC(t, depth=1) test.testT(t, 1) # # 2e cas : la fente est chimere periodique # b = T.rotate(b, (0, 0, 0), (0, 0, 1), 30.) Internal.createChild(b, '.Solver#Param', 'UserDefinedData_t', value=None, children=[]) solverParam = b[2][len(b[2]) - 1] Internal.createChild(solverParam, 'axis_ang_1', 'DataArray_t', value=10, children=[]) Internal.createChild(solverParam, 'axis_ang_2', 'DataArray_t', value=1,
# - reorderAll (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T ni = 30; nj = 40; nk = 1 m1 = G.cart((0,0,0), (10./(ni-1),10./(nj-1),1), (ni,nj,nk)); m1[0]='cart1' m2 = T.rotate(m1, (0.2,0.2,0.), (0.,0.,1.), 15.) m2 = T.reorder(m2,(-1,2,3)); m2[0]='cart2' t = C.newPyTree(['Base',2,[m1,m2]]) t = T.reorderAll(t, 1) C.convertPyTree2File(t, "out.cgns")
# - display (pyTree) - import Generator.PyTree as G import Converter.PyTree as C import CPlot.PyTree import Transform.PyTree as T a = G.cart((0,0,0),(1,1,1),(18,28,3)) t = C.newPyTree(['Base',a]) for i in xrange(360): t = T.rotate(t, (9, 14, 3.5), (0,0,1), 1.) CPlot.PyTree.display(t)
# - surfaceWalk (pyTree) import Converter.PyTree as C import Geom.PyTree as D import Transform.PyTree as T import Generator.PyTree as G # User definition of parametric curve def f(t, u): x = t + u y = t * t + 1 + u * u z = u return (x, y, z) # Array definition of geometry a = D.surface(f) c = D.circle((1.2, 1.7, 0.6), 0.1) c = T.rotate(c, (1.2, 1.7, 0.6), (0, 1, 0), 90.) c = T.reorder(c, (-1, 2, 3)) c = T.projectOrtho(c, [a]) h = G.cart((0., 0., 0.), (0.01, 1, 1), (15, 1, 1)) r = G.surfaceWalk([a], c, h, niter=100) C.convertPyTree2File(r, "out.cgns")
# - 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")
import KCore.test as test vectnames = [['centers:VelocityX','centers:VelocityY','centers:VelocityZ']] ni = 91; nj = 21 a = G.cylinder((0,0,0),0.5,1.,0.,90.,1.,(ni,nj,1)) a = C.initVars(a,'centers:VelocityX=0.') a = C.initVars(a,'centers:VelocityY=0.') a = C.initVars(a,'centers:VelocityZ=1.') vx = C.getField('centers:VelocityX',a)[0] vy = C.getField('centers:VelocityY',a)[0] nic = vx[2]; njc = vx[3] for j in xrange(njc): for i in xrange(nic): i0 = i * math.pi/2./90. vx[1][0,i+j*nic] = math.cos(i0) vy[1][0,i+j*nic] = math.sin(i0) C.setFields([vx],a,loc='centers') C.setFields([vy],a,loc='centers') a = C.center2Node(a,'centers:VelocityX') # Rotate with axis+angle b = T.rotate(a, (0.,0.,0.), (0.,0.,1.), 90., vectors=vectnames) test.testT(b,1) # Rotate with axis transformations c = T.rotate(a, (0.,0.,0.), ((1.,0.,0.),(0,1,0),(0,0,1)), ((1,1,0), (1,-1,0), (0,0,1)), vectors=vectnames) test.testT(c,2) # Rotate with three angles d = T.rotate(a, (0.,0.,0.), (0.,0.,90.), vectors=vectnames) test.testT(d,3)
# - sharpEdges (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Post.PyTree as P import Transform.PyTree as T import Geom.PyTree as D import KCore.test as test # liste de zones 2D structurees a1 = G.cart((0.,0.,0.),(1.5,1.,1.),(2,2,1)) a1 = C.addBC2Zone(a1,'wall','BCWall','jmin') a1 = C.addBC2Zone(a1,'overlap','BCOverlap','jmax') a2 = T.rotate(a1,(0.,0.,0.),(0.,1.,0.),100.); a2[0] = 'cart2' A = [a1,a2]; A = C.initVars(A,'P',1.); A = C.initVars(A,'centers:Q',2.) res = P.sharpEdges(A,alphaRef=45.) test.testT(res,1) # liste de zones QUAD A = C.convertArray2Hexa(A) A = C.initVars(A,'P',1.); A = C.initVars(A,'centers:Q',2.) res = P.sharpEdges(A,alphaRef=45.) test.testT(res,2) # liste de zones TRI A = C.convertArray2Tetra(A) A = C.initVars(A,'P',1.); A = C.initVars(A,'centers:Q',2.) res = P.sharpEdges(A,alphaRef=45.) test.testT(res,3) # 1D structure l1 = D.line((0.,0.,0.),(1.,0.,0.))
# - bboxIntersection (pyTree) - import Generator.PyTree as G import Transform.PyTree as T import KCore.test as test boxA = G.cartTetra((2,-1,0.5), (1,2,0.5), (2,2,2)) boxB = G.cartTetra((2,-1,0.5), (2,2,1), (2,2,2)) boxB = T.rotate(boxB,(0,0,0),(10,5,-20)) AABB = G.BB(boxA) OBB = G.BB(boxB, method='OBB') intersect = G.bboxIntersection(AABB, AABB, tol=1e-10,isBB=True, method='AABB') test.testO(intersect,1) intersect = G.bboxIntersection(AABB, OBB, tol=1e-10, isBB=True, method='AABBOBB') test.testO(intersect,2) intersect = G.bboxIntersection(AABB, OBB, tol=1e-10, isBB=True, method='OBB') test.testO(intersect,3)
# - checkPointInCEBB (pyTree) - import Generator.PyTree as G import Transform.PyTree as T import Converter.PyTree as C Ni = 20 Nj = 20 a2 = G.cart((-0.1, 0, 0), (0.5 / Ni, 0.5 / Nj, 1), (Ni, Nj, 2)) a2 = T.rotate(a2, (-0.1, 0, 0), (0, 0, 1), 0.22) # Check if point is in CEBB of a2 val = G.checkPointInCEBB(a2, (0.04839, 0.03873, 0.5)) print val
children=[]) Internal.createChild(solverParam, 'axis_vct_y', 'DataArray_t', value=0., children=[]) Internal.createChild(solverParam, 'axis_vct_z', 'DataArray_t', value=1., children=[]) Internal.createChild(solverParam, 'periodic_dir', 'DataArray_t', value=3, children=[]) b = T.rotate(b, (0, 0, 0), (0, 0, 1), 60.) # t = C.newPyTree(['Base', 'Base2']) t[2][1][2] = [a] t[2][2][2] = [b] t = C.initVars(t, 'Density', 1.) t = C.initVars(t, 'centers:cellN', 1) t = X.applyBCOverlaps(t, depth=1) t = X.setDoublyDefinedBC(t, depth=1) t = X.setInterpolations(t, double_wall=1, storage='direct', prefixFile=LOCAL + '/chm') test.testT(t, 2)
# - CEBBIntersection (pyTree)- import Generator.PyTree as G import Transform.PyTree as T ni = 11 nj = 3 nk = 11 a1 = G.cart((0., 0., 0.), (0.1, 0.1, 0.2), (ni, nj, nk)) a2 = G.cart((1., 0., 0.), (0.1, 0.1, 0.2), (ni, nj, nk)) a2 = T.rotate(a2, (0, 0, 0), (0, 0, 1), 12.) print(G.CEBBIntersection(a1, a2))
import Post.PyTree as P import KCore.test as test # cas simple a = D.circle((0., 0., 0.), 1.) a = C.convertArray2Hexa(a) a = G.close(a) a = C.initVars(a, 'F=3*{CoordinateX}+4*{CoordinateY}') a = C.initVars(a, 'centers:D={CoordinateX}') b = C.convertBAR2Struct(a) t = C.newPyTree(['Base', 1, b]) test.testT(t, 1) # # cas ou la bar n'est pas ordonnee - pas de boucle # a1 = G.cart((0., 0., 0.), (0.1, 0.1, 0.1), (11, 11, 1)) a2 = G.cart((0., 1., 0.), (0.1, 0.1, 0.1), (11, 1, 11)) a2 = T.rotate(a2, (0., 1., 0.), (1, 0, 0), -55) A = [a1, a2] A = C.convertArray2Hexa(A) a = T.join(A) a = T.reorder(a, (1, )) a = P.sharpEdges(a, 30.)[0] a = G.close(a) a = C.initVars(a, 'F=3*{CoordinateX}+4*{CoordinateY}') a = C.initVars(a, 'centers:D', 1.) b = C.convertBAR2Struct(a) t = C.newPyTree(['Base', 1]) t[2][1][2] += [b] test.testT(t, 2)
def moveZone__(z, time): cont = Internal.getNodeFromName1(z, 'TimeMotion') if cont is not None: motions = Internal.getNodesFromType1(cont, 'TimeRigidMotion_t') for m in motions: type = Internal.getNodeFromName1(m, 'MotionType') dtype = type[1][0] if dtype == 1: # type 1: time string tx = evalTimeString__(m, 'tx', time) ty = evalTimeString__(m, 'ty', time) tz = evalTimeString__(m, 'tz', time) cx = evalTimeString__(m, 'cx', time) cy = evalTimeString__(m, 'cy', time) cz = evalTimeString__(m, 'cz', time) ex = evalTimeString__(m, 'ex', time) ey = evalTimeString__(m, 'ey', time) ez = evalTimeString__(m, 'ez', time) angle = evalTimeString__(m, 'angle', time) z = T.translate(z, (tx, ty, tz)) if (angle != 0): z = T.rotate(z, (cx, cy, cz), (ex - cx, ey - cy, ez - cz), angle) elif dtype == 2: # type 2: rotation motion CassiopeeSolver try: import Cassiopee as K import elsA_user as E # caveat import KBridge except: raise ImportError( "evalPosition: motionRotor requires CassiopeeSolver.") transl_speed = getNodeValue__(m, 'transl_speed') psi0 = getNodeValue__(m, 'psi0') psi0_b = getNodeValue__(m, 'psi0_b') alp_pnt = getNodeValue__(m, 'alp_pnt') alp_vct = getNodeValue__(m, 'alp_vct') alp0 = getNodeValue__(m, 'alp0') rot_pnt = getNodeValue__(m, 'rot_pnt') rot_vct = getNodeValue__(m, 'rot_vct') rot_omg = getNodeValue__(m, 'rot_omg') del_pnt = getNodeValue__(m, 'del_pnt') del_vct = getNodeValue__(m, 'del_vct') del0 = getNodeValue__(m, 'del0') delc = getNodeValue__(m, 'delc') dels = getNodeValue__(m, 'dels') bet_pnt = getNodeValue__(m, 'bet_pnt') bet_vct = getNodeValue__(m, 'bet_vct') bet0 = getNodeValue__(m, 'bet0') betc = getNodeValue__(m, 'betc') bets = getNodeValue__(m, 'bets') tet_pnt = getNodeValue__(m, 'tet_pnt') tet_vct = getNodeValue__(m, 'tet_vct') tet0 = getNodeValue__(m, 'tet0') tetc = getNodeValue__(m, 'tetc') tets = getNodeValue__(m, 'tets') span_vct = getNodeValue__(m, 'span_vct') pre_lag_ang = getNodeValue__(m, 'pre_lag_ang') pre_lag_pnt = getNodeValue__(m, 'pre_lag_pnt') pre_lag_vct = getNodeValue__(m, 'pre_lag_vct') pre_con_ang = getNodeValue__(m, 'pre_con_ang') pre_con_pnt = getNodeValue__(m, 'pre_con_pnt') pre_con_vct = getNodeValue__(m, 'pre_con_vct') if z[0] + '_' + m[0] not in DEFINEDMOTIONS: Func1 = E.function('rotor_motion', z[0] + '_' + m[0]) # angle initial du rotor par rapport au champ a l'infini Func1.set("psi0", float(psi0[0])) # Angle initial de la pale # (si z est l'axe de rotation cet angle vaut psi0_b+pi/2) Func1.set("psi0_b", float(psi0_b[0])) # parametres inclinaison du rotor Func1.set("alp_pnt_x", float(alp_pnt[0])) Func1.set("alp_pnt_y", float(alp_pnt[1])) Func1.set("alp_pnt_z", float(alp_pnt[2])) Func1.set("alp_vct_x", float(alp_vct[0])) Func1.set("alp_vct_y", float(alp_vct[1])) Func1.set("alp_vct_z", float(alp_vct[2])) Func1.set("alp0", float(alp0[0])) # parametres rotation uniforme du rotor Func1.set("rot_pnt_x", float(rot_pnt[0])) Func1.set("rot_pnt_y", float(rot_pnt[1])) Func1.set("rot_pnt_z", float(rot_pnt[2])) Func1.set("rot_vct_x", float(rot_vct[0])) Func1.set("rot_vct_y", float(rot_vct[1])) Func1.set("rot_vct_z", float(rot_vct[2])) Func1.set("rot_omg", float(rot_omg[0])) # parametres 1ere rotation: trainee Func1.set("del_pnt_x", float(del_pnt[0])) Func1.set("del_pnt_y", float(del_pnt[1])) Func1.set("del_pnt_z", float(del_pnt[2])) Func1.set("del_vct_x", float(del_vct[0])) Func1.set("del_vct_y", float(del_vct[1])) Func1.set("del_vct_z", float(del_vct[2])) Func1.set("del0", float(del0[0])) Func1.set("nhdel", 3) Func1.set("del1c", float(delc[0])) Func1.set("del1s", float(dels[0])) Func1.set("del2c", float(delc[1])) Func1.set("del2s", float(dels[1])) Func1.set("del3c", float(delc[2])) Func1.set("del3s", float(dels[2])) # parametres 2eme rotation: battement Func1.set("bet_pnt_x", float(bet_pnt[0])) Func1.set("bet_pnt_y", float(bet_pnt[1])) Func1.set("bet_pnt_z", float(bet_pnt[2])) Func1.set("bet_vct_x", float(bet_vct[0])) Func1.set("bet_vct_y", float(bet_vct[1])) Func1.set("bet_vct_z", float(bet_vct[2])) Func1.set("bet0", float(bet0[0])) Func1.set("nhbet", 3) Func1.set("bet1c", float(betc[0])) Func1.set("bet1s", float(bets[0])) Func1.set("bet2c", float(betc[1])) Func1.set("bet2s", float(bets[1])) Func1.set("bet3c", float(betc[2])) Func1.set("bet3s", float(bets[2])) # parametres 3eme rotation: pas cyclique Func1.set("tet_pnt_x", float(tet_pnt[0])) Func1.set("tet_pnt_y", float(tet_pnt[1])) Func1.set("tet_pnt_z", float(tet_pnt[2])) Func1.set("tet_vct_x", float(tet_vct[0])) Func1.set("tet_vct_y", float(tet_vct[1])) Func1.set("tet_vct_z", float(tet_vct[2])) Func1.set("tet0", float(tet0[0])) Func1.set("nhtet", 1) Func1.set("tet1c", float(tetc[0])) Func1.set("tet1s", float(tets[0])) Func1.set('span_vct_x', float(span_vct[0])) Func1.set('span_vct_y', float(span_vct[1])) Func1.set('span_vct_z', float(span_vct[2])) Func1.set('pre_lag_ang', float(pre_lag_ang[0])) Func1.set('pre_lag_pnt_x', float(pre_lag_pnt[0])) Func1.set('pre_lag_pnt_y', float(pre_lag_pnt[1])) Func1.set('pre_lag_pnt_z', float(pre_lag_pnt[2])) Func1.set('pre_lag_vct_x', float(pre_lag_vct[0])) Func1.set('pre_lag_vct_y', float(pre_lag_vct[1])) Func1.set('pre_lag_vct_z', float(pre_lag_vct[2])) Func1.set('pre_con_ang', float(pre_con_ang[0])) Func1.set('pre_con_pnt_x', float(pre_con_pnt[0])) Func1.set('pre_con_pnt_y', float(pre_con_pnt[1])) Func1.set('pre_con_pnt_z', float(pre_con_pnt[2])) Func1.set('pre_con_vct_x', float(pre_con_vct[0])) Func1.set('pre_con_vct_y', float(pre_con_vct[1])) Func1.set('pre_con_vct_z', float(pre_con_vct[2])) DEFINEDMOTIONS[z[0] + '_' + m[0]] = Func1 else: Func1 = DEFINEDMOTIONS[z[0] + '_' + m[0]] M = KBridge.evalKDesFunction(Func1, time) z = evalPosition___(z, None, M) z = T.translate(z, (transl_speed[0] * time, transl_speed[1] * time, transl_speed[2] * time)) elif dtype == 3: # type 3: constant transl + rotation transl_speed = getNodeValue__(m, 'transl_speed') axis_pnt = getNodeValue__(m, 'axis_pnt') axis_vct = getNodeValue__(m, 'axis_vct') omega = getNodeValue__(m, 'omega') tx = transl_speed[0] * time ty = transl_speed[1] * time tz = transl_speed[2] * time z = T.translate(z, (tx, ty, tz)) cx = axis_pnt[0] + tx cy = axis_pnt[1] + ty cz = axis_pnt[2] + tz ex = axis_vct[0] ey = axis_vct[1] ez = axis_vct[2] angle = omega[0] * time * __RAD2DEG__ z = T.rotate(z, (cx, cy, cz), (ex - cx, ey - cy, ez - cz), angle) return z
# 1D structure a = G.cylinder((0., 0., 0.), 0.5, 1., 360., 0., 10., (50, 1, 1)) a = C.initVars(a, 'P', 1.) a = C.initVars(a, 'centers:Q', 2.) vector = [0., 1., 0.] res = P.silhouette(a, vector) test.testT(res, 1) vector = [1., 0., 0.] # 2D a1 = G.cylinder((0., 0., 0.), 0.5, 1., 360., 0., 10., (50, 1, 30)) a1 = C.addBC2Zone(a1, 'wall', 'BCWall', 'jmin') a1 = C.addBC2Zone(a1, 'overlap', 'BCOverlap', 'jmax') a2 = T.rotate(a1, (0., 0., 0.), (0., 1., 0.), 120.) a2[0] = 'cart2' A = [a1, a2] A = C.initVars(A, 'P', 1.) A = C.initVars(A, 'centers:Q', 2.) res = P.silhouette(A, vector) test.testT(res, 2) # BAR l1 = D.line((0., 0., 0.), (1., 0., 0.)) l2 = D.line((0., 0., 0.), (0., 1., 0.)) A = C.convertArray2Tetra([l1, l2]) A = C.initVars(A, 'P', 1.) A = C.initVars(A, 'centers:Q', 2.) res = P.silhouette(A, vector) test.testT(res, 3)
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()
def dens(x, y): return 3 * x * y # cas 2D c1 = G.cart((0, 0, 0), (0.01, 0.01, 1), (201, 101, 2)) c1 = C.addBC2Zone(c1, 'wall1', 'BCWall', 'imin') c1 = C.addBC2Zone(c1, 'match1', 'BCMatch', 'imax', c1, 'imin', [1, 2, 3]) c1 = C.addBC2Zone(c1, 'overlap1', 'BCOverlap', 'jmax') c1 = C.initVars(c1, 'centers:celln', 1.) c1 = C.initVars(c1, 'Density', dens, ['CoordinateX', 'CoordinateY']) c2 = G.cart((0, 0, 0), (0.01, 0.01, 1), (51, 81, 2)) c2 = T.rotate(c2, (0, 0, 0), (0, 0, 1), 0.2) c2 = C.addBC2Zone(c2, 'wall1', 'BCWall', 'imin') c2 = C.addBC2Zone(c2, 'overlap1', 'BCOverlap', 'imax') c2 = C.initVars(c2, 'centers:celln', 1.) c2 = C.initVars(c2, 'Density', dens, ['CoordinateX', 'CoordinateY']) a = T.patch(c1, c2, (1, 1, 1)) t = C.newPyTree(['Base', 3]) t[2][1][2].append(a) test.testT(t, 1) # multizone a = D.sphere6((0, 0, 0), 1, N=20) t = C.newPyTree(['Base', 3]) t[2][1][2] += a k = 0 t2 = T.subzone(t, (1, 1, k + 1), (-1, -1, k + 1))
# - blankIntersectingCells (pyTree) import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T import Connector.PyTree as X a1 = G.cart((0., 0., 0.), (1., 1., 1.), (11, 11, 11)) a2 = T.rotate(a1, (0., 0., 0.), (0., 0., 1.), 10.) a2 = T.translate(a2, (7., 5., 5.)) a1[0] = 'cart1' a2[0] = 'cart2' t = C.newPyTree(['Base', a1, a2]) t = C.initVars(t, 'centers:cellN', 1.) t2 = X.blankIntersectingCells(t, tol=1.e-10) C.convertPyTree2File(t2, "out.cgns")
a X.connectMatch on the full mesh. Since zone names in the duplicated mesh are the same as in original mesh, this will result in a correct connectivity. Then, we perform the same thing for the other direction. """ import Converter.PyTree as C import Connector.PyTree as X import Transform.PyTree as T import Generator.PyTree as G a = G.cylinder((0., 0., 0.), 0.1, 1., 0., 90., 5., (11, 11, 11)) t = C.newPyTree(['Cylindre']) t[2][1][2] += [a] # Duplicate mesh by a rotation of +90 degrees ap = T.rotate(a, (0., 0., 0.), (0., 0., 1.), 90.) t = C.addBase2PyTree(t, 'CylindreDup') t[2][2][2] += [ap] t = X.connectMatch(t) # Duplicate mesh by a rotation of +90 degrees # Replace duplicated zones am = T.rotate(a, (0., 0., 0.), (0., 0., 1.), -90.) t[2][2][2] = [am] t = X.connectMatch(t) # Remove duplicated basis t[2][1:] = t[2][1:2] C.convertPyTree2File(t, 'out.cgns')
def F(x, y): return x * x + 2 * y ni = 30 nj = 40 a = G.cart((0, 0, 0), (10. / (ni - 1), 10. / (nj - 1), 1), (ni, nj, 1)) a = C.initVars(a, 'centers:cellN', 1.) a = C.initVars(a, 'Density', F, ['CoordinateX', 'CoordinateY']) a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imax') a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmax') #------------------------------------------------- # test 1 : blocs recouvrants pareillement orientes #------------------------------------------------- b = T.rotate(a, (0.2, 0.2, 0.), (0., 0., 1.), 15.) b[0] = 'cart2' B = T.reorderAll([a, b], 1) test.testT(B, 1) #------------------------------------------------- # test 2 : blocs recouvrants orientes differemment #------------------------------------------------- b = T.reorder(b, (-1, 2, 3)) B = T.reorderAll([a, b], 1) test.testT(B, 2) #--------------------------------- # test 3: blocs sans intersection #--------------------------------- b = T.translate(a, (0., 12, 0.))
def drawCircle(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') w = WIDGETS['draw'] prev = []; second = [] if CTK.__BUSY__ == False: CTK.__BUSY__ = True TTK.sunkButton(w) CPlot.setState(cursor=1) while CTK.__BUSY__: 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 second point...\n') elif (second == [] and prev != l): second = l CTK.TXT.insert('START', 'Click third point...\n') elif (prev != l and second != l): x1 = l[0]; y1 = l[1]; z1 = l[2] x2 = prev[0]; y2 = prev[1]; z2 = prev[2] x3 = second[0]; y3 = second[1]; z3 = second[2] xa = x2 - x1; ya = y2 - y1; za = z2 - z1 xb = x3 - x1; yb = y3 - y1; zb = z3 - z1 xc = x3 - x2; yc = y3 - y2; zc = z3 - z2 a2 = xa*xa + ya*ya + za*za b2 = xb*xb + yb*yb + zb*zb c2 = xc*xc + yc*yc + zc*zc A = 2*b2*c2 + 2*c2*a2 + 2*a2*b2 - a2*a2 - b2*b2 - c2*c2 R = math.sqrt( a2*b2*c2 / A ) nx = ya*zb - za*yb ny = za*xb - xa*zb nz = xa*yb - ya*xb tx = ya*nz - za*ny ty = za*nx - xa*nz tz = xa*ny - ya*nx norm = tx*tx + ty*ty + tz*tz normi = 1./math.sqrt(norm) tx = tx*normi; ty = ty*normi; tz = tz*normi; alpha = R*R - (xa*xa+ya*ya+za*za)*0.25 alpha = math.sqrt(alpha) center = [0,0,0] center[0] = 0.5*(x1+x2) + alpha*tx center[1] = 0.5*(y1+y2) + alpha*ty center[2] = 0.5*(z1+z2) + alpha*tz l = (center[0]-x3)*(center[0]-x3) + \ (center[1]-y3)*(center[1]-y3) + \ (center[2]-z3)*(center[2]-z3) if (abs(l - R*R) > 1.e-10): center[0] = 0.5*(x1+x2) - alpha*tx center[1] = 0.5*(y1+y2) - alpha*ty center[2] = 0.5*(z1+z2) - alpha*tz l = (center[0]-x3)*(center[0]-x3) + \ (center[1]-y3)*(center[1]-y3) + \ (center[2]-z3)*(center[2]-z3) circle = D.circle( (center[0],center[1],center[2]), R, N=npts) e1 = [x1-center[0], y1-center[1], z1-center[2]] e2 = [x2-center[0], y2-center[1], z2-center[2]] e3 = Vector.cross(e1, e2) e4 = Vector.cross(e1, e3) circle = T.rotate(circle, (center[0], center[1], center[2]), ((1,0,0), (0,1,0), (0,0,1)), (e1, e4, e3)) if (surfaces != []): circle = T.projectOrthoSmooth(circle, surfaces) CTK.add(CTK.t, nob, -1, circle) CTK.TXT.insert('START', 'Circle 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)
t[2][1][2][0] = C.addBC2Zone(t[2][1][2][0], 'overlap', 'BCOverlap', 'imin') t = C.fillEmptyBCWith(t, 'wall', 'BCWall', dim=2) b = T.merge(t) t2 = C.newPyTree(['Surface', 2]) t2[2][1][2] += b test.testT(t2, 1) b = T.merge(t, alphaRef=45.) t2 = C.newPyTree(['Surface', 2]) t2[2][1][2] = b test.testT(t2, 2) # # cas d'angles vifs # a1 = G.cart((0, 0, 0), (1, 1, 1), (11, 11, 1)) a3 = G.cart((10, 0, 0), (1, 1, 1), (11, 11, 1)) a2 = T.rotate(a1, (0, 0, 0), (1, 0, 0), 90.) a2 = T.reorder(a2, (-1, 2, 3)) a2[0] = C.getZoneName(a1[0]) t = C.newPyTree(['Base', 2]) t[2][1][2] += [a1, a2, a3] t = C.initVars(t, 'F', 1.) t = C.initVars(t, 'centers:G', 2.) t[2][1][2][0] = C.addBC2Zone(t[2][1][2][0], 'overlap', 'BCOverlap', 'imin') t = X.connectMatch(t, dim=2) t = C.fillEmptyBCWith(t, 'wall', 'BCWall', dim=2) a = T.merge(t, alphaRef=45.) t = C.newPyTree(['Base', 2]) t[2][1][2] += a test.testT(t, 3) # volume grid
def drawArc(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') w = WIDGETS['draw'] prev = []; second = [] if CTK.__BUSY__ == False: CTK.__BUSY__ = True TTK.sunkButton(w) CPlot.setState(cursor=1) while CTK.__BUSY__: 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 second point...\n') elif (second == [] and prev != l): second = l CTK.TXT.insert('START', 'Click third point...\n') elif (prev != l and second != l): x1 = l[0]; y1 = l[1]; z1 = l[2] x2 = prev[0]; y2 = prev[1]; z2 = prev[2] x3 = second[0]; y3 = second[1]; z3 = second[2] xa = x2 - x1; ya = y2 - y1; za = z2 - z1 xb = x3 - x1; yb = y3 - y1; zb = z3 - z1 xc = x3 - x2; yc = y3 - y2; zc = z3 - z2 a2 = xa*xa + ya*ya + za*za b2 = xb*xb + yb*yb + zb*zb c2 = xc*xc + yc*yc + zc*zc A = 2*b2*c2 + 2*c2*a2 + 2*a2*b2 - a2*a2 - b2*b2 - c2*c2 R = math.sqrt( a2*b2*c2 / A ) nx = ya*zb - za*yb ny = za*xb - xa*zb nz = xa*yb - ya*xb tx = ya*nz - za*ny ty = za*nx - xa*nz tz = xa*ny - ya*nx norm = tx*tx + ty*ty + tz*tz normi = 1./math.sqrt(norm) tx = tx*normi; ty = ty*normi; tz = tz*normi; alpha = R*R - (xa*xa+ya*ya+za*za)*0.25 alpha = math.sqrt(alpha) center = [0,0,0] center[0] = 0.5*(x1+x2) + alpha*tx center[1] = 0.5*(y1+y2) + alpha*ty center[2] = 0.5*(z1+z2) + alpha*tz dx3 = center[0]-x3; dy3 = center[1]-y3; dz3 = center[2]-z3 l = dx3*dx3 + dy3*dy3 + dz3*dz3 if (abs(l - R*R) > 1.e-10): center[0] = 0.5*(x1+x2) - alpha*tx center[1] = 0.5*(y1+y2) - alpha*ty center[2] = 0.5*(z1+z2) - alpha*tz dx3 = center[0]-x3; dy3 = center[1]-y3; dz3 = center[2]-z3 l = dx3*dx3 + dy3*dy3 + dz3*dz3 e1 = [x1-center[0], y1-center[1], z1-center[2]] e2 = [x2-center[0], y2-center[1], z2-center[2]] e3 = Vector.cross(e1, e2) e4 = Vector.cross(e1, e3) # Images des pts dans le plan xyz pt1 = D.point((x1,y1,z1)) pt2 = D.point((x2,y2,z2)) pt3 = D.point((x3,y3,z3)) pt1 = T.rotate(pt1, (center[0], center[1], center[2]), (e1, e4, e3), ((1,0,0), (0,1,0), (0,0,1)) ) pt2 = T.rotate(pt2, (center[0], center[1], center[2]), (e1, e4, e3), ((1,0,0), (0,1,0), (0,0,1))) pt3 = T.rotate(pt3, (center[0], center[1], center[2]), (e1, e4, e3), ((1,0,0), (0,1,0), (0,0,1))) xp1 = C.getValue(pt1, 'CoordinateX', 0) yp1 = C.getValue(pt1, 'CoordinateY', 0) zp1 = C.getValue(pt1, 'CoordinateZ', 0) xp2 = C.getValue(pt2, 'CoordinateX', 0) yp2 = C.getValue(pt2, 'CoordinateY', 0) zp2 = C.getValue(pt2, 'CoordinateZ', 0) xp3 = C.getValue(pt3, 'CoordinateX', 0) yp3 = C.getValue(pt3, 'CoordinateY', 0) zp3 = C.getValue(pt3, 'CoordinateZ', 0) dx1 = (xp1-center[0])/R; dy1 = (yp1-center[1])/R if dx1 > 1.: dx1 = 1. if dx1 < -1.: dx1 = -1. if dy1 > 0: teta1 = math.acos(dx1) else: teta1 = 2*math.pi - math.acos(dx1) teta1 = teta1*180./math.pi; teta1 = 360. dx2 = (xp2-center[0])/R; dy2 = (yp2-center[1])/R if dx2 > 1.: dx2 = 1. if dx2 < -1.: dx2 = -1. if dy2 > 0: teta2 = math.acos(dx2) else: teta2 = 2*math.pi - math.acos(dx2) teta2 = teta2*180./math.pi dx3 = (xp3-center[0])/R; dy3 = (yp3-center[1])/R if dx3 > 1.: dx3 = 1. if dx3 < -1.: dx3 = -1. if dy3 > 0: teta3 = math.acos(dx3) else: teta3 = 2*math.pi - math.acos(dx3) teta3 = teta3*180./math.pi if teta3 > teta2: teta1 = 360. else: teta1 = 0. circle = D.circle((center[0],center[1],center[2]), R, tetas=teta2, tetae=teta1, N=npts) circle = T.rotate(circle, (center[0], center[1], center[2]), ((1,0,0), (0,1,0), (0,0,1)), (e1, e4, e3)) if surfaces != []: circle = T.projectOrthoSmooth(circle, surfaces) CTK.add(CTK.t, nob, -1, circle) CTK.TXT.insert('START', 'Circle 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)