Example #1
0
def setTime(event=None):
    if CTK.t == []: return
    walls = VARS[3].get()
    time = CTK.varsFromWidget(VARS[1].get(), type=1)
    if len(time) != 1:
        CTK.TXT.insert('START', 'Invalid time.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    time = time[0]
    t0 = CTK.varsFromWidget(VARS[0].get(), type=1)[0]
    tf = CTK.varsFromWidget(VARS[2].get(), type=1)[0]
    step = (tf - t0) / 100.

    if CTK.__MAINTREE__ == 1:
        CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones()
    if walls == '1' and CTK.dt == []:
        zones = Internal.getZones(CTK.t)
        Z = buildWalls(zones)
        CTK.dt = C.newPyTree(['Base'])
        CTK.dt[2][1][2] += Z

    if walls == '1': temp = RM.evalPosition(CTK.dt, time)
    else: temp = RM.evalPosition(CTK.t, time)

    WIDGETS['slider'].set((time - t0) / step)
    WIDGETS['slider'].update()
    CTK.display(temp, mainTree=CTK.TIME)
Example #2
0
def playForward(event=None):
    if CTK.t == []: return
    walls = VARS[3].get()
    t0 = CTK.varsFromWidget(VARS[0].get(), type=1)[0]
    time = CTK.varsFromWidget(VARS[1].get(), type=1)[0]
    tf = CTK.varsFromWidget(VARS[2].get(), type=1)[0]
    step = (tf - t0) / 100.

    if CTK.__MAINTREE__ == 1:
        CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones()

    if (walls == '1' and CTK.dt == []):
        zones = Internal.getNodesFromType(CTK.t, 'Zone_t')
        Z = buildWalls(zones)
        CTK.dt = C.newPyTree(['Base'])
        CTK.dt[2][1][2] += Z

    CTK.__BUSY__ = True
    CPlot.setState(cursor=2)
    while (time < tf and CTK.__BUSY__):
        if (walls == '1'): temp = RM.evalPosition(CTK.dt, time)
        else: temp = RM.evalPosition(CTK.t, time)
        CTK.display(temp, mainTree=CTK.TIME)
        time += step
        VARS[1].set(str(time))
        WIDGETS['slider'].set((time - t0) / step)
        WIDGETS['time'].update()
        WIDGETS['slider'].update()
    CTK.__BUSY__ = False
    CPlot.setState(cursor=0)
Example #3
0
def setVars3(event=None):
    nzs = CPlot.getSelectedZones()
    if (nzs == []):
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    name = VARS[0].get()
    CTK.saveTree()

    transl_speed = CTK.varsFromWidget(VARS[43].get(), 1)
    axis_pnt = CTK.varsFromWidget(VARS[44].get(), 1)
    axis_vct = CTK.varsFromWidget(VARS[45].get(), 1)
    omega = VARS[46].get()

    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        CTK.t[2][nob][2][noz] = RM.setPrescribedMotion3(
            z,
            name,
            transl_speed=transl_speed,
            axis_pnt=axis_pnt,
            axis_vct=axis_vct,
            omega=omega)
    CTK.TKTREE.updateApp()
    CTK.TXT.insert('START', 'Motion set in selected zones.\n')
Example #4
0
def extendSurf():
    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

    # surfaces
    name = VARS[0].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[1].get(), type=1)
    dhloc = dhloc[0]
    N = CTK.varsFromWidget(VARS[2].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[3].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)
        contours.append(contour)

    # Extension
    zlist = G.buildExtension(contours, surfaces, dh, niter=nit)
    c = 0
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        CTK.t[2][nob][2][noz] = zlist[c]
        c += 1

    CTK.TXT.insert('START', 'Surface extension done.\n')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CTK.display(CTK.t)
Example #5
0
def setSlider(event=None):
    t0 = CTK.varsFromWidget(VARS[0].get(), type=1)[0]
    tf = CTK.varsFromWidget(VARS[2].get(), type=1)[0]
    st = WIDGETS['slider'].get()
    step = (tf - t0) / 100.
    time = st * step + t0
    VARS[1].set(str(time))
    VARS[4].set('Time [%g].' % time)
Example #6
0
def find(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
    if len(nzs) != 1:
        CTK.TXT.insert('START', 'Only one block must be selected.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    nz = nzs[0]
    nob = CTK.Nb[nz] + 1
    noz = CTK.Nz[nz]
    z = CTK.t[2][nob][2][noz]
    type = VARS[0].get()
    if type == 'Node index':
        inds = CTK.varsFromWidget(VARS[1].get(), type=3)
        if len(inds) == 0:
            CTK.TXT.insert('START', 'Invalid index.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
            return
        [px, py, pz] = C.getValue(z, Internal.__GridCoordinates__, inds[0])
        CTK.TXT.insert('START', 'Node %s found.\n' % VARS[1].get())
    elif type == 'Coordinates':
        vars = CTK.varsFromWidget(VARS[1].get(), type=1)
        if len(vars) != 3:
            CTK.TXT.insert('START', 'Invalid coordinates.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
            return
        [px, py, pz] = vars
        CTK.TXT.insert('START', 'Coordinates %s found.\n' % VARS[1].get())
    else:  # type = element index
        inds = CTK.varsFromWidget(VARS[1].get(), type=3)
        if len(inds) == 0:
            CTK.TXT.insert('START', 'Invalid index.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
            return
        zp = Internal.copyRef(z)
        C._deleteAllBCAndSolutions__(zp)
        zp = C.node2Center(z)
        [px, py, pz] = C.getValue(zp, Internal.__GridCoordinates__, inds[0])
        CTK.TXT.insert('START', 'Element %s found.\n' % VARS[1].get())

    (xeye, yeye, zeye) = CPlot.getState('posEye')
    (xcam, ycam, zcam) = CPlot.getState('posCam')
    dx = xcam - xeye
    dy = ycam - yeye
    dz = zcam - zeye
    CPlot.setState(posEye=(px, py, pz))
    CPlot.setState(posCam=(px + dx, py + dy, pz + dz))
    CPlot.setActivePoint(px, py, pz)
def uniformize(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

    type = VARS[2].get()
    density = -1; npts = 2; factor = -1
    if type == 'Density':
        density = CTK.varsFromWidget(VARS[0].get(), 1)
        if len(density) != 1:
            CTK.TXT.insert('START', 'Invalid points density.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
        density = density[0]
    elif type == 'Npts':
        npts = CTK.varsFromWidget(VARS[0].get(), 2)
        if len(npts) != 1:
            CTK.TXT.insert('START', 'Invalid number of points.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
        npts = npts[0]
    elif type == 'Factor':
        factor = CTK.varsFromWidget(VARS[0].get(), 1)
        if len(factor) != 1:
            CTK.TXT.insert('START', 'Invalid number factor.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')

    CTK.saveTree()

    # Get first selected zone
    nz = nzs[0]
    nob = CTK.Nb[nz]+1
    noz = CTK.Nz[nz]
    zone = CTK.t[2][nob][2][noz]
    dim = Internal.getZoneDim(zone)
    if dim[0] == 'Structured':
        if dim[2] != 1 and dim[3] != 1: 
            fail = apply3D(density, npts, factor, ntype=0)
        elif dim[2] != 1 and dim[3] == 1: 
            fail = apply2D(density, npts, factor, ntype=0)
        else: fail = uniformize1D(density, npts, factor)
    else: fail = uniformize1D(density, npts, factor) # all zones

    if not fail:
        CTK.TXT.insert('START', 'Uniformize successfull.\n')
    else:
        CTK.TXT.insert('START', 'Uniformize edge fails for at least one zone.\n')
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
Example #8
0
def setInfo(event=None):
    posCam = VARS[0].get()
    posCam = CTK.varsFromWidget(posCam, 1)
    if posCam != [] and len(posCam) == 3:
        CPlot.setState(posCam=posCam)
    posEye = VARS[1].get()
    posEye = CTK.varsFromWidget(posEye, 1)
    if posEye != [] and len(posEye) == 3:
        CPlot.setState(posEye=posEye)
    dirCam = VARS[2].get()
    dirCam = CTK.varsFromWidget(dirCam, 1)
    if dirCam != [] and len(dirCam) == 3:
        CPlot.setState(dirCam=dirCam)
Example #9
0
def generatePLM():
    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 len(nzs) == 0:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    hf = CTK.varsFromWidget(VARS[1].get(), type=1)
    if (len(hf) != 1):
        CTK.TXT.insert('START', 'First cell height is incorrect.\n')
        return
    hf = hf[0]
    h = CTK.varsFromWidget(VARS[0].get(), type=1)
    if (len(h) != 1):
        CTK.TXT.insert('START', 'Mesh height is incorrect.\n')
        return
    h = h[0]
    density = CTK.varsFromWidget(VARS[2].get(), type=1)
    if (len(density) != 1):
        CTK.TXT.insert('START', 'Grid point density is incorrect.\n')
        return
    density = density[0]

    try:
        CTK.saveTree()
        CTK.t = C.addBase2PyTree(CTK.t, 'MESHES')
        bases = Internal.getNodesFromName1(CTK.t, 'MESHES')
        gnob = C.getNobOfBase(bases[0], CTK.t)
        for nz in nzs:
            nob = CTK.Nb[nz] + 1
            noz = CTK.Nz[nz]
            z = CTK.t[2][nob][2][noz]
            B = G.polyLineMesher(z, h, hf, density)
            for i in B[0]:
                CTK.add(CTK.t, gnob, -1, i)
        CTK.TXT.insert('START', 'PLM mesh created.\n')
        (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
        CTK.TKTREE.updateApp()
        CPlot.render()
    except Exception, e:
        Panels.displayErrors([0, str(e)], header='Error: PLM')
        CTK.TXT.insert('START', 'PLM mesh failed.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
Example #10
0
def remap():
    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
    a = []
    for nz in nzs:
        nob = CTK.Nb[nz]+1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        a.append(z)

    # density
    density = CTK.varsFromWidget(VARS[0].get(), type=1)
    if len(density) != 1:
        CTK.TXT.insert('START', 'Density is incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error'); return
    density = density[0]
    
    # offset
    offset = CTK.varsFromWidget(VARS[1].get(), type=1)
    if len(offset) != 1:
        CTK.TXT.insert('START', 'Offset is incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error'); return
    offset = offset[0]

    CTK.saveTree()

    if VARS[2].get() == '0': iso = withCart(a, offset, density)
    else: iso = withOctree(a, offset, density)
        
    if iso != []:
        nob = CTK.Nb[nzs[0]]+1
        for i in iso: CTK.add(CTK.t, nob, -1, i)
    
        #C._fillMissingVariables(CTK.t)
        CTK.TXT.insert('START', 'Surface filtered and offset (offset=%g).\n'%offset)
        (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
        CTK.TKTREE.updateApp()
        CPlot.render()
    else:
         CTK.TXT.insert('START', 'Surface filter failed.\n')
         CTK.TXT.insert('START', 'Error: ', 'Error')     
def addkplanes():
    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
    N = CTK.varsFromWidget(VARS[1].get(), type=2)
    if len(N) != 1:
        CTK.TXT.insert('START', 'Number of layers is incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    N = N[0]
    nzs = CPlot.getSelectedZones()
    if nzs == []:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    CTK.saveTree()
    fail = False
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        #try:
        z = T.addkplane(CTK.t[2][nob][2][noz], N=N)
        CTK.replace(CTK.t, nob, noz, z)
        #except Exception as e: fail = True
    if not fail: CTK.TXT.insert('START', 'K planes added.\n')
    else:
        CTK.TXT.insert('START', 'add K planes failed.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
Example #12
0
def streamRibbon():
    if CTK.t == []: return
    npts = CTK.varsFromWidget(VARS[0].get(), type=2)
    if len(npts) != 1:
        CTK.TXT.insert('START', 'Number of points in stream incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    npts = npts[0]
    v1 = VARS[1].get()
    v2 = VARS[2].get()
    v3 = VARS[3].get()
    CTK.TXT.insert('START', 'Click to select starting point...\n')
    l = []
    while (l == []):
        l = CPlot.getActivePoint()
        time.sleep(0.1)
    print('Ribbon: starting point %d' % l)
    CTK.saveTree()
    CTK.t = C.addBase2PyTree(CTK.t, 'STREAMS', 2)
    b = Internal.getNodesFromName1(CTK.t, 'STREAMS')
    nob = C.getNobOfBase(b[0], CTK.t)
    try:
        stream = P.streamRibbon(CTK.t, (l[0], l[1], l[2]), (0, 0, 0.01),
                                [v1, v2, v3],
                                N=npts)
        CTK.add(CTK.t, nob, -1, stream)
        CTK.TXT.insert('START', 'Stream ribbon created.\n')
    except Exception as e:
        Panels.displayErrors([0, str(e)], header='Error: streamRibbon')
        CTK.TXT.insert('START', 'Stream ribbon fails.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CTK.display(CTK.t)
Example #13
0
def compute():
    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
    type = VARS[0].get()
    var1 = VARS[2].get()

    if (type == 'INT((v1,v2,v3).ndS)' or 'INT((v1,v2,v3)^OMdS)'):
        var2 = VARS[3].get()
        var3 = VARS[4].get()
        vector = [var1, var2, var3]
    if (type == 'INT((v1,v2,v3)^OMdS)' or type == 'INT(v1n^OMdS)'):
        center = CTK.varsFromWidget(VARS[1].get(), type=1)
        if (len(center) != 3):
            CTK.TXT.insert('START',
                           'Center for moment integration 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

    res1 = 0.
    res2 = 0.
    res3 = 0.
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        if (type == 'INT(v1dS)'):
            res1 += P.integ(z, var1)[0]
        elif (type == 'INT(v1.ndS)'):
            res = P.integNorm(z, var1)[0]
            res1 += res[0]
            res2 += res[1]
            res3 += res[2]
        elif (type == 'INT((v1,v2,v3).ndS)'):
            res1 += P.integNormProduct(z, vector)
        elif (type == 'INT((v1,v2,v3)^OMdS)'):
            res = P.integMoment(z, center, vector)
            res1 += res[0]
            res2 += res[1]
            res3 += res[2]
        elif (type == 'INT(v1n^OMdS)'):
            res = P.integMomentNorm(z, center, var1)[0]
            res1 += res[0]
            res2 += res[1]
            res3 += res[2]
    if (type == 'INT((v1,v2,v3)^OMdS)' or type == 'INT(v1n^OMdS)'
            or type == 'INT(v1.ndS)'):
        res = [res1, res2, res3]
    else:
        res = res1
    CTK.TXT.insert('START', 'Res=' + str(res) + '.\n')
def smooth(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

    eps = CTK.varsFromWidget(VARS[7].get(), 1)
    if len(eps) != 1:
        CTK.TXT.insert('START', 'Invalid smoother power.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
    eps = eps[0]
    niter = CTK.varsFromWidget(VARS[6].get(), 2)
    if len(niter) != 1:
        CTK.TXT.insert('START', 'Invalid number of smoother iterations.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
    niter = niter[0]

    CTK.saveTree()

    # Get first selected zone
    nz = nzs[0]
    nob = CTK.Nb[nz]+1
    noz = CTK.Nz[nz]
    zone = CTK.t[2][nob][2][noz]
    dim = Internal.getZoneDim(zone)
    if dim[0] == 'Structured':
        if dim[2] != 1 and dim[3] != 1: 
            fail = apply3D(1., niter, eps, ntype=4)
        elif dim[2] != 1 and dim[3] == 1: 
            fail = apply2D(1., niter, eps, ntype=4)
        else: fail = smooth1D(niter, eps)
    else: fail = smooth1D(niter, eps) # all zones

    if not fail:
        CTK.TXT.insert('START', 'Smooth successfull.\n')
    else:
        CTK.TXT.insert('START', 'Smooth fails for at least one zone.\n')
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
Example #15
0
def createZEllipse():
    import Geom.PyTree as D
    import Transform.PyTree as T
    alpha = CTK.varsFromWidget(VARS[1].get(), type=2)
    if len(alpha) == 1:
        ax = alpha[0]
        ay = alpha[0]
        az = alpha[0]
        bx = alpha[0]
        by = alpha[0]
        bz = alpha[0]
    elif len(alpha) == 3:
        ax = alpha[0]
        ay = alpha[1]
        az = alpha[2]
        bx = alpha[0]
        by = alpha[1]
        bz = alpha[2]
    elif len(alpha) == 6:
        ax = alpha[0]
        ay = alpha[1]
        az = alpha[2]
        bx = alpha[3]
        by = alpha[4]
        bz = alpha[5]
    else:
        CTK.TXT.insert('START', 'Borders factor incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    try:
        box = G.bbox(CTK.t)
    except:
        box = [0, 0, 0, 1, 1, 1]
    hx = box[3] - box[0]
    hy = box[4] - box[1]
    if hx < 1.e-10: hx = 0.1
    if hy < 1.e-10: hy = 0.1

    hx = hx * 0.7 * ax
    hy = hy * 0.7 * ay
    cx = 0.5 * (box[0] + box[3])
    cy = 0.5 * (box[1] + box[4])
    if hx < hy:
        s = D.circle((cx, cy, box[2]), hx, N=50)
        s = T.contract(s, (cx, cy, box[2]), (1, 0, 0), (0, 0, 1), hy / hx)
    else:
        s = D.circle((cx, cy, box[2]), hy, N=50)
        s = T.contract(s, (cx, cy, box[2]), (0, 1, 0), (0, 0, 1), hx / hy)

    s = C.convertArray2Tetra(s)
    s = G.close(s, 1.e-6)
    p = G.fittingPlaster(s, bumpFactor=0.)
    s = G.gapfixer(s, p)
    s = CPlot.addRender2Zone(s, material='Solid', color='White', meshOverlay=0)
    return [s]
def rotate(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
    axis = VARS[2].get()
    angle = CTK.varsFromWidget(VARS[3].get(), type=1)
    if len(angle) == 1:
        angle = angle[0]
        X = None
    elif len(angle) == 4:
        X = (angle[1], angle[2], angle[3])
        angle = angle[0]
    else:
        CTK.TXT.insert('START', 'Invalid angle or angle+rotation center.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    if axis == 'around X': axe = (1., 0., 0.)
    elif axis == 'around Y': axe = (0., 1., 0.)
    elif axis == 'around Z': axe = (0., 0., 1.)
    elif axis == 'around view':
        pos = CPlot.getState('posCam')
        eye = CPlot.getState('posEye')
        axe = (eye[0] - pos[0], eye[1] - pos[1], eye[2] - pos[2])
    else:
        axe = (0., 0., 1.)
    try:
        angle = float(angle)
    except:
        angle = 0.

    nzs = CPlot.getSelectedZones()
    if nzs == []:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    CTK.saveTree()
    if X is None:
        sel = []
        for nz in nzs:
            nob = CTK.Nb[nz] + 1
            noz = CTK.Nz[nz]
            z = CTK.t[2][nob][2][noz]
            sel.append(z)
        X = G.barycenter(sel)

    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        a = T.rotate(CTK.t[2][nob][2][noz], (X[0], X[1], X[2]), axe, angle)
        CTK.replace(CTK.t, nob, noz, a)
    CTK.TXT.insert('START', 'Zones have been rotated.\n')
    CTK.TKTREE.updateApp()
    CPlot.render()
Example #17
0
def connectNearMatch():
    if CTK.t == []: return
    eps = VARS[2].get()
    eps = float(eps)
    ratio = VARS[3].get()
    ratio = CTK.varsFromWidget(ratio, type=2)

    if len(ratio) != 1 and len(ratio) != 3:
        CTK.TXT.insert('START', 'Invalid ratio for nearmatch.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    if len(ratio) == 1: ratio = ratio[0]

    node = Internal.getNodeFromName(CTK.t, 'EquationDimension')
    if node is not None: ndim = Internal.getValue(node)
    else:
        CTK.TXT.insert('START',
                       'EquationDimension not found (tkState). Using 3D.\n')
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
        ndim = 3

    nzs = CPlot.getSelectedZones()
    CTK.saveTree()
    if CTK.__MAINTREE__ <= 0 or nzs == []:
        try:
            CTK.t = X.connectNearMatch(CTK.t, ratio=ratio, tol=eps, dim=ndim)
            CTK.TKTREE.updateApp()
            CTK.TXT.insert('START', 'n/m matching BCs successfully set.\n')
        except Exception as e:
            Panels.displayErrors([0, str(e)], header='Error: connectNearMatch')
            CTK.TXT.insert('START', 'n/m matching BCs failed.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
    else:
        sel = []
        for nz in nzs:
            nob = CTK.Nb[nz] + 1
            noz = CTK.Nz[nz]
            z = CTK.t[2][nob][2][noz]
            sel.append(z)
        try:
            sel = X.connectNearMatch(sel, ratio=ratio, tol=eps, dim=ndim)
            c = 0
            for nz in nzs:
                nob = CTK.Nb[nz] + 1
                noz = CTK.Nz[nz]
                CTK.t[2][nob][2][noz] = sel[c]
                c += 1
            CTK.TKTREE.updateApp()
            CTK.TXT.insert('START', 'n/m matching BCs successfully set.\n')
        except Exception as e:
            Panels.displayErrors([0, str(e)], header='Error: connectNearMatch')
            CTK.TXT.insert('START', 'n/m matching BCs failed.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
    check()
Example #18
0
def union():
    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 len(nzs) < 2:
        CTK.TXT.insert('START', 'Please, select two or more surfaces.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    tol = CTK.varsFromWidget(VARS[0].get(), type=1)
    if len(tol) != 1:
        CTK.TXT.insert('START', 'Tolerance is incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    tol = tol[0]

    CTK.saveTree()
    zlist = []
    deletedZoneNames = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        deletedZoneNames.append(CTK.t[2][nob][0] + Internal.SEP1 +
                                CTK.t[2][nob][2][noz][0])
        z = CTK.t[2][nob][2][noz]
        zlist.append(z)

    try:
        j = XOR.booleanUnion(zlist[0], zlist[1], tol=tol)
    except Exception as e:
        Panels.displayErrors([0, str(e)], header='Error: union')
        CTK.TXT.insert('START', 'Union failed\n')
        return

    for nz in range(len(zlist) - 2):
        try:
            j = XOR.booleanUnion(j, zlist[nz + 2], tol=tol)
        except Exception as e:
            Panels.displayErrors([0, str(e)], header='Error: union')
            CTK.TXT.insert('START', 'Union failed.\n')
            return

    CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs)
    CPlot.delete(deletedZoneNames)
    CTK.add(CTK.t, CTK.Nb[0] + 1, -1, j)

    CTK.TXT.insert('START', 'Union performed.\n')
    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
Example #19
0
def runCheckPyTree():
    if CTK.t == []: return
    errors = []
    v = VARS[3].get()
    if v == 'All conformity' or v == ' > Node conformity':
        errors += Internal.checkPyTree(CTK.t, level=1)
    if v == 'All conformity' or v == ' > Unique base name':
        errors += Internal.checkPyTree(CTK.t, level=2)
    if v == 'All conformity' or v == ' > Unique zone name':
        errors += Internal.checkPyTree(CTK.t, level=3)
    if v == 'All conformity' or v == ' > Unique BC name':
        errors += Internal.checkPyTree(CTK.t, level=4)
    if v == 'All conformity' or v == ' > Valid BC ranges':
        errors += Internal.checkPyTree(CTK.t, level=5)
    if v == 'All conformity' or v == ' > Valid BC match':
        errors += Internal.checkPyTree(CTK.t, level=6)
    if v == 'All conformity' or v == ' > Referenced families':
        errors += Internal.checkPyTree(CTK.t, level=7)
    if v == 'All conformity' or v == ' > Valid CGNS types':
        errors += Internal.checkPyTree(CTK.t, level=8)
    if v == 'All conformity' or v == ' > Valid element nodes':
        errors += Internal.checkPyTree(CTK.t, level=9)
    if v == 'All conformity' or v == ' > Valid CGNS flowfield name':
        errors += Internal.checkPyTree(CTK.t, level=10)
    if v == 'Multigrid compatibility':
        MGlevel = CTK.varsFromWidget(VARS[2].get(), type=2)
        minBlk = CTK.varsFromWidget(VARS[0].get(), type=2)
        minBC = CTK.varsFromWidget(VARS[1].get(), type=2)
        if len(MGlevel) > 0 and len(minBlk) > 0 and len(minBC) > 0:
            errors += Internal.checkMultigrid(CTK.t,
                                              level=MGlevel[0],
                                              nbMinCoarseB=minBlk[0],
                                              nbMinCoarseW=minBC[0])
    if (v == 'Maximum number of nodes'):
        minBlk = CTK.varsFromWidget(VARS[0].get(), type=2)
        if len(minBlk) > 0:
            errors = Internal.checkSize(CTK.t, sizeMax=minBlk[0])

    if len(errors) == 0: errors = [0, 'No error found.']
    Panels.displayErrors(errors, header='Checking pyTree')
    CTK.TXT.insert('START', 'pyTree checked.\n')
Example #20
0
def streamSurface():
    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
    npts = CTK.varsFromWidget(VARS[0].get(), type=2)
    if (len(npts) != 1):
        CTK.TXT.insert('START', 'Number of points in stream incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    npts = npts[0]
    nzs = CPlot.getSelectedZones()
    if (nzs == []):
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    v1 = VARS[1].get()
    v2 = VARS[2].get()
    v3 = VARS[3].get()
    streams = []
    fail = False
    errors = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        z = C.convertArray2Tetra(z)
        try:
            stream = P.streamSurf(CTK.t, z, [v1, v2, v3], N=npts)
            streams.append(stream)
        except Exception as e:
            fail = True
            errors += [0, str(e)]

    CTK.saveTree()
    CTK.t = C.addBase2PyTree(CTK.t, 'STREAMS', 2)
    b = Internal.getNodesFromName1(CTK.t, 'STREAMS')
    nob = C.getNobOfBase(b[0], CTK.t)
    for i in streams:
        CTK.add(CTK.t, nob, -1, i)
    if (fail == False):
        CTK.TXT.insert('START', 'Stream surface created.\n')
    else:
        Panels.displayErrors(errors, header='Error: streamSurf')
        CTK.TXT.insert('START', 'Sream surface fails for at least one zone.\n')
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
def changeFrame():
    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

    mode = VARS[7].get()
    assert (mode in dir(T))

    args = CTK.varsFromWidget(VARS[8].get(), type=1)
    if len(args) != 6:
        CTK.TXT.insert(
            'START',
            '{} requires 6 values.\nOrigin: x0;y0;z0\n Axis tx;ty;tz.\n'.
            format(mode))
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    origin = (args[0], args[1], args[2])
    axis = (args[3], args[4], args[5])
    CTK.saveTree()

    fail = False
    errors = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        try:
            func = getattr(T, mode)
            a = func(CTK.t[2][nob][2][noz], origin, axis)
            CTK.replace(CTK.t, nob, noz, a)
        except Exception as e:
            fail = True
            errors += [0, str(e)]

    if not fail: CTK.TXT.insert('START', '{} done.\n'.format(mode))
    else:
        Panels.displayErrors(errors, header='Error: {}'.format(mode))
        CTK.TXT.insert('START',
                       '{} fails for at least one zone.\n'.format(mode))
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
    CTK.TKTREE.updateApp()
    CPlot.render()
Example #22
0
def draw():
    if CTK.t == []: return
    type = VARS[0].get()
    npts = CTK.varsFromWidget(VARS[1].get(), 2)
    if len(npts) != 1:
        CTK.TXT.insert('START', 'Invalid number of points.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
    npts = npts[0]
    if type == 'Polyline': drawPolyline()
    elif type == 'Line': drawLine(npts)
    elif type == 'Circle': drawCircle(npts)
    elif type == 'Circular arc': drawArc(npts)
    elif type == 'Rectangle': drawRectangle(npts)
    elif type == 'Cubic': drawCubic(npts)
    elif type == 'Free hand': drawFreeHand()
Example #23
0
def difference2():
    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 len(nzs) != 2:
        CTK.TXT.insert('START', 'Please, select two surfaces.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    tol = CTK.varsFromWidget(VARS[0].get(), type=1)
    if len(tol) != 1:
        CTK.TXT.insert('START', 'Tolerance is incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    tol = tol[0]

    CTK.saveTree()
    deletedZoneNames = []
    nz = nzs[0]
    nob1 = CTK.Nb[nz] + 1
    noz1 = CTK.Nz[nz]
    deletedZoneNames.append(CTK.t[2][nob1][0] + Internal.SEP1 +
                            CTK.t[2][nob1][2][noz1][0])
    z1 = CTK.t[2][nob1][2][noz1]
    nz = nzs[1]
    nob2 = CTK.Nb[nz] + 1
    noz2 = CTK.Nz[nz]
    deletedZoneNames.append(CTK.t[2][nob2][0] + Internal.SEP1 +
                            CTK.t[2][nob2][2][noz2][0])
    z2 = CTK.t[2][nob2][2][noz2]

    try:
        j = XOR.booleanMinus(z2, z1, tol=tol)
        CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs)
        CPlot.delete(deletedZoneNames)
        CTK.add(CTK.t, nob1, -1, j)
        CTK.TXT.insert('START', 'Difference performed.\n')
    except Exception as e:
        Panels.displayErrors([0, str(e)], header='Error: difference')
        CTK.TXT.insert('START', 'Difference failed.\n')

    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
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()
Example #25
0
def createPoint(event=None):
    point = CTK.varsFromWidget(VARS[0].get(), type=1)
    if len(point) != 3:
        CTK.TXT.insert('START', 'Point coords are incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    CTK.saveTree()
    CTK.t = C.addBase2PyTree(CTK.t, 'POINTS', 1)
    base = Internal.getNodesFromName1(CTK.t, 'POINTS')
    base = base[0]
    nob = C.getNobOfBase(base, CTK.t)
    a = D.point((point[0], point[1], point[2]))
    CTK.add(CTK.t, nob, -1, a)
    CTK.TXT.insert('START', 'Point ' + VARS[0].get() + ' created.\n')
    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
Example #26
0
def createZPlane():
    alpha = CTK.varsFromWidget(VARS[1].get(), type=2)
    if len(alpha) == 1:
        ax = alpha[0]
        ay = alpha[0]
        az = alpha[0]
        bx = alpha[0]
        by = alpha[0]
        bz = alpha[0]
    elif len(alpha) == 3:
        ax = alpha[0]
        ay = alpha[1]
        az = alpha[2]
        bx = alpha[0]
        by = alpha[1]
        bz = alpha[2]
    elif len(alpha) == 6:
        ax = alpha[0]
        ay = alpha[1]
        az = alpha[2]
        bx = alpha[3]
        by = alpha[4]
        bz = alpha[5]
    else:
        CTK.TXT.insert('START', 'Borders factor incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    try:
        box = G.bbox(CTK.t)
    except:
        box = [0, 0, 0, 1, 1, 1]
    hx = box[3] - box[0]
    hy = box[4] - box[1]
    if hx < 1.e-10: hx = 0.1
    if hy < 1.e-10: hy = 0.1

    hx = hx * 0.5
    hy = hy * 0.5
    b = G.cart((box[0] - ax * hx, box[1] - ay * hy, box[2]), (hx, hy, 1),
               (ax + bx + 3, ay + by + 3, 1))
    b = CPlot.addRender2Zone(b, material='Solid', color='White', meshOverlay=1)
    return [b]
def expandLayer():
    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
    level = CTK.varsFromWidget(VARS[4].get(), type=2)
    if level == []:
        CTK.TXT.insert('START', 'Invalid level.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    else:
        level = level[0]
    CTK.saveTree()
    nzs = CPlot.getSelectedZones()
    if nzs == []:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    fail = False
    errors = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        try:
            z = G.expandLayer(z, level=level)
            CTK.replace(CTK.t, nob, noz, z)
        except Exception as e:
            fail = True
            errors += [0, str(e)]

    #C._fillMissingVariables(CTK.t)
    if not fail:
        CTK.TXT.insert('START', 'Level %d expanded.\n' % level)
    else:
        Panels.displayErrors(errors, header='Error: expandLayers')
        CTK.TXT.insert('START', 'Expand layer fails for at least one zone.\n')
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
def enforce(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

    h = CTK.varsFromWidget(VARS[1].get(), 1)
    if len(h) != 1:
        CTK.TXT.insert('START', 'Invalid spacing.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
    h = h[0]

    CTK.saveTree()
    
    # Get first selected zone
    nz = nzs[0]
    nob = CTK.Nb[nz]+1
    noz = CTK.Nz[nz]
    zone = CTK.t[2][nob][2][noz]
    dim = Internal.getZoneDim(zone)
    if dim[0] == 'Structured':
        if dim[2] != 1 and dim[3] != 1: 
            fail = apply3D(1., 1, h, ntype=2)
        elif dim[2] != 1 and dim[3] == 1: 
            fail = apply2D(1., 1, h, ntype=2)
        else: fail = stretch1D(h)
    else: fail = stretch1D(h)

    if not fail:
        CTK.TXT.insert('START', 'Stretch successfull.\n')
    else:
        CTK.TXT.insert('START', 'stretch failed.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
    #C.fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
Example #29
0
def setCanvasPos(event=None):
    if CTK.t == []: return
    global XC, YC, ZC
    dir = VARS[0].get()
    res = CTK.varsFromWidget(VARS[1].get(), type=1)
    if dir == 'View':
        if (len(res) != 3):
            CTK.TXT.insert('START', 'xc;yc;zc is incorrect.\n')
            return
        else:
            XC = res[0]
            YC = res[1]
            ZC = res[2]
    else:
        if (len(res) != 1):
            CTK.TXT.insert('START', 'pos is incorrect.\n')
            return
        else:
            if (dir == 'YZ'): XC = res[0]
            elif (dir == 'XZ'): YC = res[0]
            else: ZC = res[0]
    setCanvas()
Example #30
0
def addGhostCells(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
    N = CTK.varsFromWidget(VARS[0].get(), type=2)
    if len(N) != 1:
        CTK.TXT.insert('START', 'Number of ghost cell layers is incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    N = N[0]

    CTK.saveTree()

    zones = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        zones += [z]

    zones = Internal.addGhostCells(CTK.t, zones, N, adaptBCs=1)
    c = 0
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        CTK.replace(CTK.t, nob, noz, zones[c])
        c += 1

    CTK.TXT.insert('START', 'Ghost cells added.\n')
    CTK.TKTREE.updateApp()
    CPlot.render()