コード例 #1
0
def meshTri(P0, P1, P2, N):
    C01 = (0.5 * (P0[0] + P1[0]), 0.5 * (P0[1] + P1[1]), 0.5 * (P0[2] + P1[2]))
    C12 = (0.5 * (P1[0] + P2[0]), 0.5 * (P1[1] + P2[1]), 0.5 * (P1[2] + P2[2]))
    C02 = (0.5 * (P0[0] + P2[0]), 0.5 * (P0[1] + P2[1]), 0.5 * (P0[2] + P2[2]))
    C = (1. / 3. * (P0[0] + P1[0] + P2[0]), 1. / 3. * (P0[1] + P1[1] + P2[1]),
         1. / 3. * (P0[2] + P1[2] + P2[2]))

    l1 = D.line(P0, C01, N)
    l2 = D.line(C01, C, N)
    l3 = D.line(C, C02, N)
    l4 = D.line(C02, P0, N)
    m1 = G.TFI([l1, l2, l3, l4])
    m1 = T.reorder(m1, (-1, 2, 3))

    l1 = D.line(C01, P1, N)
    l2 = D.line(P1, C12, N)
    l3 = D.line(C12, C, N)
    l4 = D.line(C, C01, N)
    m2 = G.TFI([l1, l2, l3, l4])
    m2 = T.reorder(m2, (-1, 2, 3))

    l1 = D.line(C, C12, N)
    l2 = D.line(C12, P2, N)
    l3 = D.line(P2, C02, N)
    l4 = D.line(C02, C, N)
    m3 = G.TFI([l1, l2, l3, l4])
    m3 = T.reorder(m3, (-1, 2, 3))
    return [m1, m2, m3]
コード例 #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
a = G.cylinder((0, 0, 0), 0.5, 1., 180., 0., 1., (21, 21, 21))
a = C.addBC2Zone(a, 'wall', 'BCWall', 'jmin')
a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'jmax')
a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'kmin')
a = C.addBC2Zone(a, 'overlap', 'BCOverlap', 'kmax')
a1 = T.subzone(a, (1, 1, 1), (11, 21, 21))
a2 = T.subzone(a, (11, 1, 1), (21, 21, 21))
t = C.newPyTree(['MESH'])
t[2][1][2] = [a1, a2]
t = X.connectMatch(t)
t = C.fillEmptyBCWith(t, 'sym', 'BCSymmetryPlane')
t = C.initVars(
    t, '{F}={CoordinateX}*{CoordinateX}+{CoordinateY}+2*{CoordinateZ}')

# Symmetry y=0
t2 = T.symetrize(t, (0., 0., 0.), (1, 0, 0), (0, 0, 1))
# Rename zones with a unique name
zones = Internal.getNodesFromType(t2, 'Zone_t')
for z in zones:
    z[0] = C.getZoneName(z[0])
# Reorder created zones
t2 = T.reorder(t2, (-1, 2, 3))
# Merge both trees into one into 2 separated bases
t = C.mergeTrees(t, t2)
# Remove the BCSymmetryPlane
t = C.rmBCOfType(t, 'BCSymmetryPlane')
# Computes the BCMatch instead of symmetry plane
t = X.connectMatch(t)
# Output
C.convertPyTree2File(t, 'mesh.cgns')
コード例 #4
0
ファイル: TFIPT_t2.py プロジェクト: MicK7/cassiopee_anaconda
# - TFI 3D structure -
import Generator.PyTree as G
import Converter.PyTree as C
import Transform.PyTree as T
import KCore.test as test

xo = 0.; yo = 0.; zo = 0.
nx = 21; ny = 21; nz = 21 
hx = 1./(nx-1); hy = 1./(ny-1); hz = 1./(nz-1)

# grilles z = cste 
fzmin = G.cart((xo,yo,zo), (hx,hy,1.), (nx,ny,1))
fzmax = T.translate(fzmin, (0.,0.,1.))

# grilles x = cste
fxmin = G.cart((xo,yo,zo),(1,hy,hz),(1,ny,nz))
fxmin = T.reorder(fxmin,(3,1,2))
fxmax = T.translate(fxmin, (1.,0.,0.))

# grilles y = cste
fymin = G.cart((xo,yo,zo),(hx,1.,hz),(nx,1,nz))
fymin = T.reorder(fymin,(1,3,2))
fymax = T.translate(fymin, (0.,1.,0.))

r = [fxmin,fxmax,fymin,fymax,fzmin,fzmax]
m = G.TFI(r)
test.testT(m)
コード例 #5
0
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')
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')
コード例 #6
0
ni = 30
nj = 40
a = G.cart((0, 0, 0), (10. / (ni - 1), 10. / (nj - 1), 1), (ni, nj, 1))
a = C.initVars(a, 'centers:cellN', 1.)
a = C.initVars(a, 'Density', F, ['CoordinateX', 'CoordinateY'])
a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imax')
a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmax')

#-------------------------------------------------
# test 1 : blocs recouvrants pareillement orientes
#-------------------------------------------------
b = T.rotate(a, (0.2, 0.2, 0.), (0., 0., 1.), 15.)
b[0] = 'cart2'
B = T.reorderAll([a, b], 1)
test.testT(B, 1)

#-------------------------------------------------
# test 2 : blocs recouvrants orientes differemment
#-------------------------------------------------
b = T.reorder(b, (-1, 2, 3))
B = T.reorderAll([a, b], 1)
test.testT(B, 2)

#---------------------------------
# test 3: blocs sans intersection
#---------------------------------
b = T.translate(a, (0., 12, 0.))
A = [a, b]
B = T.reorderAll(A)
test.testT(B, 3)
コード例 #7
0
# - extractBCMatch (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as CP
import Converter.Internal as Internal
import Transform.PyTree as T
import Connector.PyTree as X
import KCore.test as test

# Cas 2D
# ======
a = G.cart((1, 1, 1), (1., 1., 1.), (4, 10, 1))
a[0] = 'cart1'
b = G.cart((4, 2, 1), (1., 1., 1.), (5, 8, 1))
b[0] = 'cart2'
a = T.reorder(a, (2, -1, 3))

t = CP.newPyTree(['Base', a, b])
t = CP.initVars(t, '{F}=3*{CoordinateX}+2*{CoordinateY}')
t = CP.initVars(t, '{centers:G}=2.3')
t = CP.initVars(t, '{centers:H}={centers:CoordinateY}')
t = CP.initVars(t, '{centers:M}={centers:CoordinateX}')
t = X.connectMatch(t, dim=2)
t = CP.fillEmptyBCWith(t, "wall", 'BCWall')

zones = Internal.getZones(t)
it = 0

for z in zones:
    it = it + 1
    dim = Internal.getZoneDim(z)
    gcs = Internal.getNodesFromType2(z, 'GridConnectivity1to1_t')
コード例 #8
0
# - getSmoothNormalMap (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T
import Geom.PyTree as D

a = G.cart((0.,0.,0.),(1.,1.,1.),(10,10,1))
b = G.cart((0.,0.,0.),(1.,1.,1.),(1,10,10))
b = T.rotate(b,(0.,0.,0.),(0.,1.,0.),45.)
c = C.convertArray2Hexa([a,b])
c = T.join(c); c = T.reorder(c,(1,))
c = T.rotate(c,(0.,0.,0.),(0.,1.,0.),15.)
c = G.getSmoothNormalMap(c,niter=4)
C.convertPyTree2File(c, "out.cgns")
コード例 #9
0
# - makeCartesian(pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import KCore.test as test
a = G.cart((0., 0., 0.), (1., 1., 1.), (10, 10, 10))
a = T.reorder(a, (3, 2, -1))
a = T.makeCartesianXYZ(a)
test.testT(a)
コード例 #10
0
ni = 30
nj = 30
nk = 10
lx = 1.
ly = 1.
lz = 0.25
dx = lx / float(ni - 1)
dy = ly / float(nj - 1)
dz = lz / float(nk - 1)

a = G.cart((1, 1, 1), (dx, dy, dz), (ni, nj, nk))
a[0] = 'cart1'
b = G.cart((lx + 1, 1 + 15. * dy, 1), (dx, dy, dz), (ni, nj, nk))
b[0] = 'cart2'
c = G.cart((lx + 1, 1 - 14. * dy, 1), (dx, dy, dz), (ni, nj, nk))
c[0] = 'cart3'

a = T.reorder(a, (3, 1, 2))

t = C.newPyTree(['Base', a, b, c])
t = C.initVars(t, '{centers:F}={centers:CoordinateX}*{centers:CoordinateY}')
t = C.initVars(t, '{G}=2.3')
t = C.initVars(t, '{centers:H}={centers:CoordinateY}')
t = C.initVars(t, '{centers:M}={centers:CoordinateX}')
t = X.connectMatch(t)
t = C.fillEmptyBCWith(t, "wall", 'BCWall')

P._computeGrad2(t, 'centers:F')

test.testT(t, 1)
コード例 #11
0
# - reorder (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.PyTree as C
import KCore.test as test
import Post.PyTree as P
import Geom.PyTree as D

# tests sur une zone de l'arbre
# reorder a Cartesian structured mesh
a = G.cart((0, 0, 0), (1, 1, 1), (8, 9, 20))
C._initVars(a, '{Density}={CoordinateX}**2+2*{CoordinateY}')
C._initVars(a, '{centers:F}={centers:CoordinateX}')
a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imax')
a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmax')
a = T.reorder(a, (2, 1, -3))
test.testT(a, 1)

# reorder a TRI mesh
a = G.cartTetra((0, 0, 0), (1, 1, 1), (8, 9, 1))
C._initVars(a, '{Density}={CoordinateX}**2+2*{CoordinateY}')
C._initVars(a, '{centers:F}={centers:CoordinateX}')
a = T.reorder(a, (-1, ))
test.testT(a, 2)

# reorder a QUAD mesh
a = G.cartHexa((0, 0, 0), (1, 1, 1), (8, 9, 1))
C._initVars(a, '{Density}={CoordinateX}**2+2*{CoordinateY}')
C._initVars(a, '{centers:F}={centers:CoordinateX}')
a = T.reorder(a, (-1, ))
test.testT(a, 3)
コード例 #12
0
# - polyLineMesher (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T

tb = C.convertFile2PyTree('fusee.plt')
tb = G.close(tb,1e-2); tb = T.reorder(tb,(-1,2,3))
h = 0.02; hf = 0.0001; density = 500

res = G.polyLineMesher(tb[2][1][2][0], h, hf, density)
zones = res[0]; h = res[1]; density = res[2]
t = C.newPyTree(['PolyC1']); t[2][1][2] += zones
C.convertPyTree2File(t, 'out.cgns')
コード例 #13
0
a = C.addBC2Zone(a, 'wall1', 'BCWall', 'jmin')
a = C.addBC2Zone(a, 'wall2', 'BCWall', 'kmin')
a = C.addBC2Zone(a, 'match1', 'BCMatch', 'imin', a, 'imax', [1, 2, 3])
a = C.addBC2Zone(a, 'match2', 'BCMatch', 'imax', a, 'imin', [1, 2, 3])
a = C.fillEmptyBCWith(a, 'overlap', 'BCOverlap')
a = C.initVars(a, 'Density', 1.)
a = C.initVars(a, 'centers:cellN', 1.)
t = G.getRegularityMap(a)
test.testT(t, 1)

# Test 2D structure
msh = D.naca(12., 5001)
# Distribution
Ni = 300
Nj = 50
distrib = G.cart((0, 0, 0), (1. / (Ni - 1), 0.5 / (Nj - 1), 1), (Ni, Nj, 1))
a = G.hyper2D(msh, distrib, "C")
a = T.reorder(a, (-3, 2, 1))
a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin')
a = C.initVars(a, 'Density', 1.)
a = C.initVars(a, 'centers:cellN', 1.)
t = G.getRegularityMap(a)
test.testT(t, 2)

# Test 1D structure
a = G.cart((0., 0., 0.), (0.1, 0.1, 0.2), (1, 10, 1))
a = C.initVars(a, 'Density', 1.)
a = C.initVars(a, 'centers:cellN', 1.)
t = G.getRegularityMap(a)
test.testT(t, 3)
コード例 #14
0
# - reorder (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.PyTree as C

a = G.cart((0,0,0), (1,1,1), (8,9,20))
a = T.reorder(a, (2,1,-3))
C.convertPyTree2File(a, "out.cgns")
コード例 #15
0
# - makeDirect (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import KCore.test as test

a = G.cart((0., 0., 0.), (1., 1., 1.), (10, 10, 10))
a = T.reorder(a, (1, 2, -3))  # indirect now
a = T.makeDirect(a)
test.testT(a, 1)
コード例 #16
0
# - getSmoothNormalMap (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T
import KCore.test as test
a = G.cart((0., 0., 0.), (1., 1., 1.), (10, 10, 1))
b = G.cart((0., 0., 0.), (1., 1., 1.), (1, 10, 10))
b = T.rotate(b, (0., 0., 0.), (0., 1., 0.), 45.)
#QUAD
c = C.convertArray2Hexa([a, b])
c = T.join(c)
c = T.reorder(c, (1, ))
c = T.rotate(c, (0., 0., 0.), (0., 1., 0.), 15.)
c = G.getSmoothNormalMap(c, niter=4)
test.testT(c, 1)
#QUAD
c = C.convertArray2Tetra([a, b])
c = T.join(c)
c = T.reorder(c, (1, ))
c = T.rotate(c, (0., 0., 0.), (0., 1., 0.), 15.)
c = G.getSmoothNormalMap(c, niter=4)
test.testT(c, 2)
コード例 #17
0
def walkOut():
    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
    # Constraints
    name = VARS[0].get()
    names = name.split(';')
    constraints = []
    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]): constraints.append(z)
                
    # surfaces
    name = VARS[1].get()
    names = name.split(';')
    surfaces = []
    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]): surfaces.append(z)
                    
    # - Hauteur de chaque maille -
    dhloc = CTK.varsFromWidget(VARS[2].get(), type=1); dhloc = dhloc[0]
    N = CTK.varsFromWidget(VARS[3].get(), type=2); N = N[0]
    dh = G.cart((0.,0.,0.),(dhloc,1.,1.),(N+1,1,1))

    # - nb d'iterations de lissage -
    nit = CTK.varsFromWidget(VARS[4].get(), type=2); nit = nit[0]
    # - contour -
    nzs = CPlot.getSelectedZones()
    if (nzs == []):
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error'); return
    CTK.saveTree()
    contours = []
    for nz in nzs:
        nob = CTK.Nb[nz]+1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        contour = C.convertBAR2Struct(z)
        contour = T.reorder(contour,(-1,2,3))
        contours.append(contour)
    # surfaceWalk
    zlist = []
    fail = False; errors = []
    for c in contours:
        try:
            z = G.surfaceWalk(surfaces, c, dh, constraints=constraints,
                              niter=nit, check=1)
            zlist.append(z)
        except Exception as e:
            fail = True; errors += [0,str(e)]
            
    # Ajout dans la base SURFACES
    CTK.t = C.addBase2PyTree(CTK.t, 'SURFACES')
    bases = Internal.getNodesFromName1(CTK.t, 'SURFACES')
    nob = C.getNobOfBase(bases[0], CTK.t)
    for i in zlist: CTK.add(CTK.t, nob, -1, i)
    #C._fillMissingVariables(CTK.t)
    if not fail: CTK.TXT.insert('START', 'Surface walk done.\n')
    else:
        Panels.displayErrors(errors, header='Error: surfaceWalk')
        CTK.TXT.insert('START', 'Surface walk fails for at least one zone.\n')
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CTK.display(CTK.t)
コード例 #18
0
# - polyLineMesher (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T

tb = C.convertFile2PyTree('fusee.plt')
tb = G.close(tb, 1e-2)
tb = T.reorder(tb, (-1, 2, 3))
h = 0.02
hf = 0.0001
density = 500

res = G.polyLineMesher(tb[2][1][2][0], h, hf, density)
zones = res[0]
h = res[1]
density = res[2]
t = C.newPyTree(['PolyC1'])
t[2][1][2] += zones
C.convertPyTree2File(t, 'out.cgns')
コード例 #19
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()
コード例 #20
0
# - getSharpestAngle (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T
import Geom.PyTree as D

N = 10
d1 = G.cart((0.,0.,0.), (0.05,1,1),(N,1,4)) 
d2 = G.cart((0.,0.,0.), (1.,0.001,1),(1,10*N,4))
d2 = T.rotate(d2,(0.,0.,0.),(0.,0.,1.),30.)
s = T.join(d1,d2)
s = C.convertArray2Hexa(s)
s = T.reorder(s,(-1,))
s = D.getSharpestAngle(s)
ts = C.newPyTree(['Base',2]); ts[2][1][2] +=[s]
C.convertPyTree2File(ts,"out.cgns")
コード例 #21
0
# - 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")
コード例 #22
0
# - reorderAll (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T

ni = 30; nj = 40; nk = 1
m1 = G.cart((0,0,0), (10./(ni-1),10./(nj-1),1), (ni,nj,nk)); m1[0]='cart1'
m2 = T.rotate(m1, (0.2,0.2,0.), (0.,0.,1.), 15.)
m2 = T.reorder(m2,(-1,2,3)); m2[0]='cart2'
t = C.newPyTree(['Base',2,[m1,m2]])
t = T.reorderAll(t, 1)
C.convertPyTree2File(t, "out.cgns")
コード例 #23
0
import Connector.PyTree as X
import Generator.PyTree as G
import Geom.PyTree as D
import Post.PyTree as P
import KCore.test as test
import Transform.PyTree as T
#import sys
#import time, datetime
#tdebut = time.time()

# Test 1
# Tet mask
m = G.cart((0., 0., 0.), (0.1, 0.1, 0.2), (10, 10, 10))
m = P.exteriorFaces(m)
m = C.convertArray2Tetra(m)
m = T.reorder(m, (-1, ))
#C.convertPyTree2File(m, 'm.plt')
# Mesh to blank
a = G.cart((-5., -5., -5.), (0.5, 0.5, 0.5), (100, 100, 100))
t = C.newPyTree(['Cart'])
t[2][1][2].append(a)
# celln init
t = C.initVars(t, 'nodes:cellN', 1.)
#C.convertPyTree2File(t, 'b.plt')
# Blanking
t = X.blankCellsTri(t, [[m]], [],
                    blankingType="node_in",
                    tol=1.e-12,
                    cellnval=4,
                    overwrite=1)
#C.convertPyTree2File(t, 'out1t.cgns')
コード例 #24
0
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.PyTree as C
import KCore.test as test

# reorder a Cartesian structured mesh
a = G.cart((0, 0, 0), (1, 1, 1), (8, 9, 20))
C._initVars(a, '{Density}={CoordinateX}**2+2*{CoordinateY}')
C._initVars(a, 'centers:cellN', 1.)
C._initVars(a, '{Density}={CoordinateX}**2+2*{CoordinateY}')
a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imax')
a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'jmax')
t = C.newPyTree(['Base'])
t[2][1][2].append(a)
t[2][1] = C.addState(t[2][1], 'EquationDimension', 3)
t = T.reorder(t, (2, 1, -3))
test.testT(t, 1)

# reorder a TRI mesh
a = G.cartTetra((0, 0, 0), (1, 1, 1), (8, 9, 1))
C._initVars(a, '{Density}={CoordinateX}**2+2*{CoordinateY}')
#C._initVars(a,'centers:cellN',1.)
t = C.newPyTree(['Base', 2, a])
t[2][1] = C.addState(t[2][1], 'EquationDimension', 2)
t = T.reorder(t, (-1, ))
test.testT(t, 2)

# reorder a QUAD mesh
a = G.cartHexa((0, 0, 0), (1, 1, 1), (8, 9, 1))
C._initVars(a, '{Density}={CoordinateX}**2+2*{CoordinateY}')
#C._initVars(a, 'centers:cellN', 1.)
コード例 #25
0
# - 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)
コード例 #26
0
import Post.PyTree as P
import KCore.test as test

# cas simple
a = D.circle((0., 0., 0.), 1.)
a = C.convertArray2Hexa(a)
a = G.close(a)
a = C.initVars(a, 'F=3*{CoordinateX}+4*{CoordinateY}')
a = C.initVars(a, 'centers:D={CoordinateX}')
b = C.convertBAR2Struct(a)
t = C.newPyTree(['Base', 1, b])
test.testT(t, 1)
#
# cas ou la bar n'est pas ordonnee - pas de boucle
#
a1 = G.cart((0., 0., 0.), (0.1, 0.1, 0.1), (11, 11, 1))
a2 = G.cart((0., 1., 0.), (0.1, 0.1, 0.1), (11, 1, 11))
a2 = T.rotate(a2, (0., 1., 0.), (1, 0, 0), -55)
A = [a1, a2]
A = C.convertArray2Hexa(A)
a = T.join(A)
a = T.reorder(a, (1, ))
a = P.sharpEdges(a, 30.)[0]
a = G.close(a)
a = C.initVars(a, 'F=3*{CoordinateX}+4*{CoordinateY}')
a = C.initVars(a, 'centers:D', 1.)
b = C.convertBAR2Struct(a)
t = C.newPyTree(['Base', 1])
t[2][1][2] += [b]
test.testT(t, 2)
コード例 #27
0
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
test.testT(t2, 2)
#
# cas d'angles vifs
#
a1 = G.cart((0, 0, 0), (1, 1, 1), (11, 11, 1))
a3 = G.cart((10, 0, 0), (1, 1, 1), (11, 11, 1))
a2 = T.rotate(a1, (0, 0, 0), (1, 0, 0), 90.)
a2 = T.reorder(a2, (-1, 2, 3))
a2[0] = C.getZoneName(a1[0])
t = C.newPyTree(['Base', 2])
t[2][1][2] += [a1, a2, a3]
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 = X.connectMatch(t, dim=2)
t = C.fillEmptyBCWith(t, 'wall', 'BCWall', dim=2)
a = T.merge(t, alphaRef=45.)
t = C.newPyTree(['Base', 2])
t[2][1][2] += a
test.testT(t, 3)

# volume grid
a = D.surface(f, N=50)
コード例 #28
0
import Converter.PyTree as C
import Converter.Internal as Internal
import Transform.PyTree as T
import Connector.PyTree as X
import KCore.test as test

Nj = 5
a = G.cart((1, 1, 1), (1., 1., 1.), (4, Nj, 6))
a[0] = 'cart1'
b = G.cart((4, 1, 1), (1., 1., 1.), (3, Nj, 3))
b[0] = 'cart2'
c = G.cart((4, 1, 3), (1., 1., 1.), (3, Nj, 6))
c[0] = 'cart3'
d = G.cart((1, 1, 6), (1., 1., 1.), (4, Nj, 3))
d[0] = 'cart4'
a = T.reorder(a, (-2, 1, 3))
b = T.reorder(b, (1, 2, 3))
c = T.reorder(c, (3, 1, 2))

# init cellN
a = C.initVars(a, 'centers:cellN', 1.)
b = C.initVars(b, 'centers:cellN', 0.)
c = C.initVars(c, 'centers:cellN', 1.)
d = C.initVars(d, 'centers:cellN', 0.)

t = C.newPyTree(['Base', a, b, c, d])
t = C.initVars(t, '{F}=3*{CoordinateX}+2*{CoordinateY}')
t = C.initVars(t, '{centers:G}={centers:CoordinateZ}')
t = X.connectMatch(t, dim=3)
t = C.fillEmptyBCWith(t, 'wall', 'BCWall')
t = Internal.addGhostCells(t, t, 2, adaptBCs=0, fillCorner=1)
コード例 #29
0
# 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.
    b = G.cart((x, ymin - 1, zmin - 1), (dx, ymax - ymin + 2, zmax - zmin + 2),
               (2, 2, 2))
    b = P.exteriorFaces(b)
    b = C.convertArray2Tetra(b)
    b = T.join(b)
    b = G.close(b)
    b = T.reorder(b, (-1, ))
    band = G.booleanIntersection(a, b)
    bands += [band]

# Boolean operators do not keep field
bands = P.extractMesh(a, bands)

# Sortie
t = C.newPyTree(['Base'])
t[2][1][2] += bands
C.convertPyTree2File(t, 'out.cgns')
コード例 #30
0
# - extractAllBCMatch (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Transform.PyTree as T
import Connector.PyTree as X
import KCore.test as test

a = G.cart((1,1,1), (1.,1.,1.), (4,10,3)); a[0]='cart1'
b = G.cart((4,2,0), (1.,1.,1.), (5, 8,5)); b[0]='cart2'

a = T.reorder(a,(-3,1,-2))

t = C.newPyTree(['Base',a,b])

t = C.initVars(t, '{F}=3*{CoordinateX}+2*{CoordinateY}')
t = C.initVars(t, '{centers:G}=2.53')
t = C.initVars(t, '{centers:H}={centers:CoordinateY}')
t = C.initVars(t, '{centers:M}={centers:CoordinateX}')
t = X.connectMatch(t,dim=3)
t = C.fillEmptyBCWith(t,"wall",'BCWall')

dico = C.extractAllBCMatch(t,['centers:G','centers:M']) 
test.testO(dico, 1)

dico = C.extractAllBCMatch(t)
test.testO(dico, 2)