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)
# - 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.))
def smooth(): if CTK.t == []: return if CTK.__MAINTREE__ <= 0: CTK.TXT.insert('START', 'Fail on a temporary tree.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return smooth = CTK.varsFromWidget(VARS[0].get(), type=2) if len(smooth) != 1: CTK.TXT.insert('START', 'Smooth iter is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return smooth = smooth[0] eps = CTK.varsFromWidget(VARS[4].get(), type=1) if len(eps) != 1: CTK.TXT.insert('START', 'Eps is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return eps = eps[0] ntype = VARS[8].get() if ntype == 'Volume': ntype = 0 elif ntype == 'Scale': ntype = 1 elif ntype == 'Taubin': ntype = 2 else: ntype = 0 # Constraint strength strength = CTK.varsFromWidget(VARS[2].get(), type=1) if len(strength) != 1: CTK.TXT.insert('START', 'Constraint strength is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return strength = strength[0] # Constraints fixedConstraints = []; projConstraints = [] name = VARS[1].get() names = name.split(';') for v in names: v = v.lstrip(); v = v.rstrip() sname = v.split('/', 1) base = Internal.getNodeFromName1(CTK.t, sname[0]) if base is not None: nodes = Internal.getNodesFromType1(base, 'Zone_t') for z in nodes: if (z[0] == sname[1]): fixedConstraints.append(z) CTK.saveTree() # Get all zones zones = [] for nz in nzs: nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] zones.append(z) # Mesh unique try: A = C.convertArray2Tetra(zones) A = T.join(A); A = G.close(A) except Exception as e: Panels.displayErrors([0,str(e)], header='Error: smooth') CTK.TXT.insert('START', 'Some zones are invalid for smoothing.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return # pb surfacique ou volumique? dims = Internal.getZoneDim(A) pbDim = 3 if dims[3] == 'TRI': pbDim = 2 # Keep external faces if VARS[3].get() == 1 or pbDim == 3: try: ext = P.exteriorFaces(A) except: ext = [] if VARS[3].get() == 1 and ext != []: fixedConstraints.append(ext) # Keep sharp edges if VARS[5].get() == 1: angle = CTK.varsFromWidget(VARS[6].get(), type=1) if len(angle) != 1: CTK.TXT.insert('START', 'Sharp edges angle is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return angle = angle[0] if pbDim == 2: try: sharp = P.sharpEdges(A, angle) fixedConstraints += sharp except: pass else: try: sharp = P.sharpEdges(ext, angle) fixedConstraints += sharp except: pass # Project on surface Pj = VARS[7].get() if pbDim == 2: projSurf = A else: # projSurf = ext # Pour l'instant, on ne sait pas projeter un maillage volumique # sur une surface Pj = 0 # Smooth fail = False try: if Pj == 0: zones = T.smooth(zones, eps=eps, niter=smooth, type=ntype, fixedConstraints=fixedConstraints, projConstraints=projConstraints, delta=strength) else: for s in xrange(smooth): zones = T.smooth(zones, eps=eps, niter=2, type=ntype, fixedConstraints=fixedConstraints, projConstraints=projConstraints, delta=strength) zones = T.projectOrtho(zones, [projSurf]) except Exception as e: fail = True Panels.displayErrors([0,str(e)], header='Error: smooth') if fail == False: c = 0 for nz in nzs: nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] a = zones[c]; c += 1 CTK.replace(CTK.t, nob, noz, a) CTK.TXT.insert('START', 'Mesh smoothed.\n') else: CTK.TXT.insert('START', 'Smooth fails.\n') CTK.TXT.insert('START', 'Error: ', 'Error') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
# - sharpEdges (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Post.PyTree as P import Transform.PyTree as T a1 = G.cart((0., 0., 0.), (1.5, 1., 1.), (2, 2, 1)) a2 = T.rotate(a1, (0., 0., 0.), (0., 1., 0.), 100.) a2[0] = 'cart2' res = P.sharpEdges([a1, a2], alphaRef=45.) t = C.newPyTree(['Edge', 1, 'Base', 2]) t[2][1][2] += res t[2][2][2] += [a1, a2] C.convertPyTree2File(t, "out.cgns")