示例#1
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]
示例#2
0
def meshCircle(center, R, N):
    coeff = R * math.sqrt(2.) * 0.25
    x = center[0]
    y = center[1]
    z = center[2]
    c = D.circle(center, R, tetas=-45., tetae=45., N=N)
    l1 = D.line((x + coeff, y - coeff, z), (x + coeff, y + coeff, z), N=N)
    l2 = D.line((x + coeff, y - coeff, z), (x + 2 * coeff, y - 2 * coeff, z),
                N=N)
    l3 = D.line((x + coeff, y + coeff, z), (x + 2 * coeff, y + 2 * coeff, z),
                N=N)
    m1 = G.TFI([c, l1, l2, l3])

    c = D.circle(center, R, tetas=45., tetae=45. + 90., N=N)
    l1 = D.line((x + coeff, y + coeff, z), (x - coeff, y + coeff, z), N=N)
    l2 = D.line((x + coeff, y + coeff, z), (x + 2 * coeff, y + 2 * coeff, z),
                N=N)
    l3 = D.line((x - coeff, y + coeff, z), (x - 2 * coeff, y + 2 * coeff, z),
                N=N)
    m2 = G.TFI([c, l1, l2, l3])

    c = D.circle(center, R, tetas=45. + 90, tetae=45. + 180., N=N)
    l1 = D.line((x - coeff, y + coeff, z), (x - coeff, y - coeff, z), N=N)
    l2 = D.line((x - coeff, y + coeff, z), (x - 2 * coeff, y + 2 * coeff, z),
                N=N)
    l3 = D.line((x - coeff, y - coeff, z), (x - 2 * coeff, y - 2 * coeff, z),
                N=N)
    m3 = G.TFI([c, l1, l2, l3])

    c = D.circle(center, R, tetas=45. + 180, tetae=45. + 270., N=N)
    l1 = D.line((x - coeff, y - coeff, z), (x + coeff, y - coeff, z), N=N)
    l2 = D.line((x - coeff, y - coeff, z), (x - 2 * coeff, y - 2 * coeff, z),
                N=N)
    l3 = D.line((x + coeff, y - coeff, z), (x + 2 * coeff, y - 2 * coeff, z),
                N=N)
    m4 = G.TFI([c, l1, l2, l3])

    h = 2 * coeff / (N - 1)
    m5 = G.cart((x - coeff, y - coeff, z), (h, h, h), (N, N, 1))
    m5 = T.reorder(m5, (-1, 2, 3))
    return [m1, m2, m3, m4, m5]
示例#3
0
# - TFIO (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Geom.PyTree as D

a = D.circle((0, 0, 0), 1., N=41)
r = G.TFIO(a)
C.convertPyTree2File(r, 'out.cgns')
示例#4
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')
示例#5
0
# test - enforceCurvature2 (pyTree)
import Converter.PyTree as C
import Geom.PyTree as D
import Generator.PyTree as G
import KCore.test as test

# Cas 1 : courbure constante 
a = D.circle((0,0,0),0.1,N=51)
ni = 101; db = G.cart((0,0,0),(1./(ni-1),1,1),(ni,1,1))
db = C.addBC2Zone(db, 'wall1', 'BCWall', 'jmin')
db = C.addBC2Zone(db, 'match1', 'BCMatch', 'imin',db,'imax',[1,2])
db = C.addBC2Zone(db, 'match2', 'BCMatch', 'imax',db,'imin',[1,2])
db = C.addBC2Zone(db, 'wall2','BCWall','jmax')
db = C.addVars(db,'Density'); db = C.addVars(db,'centers:cellN')
db2 = G.enforceCurvature2(db, a)
test.testT([db2],1)

# Cas 2 : courbure variable
a = D.naca(12.)
ni = 101; db = G.cart((0,0,0),(1./(ni-1),1,1),(ni,1,1))
db = C.addBC2Zone(db, 'wall1','BCWall','jmin')
db = C.addBC2Zone(db, 'match1','BCMatch','imin',db,'imax',[1,2])
db = C.addBC2Zone(db, 'match2','BCMatch','imax',db,'imin',[1,2])
db = C.addBC2Zone(db, 'wall2','BCWall','jmax')
db = C.addVars(db,'Density'); db = C.addVars(db,'centers:cellN')
db2 = G.enforceCurvature2(db, a)
test.testT([db2],2)
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')
# - gapfixer (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import KCore.test as test

a = D.circle((0, 0, 0), 1, N=100)
a = C.convertArray2Tetra(a)
a = G.close(a)
b = G.cart((-2., -2., 0.), (0.1, 0.1, 1.), (50, 50, 1))
a = C.initVars(a, 'F', 1.)
a = C.initVars(a, 'centers:G', 2.)
a1 = G.gapfixer(a, b)
test.testT(a1, 1)

hp = D.point((0.5, 0.5, 0.))
a2 = G.gapfixer(a, b, hp, refine=0)
test.testT(a2, 2)
示例#8
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()
# - T3mesher2D (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import KCore.test as test

a = D.circle((0, 0, 0), 1, N=50)
a = C.convertArray2Tetra(a)
a = G.close(a)
a = C.initVars(a, 'F', 1.)
a = C.initVars(a, 'centers:G', 2.)
b = G.T3mesher2D(a, triangulateOnly=0, grading=1.2,
                 metricInterpType=1)  # geometric metric interpolation
test.testT(b)
# - 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)
示例#11
0
def drawArc(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')
    w = WIDGETS['draw']
    prev = []; second = []
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            CTK.saveTree()
            surfaces = getSurfaces()
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if (CTK.__BUSY__ == True):
                if (prev == []):
                    prev = l
                    CTK.TXT.insert('START', 'Click second point...\n')
                elif (second == [] and prev != l):
                    second = l
                    CTK.TXT.insert('START', 'Click third point...\n')
                elif (prev != l and second != l):
                    x1 = l[0]; y1 = l[1]; z1 = l[2]
                    x2 = prev[0]; y2 = prev[1]; z2 = prev[2]
                    x3 = second[0]; y3 = second[1]; z3 = second[2]
                    xa = x2 - x1; ya = y2 - y1; za = z2 - z1
                    xb = x3 - x1; yb = y3 - y1; zb = z3 - z1
                    xc = x3 - x2; yc = y3 - y2; zc = z3 - z2
                    a2 = xa*xa + ya*ya + za*za
                    b2 = xb*xb + yb*yb + zb*zb
                    c2 = xc*xc + yc*yc + zc*zc
                    A = 2*b2*c2 + 2*c2*a2 + 2*a2*b2 - a2*a2 - b2*b2 - c2*c2
                    R = math.sqrt( a2*b2*c2 / A )
                    
                    nx = ya*zb - za*yb
                    ny = za*xb - xa*zb
                    nz = xa*yb - ya*xb
                    tx = ya*nz - za*ny
                    ty = za*nx - xa*nz
                    tz = xa*ny - ya*nx
                    norm = tx*tx + ty*ty + tz*tz
                    normi = 1./math.sqrt(norm)
                    tx = tx*normi; ty = ty*normi; tz = tz*normi;
                    alpha = R*R - (xa*xa+ya*ya+za*za)*0.25
                    alpha = math.sqrt(alpha)
                    center = [0,0,0]
                    center[0] = 0.5*(x1+x2) + alpha*tx
                    center[1] = 0.5*(y1+y2) + alpha*ty
                    center[2] = 0.5*(z1+z2) + alpha*tz
                    dx3 = center[0]-x3; dy3 = center[1]-y3; dz3 = center[2]-z3
                    l = dx3*dx3 + dy3*dy3 + dz3*dz3
                    if (abs(l - R*R) > 1.e-10):
                        center[0] = 0.5*(x1+x2) - alpha*tx
                        center[1] = 0.5*(y1+y2) - alpha*ty
                        center[2] = 0.5*(z1+z2) - alpha*tz
                        dx3 = center[0]-x3; dy3 = center[1]-y3; dz3 = center[2]-z3
                        l = dx3*dx3 + dy3*dy3 + dz3*dz3
                    
                    e1 = [x1-center[0], y1-center[1], z1-center[2]]
                    e2 = [x2-center[0], y2-center[1], z2-center[2]]
                    e3 = Vector.cross(e1, e2)
                    e4 = Vector.cross(e1, e3)

                    # Images des pts dans le plan xyz 
                    pt1 = D.point((x1,y1,z1))
                    pt2 = D.point((x2,y2,z2))
                    pt3 = D.point((x3,y3,z3))
                    pt1 = T.rotate(pt1,
                                   (center[0], center[1], center[2]),
                                   (e1, e4, e3),
                                   ((1,0,0), (0,1,0), (0,0,1)) )
                    pt2 = T.rotate(pt2,
                                   (center[0], center[1], center[2]),
                                   (e1, e4, e3),
                                   ((1,0,0), (0,1,0), (0,0,1)))
                    pt3 = T.rotate(pt3,
                                   (center[0], center[1], center[2]),
                                   (e1, e4, e3),
                                   ((1,0,0), (0,1,0), (0,0,1)))
                    xp1 = C.getValue(pt1, 'CoordinateX', 0)
                    yp1 = C.getValue(pt1, 'CoordinateY', 0)
                    zp1 = C.getValue(pt1, 'CoordinateZ', 0)
                    xp2 = C.getValue(pt2, 'CoordinateX', 0)
                    yp2 = C.getValue(pt2, 'CoordinateY', 0)
                    zp2 = C.getValue(pt2, 'CoordinateZ', 0)
                    xp3 = C.getValue(pt3, 'CoordinateX', 0)
                    yp3 = C.getValue(pt3, 'CoordinateY', 0)
                    zp3 = C.getValue(pt3, 'CoordinateZ', 0)
                    
                    dx1 = (xp1-center[0])/R; dy1 = (yp1-center[1])/R
                    if dx1 > 1.: dx1 = 1.
                    if dx1 < -1.: dx1 = -1.
                    if dy1 > 0: teta1 = math.acos(dx1)
                    else: teta1 = 2*math.pi - math.acos(dx1)
                    teta1 = teta1*180./math.pi; teta1 = 360.

                    dx2 = (xp2-center[0])/R; dy2 = (yp2-center[1])/R
                    if dx2 > 1.: dx2 = 1.
                    if dx2 < -1.: dx2 = -1.
                    if dy2 > 0: teta2 = math.acos(dx2)
                    else: teta2 = 2*math.pi - math.acos(dx2)
                    teta2 = teta2*180./math.pi

                    dx3 = (xp3-center[0])/R; dy3 = (yp3-center[1])/R
                    if dx3 > 1.: dx3 = 1.
                    if dx3 < -1.: dx3 = -1.
                    if dy3 > 0: teta3 = math.acos(dx3)
                    else: teta3 = 2*math.pi - math.acos(dx3)
                    teta3 = teta3*180./math.pi

                    if teta3 > teta2: teta1 = 360.
                    else: teta1 = 0.

                    circle = D.circle((center[0],center[1],center[2]), R, 
                                      tetas=teta2, tetae=teta1, N=npts)
                    circle = T.rotate(circle,
                                      (center[0], center[1], center[2]),
                                      ((1,0,0), (0,1,0), (0,0,1)),
                                      (e1, e4, e3))
                    if surfaces != []:
                        circle = T.projectOrthoSmooth(circle, surfaces)
                    CTK.add(CTK.t, nob, -1, circle)
                    CTK.TXT.insert('START', 'Circle created.\n')
                    CTK.__BUSY__ = False
                    TTK.raiseButton(w)
                    CPlot.setState(cursor=0)
                    #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(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
示例#12
0
def drawCircle(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')
    w = WIDGETS['draw']
    prev = []; second = []
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            CTK.saveTree()
            surfaces = getSurfaces()
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if (CTK.__BUSY__ == True):
                if prev == []:
                    prev = l
                    CTK.TXT.insert('START', 'Click second point...\n')
                elif (second == [] and prev != l):
                    second = l
                    CTK.TXT.insert('START', 'Click third point...\n')
                elif (prev != l and second != l):
                    x1 = l[0]; y1 = l[1]; z1 = l[2]
                    x2 = prev[0]; y2 = prev[1]; z2 = prev[2]
                    x3 = second[0]; y3 = second[1]; z3 = second[2]
                    xa = x2 - x1; ya = y2 - y1; za = z2 - z1
                    xb = x3 - x1; yb = y3 - y1; zb = z3 - z1
                    xc = x3 - x2; yc = y3 - y2; zc = z3 - z2
                    a2 = xa*xa + ya*ya + za*za
                    b2 = xb*xb + yb*yb + zb*zb
                    c2 = xc*xc + yc*yc + zc*zc
                    A = 2*b2*c2 + 2*c2*a2 + 2*a2*b2 - a2*a2 - b2*b2 - c2*c2
                    R = math.sqrt( a2*b2*c2 / A )
                    
                    nx = ya*zb - za*yb
                    ny = za*xb - xa*zb
                    nz = xa*yb - ya*xb
                    tx = ya*nz - za*ny
                    ty = za*nx - xa*nz
                    tz = xa*ny - ya*nx
                    norm = tx*tx + ty*ty + tz*tz
                    normi = 1./math.sqrt(norm)
                    tx = tx*normi; ty = ty*normi; tz = tz*normi;
                    alpha = R*R - (xa*xa+ya*ya+za*za)*0.25
                    alpha = math.sqrt(alpha)
                    center = [0,0,0]
                    center[0] = 0.5*(x1+x2) + alpha*tx
                    center[1] = 0.5*(y1+y2) + alpha*ty
                    center[2] = 0.5*(z1+z2) + alpha*tz
                    l = (center[0]-x3)*(center[0]-x3) + \
                        (center[1]-y3)*(center[1]-y3) + \
                        (center[2]-z3)*(center[2]-z3)
                    if (abs(l - R*R) > 1.e-10):
                        center[0] = 0.5*(x1+x2) - alpha*tx
                        center[1] = 0.5*(y1+y2) - alpha*ty
                        center[2] = 0.5*(z1+z2) - alpha*tz
                        l = (center[0]-x3)*(center[0]-x3) + \
                        (center[1]-y3)*(center[1]-y3) + \
                        (center[2]-z3)*(center[2]-z3)
                    circle = D.circle( (center[0],center[1],center[2]), R, N=npts)
                    e1 = [x1-center[0], y1-center[1], z1-center[2]]
                    e2 = [x2-center[0], y2-center[1], z2-center[2]]
                    e3 = Vector.cross(e1, e2)
                    e4 = Vector.cross(e1, e3)
                    circle = T.rotate(circle,
                                      (center[0], center[1], center[2]),
                                      ((1,0,0), (0,1,0), (0,0,1)),
                                      (e1, e4, e3))
                    if (surfaces != []):
                        circle = T.projectOrthoSmooth(circle, surfaces)
                    CTK.add(CTK.t, nob, -1, circle)
                    CTK.TXT.insert('START', 'Circle created.\n')
                    CTK.__BUSY__ = False
                    TTK.raiseButton(w)
                    CPlot.setState(cursor=0)
                    #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(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
示例#13
0
# - convertBAR2Struct (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Geom.PyTree as D

a = D.circle((0., 0., 0.), 1.)
a = C.convertArray2Hexa(a)
a = G.close(a)
b = C.convertBAR2Struct(a)
C.convertPyTree2File(b, 'out.cgns')
# - selectInsideElts (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Geom.PyTree as D

a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 1))
a = C.convertArray2Tetra(a)
b = D.circle((5, 5, 0), 3.)
b = C.convertArray2Tetra(b)
a = G.selectInsideElts(a, b)
C.convertPyTree2File(a, 'out.cgns')
# - surfaceWalk (pyTree)
import Converter.PyTree as C
import Geom.PyTree as D
import Transform.PyTree as T
import Generator.PyTree as G


# User definition of parametric curve
def f(t, u):
    x = t + u
    y = t * t + 1 + u * u
    z = u
    return (x, y, z)


# Array definition of geometry
a = D.surface(f)

c = D.circle((1.2, 1.7, 0.6), 0.1)
c = T.rotate(c, (1.2, 1.7, 0.6), (0, 1, 0), 90.)
c = T.reorder(c, (-1, 2, 3))
c = T.projectOrtho(c, [a])

h = G.cart((0., 0., 0.), (0.01, 1, 1), (15, 1, 1))
r = G.surfaceWalk([a], c, h, niter=100)
C.convertPyTree2File(r, "out.cgns")
示例#16
0
# - densify (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D

a = D.circle((0, 0, 0), 1., 10)
b = G.densify(a, 0.01)
C.convertPyTree2File(b, 'out.cgns')
# - splitTRI (PyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import Transform.PyTree as T
import KCore.test as test

a = D.circle((0, 0, 0), 1, N=20)
a = C.convertArray2Tetra(a)
a = G.close(a)
b = G.T3mesher2D(a)
#C.convertArrays2File([b], 'out.plt')
c = [[9, 25, 27, 30, 29, 28, 34, 38, 0], [29, 23, 19, 20, 24, 29]]
D = T.splitTRI(b, c)
t = C.newPyTree(['Base', 2])
t[2][1][2] += D
test.testT(t, 1)
示例#18
0
# - close (pyTree)-
import Generator.PyTree as G
import Converter.PyTree as C
import KCore.test as test
import Geom.PyTree as D
import Transform.PyTree as T

# test 1D : circle
a = D.circle((0., 0., 0.), 1., 0., 359.995, 500)
C._addVars(a, 'Density')
C._addVars(a, 'centers:cellN')
a = C.convertArray2Tetra(a)
a2 = G.close(a, 1.e-4)
test.testT(a2, 1)

# test 2D cylindre QUAD
ni = 20
nj = 20
nk = 5
a0 = G.cylinder((0., 0., 0.), 0., 1., 0., 359, 1., (ni, nj, nk))
a = T.subzone(a0, (1, nj, 1), (ni, nj, nk))
C._addVars(a, 'Density')
C._addVars(a, 'centers:cellN')
a = C.convertArray2Hexa(a)
a2 = G.close(a, 1.e-1)
test.testT(a2, 2)

# test 2D TRI
a = T.subzone(a0, (1, nj, 1), (ni, nj, nk))
a = C.convertArray2Tetra(a)
C._addVars(a, 'Density')
# - blanCells (pyTree) -
# - 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)
示例#20
0
    y = t*t+1
    z = 0.
    return (x,y,z)

# i-array ouvert
a1 = D.curve(f, 10)
b1 = D.getCurvatureHeight(a1)
test.testT([b1], 1)

# BAR-array ouvert
a2 = C.convertArray2Tetra(a1)
b2 = D.getCurvatureHeight( a2 )
test.testT([b2], 2)

# i-array ferme
a1 = D.circle((0,0,0),1.)
b1 = D.getCurvatureHeight(a1)
test.testT([b1], 11)

# BAR-array ferme
a2 = D.circle((0,0,0),1.)
b2 = D.getCurvatureHeight(a2)
test.testT([b2], 21)

# structured 2D
a3 = D.sphere((0,0,0), 1., 20)
b3 = D.getCurvatureHeight( a3 )
test.testT([b3], 3)

# QUAD
a4 = C.convertArray2Hexa(a3)
# - volumeFromCrossSection (pyTree) -
import Converter.PyTree as C
import Geom.PyTree as D
contours = []
for z in [0.,1.]:
    contours.append(D.circle((0,0,z),1.,N=15))
vol = D.volumeFromCrossSections(contours)
C.convertPyTree2File(vol,'out.cgns')
示例#22
0
# - TFIMono (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Geom.PyTree as D
 
a1 = D.circle((0,0,0), 1., tetas=0, tetae=180., N=41)
a2 = D.line((-1,0,0),(1,0,0), N=21)
r = G.TFIMono(a1, a2)
C.convertPyTree2File(r, 'out.cgns')
# - adaptOctree (pyTree) - 
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import KCore.test as test

s = D.circle((0,0,0), 1., N=100); snear = 0.1
o = G.octree([s], [snear], dfar=5.,balancing=1)
o = C.initVars(o,'centers:indicator', 2.)
res = G.adaptOctree(o)
t = C.newPyTree(['OCTREE',2]); t[2][1][2] += [res]
test.testT(t)

s = D.sphere((0,0,0), 1., N=20); snear = 0.5
o = G.octree([s], [snear], dfar=5., balancing=1)
o = C.initVars(o,'centers:indicator',2.)
res = G.adaptOctree(o)
t = C.newPyTree(['OCTREE']); t[2][1][2] += [res]
test.testT(t,2)
示例#24
0
# - axisym (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D

# Axisym a curve
a0 = D.line((0.5,0,0), (0.6,0,1))
a = D.axisym(a0,(0.,0.,0.),(0.,0.,1.),360.,360)
C.convertPyTree2File(a, "out.cgns")

# Axisym a curve with varying r
a0 = D.line((1.0,0,0), (0.,0,1))
a1 = D.circle((0,0,0), 2.)
a = D.axisym(a0, (0.,0.,0.), (0.,0.,1.), rmod=a1)
C.convertPyTree2File([a,a0,a1], "out1.cgns")

# Axisym a 2D cart grid
a = G.cart((0.,0.,0.), (0.1,0.1,0.2),(10,10,1))
a = D.axisym(a,(1.,0.,0.),(0.,1.,0.),30.,4)
C.convertPyTree2File(a, 'out2.cgns')
示例#25
0
# - getCurvatureRadius (pyTree) -
import Geom.PyTree as D
import Converter.PyTree as C

a = D.circle((0, 0, 0), 1, 10, 0, 10)
a = D.getCurvatureRadius(a)
t = C.newPyTree(['Base', 1])
t[2][1][2].append(a)
C.convertPyTree2File(t, 'out.cgns')
示例#26
0
# - setInterpData (pyTree) - 
# case without cellN field: the whole receiver zone is interpolated
import Converter.PyTree as C
import Generator.PyTree as G
import Connector.PyTree as X
import Geom.PyTree as D
import KCore.test as test

# Tetra donor zone
a = G.cartTetra((0,0,-0.2),(0.01,0.01,0.1),(101,101,5))
pts = D.circle((0.5,0.5,0),0.05,N=20)
C._initVars(pts, 'cellN', 2); C._initVars(pts, 'centers:cellN',2) 
# options to combine
notest = 1
for location in ['nodes', 'centers']:
    for stk in ['direct', 'indirect']:
        for pen in [0,1]:
            for nat in [0,1]:
                for order in [2,3,5]:
                    pts2 = X.setInterpData(pts, a, order=order, penalty=pen,
                                           nature=nat, loc=location, 
                                           storage=stk, hook=None)
                    test.testT(pts2, notest)
                    notest += 1
# - 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")
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 = 21
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)
res = IBM.extractIBMInfo(tc)
test.testT(res,1)
# CAS 2D
N = 21
a = G.cart((0,0,0),(1./(N-1),1./(N-1),1./(N-1)),(N,N,2))
body = D.circle((0.5,0,0),0.1)
t = C.newPyTree(['Base',a])
tb = C.newPyTree(['Base',body])
tb = C.addState(tb, 'EquationDimension',2)
tb = C.addState(tb, 'GoverningEquations', 'NSTurbulent')
t = DTW.distance2Walls(t,bodies=tb,loc='centers',type='ortho',dim=2)
t = P.computeGrad(t,'centers:TurbulentDistance')
t,tc=IBM.prepareIBMData(t,tb,DEPTH=2)
res = IBM.extractIBMInfo(tc)
test.testT(res,2)
示例#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
# - 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)