# - display1D (pyTree) -
import Generator.PyTree as G
import CPlot.PyTree as CPlot
import Converter.PyTree as C
import numpy

# 1D data defined in zones
b = G.cart((0,0,0), (0.1,1,1), (50,1,1))
c = G.cart((5,0,0), (0.1,1,1), (50,1,1))
B = [b, c]
CPlot.setState(gridSize=(1,2))
for i in xrange(100):
    C._initVars(B, 'f=sin({CoordinateX}+0.01*%d)'%i)
    C._initVars(B, 'g={CoordinateX}')
    CPlot.display1D(B, slot=0, bgBlend=1., gridPos=(0,0), var1='CoordinateX', var2='f')

# 1D data defined in numpys
import numpy
x = numpy.linspace(0, 2*numpy.pi)
y = numpy.sin(x)
CPlot.display1D([x,y], slot=1, var1='x', var2='y', gridPos=(0,1), bgBlend=0.8)
Example #2
0
def display1D(event=None):
    if CTK.t == []: return

    # Get slot
    try:
        slot = int(VARS[5].get())
    except:
        slot = 0
    # Get grid size
    try:
        gridSize = VARS[1].get()
        grids = gridSize.split(';')
        if (len(grids) == 1): gridSize = (int(grids[0]), 1)
        else: gridSize = (int(grids[0]), int(grids[1]))
    except:
        gridSize = (1, 1)
    CPlot.setState(gridSize=gridSize)
    # Get grid pos
    try:
        gridPos = VARS[2].get()
        grids = gridPos.split(';')
        if (len(grids) == 1): gridPos = (int(grids[0]), 1)
        else: gridPos = (int(grids[0]), int(grids[1]))
    except:
        gridPos = (0, 0)

    # Recupere la direction pour la coupe ou 'Elements'
    dir = VARS[0].get()
    if dir == 'None':
        CPlot.display1D([], slot=slot)
        return  # clear

    # Recupere le pt pour la coupe ou les elements 1D
    if dir == 'Elements':  # elements -> recupere les elements
        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
        points = []
        for nz in nzs:
            nob = CTK.Nb[nz] + 1
            noz = CTK.Nz[nz]
            z = CTK.t[2][nob][2][noz]
            selected = CTK.t[2][nob][0] + '/' + z[0]
            points.append(selected)
    elif (dir == 'I' or dir == 'J'
          or dir == 'K'):  # indice -> recupere les indices + la zone
        if (CTK.__MAINTREE__ <= 0):
            CTK.TXT.insert('START', 'Fail on a temporary tree.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
            return
        nz = CPlot.getSelectedZone()
        if (nz == -1):
            CTK.TXT.insert('START', 'Selection is empty.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
            return
        points = []
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        selected = CTK.t[2][nob][0] + '/' + z[0]
        index = CPlot.getActivePointIndex()
        points = (selected, index)
    else:  # les coupes -> recupere les coord du pt
        point = CPlot.getActivePoint()
        if point == []: point = (0., 0., 0.)

    # Recupere les variables a afficher
    var1 = VARS[3].get()
    var1 = var1.replace('centers:', '')
    var2 = VARS[4].get()
    var2 = var2.replace('centers:', '')

    # Recupere les zones actives
    actives = []
    zones = Internal.getZones(CTK.t)
    if CTK.__MAINTREE__ == 1:
        nzs = CPlot.getActiveZones()
        for nz in nzs:
            actives.append(zones[nz])
    else:
        actives = zones
    if actives == []: return

    if (dir == 'X (Y)'):
        elts = P.isoSurfMC(actives, 'CoordinateY', point[1])
        if elts != []:
            elts2 = P.isoSurfMC(elts, 'CoordinateZ', point[2])
            if (elts2 != []): elts = elts2
    elif (dir == 'Y (X)'):
        elts = P.isoSurfMC(actives, 'CoordinateX', point[0])
        if elts != []:
            elts2 = P.isoSurfMC(elts, 'CoordinateZ', point[2])
            if (elts2 != []): elts = elts2
    elif (dir == 'Z (X)'):
        elts = P.isoSurfMC(actives, 'CoordinateX', point[0])
        if (elts != []):
            elts2 = P.isoSurfMC(elts, 'CoordinateY', point[1])
            if (elts2 != []): elts = elts2
    elif (dir == 'X (Z)'):
        elts = P.isoSurfMC(actives, 'CoordinateZ', point[2])
        if elts != []:
            elts2 = P.isoSurfMC(elts, 'CoordinateY', point[1])
            if (elts2 != []): elts = elts2
    elif (dir == 'Y (Z)'):
        elts = P.isoSurfMC(actives, 'CoordinateZ', point[2])
        if elts != []:
            elts2 = P.isoSurfMC(elts, 'CoordinateX', point[0])
            if (elts2 != []): elts = elts2
    elif (dir == 'Z (Y)'):
        elts = P.isoSurfMC(actives, 'CoordinateY', point[1])
        if (elts != []):
            elts2 = P.isoSurfMC(elts, 'CoordinateX', point[0])
            if (elts2 != []): elts = elts2
    elif (dir == 'I'):
        v = points[0]
        ind = points[1]
        v = v.lstrip()
        v = v.rstrip()
        sname = v.split('/', 1)
        bases = Internal.getNodesFromName1(CTK.t, sname[0])
        elts = []
        if bases != []:
            zones = Internal.getNodesFromType1(bases[0], 'Zone_t')
            for z in zones:
                if (z[0] == sname[1]):
                    try:
                        zp = C.center2Node(z, Internal.__FlowSolutionCenters__)
                        zp = T.subzone(zp, (1, ind[3], ind[4]),
                                       (-1, ind[3], ind[4]))
                        elts.append(zp)
                    except:
                        pass
    elif (dir == 'J'):
        v = points[0]
        ind = points[1]
        v = v.lstrip()
        v = v.rstrip()
        sname = v.split('/', 1)
        bases = Internal.getNodesFromName1(CTK.t, sname[0])
        elts = []
        if bases != []:
            zones = Internal.getNodesFromType1(bases[0], 'Zone_t')
            for z in zones:
                if (z[0] == sname[1]):
                    try:
                        zp = C.center2Node(z, Internal.__FlowSolutionCenters__)
                        zp = T.subzone(zp, (ind[2], 1, ind[4]),
                                       (ind[2], -1, ind[4]))
                        elts.append(zp)
                    except:
                        pass
    elif (dir == 'K'):
        v = points[0]
        ind = points[1]
        v = v.lstrip()
        v = v.rstrip()
        sname = v.split('/', 1)
        bases = Internal.getNodesFromName1(CTK.t, sname[0])
        elts = []
        if bases != []:
            zones = Internal.getNodesFromType1(bases[0], 'Zone_t')
            for z in zones:
                if (z[0] == sname[1]):
                    try:
                        zp = C.center2Node(z, Internal.__FlowSolutionCenters__)
                        zp = T.subzone(zp, (ind[2], ind[3], 1),
                                       (ind[2], ind[3], -1))
                        elts.append(zp)
                    except:
                        pass
    elif (dir == 'Elements'):
        elts = []
        for v in points:
            v = v.lstrip()
            v = v.rstrip()
            sname = v.split('/', 1)
            bases = Internal.getNodesFromName1(CTK.t, sname[0])
            if (bases != []):
                zones = Internal.getNodesFromType1(bases[0], 'Zone_t')
                for z in zones:
                    if (z[0] == sname[1]): elts.append(z)
    if elts == []:
        CTK.TXT.insert('START', 'Nothing to display.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    try:
        elts = D.getCurvilinearAbscissa(elts)
    except:
        pass

    # Fit first axis
    pos = WIDGETS['rangePos'].get() / 50. - 1.
    zoom = WIDGETS['rangeZoom'].get() / 120.
    minv1 = C.getMinValue(elts, var1)
    maxv1 = C.getMaxValue(elts, var1)
    if (maxv1 - minv1 < 1.e-6):
        maxv1 += 5.e-7
        minv1 -= 5.e-7

    # active point localisation
    nz = CPlot.getSelectedZone()
    if (nz != -1):
        ind = CPlot.getActivePointIndex()
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        f1 = C.getValue(z, var1, ind[0])
        try:
            r1min = (f1 - minv1) * zoom + minv1 + pos * (1. - zoom) * (maxv1 -
                                                                       minv1)
            r1max = (f1 - maxv1) * zoom + maxv1 + pos * (1. - zoom) * (maxv1 -
                                                                       minv1)
        except:  # var1 not found in z, le cherche dans elts
            xf1 = C.getValue(z, 'CoordinateX', ind[0])
            yf1 = C.getValue(z, 'CoordinateY', ind[0])
            zf1 = C.getValue(z, 'CoordinateZ', ind[0])
            f1 = minv1 + 0.5 * (maxv1 - minv1)
            r1min = 0.5 * (maxv1 - minv1) * zoom + minv1 + pos * (
                1. - zoom) * (maxv1 - minv1)
            r1max = -0.5 * (maxv1 - minv1) * zoom + maxv1 + pos * (
                1. - zoom) * (maxv1 - minv1)
    else:
        f1 = minv1 + 0.5 * (maxv1 - minv1)
        r1min = 0.5 * (maxv1 - minv1) * zoom + minv1 + pos * (1. - zoom) * (
            maxv1 - minv1)
        r1max = -0.5 * (maxv1 - minv1) * zoom + maxv1 + pos * (1. - zoom) * (
            maxv1 - minv1)

    # Fit second axis
    p = P.selectCells(
        elts,
        '({%s} < %20.16g) & ({%s} > %20.16g)' % (var1, r1max, var1, r1min))
    minv2 = C.getMinValue(p, var2)
    maxv2 = C.getMaxValue(p, var2)

    # display
    CPlot.display1D(p,
                    slot=slot,
                    bgBlend=0.,
                    gridPos=gridPos,
                    var1=var1,
                    var2=var2,
                    r1=(r1min, r1max),
                    r2=(minv2, maxv2))
    CTK.TXT.insert('START', 'Plot displayed.\n')