def smooth1D(niter, eps): fail = False nzs = CPlot.getSelectedZones() for nz in nzs: nob = CTK.Nb[nz]+1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] dims = Internal.getZoneDim(z) try: if dims[0] == 'Unstructured': a = C.convertBAR2Struct(z) else: a = z a = D.getCurvilinearAbscissa(a) distrib = C.cpVars(a, 's', a, 'CoordinateX') C._initVars(distrib, 'CoordinateY', 0.) C._initVars(distrib, 'CoordinateZ', 0.) distrib = C.rmVars(distrib, 's') bornes = P.exteriorFaces(distrib) distrib = T.smooth(distrib, eps=eps, niter=niter, fixedConstraints=[bornes]) b = G.map(a, distrib) CTK.replace(CTK.t, nob, noz, b) except Exception as e: fail = True Panels.displayErrors([0,str(e)], header='Error: smooth1D') return fail
def _initConst(t, adim='adim1', MInf=None, alphaZ=0., alphaY=0., ReInf=1.e8, loc='nodes'): if MInf is None: # recuperation de reference state eq = Internal.getNodeFromName(t, 'GoverningEquations') state = Internal.getNodeFromName(t, 'ReferenceState') if state is None: raise ValueError("initConst: no reference state and no argument.") vars0 = ['Density', 'MomentumX', 'MomentumY', 'MomentumZ', 'EnergyStagnationDensity'] if (eq is not None and Internal.getValue(eq) == 'NSTurbulent'): vars0 += ['TurbulentSANuTildeDensity', 'TurbulentEnergyKineticDensity', 'TurbulentDissipationDensity'] for v in vars0: node = Internal.getNodeFromName(state, v) if node is not None: val = Internal.getValue(node) C._initVars(t, loc+':'+v, val) else: # recuperation des arguments nodes = Internal.getZones(t) for z in nodes: a = C.getFields(Internal.__GridCoordinates__, z)[0] if loc == 'nodes': a = Initiator.initConst(a, adim, MInf, alphaZ, alphaY, ReInf) z = C.setFields([a], z, 'nodes') elif loc == 'centers': a = Converter.node2Center(a) a = Initiator.initConst(a, adim, MInf, alphaZ, alphaY, ReInf) a = Converter.rmVars(a, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) z = C.setFields([a], z, 'centers') else: raise ValueError("initConst: wrong location: %s."%loc) return None
def withOctree(a, offset, density): # step tol = 1./density # octree snears = []; sec = 0 for z in a: bb = G.bbox(z) rx = bb[3]-bb[0]; ry = bb[4]-bb[1]; rz = bb[5]-bb[2] snear = min(rx, ry); snear = min(snear, rz) snear = 0.1*snear sec = max(sec, snear) snears.append(snear) o = G.octree(a, snears, dfar=offset+sec) o = compDistance(o, a, loc='nodes') # iteration d'adaptation nit = 0 while nit < 10: print('iterating: %d...'%nit) o = C.node2Center(o, 'TurbulentDistance') o = G.getVolumeMap(o) # adapt C._initVars(o, '{centers:vol}={centers:vol}**0.33333') # was 2.1 factor C._initVars(o, '{centers:indicator}=logical_and({centers:vol} > %20.16g , abs({centers:TurbulentDistance}-%20.16g) < 1.*{centers:vol})'%(tol,offset)) o1 = G.adaptOctree(o, 'centers:indicator') #C.convertPyTree2File([o1]+a, 'out%d.cgns'%nit) # check convergence dim1 = Internal.getZoneDim(o1); dim = Internal.getZoneDim(o) if dim1 == dim: break #if (nit%2 == 0): o1 = P.extractMesh([o], o1) o1 = compDistance(o1, a, loc='nodes') o = o1 nit += 1 o = C.rmVars(o, 'centers:TurbulentDistance') o = C.rmVars(o, 'centers:vol') o = C.rmVars(o, 'centers:indicator') #C.convertPyTree2File(o, 'out.cgns') # Iso surface iso = P.isoSurfMC([o], 'TurbulentDistance', value=offset) return iso
def refineCells(): 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 W = WIDGETS['refine'] if CTK.__BUSY__ == False: CPlot.unselectAllZones() CTK.__BUSY__ = True TTK.sunkButton(W) CPlot.setState(cursor=1) while CTK.__BUSY__: l = [] while l == []: nz = CPlot.getSelectedZone() l = CPlot.getActivePointIndex() CPlot.unselectAllZones() time.sleep(CPlot.__timeStep__) W.update() if CTK.__BUSY__ == False: break if CTK.__BUSY__: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] CTK.saveTree() z = CTK.t[2][nob][2][noz] C._initVars(z, 'centers:__tag__', 0) C.setValue(z, 'centers:__tag__', l[1], 1) try: z = P.refine(z, '__tag__') CTK.replace(CTK.t, nob, noz, z) except: pass CTK.TKTREE.updateApp() CPlot.render() CTK.__BUSY__ = False TTK.raiseButton(W) CPlot.setState(cursor=0) else: CTK.__BUSY__ = False TTK.raiseButton(W) CPlot.setState(cursor=0)
def addVar(event=None): if CTK.t == []: return nzs = CPlot.getSelectedZones() varname = VARS[1].get() CTK.saveTree() s = varname.split('=') if CTK.__MAINTREE__ <= 0 or nzs == []: if len(s) > 1: C._initVars(CTK.t, varname) else: C._addVars(CTK.t, varname) else: for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] z = CTK.t[2][nob][2][noz] if len(s) > 1: C._initVars(z, varname) else: C._addVars(z, varname) CTK.TXT.insert('START', 'Variable %s added.\n' % varname) CTK.TKTREE.updateApp() CTK.display(CTK.t) if CTK.TKPLOTXY is not None: CTK.TKPLOTXY.updateApp()
def initSolution(): if CTK.t == []: return CTK.saveTree() state = Internal.getNodeFromType(CTK.t, 'ReferenceState_t') if state is None: CTK.TXT.insert('START', 'state is missing (tkState).\n') CTK.TXT.insert('START', 'Error: ', 'Error'); return # Check for GoverningEquations eqs = Internal.getNodeFromType(CTK.t, 'GoverningEquations_t') Model = 'NSTurbulent' if eqs is not None: Model = Internal.getValue(eqs) vars = ['Density', 'MomentumX', 'MomentumY', 'MomentumZ', 'EnergyStagnationDensity'] for v in vars: node = Internal.getNodeFromName(state, v) if node is not None: val = float(node[1][0]) C._initVars(CTK.t, 'centers:'+v, val) else: CTK.TXT.insert('START', v + ' is missing (tkState).\n') CTK.TXT.insert('START', 'Error: ', 'Error') return if Model == 'NSTurbulent': vars = ['TurbulentSANuTildeDensity', 'TurbulentEnergyKineticDensity', 'TurbulentDissipationDensity'] for v in vars: node = Internal.getNodeFromName(state, v) if node is not None: val = float(node[1][0]) C._initVars(CTK.t, 'centers:'+v, val) CTK.TXT.insert('START', 'Solution initialized.\n') CTK.TKTREE.updateApp() CTK.display(CTK.t)
def initCellN(): if CTK.t == []: return type = VARS[8].get() CTK.saveTree() nzs = CPlot.getSelectedZones() if CTK.__MAINTREE__ <= 0 or nzs == []: if type == 'node_in': C._initVars(CTK.t, 'cellN', 1.) else: C._initVars(CTK.t, 'centers:cellN', 1.) else: for nz in nzs: nob = CTK.Nb[nz] + 1 noz = CTK.Nz[nz] if type == 'node_in': C._initVars(CTK.t[2][nob][2][noz], 'cellN', 1) else: C._initVars(CTK.t[2][nob][2][noz], 'centers:cellN', 1.) #C._fillMissingVariables(CTK.t) CTK.TXT.insert('START', 'cellN variable init to 1.\n') CTK.TKTREE.updateApp() CTK.display(CTK.t)
def setProcField(): if CTK.t == []: return CTK.saveTree() zones = Internal.getZones(CTK.t) for z in zones: param = Internal.getNodesFromName(z, '.Solver#Param') if param != []: nodes = Internal.getNodesFromName1(param[0], 'proc') (r, c) = Internal.getParentOfNode(CTK.t, z) if nodes != []: value = nodes[0][1][0, 0] C._initVars(z, 'proc', value) else: C._initVars(z, 'proc', -1.) else: C._initVars(z, 'proc', -1.) CTK.TXT.insert('START', 'Field proc set.\n') CTK.TKTREE.updateApp() CTK.display(CTK.t)
# - buildMaskFiles (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Connector.PyTree as X import Converter.elsAProfile as elsAProfile a = G.cart((-1.,-1.,-1.),(0.1,0.1,0.1), (20,20,20)) t = C.newPyTree(['Cart',a]) C._initVars(t, 'centers:cellN=({centers:CoordinateX}>0.)') t = X.cellN2OversetHoles(t) C.convertPyTree2File(t,"in.cgns") tp = elsAProfile.buildMaskFiles(t,keepOversetHoles=False, prefixBase=True) C.convertPyTree2File(tp, 'out.cgns')
# - addTurbulentDistanceIndex (pyTree) - import Generator.PyTree as G import Converter.PyTree as C import Converter.elsAProfile as CE import KCore.test as test import Converter.Internal as Internal Internal.__FlowSolutionCenters__ = 'FlowSolution#Init' a = G.cart((0., 0., 0.), (0.1, 0.1, 0.1), (10, 10, 10)) t = C.newPyTree(['Base', a]) C._initVars(t, 'centers:TurbulentDistance', 1.) tp = CE.addTurbulentDistanceIndex(t) test.testT(tp, 1) #in place CE._addTurbulentDistanceIndex(t) test.testT(t, 2)
# - deform (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T a = G.cart((0.,0.,0.),(1.,1.,1.),(10,10,10)) C._initVars(a,'dx', 10.) C._initVars(a,'dy', 0) C._initVars(a,'dz', 0) b = T.deform(a) C.convertPyTree2File(b, 'out.cgns')
def F(x, y, z): deg = 1 if deg == 0: return 10. elif deg == 1: return x + 2. * y + 3. * z elif deg == 2: return x * x + 2. * y * y + 3 * z elif deg == 3: return x * x * y + 2. * y * y * y + 3 * z elif deg == 4: return x * x * x * x + 2. * y * y * y * y + z * z else: return 2 * x * x * x * x * x + 2. * y * y * z + z * z # Donor mesh ni = 11 nj = 11 nk = 11 m = G.cartNGon((0, 0, 0), (10. / (ni - 1), 10. / (nj - 1), 1), (ni, nj, nk)) C._initVars(m, '{F}={CoordinateX}+2*{CoordinateY}+3*{CoordinateZ}') C._initVars(m, '{G}=10*{CoordinateX}') C._initVars(m, 'centers:G', 1.) # Receiver mesh a = G.cart((0, 0, 0), (10. / (ni - 1), 10. / (nj - 1), 1), (ni, nj, nk)) a[0] = 'extraction' C._initVars(a, 'F', -1000.) C._initVars(a, 'G', -1000.) # 2nd order, nodes, direct storage t = C.newPyTree(['Rcv', 'Dnr']) t[2][1][2] = [a] t[2][2][2] = [m] C._initVars(t[2][1], 'cellN', 2) t[2][2] = X.setInterpData(t[2][1], t[2][2],
import Post.PyTree as P import Generator.PyTree as G import KCore.test as test def F(x, y, z): return 12 * y * y + 4 #----- # 2D #----- ni = 30 nj = 40 m = G.cart((0, 0, 0), (10. / (ni - 1), 10. / (nj - 1), 1), (ni, nj, 1)) C._initVars(m, 'F1', F, ['CoordinateX', 'CoordinateY', 'CoordinateZ']) C._addVars(m, 'F2') C._addVars(m, 'F3') varname = ['F1', 'F2', 'F3'] m = P.computeCurl(m, varname) C._initVars(m, 'centers:F4', F, ['centers:rotx', 'centers:roty', 'centers:rotz']) C._addVars(m, 'centers:F5') C._addVars(m, 'centers:F6') m = C.addBC2Zone(m, 'ov', 'BCOverlap', 'imin') t = C.newPyTree(['Base', 2, m]) t[2][1] = C.addState(t[2][1], 'Mach', 0.6) varname = ['centers:F4', 'centers:F5', 'centers:F6'] t = P.computeCurl(t, varname) test.testT(t, 2)
# - dist2WallsEikonal (pyTree) - import Converter.PyTree as C import Connector.PyTree as X import Converter.Internal as Internal import Dist2Walls.PyTree as DTW import Geom.PyTree as D import Generator.PyTree as G import numpy DEPTH = 2 snear = 0.4; vmin = 21 # Init wall body = D.circle((0,0,0),1.,N=60) res = G.octree([body],[snear], dfar=5., balancing=1) res = G.octree2Struct(res, vmin=vmin, ext=DEPTH+1,merged=1) t = C.newPyTree(['Base']); t[2][1][2] = res # Mark solid and fluid points t = X.applyBCOverlaps(t,depth=DEPTH,loc='nodes') tc = Internal.copyRef(t) tc = X.setInterpData(t,tc,loc='nodes',storage="inverse") C._initVars(t,"cellN",1.) t = X.blankCells(t, [[body]], numpy.array([[1]]), blankingType='node_in') t = X.setHoleInterpolatedPoints(t,depth=1,loc='nodes') C._initVars(t,'flag=({cellN}>1.)') t = DTW.distance2WallsEikonal(t,body,tc=tc,DEPTH=DEPTH,nitmax=10) C.convertPyTree2File(t, 'out.cgns')
# - getMaxValue (pyTree) - import Converter.PyTree as C import Generator.PyTree as G a = G.cart((0,0,0), (1.,1.,1.), (11,2,2)) C._initVars(a, 'centers:F={centers:CoordinateX}') maxval = C.getMaxValue(a, 'CoordinateX'); print maxval #>> 10.0 maxval = C.getMaxValue(a, 'centers:F'); print maxval #>> 9.5 maxval = C.getMaxValue(a, ['CoordinateX', 'CoordinateY']); print maxval #>> [10.0, 1.0] maxval = C.getMaxValue(a, 'GridCoordinates'); print maxval #>> [10.0, 1.0, 1.0]
# - 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]) t = C.newPyTree(['Base',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)) 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]) t = C.newPyTree(['Base',2,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) # TETRA a = G.cartTetra((0,0,0), (1,1,1), (10,10,3)) C._addVars(a, 'Density'); C._initVars(a, 'centers:cellN', 1)
#!/usr/bin/env python # coding: utf-8 r"""nurbs (pyTree)""" import Geom.PyTree as D import Converter.PyTree as C import Generator.PyTree as G ni = 10 nj = 10 a = G.cart((0, 0, 0), (1, 1, 1), (ni, nj, 1)) C._initVars(a, 'weight', 1.) C.setValue(a, 'weight', (7, 1, 1), 7.) C.setValue(a, 'weight', (9, 5, 1), 9.) d = D.nurbs(a, 'weight', 4, 100, 100) C.convertPyTree2File(d, 'out.cgns') a = D.polyline([(4.1, 0.1, 1.1), (1.1, 0.2, 1.2), (1.1, 1.3, 1.3), (1.1, 1.5, 1.4), (4.5, 2.5, 1.5), (5.6, 1.5, 1.6), (6.7, 1.7, 1.7), (7.8, 0.8, 1.8), (8.9, -1.9, 1.9), (9, 0, 1)]) a = C.initVars(a, 'weight', 1.) C.setValue(a, 'weight', (7, 1, 1), 7.) C.setValue(a, 'weight', (9, 1, 1), 9.)
import KCore.test as test DEPTH = 2 snear = 0.4 vmin = 21 # Init wall body = D.circle((0, 0, 0), 1., N=60) res = G.octree([body], [snear], dfar=5., balancing=1) res = G.octree2Struct(res, vmin=vmin, ext=DEPTH + 1, merged=1) t = C.newPyTree(['Base', res]) # Mark solid and fluid points X._applyBCOverlaps(t, depth=DEPTH, loc='nodes') tc = Internal.copyRef(t) tc = X.setInterpData(t, tc, loc='nodes', storage="inverse") C._initVars(t, "cellN", 1.) t = X.blankCells(t, [[body]], numpy.array([[1]]), blankingType='node_in') X._setHoleInterpolatedPoints(t, depth=1, loc='nodes') C._initVars(t, '{flag}=({cellN}>1.)') t = DTW.distance2WallsEikonal(t, body, tc=tc, DEPTH=DEPTH, nitmax=10) test.testT(t, 1) # aux centres t = C.newPyTree(['Base']) t[2][1][2] = res Internal._rmNodesFromName(t, "FlowSolution") # Mark solid and fluid points X._applyBCOverlaps(t, depth=DEPTH, loc='centers') tc = C.node2Center(t) tc = X.setInterpData(t, tc, loc='centers', storage="inverse") C._initVars(t, "centers:cellN", 1.) t = X.blankCells(t, [[body]], numpy.array([[1]]), blankingType='center_in')
# - splitNParts (pyTree) - import Generator.PyTree as G import Transform.PyTree as T import Converter.PyTree as C import KCore.test as test # Structure + Champs + CL a = G.cart((0, 0, 0), (1, 1, 1), (50, 20, 10)) a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin') a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2, 3]) C._addVars(a, 'Density') C._initVars(a, 'centers:cellN', 1) t = C.newPyTree(['Base', a]) t = T.splitNParts(t, 4, multigrid=0, dirs=[1, 2, 3]) test.testT(t, 1) # 2D Structure + Champs + CL a = G.cart((0, 0, 0), (1, 1, 1), (50, 20, 2)) a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin') a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2]) C._addVars(a, 'Density') C._initVars(a, 'centers:cellN', 1) t = C.newPyTree(['Base', 3, a]) t = T.splitNParts(t, 4, multigrid=0, dirs=[1, 2, 3]) test.testT(t, 2) a = G.cart((0, 0, 0), (1, 1, 1), (81, 81, 81)) b = G.cart((80, 0, 0), (1, 1, 1), (41, 81, 41)) t = C.newPyTree(['Base', a, b])
# - display1D (pyTree) - import Generator.PyTree as G import CPlot.PyTree as CPlot import Converter.PyTree as C import numpy # 1D data defined in zones b = G.cart((0,0,0), (0.1,1,1), (50,1,1)) c = G.cart((5,0,0), (0.1,1,1), (50,1,1)) B = [b, c] CPlot.setState(gridSize=(1,2)) for i in xrange(100): C._initVars(B, 'f=sin({CoordinateX}+0.01*%d)'%i) C._initVars(B, 'g={CoordinateX}') CPlot.display1D(B, slot=0, bgBlend=1., gridPos=(0,0), var1='CoordinateX', var2='f') # 1D data defined in numpys import numpy x = numpy.linspace(0, 2*numpy.pi) y = numpy.sin(x) CPlot.display1D([x,y], slot=1, var1='x', var2='y', gridPos=(0,1), bgBlend=0.8)
# - blankIntersectingCells (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Geom.PyTree as D import Connector.PyTree as X import KCore.test as test import Transform.PyTree as T body = D.sphere6((0,0,0),1.,10) body = T.reorder(body,(-1,2,3)) dh = G.cart((0,0,0),(0.1,1,1),(10,1,1)) a = G.addNormalLayers(body,dh,niter=0) C._initVars(a,'centers:cellN',1.) C._initVars(a,'F',2.) a = C.addBC2Zone(a, 'wall1', 'BCWall', 'kmin') a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'kmax' ) t = C.newPyTree(['Base',a]) t2 = X.blankIntersectingCells(t, depth=1) test.testT(t2,1)
# - computeWallShearStress (pyTree) - import Generator.PyTree as G import Converter.PyTree as C import Transform.PyTree as T import Post.PyTree as P import KCore.test as test a = G.cart((0, 0, 0), (1, 1, 1), (50, 50, 1)) t = C.newPyTree(['Base', a]) C._addState(t, state='EquationDimension', value=3) C._addState(t, adim='adim1') C._initVars(t, '{VelocityX}=0.2*{CoordinateX}**2') C._initVars(t, '{VelocityY}=0.3*{CoordinateY}*{CoordinateX}') C._initVars(t, 'VelocityZ', 0.) for var in ['VelocityX', 'VelocityY', 'VelocityZ']: t = P.computeGrad(t, var) t = C.node2Center(t, var) C._initVars(t, 'centers:Density', 1.) C._initVars(t, 'centers:EnergyStagnationDensity', 1.) C._initVars(t, 'centers:Temperature', 1.) tw = P.computeWallShearStress(t) test.testT(tw, 1) # t = C.newPyTree(['Base', a]) C._addState(t, state='EquationDimension', value=3) C._addState(t, adim='adim1') C._initVars(t, '{VelocityX}=0.2*{CoordinateX}**2') C._initVars(t, '{VelocityY}=0.3*{CoordinateY}*{CoordinateX}') C._initVars(t, 'VelocityZ', 0.) for var in ['VelocityX', 'VelocityY', 'VelocityZ']: t = P.computeGrad(t, var)
# - reorder (pyTree) - import Generator.PyTree as G import Transform.PyTree as T import Converter.PyTree as C import KCore.test as test a = G.cylinder((0.,0.,0.), 0.1, 1., 0., 45., 5., (11,11,11)) C._initVars(a,'F',1.); C._initVars(a,'centers:G',2.) a = C.addBC2Zone(a,'wall','BCWall','jmin') a = C.addBC2Zone(a,'overlap','BCOverlap','jmax') b = G.cylinder((0.,0.,0.), 0.1, 1., 45., 90., 5., (11,11,11)); b[0] = 'cyl2' C._initVars(b,'F',1.); C._initVars(b,'centers:G',2.) b = C.addBC2Zone(b,'wall','BCWall','jmin') b = C.addBC2Zone(b,'overlap','BCOverlap','jmax') a = C.addBC2Zone(a, 'match', 'BCMatch', [11,11,1,11,1,11], zoneDonor=b, rangeDonor=[1,1,1,11,1,11], trirac=[1,2,3]) b = C.addBC2Zone(b, 'match', 'BCMatch', [1,1,1,11,1,11], zoneDonor=a, rangeDonor=[11,11,1,11,1,11], trirac=[1,2,3]) t = C.newPyTree(['Base']); t[2][1][2] += [a,b] t[2][1] = C.addState(t[2][1], 'EquationDimension', 3) # # reorder l arbre t2 = T.reorder(t,(-1,2,3)) test.testT(t2,1) # # reorder une zone et ne rend pas coherent le reste de l arbre t[2][1][2][0] = T.reorder(t[2][1][2][0],(-1,-2,3)) test.testT(t,2) # reorder une zone et rend coherent le reste de l'arbre a = G.cylinder((0.,0.,0.), 0.1, 1., 0., 45., 5., (11,11,11)) C._initVars(a,'F',1.); C._initVars(a,'centers:G',2.) a = C.addBC2Zone(a,'wall','BCWall','jmin')
# - cas 2D - import Converter.PyTree as C import Connector.PyTree as X import Generator.PyTree as G import Geom.PyTree as D import KCore.test as test surf = D.circle((0,0,0), 0.5, 20) a = G.cart((-1.,-1.,0.),(0.1,0.1,1), (20,20,1)) C._addBC2Zone(a, 'ov', 'BCOverlap', 'jmin') t = C.newPyTree(['Cart',2,a]) t[2][1] = C.addState(t[2][1], 'EquationDimension', 2) C._fillEmptyBCWith(t, 'wall', 'BCWall') C._addVars(t, 'Density') C._initVars(t, 'centers:cellN', 1.) bodies = [[surf]] criterions = ['cell_intersect', 'cell_intersect_opt', 'center_in'] # Matrice de masquage (arbre d'assemblage) import numpy BM = numpy.array([[1]]) c = 1 for delta in [0.,0.1]: for type in criterions: if (type == 'cell_intersect_opt' and delta > 0): c += 1 else: t2 = X.blankCells(t, bodies, BM, blankingType=type, delta=delta, dim=2) test.testT(t2,c) c += 1
# - moveCamera (pyTree) - import Geom.PyTree as D import CPlot.PyTree as CPlot import Converter.PyTree as C import Transform.PyTree as T import Generator.PyTree as G # Model a = D.sphere((0, 0, 0), 1., N=20) a = C.convertArray2Hexa(a) a = G.close(a) CPlot.display(a, posCam=(3, -1, 0.7), posEye=(0, 0, 0)) t = 0. for i in range(1000): # change model C._initVars(a, '{df}=0.1*cos(%f)*sin(10*pi*{CoordinateX})' % (t)) b = T.deformNormals(a, 'df') # Move camera CPlot.moveCamera([(3, -1, 0.7), (3, 5, 0.7), (3, 7, 0.7)], N=1000, pos=i) CPlot.display(b) t += 0.05
# - selectCells3 (pyTree) - import Generator.PyTree as G import Converter.PyTree as C import Post.PyTree as P a = G.cartNGon( (0,0,0), (1,1,1), (10,10,10) ) C._initVars(a, 'centers:F={centers:CoordinateX}') C._initVars(a, 'centers:tag=0.1*{centers:CoordinateX}+0.1*{centers:CoordinateY}') #p = P.post.selectCells3(b, 0) #print p p = P.selectCells3(a, 'centers:tag') C.convertPyTree2File(p, 'out.cgns')
# #---------- # # 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 nj = 15 nk = 15 m1 = G.cart((0, 0, 0), (10. / (ni - 1), 10. / (nj - 1), 2. / (nk - 1)),
# - importVariables (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Post.PyTree as P import Converter.Internal as Internal import KCore.test as test # z2 sans solutions z1 = G.cart((0., 0., 0.), (0.1, 0.1, 0.1), (3, 3, 3)) C._addBC2Zone(z1, 'overlap', 'BCOverlap', 'imin') C._fillEmptyBCWith(z1, 'nref', 'BCFarfield') t1 = C.newPyTree(['Base', z1]) t2 = Internal.copyRef(t1) C._initVars(t1, 'centers:cellN', 1.) C._initVars(t1, 'Pressure', 10.) C._initVars(t1, 'Density', 1.) C._addState(t1[2][1], 'Mach', 0.6) C._addState(t2[2][1], 'Mach', 0.6) t2 = P.importVariables(t1, t2) test.testT(t2, 1) # z2 avec cellN = 0 C._initVars(t2, 'centers:cellN', 0.) t2 = P.importVariables(t1, t2) test.testT(t2, 2) # z1 en centres avec z2 sans solution Internal._rmNodesByType(t2, 'FlowSolution_t') t1 = C.node2Center(t1) t2 = P.importVariables(t1, t2) test.testT(t2, 3)
# - deform (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import Transform.PyTree as T import KCore.test as test # Zone structuree a = G.cart((0., 0., 0.), (1., 1., 1.), (10, 10, 2)) a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin') a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmin') a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imax', a, 'imin', [1, 2, 3]) C._addVars(a, 'F') C._addVars(a, 'centers:G') vect = ['hx', 'hy', 'hz'] C._addVars(a, vect) C._initVars(a, 'hx', 10.) a = T.deform(a, vect) test.testT(a, 1) # Zone non structuree a = G.cartTetra((0., 0., 0.), (1., 1., 1.), (10, 10, 2)) C._addVars(a, 'F') C._addVars(a, 'centers:G') vect = ['hx', 'hy', 'hz'] C._addVars(a, vect) C._initVars(a, 'hx', 10.) a = T.deform(a, vect) test.testT(a, 2) # Arbre a = G.cart((0., 0., 0.), (1., 1., 1.), (10, 10, 1))
import Converter.Internal as Internal import Dist2Walls.PyTree as DTW import Geom.PyTree as D import Generator.PyTree as G import numpy DEPTH = 2 # Bloc cartesien N = 128; h = 0.1 a = G.cart((0.,0.,0.),(h,h,h),(N,N,1)) # Init wall sphere = D.sphere((6.4,6.4,0), 1., 100) sphere = C.convertArray2Tetra(sphere) sphere = G.close(sphere) t = C.newPyTree(['Base']); t[2][1][2] = [a]; C._initVars(t,'cellN=1') t = X.blankCellsTri(t, [[sphere]], numpy.array([[1]]), blankingType='node_in') # Condition aux limites t = X.setHoleInterpolatedPoints(t,depth=1,loc='nodes') C._initVars(t,'flag=({cellN}>1.)') t = DTW.distance2WallsEikonal(t,sphere,DEPTH=DEPTH,nitmax=10) C.convertPyTree2File(t, 'out.cgns') # Bloc cartesien N = 64; h = 0.2 a = G.cart((0.,0.,0.),(h,h,h),(N,N,1)); a[0] = 'cart2' # Init wall sphere = D.sphere((6.4,6.4,0), 1., 100) sphere = C.convertArray2Tetra(sphere) sphere = G.close(sphere) t = C.newPyTree(['Base']); t[2][1][2] = [a]