def union(): 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 len(nzs) < 2: CTK.TXT.insert('START', 'Please, select two or more surfaces.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return tol = CTK.varsFromWidget(VARS[0].get(), type=1) if len(tol) != 1: CTK.TXT.insert('START', 'Tolerance is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return tol = tol[0] CTK.saveTree() zlist = [] deletedZoneNames = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] deletedZoneNames.append(CTK.t[2][nob][0] + Internal.SEP1 + CTK.t[2][nob][2][noz][0]) z = CTK.t[2][nob][2][noz] zlist.append(z) try: j = XOR.booleanUnion(zlist[0], zlist[1], tol=tol) except Exception as e: Panels.displayErrors([0, str(e)], header='Error: union') CTK.TXT.insert('START', 'Union failed\n') return for nz in range(len(zlist) - 2): try: j = XOR.booleanUnion(j, zlist[nz + 2], tol=tol) except Exception as e: Panels.displayErrors([0, str(e)], header='Error: union') CTK.TXT.insert('START', 'Union failed.\n') return CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs) CPlot.delete(deletedZoneNames) CTK.add(CTK.t, CTK.Nb[0] + 1, -1, j) CTK.TXT.insert('START', 'Union performed.\n') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def aglomerateNonStar(t): nb_cells0 = nb_cells(t) carry_on = 1 i = 0 while (carry_on == 1): print " " print "iter %s" % i t = XOR.agglomerateNonStarCells(t) print "check closure" XOR.checkCellsClosure(t) nb_cells1 = nb_cells(t) if (nb_cells1 == nb_cells0): carry_on = 0 if (carry_on == 0): print "no cell found." if (nb_cells1 != nb_cells0): print "%d cells have been aglomerated" % (nb_cells0 - nb_cells1) #C.convertPyTree2File(t, "nonstar_iter_%s.cgns"%i) nb_cells0 = nb_cells1 i = i + 1 #if (i == 3) : carry_on=0 return t
def difference2(): 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 len(nzs) != 2: CTK.TXT.insert('START', 'Please, select two surfaces.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return tol = CTK.varsFromWidget(VARS[0].get(), type=1) if len(tol) != 1: CTK.TXT.insert('START', 'Tolerance is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return tol = tol[0] CTK.saveTree() deletedZoneNames = [] nz = nzs[0] nob1 = CTK.Nb[nz] + 1 noz1 = CTK.Nz[nz] deletedZoneNames.append(CTK.t[2][nob1][0] + Internal.SEP1 + CTK.t[2][nob1][2][noz1][0]) z1 = CTK.t[2][nob1][2][noz1] nz = nzs[1] nob2 = CTK.Nb[nz] + 1 noz2 = CTK.Nz[nz] deletedZoneNames.append(CTK.t[2][nob2][0] + Internal.SEP1 + CTK.t[2][nob2][2][noz2][0]) z2 = CTK.t[2][nob2][2][noz2] try: j = XOR.booleanMinus(z2, z1, tol=tol) CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs) CPlot.delete(deletedZoneNames) CTK.add(CTK.t, nob1, -1, j) CTK.TXT.insert('START', 'Difference performed.\n') except Exception as e: Panels.displayErrors([0, str(e)], header='Error: difference') CTK.TXT.insert('START', 'Difference failed.\n') #C._fillMissingVariables(CTK.t) (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t) CTK.TKTREE.updateApp() CPlot.render()
def aglomerate(t, vr, vm): nb_cells0 = nb_cells(t) carry_on = 1 i = 0 while (carry_on == 1): print "iter %s" % i t = XOR.agglomerateSmallCells(t, vmin=vm, vratio=vr) nb_cells1 = nb_cells(t) if (nb_cells1 == nb_cells0): carry_on = 0 if (carry_on == 0): print "no cell found." if (nb_cells1 != nb_cells0): print "%d cells have been aglomerated" % (nb_cells0 - nb_cells1) nb_cells0 = nb_cells1 i = i + 1 #if (i == 3) : carry_on=0 return t
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.) C.convertPyTree2File(x, 'out1.plt')
# - boolean union (PyTree) - import Intersector.PyTree as XOR import Converter.PyTree as C import KCore.test as test M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 x = XOR.booleanUnion(M1, M2, tol, preserve_right=1, solid_right=1) test.testT(x, 1) x = XOR.booleanUnion(M1, M2, tol, preserve_right=0, solid_right=1) test.testT(x, 2) #~ x = XOR.booleanUnion(M1, M2, tol, preserve_right=1, solid_right=0) #~ test.testT(x,3) #~ #~ x = XOR.booleanUnion(M1, M2, tol, preserve_right=0, solid_right=0) #~ test.testT(x,4)
# - convexify any concave polygon in the mesh (array) - import Intersector.PyTree as XOR import Converter.PyTree as C import KCore.test as test M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 m = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=1, agg_mode=1) #C.convertArrays2File([m], 'i.plt') m = XOR.agglomerateNonStarCells(m) test.testT(m, 1)
# - boolean difference (pyTree) - import Intersector.PyTree as XOR import Generator.PyTree as G import Converter.PyTree as C import Geom.PyTree as D import KCore.test as test s1 = D.sphere((0, 0, 0), 1, N=20) s2 = D.sphere((0., 1., 0.), 1, N=30) s1 = C.convertArray2Tetra(s1) s1 = G.close(s1) s2 = C.convertArray2Tetra(s2) s2 = G.close(s2) x = XOR.booleanMinus(s1, s2, tol=0.) test.testT(x)
# - intersection (pyTree) - import Intersector.PyTree as XOR import Generator.PyTree as G import Converter.PyTree as C import Geom.PyTree as D s1 = D.sphere((0,0,0), 1, N=20) s2 = D.sphere((0.,1.,0.), 1, N=30) s1 = C.convertArray2Tetra(s1); s1 = G.close(s1) s2 = C.convertArray2Tetra(s2); s2 = G.close(s2) x = XOR.intersection(s1, s2, tol=0.) C.convertPyTree2File(x, 'out.cgns')
# - boolean checkCellsClosure (array) - import Generator.PyTree as G import Converter.PyTree as C import Intersector.PyTree as XOR import Geom.PyTree as D M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) err = XOR.checkCellsClosure(M1)
# - boolean intersection (pyTree) - # BAR import Intersector.PyTree as XOR import Generator.PyTree as G import Converter.PyTree as C import Geom.PyTree as D import KCore.test as test 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.booleanIntersection(c1, c2, tol=0.) test.testT(x)
import Converter.PyTree as C import Intersector.PyTree as XOR import KCore.test as test M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 m = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=1, agg_mode=1) #C.convertArrays2File([m], 'i.plt') m = XOR.extractUncomputables(m) test.testT(m, 1)
import Converter.Internal as I import Intersector.PyTree as XOR import KCore.test as test import Post.PyTree as P t1 = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 10)) t1 = C.convertArray2NGon(t1) t1 = G.close(t1) t2 = G.cart((1., 0, 0), (1, 1, 1), (10, 10, 10)) t2 = C.convertArray2NGon(t2) t2 = G.close(t2) #C.convertPyTree2File(t1, 'm.plt') #C.convertPyTree2File(t2, 's.plt') # test 1 : volume/volume res = XOR.getOverlappingFaces(t1, t2, RTOL=0.05, ps_min=0.95) # create a list of polygon list (t1), one list per zone nb_zones = len(res) t1zones_pgids = [] for i in range(nb_zones): t1zones_pgids.append(res[i][0]) t = XOR.agglomerateCellsWithSpecifiedFaces(t1, t1zones_pgids) test.testT(t, 1) #test 2 : volume/surface t2 = P.exteriorFaces(t2) t2 = XOR.convertNGON2DToNGON3D(t2)
# - adapt the bounding box of a point cloud (array) - import Converter.PyTree as C import Generator.PyTree as G import Intersector.PyTree as XOR a = G.cartHexa((0.,0.,0.), (0.1,0.1,0.1), (5,5,5)) a = C.convertArray2NGon(a); a = G.close(a) m = XOR.adaptBox(a, box_ratio=10.) m = XOR.closeOctalCells(m) # optional : to close the polyhedral cells C.convertPyTree2File(m, 'out.cgns')
# - boolean intersection (pyTree) - import Intersector.PyTree as XOR import Generator.PyTree as G import Converter.PyTree as C import Geom.PyTree as D import KCore.test as test s1 = D.sphere( (0,0,0), 1, N=20 ) s2 = D.sphere( (0.,1.,0.), 1, N=30 ) s1 = C.convertArray2Tetra(s1); s1 = G.close(s1) s2 = C.convertArray2Tetra(s2); s2 = G.close(s2) x = XOR.booleanIntersection(s1, s2, tol=0.) test.testT(x, 1)
# - convexify any concave polygon in the mesh (array) - import Intersector.PyTree as XOR import Converter.PyTree as C import KCore.test as test M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 m = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=1, agg_mode=1) #C.convertArrays2File([m], 'i.plt') m = XOR.simplifyCells(m, 1) test.testT(m, 1)
# - boolean minus (PyTree) - import Intersector.PyTree as XOR import Converter.PyTree as C import KCore.test as test M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 x = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=1) test.testT(x, 1) x = XOR.booleanMinus(M1, M2, tol, preserve_right=0, solid_right=1) test.testT(x, 2) #~ x = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=0) #~ test.testT(x,3) #~ #~ x = XOR.booleanMinus(M1, M2, tol, preserve_right=0, solid_right=0) #~ test.testT(x,4)
import Converter.PyTree as C import Generator.PyTree as G import Intersector.PyTree as XOR 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, 0., 2) x = T.splitManifold(x) C.convertPyTree2File(x, 'outS.cgns') 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) x = T.splitManifold(c) C.convertPyTree2File(x, "outB.cgns")
# - boolean modified solid (PyTree) - import Intersector.PyTree as XOR import Converter.PyTree as C import KCore.test as test M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 x = XOR.booleanModifiedSolid(M1, M2, tol, preserve_solid=1) test.testT(x, 1) x = XOR.booleanModifiedSolid(M1, M2, tol, preserve_solid=0) test.testT(x, 2)
# - boolean difference (array) - import Intersector.PyTree as XOR import Converter.PyTree as C import Transform.PyTree as T M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M1 = C.conformizeNGon(M1) M1 = XOR.closeOctalCells(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) M2 = C.conformizeNGon(M2) M2 = XOR.closeOctalCells(M2) tol = -0.5e-3 M = T.join(M1,M2) M = XOR.selfX(M) C.convertPyTree2File(M, 'out.cgns')
import Intersector.PyTree as XOR import KCore.test as test mesh = G.cart((0, 0, 0), (1, 1, 1), (20, 20, 20)) source = G.cart((8, 8, 8), (0.2, 0.2, 0.2), (20, 20, 20)) #C.convertPyTree2File(mesh, 'm.cgns') #C.convertPyTree2File(source, 's.cgns') t = C.newPyTree(['Base', mesh]) t = T.splitNParts(t, 2, multigrid=0, dirs=[1, 2, 3]) zones = I.getZones(t) p1 = zones[0] p1 = C.convertArray2Tetra(p1, split='withBarycenters') p1 = C.convertArray2NGon(p1) p2 = C.convertArray2NGon(zones[1]) mesh = XOR.booleanUnion(p1, p2) #conformize the join #C.convertPyTree2File(mesh, 'u.cgns') m1 = XOR.adaptCells(mesh, source, sensor_type=0) m1 = XOR.closeOctalCells(m1) #C.convertPyTree2File(m1, 'out.cgns') test.testT(m1, 1) m2 = XOR.adaptCells(mesh, source, sensor_type=2) m2 = XOR.closeOctalCells(m2) #C.convertPyTree2File(m2, 'out1.cgns') test.testT(m2, 2)
# - adapt the bounding box of a point cloud (array) - import Intersector.PyTree as XOR import Converter.PyTree as C import Generator.PyTree as G import KCore.test as test a = G.cartHexa((0.,0.,0.), (0.1,0.1,0.1), (5,5,5)) a = C.convertArray2NGon(a); a = G.close(a) m = XOR.adaptBox(a, box_ratio=10.) m = XOR.closeOctalCells(m) test.testT(m,1)
# - extractNonStar (pyTree) - import Converter.PyTree as C import Intersector.PyTree as XOR import KCore.test as test M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 t = XOR.booleanMinus(M1, M2, tol, preserve_right=0, solid_right=0, agg_mode=1) t=XOR.extractPathologicalCells(t, 2) # ask for 2 level of neighgbors test.testT(t, 1)
# - convexify any concave polygon in the mesh (array) - import Intersector.PyTree as XOR import Converter.PyTree as C import KCore.test as test import KCore.test as test M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 m = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=1, agg_mode=2) #full agg to convexify afterward #C.convertArrays2File([m], 'i.plt') PG_threshold = 1.e-2 m = XOR.prepareCellsSplit(m, PH_set = 0, split_policy = 0, PH_conc_threshold = 1./3., PH_cvx_threshold = 0.05, PG_cvx_threshold = PG_threshold) test.testT(m, 1) m = XOR.prepareCellsSplit(m, PH_set = 0, split_policy = 1, PH_conc_threshold = 1./3., PH_cvx_threshold = 0.05, PG_cvx_threshold = PG_threshold) test.testT(m, 2) m = XOR.prepareCellsSplit(m, PH_set = 0, split_policy = 2, PH_conc_threshold = 1./3., PH_cvx_threshold = 0.05, PG_cvx_threshold = PG_threshold) test.testT(m, 3) m = XOR.prepareCellsSplit(m, PH_set = 1, split_policy = 0, PH_conc_threshold = 1./3., PH_cvx_threshold = 0.05, PG_cvx_threshold = PG_threshold) test.testT(m, 4)
# - boolean difference (pyTree) - # BAR import Intersector.PyTree as XOR import Generator.PyTree as G import Converter.PyTree as C import Geom.PyTree as D import KCore.test as test 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.booleanMinus(c1, c2, tol=0.) test.testT(x)
# - booleanUnion (pyTree) - import Intersector.PyTree as XOR import Generator.PyTree as G import Converter.PyTree as C import Geom.PyTree as D s1 = D.sphere((0, 0, 0), 1, N=20) s2 = D.sphere((0., 1., 0.), 1, N=30) s1 = C.convertArray2Tetra(s1) s1 = G.close(s1) s2 = C.convertArray2Tetra(s2) s2 = G.close(s2) x = XOR.booleanUnion(s1, s2, tol=0.) C.convertPyTree2File(x, 'out.cgns')
# - triangulateExteriorFaces (PyTree) - import Intersector.PyTree as XOR import Converter.PyTree as C import KCore.test as test t = C.convertFile2PyTree('boolNG_M1.tp') t = C.convertArray2NGon(t) t = C.fillEmptyBCWith(t, 'wall', 'BCWall', dim=3) XOR._triangulateBC(t, 'BCWall') test.testT(t, 1)
import Geom.PyTree as D import Converter.PyTree as C import Intersector.PyTree as XOR # octree s = D.sphere((0, 0, 0), 1., 100) snear = 0.1 t = G.octree([s], [snear], dfar=5., balancing=1, ratio=2) # ngon converion t = C.convertArray2NGon(t) # ngon conformization t = C.conformizeNGon(t) t = G.close(t) # ngon close cells t = XOR.closeOctalCells(t) #t = XOR.reorientExternalFaces(t) # ngon converion of the sphere s = C.convertArray2NGon(s) # ngon converion to the nuga format s = XOR.convertNGON2DToNGON3D(s) #s = XOR.reorientExternalFaces(s) # Boolean operation x = XOR.diffSurf(t, s, tol=0., preserve_right=1, agg_mode=2) # agg_mode=2 : full mode aggregation x = XOR.agglomerateSmallCells(x, 0., 10.) t = C.newPyTree(['Base', 2])
# - convexify any concave polygon in the mesh (array) - import Intersector.PyTree as XOR import Converter.PyTree as C M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 m = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=1, agg_mode=1) m = XOR.simplifyCells(m, 1) m = XOR.prepareCellsSplit(m, PH_set=0, split_policy=0, PH_conc_threshold=1. / 3., PH_cvx_threshold=0.05, PG_cvx_threshold=1.e-8) m = XOR.splitNonStarCells(m, PH_conc_threshold=1. / 3., PH_cvx_threshold=0.05, PG_cvx_threshold=1.e-8) C.convertPyTree2File(m, 'out.cgns')
# - Extract pathological cells (uncomputable or non-star) - (array) import Converter.PyTree as C import Intersector.PyTree as XOR import KCore.test as test M1 = C.convertFile2PyTree('boolNG_M1.tp') M1 = C.convertArray2NGon(M1) M2 = C.convertFile2PyTree('boolNG_M2.tp') M2 = C.convertArray2NGon(M2) tol = -0.5e-3 t = XOR.booleanMinus(M1, M2, tol, preserve_right=1, solid_right=1, agg_mode=1) t = XOR.computeAspectRatio(t) test.testT(t, 1)