コード例 #1
0
def withOctree(a, offset, density):
    # step
    tol = 1./density
    
    # octree
    snears = []; sec = 0
    for z in a:
        bb = G.bbox(z)
        rx = bb[3]-bb[0]; ry = bb[4]-bb[1]; rz = bb[5]-bb[2]
        snear = min(rx, ry); snear = min(snear, rz)
        snear = 0.1*snear
        sec = max(sec, snear)
        snears.append(snear)
    o = G.octree(a, snears, dfar=offset+sec)
    o = compDistance(o, a, loc='nodes')

    # iteration d'adaptation
    nit = 0
    while nit < 10:
        print('iterating: %d...'%nit)

        o = C.node2Center(o, 'TurbulentDistance')
        o = G.getVolumeMap(o)

        # adapt
        C._initVars(o, '{centers:vol}={centers:vol}**0.33333')
        # was 2.1 factor
        C._initVars(o, '{centers:indicator}=logical_and({centers:vol} > %20.16g , abs({centers:TurbulentDistance}-%20.16g) < 1.*{centers:vol})'%(tol,offset))
        o1 = G.adaptOctree(o, 'centers:indicator')

        #C.convertPyTree2File([o1]+a, 'out%d.cgns'%nit)

        # check convergence
        dim1 = Internal.getZoneDim(o1); dim = Internal.getZoneDim(o)
        if dim1 == dim: break

        #if (nit%2 == 0): o1 = P.extractMesh([o], o1)
        o1 = compDistance(o1, a, loc='nodes')
        o = o1
        nit += 1
    
    o = C.rmVars(o, 'centers:TurbulentDistance')
    o = C.rmVars(o, 'centers:vol')
    o = C.rmVars(o, 'centers:indicator')
    #C.convertPyTree2File(o, 'out.cgns')

    # Iso surface
    iso = P.isoSurfMC([o], 'TurbulentDistance', value=offset)
    return iso
コード例 #2
0
def extractIsoSurf(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

    field = VARS[0].get()
    value = VARS[1].get()

    try: value = float(value)
    except: value = 1.
    
    nzs = CPlot.getSelectedZones()
    CTK.saveTree()

    if nzs == []:
        z = Internal.getZones(CTK.t)
    else:
        z = []
        for nz in nzs:
            nob = CTK.Nb[nz]+1
            noz = CTK.Nz[nz]
            z.append(CTK.t[2][nob][2][noz])

    isos = []
    try:
        iso = P.isoSurfMC(z, field, value)
        isos += iso
    except Exception as e:
        Panels.displayErrors([0,str(e)], header='Error: isoSurf')
    if isos == []:
        CTK.TXT.insert('START', 'isoSurf failed.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
    else:
        CTK.TXT.insert('START', 'isoSurf of '+field+'='
                       +str(value)+' computed.\n')
    for i in isos: i[0] = C.getZoneName(i[0]) # unique name
    CTK.t = C.addBase2PyTree(CTK.t, 'SURFACES', 2)
    base = Internal.getNodeFromName1(CTK.t, 'SURFACES')
    nob = C.getNobOfBase(base, CTK.t)
    for i in isos: CTK.add(CTK.t, nob, -1, i)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
コード例 #3
0
def withCart(a, offset, density):
    # Calcul la grille cartesienne
    BB = G.bbox(a)
    xmin = BB[0]; ymin = BB[1]; zmin = BB[2]
    xmax = BB[3]; ymax = BB[4]; zmax = BB[5]
    ni = density*(xmax-xmin); nj = density*(ymax-ymin);
    nk = density*(zmax-zmin)
    if ni < 2: ni = 2
    if nj < 2: nj = 2
    if nk < 2: nk = 2
    hi = (xmax-xmin)/(ni-1); hj = (ymax-ymin)/(nj-1); hk = (zmax-zmin)/(nk-1)
    h = min(hi, hj); h = min(h, hk); h = max(h, 1.e-6)
    ni = int((xmax-xmin)/h)+7; nj = int((ymax-ymin)/h)+7
    nk = int((zmax-zmin)/h)+7
    ni += int(2*offset/h); nj += int(2*offset/h); nk += int(2*offset/h)
    b = G.cart( (xmin-3*h-offset, ymin-3*h-offset, zmin-3*h-offset), (h, h, h), (ni,nj,nk) )

    # Calcul la distance a la paroi
    b = compDistance(b, a, loc='nodes')
    #C.convertPyTree2File(b, 'out.cgns')

    # Extraction isoSurf
    iso = P.isoSurfMC([b], 'TurbulentDistance', value=offset)
    return iso
コード例 #4
0
# - isoSurfMC (pyTree) -
import Post.PyTree as P
import Converter.PyTree as C
import Generator.PyTree as G

a = G.cartHexa( (-20,-20,-20), (0.5,0.5,0.5), (50,50,50))
a = C.initVars(a, 'field={CoordinateX}*{CoordinateX}+{CoordinateY}*{CoordinateY}+{CoordinateZ}')

iso = P.isoSurfMC(a, 'field', value=5.)
C.convertPyTree2File(iso, 'out.cgns')
コード例 #5
0
ファイル: iso.py プロジェクト: guillaume-florent/cassiopee-ce
# - Calcul d'isosurfaces a la paroi en distribue -
import Converter.PyTree as C
import Distributor2.PyTree as Distributor2
import Converter.Mpi as Cmpi
import Transform.PyTree as T
import Post.PyTree as P

rank = Cmpi.rank
size = Cmpi.size

# lecture du squelette
a = Cmpi.convertFile2SkeletonTree('cart.cgns')

# equilibrage
(a, dic) = Distributor2.distribute(a, NProc=size, algorithm='fast', useCom=0)

# load des zones locales dans le squelette
a = Cmpi.readZones(a, 'cart.cgns', proc=rank)

# Passage en arbre partiel
a = Cmpi.convert2PartialTree(a)

# Calcul de l'iso surface
isos = P.isoSurfMC(a, 'F', 0.3)
isos = Cmpi.setProc(isos, rank)  # affecte les isos au proc local
t = C.newPyTree(['Base'])
t[2][1][2] += isos

# Reconstruit l'arbre complet a l'ecriture
Cmpi.convertPyTree2File(t, 'out.cgns')
コード例 #6
0
#!/usr/bin/env python
# coding: utf-8
r"""<TBC>"""

# Extraction de lignes x=cte sur un maillage surfacique
import Converter.PyTree as C
import Post.PyTree as P
import Geom.PyTree as D

# IN: surface+solution
a = D.sphere((0, 0, 0), 1, N=100)
a = C.initVars(a, 'p={CoordinateX}+{CoordinateY}')

# Extraction de lignes x = cste
lines = []
for i in range(10):
    x = i / 10.
    p = P.isoSurfMC(a, 'CoordinateX', x)
    lines += p

# Sortie
t = C.newPyTree(['Base'])
t[2][1][2] += lines
C.convertPyTree2File(t, 'out.cgns')
コード例 #7
0
def view(event=None):
    if CTK.t == []: return
    pos = float(VARS[1].get())
    global VALUE
    VALUE = pos
    delta = float(VARS[4].get())
    global DELTA
    DELTA = delta
    plane = VARS[0].get()
    order = int(VARS[3].get())
    eps = float(VARS[2].get())
    algo = VARS[5].get()

    nzs = CPlot.getSelectedZones()
    if nzs != []:
        point = CPlot.getActivePoint()
        if len(point) == 3:
            if plane == 'X': pos = point[0]
            elif plane == 'Y': pos = point[1]
            elif plane == 'Z': pos = point[2]
            VARS[1].set(str(pos))
            VALUE = pos

    if plane == 'Mesh':
        CTK.display(CTK.t)
        return
    try:
        if CTK.__MAINTREE__ == 1:
            CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones()
        active = []
        tp = Internal.appendBaseName2ZoneName(CTK.t,
                                              updateRef=False,
                                              separator=Internal.SEP1)
        for z in CTK.__MAINACTIVEZONES__:
            active.append(tp[2][CTK.Nb[z] + 1][2][CTK.Nz[z]])

        temp = C.newPyTree(['Base'])
        temp[2][1][2] += active
        if plane == 'X' and algo == 'Slice1':
            p = P.isoSurfMC(active, 'CoordinateX', pos)
        elif plane == 'Y' and algo == 'Slice1':
            p = P.isoSurfMC(active, 'CoordinateY', pos)
        elif plane == 'Z' and algo == 'Slice1':
            p = P.isoSurfMC(active, 'CoordinateZ', pos)
        elif plane == 'X' and algo == 'Slice2':
            p = P.extractPlane(active, (1, 0, 0, -pos), order=order, tol=eps)
        elif plane == 'Y' and algo == 'Slice2':
            p = P.extractPlane(active, (0, 1, 0, -pos), order=order, tol=eps)
        elif plane == 'Z' and algo == 'Slice2':
            p = P.extractPlane(active, (0, 0, 1, -pos), order=order, tol=eps)
        elif plane == 'X' and algo == 'Select+':
            p = P.selectCells(temp, '{CoordinateX}>=' + str(VALUE))
        elif plane == 'Y' and algo == 'Select+':
            p = P.selectCells(temp, '{CoordinateY}>=' + str(VALUE))
        elif plane == 'Z' and algo == 'Select+':
            p = P.selectCells(temp, '{CoordinateZ}>=' + str(VALUE))
        elif plane == 'X' and algo == 'Select-':
            p = P.selectCells(temp, '{CoordinateX}<=' + str(VALUE))
        elif plane == 'Y' and algo == 'Select-':
            p = P.selectCells(temp, '{CoordinateY}<=' + str(VALUE))
        elif plane == 'Z' and algo == 'Select-':
            p = P.selectCells(temp, '{CoordinateZ}<=' + str(VALUE))
        elif plane == 'X' and algo == 'Select=':
            p = P.selectCells(
                temp, '({CoordinateX}>=' + str(VALUE - DELTA) +
                ') & ({CoordinateX}<=' + str(VALUE + DELTA) + ')')
        elif plane == 'Y' and algo == 'Select=':
            p = P.selectCells(
                temp, '({CoordinateY}>=' + str(VALUE - DELTA) +
                ') & ({CoordinateY}<=' + str(VALUE + DELTA) + ')')
        elif plane == 'Z' and algo == 'Select=':
            p = P.selectCells(
                temp, '({CoordinateZ}>=' + str(VALUE - DELTA) +
                ') & ({CoordinateZ}<=' + str(VALUE + DELTA) + ')')
        CTK.dt = C.newPyTree(['Base'])
        if algo == 'Slice1': CTK.dt[2][1][2] += p
        elif algo == 'Slice2': CTK.dt[2][1][2] += [p]
        else: CTK.dt[2][1][2] += p[2][1][2]
        CTK.display(CTK.dt, mainTree=CTK.SLICE)
        if CTK.TKPLOTXY is not None: CTK.TKPLOTXY.updateApp()
    except ValueError:
        CTK.TXT.insert('START', 'Intersection is empty.\n')
        return
    except Exception as e:
        Panels.displayErrors([0, str(e)], header='Error: slice')
        CTK.TXT.insert('START', 'Slice failed.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
コード例 #8
0
def extract(event=None):
    if CTK.t == []: return
    pos = float(VARS[1].get())
    global VALUE
    VALUE = pos
    delta = float(VARS[4].get())
    global DELTA
    DELTA = delta
    plane = VARS[0].get()
    order = int(VARS[3].get())
    eps = float(VARS[2].get())
    algo = VARS[5].get()

    nzs = CPlot.getSelectedZones()
    if nzs != []:
        point = CPlot.getActivePoint()
        if plane == 'X': pos = point[0]
        elif plane == 'Y': pos = point[1]
        elif plane == 'Z': pos = point[2]
        VARS[1].set(str(pos))
        VALUE = pos

    if plane == 'Mesh': return
    try:
        CTK.saveTree()
        if CTK.__MAINTREE__ == 1:
            CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones()
        active = []
        zones = Internal.getZones(CTK.t)
        for z in CTK.__MAINACTIVEZONES__:
            active.append(zones[z])
        temp = C.newPyTree(['Base'])
        temp[2][1][2] += active
        if plane == 'X' and algo == 'Slice1':
            p = P.isoSurfMC(active, 'CoordinateX', pos)
        elif plane == 'Y' and algo == 'Slice1':
            p = P.isoSurfMC(active, 'CoordinateY', pos)
        elif plane == 'Z' and algo == 'Slice1':
            p = P.isoSurfMC(active, 'CoordinateZ', pos)
        elif plane == 'X' and algo == 'Slice2':
            p = P.extractPlane(active, (1, 0, 0, -pos), order=order, tol=eps)
        elif plane == 'Y' and algo == 'Slice2':
            p = P.extractPlane(active, (0, 1, 0, -pos), order=order, tol=eps)
        elif plane == 'Z' and algo == 'Slice2':
            p = P.extractPlane(active, (0, 0, 1, -pos), order=order, tol=eps)
        elif plane == 'X' and algo == 'Select+':
            p = P.selectCells(temp, '{CoordinateX}>=' + str(VALUE))
        elif plane == 'Y' and algo == 'Select+':
            p = P.selectCells(temp, '{CoordinateY}>=' + str(VALUE))
        elif plane == 'Z' and algo == 'Select+':
            p = P.selectCells(temp, '{CoordinateZ}>=' + str(VALUE))
        elif plane == 'X' and algo == 'Select-':
            p = P.selectCells(temp, '{CoordinateX}<=' + str(VALUE))
        elif plane == 'Y' and algo == 'Select-':
            p = P.selectCells(temp, '{CoordinateY}<=' + str(VALUE))
        elif plane == 'Z' and algo == 'Select-':
            p = P.selectCells(temp, '{CoordinateZ}<=' + str(VALUE))
        elif plane == 'X' and algo == 'Select=':
            p = P.selectCells(
                temp, '({CoordinateX}>=' + str(VALUE - DELTA) +
                ') & ({CoordinateX}<=' + str(VALUE + DELTA) + ')')
        elif plane == 'Y' and algo == 'Select=':
            p = P.selectCells(
                temp, '({CoordinateY}>=' + str(VALUE - DELTA) +
                ') & ({CoordinateY}<=' + str(VALUE + DELTA) + ')')
        elif plane == 'Z' and algo == 'Select=':
            p = P.selectCells(
                temp, '({CoordinateZ}>=' + str(VALUE - DELTA) +
                ') & ({CoordinateZ}<=' + str(VALUE + DELTA) + ')')
        CTK.t = C.addBase2PyTree(CTK.t, 'EXTRACT', 2)
        base = Internal.getNodeFromName1(CTK.t, 'EXTRACT')
        if algo == 'Slice1':
            for i in p:
                i[0] = C.getZoneName(i[0])
            base[2] += p
        elif algo == 'Slice2':
            p[0] = C.getZoneName(p[0])
            base[2] += [p]
        else:
            p = C.deleteEmptyZones(p)
            for i in p[2][1][2]:
                i[0] = C.getZoneName(i[0])
            base[2] += p[2][1][2]
        #C._fillMissingVariables(CTK.t)
        CTK.TXT.insert('START', 'Slice extracted.\n')
        (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
        CTK.TKTREE.updateApp()
        CTK.display(CTK.t)
        if CTK.TKPLOTXY is not None: CTK.TKPLOTXY.updateApp()
    except ValueError:
        CTK.TXT.insert('START', 'Intersection is empty.\n')
        return
    except Exception as e:
        Panels.displayErrors([0, str(e)], header='Error: slice')
        CTK.TXT.insert('START', 'Slice failed.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
コード例 #9
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')