# - merge (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T import Connector.PyTree as X import Geom.PyTree as D def f(t,u): x = t+u y = t*t+1+u*u z = u return (x,y,z) a = D.surface(f) b = T.splitSize(a, 100) b = X.connectMatch(b, dim=2) t = C.newPyTree(['Surface']); t[2][1][2] += b b = T.merge(t) t[2][1][2] = b C.convertPyTree2File(t, "out.cgns")
import Generator.PyTree as G import Transform.PyTree as T import Connector.PyTree as X import Geom.PyTree as D import KCore.test as test def f(t, u): x = t + u y = t * t + 1 + u * u z = u return (x, y, z) # surface grid a = D.surface(f, N=50) b = T.splitSize(a, 100) b = X.connectMatch(b, dim=2) t = C.newPyTree(['Surface', 2]) t[2][1][2] += b 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 = 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
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()
# - conformUnstr (pyTree) - # Conforming 1 or 2 TRI/BAR together (same type for both operands) import Generator.PyTree as G import Intersector.PyTree as XOR import Converter.PyTree as C import Geom.PyTree as D from Geom.Parametrics import base import Transform.PyTree as T s1 = D.sphere((0, 0, 0), 1, N=20) s2 = D.surface(base['plane'], N=30) s2 = T.translate(s2, (0.2, 0.2, 0.2)) s1 = C.convertArray2Tetra(s1) s1 = G.close(s1) s2 = C.convertArray2Tetra(s2) s2 = G.close(s2) x = XOR.conformUnstr(s1, s2, tol=0.) C.convertPyTree2File(x, 'out.plt') c1 = D.circle((0, 0, 0), 1, N=100) c2 = D.circle((0.2, 0, 0), 1, N=50) c1 = C.convertArray2Tetra(c1) c1 = G.close(c1) c2 = C.convertArray2Tetra(c2) c2 = G.close(c2) x = XOR.conformUnstr(c1, c2, tol=0.)
# Fonction de surface def FS(t, u): x = t + u y = t * t + 1 + u * u z = u return (x, y, z) # Create an init function def FI(x, y, z): return x * x + y * y + z * z # Creation de la surface portant la solution a = D.surface(FS, 50) a = C.initVars(a, 'sol', FI, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) # Creation de la surface d'extraction e = D.surface(FS, 100) e = P.extractMesh([a], e, order=2, tol=1.e-3) test.testT(e, 1) # unstructured surface a = C.convertArray2Tetra(a) a = C.initVars(a, 'sol', FI, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) e = C.convertArray2Tetra(e) e = P.extractMesh([a], e, order=2, tol=1.e-3) test.testT(e, 2) # arbre