예제 #1
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()
예제 #2
0
def setCanvas(event=None):
    dir = VARS[0].get()
    CTK.saveTree()
    deleteCanvasBase()
    CTK.t = C.addBase2PyTree(CTK.t, 'CANVAS', 2)

    size = CANVASSIZE
    if dir == 'View':
        a = G.cart((-size, 0, -size), (2 * size, 2 * size, 2 * size),
                   (2, 1, 2))
        a = T.translate(a, (XC, YC, ZC))
        a = T.rotate(a, (XC, YC, ZC), ((1, 0, 0), (0, 1, 0), (0, 0, 1)),
                     ((-DIRX, -DIRY, -DIRZ), (LX, LY, LZ), (UX, UY, UZ)))
        VARS[1].set(str(XC) + ';' + str(YC) + ';' + str(ZC))
    elif dir == 'YZ':
        a = G.cart((0, -size, -size), (2 * size, 2 * size, 2 * size),
                   (1, 2, 2))
        a = T.translate(a, (XC, YC, ZC))
        VARS[1].set(str(XC))
    elif dir == 'XZ':
        a = G.cart((-size, 0, -size), (2 * size, 2 * size, 2 * size),
                   (2, 1, 2))
        a = T.translate(a, (XC, YC, ZC))
        VARS[1].set(str(YC))
    else:
        a = G.cart((-size, -size, 0), (2 * size, 2 * size, 2 * size),
                   (2, 2, 1))
        a = T.translate(a, (XC, YC, ZC))
        VARS[1].set(str(ZC))
    nodes = Internal.getNodesFromName1(CTK.t, 'CANVAS')
    base = nodes[0]
    nob = C.getNobOfBase(base, CTK.t)
    CTK.add(CTK.t, nob, -1, a)

    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
예제 #3
0
def translateClick():
    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
    prev = []
    w = WIDGETS['translate']
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        nzs = CPlot.getSelectedZones()
        CTK.TXT.insert('START', 'Click start point...\n')
        TTK.sunkButton(w)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            l = []
            while l == []:
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if CTK.__BUSY__ == False: break
            if CTK.__BUSY__:
                if prev == []:
                    prev = l
                    if nzs == []: nzs = CPlot.getSelectedZones()
                    CTK.TXT.insert('START', 'Click end point...\n')
                elif prev != l:
                    CTK.saveTree()
                    vx = l[0] - prev[0]
                    vy = l[1] - prev[1]
                    vz = l[2] - prev[2]
                    for nz in nzs:
                        nob = CTK.Nb[nz] + 1
                        noz = CTK.Nz[nz]
                        z = CTK.t[2][nob][2][noz]
                        a = T.translate(z, (vx, vy, vz))
                        CTK.replace(CTK.t, nob, noz, a)
                    CTK.TKTREE.updateApp()
                    CTK.TXT.insert('START', 'Zones translated.\n')
                    CPlot.render()
                    prev = []
                    break
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
    else:
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
예제 #4
0
def translate():
    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
    v = CTK.varsFromWidget(VARS[0].get(), type=1)
    if len(v) != 3:
        CTK.TXT.insert('START', 'Translation vector 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()
    axis = VARS[6].get()
    if axis == 'along view':
        posCam = CPlot.getState('posCam')
        posEye = CPlot.getState('posEye')
        dirCam = CPlot.getState('dirCam')
        axe1 = (posEye[0] - posCam[0], posEye[1] - posCam[1],
                posEye[2] - posCam[2])
        axe2 = dirCam
        axe3 = (axe1[1] * axe2[2] - axe1[2] * axe2[1],
                axe1[2] * axe2[0] - axe1[0] * axe2[2],
                axe1[0] * axe2[1] - axe1[1] * axe2[0])
        axe1 = Vector.normalize(axe1)
        axe2 = Vector.normalize(axe2)
        axe3 = Vector.normalize(axe3)
        ax = v[0] * axe1[0] + v[1] * axe2[0] + v[2] * axe3[0]
        ay = v[0] * axe1[1] + v[1] * axe2[1] + v[2] * axe3[1]
        az = v[0] * axe1[2] + v[1] * axe2[2] + v[2] * axe3[2]
        v[0] = ax
        v[1] = ay
        v[2] = az

    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        a = T.translate(CTK.t[2][nob][2][noz], (v[0], v[1], v[2]))
        CTK.replace(CTK.t, nob, noz, a)
    CTK.TXT.insert('START', 'Zones have been translated.\n')
    CTK.TKTREE.updateApp()
    CPlot.render()
# - collarMesh (pyTree)
import Converter.PyTree as C
import Geom.PyTree as D
import Transform.PyTree as T
import Generator.PyTree as G

s1 = D.sphere((0., 0., 0.), 1, 20)
s2 = T.translate(s1, (1.2, 0., 0.))
s2 = T.homothety(s2, (0, 0, 0), 0.5)
dhj = G.cart((0., 0., 0.), (1.e-2, 1, 1), (21, 1, 1))
dhk = G.cart((0., 0., 0.), (1.e-2, 1, 1), (11, 1, 1))
a = G.collarMesh(s1, s2, dhj, dhk, niterj=100, niterk=100, type='union')
C.convertPyTree2File(a, "out.cgns")
예제 #6
0
def moveZone__(z, time):
    cont = Internal.getNodeFromName1(z, 'TimeMotion')
    if cont is not None:
        motions = Internal.getNodesFromType1(cont, 'TimeRigidMotion_t')
        for m in motions:
            type = Internal.getNodeFromName1(m, 'MotionType')
            dtype = type[1][0]
            if dtype == 1:  # type 1: time string
                tx = evalTimeString__(m, 'tx', time)
                ty = evalTimeString__(m, 'ty', time)
                tz = evalTimeString__(m, 'tz', time)
                cx = evalTimeString__(m, 'cx', time)
                cy = evalTimeString__(m, 'cy', time)
                cz = evalTimeString__(m, 'cz', time)
                ex = evalTimeString__(m, 'ex', time)
                ey = evalTimeString__(m, 'ey', time)
                ez = evalTimeString__(m, 'ez', time)
                angle = evalTimeString__(m, 'angle', time)
                z = T.translate(z, (tx, ty, tz))
                if (angle != 0):
                    z = T.rotate(z, (cx, cy, cz), (ex - cx, ey - cy, ez - cz),
                                 angle)
            elif dtype == 2:  # type 2: rotation motion CassiopeeSolver
                try:
                    import Cassiopee as K
                    import elsA_user as E  # caveat
                    import KBridge
                except:
                    raise ImportError(
                        "evalPosition: motionRotor requires CassiopeeSolver.")
                transl_speed = getNodeValue__(m, 'transl_speed')
                psi0 = getNodeValue__(m, 'psi0')
                psi0_b = getNodeValue__(m, 'psi0_b')
                alp_pnt = getNodeValue__(m, 'alp_pnt')
                alp_vct = getNodeValue__(m, 'alp_vct')
                alp0 = getNodeValue__(m, 'alp0')
                rot_pnt = getNodeValue__(m, 'rot_pnt')
                rot_vct = getNodeValue__(m, 'rot_vct')
                rot_omg = getNodeValue__(m, 'rot_omg')
                del_pnt = getNodeValue__(m, 'del_pnt')
                del_vct = getNodeValue__(m, 'del_vct')
                del0 = getNodeValue__(m, 'del0')
                delc = getNodeValue__(m, 'delc')
                dels = getNodeValue__(m, 'dels')
                bet_pnt = getNodeValue__(m, 'bet_pnt')
                bet_vct = getNodeValue__(m, 'bet_vct')
                bet0 = getNodeValue__(m, 'bet0')
                betc = getNodeValue__(m, 'betc')
                bets = getNodeValue__(m, 'bets')
                tet_pnt = getNodeValue__(m, 'tet_pnt')
                tet_vct = getNodeValue__(m, 'tet_vct')
                tet0 = getNodeValue__(m, 'tet0')
                tetc = getNodeValue__(m, 'tetc')
                tets = getNodeValue__(m, 'tets')
                span_vct = getNodeValue__(m, 'span_vct')
                pre_lag_ang = getNodeValue__(m, 'pre_lag_ang')
                pre_lag_pnt = getNodeValue__(m, 'pre_lag_pnt')
                pre_lag_vct = getNodeValue__(m, 'pre_lag_vct')
                pre_con_ang = getNodeValue__(m, 'pre_con_ang')
                pre_con_pnt = getNodeValue__(m, 'pre_con_pnt')
                pre_con_vct = getNodeValue__(m, 'pre_con_vct')

                if z[0] + '_' + m[0] not in DEFINEDMOTIONS:
                    Func1 = E.function('rotor_motion', z[0] + '_' + m[0])
                    # angle initial du rotor par rapport au champ a l'infini
                    Func1.set("psi0", float(psi0[0]))
                    # Angle initial de la pale
                    # (si z est l'axe de rotation cet angle vaut psi0_b+pi/2)
                    Func1.set("psi0_b", float(psi0_b[0]))
                    # parametres inclinaison du rotor
                    Func1.set("alp_pnt_x", float(alp_pnt[0]))
                    Func1.set("alp_pnt_y", float(alp_pnt[1]))
                    Func1.set("alp_pnt_z", float(alp_pnt[2]))
                    Func1.set("alp_vct_x", float(alp_vct[0]))
                    Func1.set("alp_vct_y", float(alp_vct[1]))
                    Func1.set("alp_vct_z", float(alp_vct[2]))
                    Func1.set("alp0", float(alp0[0]))
                    # parametres rotation uniforme du rotor
                    Func1.set("rot_pnt_x", float(rot_pnt[0]))
                    Func1.set("rot_pnt_y", float(rot_pnt[1]))
                    Func1.set("rot_pnt_z", float(rot_pnt[2]))
                    Func1.set("rot_vct_x", float(rot_vct[0]))
                    Func1.set("rot_vct_y", float(rot_vct[1]))
                    Func1.set("rot_vct_z", float(rot_vct[2]))
                    Func1.set("rot_omg", float(rot_omg[0]))
                    # parametres 1ere rotation: trainee
                    Func1.set("del_pnt_x", float(del_pnt[0]))
                    Func1.set("del_pnt_y", float(del_pnt[1]))
                    Func1.set("del_pnt_z", float(del_pnt[2]))
                    Func1.set("del_vct_x", float(del_vct[0]))
                    Func1.set("del_vct_y", float(del_vct[1]))
                    Func1.set("del_vct_z", float(del_vct[2]))
                    Func1.set("del0", float(del0[0]))
                    Func1.set("nhdel", 3)
                    Func1.set("del1c", float(delc[0]))
                    Func1.set("del1s", float(dels[0]))
                    Func1.set("del2c", float(delc[1]))
                    Func1.set("del2s", float(dels[1]))
                    Func1.set("del3c", float(delc[2]))
                    Func1.set("del3s", float(dels[2]))
                    # parametres 2eme rotation: battement
                    Func1.set("bet_pnt_x", float(bet_pnt[0]))
                    Func1.set("bet_pnt_y", float(bet_pnt[1]))
                    Func1.set("bet_pnt_z", float(bet_pnt[2]))
                    Func1.set("bet_vct_x", float(bet_vct[0]))
                    Func1.set("bet_vct_y", float(bet_vct[1]))
                    Func1.set("bet_vct_z", float(bet_vct[2]))
                    Func1.set("bet0", float(bet0[0]))
                    Func1.set("nhbet", 3)
                    Func1.set("bet1c", float(betc[0]))
                    Func1.set("bet1s", float(bets[0]))
                    Func1.set("bet2c", float(betc[1]))
                    Func1.set("bet2s", float(bets[1]))
                    Func1.set("bet3c", float(betc[2]))
                    Func1.set("bet3s", float(bets[2]))
                    # parametres 3eme rotation: pas cyclique
                    Func1.set("tet_pnt_x", float(tet_pnt[0]))
                    Func1.set("tet_pnt_y", float(tet_pnt[1]))
                    Func1.set("tet_pnt_z", float(tet_pnt[2]))
                    Func1.set("tet_vct_x", float(tet_vct[0]))
                    Func1.set("tet_vct_y", float(tet_vct[1]))
                    Func1.set("tet_vct_z", float(tet_vct[2]))
                    Func1.set("tet0", float(tet0[0]))
                    Func1.set("nhtet", 1)
                    Func1.set("tet1c", float(tetc[0]))
                    Func1.set("tet1s", float(tets[0]))
                    Func1.set('span_vct_x', float(span_vct[0]))
                    Func1.set('span_vct_y', float(span_vct[1]))
                    Func1.set('span_vct_z', float(span_vct[2]))
                    Func1.set('pre_lag_ang', float(pre_lag_ang[0]))
                    Func1.set('pre_lag_pnt_x', float(pre_lag_pnt[0]))
                    Func1.set('pre_lag_pnt_y', float(pre_lag_pnt[1]))
                    Func1.set('pre_lag_pnt_z', float(pre_lag_pnt[2]))
                    Func1.set('pre_lag_vct_x', float(pre_lag_vct[0]))
                    Func1.set('pre_lag_vct_y', float(pre_lag_vct[1]))
                    Func1.set('pre_lag_vct_z', float(pre_lag_vct[2]))
                    Func1.set('pre_con_ang', float(pre_con_ang[0]))
                    Func1.set('pre_con_pnt_x', float(pre_con_pnt[0]))
                    Func1.set('pre_con_pnt_y', float(pre_con_pnt[1]))
                    Func1.set('pre_con_pnt_z', float(pre_con_pnt[2]))
                    Func1.set('pre_con_vct_x', float(pre_con_vct[0]))
                    Func1.set('pre_con_vct_y', float(pre_con_vct[1]))
                    Func1.set('pre_con_vct_z', float(pre_con_vct[2]))
                    DEFINEDMOTIONS[z[0] + '_' + m[0]] = Func1
                else:
                    Func1 = DEFINEDMOTIONS[z[0] + '_' + m[0]]
                M = KBridge.evalKDesFunction(Func1, time)
                z = evalPosition___(z, None, M)
                z = T.translate(z, (transl_speed[0] * time, transl_speed[1] *
                                    time, transl_speed[2] * time))
            elif dtype == 3:  # type 3: constant transl + rotation
                transl_speed = getNodeValue__(m, 'transl_speed')
                axis_pnt = getNodeValue__(m, 'axis_pnt')
                axis_vct = getNodeValue__(m, 'axis_vct')
                omega = getNodeValue__(m, 'omega')
                tx = transl_speed[0] * time
                ty = transl_speed[1] * time
                tz = transl_speed[2] * time
                z = T.translate(z, (tx, ty, tz))
                cx = axis_pnt[0] + tx
                cy = axis_pnt[1] + ty
                cz = axis_pnt[2] + tz
                ex = axis_vct[0]
                ey = axis_vct[1]
                ez = axis_vct[2]
                angle = omega[0] * time * __RAD2DEG__
                z = T.rotate(z, (cx, cy, cz), (ex - cx, ey - cy, ez - cz),
                             angle)
    return z
예제 #7
0
# - nearestNodes (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T
import Post.PyTree as P

a = G.cart((0,0,0), (1,1,1), (10,10,10))
b = T.translate(a,(0.15,0.,0.))
f = P.exteriorFaces(b)

hook = C.createHook(a, function='nodes')
# Indices des noeuds de a les plus proches des noeuds de f
# et distance correspondante
nodes,dist = C.nearestNodes(hook, f)
print nodes,dist
import Transform.PyTree as T
import Connector.PyTree as X
import Connector.Mpi as Xmpi
import Distributor2.PyTree as Distributor2
import KCore.test as test

# Cree le fichier test
if Cmpi.rank == 0:
    Ni = 50
    Nj = 50
    Nk = 2
    a = G.cart((0, 0, 0), (1. / (Ni - 1), 1. / (Nj - 1), 1), (Ni, Nj, Nk))
    b = G.cart((0, 0, 0), (2. / (Ni - 1), 2. / (Nj - 1), 1), (Ni, Nj, Nk))
    b[0] = 'cart2'
    a = T.rotate(a, (0, 0, 0), (0, 0, 1), 10.)
    a = T.translate(a, (0.5, 0.5, 0))
    t = C.newPyTree(['Base1', 'Base2'])
    t[2][1][2].append(a)
    t[2][2][2].append(b)
    t = C.fillEmptyBCWith(t, 'overlap', 'BCOverlap', dim=2)
    t = C.addVars(t, 'Density')
    t = C.addVars(t, 'centers:Pressure')
    C.convertPyTree2File(t, 'in.cgns')
Cmpi.barrier()

t = Cmpi.convertFile2SkeletonTree('in.cgns')
import sys
sys.exit()
(t, dic) = Distributor2.distribute(t, NProc=Cmpi.size, algorithm='fast')
t = Cmpi.readZones(t, 'in.cgns', proc=Cmpi.rank)
예제 #9
0
# - setHoleInterpolatedPts (pyTree) -
import Converter.PyTree as C
import Connector.PyTree as X
import Generator.PyTree as G
import Transform.PyTree as T
import KCore.test as test
def sphere(x,y,z):
    if x*x+y*y+z*z < 0.5**2 : return 0.
    else: return 1.

# Cas structure
# Champ cellN en noeud
a = G.cart((-2.,-1.,-1.),(0.1,0.1,0.1), (21,21,21))
b = T.translate(a,(2,0,0)); b[0] = 'cart2'
t = C.newPyTree(['Cart']); t[2][1][2]+=[a,b]
t = X.connectMatch(t)
t = C.fillEmptyBCWith(t,'nref','BCFarfield')
t = C.initVars(t,'Density',1.)
t = C.initVars(t,'cellN', sphere, ['CoordinateX','CoordinateY','CoordinateZ'])
nod = 1
for d in [-2,-1,0,1,2,5]:
    t2 = X.setHoleInterpolatedPoints(t,depth=d,dir=1)
    test.testT(t2,nod); nod+=1

#
# Champ en centres
#
a = G.cart((-2.,-1.,-1.),(0.1,0.1,0.1), (21,21,21))
b = T.translate(a,(2,0,0)); b[0] = 'cart2'
t = C.newPyTree(['Cart']); t[2][1][2]+=[a,b]
t = X.connectMatch(t)
import Connector.PyTree as X
import Generator.PyTree as G
import Transform.PyTree as T
import KCore.test as test


def sphere(x, y, z):
    if x * x + y * y + z * z < 0.5**2: return 0.
    else: return 1.


#
# Champ en noeuds non structure PENTA
#
a = G.cartPenta((-2., -1., -1.), (0.1, 0.1, 0.1), (21, 21, 21))
b = T.translate(a, (2, 0, 0))
b[0] = 'cart2'
t = C.newPyTree(['Cart'])
t[2][1][2] += [a, b]
t = C.initVars(t, 'Density', 1.)
t = C.initVars(t, 'cellN', sphere,
               ['CoordinateX', 'CoordinateY', 'CoordinateZ'])
nod = 1
for d in [-2, -1, 0, 1, 2, 5]:
    t2 = X.setHoleInterpolatedPoints(t, depth=d)
    test.testT(t2, nod)
    nod += 1

# Champ cellN en centres
a = G.cartPenta((-2., -1., -1.), (0.1, 0.1, 0.1), (21, 21, 21))
b = T.translate(a, (2, 0, 0))
예제 #11
0
def getListOfOffBodyIntersectingNBZones(tBB,
                                        noBaseOff,
                                        NIT=1,
                                        DEPTH=2,
                                        RotationCenter=None,
                                        RotationAngle=None,
                                        Translation=None):

    rotation = True
    translation = True
    if RotationAngle is None: rotation = False
    if Translation is None: translation = False
    if rotation is True and translation is True:
        raise ValueError(
            "ToolboxIBM: translation and rotation not yet possible together.")
    constantMotion = False
    if rotation:
        if len(RotationAngle) == 3 and isinstance(RotationAngle[0],
                                                  list) == False:
            constantMotion = True
    if translation:
        if len(Translation) == 3 and isinstance(Translation[0], list) == False:
            constantMotion = True

    xc0 = RotationCenter[0]
    yc0 = RotationCenter[1]
    zc0 = RotationCenter[2]

    listOfOffBodyIntersectingNBZones = []
    C._initVars(tBB[2][noBaseOff], "{CoordinateXInit}={CoordinateX}")
    C._initVars(tBB[2][noBaseOff], "{CoordinateYInit}={CoordinateY}")
    C._initVars(tBB[2][noBaseOff], "{CoordinateZInit}={CoordinateZ}")

    for it in range(NIT):
        if constantMotion:
            if rotation:
                angleX = RotationAngle[0] * it
                angleY = RotationAngle[1] * it
                angleZ = RotationAngle[2] * it
                print('Rotation (degres) : (alphaX=%g,alphaY=%g,alphaZ=%g)' %
                      (angleX, angleY, angleZ))
            elif translation:
                tx = Translation[0]
                ty = Translation[1]
                tz = Translation[2]
        else:
            if rotation:
                angleX = RotationAngle[it][0]
                angleY = RotationAngle[it][1]
                angleZ = RotationAngle[it][2]
                print('Rotation (degres) : (alphaX=%g,alphaY=%g,alphaZ=%g)' %
                      (angleX, angleY, angleZ))
            elif translation:
                tx = Translation[it][0]
                ty = Translation[it][1]
                tz = Translation[it][2]

        # on fait bouger le maillage de fond dans le mvt oppose - pour ne pas bouger ts les maillages proches corps
        if rotation:
            tBB[2][noBaseOff] = T.rotate(tBB[2][noBaseOff], (xc0, yc0, zc0),
                                         (-angleX, -angleY, -angleZ))
        elif translation:
            tBB[2][noBaseOff] = T.translate(tBB[2][noBaseOff], (-tx, -ty, -tz))

        for nob in range(len(tBB[2])):
            if nob != noBaseOff and Internal.getType(
                    tBB[2][nob]) == 'CGNSBase_t':
                dictOfIntersectingZones = X.getIntersectingDomains(
                    tBB[2][nob],
                    t2=tBB[2][noBaseOff],
                    method='AABB',
                    taabb=tBB[2][nob],
                    taabb2=tBB[2][noBaseOff])
                for bodyZone in dictOfIntersectingZones:
                    listOfOffBodyIntersectingNBZones += dictOfIntersectingZones[
                        bodyZone]
                listOfOffBodyIntersectingNBZones = list(
                    set(listOfOffBodyIntersectingNBZones))

        C._initVars(tBB[2][noBaseOff], "{CoordinateX}={CoordinateXInit}")
        C._initVars(tBB[2][noBaseOff], "{CoordinateY}={CoordinateYInit}")
        C._initVars(tBB[2][noBaseOff], "{CoordinateZ}={CoordinateZInit}")

    listOfOffBodyIntersectingNBZones = list(
        set(listOfOffBodyIntersectingNBZones))
    return listOfOffBodyIntersectingNBZones
# - conformUnstr (pyTree) -
# Conforming 1 or 2 TRI/BAR together (same type for both operands)
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.)
예제 #13
0
# - usurp (pyTree)-
import Post.PyTree as P
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T
import KCore.test as test

# Creation des cylindres
a1 = G.cylinder((0, 0, 0), 0, 2, 360, 0, 1., (100, 2, 10))
a1 = T.subzone(a1, (1, 2, 1), (100, 2, 10))
a1[0] = 'cyl1'
a1 = C.addBC2Zone(a1, 'overlap', 'BCOverlap', 'imin')
a1 = C.fillEmptyBCWith(a1, 'nref', 'BCFarfield')
a2 = G.cylinder((0, 0, 0), 0, 2, 90, 0, 0.5, (10, 2, 10))
a2 = T.translate(a2, (0, 0, 0.2))
a2 = T.subzone(a2, (1, 2, 1), (10, 2, 10))
a2[0] = 'cyl2'

# creation des celln
C._addVars(a1, 'Density')
C._initVars(a1, 'centers:cellN', 1.)
C._initVars(a2, 'centers:cellN', 1.)
t = C.newPyTree(['Base', 2])
t[2][1][2] += [a1, a2]
t[2][1] = C.addState(t[2][1], 'Mach', 0.6)
try:
    t = P.usurp(t)
    test.testT(t[2][1][2][0])
except:
    pass
예제 #14
0
tsph = GP.sphere6((0, 0, 0), 1., N=3, ntype='TRI')
tsph = C.convertLO2HO(tsph, 0)
for i in range(C.getNPts(tsph)):
    x = C.getValue(tsph, 'CoordinateX', i)
    y = C.getValue(tsph, 'CoordinateY', i)
    z = C.getValue(tsph, 'CoordinateZ', i)
    nrm = sqrt(x * x + y * y + z * z)
    x /= nrm
    y /= nrm
    z /= nrm
    C.setValue(tsph, 'CoordinateX', i, x)
    C.setValue(tsph, 'CoordinateY', i, y)
    C.setValue(tsph, 'CoordinateZ', i, z)

tsph = T.translate(tsph, (3., 0, 0))
t = C.newPyTree(['Base1', 'Base2'])
t[2][1][2] += Ci.getZones(qsph)
t[2][2][2] += Ci.getZones(tsph)

for shader in [
        "Chrome", "Glass", "Wood", 'Marble', 'XRay', 'Metal', 'Granite',
        'Brick', 'Cloud', 'Gooch'
]:
    s = CPlot.addRender2Zone(t, material=shader, color='White')
    CPlot.display(s, mode="Render")
    l = ''
    while (l != 'n'):
        l = CPlot.getKeyboard()
        CPlot.resetKeyboard()
예제 #15
0
# - splitSize (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.PyTree as C
import Connector.PyTree as X
import KCore.test as test

t = C.newPyTree(['Base'])
a = G.cart((0, 0, 0), (1, 1, 1), (51, 21, 11))
a[0] = 'cart1'
a2 = T.translate(a, (46, 0, 0))
a2[0] = 'cart2'
a3 = T.translate(a, (-50, 0, 0))
a3[0] = 'cart3'
a = C.addBC2Zone(a, 'overlap1', 'BCOverlap', 'imax')
a2 = C.addBC2Zone(a2, 'overlap2', 'BCOverlap', 'imin')
t[2][1][2] += [a, a2, a3]
t = C.fillEmptyBCWith(t, 'wall', 'BCWall')
t[2][1] = C.addState(t[2][1], 'EquationDimension', 3)
t = T.splitSize(t, 700)
t = X.connectMatch(t)
test.testT(t)
# - display (pyTree) -
# Affichage des shaders (mode solid)
import Geom.PyTree as D
import CPlot.PyTree as CPlot
import Transform.PyTree as T
import Converter.PyTree as C
import time

a = D.sphere((0, 0, 0), 1.)
a = CPlot.addRender2Zone(a, material='Chrome', color='White')

b = T.translate(a, (0, 2.5, 0))
b = CPlot.addRender2Zone(b, material='Glass', color='Blue')

c = T.translate(a, (0, 5., 0))
c = CPlot.addRender2Zone(c, material='Wood', color='Brown')

d = T.translate(a, (0, 0, -2.5))
d = CPlot.addRender2Zone(d, material='Marble', color='Yellow')

e = T.translate(a, (0, 2.5, -2.5))
e = CPlot.addRender2Zone(e, material='XRay', color='Blue')

f = T.translate(a, (0, 5, -2.5))
f = CPlot.addRender2Zone(f, material='Metal', color='Blue')

i = T.translate(a, (0, 0, -5))
i = CPlot.addRender2Zone(i, material='Granite', color='White')

g = T.translate(a, (0, 2.5, -5.))
g = C.initVars(g,
예제 #17
0
# - stack (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Transform.PyTree as T

a = G.cylinder((0, 0, 0), 1, 1.3, 360, 0, 1., (50, 10, 1))
b = T.rotate(a, (0, 0, 0), (1, 0, 0), 5.)
b = T.translate(b, (0, 0, 0.5))
c = G.stack(a, b)
C.convertPyTree2File(c, 'out.cgns')
예제 #18
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()
예제 #19
0
def replaceText(event=None):
    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
    nzs = CPlot.getSelectedZones()
    if nzs == []:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    CTK.saveTree()
    # Recupere l'OBB de la selection
    Z = []
    dels = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        Z.append(CTK.t[2][nob][2][noz])
        dels.append(CTK.t[2][nob][0] + Internal.SEP1 +
                    CTK.t[2][nob][2][noz][0])
    nob0 = CTK.Nb[nzs[0]] + 1
    try:
        a = T.join(Z)
    except:
        a = Z[0]
    OBB = G.BB(a, method='OBB')

    P0 = C.getValue(OBB, 'GridCoordinates', 0)
    P1 = C.getValue(OBB, 'GridCoordinates', 1)
    P2 = C.getValue(OBB, 'GridCoordinates', 2)
    P3 = C.getValue(OBB, 'GridCoordinates', 4)
    v1 = Vector.sub(P1, P0)
    n1 = Vector.norm(v1)
    v2 = Vector.sub(P2, P0)
    n2 = Vector.norm(v2)
    v3 = Vector.sub(P3, P0)
    n3 = Vector.norm(v3)
    v1p = v1
    v2p = v2
    v3p = v3
    if abs(n1) < 1.e-12:
        v1 = Vector.cross(v2, v3)
        v1p = (0., 0., 0.)
    elif abs(n2) < 1.e-12:
        v2 = Vector.cross(v1, v3)
        v2p = (0., 0., 0.)
    elif abs(n3) < 1.e-12:
        v3 = Vector.cross(v2, v3)
        v3p = (0., 0., 0.)

    # Essaie de matcher les vecteur sur la vue p1,p2,p3
    # On suppose que dirCam doit etre e2, ...
    posCam = CPlot.getState('posCam')
    posEye = CPlot.getState('posEye')
    dirCam = CPlot.getState('dirCam')
    e2 = dirCam
    e3 = Vector.sub(posCam, posEye)
    e1 = Vector.cross(e2, e3)

    f1 = None
    f2 = None
    f3 = None
    Pt = P0
    s1 = Vector.dot(e1, v1)
    s2 = Vector.dot(e1, v2)
    s3 = Vector.dot(e1, v3)
    if abs(s1) > abs(s2) and abs(s1) > abs(s3):
        if s1 > 0: f1 = v1
        else:
            f1 = Vector.mul(-1., v1)
            Pt = Vector.add(Pt, v1p)
    elif abs(s2) > abs(s1) and abs(s2) > abs(s3):
        if s2 > 0: f1 = v2
        else:
            f1 = Vector.mul(-1., v2)
            Pt = Vector.add(Pt, v2p)
    elif abs(s3) > abs(s1) and abs(s3) > abs(s2):
        if s3 > 0: f1 = v3
        else:
            f1 = Vector.mul(-1., v3)
            Pt = Vector.add(Pt, v3p)
    s1 = Vector.dot(e2, v1)
    s2 = Vector.dot(e2, v2)
    s3 = Vector.dot(e2, v3)
    if abs(s1) > abs(s2) and abs(s1) > abs(s3):
        if s1 > 0: f2 = v1
        else:
            f2 = Vector.mul(-1., v1)
            Pt = Vector.add(Pt, v1p)
    elif abs(s2) > abs(s1) and abs(s2) > abs(s3):
        if s2 > 0: f2 = v2
        else:
            f2 = Vector.mul(-1., v2)
            Pt = Vector.add(Pt, v2p)
    elif abs(s3) > abs(s1) and abs(s3) > abs(s2):
        if s3 > 0: f2 = v3
        else:
            f2 = Vector.mul(-1., v3)
            Pt = Vector.add(Pt, v3p)
    s1 = Vector.dot(e3, v1)
    s2 = Vector.dot(e3, v2)
    s3 = Vector.dot(e3, v3)
    if abs(s1) > abs(s2) and abs(s1) > abs(s3):
        if s1 > 0: f3 = v1
        else:
            f3 = Vector.mul(-1., v1)
            Pt = Vector.add(Pt, v1p)
    elif abs(s2) > abs(s1) and abs(s2) > abs(s3):
        if s2 > 0: f3 = v2
        else:
            f3 = Vector.mul(-1., v2)
            Pt = Vector.add(Pt, v2p)
    elif abs(s3) > abs(s1) and abs(s3) > abs(s2):
        if s3 > 0: f3 = v3
        else:
            f3 = Vector.mul(-1., v3)
            Pt = Vector.add(Pt, v3p)
    (x0, y0, z0) = Pt
    n2 = Vector.norm(f2)

    # Cree le texte
    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
    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)
    BB = G.bbox(a)
    h2 = BB[4] - BB[1]

    # Scale, positionne le texte
    factor = n2 / h2
    a = T.homothety(a, (BB[0], BB[1], BB[2]), factor)
    a = T.translate(a, (x0 - BB[0], y0 - BB[1], z0 - BB[2]))
    a = T.rotate(a, (x0, y0, z0), ((1, 0, 0), (0, 1, 0), (0, 0, 1)),
                 ((f1, f2, f3)))

    CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs)
    CPlot.delete(dels)
    CTK.add(CTK.t, nob0, -1, a)
    #C._fillMissingVariables(CTK.t)
    CTK.TXT.insert('START', 'Text replaced.\n')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
예제 #20
0
# - blankIntersectingCells (pyTree)
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T
import Connector.PyTree as X

a1 = G.cart((0., 0., 0.), (1., 1., 1.), (11, 11, 11))
a2 = T.rotate(a1, (0., 0., 0.), (0., 0., 1.), 10.)
a2 = T.translate(a2, (7., 5., 5.))
a1[0] = 'cart1'
a2[0] = 'cart2'
t = C.newPyTree(['Base', a1, a2])
t = C.initVars(t, 'centers:cellN', 1.)
t2 = X.blankIntersectingCells(t, tol=1.e-10)
C.convertPyTree2File(t2, "out.cgns")
# - splitMultiplePts (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import Converter.PyTree as C
import Connector.PyTree as X

nk = 2
z0 = G.cart((0., 0., 0.), (0.1, 0.1, 1.), (10, 10, nk))
z1 = T.subzone(z0, (1, 1, 1), (5, 10, nk))
z1[0] = 'cart1'
z2 = T.subzone(z0, (5, 1, 1), (10, 5, nk))
z2[0] = 'cart2'
z3 = T.subzone(z0, (5, 5, 1), (10, 10, nk))
z3[0] = 'cart3'
z0 = T.translate(z0, (-0.9, 0., 0.))
z0[0] = 'cart0'
z4 = G.cart((-0.9, 0.9, 0.), (0.1, 0.1, 1.), (19, 5, nk))
z4[0] = 'cart4'
t = C.newPyTree(['Base', z1, z2, z3, z4])
t = X.connectMatch(t, dim=2)
t = C.fillEmptyBCWith(t, 'wall', 'BCWall', dim=2)
t = T.splitMultiplePts(t, dim=2)
C.convertPyTree2File(t, 'out.cgns')
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)
예제 #23
0
def prepareMotionChimeraData(t,
                             tc,
                             tblank,
                             noBaseOff,
                             tBB=None,
                             DEPTH=2,
                             loc='centers',
                             NIT=1,
                             RotationCenter=None,
                             RotationAngle=None,
                             Translation=None,
                             listOfSteadyOffBodyZones=None,
                             listOfOffBodyIntersectingNBZones=None):

    # arbre de BBox des zones donneuses
    if tBB is None: tBB = G.BB(tc)  # BB des zones donneuses

    if listOfOffBodyIntersectingNBZones is None:
        listOfOffBodyIntersectingNBZones = getListOfOffBodyIntersectingNBZones(
            tBB,
            noBaseOff,
            NIT=NIT,
            DEPTH=DEPTH,
            RotationCenter=RotationCenter,
            RotationAngle=RotationAngle,
            Translation=Translation)
        listOfSteadyOffBodyZones = getListOfSteadyOffBodyZones(
            tBB, noBaseOff, listOfOffBodyIntersectingNBZones)

    if listOfSteadyOffBodyZones is None:
        listOfSteadyOffBodyZones = getListOfSteadyOffBodyZones(
            tBB, noBaseOff, listOfOffBodyIntersectingNBZones)

    dimPb = Internal.getNodeFromName(t, 'EquationDimension')
    if dimPb is None:
        raise ValueError('EquationDimension is missing in input body tree.')
    dimPb = Internal.getValue(dimPb)
    if dimPb == 2:
        z0 = Internal.getNodeFromType2(t, 'Zone_t')
        dims = Internal.getZoneDim(z0)
        npts = dims[1] * dims[2] * dims[3]
        zmin = C.getValue(z0, 'CoordinateZ', 0)
        zmax = C.getValue(z0, 'CoordinateZ', npts - 1)
        dz = zmax - zmin
        # Creation du corps 2D pour le preprocessing IBC
        tblank = T.addkplane(tblank)
        tblank = T.contract(tblank, (0, 0, 0), (1, 0, 0), (0, 1, 0), dz)

    rotation = True
    translation = True
    if RotationAngle is None: rotation = False
    if Translation is None: translation = False
    if rotation is True and translation is True:
        raise ValueError(
            "ToolboxIBM: translation and rotation not yet possible together.")
    constantMotion = False
    if rotation:
        if len(RotationAngle) == 3 and isinstance(RotationAngle[0],
                                                  list) == False:
            constantMotion = True
    if translation:
        if len(Translation) == 3 and isinstance(Translation[0], list) == False:
            constantMotion = True

    xc0 = RotationCenter[0]
    yc0 = RotationCenter[1]
    zc0 = RotationCenter[2]

    C._initVars(t[2][noBaseOff], '{centers:cellNInit}={centers:cellN}')
    C._initVars(tc[2][noBaseOff], "{cellNInit}={cellN}")
    dictOfNearBodyBaseNb = {}
    dictOfNearBodyZoneNb = {}
    for nob in range(len(tc[2])):
        if nob != noBaseOff:
            base = tc[2][nob]
            if Internal.getType(base) == 'CGNSBase_t':
                for noz in range(len(base[2])):
                    zone = base[2][noz]
                    if Internal.getType(zone) == 'Zone_t':
                        zname = zone[0]
                        dictOfNearBodyZoneNb[zname] = noz
                        dictOfNearBodyBaseNb[zname] = nob

    dictOfOffBodyZoneNb = {}
    dictOfOffBodyADT = {}  # preconditionnement
    for noz in range(len(tc[2][noBaseOff][2])):
        z = tc[2][noBaseOff][2][noz]
        zname = z[0]
        if Internal.getType(z) == 'Zone_t':
            dictOfOffBodyZoneNb[zname] = noz
            if zname in listOfOffBodyIntersectingNBZones:
                zc = tc[2][noBaseOff][2][noz]
                hook0 = C.createHook(zc, 'adt')
                dictOfOffBodyADT[zname] = hook0

    C._initVars(tc, '{CoordinateXInit}={CoordinateX}')
    C._initVars(tc, '{CoordinateYInit}={CoordinateY}')
    C._initVars(tc, '{CoordinateZInit}={CoordinateZ}')
    C._initVars(t, '{CoordinateXInit}={CoordinateX}')
    C._initVars(t, '{CoordinateYInit}={CoordinateY}')
    C._initVars(t, '{CoordinateZInit}={CoordinateZ}')
    C._initVars(tBB, '{CoordinateXInit}={CoordinateX}')
    C._initVars(tBB, '{CoordinateYInit}={CoordinateY}')
    C._initVars(tBB, '{CoordinateZInit}={CoordinateZ}')

    if NIT > 1:
        for zc in Internal.getZones(tc):
            IDatas = Internal.getNodesFromName(zc, "ID_*")
            for ID in IDatas:
                name = ID[0].split('_')
                ID[0] = 'IDSteady_%s' % (name[1])

    tloc = C.newPyTree(['OffMotion'])
    for zr in t[2][noBaseOff][2]:
        if Internal.getType(zr) == 'Zone_t':
            znamer = zr[0]
            if znamer not in listOfSteadyOffBodyZones:
                # print " Zone de fond en mvt %s"%znamer
                tloc[2][1][2].append(zr)
            else:
                tloc[2][1][2].append(zr)
        tBBloc = G.BB(tloc)

    # a remonter dans l interface
    intersectionsDictOffOff = X.getIntersectingDomains(tBB[2][noBaseOff],
                                                       method='AABB',
                                                       taabb=tBB[2][noBaseOff])
    listOfIntersectionDictsNBNB = {}
    for nob in range(len(t[2])):
        if nob != noBaseOff and Internal.getType(t[2][nob]) == 'CGNSBase_t':
            intersectionsDictNB = X.getIntersectingDomains(tBB[2][nob],
                                                           method='AABB',
                                                           taabb=tBB[2][nob])
            listOfIntersectionDictsNBNB[nob] = intersectionsDictNB

    for it in range(NIT):
        print(' ------------------- Iteration %d ----------------------- ' %
              it)
        if constantMotion:
            if rotation:
                angleX = RotationAngle[0] * it
                angleY = RotationAngle[1] * it
                angleZ = RotationAngle[2] * it
                print('Rotation (degres) : (alphaX=%g,alphaY=%g,alphaZ=%g)' %
                      (angleX, angleY, angleZ))

            elif translation:
                tx = Translation[0]
                ty = Translation[1]
                tz = Translation[2]
        else:
            if rotation:
                angleX = RotationAngle[it][0]
                angleY = RotationAngle[it][1]
                angleZ = RotationAngle[it][2]
                print('Rotation (degres) : (alphaX=%g,alphaY=%g,alphaZ=%g)' %
                      (angleX, angleY, angleZ))

            elif translation:
                tx = Translation[it][0]
                ty = Translation[it][1]
                tz = Translation[it][2]

        if rotation:
            tblankM = T.rotate(tblank, (xc0, yc0, zc0),
                               (angleX, angleY, angleZ))
        elif translation:
            tblankM = T.translate(tblank, (tx, ty, tz))

        C._initVars(tloc, "{centers:cellN}={centers:cellNInit}")
        tloc = blankByIBCBodies(tloc,
                                tblankM,
                                'centers',
                                dim=dimPb,
                                gridType='composite')
        tloc = X.setHoleInterpolatedPoints(tloc, depth=DEPTH, loc='centers')
        for zloc in Internal.getZones(tloc):
            zname = zloc[0]
            nozloc = dictOfOffBodyZoneNb[zname]
            C._cpVars(zloc, 'centers:cellN', tc[2][noBaseOff][2][nozloc],
                      "cellN")

        dictOfMotionADT = {
        }  # ADT des blocs en mvt  a detruire a chq pas de temps

        # bases proches corps interpolees par le maillage de fond fixe + ses voisins
        for nob in range(len(t[2])):
            base = t[2][nob]
            if nob != noBaseOff and Internal.getType(base) == 'CGNSBase_t':
                if rotation:
                    T._rotate(base, (xc0, yc0, zc0), (angleX, angleY, angleZ))
                    T._rotate(tBB[2][nob], (xc0, yc0, zc0),
                              (angleX, angleY, angleZ))
                    T._rotate(tc[2][nob], (xc0, yc0, zc0),
                              (angleX, angleY, angleZ))
                elif translation:
                    T._translate(base, (tx, ty, tz))
                    T._translate(tBB[2][nob], (tx, ty, tz))
                    T._translate(tc[2][nob], (tx, ty, tz))

        tBBNB = Internal.rmNodesByName(tBB, tBB[2][noBaseOff][0])
        intersectionsDictOffNB = X.getIntersectingDomains(
            tBB[2][noBaseOff],
            t2=tBBNB,
            method='AABB',
            taabb=tBB[2][noBaseOff],
            taabb2=tBBNB)
        for nob in range(len(t[2])):
            base = t[2][nob]
            if nob != noBaseOff and Internal.getType(base) == 'CGNSBase_t':
                # test intersection entre maillage proche corps et maillage de fond
                intersectionsDictNBO = X.getIntersectingDomains(
                    tBB[2][nob],
                    t2=tBB[2][noBaseOff],
                    method='AABB',
                    taabb=tBB[2][nob],
                    taabb2=tBB[2][noBaseOff])

                print('Near-body base %s in motion' % (base[0]))
                intersectionsDictNBNB = listOfIntersectionDictsNBNB[nob]
                for zr in Internal.getZones(base):
                    if Internal.getNodesFromName(zr, "ov_ext*") != []:
                        znamer = zr[0]
                        donorZones = []
                        hooks = []
                        for znamed in intersectionsDictNBO[znamer]:
                            if znamed in dictOfOffBodyZoneNb:  # donneur=fond
                                nozd = dictOfOffBodyZoneNb[znamed]
                                zd = tc[2][noBaseOff][2][nozd]
                                hooks.append(dictOfOffBodyADT[znamed])
                                donorZones.append(zd)
                        for znamed in intersectionsDictNBNB[znamer]:
                            nozd = dictOfNearBodyZoneNb[znamed]
                            nobd = dictOfNearBodyBaseNb[znamed]
                            zd = tc[2][nobd][2][nozd]
                            if znamed not in dictOfMotionADT:
                                hook0 = C.createHook(zd, 'adt')
                                dictOfMotionADT[znamed] = hook0
                            hooks.append(dictOfMotionADT[znamed])
                            donorZones.append(zd)

                        donorZones = X.setInterpData(zr,donorZones,nature=1,penalty=1,loc='centers',storage='inverse',sameName=1,\
                                                     hook=hooks, itype='chimera')
                        for zd in donorZones:
                            znamed = zd[0]
                            if znamed in dictOfOffBodyZoneNb:
                                nozd = dictOfOffBodyZoneNb[znamed]
                                tc[2][noBaseOff][2][nozd] = zd
                            elif znamed in dictOfNearBodyZoneNb:
                                nozd = dictOfNearBodyZoneNb[znamed]
                                nobd = dictOfNearBodyBaseNb[znamed]
                                tc[2][nobd][2][nozd] = zd

        # base de fond : interpolee depuis ses zones voisines + zones proches corps
        # les donneurs proches corps mobiles sont deja deplaces
        # intersectionsDict = X.getIntersectingDomains(tBBloc,t2=tBB,method='AABB',taabb=tBBloc,taabb2=tBB)
        for zr in Internal.getZones(tloc):
            znamer = zr[0]
            if znamer not in listOfSteadyOffBodyZones:
                donorZones = []
                hooks = []
                for znamed in intersectionsDictOffOff[
                        znamer]:  # donneur=maillage de fond
                    nozd = dictOfOffBodyZoneNb[znamed]
                    zd = tc[2][noBaseOff][2][nozd]
                    if znamed not in dictOfOffBodyADT:
                        hook0 = C.createHook(zd, 'adt')
                        dictOfOffBodyADT[znamed] = hook0
                    hooks.append(dictOfOffBodyADT[znamed])
                    donorZones.append(zd)
                for znamed in intersectionsDictOffNB[znamer]:
                    nozd = dictOfNearBodyZoneNb[znamed]
                    nobd = dictOfNearBodyBaseNb[znamed]
                    zd = tc[2][nobd][2][nozd]
                    if znamed not in dictOfMotionADT:
                        hook0 = C.createHook(zd, 'adt')
                        dictOfMotionADT[znamed] = hook0
                    hooks.append(dictOfMotionADT[znamed])
                    donorZones.append(zd)

                # print 'Off-body motion zone %s'%znamer
                donorZones = X.setInterpData(zr,donorZones,nature=1,penalty=1,loc='centers',storage='inverse',sameName=1,\
                                             hook=hooks, itype='chimera')
                for zd in donorZones:
                    znamed = zd[0]
                    if znamed in dictOfOffBodyZoneNb:
                        nozd = dictOfOffBodyZoneNb[znamed]
                        tc[2][noBaseOff][2][nozd] = zd
                    elif znamed in dictOfNearBodyZoneNb:
                        nozd = dictOfNearBodyZoneNb[znamed]
                        nobd = dictOfNearBodyBaseNb[znamed]
                        tc[2][nobd][2][nozd] = zd

        for dnrname in dictOfMotionADT:
            C.freeHook(dictOfMotionADT[dnrname])

        # Reinit
        if NIT == 1:
            for dnrname in dictOfOffBodyADT:
                C.freeHook(dictOfOffBodyADT[dnrname])
            C._rmVars(tc, [
                "CoordinateX", "CoordinateY", "CoordinateZ", "cellNInit",
                "CoordinateXInit", "CoordinateYInit", "CoordinateZInit"
            ])
            C._initVars(t, '{CoordinateX}={CoordinateXInit}')
            C._initVars(t, '{CoordinateY}={CoordinateYInit}')
            C._initVars(t, '{CoordinateZ}={CoordinateZInit}')
            C._rmVars(t, [
                "centers:cellNInit", "CoordinateXInit", "CoordinateYInit",
                "CoordinateZInit"
            ])
            C._cpVars(tc, "cellN", t, 'centers:cellN')
            return t, tc

        else:
            for zc in Internal.getZones(tc):
                IDatas = Internal.getNodesFromName(zc, "ID_*")
                for ID in IDatas:
                    name = ID[0].split('_')
                    ID[0] = 'ID#%d_%s' % (it, name[1])

            if it == 5:
                C.convertPyTree2File(t, "t5.cgns")
                C.convertPyTree2File(tc, "tc5.cgns")
            C._initVars(tc[2][noBaseOff], "{cellN}={cellNInit}")  # reinit
            C._initVars(t[2][noBaseOff],
                        "{centers:cellN}={centers:cellNInit}")  # reinit
            C._initVars(tc, '{CoordinateX}={CoordinateXInit}')
            C._initVars(tc, '{CoordinateY}={CoordinateYInit}')
            C._initVars(tc, '{CoordinateZ}={CoordinateZInit}')
            C._initVars(t, '{CoordinateX}={CoordinateXInit}')
            C._initVars(t, '{CoordinateY}={CoordinateYInit}')
            C._initVars(t, '{CoordinateZ}={CoordinateZInit}')
            C._initVars(tBB, '{CoordinateX}={CoordinateXInit}')
            C._initVars(tBB, '{CoordinateY}={CoordinateYInit}')
            C._initVars(tBB, '{CoordinateZ}={CoordinateZInit}')

    for dnrname in dictOfOffBodyADT:
        C.freeHook(dictOfOffBodyADT[dnrname])

    C._rmVars(t, [
        "centers:cellNInit", "CoordinateXInit", "CoordinateYInit",
        "CoordinateZInit"
    ])
    C._initVars(tc[2][noBaseOff], "{cellN}={cellNInit}")
    C._cpVars(tc, "cellN", t, "centers:cellN")
    C._rmVars(
        tc,
        ["cellNInit", "CoordinateXInit", "CoordinateYInit", "CoordinateZInit"])
    return t, tc
예제 #24
0
# - 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)
예제 #25
0
# - collarMesh (pyTree) 
import Converter.PyTree as C
import Geom.PyTree as D
import Transform.PyTree as T
import Generator.PyTree as G

s1 = D.sphere((0.,0.,0.),1,20)
s2 = T.translate(s1,(1.2,0.,0.)); s2 = T.homothety(s2,(0,0,0),0.5)
dhj = G.cart((0.,0.,0.),(1.e-2,1,1),(21,1,1))
dhk = G.cart((0.,0.,0.),(1.e-2,1,1),(11,1,1))
a = G.collarMesh(s1,s2, dhj,dhk,niterj=100,niterk=100,type='union')
C.convertPyTree2File(a,"out.cgns")