def orthoProject():
    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)
    if surfaces == []:
        CTK.TXT.insert('START', 'Projection surface is empty.\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()
    fail = False
    errors = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        try:
            a = T.projectOrtho(z, surfaces)
            CTK.replace(CTK.t, nob, noz, a)
        except Exception as e:
            fail = True
            errors += [0, str(e)]

    if not fail:
        CTK.TXT.insert('START', 'Zones projected.\n')
    else:
        Panels.displayErrors(errors, header='Error: projectOrtho')
        CTK.TXT.insert('START', 'Projection fails for at least one zone.\n')
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
    CTK.TKTREE.updateApp()
    CPlot.render()
# - projectOrtho (pyTree) -
import Geom.PyTree as D
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T

a = D.sphere((0, 0, 0), 1., 20)
b = G.cart((1.1, -0.1, -0.1), (0.1, 0.1, 0.1), (1, 5, 5))
c = T.projectOrtho(b, a)
c[0] = 'projection'
C.convertPyTree2File([a, b, c], 'out.cgns')
Exemplo n.º 3
0
def OTFI():
    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
    surf = getSurfaces()

    zones = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        z = C.convertArray2Hexa(z)
        zones.append(z)
    zones = T.join(zones)
    zones = G.close(zones)
    a = C.convertBAR2Struct(z)

    weight = CTK.varsFromWidget(VARS[1].get(), type=1)
    weight = weight[0]

    # Nombre de pts
    Nt = Internal.getZoneDim(a)[1]
    if Nt / 2 - Nt * 0.5 == 0:
        CTK.TXT.insert('START', 'Number of points of countour must be odd.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    coords = C.getFields(Internal.__GridCoordinates__, a)[0]

    optWeight = 0
    optOffset = 0
    optScore = 1.e6
    Nt = coords[2]
    for j in range(-Nt // 4, Nt // 4 + 1):
        for i in range(3, 10):
            try:
                [m, m1, m2, m3, m4] = TFIs.TFIO__(coords, i, j)
                score = quality([m, m1, m2, m3])
                if score < optScore:
                    optWeight = i
                    optOffset = j
                    optScore = score
            except:
                pass
    print('resulting weight=%g, offset=%g.' % (optWeight, optOffset))
    print('resulting score=%g.' % optScore)
    [m, m1, m2, m3, m4] = TFIs.TFIO__(coords, optWeight, optOffset)

    m = C.convertArrays2ZoneNode('TFI1', [m])
    m1 = C.convertArrays2ZoneNode('TFI2', [m1])
    m2 = C.convertArrays2ZoneNode('TFI3', [m2])
    m3 = C.convertArrays2ZoneNode('TFI4', [m3])
    m4 = C.convertArrays2ZoneNode('TFI5', [m4])

    if surf != []:
        m = T.projectOrtho(m, surf)
        m1 = T.projectOrthoSmooth(m1, surf)
        m2 = T.projectOrthoSmooth(m2, surf)
        m3 = T.projectOrthoSmooth(m3, surf)
        m4 = T.projectOrthoSmooth(m4, surf)

    CTK.saveTree()
    CTK.t = C.addBase2PyTree(CTK.t, 'MESHES')
    bases = Internal.getNodesFromName1(CTK.t, 'MESHES')
    nob = C.getNobOfBase(bases[0], CTK.t)
    for i in [m, m1, m2, m3, m4]:
        CTK.add(CTK.t, nob, -1, i)
    CTK.TXT.insert('START', 'O-TFI mesh created.\n')

    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
Exemplo n.º 4
0
def smooth():
    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
    
    smooth = CTK.varsFromWidget(VARS[0].get(), type=2)
    if len(smooth) != 1:
        CTK.TXT.insert('START', 'Smooth iter is incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error'); return
    smooth = smooth[0]

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

    ntype = VARS[8].get()
    if ntype == 'Volume': ntype = 0
    elif ntype == 'Scale': ntype = 1
    elif ntype == 'Taubin': ntype = 2
    else: ntype = 0

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

    # Constraints
    fixedConstraints = []; projConstraints = []

    name = VARS[1].get()
    names = name.split(';')    
    for v in names:
        v = v.lstrip(); v = v.rstrip()
        sname = v.split('/', 1)
        base = Internal.getNodeFromName1(CTK.t, sname[0])
        if base is not None:
            nodes = Internal.getNodesFromType1(base, 'Zone_t')
            for z in nodes:
                if (z[0] == sname[1]): fixedConstraints.append(z)

    CTK.saveTree()
    
    # Get all zones
    zones = []
    for nz in nzs:
        nob = CTK.Nb[nz]+1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        zones.append(z)

    # Mesh unique
    try:
        A = C.convertArray2Tetra(zones)
        A = T.join(A); A = G.close(A)
    except Exception as e:
        Panels.displayErrors([0,str(e)], header='Error: smooth')
        CTK.TXT.insert('START', 'Some zones are invalid for smoothing.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error'); return

    # pb surfacique ou volumique?
    dims = Internal.getZoneDim(A)
    pbDim = 3
    if dims[3] == 'TRI': pbDim = 2
        
    # Keep external faces
    if VARS[3].get() == 1 or pbDim == 3: 
        try: ext = P.exteriorFaces(A)
        except: ext = []
    if VARS[3].get() == 1 and ext != []: fixedConstraints.append(ext)

    # Keep sharp edges
    if VARS[5].get() == 1:
        angle = CTK.varsFromWidget(VARS[6].get(), type=1)
        if len(angle) != 1:
            CTK.TXT.insert('START', 'Sharp edges angle is incorrect.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error'); return
        angle = angle[0]
        if pbDim == 2:
            try:
                sharp = P.sharpEdges(A, angle)
                fixedConstraints += sharp
            except: pass
        else:
            try:
                sharp = P.sharpEdges(ext, angle)
                fixedConstraints += sharp
            except: pass

    # Project on surface
    Pj = VARS[7].get()
    if pbDim == 2: projSurf = A
    else:
        # projSurf = ext
        # Pour l'instant, on ne sait pas projeter un maillage volumique
        # sur une surface
        Pj = 0
    
    # Smooth
    fail = False
    try:
        if Pj == 0:
            zones = T.smooth(zones, eps=eps, niter=smooth, type=ntype,
                             fixedConstraints=fixedConstraints, 
                             projConstraints=projConstraints, delta=strength)
        else:
            for s in xrange(smooth):
                zones = T.smooth(zones, eps=eps, niter=2, type=ntype,
                                 fixedConstraints=fixedConstraints, 
                                 projConstraints=projConstraints, 
                                 delta=strength)
                zones = T.projectOrtho(zones, [projSurf])
    except Exception as e:
        fail = True
        Panels.displayErrors([0,str(e)], header='Error: smooth')

    if fail == False:
        c = 0
        for nz in nzs:
            nob = CTK.Nb[nz]+1
            noz = CTK.Nz[nz]
            a = zones[c]; c += 1
            CTK.replace(CTK.t, nob, noz, a)
            CTK.TXT.insert('START', 'Mesh smoothed.\n')
    else:
        CTK.TXT.insert('START', 'Smooth fails.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')

    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
# - surfaceWalk (pyTree)
import Converter.PyTree as C
import Geom.PyTree as D
import Transform.PyTree as T
import Generator.PyTree as G


# User definition of parametric curve
def f(t, u):
    x = t + u
    y = t * t + 1 + u * u
    z = u
    return (x, y, z)


# Array definition of geometry
a = D.surface(f)

c = D.circle((1.2, 1.7, 0.6), 0.1)
c = T.rotate(c, (1.2, 1.7, 0.6), (0, 1, 0), 90.)
c = T.reorder(c, (-1, 2, 3))
c = T.projectOrtho(c, [a])

h = G.cart((0., 0., 0.), (0.01, 1, 1), (15, 1, 1))
r = G.surfaceWalk([a], c, h, niter=100)
C.convertPyTree2File(r, "out.cgns")
Exemplo n.º 6
0
# - projectOrtho (pyTree) -
import Geom.PyTree as D
import Converter.PyTree as C
import Generator.PyTree as G
import Transform.PyTree as T
import KCore.test as test

# sur une zone structuree
a = D.sphere((0, 0, 0), 1., 20)
a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin')
a = C.addBC2Zone(a, 'match1', 'BCMatch', 'jmin', a, 'jmax', [1, 2])
b = G.cart((-0.5, -0.5, -0.5), (0.05, 0.05, 0.1), (20, 20, 1))
b = C.addVars(b, 'F')
b = C.addVars(b, 'centers:G')
c = T.projectOrtho(b, a)
test.testT(c, 1)

# sur une zone non structuree
a = D.sphere((0, 0, 0), 1., 20)
a = C.addBC2Zone(a, 'wall1', 'BCWall', 'imin')
a = C.addBC2Zone(a, 'match1', 'BCMatch', 'jmin', a, 'jmax', [1, 2])
b = G.cartTetra((-0.5, -0.5, -0.5), (0.05, 0.05, 0.1), (20, 20, 1))
b = C.initVars(b, 'F', 2.)
b = C.addVars(b, 'centers:G')
c = T.projectOrtho(b, a)
test.testT(c, 2)

# NS sur une zone non structuree
a = D.sphere((0, 0, 0), 1., 20)
a = C.convertArray2Tetra(a)
b = G.cartTetra((-0.5, -0.5, -0.5), (0.05, 0.05, 0.1), (20, 20, 1))
Exemplo n.º 7
0
def apply2D(density, npts, factor, ntype=0):
    nzs = CPlot.getSelectedZones()
    nz = nzs[0]
    nob = CTK.Nb[nz]+1
    noz = CTK.Nz[nz]
    zone = CTK.t[2][nob][2][noz]
    ret = getEdges2D(zone, 0.)
    if ret is None: return True
    (m, r, u, ind) = ret
    out = []
    # Applique la fonction sur m[0] (edge a modifier)
    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: # copyDistrib (factor=source=edge pour l'instant)
        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 = getEdges2D(zone, 2.)
        if ret is None: return True
        (m, r, u, 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 += u
    #tp = C.newPyTree(['Base'])
    #tp[2][1][2] += out
    #C.convertPyTree2File(tp, 'edges.cgns')

    # Rebuild
    try:
        b = G.TFI(out)
        # Projection du patch interieur
        #dimsb = Internal.getZoneDim(b)
        #bs = T.subzone(b, (2,2,1), (dimsb[1]-1,dimsb[2]-1,1))
        #bs = T.projectOrtho(bs, [zone])
        #b = T.patch(b, bs, position=(2,2,1))

        #tp = C.newPyTree(['Base'])
        #tp[2][1][2] += [b, zone]
        #C.convertPyTree2File(tp, 'face.cgns')
        b = T.projectOrtho(b, [zone])
        CTK.replace(CTK.t, nob, noz, b)
        return False
    except Exception as e:
        Panels.displayErrors([0,str(e)], header='Error: apply2D')
        return True