コード例 #1
0
def uniformize1D(density, npts, factor):
    fail = False
    nzs = CPlot.getSelectedZones()
    for nz in nzs:
        nob = CTK.Nb[nz]+1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        dims = Internal.getZoneDim(z)
        try:
            if dims[0] == 'Unstructured':
                a = C.convertBAR2Struct(z); np = dims[1]
            else: a = z; np = dims[1]*dims[2]*dims[3]
            if density > 0: npts = D.getLength(a)*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(a, distrib)
            CTK.replace(CTK.t, nob, noz, b)
        except Exception as e:
            fail = True
            Panels.displayErrors([0,str(e)], header='Error: uniformize1D')
    return fail
コード例 #2
0
# - getDistantIndex (PyTree)-
import Geom.PyTree as D
import KCore.test as test
import Converter.PyTree as C

a = D.naca(12., 5001)
l = D.getLength(a)
l2 = D.getDistantIndex(a, 1, l / 10.)
test.testO(l2, 1)
コード例 #3
0
# - getLength (pyTree) -
import Geom.PyTree as D

a = D.line((0, 0, 0), (1, 0, 0))
print(D.getLength(a))
コード例 #4
0
# - getLength (pyTree)-
import Geom.PyTree as D

a = D.line((0, 0, 0), (1, 0, 0))
print D.getLength(a)
コード例 #5
0
def stretch1D(h):
    fail = False
    nzs = CPlot.getSelectedZones()
    nz = nzs[0]
    nob = CTK.Nb[nz]+1
    noz = CTK.Nz[nz]
    z = CTK.t[2][nob][2][noz]
    dims = Internal.getZoneDim(z)
    try:
        if dims[0] == 'Unstructured': a = C.convertBAR2Struct(z)
        else: a = z
    except Exception as e:
        #print 'Error: stretch1D: %s.'%str(e)
        Panels.displayErrors([0,str(e)], header='Error: stretch1D')
        return True # Fail

    ind = CPlot.getActivePointIndex()
    if ind == []: return True # Fail
    ind = ind[0]
    
    l = D.getLength(a)
    a = D.getCurvilinearAbscissa(a)
    zp = D.getCurvilinearAbscissa(z)
    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(zp, 's', ind)
    
    Xc = CPlot.getActivePoint()
    valf = val
    Pind = C.getValue(z, 'GridCoordinates', ind)
    if ind < N-1: # cherche avec indp1
        Pindp1 = C.getValue(z, 'GridCoordinates', ind+1)
        v1 = Vector.sub(Pindp1, Pind)
        v2 = Vector.sub(Xc, Pind)
        if Vector.dot(v1,v2) >= 0:
            val2 = C.getValue(zp, '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(z, 'GridCoordinates', ind-1)
        v1 = Vector.sub(Pindm1, Pind)
        v2 = Vector.sub(Xc, Pind)
        if Vector.dot(v1,v2) >= 0:
            val2 = C.getValue(zp, 's', ind-1)
            alpha = Vector.norm(v2)/Vector.norm(v1)
            valf = val+alpha*(val2-val)
    
    if h < 0: # enforce point
        distrib = G.enforcePoint(distrib, valf)
    else: # enforce h
        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)
    try:
        a1 = G.map(a, distrib)
        CTK.replace(CTK.t, nob, noz, a1)
    except Exception as e:
        fail = True
        Panels.displayErrors([0,str(e)], header='Error: stretch1D')
    return fail
コード例 #6
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
コード例 #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
コード例 #8
0
# - getLength (pyTree)-
import Geom.PyTree as D
import Converter.PyTree as C
import KCore.test as test

# test getLength structure
a = D.line((0, 0, 0), (1, 0, 0))
l = D.getLength(a)
test.testO(l, l)

# test getLength BAR
a2 = C.convertArray2Tetra(a)
l = D.getLength(a2)
test.testO(l, 2)

# test getLength par lots structure
b = D.line((10, 0, 0), (1, 0, 0))
l = D.getLength([a, b])
test.testO(l, 3)

# test getLength par lots non structure
b2 = C.convertArray2Tetra(b)
l = D.getLength([a2, b2])
test.testO(l, 4)

# test getLength par lots mixte
l = D.getLength([a, b2])
test.testO(l, 5)