示例#1
0
def extractExternalContours():
    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()

    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        contours = P.exteriorFacesStructured(z)
        CTK.t[2][nob][2] = CTK.t[2][nob][2] + contours
    CTK.TXT.insert('START', 'External contours extracted.\n')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CTK.display(CTK.t)
# - exteriorFacesStructured (pyTree) -
import Converter.PyTree as C
import Post.PyTree as P
import Generator.PyTree as G
import KCore.test as test

# 1D 
a = G.cart((0,0,0), (1,1,1), (10,1,1))
A = P.exteriorFacesStructured(a)
t = C.newPyTree(['Base',0]); t[2][1][2] += A
test.testT(t,1)

# 2D 
a = G.cart((0,0,0), (1,1,1), (1,6,10))
A = P.exteriorFacesStructured(a)
t = C.newPyTree(['Base',1]); t[2][1][2] += A
test.testT(t,2)

# 3D 
a = G.cart((0,0,0), (1,1,1), (4,4,6))
A = P.exteriorFacesStructured(a)
t = C.newPyTree(['Base',2]); t[2][1][2] += A
test.testT(t,3)
示例#3
0
# - exteriorFacesStructured (pyTree) -
import Converter.PyTree as C
import Post.PyTree as P
import Generator.PyTree as G
import KCore.test as test

# 1D
a = G.cart((0, 0, 0), (1, 1, 1), (10, 1, 1))
C._addVars(a, 'Density')
C._addVars(a, 'centers:cellN')
t = C.newPyTree(['Base', 1, a])
t[2][1] = C.addState(t[2][1], 'Mach', 0.6)
zones = P.exteriorFacesStructured(t)
test.testT(zones, 1)

# 2D
a = G.cart((0, 0, 0), (1, 1, 1), (1, 6, 10))
C._addVars(a, 'Density')
C._addVars(a, 'centers:cellN')
t = C.newPyTree(['Base', 2, a])
t[2][1] = C.addState(t[2][1], 'Mach', 0.6)
zones = P.exteriorFacesStructured(t)
test.testT(zones, 2)

# 3D
a = G.cart((0, 0, 0), (1, 1, 1), (4, 4, 6))
C._addVars(a, 'Density')
C._addVars(a, 'centers:cellN')
t = C.newPyTree(['Base', 3, a])
t[2][1] = C.addState(t[2][1], 'Mach', 0.6)
zones = P.exteriorFacesStructured(t)
示例#4
0
def check():
    if CTK.t == []: return

    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

    # Varie de 0 a 180 degres
    global __SPLITFACTOR__
    splitFactor = 180. - WIDGETS['splitFactor'].get() * 180. / 100.
    __SPLITFACTOR__ = splitFactor

    wins = C.getEmptyBC(CTK.t, ndim, splitFactor)
    if CTK.__MAINTREE__ == 1:
        CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones()
    CTK.dt = C.newPyTree(['Base', 'Edges'])
    tp = Internal.appendBaseName2ZoneName(CTK.t,
                                          updateRef=False,
                                          separator=Internal.SEP1,
                                          trailing=Internal.SEP1)
    bases = Internal.getBases(tp)
    nb = 0
    for b in bases:
        nodes = Internal.getNodesFromType1(b, 'Zone_t')
        nz = 0
        for z in nodes:
            ztype = Internal.getZoneType(z)
            winz = wins[nb][nz]
            if ztype == 1:  # structure
                for w in winz:
                    imin = w[0]
                    imax = w[1]
                    jmin = w[2]
                    jmax = w[3]
                    kmin = w[4]
                    kmax = w[5]
                    zp = T.subzone(z, (imin, jmin, kmin), (imax, jmax, kmax))
                    CTK.dt[2][1][2].append(zp)
            else:  # non structure
                for w in winz:
                    zp = T.subzone(z, w, type='faces')
                    CTK.dt[2][1][2].append(zp)
            nz += 1
        nb += 1

    if VARS[7].get() == '1':  # display les edges des zones en +
        exts = []
        zones = Internal.getZones(tp)
        for z in zones:
            ztype = Internal.getZoneType(z)
            if ztype == 1:
                zp = P.exteriorFacesStructured(z)
                exts += zp
            else:
                #zp = P.exteriorFaces(z); zp = P.sharpEdges(zp)
                zp = []
                exts += zp
        CTK.dt[2][2][2] += exts
        #C._fillMissingVariables(CTK.dt) # bug exteriorFacesStruct

        # Activate
        lenZ = len(CTK.dt[2][1][2])
        lenExts = len(exts)
        active = [(i, 1) for i in range(lenZ + lenExts)]
        for i in range(lenZ):
            active[i] = (i, 1)
        for i in range(lenExts):
            active[i + lenZ] = (i + lenZ, 0)

        CTK.display(CTK.dt, mainTree=CTK.UNDEFINEDBC)
        CPlot.setActiveZones(active)
        CPlot.setState(edgifyDeactivatedZones=1)
    else:
        lenZ = len(CTK.dt[2][1][2])
        active = [(i, 1) for i in range(lenZ)]
        CTK.display(CTK.dt, mainTree=CTK.UNDEFINEDBC)
        CPlot.setActiveZones(active)

    # modifie la couleur du bouton
    l = len(Internal.getZones(CTK.dt))
    if l == 0: TTK.setButtonGreen(WIDGETS['undefinedBC'])
    else: TTK.setButtonRed(WIDGETS['undefinedBC'])
    WIDGETS['undefinedBC'].update()
示例#5
0
def view(event=None):
    if CTK.t == []: return

    BCTypes = []
    selection = WIDGETS['BCLB'].curselection()
    for s in selection:
        t = WIDGETS['BCLB'].get(s)
        if t not in Internal.KNOWNBCS: t = 'FamilySpecified:' + t
        BCTypes.append(t)
    if 'FamilySpecified:-All BC-' in BCTypes: BCTypes = ['*']

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

    tp = Internal.appendBaseName2ZoneName(CTK.t,
                                          updateRef=False,
                                          separator=Internal.SEP1)
    CTK.dt = C.newPyTree(['Base', 'Edges'])
    active = []
    for z in CTK.__MAINACTIVEZONES__:
        active.append(tp[2][CTK.Nb[z] + 1][2][CTK.Nz[z]])

    Z = []
    for t in BCTypes:
        Z += C.extractBCOfType(active, t, topTree=tp)
        if t == 'BCWall':  # Dans ce cas, affiche tous les types de BCWall
            Z += C.extractBCOfType(active, 'BCWallInviscid')
            Z += C.extractBCOfType(active, 'BCWallViscous')
            Z += C.extractBCOfType(active, 'BCWallViscousIsoThermal')
    CTK.dt[2][1][2] += Z

    if VARS[7].get() == '1':  # display les edges des zones en +
        exts = []
        for z in active:
            ztype = Internal.getZoneType(z)
            if ztype == 1:
                zp = P.exteriorFacesStructured(z)
                exts += zp
            else:
                #zp = P.exteriorFaces(z)
                #zp = P.sharpEdges(zp)
                zp = []
                exts += zp

        CTK.dt[2][2][2] += exts
        C._fillMissingVariables(CTK.dt)  # bug exteriorFaces

        # Activate
        lenZ = len(CTK.dt[2][1][2])
        lenExts = len(CTK.dt[2][2][2])
        active = [(i, 1) for i in range(lenZ + lenExts)]
        for i in range(lenZ):
            active[i] = (i, 1)
        for i in range(lenExts):
            active[i + lenZ] = (i + lenZ, 0)

        CTK.display(CTK.dt, mainTree=CTK.DEFINEDBC)
        CPlot.setActiveZones(active)
        CPlot.setState(edgifyDeactivatedZones=1)
    else:
        lenZ = len(CTK.dt[2][1][2])
        active = [(i, 1) for i in range(lenZ)]
        C._fillMissingVariables(CTK.dt)  # si BCDataSet != fields
        CTK.display(CTK.dt, mainTree=CTK.DEFINEDBC)
        CPlot.setActiveZones(active)
        CPlot.setState(edgifyDeactivatedZones=0)
def apply3D(density, npts, factor, ntype):
    nzs = CPlot.getSelectedZones()
    nz = nzs[0]
    nob = CTK.Nb[nz]+1
    noz = CTK.Nz[nz]
    zone = CTK.t[2][nob][2][noz]
    ret = getEdges3D(zone, 0.)
    if ret is None: return True
    (m, r, f, ue, uf, ind) = ret
    out = []
    # Applique la fonction sur m
    i = m[0]
    dims = Internal.getZoneDim(i)
    np = dims[1]*dims[2]*dims[3]
    if ntype == 0: # uniformize
        if density > 0: npts = D.getLength(i)*density
        if factor > 0: npts = np*factor[0]
        npts = int(max(npts, 2))
        distrib = G.cart((0,0,0), (1./(npts-1.),1,1), (npts,1,1))
        b = G.map(i, distrib)
    elif ntype == 1: # refine
        if factor < 0: factor = (npts-1.)/(np-1)
        else: npts = factor*(np-1)+1
        b = G.refine(i, factor, 1)
    elif ntype == 2: # stretch (factor=h)
        h = factor
        l = D.getLength(i)
        a = D.getCurvilinearAbscissa(i)
        distrib = C.cpVars(a, 's', a, 'CoordinateX')
        C._initVars(distrib, 'CoordinateY', 0.)
        C._initVars(distrib, 'CoordinateZ', 0.)
        distrib = C.rmVars(distrib, 's')
        N = dims[1]
        val = C.getValue(a, 's', ind)
        Xc = CPlot.getActivePoint()
        valf = val
        Pind = C.getValue(i, 'GridCoordinates', ind)
        if ind < N-1: # cherche avec indp1
            Pindp1 = C.getValue(i, 'GridCoordinates', ind+1)
            v1 = Vector.sub(Pindp1, Pind)
            v2 = Vector.sub(Xc, Pind)
            if Vector.dot(v1,v2) >= 0:
                val2 = C.getValue(a, 's', ind+1)
                alpha = Vector.norm(v2)/Vector.norm(v1)
                valf = val+alpha*(val2-val)
        if ind > 0 and val == valf: # cherche avec indm1
            Pindm1 = C.getValue(i, 'GridCoordinates', ind-1)
            v1 = Vector.sub(Pindm1, Pind)
            v2 = Vector.sub(Xc, Pind)
            if Vector.dot(v1,v2) >= 0:
                val2 = C.getValue(a, 's', ind-1)
                alpha = Vector.norm(v2)/Vector.norm(v1)
                valf = val+alpha*(val2-val)
        if h < 0: distrib = G.enforcePoint(distrib, valf)
        else:
            if val == 0: distrib = G.enforcePlusX(distrib, h/l, N/10, 1)
            elif val == 1: distrib = G.enforceMoinsX(distrib, h/l, N/10, 1)
            else: distrib = G.enforceX(distrib, valf, h/l, N/10, 1)
        b = G.map(i, distrib)
    elif ntype == 3:
        source = factor
        b = G.map(i, source, 1)
    elif ntype == 4: # smooth (factor=eps, npts=niter)
        niter = npts
        eps = factor
        a = D.getCurvilinearAbscissa(i)
        distrib = C.cpVars(a, 's', a, 'CoordinateX')
        C._initVars(distrib, 'CoordinateY', 0.)
        C._initVars(distrib, 'CoordinateZ', 0.)
        distrib = C.rmVars(distrib, 's')
        bornes = P.exteriorFaces(distrib)
        distrib = T.smooth(distrib, eps=eps, niter=niter, 
                           fixedConstraints=[bornes])
        b = G.map(i, distrib, 1)
    dimb = Internal.getZoneDim(b)
    npts = dimb[1]
    out.append(b)
    # Raffine les edges si necessaires
    if npts != np:
        ret = getEdges3D(zone, 2.)
        if ret is None: return True
        (m, r, f, ue, uf, ind) = ret
    for i in r:
        dims = Internal.getZoneDim(i)
        np = dims[1]*dims[2]*dims[3]
        factor = (npts-1.)/(np-1)  # npts de m
        b = G.refine(i, factor, 1)
        out.append(b)
    # Garde les autres
    out += ue
    outf = []
    # Rebuild les faces
    for i in f:
        # trouve les edges de la face
        edges = P.exteriorFacesStructured(i)
        match = []
        for e in edges:
            dime = Internal.getZoneDim(e)
            np = dime[1]-1
            P0 = C.getValue(e, Internal.__GridCoordinates__, 0)
            P1 = C.getValue(e, Internal.__GridCoordinates__, np)
            for ei in out: # retrouve les edges par leurs extremites
                dimei = Internal.getZoneDim(ei)
                npi = dimei[1]-1
                Q0 = C.getValue(ei, Internal.__GridCoordinates__, 0)
                Q1 = C.getValue(ei, Internal.__GridCoordinates__, npi)
                t1 = Vector.norm2(Vector.sub(P0,Q0))
                t2 = Vector.norm2(Vector.sub(P1,Q1))
                if (t1 < 1.e-12 and t2 < 1.e-12): match.append(ei)
        if len(match) == 4: # OK
            fn = G.TFI(match)
            # Projection du patch interieur
            #dimsf = Internal.getZoneDim(fn)
            #fns = T.subzone(fn, (2,2,1), (dimsf[1]-1,dimsf[2]-1,1))
            #fns = T.projectOrtho(fns, [i])
            #fn = T.patch(fn, fns, position=(2,2,1))

            #fn = T.projectOrtho(fn, [i])
            outf.append(fn)
        else: return True
    outf += uf
    try:
        b = G.TFI(outf)
        CTK.replace(CTK.t, nob, noz, b)
        return False
    except Exception as e:
        Panels.displayErrors([0,str(e)], header='Error: apply3D')
        return True