def smooth1D(niter, eps):
    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)
            else: a = z
            a = D.getCurvilinearAbscissa(a)
            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(a, distrib)
            CTK.replace(CTK.t, nob, noz, b)
        except Exception as e:
            fail = True
            Panels.displayErrors([0,str(e)], header='Error: smooth1D')
    return fail
Beispiel #2
0
def exteriorFaces():
    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()

    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
    p = Internal.getNodesFromName1(CTK.t, 'CONTOURS')
    gnob = C.getNobOfBase(p[0], CTK.t)

    fail = False
    errors = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        try:
            ext = P.exteriorFaces(CTK.t[2][nob][2][noz])
            ext = T.splitConnexity(ext)
            for i in ext:
                CTK.add(CTK.t, gnob, -1, i)
        except TypeError as e:  # type d'element non reconnu
            fail = True
            errors += [0, str(e)]
        except ValueError:  # empty set
            pass
    #C._fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    if not fail: CTK.TXT.insert('START', 'Exterior faces done.\n')
    else:
        Panels.displayErrors(errors, header='Error: exteriorFaces')
        CTK.TXT.insert('START',
                       'Exterior faces fails for at least one zone.\n')
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
    CPlot.render()
# Extraction de lignes x = cste
bb = G.bbox(a)
xmin = bb[0]
ymin = bb[1]
zmin = bb[2]
xmax = bb[3]
ymax = bb[4]
zmax = bb[5]

bands = []
dx = 1. / 10
for i in range(10):
    x = i / 10.
    b = G.cart((x, ymin - 1, zmin - 1), (dx, ymax - ymin + 2, zmax - zmin + 2),
               (2, 2, 2))
    b = P.exteriorFaces(b)
    b = C.convertArray2Tetra(b)
    b = T.join(b)
    b = G.close(b)
    b = T.reorder(b, (-1, ))
    band = G.booleanIntersection(a, b)
    bands += [band]

# Boolean operators do not keep field
bands = P.extractMesh(a, bands)

# Sortie
t = C.newPyTree(['Base'])
t[2][1][2] += bands
C.convertPyTree2File(t, 'out.cgns')
# - blankCellsTri (pyTree) - 'NODE IN'
import Converter.PyTree as C
import Connector.PyTree as X
import Generator.PyTree as G
import Geom.PyTree as D
import Post.PyTree as P

# Tet mask
m = G.cart((0., 0., 0.), (0.1, 0.1, 0.2), (10, 10, 10))
m = P.exteriorFaces(m)
m = C.convertArray2Tetra(m)
# Mesh to blank
a = G.cart((-5., -5., -5.), (0.5, 0.5, 0.5), (100, 100, 100))

t = C.newPyTree(['Cart', a])
t = C.initVars(t, 'centers:cellN', 1.)

masks = [[m]]
# Matrice de masquage (arbre d'assemblage)
import numpy
BM = numpy.array([[1]])

t = X.blankCellsTri(t, masks, BM, blankingType='node_in', tol=1.e-12)
C.convertPyTree2File(t, 'out.cgns')
Beispiel #5
0
# - plaster (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Transform.PyTree as T
import Post.PyTree as P
import Geom.PyTree as D

a = D.sphere((0, 0, 0), 1)
a = T.subzone(a, (6, 1, 1), (50, 200, 1))
a = C.convertArray2Hexa(a)
a = G.close(a)

# contours
c = P.exteriorFaces(a)
cs = T.splitConnexity(c)

# plaster hole
p = G.plaster([cs[0]], [a])
t = C.newPyTree(['Sphere', 2, 'Contours', 1, 'Plaster', 2])
t[2][1][2].append(a)
t[2][2][2] += cs
t[2][3][2].append(p)
C.convertPyTree2File(t, 'out.cgns')
Beispiel #6
0
import Generator.PyTree as G
import Connector.PyTree as X
import Geom.PyTree as D
import Post.PyTree as P
import numpy as N
import Dist2Walls.PyTree as DTW
import Transform.PyTree as T
import Initiator.PyTree as I
import KCore.test as test
import sys

a = G.cart((-1, -1, -1), (0.04, 0.04, 1), (51, 51, 3))
s = G.cylinder((0, 0, -1), 0, 0.4, 360, 0, 4, (30, 30, 5))
s = C.convertArray2Tetra(s)
s = T.join(s)
s = P.exteriorFaces(s)
t = C.newPyTree(['Base'])
t[2][1][2] = [a]
# Blanking
bodies = [[s]]
BM = N.array([[1]], N.int32)
t = X.blankCells(t, bodies, BM, blankingType='center_in')
t = X.setHoleInterpolatedPoints(t, depth=-2)
# Dist2Walls
t = DTW.distance2Walls(t, [s], type='ortho', loc='centers', signed=1)
t = C.center2Node(t, 'centers:TurbulentDistance')
# Gradient de distance localise en centres => normales
t = P.computeGrad(t, 'TurbulentDistance')
t = I.initConst(t, MInf=0.2, loc='centers')
tc = C.node2Center(t)
t = X.setIBCData(t, tc, loc='centers', storage='direct')
Beispiel #7
0
# - exteriorFaces (pyTree) -
import Converter.PyTree as C
import Post.PyTree as P
import Generator.PyTree as G
import KCore.test as test

# test faces exterieures au sens large
# faces ayant 2 voisins
a = G.cartTetra((0, 0, 0), (1, 1., 1), (20, 2, 1))
a = C.addVars(a, 'Density')
a = C.addVars(a, 'centers:cellN')
t = C.newPyTree(['Base', 1])
t[2][1][2].append(a)
t[2][1] = C.addState(t[2][1], 'Mach', 0.6)
t = P.exteriorFaces(t)
test.testT(t, 1)

# test faces interieures au sens strict :
# faces n'ayant que des noeuds exterieurs
a = G.cartTetra((0, 0, 0), (1, 1., 1), (20, 2, 1))
a = C.addVars(a, 'Density')
a = C.addVars(a, 'centers:cellN')
t = C.newPyTree(['Base', 1])
t[2][1][2].append(a)
t[2][1] = C.addState(t[2][1], 'Mach', 0.6)
t = P.exteriorFaces(t)
test.testT(t, 2)

# cas 3D
a = G.cart((0, 0, 0), (1, 1, 1), (4, 4, 6))
a = C.addVars(a, 'Density')
Beispiel #8
0
# - setInterpTransfers IBC + extraction (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Connector.PyTree as X
import Geom.PyTree as D
import Post.PyTree as P
import numpy as N
import Dist2Walls.PyTree as DTW
import Transform.PyTree as T
import Initiator.PyTree as I
import Converter.Internal as Internal
import KCore.test as test

a = G.cart((-1,-1,-1),(0.04,0.04,1),(51,51,3))
s = G.cylinder((0,0,-1), 0, 0.4, 360, 0, 4, (30,30,5)) 
s = C.convertArray2Tetra(s); s = T.join(s); s = P.exteriorFaces(s)
t = C.newPyTree(['Base']); t[2][1][2] = [a]
# Blanking
bodies = [[s]]
BM = N.array([[1]],N.int32)
t = X.blankCells(t,bodies,BM,blankingType='center_in')
t = X.setHoleInterpolatedPoints(t,depth=-2)
# Dist2Walls
t = DTW.distance2Walls(t,[s],type='ortho',loc='centers',signed=1)
t = C.center2Node(t,'centers:TurbulentDistance')
# Gradient de distance localise en centres => normales
t = P.computeGrad(t, 'TurbulentDistance')
t = I.initConst(t,MInf=0.2,loc='centers')
tc = C.node2Center(t)
t = X.setIBCData(t, tc, loc='centers', storage='direct')
no = 1
Beispiel #9
0
def createGround():
    import Post.PyTree as P
    alpha = CTK.varsFromWidget(VARS[1].get(), type=2)
    if len(alpha) == 1:
        ax = alpha[0]
        ay = alpha[0]
        az = alpha[0]
        bx = alpha[0]
        by = alpha[0]
        bz = alpha[0]
    elif len(alpha) == 3:
        ax = alpha[0]
        ay = alpha[1]
        az = alpha[2]
        bx = alpha[0]
        by = alpha[1]
        bz = alpha[2]
    elif len(alpha) == 6:
        ax = alpha[0]
        ay = alpha[1]
        az = alpha[2]
        bx = alpha[3]
        by = alpha[4]
        bz = alpha[5]
    else:
        CTK.TXT.insert('START', 'Borders factor incorrect.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    try:
        box = G.bbox(CTK.t)
    except:
        box = [0, 0, 0, 1, 1, 1]
    hx = box[3] - box[0]
    hy = box[4] - box[1]
    hz = box[5] - box[2]
    if hx < 1.e-10: hx = 0.1
    if hy < 1.e-10: hy = 0.1
    if hz < 1.e-10: hz = 0.001
    h = max(hx, hy)
    ay = ax
    bx = ax
    by = ax
    # force square
    deltax = 0.5 * (h - hx)
    deltay = 0.5 * (h - hy)

    hx = h * 0.5
    hy = h * 0.5
    hz = 0.1 * hz
    b = G.cart(
        (box[0] - ax * hx - deltax, box[1] - ay * hy - deltay, box[2] - hz),
        (hx, hy, hz), (ax + bx + 3, ay + by + 3, 2))
    b = P.exteriorFaces(b)
    b = CPlot.addRender2Zone(b, material='Solid', color='White', meshOverlay=1)
    # plafond (optionel)
    c = G.cart((box[0] - ax * hx - deltax, box[1] - ay * hy - deltay, box[2] +
                (ax + bx + 2) * hx - hz), (hx, hy, hz),
               (ax + bx + 3, ay + by + 3, 1))

    return [b, c]
Beispiel #10
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()
# - exteriorFaces (pyTree) -
import Converter.PyTree as C
import Post.PyTree as P
import Generator.PyTree as G
import KCore.test as test

# test faces exterieures au sens large
# faces ayant 2 voisins
a = G.cartTetra((0, 0, 0), (1, 1., 1), (20, 2, 1))
C._addVars(a, 'Density')
C._addVars(a, 'centers:cellN')
b = P.exteriorFaces(a)
test.testT(b, 1)

# test faces interieures au sens strict :
# faces n'ayant que des noeuds exterieurs
a = G.cartTetra((0, 0, 0), (1, 1., 1), (20, 2, 1))
C._addVars(a, 'Density')
C._addVars(a, 'centers:cellN')
b = P.exteriorFaces(a)
test.testT(b, 2)

# cas 3D
a = G.cart((0, 0, 0), (1, 1, 1), (4, 4, 6))
C._addVars(a, 'Density')
C._addVars(a, 'centers:cellN')
b = P.exteriorFaces(a)
test.testT(b, 3)

# CAS avec indices
indices = []
t2 = G.close(t2)
#C.convertPyTree2File(t1, 'm.plt')
#C.convertPyTree2File(t2, 's.plt')

# test 1 : volume/volume
res = XOR.getOverlappingFaces(t1, t2, RTOL=0.05, ps_min=0.95)

# create a list of polygon list (t1), one list per zone
nb_zones = len(res)
t1zones_pgids = []
for i in range(nb_zones):
    t1zones_pgids.append(res[i][0])

t = XOR.agglomerateCellsWithSpecifiedFaces(t1, t1zones_pgids)

test.testT(t, 1)

#test 2 : volume/surface

t2 = P.exteriorFaces(t2)
t2 = XOR.convertNGON2DToNGON3D(t2)

res = XOR.getOverlappingFaces(t1, t2, RTOL=0.05, ps_min=0.95)

t1zones_pgids = []
for i in range(nb_zones):
    t1zones_pgids.append(res[i][0])

t = XOR.agglomerateCellsWithSpecifiedFaces(t1, t1zones_pgids)

test.testT(t, 2)
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
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
# - BB (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import Post.PyTree as P
import KCore.test as test

# Rotated box
box = G.cartTetra((0, 0, 0), (1., 1., 1.), (2, 2, 2))
box = P.exteriorFaces(box)
box = T.rotate(box, (0, 0, 0), (1, 0, 0), +50.)  # Rotation X
box = T.rotate(box, (0, 0, 0), (0, 1, 0), -20.)  # Rotation Y
box = T.rotate(box, (0, 0, 0), (0, 0, 1), 30.)  # Rotation Z
OBB = G.BB(box, method='OBB', weighting=1)
test.testT(OBB, 1)

# Aligned box
box = G.cartTetra((0, 0, 0), (1., 1., 1.), (2, 2, 2))
box = P.exteriorFaces(box)
OBB = G.BB(box, method='OBB', weighting=1)
test.testT(OBB, 2)
Beispiel #16
0
def generateCompositeIBMMesh(tb,
                             vmin,
                             snears,
                             dfar,
                             dfarloc=0.,
                             DEPTH=2,
                             NP=0,
                             check=True,
                             merged=1,
                             sizeMax=4000000,
                             symmetry=0,
                             externalBCType='BCFarfield'):
    tbox = None
    snearsf = None
    dimPb = Internal.getNodeFromName(tb, 'EquationDimension')
    if dimPb is None:
        raise ValueError('EquationDimension is missing in input body tree.')
    dimPb = Internal.getValue(dimPb)
    model = Internal.getNodeFromName(tb, 'GoverningEquations')
    refstate = C.getState(tb)
    # list of near body meshes
    t = Internal.copyRef(tb)
    Internal._rmNodesFromType(t, "Zone_t")
    snearsExt = []
    tblank = Internal.copyRef(tb)

    DEPTHEXT = 3 * DEPTH + 1
    tov = Internal.rmNodesFromType(tb, 'Zone_t')
    for nob in range(len(tb[2])):
        base = tb[2][nob]
        if base[3] == 'CGNSBase_t':
            basename = base[0]
            res = generateIBMMesh(base,
                                  vmin,
                                  snears,
                                  dfarloc,
                                  DEPTH=DEPTH,
                                  NP=NP,
                                  tbox=None,
                                  snearsf=None,
                                  check=check,
                                  merged=merged,
                                  symmetry=symmetry,
                                  sizeMax=sizeMax,
                                  externalBCType='BCDummy',
                                  to=None,
                                  composite=1,
                                  mergeByParents=False)

            res = Internal.getZones(res)
            t[2][nob][2] = res
            # blanking box for off-body mesh
            extFacesL = C.extractBCOfType(res, "BCDummy")
            bbl = G.bbox(extFacesL)
            lMax = 0.
            for extf in extFacesL:
                if dimPb == 2: extf = T.subzone(extf, (1, 1, 1), (-1, 1, 1))
                extf = G.getVolumeMap(extf)
                dxloc = C.getValue(extf, 'centers:vol', 0)
                if dimPb == 3:
                    dxloc = dxloc**0.5
                lMax = max(lMax, dxloc)
                snearsExt.append(dxloc)
                tov[2][nob][2].append(extf)

            # ATTENTION : engendre une boite parallelepipedique - peut ne pas etre valide dans
            # les cas ou le maillage cartesien proche corps n est pas parallelepipedique
            # A ameliorer
            # IDEM pour les conditions aux limites dans octree2StructLoc et generateIBMMesh
            xminb = bbl[0] + DEPTHEXT * lMax
            xmaxb = bbl[3] - DEPTHEXT * lMax
            yminb = bbl[1] + DEPTHEXT * lMax
            ymaxb = bbl[4] - DEPTHEXT * lMax
            if dimPb == 3:
                zminb = bbl[2] + DEPTHEXT * lMax
                zmaxb = bbl[5] - DEPTHEXT * lMax
                blankingBoxL = G.cart(
                    (xminb, yminb, zminb),
                    (xmaxb - xminb, ymaxb - yminb, zmaxb - zminb), (2, 2, 2))
            else:
                blankingBoxL = G.cart((xminb, yminb, 0.),
                                      (xmaxb - xminb, ymaxb - yminb, 1.),
                                      (2, 2, 1))
            blankingBoxL = P.exteriorFaces(blankingBoxL)
            tblank[2][nob][2] = [blankingBoxL]

    tcart = generateIBMMesh(tov,
                            vmin,
                            snearsExt,
                            dfar,
                            DEPTH=DEPTH,
                            NP=NP,
                            tbox=tbox,
                            snearsf=snearsf,
                            check=check,
                            merged=1,
                            sizeMax=sizeMax,
                            symmetry=symmetry,
                            externalBCType='BCFarfield',
                            to=None,
                            mergeByParents=True)
    tcart[2][1][0] = 'OffBody'
    C._rmBCOfType(
        t, 'BCDummy')  # near body grids external borders must be BCOverlap
    t = C.fillEmptyBCWith(t, 'ov_ext', 'BCOverlap', dim=dimPb)
    t = C.mergeTrees(t, tcart)
    model = Internal.getValue(model)
    C._addState(t, 'GoverningEquations', model)
    C._addState(t, 'EquationDimension', dimPb)
    C._addState(t, state=refstate)
    return t, tblank