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()
import Generator.PyTree as G import Connector.PyTree as X import KCore.test as test # #---------- # # 2D STRUCT # #---------- ni = 15 nj = 15 m1 = G.cart((0, 0, 0), (10. / (ni - 1), 10. / (nj - 1), 1.), (ni, nj, 1)) m2 = G.cart((0, 10, 0), (10. / (ni - 1), 10. / (nj - 1), 1.), (ni, nj, 1)) m3 = G.cart((10, 0, 0), (10. / (ni - 1), 10. / (nj - 1), 1.), (ni, nj, 1)) t = C.newPyTree(['Base', m1, m2, m3]) t = X.connectMatch(t, dim=2) t = C.fillEmptyBCWith(t, "wall", 'BCWall') C._initVars(t, '{centers:fldX}= ({centers:CoordinateX})**2') C._initVars(t, '{centers:fldY}= ({centers:CoordinateY})**2') C._initBCDataSet(t, '{fldX}=0.5') C._initBCDataSet(t, '{fldY}=0.5') P._computeDiv2(t, 'centers:fld') test.testT(t, 1) # #---------- # # 3D STRUCT # #---------- ni = 15
# - getProcList (pyTree) - import Generator.PyTree as G import Distributor2.PyTree as D2 import Converter.PyTree as C import Connector.PyTree as X N = 11 t = C.newPyTree(['Base']) pos = 0 for i in range(N): a = G.cart((pos,0,0), (1,1,1), (10+i, 10, 10)) pos += 10 + i - 1 t[2][1][2].append(a) t = X.connectMatch(t) t, stats = D2.distribute(t, 3) procList = D2.getProcList(t) print(procList)
# - 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 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 test.testT(t2, 2) #
import KCore.test as test a = G.cartNGon((1, 1, 1), (1., 1., 1.), (4, 10, 1)) a[0] = 'cart1' b = G.cartNGon((4, 2, 1), (1., 1., 1.), (5, 8, 1)) b[0] = 'cart2' c = G.cartNGon((4, 9, 1), (1., 1., 1.), (4, 5, 1)) c[0] = 'cart3' t = CP.newPyTree(['Base', a, b, c]) t = CP.initVars(t, '{F}=3*{CoordinateX}+2*{CoordinateY}') t = CP.initVars(t, '{centers:G}=2.3') t = CP.initVars(t, '{centers:H}={centers:CoordinateY}') t = CP.initVars(t, '{centers:M}={centers:CoordinateX}') t = X.connectMatch(t, dim=2) t = CP.fillEmptyBCWith(t, "wall", 'BCWall') varL = ['H'] zones = Internal.getZones(t) it = 0 for z in zones: dim = Internal.getZoneDim(z) gcs = Internal.getNodesFromType2(z, 'GridConnectivity_t') for gc in gcs: it = it + 1 zname = Internal.getValue(gc) zdonor = Internal.getNodeFromName(t, zname)
d = G.cart((1, 1, 6), (1., 1., 1.), (4, Nj, 3)) d[0] = 'cart4' a = T.reorder(a, (-2, 1, 3)) b = T.reorder(b, (1, 2, 3)) c = T.reorder(c, (3, 1, 2)) # init cellN a = C.initVars(a, 'centers:cellN', 1.) b = C.initVars(b, 'centers:cellN', 0.) c = C.initVars(c, 'centers:cellN', 1.) d = C.initVars(d, 'centers:cellN', 0.) t = C.newPyTree(['Base', a, b, c, d]) t = C.initVars(t, '{F}=3*{CoordinateX}+2*{CoordinateY}') t = C.initVars(t, '{centers:G}={centers:CoordinateZ}') t = X.connectMatch(t, dim=3) t = C.fillEmptyBCWith(t, 'wall', 'BCWall') t = Internal.addGhostCells(t, t, 2, adaptBCs=0, fillCorner=1) test.testT(t, 1) t = C.newPyTree(['Base', a, b, c, d]) t = C.initVars(t, '{F}=3*{CoordinateX}+2*{CoordinateY}') t = C.initVars(t, '{centers:G}={centers:CoordinateZ}') t = X.connectMatch(t, dim=3) t = C.fillEmptyBCWith(t, "wall", 'BCWall') t = Internal.addGhostCells(t, t, 2, adaptBCs=1, fillCorner=1) test.testT(t, 2) # geometrical extrapolation of corner cells t = C.newPyTree(['Base', a, b, c, d]) t = C.initVars(t, '{F}=3*{CoordinateX}+2*{CoordinateY}') t = C.initVars(t, '{centers:G}={centers:CoordinateZ}')
a[0] = 'cart1' # partiellement coincident # --- CL a2 = G.cart((1., 0.5, 0.), (0.1, 0.1, 0.1), (11, 21, 2)) a2[0] = 'cart2' a2 = C.addBC2Zone(a2, 'wall1', 'BCWall', 'jmax') a2 = C.addBC2Zone(a2, 'overlap1', 'BCOverlap', 'jmin') # --- champ aux centres a2 = C.initVars(a2, 'centers:Density', 1.) # --- champ aux noeuds a2 = C.initVars(a2, 'cellN', 2.) t = C.newPyTree(['Base', a, a2]) # --- Equation state t[2][1] = C.addState(t[2][1], 'EquationDimension', 3) t[2][1][2] = X.connectMatch(t[2][1][2]) test.testT(t, 1) # coincident a3 = G.cart((1.00001, 0., 0.), (0.1, 0.1, 0.1), (11, 21, 2)) a3[0] = 'cart3' t = C.newPyTree(['Base']) t[2][1][2] += [a, a3] C._addState(t[2][1], 'EquationDimension', 3) t[2][1][2] = X.connectMatch(t[2][1][2], tol=2.e-5) test.testT(t, 2) # CAS NGON a1 = G.cartNGon((0., 0., 0.), (0.1, 0.1, 0.1), (11, 21, 11)) a1[0] = 'cart1' a2 = G.cartNGon((1., 0., 0.), (0.1, 0.1, 0.1), (11, 21, 11))
def connectMatch(): if CTK.t == []: return eps = VARS[2].get() eps = float(eps) node = Internal.getNodeFromName(CTK.t, 'EquationDimension') if node is not None: ndim = Internal.getValue(node) else: CTK.TXT.insert('START', 'EquationDimension not found (tkState). Using 3D.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') ndim = 3 mode = VARS[9].get() translation = [0., 0., 0.] rotationCenter = [0., 0., 0.] rotationAngle = [0., 0., 0.] if mode == 'Translation': mode = 1 translation = CTK.varsFromWidget(VARS[10].get(), type=1) elif mode == 'Rotation (Degree)': mode = 1 f = CTK.varsFromWidget(VARS[10].get(), type=1) rotationCenter = f[0:3] rotationAngle = f[3:6] else: mode = 0 nzs = CPlot.getSelectedZones() CTK.saveTree() if CTK.__MAINTREE__ <= 0 or nzs == []: try: if mode == 0: CTK.t = X.connectMatch(CTK.t, tol=eps, dim=ndim) else: CTK.t = X.connectMatchPeriodic(CTK.t, rotationCenter=rotationCenter, rotationAngle=rotationAngle, translation=translation, tol=eps, dim=ndim, unitAngle=None) CTK.TKTREE.updateApp() CTK.TXT.insert('START', 'Matching BCs successfully set.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: connectMatch') CTK.TXT.insert('START', 'Matching BCs failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') else: sel = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] sel.append(z) try: if mode == 0: sel = X.connectMatch(sel, tol=eps, dim=ndim) else: sel = X.connectMatchPeriodic(sel, rotationCenter=rotationCenter, rotationAngle=rotationAngle, translation=translation, tol=eps, dim=ndim, unitAngle=None) c = 0 for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] CTK.t[2][nob][2][noz] = sel[c] c += 1 CTK.TKTREE.updateApp() CTK.TXT.insert('START', 'Matching BCs successfully set.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: connectMatch') CTK.TXT.insert('START', 'Matching BCs failed.\n') CTK.TXT.insert('START', 'Error: ', 'Error') check()
I.newDataArray('CoordinateX', value=xm, parent=g) I.newDataArray('CoordinateY', value=ym, parent=g) I.newDataArray('CoordinateZ', value=zm, parent=g) f = I.newFlowSolution(name='FlowSolution', gridLocation='Vertex', parent=z) I.newDataArray('SkewAngle', value=skewang, parent=f) I.newDataArray('GrowthZ', value=growthz, parent=f) I.newDataArray('GrowthN', value=growthn, parent=f) C.convertPyTree2File(t, f'{project_name}.dat', format='fmt_tp') # Create Family fwall = I.newFamily(name='Wall', parent=b) fnref = I.newFamily(name='NRef', parent=b) fsym = I.newFamily(name='Sym', parent=b) # Create join t = X.connectMatch(t, tol=1.e-9, dim=3 if dz > 0. else 2) # Create BC if sharp: C._addBC2Zone(t, 'nref', 'FamilySpecified:NRef', 'imin') C._addBC2Zone(t, 'nref', 'FamilySpecified:NRef', 'imax') C._addBC2Zone(t, 'wall', 'FamilySpecified:Wall', 'jmin') C._addBC2Zone(t, 'nref', 'FamilySpecified:NRef', 'jmax') else: C._addBC2Zone(t, 'wall', 'FamilySpecified:Wall', 'jmin') C._addBC2Zone(t, 'nref', 'FamilySpecified:NRef', 'jmax') if dz > 0.: C._addBC2Zone(t, 'sym', 'FamilySpecified:Sym', 'kmin') C._addBC2Zone(t, 'sym', 'FamilySpecified:Sym', 'kmax')
def step2(): import Transform as T import Generator as G CTK.saveTree() # taille de maille en envergure hp = float(VARS[5].get()) # Hauteur du maillage Dfar = float(VARS[4].get()) # Envergure span = float(VARS[6].get()) # Recupere la base STEP1 base = Internal.getNodesFromName1(CTK.t, 'STEP1') if base == []: return zones = base[0][2] l = len(zones) if l == 7: culot = 0 else: culot = 1 if culot == 0: # 2 zones exterieures, le reste interieur M2 = [ C.getAllFields(zones[l - 2], 'nodes')[0], C.getAllFields(zones[l - 1], 'nodes')[0] ] M1 = [] for z in zones[0:l - 2]: M1.append(C.getAllFields(z, 'nodes')[0]) else: # 3 zones exterieures, le reste interieur M2 = [ C.getAllFields(zones[l - 2], 'nodes')[0], C.getAllFields(zones[l - 1], 'nodes')[0], C.getAllFields(zones[l - 3], 'nodes')[0] ] M1 = [] for z in zones[0:l - 3]: M1.append(C.getAllFields(z, 'nodes')[0]) #========================================================================== # stack + resserement vers les extremites #========================================================================== M1b = T.translate(M1, (0, 0, Dfar)) B1 = [] for i in range(len(M1)): B1.append(G.stack(M1[i], M1b[i])) M1c = T.translate(M1, (0, 0, -span)) M1d = T.translate(M1, (0, 0, -span - Dfar)) B2 = [] for i in range(len(M1c)): B2.append(G.stack(M1c[i], M1d[i])) #C.convertArrays2File(B1+B2, 'bouchon.plt') M2b = T.translate(M2, (0, 0, Dfar)) M2c = T.translate(M2, (0, 0, -span - Dfar)) I = [] for i in range(len(M2b)): I.append(G.stack(M2c[i], M2b[i])) # B1, B2: les bouchons; I le reste #C.convertArrays2File(B1+B2+I, 'all.plt') #========================================================================== # Remaille la surface N = int(Dfar / hp) + 1 distrib = G.cart((0, 0, 0), (1. / (N - 1), 1, 1), (N, 1, 1)) for i in range(len(B1)): B1[i] = G.map(B1[i], distrib, 3) for i in range(len(B2)): B2[i] = G.map(B2[i], distrib, 3) N = int((2 * Dfar + span) / hp) + 1 distrib = G.cart((0, 0, 0), (1. / (N - 1), 1, 1), (N, 1, 1)) for i in range(len(I)): I[i] = G.map(I[i], distrib, 3) # Back to zones zones = [] for b in B1 + B2 + I: zones.append(C.convertArrays2ZoneNode('zone', [b])) base = Internal.getNodesFromName1(CTK.t, 'STEP2') if base != []: (p, c) = Internal.getParentOfNode(CTK.t, base[0]) del p[2][c] CTK.t = C.addBase2PyTree(CTK.t, 'STEP2', 3) base = Internal.getNodesFromName1(CTK.t, 'STEP2')[0] (p, c) = Internal.getParentOfNode(CTK.t, base) base[2] += zones # Add BCs base = X.connectMatch(base, tol=1.e-6) # # Blocs exterieurs if culot == 0: z = base[2][10] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'jmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmin') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'imin') base[2][10] = z z = base[2][11] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'jmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmin') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'imax') base[2][11] = z for i in range(5): z = base[2][i] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') base[2][i] = z for i in range(5): z = base[2][5 + i] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') base[2][5 + i] = z else: z = base[2][6] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'jmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmin') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'imax') base[2][6] = z z = base[2][8] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'jmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmin') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'imin') base[2][8] = z z = base[2][7] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'imax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmin') base[2][7] = z for i in range(3): z = base[2][i] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') base[2][i] = z for i in range(3): z = base[2][3 + i] z = C.addBC2Zone(z, 'overlap', 'BCOverlap', 'kmax') base[2][3 + i] = z base = C.fillEmptyBCWith(base, 'wall', 'BCWall') CTK.t[2][c] = base CTK.TXT.insert('START', 'Step2 performed.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CTK.display(CTK.t)
import Connector.PyTree as X import KCore.test as test # Zone structuree a = G.cart((0, 0, 0), (0.1, 0.1, 1.), (11, 11, 1)) a = C.fillEmptyBCWith(a, 'wall', 'BCWall', dim=2) a = C.initVars(a, '{F}={CoordinateX}+{CoordinateY}**2') a = C.initVars(a, '{G}=1.') a = C.initVars(a, '{alpha}=0.5') a = T.deformNormals(a, 'alpha', niter=1) test.testT(a, 1) # Liste de zones structuree a = D.sphere6((0, 0, 0), 1., 20) a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin') a = X.connectMatch(a, dim=2) a = C.initVars(a, '{F}={CoordinateX}+{CoordinateY}**2') a = C.initVars(a, '{G}=1.') a = C.initVars(a, '{alpha}=0.5') a = T.deformNormals(a, 'alpha', niter=1) test.testT(a, 2) # Zone non structuree a = D.sphere((0, 0, 0), 1., 50) a = C.initVars(a, '{F}={CoordinateX}+{CoordinateY}**2') a = C.initVars(a, '{G}=1.') a = C.initVars(a, '{alpha}=0.5') a = T.deformNormals(a, 'alpha', niter=1) test.testT(a, 3) # Arbre
# - connectMatch 2D (pyTree)- import Generator.PyTree as G import Converter.PyTree as C import Connector.PyTree as X import KCore.test as test # liste de zones a = G.cart((0., 0., 0.), (0.1, 0.1, 0.1), (11, 21, 1)) a[0] = 'cart1' # --- champ au centre C._initVars(a, 'centers:Density', 1.) # --- CL a = C.addBC2Zone(a, 'wall1', 'BCWall', 'jmin') # partiellement coincident a2 = G.cart((1., 0.5, 0.), (0.1, 0.1, 0.1), (11, 21, 1)) a2[0] = 'cart2' # --- champ au noeud C._initVars(a2, 'Density', 1.) a2 = C.addBC2Zone(a2, 'wall1', 'BCOverlap', 'imax') t = C.newPyTree(['Base', 2, a, a2]) t[2][1][2] = X.connectMatch(t[2][1][2], dim=2) test.testT(t, 1) # coincident a3 = G.cart((1.00001, 0., 0.), (0.1, 0.1, 0.1), (11, 21, 1)) a3[0] = 'cart3' t[2][1][2].append(a3) t[2][1][2] = X.connectMatch(t[2][1][2], dim=2) test.testT(t, 2)
import Converter.PyTree as C import Converter.Internal as Internal import Converter import Dist2Walls.PyTree as DTW import Geom.PyTree as D import Generator.PyTree as G import Connector.PyTree as X # Creation of the structured multiblock mesh # kmin=1 define the wall BC m = D.sphere6((0, 0, 0), 1., N=10) di = G.cart((0., 0., 0.), (0.1, 1., 1.), (11, 1, 1)) m = G.addNormalLayers(m, di) m = C.addBC2Zone(m, 'wall', 'BCWall', 'kmin') m = C.addBC2Zone(m, 'nref', 'BCFarfield', 'kmax') m = X.connectMatch(m) t = C.newPyTree(['Base']) t[2][1][2] = m t = C.initVars(t, 'centers:cellN', 1.) # # Get the wall surfaces # walls = C.extractBCOfType(t, 'BCWall') walls += C.extractBCOfType(t, 'BCWallViscous') walls += C.extractBCOfType(t, 'BCWallInviscid') # Convert the wall border to centers bodies = C.node2Center(walls) # # Computes the distance field #
import Converter.PyTree as C import Connector.PyTree as X import Transform.PyTree as T import KCore.test as test a = G.cart((0., 0., 0.), (0.1, 0.1, 0.1), (11, 20, 2)) # partiellement coincident # --- CL a2 = G.cart((1., 0.5, 0.), (0.1, 0.1, 0.1), (11, 21, 2)) a2 = T.oneovern(a2, (2, 2, 1)) a2 = C.addBC2Zone(a2, 'wall1', 'BCWall', 'jmax') a2 = C.addBC2Zone(a2, 'overlap1', 'BCOverlap', 'jmin') # --- champ aux centres a2 = C.initVars(a2, 'centers:Density', 1.) # --- champ aux noeuds a2 = C.initVars(a2, 'cellN', 2.) t = C.newPyTree(['Base']) t[2][1][2] += [a, a2] # --- Equation state t[2][1] = C.addState(t[2][1], 'EquationDimension', 3) t = X.connectNearMatch(t) test.testT(t, 1) # coincident a3 = G.cart((1.00001, -1.4, 0.), (0.1, 0.1, 0.1), (11, 20, 2)) t[2][1][2].append(a3) t = X.connectMatch(t, tol=2.e-5) t = X.connectNearMatch(t, tol=2.e-5) test.testT(t, 2)