def createZEllipse(): import Geom.PyTree as D import Transform.PyTree as T alpha = CTK.varsFromWidget(VARS[1].get(), type=2) if len(alpha) == 1: ax = alpha[0] ay = alpha[0] az = alpha[0] bx = alpha[0] by = alpha[0] bz = alpha[0] elif len(alpha) == 3: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[0] by = alpha[1] bz = alpha[2] elif len(alpha) == 6: ax = alpha[0] ay = alpha[1] az = alpha[2] bx = alpha[3] by = alpha[4] bz = alpha[5] else: CTK.TXT.insert('START', 'Borders factor incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return try: box = G.bbox(CTK.t) except: box = [0, 0, 0, 1, 1, 1] hx = box[3] - box[0] hy = box[4] - box[1] if hx < 1.e-10: hx = 0.1 if hy < 1.e-10: hy = 0.1 hx = hx * 0.7 * ax hy = hy * 0.7 * ay cx = 0.5 * (box[0] + box[3]) cy = 0.5 * (box[1] + box[4]) if hx < hy: s = D.circle((cx, cy, box[2]), hx, N=50) s = T.contract(s, (cx, cy, box[2]), (1, 0, 0), (0, 0, 1), hy / hx) else: s = D.circle((cx, cy, box[2]), hy, N=50) s = T.contract(s, (cx, cy, box[2]), (0, 1, 0), (0, 0, 1), hx / hy) s = C.convertArray2Tetra(s) s = G.close(s, 1.e-6) p = G.fittingPlaster(s, bumpFactor=0.) s = G.gapfixer(s, p) s = CPlot.addRender2Zone(s, material='Solid', color='White', meshOverlay=0) return [s]
# - contract (pyTree) - import Transform.PyTree as T import Generator.PyTree as G import Converter.PyTree as C import KCore.test as test # Structure 3D a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 3)) C._addVars(a, 'Density') C._initVars(a, 'centers:cellN', 1) a = C.addBC2Zone(a, 'wall', 'BCWall', 'imin') a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2, 3]) a = T.contract(a, (0., 0., 0.), (1, 0, 0), (0, 1, 0), 0.1) test.testT(a, 1) # Structure 2D a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 1)) C._addVars(a, 'Density') C._initVars(a, 'centers:cellN', 1) a = C.addBC2Zone(a, 'wall', 'BCWall', 'imin') a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2]) a = T.contract(a, (0., 0., 0.), (1, 0, 0), (0, 1, 0), 0.1) test.testT(a, 2) # TETRA a = G.cartTetra((0, 0, 0), (1, 1, 1), (10, 10, 3)) C._addVars(a, 'Density') C._initVars(a, 'centers:cellN', 1) a = T.contract(a, (0., 0., 0.), (1, 0, 0), (0, 1, 0), 0.1)
import Transform.PyTree as T import Generator.PyTree as G import Converter.PyTree as C import KCore.test as test # Structure 3D a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 3)) a = C.addVars(a, 'Density') a = C.initVars(a, 'centers:cellN', 1) a = C.addBC2Zone(a, 'wall', 'BCWall', 'imin') a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2, 3]) t = C.newPyTree(['Base']) t[2][1][2].append(a) t[2][1] = C.addState(t[2][1], 'EquationDimension', 3) t = T.contract(t, (0., 0., 0.), (1, 0, 0), (0, 1, 0), 0.1) test.testT(t, 1) # Structure 2D a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 1)) a = C.addVars(a, 'Density') a = C.initVars(a, 'centers:cellN', 1) a = C.addBC2Zone(a, 'wall', 'BCWall', 'imin') a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2]) t = C.newPyTree(['Base', 2]) t[2][1][2].append(a) t[2][1] = C.addState(t[2][1], 'EquationDimension', 2) t = T.contract(t, (0., 0., 0.), (1, 0, 0), (0, 1, 0), 0.1) test.testT(t, 2)
# - stitchedHat (pyTree) - import Geom.PyTree as D import Generator.PyTree as G import Transform.PyTree as T import KCore.test as test import Converter.PyTree as C c = D.circle((0, 0, 0), 1., 360., 0., 100) c = T.contract(c, (0, 0, 0), (0, 1, 0), (0, 0, 1), 0.1) c = C.initVars(c, 'centers:cellN', 1.) c = C.initVars(c, 'Density', 2.) c = G.stitchedHat(c, (0, 0, 0), 1.e-4) t = C.newPyTree(['Base', 2]) t[2][1][2].append(c) test.testT(t, 1)
def scale(): 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 v = CTK.varsFromWidget(VARS[1].get(), type=1) if len(v) != 1 and len(v) != 3 and len(v) != 6: CTK.TXT.insert('START', 'Scale factor is incorrect.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return axis = VARS[5].get() if axis == 'along XYZ': axe1 = (1, 0, 0) axe2 = (0, 1, 0) axe3 = (0, 0, 1) else: # view posCam = CPlot.getState('posCam') posEye = CPlot.getState('posEye') dirCam = CPlot.getState('dirCam') axe1 = (posEye[0] - posCam[0], posEye[1] - posCam[1], posEye[2] - posCam[2]) axe2 = dirCam axe3 = (axe1[1] * axe2[2] - axe1[2] * axe2[1], axe1[2] * axe2[0] - axe1[0] * axe2[2], axe1[0] * axe2[1] - axe1[1] * axe2[0]) nzs = CPlot.getSelectedZones() if nzs == []: CTK.TXT.insert('START', 'Selection is empty.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return CTK.saveTree() selection = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] selection.append(z) if len(v) == 6: # center is given X = [v[3], v[4], v[5]] else: X = G.barycenter(selection) if len(v) == 1 and v[0] == 0.: # scale unitaire bbox = G.bbox(selection) dx = bbox[3] - bbox[0] dy = bbox[4] - bbox[1] dz = bbox[5] - bbox[2] if dx >= dy and dx >= dz: v[0] = 1. / dx if dy >= dx and dy >= dz: v[0] = 1. / dy if dz >= dy and dz >= dx: v[0] = 1. / dz list = [] for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] list.append((nob, noz, nz)) z = CTK.t[2][nob][2][noz] if len(v) == 1: a = T.homothety(z, (X[0], X[1], X[2]), v[0]) else: z = T.contract(z, (X[0], X[1], X[2]), axe2, axe3, v[0]) z = T.contract(z, (X[0], X[1], X[2]), axe1, axe3, v[1]) a = T.contract(z, (X[0], X[1], X[2]), axe1, axe2, v[2]) CTK.replace(CTK.t, nob, noz, a) CTK.TXT.insert('START', 'Zones have been scaled.\n') CTK.TKTREE.updateApp() CPlot.render()
def prepareMotionChimeraData(t, tc, tblank, noBaseOff, tBB=None, DEPTH=2, loc='centers', NIT=1, RotationCenter=None, RotationAngle=None, Translation=None, listOfSteadyOffBodyZones=None, listOfOffBodyIntersectingNBZones=None): # arbre de BBox des zones donneuses if tBB is None: tBB = G.BB(tc) # BB des zones donneuses if listOfOffBodyIntersectingNBZones is None: listOfOffBodyIntersectingNBZones = getListOfOffBodyIntersectingNBZones( tBB, noBaseOff, NIT=NIT, DEPTH=DEPTH, RotationCenter=RotationCenter, RotationAngle=RotationAngle, Translation=Translation) listOfSteadyOffBodyZones = getListOfSteadyOffBodyZones( tBB, noBaseOff, listOfOffBodyIntersectingNBZones) if listOfSteadyOffBodyZones is None: listOfSteadyOffBodyZones = getListOfSteadyOffBodyZones( tBB, noBaseOff, listOfOffBodyIntersectingNBZones) dimPb = Internal.getNodeFromName(t, 'EquationDimension') if dimPb is None: raise ValueError('EquationDimension is missing in input body tree.') dimPb = Internal.getValue(dimPb) if dimPb == 2: z0 = Internal.getNodeFromType2(t, 'Zone_t') dims = Internal.getZoneDim(z0) npts = dims[1] * dims[2] * dims[3] zmin = C.getValue(z0, 'CoordinateZ', 0) zmax = C.getValue(z0, 'CoordinateZ', npts - 1) dz = zmax - zmin # Creation du corps 2D pour le preprocessing IBC tblank = T.addkplane(tblank) tblank = T.contract(tblank, (0, 0, 0), (1, 0, 0), (0, 1, 0), dz) rotation = True translation = True if RotationAngle is None: rotation = False if Translation is None: translation = False if rotation is True and translation is True: raise ValueError( "ToolboxIBM: translation and rotation not yet possible together.") constantMotion = False if rotation: if len(RotationAngle) == 3 and isinstance(RotationAngle[0], list) == False: constantMotion = True if translation: if len(Translation) == 3 and isinstance(Translation[0], list) == False: constantMotion = True xc0 = RotationCenter[0] yc0 = RotationCenter[1] zc0 = RotationCenter[2] C._initVars(t[2][noBaseOff], '{centers:cellNInit}={centers:cellN}') C._initVars(tc[2][noBaseOff], "{cellNInit}={cellN}") dictOfNearBodyBaseNb = {} dictOfNearBodyZoneNb = {} for nob in range(len(tc[2])): if nob != noBaseOff: base = tc[2][nob] if Internal.getType(base) == 'CGNSBase_t': for noz in range(len(base[2])): zone = base[2][noz] if Internal.getType(zone) == 'Zone_t': zname = zone[0] dictOfNearBodyZoneNb[zname] = noz dictOfNearBodyBaseNb[zname] = nob dictOfOffBodyZoneNb = {} dictOfOffBodyADT = {} # preconditionnement for noz in range(len(tc[2][noBaseOff][2])): z = tc[2][noBaseOff][2][noz] zname = z[0] if Internal.getType(z) == 'Zone_t': dictOfOffBodyZoneNb[zname] = noz if zname in listOfOffBodyIntersectingNBZones: zc = tc[2][noBaseOff][2][noz] hook0 = C.createHook(zc, 'adt') dictOfOffBodyADT[zname] = hook0 C._initVars(tc, '{CoordinateXInit}={CoordinateX}') C._initVars(tc, '{CoordinateYInit}={CoordinateY}') C._initVars(tc, '{CoordinateZInit}={CoordinateZ}') C._initVars(t, '{CoordinateXInit}={CoordinateX}') C._initVars(t, '{CoordinateYInit}={CoordinateY}') C._initVars(t, '{CoordinateZInit}={CoordinateZ}') C._initVars(tBB, '{CoordinateXInit}={CoordinateX}') C._initVars(tBB, '{CoordinateYInit}={CoordinateY}') C._initVars(tBB, '{CoordinateZInit}={CoordinateZ}') if NIT > 1: for zc in Internal.getZones(tc): IDatas = Internal.getNodesFromName(zc, "ID_*") for ID in IDatas: name = ID[0].split('_') ID[0] = 'IDSteady_%s' % (name[1]) tloc = C.newPyTree(['OffMotion']) for zr in t[2][noBaseOff][2]: if Internal.getType(zr) == 'Zone_t': znamer = zr[0] if znamer not in listOfSteadyOffBodyZones: # print " Zone de fond en mvt %s"%znamer tloc[2][1][2].append(zr) else: tloc[2][1][2].append(zr) tBBloc = G.BB(tloc) # a remonter dans l interface intersectionsDictOffOff = X.getIntersectingDomains(tBB[2][noBaseOff], method='AABB', taabb=tBB[2][noBaseOff]) listOfIntersectionDictsNBNB = {} for nob in range(len(t[2])): if nob != noBaseOff and Internal.getType(t[2][nob]) == 'CGNSBase_t': intersectionsDictNB = X.getIntersectingDomains(tBB[2][nob], method='AABB', taabb=tBB[2][nob]) listOfIntersectionDictsNBNB[nob] = intersectionsDictNB for it in range(NIT): print(' ------------------- Iteration %d ----------------------- ' % it) if constantMotion: if rotation: angleX = RotationAngle[0] * it angleY = RotationAngle[1] * it angleZ = RotationAngle[2] * it print('Rotation (degres) : (alphaX=%g,alphaY=%g,alphaZ=%g)' % (angleX, angleY, angleZ)) elif translation: tx = Translation[0] ty = Translation[1] tz = Translation[2] else: if rotation: angleX = RotationAngle[it][0] angleY = RotationAngle[it][1] angleZ = RotationAngle[it][2] print('Rotation (degres) : (alphaX=%g,alphaY=%g,alphaZ=%g)' % (angleX, angleY, angleZ)) elif translation: tx = Translation[it][0] ty = Translation[it][1] tz = Translation[it][2] if rotation: tblankM = T.rotate(tblank, (xc0, yc0, zc0), (angleX, angleY, angleZ)) elif translation: tblankM = T.translate(tblank, (tx, ty, tz)) C._initVars(tloc, "{centers:cellN}={centers:cellNInit}") tloc = blankByIBCBodies(tloc, tblankM, 'centers', dim=dimPb, gridType='composite') tloc = X.setHoleInterpolatedPoints(tloc, depth=DEPTH, loc='centers') for zloc in Internal.getZones(tloc): zname = zloc[0] nozloc = dictOfOffBodyZoneNb[zname] C._cpVars(zloc, 'centers:cellN', tc[2][noBaseOff][2][nozloc], "cellN") dictOfMotionADT = { } # ADT des blocs en mvt a detruire a chq pas de temps # bases proches corps interpolees par le maillage de fond fixe + ses voisins for nob in range(len(t[2])): base = t[2][nob] if nob != noBaseOff and Internal.getType(base) == 'CGNSBase_t': if rotation: T._rotate(base, (xc0, yc0, zc0), (angleX, angleY, angleZ)) T._rotate(tBB[2][nob], (xc0, yc0, zc0), (angleX, angleY, angleZ)) T._rotate(tc[2][nob], (xc0, yc0, zc0), (angleX, angleY, angleZ)) elif translation: T._translate(base, (tx, ty, tz)) T._translate(tBB[2][nob], (tx, ty, tz)) T._translate(tc[2][nob], (tx, ty, tz)) tBBNB = Internal.rmNodesByName(tBB, tBB[2][noBaseOff][0]) intersectionsDictOffNB = X.getIntersectingDomains( tBB[2][noBaseOff], t2=tBBNB, method='AABB', taabb=tBB[2][noBaseOff], taabb2=tBBNB) for nob in range(len(t[2])): base = t[2][nob] if nob != noBaseOff and Internal.getType(base) == 'CGNSBase_t': # test intersection entre maillage proche corps et maillage de fond intersectionsDictNBO = X.getIntersectingDomains( tBB[2][nob], t2=tBB[2][noBaseOff], method='AABB', taabb=tBB[2][nob], taabb2=tBB[2][noBaseOff]) print('Near-body base %s in motion' % (base[0])) intersectionsDictNBNB = listOfIntersectionDictsNBNB[nob] for zr in Internal.getZones(base): if Internal.getNodesFromName(zr, "ov_ext*") != []: znamer = zr[0] donorZones = [] hooks = [] for znamed in intersectionsDictNBO[znamer]: if znamed in dictOfOffBodyZoneNb: # donneur=fond nozd = dictOfOffBodyZoneNb[znamed] zd = tc[2][noBaseOff][2][nozd] hooks.append(dictOfOffBodyADT[znamed]) donorZones.append(zd) for znamed in intersectionsDictNBNB[znamer]: nozd = dictOfNearBodyZoneNb[znamed] nobd = dictOfNearBodyBaseNb[znamed] zd = tc[2][nobd][2][nozd] if znamed not in dictOfMotionADT: hook0 = C.createHook(zd, 'adt') dictOfMotionADT[znamed] = hook0 hooks.append(dictOfMotionADT[znamed]) donorZones.append(zd) donorZones = X.setInterpData(zr,donorZones,nature=1,penalty=1,loc='centers',storage='inverse',sameName=1,\ hook=hooks, itype='chimera') for zd in donorZones: znamed = zd[0] if znamed in dictOfOffBodyZoneNb: nozd = dictOfOffBodyZoneNb[znamed] tc[2][noBaseOff][2][nozd] = zd elif znamed in dictOfNearBodyZoneNb: nozd = dictOfNearBodyZoneNb[znamed] nobd = dictOfNearBodyBaseNb[znamed] tc[2][nobd][2][nozd] = zd # base de fond : interpolee depuis ses zones voisines + zones proches corps # les donneurs proches corps mobiles sont deja deplaces # intersectionsDict = X.getIntersectingDomains(tBBloc,t2=tBB,method='AABB',taabb=tBBloc,taabb2=tBB) for zr in Internal.getZones(tloc): znamer = zr[0] if znamer not in listOfSteadyOffBodyZones: donorZones = [] hooks = [] for znamed in intersectionsDictOffOff[ znamer]: # donneur=maillage de fond nozd = dictOfOffBodyZoneNb[znamed] zd = tc[2][noBaseOff][2][nozd] if znamed not in dictOfOffBodyADT: hook0 = C.createHook(zd, 'adt') dictOfOffBodyADT[znamed] = hook0 hooks.append(dictOfOffBodyADT[znamed]) donorZones.append(zd) for znamed in intersectionsDictOffNB[znamer]: nozd = dictOfNearBodyZoneNb[znamed] nobd = dictOfNearBodyBaseNb[znamed] zd = tc[2][nobd][2][nozd] if znamed not in dictOfMotionADT: hook0 = C.createHook(zd, 'adt') dictOfMotionADT[znamed] = hook0 hooks.append(dictOfMotionADT[znamed]) donorZones.append(zd) # print 'Off-body motion zone %s'%znamer donorZones = X.setInterpData(zr,donorZones,nature=1,penalty=1,loc='centers',storage='inverse',sameName=1,\ hook=hooks, itype='chimera') for zd in donorZones: znamed = zd[0] if znamed in dictOfOffBodyZoneNb: nozd = dictOfOffBodyZoneNb[znamed] tc[2][noBaseOff][2][nozd] = zd elif znamed in dictOfNearBodyZoneNb: nozd = dictOfNearBodyZoneNb[znamed] nobd = dictOfNearBodyBaseNb[znamed] tc[2][nobd][2][nozd] = zd for dnrname in dictOfMotionADT: C.freeHook(dictOfMotionADT[dnrname]) # Reinit if NIT == 1: for dnrname in dictOfOffBodyADT: C.freeHook(dictOfOffBodyADT[dnrname]) C._rmVars(tc, [ "CoordinateX", "CoordinateY", "CoordinateZ", "cellNInit", "CoordinateXInit", "CoordinateYInit", "CoordinateZInit" ]) C._initVars(t, '{CoordinateX}={CoordinateXInit}') C._initVars(t, '{CoordinateY}={CoordinateYInit}') C._initVars(t, '{CoordinateZ}={CoordinateZInit}') C._rmVars(t, [ "centers:cellNInit", "CoordinateXInit", "CoordinateYInit", "CoordinateZInit" ]) C._cpVars(tc, "cellN", t, 'centers:cellN') return t, tc else: for zc in Internal.getZones(tc): IDatas = Internal.getNodesFromName(zc, "ID_*") for ID in IDatas: name = ID[0].split('_') ID[0] = 'ID#%d_%s' % (it, name[1]) if it == 5: C.convertPyTree2File(t, "t5.cgns") C.convertPyTree2File(tc, "tc5.cgns") C._initVars(tc[2][noBaseOff], "{cellN}={cellNInit}") # reinit C._initVars(t[2][noBaseOff], "{centers:cellN}={centers:cellNInit}") # reinit C._initVars(tc, '{CoordinateX}={CoordinateXInit}') C._initVars(tc, '{CoordinateY}={CoordinateYInit}') C._initVars(tc, '{CoordinateZ}={CoordinateZInit}') C._initVars(t, '{CoordinateX}={CoordinateXInit}') C._initVars(t, '{CoordinateY}={CoordinateYInit}') C._initVars(t, '{CoordinateZ}={CoordinateZInit}') C._initVars(tBB, '{CoordinateX}={CoordinateXInit}') C._initVars(tBB, '{CoordinateY}={CoordinateYInit}') C._initVars(tBB, '{CoordinateZ}={CoordinateZInit}') for dnrname in dictOfOffBodyADT: C.freeHook(dictOfOffBodyADT[dnrname]) C._rmVars(t, [ "centers:cellNInit", "CoordinateXInit", "CoordinateYInit", "CoordinateZInit" ]) C._initVars(tc[2][noBaseOff], "{cellN}={cellNInit}") C._cpVars(tc, "cellN", t, "centers:cellN") C._rmVars( tc, ["cellNInit", "CoordinateXInit", "CoordinateYInit", "CoordinateZInit"]) return t, tc