コード例 #1
0
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()
コード例 #2
0
# - lineDrive (pyTree) -
import Geom.PyTree as D
import Generator.PyTree as G
import KCore.test as test
import Converter.PyTree as C

# 1D structure
a = D.naca(12.)
b = D.line((0, 0, 0), (0, 0., 1.))
c = D.lineDrive(a, b)
t = C.newPyTree(['Base', 2, c])
test.testT(t, 1)

# 1D structure + champ noeud
a = D.circle((0, 0, 0), 1)
a = C.addVars(a, 'var')
b = D.line((0, 0, 0), (0, 0, 1))
c = D.lineDrive(a, b)
t = C.newPyTree(['Base', 2, c])
test.testT(t, 2)

# 2D structure + champ en noeuds + champ en centres
a = G.cylinder((0, 0, 0), 1, 2, 360, 0, 1, (50, 21, 1))
a = C.addVars(a, 'var')
a = C.addVars(a, 'centers:var2')
b = D.line((0, 0, 0), (0, 0., 1.))
c = D.lineDrive(a, b)
import Converter.Internal as Internal
t = C.newPyTree(['Base', 3, c])
test.testT(t, 3)
コード例 #3
0
def generate(event=None):

    CTK.saveTree()
    N = CTK.varsFromWidget(VARS[0].get(), type=2)
    if len(N) != 1:
        CTK.TXT.insert('START', 'NPts is incorrect.\n')
        return
    N = N[0]
    eltType = VARS[1].get()
    surfType = VARS[2].get()

    if surfType == 'Sphere':
        s = D.sphere6((0, 0, 0), 0.5, N=N)
        xc = 0
        yc = 0
        zc = 0
    elif surfType == 'Plane':
        h = 1. / (N - 1)
        s1 = G.cart((-0.5, -0.5, -0.5), (h, h, h), (N, 1, N))
        s = [s1]
        xc = 0
        yc = 0
        zc = 0
    elif surfType == 'Cube':
        h = 1. / (N - 1)
        s1 = G.cart((-0.5, -0.5, -0.5), (h, h, h), (N, N, 1))
        s1 = T.reorder(s1, (-1, 2, 3))
        s2 = G.cart((-0.5, -0.5, 0.5), (h, h, h), (N, N, 1))
        s3 = G.cart((-0.5, -0.5, -0.5), (h, h, h), (N, 1, N))
        s4 = G.cart((-0.5, 0.5, -0.5), (h, h, h), (N, 1, N))
        s4 = T.reorder(s4, (-1, 2, 3))
        s5 = G.cart((-0.5, -0.5, -0.5), (h, h, h), (1, N, N))
        s5 = T.reorder(s5, (1, -2, 3))
        s6 = G.cart((0.5, -0.5, -0.5), (h, h, h), (1, N, N))
        s = [s1, s2, s3, s4, s5, s6]
        xc = 0
        yc = 0
        zc = 0
    elif surfType == 'Tetra':
        m1 = meshTri([0, 0, 0], [1, 0, 0], [0, 1, 0], N=N)
        m1 = T.reorder(m1, (-1, 2, 3))
        m2 = meshTri([0, 0, 0], [1, 0, 0], [0, 0, 1], N=N)
        m3 = meshTri([0, 0, 0], [0, 1, 0], [0, 0, 1], N=N)
        m3 = T.reorder(m3, (-1, 2, 3))
        m4 = meshTri([1, 0, 0], [0, 1, 0], [0, 0, 1], N=N)
        s = m1 + m2 + m3 + m4
        xc = 0.5
        yc = 0.5
        zc = 0.5
    elif surfType == 'Pyramid':
        h = 1. / (2 * N - 2)
        m0 = G.cart((-0.5, -0.5, -0.5), (h, h, h), (2 * N - 1, 2 * N - 1, 1))
        m0 = T.reorder(m0, (-1, 2, 3))
        m1 = meshTri([-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [0, 0, 0.5], N=N)
        m2 = meshTri([-0.5, -0.5, -0.5], [-0.5, 0.5, -0.5], [0, 0, 0.5], N=N)
        m2 = T.reorder(m2, (-1, 2, 3))
        m3 = meshTri([-0.5, 0.5, -0.5], [0.5, 0.5, -0.5], [0, 0, 0.5], N=N)
        m3 = T.reorder(m3, (-1, 2, 3))
        m4 = meshTri([0.5, -0.5, -0.5], [0.5, 0.5, -0.5], [0, 0, 0.5], N=N)
        s = [m0] + m1 + m2 + m3 + m4
        xc = 0.
        yc = 0.
        zc = 0.
    elif surfType == 'Cylinder':
        m0 = meshCircle((0, 0, -0.5), 0.5, N)
        m1 = meshCircle((0, 0, 0.5), 0.5, N)
        m1 = T.reorder(m1, (-1, 2, 3))
        m2 = D.circle((0, 0, -0.5),
                      0.5,
                      tetas=-45,
                      tetae=-45 + 360,
                      N=4 * N - 3)
        l = D.line((0, 0, -0.5), (0, 0, 0.5), N=N)
        m2 = D.lineDrive(m2, l)
        s = m0 + m1 + [m2]
        xc = 0.
        yc = 0.
        zc = 0.
    elif surfType == 'Cone':
        s = [D.cone((0., 0, 0), 1, 0.1, 1, N=N)]
        (xc, yc, zc) = G.barycenter(s)
    else:  # Geom parametrics surfaces
        formula = base[surfType]
        if formula.replace('{u}', '') == formula:  # curve
            s = D.curve(base[surfType], N)
        else:
            s = D.surface(base[surfType], N)
        (xc, yc, zc) = G.barycenter(s)
        s = [s]

    if eltType == 'TRI':
        s = C.convertArray2Tetra(s)
        s = T.join(s)
        s = G.close(s)
    elif eltType == 'QUAD':
        s = C.convertArray2Hexa(s)
        s = T.join(s)
        s = G.close(s)

    posCam = CPlot.getState('posCam')
    posEye = CPlot.getState('posEye')
    dirCam = CPlot.getState('dirCam')

    s = T.translate(s, (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 < 1.e-10: 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)
    s = T.homothety(s, (posEye[0], posEye[1], posEye[2]), 0.5 * ll)

    ux = dirCam[1] * lz - dirCam[2] * ly
    uy = dirCam[2] * lx - dirCam[0] * lz
    uz = dirCam[0] * ly - dirCam[1] * lx
    s = T.rotate(s, (posEye[0], posEye[1], posEye[2]),
                 ((1, 0, 0), (0, 1, 0), (0, 0, 1)),
                 ((-ux, -uy, -uz), (lx, ly, lz), dirCam))

    CTK.t = C.addBase2PyTree(CTK.t, 'SURFACES', 2)
    b = Internal.getNodeFromName1(CTK.t, 'SURFACES')

    if eltType == 'TRI' or eltType == 'QUAD':
        nob = C.getNobOfBase(b, CTK.t)
        CTK.add(CTK.t, nob, -1, s)
    else:
        nob = C.getNobOfBase(b, CTK.t)
        if CP.__slot__ is None:
            CTK.t[2][nob][2] += s
            CTK.display(CTK.t)
        else:
            for i in s:
                CTK.add(CTK.t, nob, -1, i)

    #C._fillMissingVariables(CTK.t)
    CTK.TXT.insert('START', 'Surface created.\n')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
コード例 #4
0
# - lineDrive (pyTree)-
import Geom.PyTree as D
import Converter.PyTree as C

# With one driving curve
a = D.naca(12.)
l = D.line((0,0,0), (0,0.,1.))
a = D.lineDrive(a, l)
C.convertPyTree2File(a, 'out.cgns')

# With a set of driving curves
a = D.naca(12.)
d1 = D.line((0,0,0), (0.,0.,1.))
d2 = D.line((1,0,0), (2,0,1))
a = D.lineDrive(a, [d1,d2])
C.convertPyTree2File(a, 'out.cgns')