def getEdges2D(zone, factor): dim = Internal.getZoneDim(zone) ni = dim[1]; nj = dim[2]; nk = dim[3] l = CPlot.getActivePointIndex() if l == []: return None i = l[2]; j = l[3]; k = l[4] e1 = T.subzone(zone, (1,1,1), (ni,1,1)) e2 = T.subzone(zone, (1,nj,1), (ni,nj,1)) e3 = T.subzone(zone, (1,1,1), (1,nj,1)) e4 = T.subzone(zone, (ni,1,1), (ni,nj,1)) u = [e1,e2,e3,e4] (i,j,k) = forceIJK(i,j,k,ni,nj,nk) r = [] if i == 1: ind = j-1 m = [e3]; u.remove(e3) if factor != 1.: r = [e4]; u.remove(e4) elif i == ni: ind = j-1 m = [e4]; u.remove(e4) if factor != 1.: r = [e3]; u.remove(e3) elif j == 1: ind = i-1 m = [e1]; u.remove(e1) if factor != 1.: r = [e2]; u.remove(e2) elif j == nj: ind = i-1 m = [e2]; u.remove(e2) if factor != 1.: r = [e1]; u.remove(e1) return m, r, u, ind
def getExtCenterSurfaces__(a, walls): dims0 = Internal.getZoneDim(a) ni0 = dims0[1] nj0 = dims0[2] nk0 = dims0[3] indicesI1 = [] indicesI2 = [] indicesJ1 = [] indicesJ2 = [] indicesK1 = [] indicesK2 = [] for w in walls: i1 = int(w[0]) i2 = int(w[1]) j1 = int(w[2]) j2 = int(w[3]) k1 = int(w[4]) k2 = int(w[5]) if i1 == i2: if i1 == 1: indicesI1.append([i1, j1, k1, i2, j2, k2]) else: indicesI2.append([i1, j1, k1, i2, j2, k2]) elif j1 == j2: if j1 == 1: indicesJ1.append([i1, j1, k1, i2, j2, k2]) else: indicesJ2.append([i1, j1, k1, i2, j2, k2]) elif k1 == k2: if k1 == 1: indicesK1.append([i1, j1, k1, i2, j2, k2]) else: indicesK2.append([i1, j1, k1, i2, j2, k2]) surfs = [] if indicesI1 != []: wloc = T.subzone(a, (1, 1, 1), (2, nj0, nk0)) surfs += getExtCenterSubWin(wloc, indicesI1, 1) if indicesI2 != []: wloc = T.subzone(a, (ni0 - 1, 1, 1), (ni0, nj0, nk0)) surfs += getExtCenterSubWin(wloc, indicesI2, 1) if indicesJ1 != []: wloc = T.subzone(a, (1, 1, 1), (ni0, 2, nk0)) surfs += getExtCenterSubWin(wloc, indicesJ1, 2) if indicesJ2 != []: wloc = T.subzone(a, (1, nj0 - 1, 1), (ni0, nj0, nk0)) surfs += getExtCenterSubWin(wloc, indicesJ2, 2) if indicesK1 != []: wloc = T.subzone(a, (1, 1, 1), (ni0, nj0, 2)) surfs += getExtCenterSubWin(wloc, indicesK1, 3) if indicesK2 != []: wloc = T.subzone(a, (1, 1, nk0 - 1), (ni0, nj0, nk0)) surfs += getExtCenterSubWin(wloc, indicesK2, 3) return surfs
def getExtCenterSubWin(wloc, allIndices, dirW=0): wloc = C.node2ExtCenter(wloc) dimsW = Internal.getZoneDim(wloc) niW = dimsW[1] njW = dimsW[2] nkW = dimsW[3] if dirW == 1: wLoc = T.subzone(wloc, (2, 1, 1), (2, njW, nkW)) elif dirW == 2: wLoc = T.subzone(wloc, (1, 2, 1), (niW, 2, nkW)) elif dirW == 3: wLoc = T.subzone(wloc, (1, 1, 2), (niW, njW, 2)) surfs = [] for indices in allIndices: imin = indices[0] imax = indices[3] jmin = indices[1] jmax = indices[4] kmin = indices[2] kmax = indices[5] dimS = Internal.getZoneDim(wLoc) niS = dimS[1] njS = dimS[2] nkS = dimS[3] if dirW == 1: iminL = jmin jminL = kmin imaxL = jmax + 1 jmaxL = kmax + 1 elif dirW == 2: iminL = imin jminL = kmin imaxL = imax + 1 jmaxL = kmax + 1 else: iminL = imin jminL = jmin imaxL = imax + 1 jmaxL = jmax + 1 sLoc = modifyBorders__(wLoc, iminL, imaxL, jminL, jmaxL) if dirW == 1: sLoc = T.subzone(sLoc, (jmin, kmin, 1), (jmax + 1, kmax + 1, 1)) elif dirW == 2: sLoc = T.subzone(sLoc, (imin, kmin, 1), (imax + 1, kmax + 1, 1)) elif dirW == 3: sLoc = T.subzone(sLoc, (imin, jmin, 1), (imax + 1, jmax + 1, 1)) surfs.append(sLoc) return surfs
def display1D(event=None): if CTK.t == []: return # Get slot try: slot = int(VARS[5].get()) except: slot = 0 # Get grid size try: gridSize = VARS[1].get() grids = gridSize.split(';') if (len(grids) == 1): gridSize = (int(grids[0]), 1) else: gridSize = (int(grids[0]), int(grids[1])) except: gridSize = (1, 1) CPlot.setState(gridSize=gridSize) # Get grid pos try: gridPos = VARS[2].get() grids = gridPos.split(';') if (len(grids) == 1): gridPos = (int(grids[0]), 1) else: gridPos = (int(grids[0]), int(grids[1])) except: gridPos = (0, 0) # Recupere la direction pour la coupe ou 'Elements' dir = VARS[0].get() if dir == 'None': CPlot.display1D([], slot=slot) return # clear # Recupere le pt pour la coupe ou les elements 1D if dir == 'Elements': # elements -> recupere les elements 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 points = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] selected = CTK.t[2][nob][0] + '/' + z[0] points.append(selected) elif (dir == 'I' or dir == 'J' or dir == 'K'): # indice -> recupere les indices + la zone if (CTK.__MAINTREE__ <= 0): CTK.TXT.insert('START', 'Fail on a temporary tree.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return nz = CPlot.getSelectedZone() if (nz == -1): CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return points = [] nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] selected = CTK.t[2][nob][0] + '/' + z[0] index = CPlot.getActivePointIndex() points = (selected, index) else: # les coupes -> recupere les coord du pt point = CPlot.getActivePoint() if point == []: point = (0., 0., 0.) # Recupere les variables a afficher var1 = VARS[3].get() var1 = var1.replace('centers:', '') var2 = VARS[4].get() var2 = var2.replace('centers:', '') # Recupere les zones actives actives = [] zones = Internal.getZones(CTK.t) if CTK.__MAINTREE__ == 1: nzs = CPlot.getActiveZones() for nz in nzs: actives.append(zones[nz]) else: actives = zones if actives == []: return if (dir == 'X (Y)'): elts = P.isoSurfMC(actives, 'CoordinateY', point[1]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateZ', point[2]) if (elts2 != []): elts = elts2 elif (dir == 'Y (X)'): elts = P.isoSurfMC(actives, 'CoordinateX', point[0]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateZ', point[2]) if (elts2 != []): elts = elts2 elif (dir == 'Z (X)'): elts = P.isoSurfMC(actives, 'CoordinateX', point[0]) if (elts != []): elts2 = P.isoSurfMC(elts, 'CoordinateY', point[1]) if (elts2 != []): elts = elts2 elif (dir == 'X (Z)'): elts = P.isoSurfMC(actives, 'CoordinateZ', point[2]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateY', point[1]) if (elts2 != []): elts = elts2 elif (dir == 'Y (Z)'): elts = P.isoSurfMC(actives, 'CoordinateZ', point[2]) if elts != []: elts2 = P.isoSurfMC(elts, 'CoordinateX', point[0]) if (elts2 != []): elts = elts2 elif (dir == 'Z (Y)'): elts = P.isoSurfMC(actives, 'CoordinateY', point[1]) if (elts != []): elts2 = P.isoSurfMC(elts, 'CoordinateX', point[0]) if (elts2 != []): elts = elts2 elif (dir == 'I'): v = points[0] ind = points[1] v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) elts = [] if bases != []: zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): try: zp = C.center2Node(z, Internal.__FlowSolutionCenters__) zp = T.subzone(zp, (1, ind[3], ind[4]), (-1, ind[3], ind[4])) elts.append(zp) except: pass elif (dir == 'J'): v = points[0] ind = points[1] v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) elts = [] if bases != []: zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): try: zp = C.center2Node(z, Internal.__FlowSolutionCenters__) zp = T.subzone(zp, (ind[2], 1, ind[4]), (ind[2], -1, ind[4])) elts.append(zp) except: pass elif (dir == 'K'): v = points[0] ind = points[1] v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) elts = [] if bases != []: zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): try: zp = C.center2Node(z, Internal.__FlowSolutionCenters__) zp = T.subzone(zp, (ind[2], ind[3], 1), (ind[2], ind[3], -1)) elts.append(zp) except: pass elif (dir == 'Elements'): elts = [] for v in points: v = v.lstrip() v = v.rstrip() sname = v.split('/', 1) bases = Internal.getNodesFromName1(CTK.t, sname[0]) if (bases != []): zones = Internal.getNodesFromType1(bases[0], 'Zone_t') for z in zones: if (z[0] == sname[1]): elts.append(z) if elts == []: CTK.TXT.insert('START', 'Nothing to display.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return try: elts = D.getCurvilinearAbscissa(elts) except: pass # Fit first axis pos = WIDGETS['rangePos'].get() / 50. - 1. zoom = WIDGETS['rangeZoom'].get() / 120. minv1 = C.getMinValue(elts, var1) maxv1 = C.getMaxValue(elts, var1) if (maxv1 - minv1 < 1.e-6): maxv1 += 5.e-7 minv1 -= 5.e-7 # active point localisation nz = CPlot.getSelectedZone() if (nz != -1): ind = CPlot.getActivePointIndex() nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] f1 = C.getValue(z, var1, ind[0]) try: r1min = (f1 - minv1) * zoom + minv1 + pos * (1. - zoom) * (maxv1 - minv1) r1max = (f1 - maxv1) * zoom + maxv1 + pos * (1. - zoom) * (maxv1 - minv1) except: # var1 not found in z, le cherche dans elts xf1 = C.getValue(z, 'CoordinateX', ind[0]) yf1 = C.getValue(z, 'CoordinateY', ind[0]) zf1 = C.getValue(z, 'CoordinateZ', ind[0]) f1 = minv1 + 0.5 * (maxv1 - minv1) r1min = 0.5 * (maxv1 - minv1) * zoom + minv1 + pos * ( 1. - zoom) * (maxv1 - minv1) r1max = -0.5 * (maxv1 - minv1) * zoom + maxv1 + pos * ( 1. - zoom) * (maxv1 - minv1) else: f1 = minv1 + 0.5 * (maxv1 - minv1) r1min = 0.5 * (maxv1 - minv1) * zoom + minv1 + pos * (1. - zoom) * ( maxv1 - minv1) r1max = -0.5 * (maxv1 - minv1) * zoom + maxv1 + pos * (1. - zoom) * ( maxv1 - minv1) # Fit second axis p = P.selectCells( elts, '({%s} < %20.16g) & ({%s} > %20.16g)' % (var1, r1max, var1, r1min)) minv2 = C.getMinValue(p, var2) maxv2 = C.getMaxValue(p, var2) # display CPlot.display1D(p, slot=slot, bgBlend=0., gridPos=gridPos, var1=var1, var2=var2, r1=(r1min, r1max), r2=(minv2, maxv2)) CTK.TXT.insert('START', 'Plot displayed.\n')
# - computeExtraVariable (pyTree) - import Generator.PyTree as G import Converter.PyTree as C import Transform.PyTree as T import Post.PyTree as P def F(x, y): return x * x + y * y a = G.cart((0, 0, 0), (1, 1, 1), (50, 50, 50)) a = C.initVars(a, 'Density', 1.) a = C.initVars(a, 'MomentumX', F, ['CoordinateX', 'CoordinateY']) a = C.initVars(a, 'MomentumY', 0.) a = C.initVars(a, 'MomentumZ', 0.) a = C.initVars(a, 'EnergyStagnationDensity', 100000.) a = P.computeExtraVariable(a, 'centers:VorticityMagnitude') a = P.computeExtraVariable(a, 'centers:QCriterion') a = P.computeExtraVariable(a, 'centers:ShearStress') b = T.subzone(a, (1, 1, 1), (50, 50, 1)) b = P.computeExtraVariable(b, 'centers:SkinFriction') b = P.computeExtraVariable(b, 'centers:SkinFrictionTangential') C.convertPyTree2File(a, 'out.cgns')
import Transform.PyTree as T # test 1D : circle a = D.circle((0., 0., 0.), 1., 0., 359.995, 500) C._addVars(a, 'Density') C._addVars(a, 'centers:cellN') a = C.convertArray2Tetra(a) a2 = G.close(a, 1.e-4) test.testT(a2, 1) # test 2D cylindre QUAD ni = 20 nj = 20 nk = 5 a0 = G.cylinder((0., 0., 0.), 0., 1., 0., 359, 1., (ni, nj, nk)) a = T.subzone(a0, (1, nj, 1), (ni, nj, nk)) C._addVars(a, 'Density') C._addVars(a, 'centers:cellN') a = C.convertArray2Hexa(a) a2 = G.close(a, 1.e-1) test.testT(a2, 2) # test 2D TRI a = T.subzone(a0, (1, nj, 1), (ni, nj, nk)) a = C.convertArray2Tetra(a) C._addVars(a, 'Density') C._initVars(a, 'centers:cellN', 1.) a2 = G.close(a, 1.e-1) test.testT(a2, 3) # test 3D cylindre HEXA
# subzone faces (pyTree) import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T import KCore.test as test N = 51 d = G.cartNGon((0,0,0), (1,1,1),(N,N,N)) facesL=[] for i in xrange(1,N*N): facesL.append(i+1) C._initVars(d,'F={CoordinateX}') C._initVars(d,'centers:G={centers:CoordinateY}') d = T.subzone(d, facesL, type='faces') test.testT(d,1) # 3D Tetra N = 51 d = G.cartTetra((0,0,0), (1,1,1),(N,N,N)) facesL=[] for i in xrange(1,N*N): facesL.append(i+1) C._initVars(d,'F={CoordinateX}') C._initVars(d,'centers:G={centers:CoordinateY}') d = T.subzone(d, facesL, type='faces') test.testT(d,2) # 3D Hexa N = 51 d = G.cartHexa((0,0,0), (1,1,1),(N,N,N)) facesL=[] for i in xrange(1,N*N): facesL.append(i+1) C._initVars(d,'F={CoordinateX}') C._initVars(d,'centers:G={centers:CoordinateY}') d = T.subzone(d, facesL, type='faces')
import Converter.PyTree as C import Post.PyTree as P import Generator.PyTree as G import Transform.PyTree as T import KCore.test as test # cylindre ni = 30 nj = 40 nk = 1 m1 = G.cylinder((0, 0, 0), 1, 5, 0., 360., 10., (50, 50, 1)) m1 = C.initVars(m1, 'cellN', 1.) m1 = C.initVars(m1, 'centers:ichim', 1.) # Set cellN = 2 (interpolated points) to boundary s = T.subzone(m1, (1, nj, 1), (ni, nj, nk)) s = C.initVars(s, 'cellN', 2) m1 = T.patch(m1, s, (1, nj, 1)) ni1 = m1[1][0][0] nj1 = m1[1][0][1] nk1 = nk s = T.subzone(m1, (1, 1, 1), (ni1, 1, nk1)) s = C.initVars(s, 'cellN', 2) m1 = T.patch(m1, s, (1, 1, 1)) # carre m2 = G.cart((0, 0, 0), (10. / (ni - 1), 10. / (nj - 1), -1), (ni, nj, 1)) m2 = C.initVars(m2, 'cellN', 1.) m2 = C.initVars(m2, 'Density', 1.2) test.testT(m2)
# - subzone elements (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T import KCore.test as test N = 51 d = G.cartNGon((0, 0, 0), (1, 1, 1), (N, N, N)) eltsL = [] for i in xrange(N * N): eltsL.append(i) C._initVars(d, 'F={CoordinateX}') C._initVars(d, 'centers:G={centers:CoordinateY}') d = T.subzone(d, eltsL, type='elements') test.testT(d, 1) # 3D Tetra N = 51 d = G.cartTetra((0, 0, 0), (1, 1, 1), (N, N, N)) eltsL = [] for i in xrange(N * N): eltsL.append(i) C._initVars(d, 'F={CoordinateX}') C._initVars(d, 'centers:G={centers:CoordinateY}') d = T.subzone(d, eltsL, type='elements') test.testT(d, 2) # 3D Hexa N = 51 d = G.cartHexa((0, 0, 0), (1, 1, 1), (N, N, N)) eltsL = [] for i in xrange(N * N): eltsL.append(i)
def copyDistrib(): 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() # source edge v = VARS[3].get() v = v.split(';') try: pt = eval(v[1]) except: pt = None v = v[0] v = v.lstrip(); v = v.rstrip() sname = v.split('/', 1) edge = [] 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]: edge.append(z) if edge == []: CTK.TXT.insert('START', 'Invalid source edge.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return source = edge[0] dimSource = Internal.getZoneDim(source) if dimSource[0] == 'Unstructured': CTK.TXT.insert('START', 'Invalid source edge.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return # Get first selected zone nz = nzs[0] nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] zone = CTK.t[2][nob][2][noz] dim = Internal.getZoneDim(zone) # subzone de source eventuellement if dimSource[4] == 2: # source est 2D ind = CPlot.getActivePointIndex() ni = dimSource[1]; nj = dimSource[2] deltai = min(ind[2]-ni,ind[2]-1) deltaj = min(ind[3]-nj,ind[3]-1) if deltai < deltaj: source = T.subzone(source, (1,pt[1],pt[2]),(ni,pt[1],pt[2])) else: source = T.subzone(source, (pt[0],1,pt[2]),(pt[0],nj,pt[2])) elif dimSource[4] == 3: # source est 3D ind = CPlot.getActivePointIndex() ni = dimSource[1]; nj = dimSource[2]; nk = dimSource[3] deltai = min(ind[2]-ni,ind[2]-1) deltaj = min(ind[3]-nj,ind[3]-1) deltak = min(ind[4]-nk,ind[4]-1) if deltai < deltaj and deltai < deltak: source = T.subzone(source, (1,pt[1],pt[2]),(ni,pt[1],pt[2])) elif deltaj < deltai and deltaj < deltak: source = T.subzone(source, (pt[0],1,pt[2]),(pt[0],nj,pt[2])) else: source = T.subzone(source, (pt[0],pt[1],1),(pt[0],pt[1],nk)) # Extrait la distribution en i source = D.getCurvilinearAbscissa(source) C._initVars(source, '{CoordinateX}={s}') C._initVars(source, 'CoordinateY', 0) C._initVars(source, 'CoordinateZ', 0) source = C.rmVars(source, 's') # Traitement if dim[0] == 'Structured': if dim[2] != 1 and dim[3] != 1: fail = apply3D(1., 1, source, ntype=3) elif dim[2] != 1 and dim[3] == 1: fail = apply2D(1., 1, source, ntype=3) else: fail = copyDistrib1D(source) else: fail = copyDistrib1D(source) # all zones if not fail: CTK.TXT.insert('START', 'Distribution copy done.\n') else: CTK.TXT.insert('START', 'Distribution copy fails for at least one zone.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def getEdges3D(zone, factor): dim = Internal.getZoneDim(zone) ni = dim[1]; nj = dim[2]; nk = dim[3] l = CPlot.getActivePointIndex() if l == []: return None i = l[2]; j = l[3]; k = l[4] e1 = T.subzone(zone, (1,1,1), (ni,1,1)) e2 = T.subzone(zone, (1,nj,1), (ni,nj,1)) e3 = T.subzone(zone, (1,1,1), (1,nj,1)) e4 = T.subzone(zone, (ni,1,1), (ni,nj,1)) e5 = T.subzone(zone, (1,1,nk), (ni,1,nk)) e6 = T.subzone(zone, (1,nj,nk), (ni,nj,nk)) e7 = T.subzone(zone, (1,1,nk), (1,nj,nk)) e8 = T.subzone(zone, (ni,1,nk), (ni,nj,nk)) e9 = T.subzone(zone, (1,1,1), (1,1,nk)) e10 = T.subzone(zone, (ni,1,1), (ni,1,nk)) e11 = T.subzone(zone, (1,nj,1), (1,nj,nk)) e12 = T.subzone(zone, (ni,nj,1), (ni,nj,nk)) f1 = T.subzone(zone, (1,1,1), (ni,nj,1)) f2 = T.subzone(zone, (1,1,nk), (ni,nj,nk)) f3 = T.subzone(zone, (1,1,1), (ni,1,nk)) f4 = T.subzone(zone, (1,nj,1), (ni,nj,nk)) f5 = T.subzone(zone, (1,1,1), (1,nj,nk)) f6 = T.subzone(zone, (ni,1,1), (ni,nj,nk)) ue = [e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12] # unmodified edges uf = [f1,f2,f3,f4,f5,f6] # unmodified faces #temp = C.newPyTree(['Base']) #temp[2][1][2] += ue #temp[2][1][2] += uf #C.convertPyTree2File(temp, 'edges.cgns') (i,j,k) = forceIJK(i,j,k,ni,nj,nk) r = [] # refined edges if (i == 1 and j == 1): ind = k-1 m = [e9] f = [f3,f5] if (factor != 1.): r = [e11,e12,e10]; f += [f4,f6] elif (i == ni and j == 1): ind = k-1 m = [e10] f = [f6,f3] if (factor != 1.): r = [e9,e11,e12] f += [f5,f4] elif (i == 1 and j == nj): ind = k-1 m = [e11] f = [f5,f4] if (factor != 1.): r = [e9,e10,e12]; f += [f3,f6] elif (i == ni and j == nj): ind = k-1 m = [e12] f = [f6,f4] if (factor != 1.): r = [e10,e9,e11]; f += [f3,f5] elif (i == 1 and k == 1): ind = j-1 m = [e3] f = [f1,f5] if (factor != 1.): r = [e4,e8,e7]; f += [f2,f6] elif (i == ni and k == 1): ind = j-1 m = [e4] f = [f6,f1] if (factor != 1.): r = [e3,e8,e7]; f += [f2,f5] elif (i == 1 and k == nk): ind = j-1 m = [e7] f = [f5,f2] if (factor != 1.): r = [e8,e4,e3]; f += [f6,f1] elif (i == ni and k == nk): ind = j-1 m = [e8] f = [f6,f2] if (factor != 1.): r = [e7,e3,e4]; f += [f5,f1] elif (j == 1 and k == 1): ind = i-1 m = [e1] f = [f1,f3] if (factor != 1.): r = [e2,e6,e5]; f += [f2,f4] elif (j == nj and k == 1): ind = i-1 m = [e2] f = [f4,f1] if (factor != 1.): r = [e1,e6,e5]; f += [f2,f3] elif (j == 1 and k == nk): ind = i-1 m = [e5] f = [f2,f3] if (factor != 1.): r = [e6,e2,e1]; f += [f1,f4] elif (j == nj and k == nk): ind = i-1 m = [e6] f = [f2,f4] if (factor != 1.): r = [e5,e1,e2]; f += [f3,f1] for i in m+r: ue.remove(i) for i in f: uf.remove(i) return m, r, f, ue, uf, ind
# - subzone (pyTree) - import Converter.PyTree as C import Transform.PyTree as T import Generator.PyTree as G a = G.cart((0,0,0), (1,1,1), (10,20,1)) a = T.subzone(a, (3,3,1), (7,8,1)) C.convertPyTree2File(a, 'out.cgns')
y = t * t + 1 + u * u z = u return (x, y, z) # surface grids a = D.surface(f) t = C.newPyTree(['Base', 2]) b = [] i1 = 1 for i in range(10): i2 = (i + 1) * 10 j1 = 1 for j in range(10): j2 = (j + 1) * 10 b.append(T.subzone(a, (i1, j1, 1), (i2, j2, 1))) j1 = j2 i1 = i2 t[2][1][2] += b t = C.initVars(t, 'F', 1.) t = C.initVars(t, 'centers:G', 2.) res = T.merge(t, dir=2) t[2][1][2] = res test.testT(t, 1) res = T.merge(t, dir=1) t[2][1][2] = res test.testT(t, 2) # volume grids distrib = G.cart((0., 0., 0.), (0.1, 1, 1), (10, 1, 1)) a = G.addNormalLayers(a, distrib)
r"""Transform : symmetrize a case""" # Symmetrize a mesh import Converter.PyTree as C import Transform.PyTree as T import Generator.PyTree as G import Connector.PyTree as X import Converter.Internal as Internal # Create a 2-block mesh for half cylinder symmetric case a = G.cylinder((0, 0, 0), 0.5, 1., 180., 0., 1., (21, 21, 21)) a = C.addBC2Zone(a, 'wall', 'BCWall', 'jmin') a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'jmax') a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'kmin') a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'kmax') a1 = T.subzone(a, (1, 1, 1), (11, 21, 21)) a2 = T.subzone(a, (11, 1, 1), (21, 21, 21)) t = C.newPyTree(['MESH']) t[2][1][2] = [a1, a2] t = X.connectMatch(t) t = C.fillEmptyBCWith(t, 'sym', 'BCSymmetryPlane') t = C.initVars( t, '{F}={CoordinateX}*{CoordinateX}+{CoordinateY}+2*{CoordinateZ}') # Symmetry y=0 t2 = T.symetrize(t, (0., 0., 0.), (1, 0, 0), (0, 0, 1)) # Rename zones with a unique name zones = Internal.getNodesFromType(t2, 'Zone_t') for z in zones: z[0] = C.getZoneName(z[0]) # Reorder created zones
def generateCompositeIBMMesh(tb, vmin, snears, dfar, dfarloc=0., DEPTH=2, NP=0, check=True, merged=1, sizeMax=4000000, symmetry=0, externalBCType='BCFarfield'): tbox = None snearsf = None dimPb = Internal.getNodeFromName(tb, 'EquationDimension') if dimPb is None: raise ValueError('EquationDimension is missing in input body tree.') dimPb = Internal.getValue(dimPb) model = Internal.getNodeFromName(tb, 'GoverningEquations') refstate = C.getState(tb) # list of near body meshes t = Internal.copyRef(tb) Internal._rmNodesFromType(t, "Zone_t") snearsExt = [] tblank = Internal.copyRef(tb) DEPTHEXT = 3 * DEPTH + 1 tov = Internal.rmNodesFromType(tb, 'Zone_t') for nob in range(len(tb[2])): base = tb[2][nob] if base[3] == 'CGNSBase_t': basename = base[0] res = generateIBMMesh(base, vmin, snears, dfarloc, DEPTH=DEPTH, NP=NP, tbox=None, snearsf=None, check=check, merged=merged, symmetry=symmetry, sizeMax=sizeMax, externalBCType='BCDummy', to=None, composite=1, mergeByParents=False) res = Internal.getZones(res) t[2][nob][2] = res # blanking box for off-body mesh extFacesL = C.extractBCOfType(res, "BCDummy") bbl = G.bbox(extFacesL) lMax = 0. for extf in extFacesL: if dimPb == 2: extf = T.subzone(extf, (1, 1, 1), (-1, 1, 1)) extf = G.getVolumeMap(extf) dxloc = C.getValue(extf, 'centers:vol', 0) if dimPb == 3: dxloc = dxloc**0.5 lMax = max(lMax, dxloc) snearsExt.append(dxloc) tov[2][nob][2].append(extf) # ATTENTION : engendre une boite parallelepipedique - peut ne pas etre valide dans # les cas ou le maillage cartesien proche corps n est pas parallelepipedique # A ameliorer # IDEM pour les conditions aux limites dans octree2StructLoc et generateIBMMesh xminb = bbl[0] + DEPTHEXT * lMax xmaxb = bbl[3] - DEPTHEXT * lMax yminb = bbl[1] + DEPTHEXT * lMax ymaxb = bbl[4] - DEPTHEXT * lMax if dimPb == 3: zminb = bbl[2] + DEPTHEXT * lMax zmaxb = bbl[5] - DEPTHEXT * lMax blankingBoxL = G.cart( (xminb, yminb, zminb), (xmaxb - xminb, ymaxb - yminb, zmaxb - zminb), (2, 2, 2)) else: blankingBoxL = G.cart((xminb, yminb, 0.), (xmaxb - xminb, ymaxb - yminb, 1.), (2, 2, 1)) blankingBoxL = P.exteriorFaces(blankingBoxL) tblank[2][nob][2] = [blankingBoxL] tcart = generateIBMMesh(tov, vmin, snearsExt, dfar, DEPTH=DEPTH, NP=NP, tbox=tbox, snearsf=snearsf, check=check, merged=1, sizeMax=sizeMax, symmetry=symmetry, externalBCType='BCFarfield', to=None, mergeByParents=True) tcart[2][1][0] = 'OffBody' C._rmBCOfType( t, 'BCDummy') # near body grids external borders must be BCOverlap t = C.fillEmptyBCWith(t, 'ov_ext', 'BCOverlap', dim=dimPb) t = C.mergeTrees(t, tcart) model = Internal.getValue(model) C._addState(t, 'GoverningEquations', model) C._addState(t, 'EquationDimension', dimPb) C._addState(t, state=refstate) return t, tblank
test.testT(a, 1) # TRI -> TRI_6 a = D.triangle((0,0,0), (1,0,0), (1,1,0)) a = C.convertLO2HO(a, 0) a = C.convertHO2LO(a, 0) test.testT(a, 2) # QUAD -> QUAD_8 a = D.quadrangle((0,0,0), (1,0,0), (1,1,0), (0,1,0)) a = C.convertLO2HO(a, 0) a = C.convertHO2LO(a, 0) test.testT(a, 3) # QUAD -> QUAD_9 a = D.quadrangle((0,0,0), (1,0,0), (1,1,0), (0,1,0)) a = C.convertLO2HO(a, 1) a = C.convertHO2LO(a, 0) test.testT(a, 4) # TETRA -> TETRA_10 a = G.cart((0,0,0), (1,1,1), (2,2,2)) a = C.convertArray2Tetra(a) a = T.subzone(a, [0], type='elements') a = C.convertLO2HO(a, 0) a = C.convertHO2LO(a, 0) test.testT(a, 5)
xmax = BB[3] ymax = BB[4] zmax = BB[5]+0.5 hi = (xmax-xmin)/(ni-1) hj = (ymax-ymin)/(nj-1) h = min(hi, hj) ni = int((xmax-xmin)/h)+7 nj = int((ymax-ymin)/h)+7 b = G.cart((xmin-3*h, ymin-3*h, zmin), (h, h, 1.), (ni, nj, nk)) t = C.newPyTree(['Cart']) t[2][1][2].append(b) # Masquage t = C.initVars(t, 'cellN', 1) BM = numpy.array([[1]]) t = X.blankCells(t, [[s2]], BM, blankingType='node_in', dim=2) # Adapte le front de la grille a la surface dim = Internal.getZoneDim(b) t = T.subzone(t, (1, 1, 2), (dim[1], dim[2], 2)) t = G.snapFront(t, [s2]) t = C.addBase2PyTree(t, 'Surface', cellDim=2) s2 = C.initVars(s2, 'cellN', 1) t[2][2][2].append(s2) C.convertPyTree2File(t, 'out.cgns')
c1 = G.cart((0, 0, 0), (0.01, 0.01, 1), (201, 101, 20)) C._addBC2Zone(c1, 'wall1', 'BCWall', 'imin') C._addBC2Zone(c1, 'match1', 'BCMatch', 'imax', c1, 'imin', [1, 2, 3]) C._addBC2Zone(c1, 'overlap1', 'BCOverlap', 'jmax') C._initVars(c1, 'centers:celln', 1.) C._initVars(c1, 'Density', dens, ['CoordinateX', 'CoordinateY']) c2 = G.cart((0, 0, 0), (0.01, 0.01, 1), (51, 81, 20)) c2 = T.rotate(c2, (0, 0, 0), (0, 0, 1), 0.2) C._addBC2Zone(c2, 'wall1', 'BCWall', 'imin') C._addBC2Zone(c2, 'overlap1', 'BCOverlap', 'imax') C._initVars(c2, 'centers:celln', 1.) C._initVars(c2, 'Density', dens, ['CoordinateX', 'CoordinateY']) a = T.patch(c1, c2, (1, 1, 1)) t = C.newPyTree(['Base', a]) test.testT(t, 2) # multi-zone 3D a = D.sphere6( (0, 0, 0), 1, N=20, ) d = G.cart((0.1, 0., 0.), (0.1, 1, 1), (5, 1, 1)) a = G.addNormalLayers(a, d) t = C.newPyTree(['Base', 3, a]) t2 = T.subzone(t, (1, 1, 2), (-1, -1, 4)) t2 = T.smooth(t2, eps=0.5, niter=20) t = T.patch(t, t2, (1, 1, 2)) test.testT(t, 3)
# - splitTBranches (pyTree) import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T a = G.cylinder((0., 0., 0.), 0.5, 1., 360., 0., 10., (50, 1, 50)) c1 = T.subzone(a, (1, 1, 1), (50, 1, 1)) c2 = T.subzone(a, (1, 50, 1), (50, 50, 1)) c3 = T.subzone(a, (1, 1, 1), (1, 50, 1)) c = [c1, c2, c3] c = C.convertArray2Hexa(c) c = T.join(c) res = T.splitTBranches(c) C.convertPyTree2File(res, "out.cgns")
# - usurp (pyTree)- import Post.PyTree as P import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T import KCore.test as test # Creation des cylindres a1 = G.cylinder((0, 0, 0), 0, 2, 360, 0, 1., (100, 2, 10)) a1 = T.subzone(a1, (1, 2, 1), (100, 2, 10)) a1[0] = 'cyl1' a1 = C.addBC2Zone(a1, 'overlap', 'BCOverlap', 'imin') a1 = C.fillEmptyBCWith(a1, 'nref', 'BCFarfield') a2 = G.cylinder((0, 0, 0), 0, 2, 90, 0, 0.5, (10, 2, 10)) a2 = T.translate(a2, (0, 0, 0.2)) a2 = T.subzone(a2, (1, 2, 1), (10, 2, 10)) a2[0] = 'cyl2' # creation des celln C._addVars(a1, 'Density') C._initVars(a1, 'centers:cellN', 1.) C._initVars(a2, 'centers:cellN', 1.) t = C.newPyTree(['Base', 2]) t[2][1][2] += [a1, a2] t[2][1] = C.addState(t[2][1], 'Mach', 0.6) try: t = P.usurp(t) test.testT(t[2][1][2][0]) except: pass
# - connectNearMatch (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, 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))
import KCore.test as test # NGON 2D ne contenant pas de faces externes a = D.sphere((0, 0, 0), 1., 15) a = C.convertArray2NGon(a) a = G.close(a) a = C.initVars(a, 'F', 1.) a = C.initVars(a, 'centers:G', 1.) res = T.dual(a) t = C.newPyTree(['Base']) t[2][1][2] += [res] test.testT(t) # NGON 2D contenant des faces externes a = D.sphere((0, 0, 0), 1., 15) a = T.subzone(a, (1, 1, 1), (15, 15, 1)) a = C.convertArray2NGon(a) a = G.close(a) a = C.initVars(a, 'F', 1.) res = T.dual(a) t = C.newPyTree(['Base']) t[2][1][2] += [res] test.testT(t, 2) # NGON 3D a = G.cartHexa((0, 0, 0), (1, 1, 1), (11, 11, 11)) a = C.convertArray2NGon(a) a = G.close(a) res = T.dual(a) t = C.newPyTree(['Base']) t[2][1][2] += [res]
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)) t2 = T.smooth(t2, eps=0.5, niter=20, projConstraints=Internal.getNodesFromType(t2, 'Zone_t')) t = T.patch(t, t2, (1, 1, k + 1)) test.testT(t, 3) # cas 3D c1 = G.cart((0, 0, 0), (0.01, 0.01, 1), (201, 101, 20)) 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'])
import Transform.PyTree as T import Generator.PyTree as G import KCore.test as test # 3d structure a = G.cart((0, 0, 0), (1, 1, 1), (10, 20, 10)) C._addBC2Zone(a, 'wall1', 'BCWall', 'jmin') C._addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2, 3]) C._addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmax') C._initVars(a, 'centers:celln', 1.) C._initVars(a, '{centers:G}={centers:CoordinateX}') C._initVars(a, '{Density}=3*{CoordinateX}*{CoordinateY}') t = C.newPyTree(['Base']) t[2][1][2].append(a) t[2][1] = C.addState(t[2][1], 'EquationDimension', 3) t = T.subzone(t, (3, 1, 3), (7, 8, 5)) test.testT(t, 1) # # 2D structure # a = G.cart((0, 0, 0), (1, 1, 1), (10, 20, 1)) C._addBC2Zone(a, 'wall1', 'BCWall', 'jmin') C._addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2]) C._addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmax') C._initVars(a, 'centers:celln', 1.) C._initVars(a, '{centers:G}={centers:CoordinateX}') C._initVars(a, '{Density}=3*{CoordinateX}*{CoordinateY}') t = C.newPyTree(['Base', 2]) t[2][1][2].append(a) t[2][1] = C.addState(t[2][1], 'EquationDimension', 2) t = T.subzone(t, (3, 1, 1), (7, 8, 1))
import Generator.PyTree as G import KCore.test as test def dens(x,y): return 3*x*y #--------------- # sur une zone #--------------- # structure 3D + CL + champs sur une zone a = G.cart((0,0,0), (1,1,1), (10,20,10)) a = C.initVars(a, 'Density', dens, ['CoordinateX','CoordinateY']) a = C.initVars(a,'centers:cellN',1) a = C.addBC2Zone(a, 'wall1', 'BCWall', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin',[1,2,3]) a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmax') a = T.subzone(a, (3,3,3), (7,8,5)) t = C.newPyTree(['Base',a]) test.testT(t, 1) # structure 2D + CL a = G.cart((0,0,0), (1,1,1), (10,20,1)) a = C.initVars(a,'Density',dens,['CoordinateX','CoordinateY']) a = C.initVars(a,'centers:cellN',1) a = C.addBC2Zone(a, 'wall1','BCWall', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin',[1,2]) a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmax') a = T.subzone(a, (3,3,1), (7,8,1)) t = C.newPyTree(['Base',2,a]) test.testT(t, 2) #---------------
def check(): if CTK.t == []: return 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 # Varie de 0 a 180 degres global __SPLITFACTOR__ splitFactor = 180. - WIDGETS['splitFactor'].get() * 180. / 100. __SPLITFACTOR__ = splitFactor wins = C.getEmptyBC(CTK.t, ndim, splitFactor) if CTK.__MAINTREE__ == 1: CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones() CTK.dt = C.newPyTree(['Base', 'Edges']) tp = Internal.appendBaseName2ZoneName(CTK.t, updateRef=False, separator=Internal.SEP1, trailing=Internal.SEP1) bases = Internal.getBases(tp) nb = 0 for b in bases: nodes = Internal.getNodesFromType1(b, 'Zone_t') nz = 0 for z in nodes: ztype = Internal.getZoneType(z) winz = wins[nb][nz] if ztype == 1: # structure for w in winz: imin = w[0] imax = w[1] jmin = w[2] jmax = w[3] kmin = w[4] kmax = w[5] zp = T.subzone(z, (imin, jmin, kmin), (imax, jmax, kmax)) CTK.dt[2][1][2].append(zp) else: # non structure for w in winz: zp = T.subzone(z, w, type='faces') CTK.dt[2][1][2].append(zp) nz += 1 nb += 1 if VARS[7].get() == '1': # display les edges des zones en + exts = [] zones = Internal.getZones(tp) for z in zones: ztype = Internal.getZoneType(z) if ztype == 1: zp = P.exteriorFacesStructured(z) exts += zp else: #zp = P.exteriorFaces(z); zp = P.sharpEdges(zp) zp = [] exts += zp CTK.dt[2][2][2] += exts #C._fillMissingVariables(CTK.dt) # bug exteriorFacesStruct # Activate lenZ = len(CTK.dt[2][1][2]) lenExts = len(exts) active = [(i, 1) for i in range(lenZ + lenExts)] for i in range(lenZ): active[i] = (i, 1) for i in range(lenExts): active[i + lenZ] = (i + lenZ, 0) CTK.display(CTK.dt, mainTree=CTK.UNDEFINEDBC) CPlot.setActiveZones(active) CPlot.setState(edgifyDeactivatedZones=1) else: lenZ = len(CTK.dt[2][1][2]) active = [(i, 1) for i in range(lenZ)] CTK.display(CTK.dt, mainTree=CTK.UNDEFINEDBC) CPlot.setActiveZones(active) # modifie la couleur du bouton l = len(Internal.getZones(CTK.dt)) if l == 0: TTK.setButtonGreen(WIDGETS['undefinedBC']) else: TTK.setButtonRed(WIDGETS['undefinedBC']) WIDGETS['undefinedBC'].update()
def setBCWith(): if CTK.t == []: return if CTK.__MAINTREE__ != CTK.UNDEFINEDBC: CTK.TXT.insert('START', 'Fail on a this tree (view undefined BC before).\n') CTK.TXT.insert('START', 'Error: ', 'Error') return nzs = CPlot.getSelectedZones() if nzs == []: return typeBC = VARS[6].get() if typeBC not in Internal.KNOWNBCS: nameBC = typeBC typeBC = 'FamilySpecified:' + typeBC else: nameBC = typeBC 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 splitFactor = 180. - WIDGETS['splitFactor'].get() * 180. / 100. if __SPLITFACTOR__ != splitFactor: CTK.TXT.insert('START', 'Split factor changed: view undefinedBC again.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() wins = C.getEmptyBC(CTK.t, ndim, splitFactor) bases = Internal.getBases(CTK.t) for nz in nzs: # pour chaque zone selectionnee c = 0 nob = 0 for wb in wins: # par base b = bases[nob] zones = Internal.getNodesFromType1(b, 'Zone_t') noz = 0 for wz in wb: # par zone z = zones[noz] dim = Internal.getZoneDim(z) for w in wz: if c == nz: if dim[0] == 'Structured': # structure C._addBC2Zone(z, nameBC, typeBC, w) elif dim[0] == 'Unstructured' and dim[3] == 'NGON': C._addBC2Zone(z, nameBC, typeBC, faceList=w) else: # BE + BCC zp = T.subzone(z, w, type='faces') zp[0] = C.getZoneName(zp[0]) C._addBC2Zone(z, nameBC, typeBC, subzone=zp) c += 1 noz += 1 nob += 1 #print 'BC is ', w, 'corresponding ', nob-1, noz-1 CTK.TXT.insert('START', 'BCs set to %s.\n' % typeBC) CTK.TKTREE.updateApp() check()
# - splitMultiplePts (pyTree) - import Generator.PyTree as G import Transform.PyTree as T import Converter.PyTree as C import Connector.PyTree as X nk = 2 z0 = G.cart((0., 0., 0.), (0.1, 0.1, 1.), (10, 10, nk)) z1 = T.subzone(z0, (1, 1, 1), (5, 10, nk)) z1[0] = 'cart1' z2 = T.subzone(z0, (5, 1, 1), (10, 5, nk)) z2[0] = 'cart2' z3 = T.subzone(z0, (5, 5, 1), (10, 10, nk)) z3[0] = 'cart3' z0 = T.translate(z0, (-0.9, 0., 0.)) z0[0] = 'cart0' z4 = G.cart((-0.9, 0.9, 0.), (0.1, 0.1, 1.), (19, 5, nk)) z4[0] = 'cart4' t = C.newPyTree(['Base', z1, z2, z3, z4]) t = X.connectMatch(t, dim=2) t = C.fillEmptyBCWith(t, 'wall', 'BCWall', dim=2) t = T.splitMultiplePts(t, dim=2) C.convertPyTree2File(t, 'out.cgns')
# - plaster (pyTree) - import Generator.PyTree as G import Converter.PyTree as C import Transform.PyTree as T import Post.PyTree as P import Geom.PyTree as D a = D.sphere((0, 0, 0), 1) a = T.subzone(a, (6, 1, 1), (50, 200, 1)) a = C.convertArray2Hexa(a) a = G.close(a) # contours c = P.exteriorFaces(a) cs = T.splitConnexity(c) # plaster hole p = G.plaster([cs[0]], [a]) t = C.newPyTree(['Sphere', 2, 'Contours', 1, 'Plaster', 2]) t[2][1][2].append(a) t[2][2][2] += cs t[2][3][2].append(p) C.convertPyTree2File(t, 'out.cgns')
def extract(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 if len(nzs) != 1: CTK.TXT.insert('START', 'Only one block must be selected.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return nz = nzs[0] nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] type = VARS[0].get() if type == 'Node index': CTK.TXT.insert('START', 'Nodes are invalid for extraction.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return inds = CTK.varsFromWidget(VARS[1].get(), type=3) if len(inds) == 0: CTK.TXT.insert('START', 'Invalid index.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return ind = inds[0] [px, py, pz] = C.getValue(z, Internal.__GridCoordinates__, ind) #try: a = T.subzone(z, inds) b = Internal.createUniqueChild(CTK.t, 'EXTRACT', 'CGNSBase_t') nob = C.getNobOfBase(b, CTK.t) CTK.add(CTK.t, nob, -1, a) #except: pass #CTK.TXT.insert('START', 'Extraction not implemented for Nodes.\n') #CTK.TXT.insert('START', 'Error: ', 'Error') elif type == 'Coordinates': CTK.TXT.insert('START', 'Coordinates are invalid for extraction.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return [px, py, pz] = vars else: # type = element index inds = CTK.varsFromWidget(VARS[1].get(), type=3) if len(inds) == 0: CTK.TXT.insert('START', 'Invalid index.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return ind = inds[0] try: if Internal.getZoneType(z) == 1: # struct dims = Internal.getZoneDim(z) indices = [] for ind in inds: # convert to monoindex if isinstance(ind, tuple): ind = ind[0] - 1 + (ind[1] - 1) * dims[1] + ( ind[2] - 1) * dims[1] * dims[2] indices.append(ind) else: indices.append(ind) a = T.subzone(C.convertArray2Hexa(z), indices, type='elements') else: # unstruct a = T.subzone(z, inds, type='elements') b = Internal.createUniqueChild(CTK.t, 'EXTRACT', 'CGNSBase_t') nob = C.getNobOfBase(b, CTK.t) CTK.add(CTK.t, nob, -1, a) except: pass #zp = C.node2Center(z) #[px,py,pz] = C.getValue(zp, Internal.__GridCoordinates__, ind) #(xeye,yeye,zeye) = CPlot.getState('posEye') #(xcam,ycam,zcam) = CPlot.getState('posCam') #dx = xcam-xeye; dy = ycam-yeye; dz = zcam-zeye #CPlot.setState(posEye=(px,py,pz)) #CPlot.setState(posCam=(px-0.1*dx,py-0.1*dy,pz-0.1*dz)) #CPlot.setActivePoint(px,py,pz) CTK.TXT.insert('START', 'Cell extracted.\n') (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp()