示例#1
0
def drawCubic(npts):
    global CURRENTZONE; global CURRENTPOLYLINE
    if (CTK.t == []): return
    w = WIDGETS['draw']
    if (CTK.__BUSY__ == False):
        CPlot.unselectAllZones()
        CTK.saveTree()
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while (CTK.__BUSY__ == True):
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                CPlot.unselectAllZones()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if (CTK.__BUSY__ == True):
                CURRENTPOLYLINE.append((l[0],l[1],l[2]))
                if (CURRENTZONE == None):
                    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
                    base = Internal.getNodeFromName1(CTK.t, 'CONTOURS')
                    nob = C.getNobOfBase(base, CTK.t)
                    a = D.polyline(CURRENTPOLYLINE)
                    CURRENTZONE = a
                    CTK.add(CTK.t, nob, -1, a)
                    ret = Internal.getParentOfNode(CTK.t, CURRENTZONE)
                    noz = ret[1]
                else:
                    a = D.polyline(CURRENTPOLYLINE)
                    CURRENTZONE = a
                    CTK.replace(CTK.t, nob, noz, a)
                (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                CTK.TKTREE.updateApp()
                CPlot.render()
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       ret = Internal.getParentOfNode(CTK.t, CURRENTZONE)
       a = D.polyline(CURRENTPOLYLINE)
       d = G.cart( (0,0,0), (1./(npts-1),1,1), (npts,1,1) )
       a = G.map(a, d)
       surfaces = getSurfaces()
       if (surfaces != []): a = T.projectOrthoSmooth(a, surfaces)
       nob = C.getNobOfBase(ret[0], CTK.t)
       CTK.replace(CTK.t, nob, ret[1], a)
       #C._fillMissingVariables(CTK.t)
       (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
       CTK.TKTREE.updateApp()
       CPlot.render()
       CURRENTZONE = None
       CURRENTPOLYLINE = []
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
示例#2
0
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]
def extrudeWCurve(mode=0):
    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
    # - curve -
    name = VARS[3].get()
    names = name.split(';')
    curve = []
    for v in names:
        v = v.lstrip()
        v = v.rstrip()
        sname = v.split('/', 1)
        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]: curve.append(z)
    if len(curve) == 0:
        CTK.TXT.insert('START', 'Curve is incorrect.\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()
    fail = False
    errors = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        try:
            if mode == 0: z = D.lineDrive(z, curve)
            else: z = D.orthoDrive(z, curve)
            CTK.replace(CTK.t, nob, noz, z)
        except Exception as e:
            fail = True
            errors += [0, str(e)]

    if not fail:
        CTK.TXT.insert('START', 'Mesh extruded with curve(s).\n')
    else:
        Panels.displayErrors(errors, header='Error: extrusion')
        CTK.TXT.insert('START', 'Extrusion fails for at least one zone.\n')
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
示例#4
0
def createText(event=None):
    CTK.saveTree()
    text = VARS[0].get()
    type = VARS[1].get()
    font = VARS[3].get()

    smoothness = VARS[2].get()
    smooth = 0
    if smoothness == 'Regular': smooth = 0
    elif smoothness == 'Smooth': smooth = 2
    elif smoothness == 'Very smooth': smooth = 4
    CTK.t = C.addBase2PyTree(CTK.t, 'TEXT', 3)
    nodes = Internal.getNodesFromName1(CTK.t, 'TEXT')
    base = nodes[0]
    if type == '3D': a = D.text3D(text, smooth=smooth, font=font)
    elif type == '2D': a = D.text2D(text, smooth=smooth, font=font)
    elif type == '1D':
        a = D.text1D(text, smooth=smooth, font=font)
        a = C.convertArray2Tetra(a)
        a = T.join(a)

    # Modification de l'angle, de la position et de la taille du texte
    # en fonction du point de vue
    posCam = CPlot.getState('posCam')
    posEye = CPlot.getState('posEye')
    dirCam = CPlot.getState('dirCam')
    BB = G.bbox(a)
    xc = 0.5 * (BB[3] + BB[0])
    yc = 0.5 * (BB[4] + BB[1])
    zc = 0.5 * (BB[5] + BB[2])
    a = T.translate(a, (posEye[0] - xc, posEye[1] - yc, posEye[2] - zc))
    lx = posEye[0] - posCam[0]
    ly = posEye[1] - posCam[1]
    lz = posEye[2] - posCam[2]
    if (lx * lx + ly * ly + lz * lz == 0.): lx = -1
    if (dirCam[0] * dirCam[0] + dirCam[1] * dirCam[1] +
            dirCam[2] * dirCam[2] == 0.):
        dirCam = (0, 0, 1)
    ll = math.sqrt(lx * lx + ly * ly + lz * lz)
    a = T.homothety(a, (posEye[0], posEye[1], posEye[2]), 0.01 * ll)
    ux = dirCam[1] * lz - dirCam[2] * ly
    uy = dirCam[2] * lx - dirCam[0] * lz
    uz = dirCam[0] * ly - dirCam[1] * lx
    a = T.rotate(a, (posEye[0], posEye[1], posEye[2]),
                 ((1, 0, 0), (0, 1, 0), (0, 0, 1)),
                 ((-ux, -uy, -uz), dirCam, (lx, ly, lz)))

    nob = C.getNobOfBase(base, CTK.t)
    CTK.add(CTK.t, nob, -1, a)
    #C._fillMissingVariables(CTK.t)
    CTK.TXT.insert('START', 'Text created.\n')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
示例#5
0
def createTools():
    global TOOLS
    if TOOLS != []: return  # deja crees
    # square
    P0 = (0, 0, 0)
    # pointe
    P0 = (0, 0, 0)
    P1 = (-1, -1, 1)
    P2 = (-1, 1, 1)
    P3 = (-1, 1, -1)
    P4 = (-1, -1, -1)
    t1 = D.triangle(P0, P1, P2)
    t2 = D.triangle(P0, P2, P3)
    t3 = D.triangle(P0, P3, P4)
    t4 = D.triangle(P0, P4, P1)
    t = T.join([t1, t2, t3, t4])
    t = G.close(t)
    TOOLS.append(t)
    # biseau horizontal
    P0 = (0, -1, 0)
    P1 = (0, 1, 0)
    P1 = (-1, -1, 1)
    P2 = (-1, 1, 1)
    P3 = (-1, 1, -1)
    P4 = (-1, -1, -1)
    t1 = D.triangle(P0, P1, P2)
    t2 = D.triangle(P0, P2, P3)
    t3 = D.triangle(P0, P3, P4)
    t4 = D.triangle(P0, P4, P1)
    t = T.join([t1, t2, t3, t4])
    t = G.close(t)
    # biseau vertical
    # pointe spherique
    return TOOLS
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
示例#7
0
def submenu(items):
    import Geom.PyTree  as D
    import Transform.PyTree as T
    import Converter.PyTree as C
    nitems = len(items)
    out =  []; c = 0
    for i in items:
        a = D.text2D(i)
        CPlot._addRender2Zone(a, color='White')
        T._translate(a, (0,-c,0))
        out.append(a)
        c += 10
    t = C.newPyTree(['Base']); t[2][1][2] += out
    CPlot.display(t, mode='Render')
    CPlot.setState(activateShortCuts=0)
    current = 0
    go = True; l = ''
    while go:  
        while l == '':
            l = CPlot.getKeyboard(); time.sleep(dt)
        v = ord(l[0]); print(v)
        if v == 1: # up 
            b = CPlot.addRender2Zone(out[current], color='White')
            CPlot.replace(t, 1, current, b)
            current -= 1
            if current < 0: current = nitems-1
            b = CPlot.addRender2Zone(out[current], color='Red')
            CPlot.replace(t, 1, current, b)
            CPlot.render()
        elif v == 2: # down
            b = CPlot.addRender2Zone(out[current], color='White')
            CPlot.replace(t, 1, current, b)
            current += 1
            if current >= nitems: current = 0
            b = CPlot.addRender2Zone(out[current], color='Red')
            CPlot.replace(t, 1, current, b)
            CPlot.render()
        elif v == 3:
            b = CPlot.addRender2Zone(out[current], color='White')
            CPlot.replace(t, 1, current, b)
            current -= 1
            if current < 0: current = nitems-1
            b = CPlot.addRender2Zone(out[current], color='Red')
            CPlot.replace(t, 1, current, b)
            CPlot.render()
        elif v == 4:
            b = CPlot.addRender2Zone(out[current], color='White')
            CPlot.replace(t, 1, current, b)
            current += 1
            if current >= nitems: current = 0
            b = CPlot.addRender2Zone(out[current], color='Red')
            CPlot.replace(t, 1, current, b)
            CPlot.render()
        elif v == 13: 
            print('returning %s.'%str(current))
            return current, items[current]   
        time.sleep(dt)
        l = ''; v = -1; CPlot.resetKeyboard()
示例#8
0
def drawLine(npts):
    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
    nodes = Internal.getNodesFromName1(CTK.t, 'CONTOURS')
    nob = C.getNobOfBase(nodes[0], CTK.t)
    CTK.TXT.insert('START', 'Click first point...\n')
    prev = []
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        TTK.sunkButton(WIDGETS['draw'])
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            CTK.saveTree()
            surfaces = getSurfaces()
            l = []
            while l == []:
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                WIDGETS['draw'].update()
                if CTK.__BUSY__ == False: break
            if CTK.__BUSY__:
                if prev == []:
                    prev = l
                    CTK.TXT.insert('START', 'Click second point...\n')
                elif (prev != l):
                    line = D.line(prev, l, npts)
                    if surfaces != []: line = T.projectOrthoSmooth(line, surfaces)
                    CTK.add(CTK.t, nob, -1, line)
                    CTK.TXT.insert('START', 'Line created.\n')
                    CTK.__BUSY__ = False
                    TTK.raiseButton(WIDGETS['draw'])
                    #C._fillMissingVariables(CTK.t)
                    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                    CTK.TKTREE.updateApp()
                    CPlot.render()
                    CPlot.setState(cursor=0)
                    prev = []
                    return
        CTK.__BUSY__ = False
        TTK.raiseButton(WIDGETS['draw'])
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       TTK.raiseButton(WIDGETS['draw'])
       CPlot.setState(cursor=0)
    return
示例#9
0
def createPoint(event=None):
    point = CTK.varsFromWidget(VARS[0].get(), type=1)
    if len(point) != 3:
        CTK.TXT.insert('START', 'Point coords are incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    CTK.saveTree()
    CTK.t = C.addBase2PyTree(CTK.t, 'POINTS', 1)
    base = Internal.getNodesFromName1(CTK.t, 'POINTS')
    base = base[0]
    nob = C.getNobOfBase(base, CTK.t)
    a = D.point((point[0], point[1], point[2]))
    CTK.add(CTK.t, nob, -1, a)
    CTK.TXT.insert('START', 'Point ' + VARS[0].get() + ' created.\n')
    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
示例#10
0
def uniformize1D(density, npts, factor):
    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); np = dims[1]
            else: a = z; np = dims[1]*dims[2]*dims[3]
            if density > 0: npts = D.getLength(a)*density
            if factor > 0: npts = np*factor[0]
            npts = int(max(npts, 2))
            distrib = G.cart((0,0,0), (1./(npts-1.),1,1), (npts,1,1))
            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: uniformize1D')
    return fail
示例#11
0
# - text2D (pyTree) -
import Geom.PyTree as D
import Converter.PyTree as C
import KCore.test as test

a = D.text2D("CASSIOPEE")
t = C.newPyTree(['Base', 2])
t[2][1][2].append(a)
test.testT(t, 1)
test.writeCoverage(100)
# - deformMesh (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.PyTree as C
import Geom.PyTree as D

a1 = D.sphere6((0, 0, 0), 1, 20)
a1 = C.convertArray2Tetra(a1)
a1 = T.join(a1)
point = C.getValue(a1, 'GridCoordinates', 0)
a2 = T.deformPoint(a1, point, (0.1, 0.05, 0.2), 0.5, 2.)
delta = C.diffArrays(a2, a1)
deltax = C.getField('DCoordinateX', delta)
deltay = C.getField('DCoordinateY', delta)
deltaz = C.getField('DCoordinateZ', delta)
for noz in xrange(len(deltax)):
    deltax[noz][0] = 'dx'
    deltay[noz][0] = 'dy'
    deltaz[noz][0] = 'dz'
a1 = C.setFields(deltax, a1, 'nodes')
a1 = C.setFields(deltay, a1, 'nodes')
a1 = C.setFields(deltaz, a1, 'nodes')

m = D.sphere6((0, 0, 0), 2, 20)
m = T.deformMesh(m, a1)
C.convertPyTree2File(m, "out.cgns")
# - 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)
示例#14
0
#!/usr/bin/env python
# coding: utf-8
r"""<TBC>"""

import Generator.PyTree as G
import Converter.PyTree as C
import Transform.PyTree as T
import Geom.PyTree as D

N = 4

# Donor mesh
a = G.cart((-2, -2, -2), (0.04, 0.04, 0.04), (200, 100, 100))
a = C.initVars(a, '{Density} = {CoordinateX}')
a = T.splitNParts(a, N=3 * N)
t = C.newPyTree(['Base'])
t[2][1][2] += a
C.convertPyTree2File(t, 'donor.cgns')

# Receiver mesh
b = D.sphere((1, 1, 1), 0.5, N=100)
b = T.splitNParts(b, N=N)
t = C.newPyTree(['Base'])
t[2][1][2] += b
C.convertPyTree2File(t, 'receiver.cgns')
示例#15
0
#!/usr/bin/env python
# coding: utf-8

r"""<TBC>"""

import Generator.PyTree as G
import Converter.PyTree as C
import Transform.PyTree as T
import Geom.PyTree as D

a = G.cart((-2, -2, -2), (0.04, 0.04, 0.04), (100, 100, 100))
a = T.splitSize(a, N=100000)
b = D.sphere((0, 0, 0), 1., N=100)

t = C.newPyTree(['Base'])
t[2][1][2] += a
C.convertPyTree2File(t, 'in.cgns')
t = C.newPyTree(['Base'])
t[2][1][2] += [b]
C.convertPyTree2File(t, 'walls.cgns')
示例#16
0
# - setPrescribedMotion3 (pyTree) -
# Motion defined by a constant speed and rotation speed
import RigidMotion.PyTree as R
import Converter.PyTree as C
import Geom.PyTree as D

a = D.sphere((1.2, 0., 0.), 0.2, 30)
a = R.setPrescribedMotion3(a, 'mot', transl_speed=(1, 0, 0))

C.convertPyTree2File(a, 'out.cgns')
示例#17
0
# - mapSplit (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.PyTree as C
import Geom.PyTree as D

# polyline
a = D.polyline([(0, 0, 0), (1, 0, 0), (1, 1, 0), (2, 3, 0), (1.5, 3, 0),
                (1, 1.5, 0), (0, 0, 0)])
# distribution
Ni = 41
dist = G.cart((0, 0, 0), (1. / (Ni - 1), 1, 1), (Ni, 1, 1))
dist = G.enforceX(dist, 15.5 / (Ni - 1), 0.005, 2, 5)
dist = G.enforceX(dist, 27.5 / (Ni - 1), 0.005, 2, 5)
zones = G.mapSplit(a, dist, 0.25)
t = C.newPyTree(['Base', 1])
t[2][1][2] += zones
C.convertPyTree2File(t, 'out.cgns')
示例#18
0
# - prepareIBMData (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Connector.ToolboxIBM as IBM
import Post.PyTree as P
import Geom.PyTree as D
import Dist2Walls.PyTree as DTW
import KCore.test as test
N = 51
a = G.cart((0, 0, 0), (1. / (N - 1), 1. / (N - 1), 1. / (N - 1)), (N, N, N))
body = D.sphere((0.5, 0, 0), 0.1, N=20)
t = C.newPyTree(['Base', a])
tb = C.newPyTree(['Base', body])
tb = C.addState(tb, 'EquationDimension', 3)
tb = C.addState(tb, 'GoverningEquations', 'NSTurbulent')
t = DTW.distance2Walls(t, bodies=tb, loc='centers', type='ortho')
t = P.computeGrad(t, 'centers:TurbulentDistance')
t, tc = IBM.prepareIBMData(t, tb, DEPTH=2, frontType=1)
C.convertPyTree2File(t, 't.cgns')
C.convertPyTree2File(t, 'tc.cgns')
示例#19
0
import Generator.PyTree as G
import Transform.PyTree as T
import Connector.PyTree as X
import Geom.PyTree as D
import KCore.test as test


def f(t, u):
    x = t + u
    y = t * t + 1 + u * u
    z = u
    return (x, y, z)


# surface grid
a = D.surface(f, N=50)
b = T.splitSize(a, 100)
b = X.connectMatch(b, dim=2)
t = C.newPyTree(['Surface', 2])
t[2][1][2] += b
t = C.initVars(t, 'F', 1.)
t = C.initVars(t, 'centers:G', 2.)
t[2][1][2][0] = C.addBC2Zone(t[2][1][2][0], 'overlap', 'BCOverlap', 'imin')
t = C.fillEmptyBCWith(t, 'wall', 'BCWall', dim=2)
b = T.merge(t)
t2 = C.newPyTree(['Surface', 2])
t2[2][1][2] += b
test.testT(t2, 1)
b = T.merge(t, alphaRef=45.)
t2 = C.newPyTree(['Surface', 2])
t2[2][1][2] = b
# - snapSharpEdges (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D

# polylignes avec angles vifs
s = D.polyline([(0.02, 0, 0), (1, 1, 0), (2, 1, 0), (0.02, 0, 0)])
# Grille cartesienne (reguliere)
h = 0.1
ni = 30
nj = 20
nk = 1
b = G.cart((-0.5, -0.5, 0), (h, h, 1.), (ni, nj, nk))
b = G.snapSharpEdges(b, [s], h)
t = C.newPyTree(['Cart', 'Surface'])
t[2][1][2].append(b)
t[2][2][2].append(s)
C.convertPyTree2File(t, 'out.cgns')
示例#21
0
# - merge (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T
import Connector.PyTree as X
import Geom.PyTree as D

def f(t,u):
    x = t+u
    y = t*t+1+u*u
    z = u
    return (x,y,z)

a = D.surface(f)
b = T.splitSize(a, 100)
b = X.connectMatch(b, dim=2)
t = C.newPyTree(['Surface']); t[2][1][2] += b
b = T.merge(t)
t[2][1][2] = b
C.convertPyTree2File(t, "out.cgns")
def revolve():
    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
    # - axis -
    name = VARS[4].get()
    names = name.split(';')
    curve = []
    for v in names:
        v = v.lstrip()
        v = v.rstrip()
        sname = v.split('/', 1)
        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]: curve.append(z)
    if len(curve) == 0:
        CTK.TXT.insert('START', 'Axis is incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    teta = CTK.varsFromWidget(VARS[5].get(), type=1)
    if len(teta) != 1:
        CTK.TXT.insert('START', 'Revolve angle is incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    teta = teta[0]

    Nteta = CTK.varsFromWidget(VARS[6].get(), type=2)
    if len(Nteta) != 1:
        CTK.TXT.insert('START', 'Number of points for revolve is incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    Nteta = Nteta[0]

    # - Extrait 2 pts de l'axe -
    axis = curve[0]
    [xo, yo, zo] = C.getValue(axis, Internal.__GridCoordinates__, 0)

    dim = Internal.getZoneDim(axis)
    if dim[0] == 'Structured': np = dim[1] * dim[2] * dim[3]
    else: np = dim[1]
    [x1, y1, z1] = C.getValue(axis, Internal.__GridCoordinates__, np - 1)

    ntx = x1 - xo
    nty = y1 - yo
    ntz = z1 - zo

    # - Extrait rmod si il y en a
    if len(curve) > 1: rmod = curve[1]
    else: rmod = None

    nzs = CPlot.getSelectedZones()
    if nzs == []:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    CTK.saveTree()
    fail = False
    errors = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        try:
            z = D.axisym(z, (xo, yo, zo), (ntx, nty, ntz), teta, Nteta, rmod)
            CTK.replace(CTK.t, nob, noz, z)
        except Exception as e:
            fail = True
            errors += [0, str(e)]

    if not fail:
        CTK.TXT.insert('START', 'Mesh revolved with axis.\n')
    else:
        Panels.displayErrors(errors, header='Error: revolve')
        CTK.TXT.insert('START', 'Revolution fails for at least one zone.\n')
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
# - 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
# - compIndicatorValue(pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import Post.PyTree as P

s = D.circle((0, 0, 0), 1.)
snear = 0.1
o = G.octree([s], [snear], dfar=10., balancing=1)
res = G.octree2Struct(o, vmin=11, merged=1)
res = G.getVolumeMap(res)
o = P.computeIndicatorValue(o, res, 'centers:vol')
t = C.newPyTree(['Base'])
t[2][1][2] += [o]
C.convertPyTree2File(t, "out.cgns")
示例#25
0
# - volumeFromCrossSection (pyTree) -
import Converter.PyTree as C
import Geom.PyTree as D
import KCore.test as test

contours = []
a = D.polyline([(0., 0., 0.), (1., 0., 0.), (1., 1., 0.), (0., 1., 0.),
                (0., 0., 0.)])
contours = [
    D.polyline([(0., 0., 2.), (1., 0., 2.), (1., 1., 2.), (0., 1., 2.),
                (0., 0., 2.)])
]
contours.append(a)

vol = D.volumeFromCrossSections(contours)
t = C.newPyTree(['Base', 2, vol])
test.testT(t, 1)
示例#26
0
# - cone (pyTree) -
import Geom.PyTree as D
import Converter.PyTree as C
import KCore.test as test

a = D.cone((0,0,0), 1. , 0.5, 1.)
t = C.newPyTree(['Base',2]); t[2][1][2].append(a)
test.testT(t, 1)
示例#27
0
#!/usr/bin/python
# coding: utf-8
r"""<TBC>"""

# Extraction de bandes x=cte sur un maillage surfacique
import Converter.PyTree as C
import Post.PyTree as P
import Geom.PyTree as D
import Generator.PyTree as G
import Transform.PyTree as T

# IN: surface+solution
# Attention: les normales doivent etre dirigees vers l'exterieur
a = D.sphere((0, 0, 0), 1, N=100)
a = C.initVars(a, 'p={CoordinateX}+{CoordinateY}')
a = C.convertArray2Tetra(a)
a = G.close(a)

# Extraction de lignes x = cste
bb = G.bbox(a)
xmin = bb[0]
ymin = bb[1]
zmin = bb[2]
xmax = bb[3]
ymax = bb[4]
zmax = bb[5]

bands = []
dx = 1. / 10
for i in range(10):
    x = i / 10.
示例#28
0
# - 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')
示例#29
0
# - octree (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import KCore.test as test

# 2D : QUADTREE
s = D.circle((0, 0, 0), 1., N=100)
snear = 0.1
s = C.addVars(s, 'ro')
s = C.initVars(s, 'centers:cellN', 1.)
res = G.octree([s], [snear], dfar=5.)
test.testT(res, 1)

# 3D : octree HEXA
s = D.sphere((0, 0, 0), 1., 100)
snear = 0.1
s = C.addVars(s, 'ro')
s = C.initVars(s, 'centers:cellN', 1.)
res = G.octree([s], [snear], dfar=5.)
test.testT(res, 2)
示例#30
0
# - 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')