コード例 #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
# - 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)
コード例 #3
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')
コード例 #4
0
# - 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')
コード例 #5
0
# - getCurvatureAngle (pyTree) -
import Converter.PyTree as C
import Geom.PyTree as D
import Generator.PyTree as G
import KCore.test as test

a = D.polyline([(0., 0., 0.), (1., 1., 0.), (2., 0., 0.)])
a = D.getCurvatureAngle(a)
t = C.newPyTree(['Base', 1])
t[2][1][2].append(a)
test.testT(t, 1)


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


# i-array
a1 = D.curve(f, 10)
b1 = D.getCurvatureAngle(a1)
test.testT([b1], 2)

# BAR-array
a2 = C.convertArray2Tetra(a1)
b2 = D.getCurvatureAngle(a2)
t = C.newPyTree(['Base', 1])
t[2][1][2].append(b2)
コード例 #6
0
# - orthoDrive (pyTree) -
import Geom.PyTree as D
import Converter.PyTree as C
import KCore.test as test

a = D.circle((0, 0, 0), 1.)
c = D.polyline([(0., 1., 0.), (0., 1., 1.), (2., 1., 2.)])
d = D.spline(c, 3, N=100)
o = D.orthoDrive(a, d, mode=0)
test.testT(o, 1)
コード例 #7
0
# - densify (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import KCore.test as test

a = D.polyline([(0., 0., 0.), (1., 1., 0.), (2., 0., 0.), (2.5, 0.5, 0.),
                (3.5, 0., 0.)])
a = C.convertArray2Tetra(a)
a = C.addVars(a, 'Density')
a = C.initVars(a, 'centers:cellN', 1)
c = G.densify(a, 0.1)
test.testT(c, 1)

a = D.polyline([(0., 0., 0.), (1., 1., 0.), (2., 0., 0.), (2.5, 0.5, 0.),
                (3.5, 0., 0.)])
a = C.addVars(a, 'Density')
a = C.initVars(a, 'centers:cellN', 1)
c = G.densify(a, 1.05)
c = C.initVars(a, 'F', 1.)
test.testT([c], 2)
コード例 #8
0
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.)
b = D.nurbs(a, 'weight', 4, 2000)
C.convertPyTree2File(b, 'out2.cgns')
コード例 #9
0
P0 = (0, 0, 1)
P1 = (5, 0, 1)
P2 = (0, 7, 1)
P3 = (5, 7, 1)

# Geometrie
d1 = D.line(P0, P1)
d2 = D.line(P2, P3)

P0 = (0, 0, 1)
P1 = (-2, 2, 1)
P2 = (-3, 3, 1)
P3 = (2, 5, 1)
P4 = (0, 7, 1)
pts = D.polyline([P0, P1, P2, P3, P4])
b1 = D.bezier(pts)

P0 = (5, 0, 1)
P1 = (3, 2, 1)
P2 = (2, 3, 1)
P3 = (6, 5, 1)
P4 = (5, 7, 1)
pts = D.polyline([P0, P1, P2, P3, P4])
b2 = D.bezier(pts)

# Discretisation reguliere de chaque ligne
Ni = 20
Nj = 10
r = G.cart((0, 0, 0), (1. / (Ni - 1), 1, 1), (Ni, 1, 1))
q = G.cart((0, 0, 0), (1. / (Nj - 1), 1, 1), (Nj, 1, 1))
コード例 #10
0
# - uniformize (pyTree) -
import Geom.PyTree as D
import Converter.PyTree as C

a = D.polyline([(0,0,0), (1,1,0), (2,0,0), (3,1,0), (4,0,0)])
a = D.uniformize(a, N=100)

C.convertPyTree2File(a, 'out.cgns')
コード例 #11
0
def drawFreeHand():
    global CURRENTZONE; global CURRENTPOLYLINE; global ALLZONES
    w = WIDGETS['draw']
    prev = []; first = []
    if CTK.__BUSY__ == False:
        CPlot.unselectAllZones()
        CTK.saveTree()
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        buttonState = 0
        while CTK.__BUSY__ == True:
            if prev == []: # first point
                l = []
                while l == []:
                    l = CPlot.getActivePoint()
                    if l != []: prev = l; first = l
                    time.sleep(CPlot.__timeStep__)
                    w.update()
                    if CTK.__BUSY__ == False: break
            else: # next points
                diff = -1.
                while (diff < 1.e-10):
                    (buttonState,x,y,z) = CPlot.getMouseState()
                    l = (x,y,z)
                    diff = Vector.norm2(Vector.sub(l,prev))
                    diff1 = Vector.norm2(Vector.sub(l,first))
                    if (diff1 < 1.e-10): l = first
                    if (buttonState == 5): break
                    time.sleep(CPlot.__timeStep__)
                    w.update()
                    if (CTK.__BUSY__ == False): break
                    
            prev = l
            CPlot.unselectAllZones()
            if (buttonState == 5): # button released
                ALLZONES.append(CURRENTZONE)
                CURRENTZONE = None; prev = []; first = []
                CURRENTPOLYLINE = []
                CTK.TKTREE.updateApp()
                
            if (CTK.__BUSY__ == True and buttonState != 5):
                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)
                CPlot.render()
            buttonState = 0
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       surfaces = getSurfaces()
       if (surfaces != []):
           if (CURRENTZONE != None): ALLZONES += [CURRENTZONE]
           for s in ALLZONES:
               ret = Internal.getParentOfNode(CTK.t, s)
               nob = C.getNobOfBase(ret[0], CTK.t)
               a = T.projectOrthoSmooth(s, surfaces)
               noz = ret[1]
               CTK.replace(CTK.t, nob, noz, a)
       #C._fillMissingVariables(CTK.t)
       (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
       CTK.TKTREE.updateApp()
       CPlot.render()
       CURRENTZONE = None; ALLZONES = []
       CURRENTPOLYLINE = []
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
コード例 #12
0
#!/usr/bin/env python
# coding: utf-8
r"""bezier (pyTree)"""

import Geom.PyTree as D
import Converter.PyTree as C

# Bezier 1D
pts = D.polyline([(0., 0., 0.), (0., 1., 0.), (2., 1., 0.), (2., 0., 0.),
                  (4., -1., 0.), (5., 6., 0.)])
a = D.bezier(pts, 100)
a[0] = 'bezier'
C.convertPyTree2File(a, 'out.cgns')
コード例 #13
0
# - getTangent (PyTree) -
import Geom.PyTree as D
import Converter.PyTree as C
import KCore.test as test

# Along spline
c = D.polyline([(0, 0, 0), (1, 1, 0), (2, -1, 0)])
a = D.spline(c, order=3, density=10.)
res = D.getTangent(a)
test.testO(res, 1)

# Along a tree made of splines zones
t = C.newPyTree(['Base', a])
res = D.getTangent(t)
test.testO(res, 2)
コード例 #14
0
# - TFI 2D structure -
import Generator.PyTree as G
import Geom.PyTree as D
import KCore.test as test

P0 = (0, 0, 0)
P1 = (5, 0, 0)
P2 = (0, 7, 0)
P3 = (5, 7, 0)

# Geometrie
d1 = D.line(P0, P1)
d2 = D.line(P2, P3)
pts = D.polyline([(0., 0., 0.), (-2, 2, 0), (-3, 3, 0.), (2, 5, 0.),
                  (0., 7, 0.)])
b1 = D.bezier(pts)
pts = D.polyline([(5., 0., 0.), (3, 2, 0), (2, 3, 0.), (6, 5, 0.),
                  (5., 7., 0.)])
b2 = D.bezier(pts)

# Discretisation reguliere de chaque ligne
Ni = 20
Nj = 10
r = G.cart((0, 0, 0), (1. / (Ni - 1), 1, 1), (Ni, 1, 1))
q = G.cart((0, 0, 0), (1. / (Nj - 1), 1, 1), (Nj, 1, 1))
r1 = G.map(d1, r)
r2 = G.map(d2, r)
r3 = G.map(b1, q)
r4 = G.map(b2, q)

# TFI
コード例 #15
0
# - spline (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import KCore.test as test

# Spline 1D
c = D.polyline([(0.,0.,0.), (1.,1.,0.), (2.,1.,0.), \
                (3.,0.,0.), (4.,-1.,0.), (5.,6.,0.), \
                (6.,1.,0.), (7.,2.,0.), (8.,1.,0.), \
                (9.,-1.,0.), (10.,1.,0.), (11.,-1.,0.)])
d = D.spline(c, 3, 100)
d[0] = 'spline'
t = C.newPyTree(['Base', 1])
t[2][1][2].append(d)
test.testT(t, 1)
コード例 #16
0
# - getCurvatureRadius (pyTree) -
import Geom.PyTree as D
import Converter.PyTree as C
import KCore.test as test

#cercle
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)
test.testT(t, 1)

# ligne : courbure infinie
a = D.line((0, 0, 0), (1, 0, 0), 3)
rad = D.getCurvatureRadius(a)
t = C.newPyTree(['Base', 1])
t[2][1][2].append(rad)
test.testT(t, 2)

# bezier
pts = D.polyline([(6, 0.01, 1), (5.4, 0.036, 1), (4.8, 0.064, 1),
                  (2.5, 0.21, 1), (0.3, 0.26, 1), (0, 0.047, 1), (0, 0, 0)])
a = D.bezier(pts, 100)
rad = D.getCurvatureRadius(a)
t = C.newPyTree(['Base', 1])
t[2][1][2].append(rad)
test.testT([rad], 3)