Exemplo n.º 1
0
def compute():
    if CTK.t == []: return

    nzs = CPlot.getSelectedZones()
    if nzs == []:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    surf = 0
    walls = []
    name = VARS[1].get()
    if name == '': names = []
    else: names = name.split(';')
    for v in names:
        surf = 1
        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]: walls.append(z)

    if surf == 0:
        walls = C.extractBCOfType(CTK.t, 'BCWall')
        walls += C.extractBCOfType(CTK.t, 'BCWallViscous')
        walls += C.extractBCOfType(CTK.t, 'BCWallInviscid')

    tp = C.newPyTree(['Base'])
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        tp[2][1][2].append(z)

    try:
        if (VARS[2].get() == 'absolute'): signed = 0
        else: signed = 1
        tp = DTW.distance2Walls(tp,
                                walls,
                                type=VARS[0].get(),
                                loc=VARS[3].get(),
                                signed=signed)
        c = 0
        for nz in nzs:
            nob = CTK.Nb[nz] + 1
            noz = CTK.Nz[nz]
            CTK.t[2][nob][2][noz] = tp[2][1][2][c]
            c += 1
        #C._fillMissingVariables(CTK.t)
        CTK.TKTREE.updateApp()
        CTK.display(CTK.t)
        CTK.TXT.insert('START', 'Distance to walls computed.\n')
    except Exception as e:
        Panels.displayErrors([0, str(e)], header='Error: dist2Walls')
        CTK.TXT.insert('START', 'Distance to walls failed.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
Exemplo n.º 2
0
def initWallDistance():
    if CTK.t == []: return
    bodies = C.extractBCOfType(CTK.t, 'BCWall')
    for c in range(len(bodies)):
        try: bodies[c] = C.node2ExtCenter(bodies[c])
        except: pass
    tb = C.newPyTree(['Base', 2]); tb[2][1][2] += bodies
    CTK.saveTree()
    try:
        CTK.t = DW.distance2Walls(CTK.t, tb, loc='centers', type='ortho')
        CTK.TXT.insert('START', 'Distance to wall computed.\n')
    except Exception as e:
        Panels.displayErrors([0,str(e)], header='Error: wallDistance')
        CTK.TXT.insert('START', 'Wall distance fails.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
    CTK.TKTREE.updateApp()
    CTK.display(CTK.t)
Exemplo n.º 3
0
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')

#test avec arbre tc compact
zones = Internal.getNodesFromType2(t, 'Zone_t')
X.miseAPlatDonnorTree__(zones, t, procDict=None)

t2 = X.setInterpTransfers(t, tc, bcType=0, varType=1)
test.testT(t2, 1)

t2 = X.setInterpTransfers(t, tc, bcType=1, varType=1)
# Init wall
body = D.circle((0, 0, 0), 1., N=60)
res = G.octree([body], [snear], dfar=5., balancing=1)
res = G.octree2Struct(res, vmin=vmin, ext=DEPTH + 1, merged=1)
t = C.newPyTree(['Base', res])

# Mark solid and fluid points
X._applyBCOverlaps(t, depth=DEPTH, loc='nodes')
tc = Internal.copyRef(t)
tc = X.setInterpData(t, tc, loc='nodes', storage="inverse")
C._initVars(t, "cellN", 1.)
t = X.blankCells(t, [[body]], numpy.array([[1]]), blankingType='node_in')
X._setHoleInterpolatedPoints(t, depth=1, loc='nodes')
C._initVars(t, '{flag}=({cellN}>1.)')
t = DTW.distance2WallsEikonal(t, body, tc=tc, DEPTH=DEPTH, nitmax=10)
test.testT(t, 1)
# aux centres
t = C.newPyTree(['Base'])
t[2][1][2] = res
Internal._rmNodesFromName(t, "FlowSolution")
# Mark solid and fluid points
X._applyBCOverlaps(t, depth=DEPTH, loc='centers')
tc = C.node2Center(t)
tc = X.setInterpData(t, tc, loc='centers', storage="inverse")
C._initVars(t, "centers:cellN", 1.)
t = X.blankCells(t, [[body]], numpy.array([[1]]), blankingType='center_in')
X._setHoleInterpolatedPoints(t, depth=1)
C._initVars(t, '{centers:flag}=({centers:cellN}>1.)')
t = DTW.distance2WallsEikonal(t,
                              body,
import Converter.PyTree as C
import Dist2Walls.PyTree as DTW
import Generator.PyTree as G
import Geom.PyTree as D
import Connector.PyTree as X
import Transform.PyTree as T
import Connector.ToolboxIBM as TIBM

N = 11
N2 = 2 * N - 1
h = 1. / (N - 1)
a = G.cart((-1., -1., -1.), (h, h, h), (N2, N2, 2))
zmean = C.getMeanValue(a, 'CoordinateZ')
surf = D.sphere((0, 0, zmean), 0.5, 20)
t = C.newPyTree(['Cart', a])
C.convertPyTree2File(surf, "in.cgns")
bodies = [[surf]]
# Matrice de masquage (arbre d'assemblage)
import numpy

BM = numpy.array([[1]])
C._initVars(t, 'centers:cellN', 1.)
t = X.blankCells(t, bodies, BM, blankingType='center_in', delta=0.)
DTW._distance2Walls(t, surf, loc='centers', type='ortho')
C._initVars(t, "{centers:F}={centers:cellN}")
TIBM._blankClosestTargetCells(t)
C.convertPyTree2File(t, 'out.cgns')
import Converter.PyTree as C
import Generator.PyTree as G
import Connector.ToolboxIBM as IBM
import Post.PyTree as P
import Geom.PyTree as D
import Dist2Walls.PyTree as DTW
import KCore.test as test

N = 21
a = G.cart((0, 0, 0), (1. / (N - 1), 1. / (N - 1), 1. / (N - 1)), (N, N, N))
body = D.sphere((0.5, 0, 0), 0.1, N=20)
tb = C.newPyTree(['Base', body])
C._addState(tb, 'EquationDimension', 3)
C._addState(tb, 'GoverningEquations', 'NSTurbulent')
t = C.newPyTree(['Base', a])
DTW._distance2Walls(t, bodies=tb, loc='centers', type='ortho')
C._initVars(t, 'centers:cellN', 1.)
t, tc = IBM.prepareIBMData(t, tb, DEPTH=2, frontType=0, interpDataType=1)
res = IBM.extractIBMInfo(tc)
test.testT(tc, 1)

# front 1
tb = C.newPyTree(['Base', body])
C._addState(tb, 'EquationDimension', 3)
C._addState(tb, 'GoverningEquations', 'NSTurbulent')
DTW._distance2Walls(t, bodies=tb, loc='centers', type='ortho')
C._initVars(t, 'centers:cellN', 1.)
t, tc = IBM.prepareIBMData(t, tb, DEPTH=2, frontType=1, interpDataType=1)
test.testT(tc, 12)

# front2
Exemplo n.º 7
0
# - eikonal (pyTree) -
import Dist2Walls.PyTree as Dist2Walls
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import Connector.PyTree as X
import numpy

# Bloc cartesien
N = 128
h = 0.1
a = G.cart((0., 0., 0.), (h, h, h), (N, N, 1))
C._initVars(a, 'cellN', 1.)

# Init wall
sphere = D.sphere((6.4, 6.4, 0), 1., 100)
sphere = C.convertArray2Tetra(sphere)
sphere = G.close(sphere)
t = C.newPyTree(['Base'])
t[2][1][2] = [a]
t = X.blankCellsTri(t, [[sphere]], numpy.array([[1]]), blankingType='node_in')
# Initialise le front
C._initVars(t, '{Phi}=1.e12*({cellN}>0.)')
C._initVars(t, '{speed}=%f' % (1. / h))

# Eikonal
t = Dist2Walls.eikonal(t)
C.convertPyTree2File(t, 'out.cgns')
Exemplo n.º 8
0
# - dist2WallsEikonal (pyTree) -
import Converter.PyTree as C
import Connector.PyTree as X
import Converter.Internal as Internal
import Dist2Walls.PyTree as DTW
import Geom.PyTree as D
import Generator.PyTree as G
import numpy

DEPTH = 2
snear = 0.4; vmin = 21

# Init wall
body = D.circle((0,0,0),1.,N=60)
res = G.octree([body],[snear], dfar=5., balancing=1)
res = G.octree2Struct(res, vmin=vmin, ext=DEPTH+1,merged=1)
t = C.newPyTree(['Base']); t[2][1][2] = res

# Mark solid and fluid points
t = X.applyBCOverlaps(t,depth=DEPTH,loc='nodes')
tc = Internal.copyRef(t)
tc = X.setInterpData(t,tc,loc='nodes',storage="inverse")
C._initVars(t,"cellN",1.)
t = X.blankCells(t, [[body]], numpy.array([[1]]), blankingType='node_in')
t = X.setHoleInterpolatedPoints(t,depth=1,loc='nodes')
C._initVars(t,'flag=({cellN}>1.)')
t = DTW.distance2WallsEikonal(t,body,tc=tc,DEPTH=DEPTH,nitmax=10)
C.convertPyTree2File(t, 'out.cgns')
Exemplo n.º 9
0
# - distance2Walls (pyTree) -
# - Dump TurbulentDistance node to a file -
import Dist2Walls.PyTree as DW
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import Converter.Internal as Internal
import Converter
import numpy
import KCore.test as test

a = G.cart((0.,0.,0.),(0.1,0.1,0.1),(10,10,10))
a = C.initVars(a,'centers:cellnf',1.)
sphere = D.sphere((1.2,0.,0.),0.2,100)
sphere = C.initVars(sphere,'centers:cellnf',1.)

t = C.newPyTree(['Base',a])
bodies = C.newPyTree(['Bodies',sphere])
t = DW.distance2Walls(t, bodies,loc='centers')
nodes = Internal.getNodesFromName(t, 'TurbulentDistance')
dists = []
for n in nodes:
    ni = n[1].shape[0]; nj = n[1].shape[1]; nk = n[1].shape[2]
    a = numpy.reshape(n[1], (ni*nj*nk), order='Fortran')
    a = numpy.reshape(a, (1,ni*nj*nk))
    array = ['walldistance', a, ni, nj, nk]
    array = Converter.initVars(array, 'wallglobalindex', 1)
    dists.append(array)

test.testA(dists, 1)
# - distance2Walls (pyTree) -
import Dist2Walls.PyTree as Dist2Walls
import Generator.PyTree as G
import Converter.PyTree as C
import Converter.Internal as Internal
import Geom.PyTree as D
import Converter.elsAProfile as elsAProfile

a = G.cart((0., 0., 0.), (0.1, 0.1, 0.1), (10, 10, 10))
sphere = D.sphere((1.2, 0., 0.), 0.2, 100)
t = C.newPyTree(['Base', a])
t = Dist2Walls.distance2Walls(t, sphere)
Internal._renameNode(t, 'FlowSolution#Centers', 'FlowSolution#Init')
tp = elsAProfile.addTurbulentDistanceIndex(t)
C.convertPyTree2File(tp, 'out.cgns')
a = G.cart((-1, -1, -1), (0.1, 0.1, 1), (21, 21, 3))
s = G.cylinder((0, 0, -1), 0, 0.4, 360, 0, 4, (31, 31, 5))
s = C.convertArray2Tetra(s)
s = T.join(s)
s = P.exteriorFaces(s)
t = C.newPyTree(['Base', a])
tb = C.newPyTree(['Base', s])

# Blanking
bodies = [[s]]
BM = N.array([[1]], N.int32)
t = X.blankCells(t, bodies, BM, blankingType='center_in')
t = X.setHoleInterpolatedPoints(t, depth=-1)
# Dist2Walls
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')
t2 = X.setIBCData(t, t, loc='centers', storage='direct', bcType=-1)
test.testT(t2, 1)
t2 = X.setIBCData(t, t, loc='centers', storage='direct', hi=0.1, bcType=-1)
test.testT(t2, 2)

# NODES
t = C.newPyTree(['Base', a])
# Blanking
bodies = [[s]]
BM = N.array([[1]], N.int32)
t = X.blankCells(t, bodies, BM, blankingType='node_in')
t = X.setHoleInterpolatedPoints(t, depth=-1)
Exemplo n.º 12
0
# - Calcul de distance 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 Dist2Walls.PyTree as Dist2Walls

rank = Cmpi.rank
size = Cmpi.size

# lecture des parois
bodies = C.convertFile2PyTree('walls.cgns')

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

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

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

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

# Calcul des distances a la paroi
a = Dist2Walls.distance2Walls(a, bodies, type='mininterf')

# Reconstruit l'arbre complet a l'ecriture
Cmpi.convertPyTree2File(a, 'out.cgns')
Exemplo n.º 13
0
# Bloc cartesien
a = G.cart((0., 0., 0.), (0.1, 0.1, 0.1), (128, 128, 1))
C._initVars(a, 'cellN', 1)

# Init wall
sphere = D.sphere((6.4, 6.4, 0), 1., 30)
sphere = C.convertArray2Tetra(sphere)
sphere = G.close(sphere)
t = C.newPyTree(['Base'])
t[2][1][2] = [a]
t = X.blankCellsTri(t, [[sphere]], numpy.array([[1]]), blankingType='node_in')
C._initVars(t, '{Phi}=1.e12*({cellN}>0.)')
C._initVars(t, '{speed}=%f' % (1. / 0.1))

# Eikonal
t = Dist2Walls.eikonal(t)
C._rmVars(t, ['speed'])
test.testT(t, 1)

# loc='centers'
a = G.cart((0., 0., 0.), (0.1, 0.1, 0.1), (128, 128, 1))
C._initVars(a, 'centers:cellN', 1)
t = C.newPyTree(['Base'])
t[2][1][2] = [a]
t = X.blankCellsTri(t, [[sphere]],
                    numpy.array([[1]]),
                    blankingType='center_in')
C._initVars(t, '{centers:speed}=%f' % (1. / 0.1))
# Eikonal
C._initVars(t, '{centers:flag}=({centers:cellN})<1.')  # pts sources
C._initVars(t, '{centers:Phi}=1.e12*({centers:cellN}>0.)')
import Geom.PyTree as D

# Body structured, celln aux centres
sphere = D.sphere((0.5,0.5,0.5), 0.2, 50)
sphere = C.initVars(sphere, 'centers:cellnf', 1.)
bodies = C.newPyTree(['Bodies',2,sphere])

a = G.cart((0.,0.,0.),(0.1,0.1,0.1),(11,11,11))
# --- champ aux noeuds
a = C.initVars(a, 'Density', 0.5)
# --- champ aux centres
a = C.initVars(a, 'Pressure', 0.7)
t = C.newPyTree(['Base', a])
# --- Equation state
t[2][1] = C.addState(t[2][1], 'EquationDimension', 3)
t2 = DW.distance2Walls(t, bodies, type='mininterf', loc='centers')
test.testT(t2,1)

# Body structured, celln aux noeuds
sphere = D.sphere((0.5,0.5,0.5), 0.2, 50)
sphere = C.initVars(sphere,'cellnf', 1.)
bodies = C.newPyTree(['Bodies',2,sphere])

a = G.cart((0.,0.,0.),(0.1,0.1,0.1),(11,11,11))
# --- champ aux noeuds
a = C.initVars(a, 'Density', 0.5)
# --- champ aux centres
a = C.initVars(a, 'Pressure', 0.7)
t = C.newPyTree(['Base',a])
# --- Equation state
t[2][1] = C.addState(t[2][1], 'EquationDimension', 3)
Exemplo n.º 15
0
DEPTH = 2
# Bloc cartesien
N = 128; h = 0.1
a = G.cart((0.,0.,0.),(h,h,h),(N,N,1))
# Init wall
sphere = D.sphere((6.4,6.4,0), 1., 100)
sphere = C.convertArray2Tetra(sphere)
sphere = G.close(sphere)
t = C.newPyTree(['Base']); t[2][1][2] = [a]; 
C._initVars(t,'cellN=1')
t = X.blankCellsTri(t, [[sphere]], numpy.array([[1]]), blankingType='node_in')
# Condition aux limites
t = X.setHoleInterpolatedPoints(t,depth=1,loc='nodes')
C._initVars(t,'flag=({cellN}>1.)')
t = DTW.distance2WallsEikonal(t,sphere,DEPTH=DEPTH,nitmax=10)
C.convertPyTree2File(t, 'out.cgns')

# Bloc cartesien
N = 64; h = 0.2
a = G.cart((0.,0.,0.),(h,h,h),(N,N,1)); a[0] = 'cart2'
# Init wall
sphere = D.sphere((6.4,6.4,0), 1., 100)
sphere = C.convertArray2Tetra(sphere)
sphere = G.close(sphere)
t = C.newPyTree(['Base']); t[2][1][2] = [a]
C._initVars(t,'cellN=1.')
t = X.blankCellsTri(t, [[sphere]], numpy.array([[1]]), blankingType='node_in')
t = X.setHoleInterpolatedPoints(t,depth=1,loc='nodes')
# Initialise le front
C._initVars(t,'flag=({cellN}>1.)')
Exemplo n.º 16
0
# Bloc cartesien
N = 128
h = 0.1
a = G.cart((0., 0., 0.), (h, h, h), (N, N, 1))

# Init wall
sphere = D.sphere((6.4, 6.4, 0), 1., 100)
sphere = C.convertArray2Tetra(sphere)
sphere = G.close(sphere)
t = C.newPyTree(['Base', a])
C._initVars(t, 'cellN', 1)
t = X.blankCellsTri(t, [[sphere]], numpy.array([[1]]), blankingType='node_in')
# Condition aux limites
t = X.setHoleInterpolatedPoints(t, depth=1, loc='nodes')
C._initVars(t, '{flag}=({cellN}>1.)')
t = DTW.distance2WallsEikonal(t, sphere, tc=None, DEPTH=DEPTH, nitmax=10)
test.testT(t, 1)

# En centres
# Bloc cartesien
N = 128
h = 0.1
a = G.cart((0., 0., 0.), (h, h, h), (N, N, 1))

# Init wall
sphere = D.sphere((6.4, 6.4, 0), 1., 100)
sphere = C.convertArray2Tetra(sphere)
sphere = G.close(sphere)
t = C.newPyTree(['Base'])
t[2][1][2] = [a]
C._initVars(t, 'centers:cellN', 1)
# - distance2Walls (pyTree) -
# - Dump TurbulentDistance node to a file -
import Dist2Walls.PyTree as DW
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import Converter.Internal as Internal
import Converter
import numpy

a = G.cart((0., 0., 0.), (0.1, 0.1, 0.1), (10, 10, 10))
a = C.initVars(a, 'centers:cellnf', 1.)
sphere = D.sphere((1.2, 0., 0.), 0.2, 100)
sphere = C.initVars(sphere, 'centers:cellnf', 1.)

t = C.newPyTree(['Base', a])
bodies = C.newPyTree(['Bodies', sphere])
t = DW.distance2Walls(t, bodies)
nodes = Internal.getNodesFromName(t, 'TurbulentDistance')
c = 0
for n in nodes:
    ni = n[1].shape[0]
    nj = n[1].shape[1]
    nk = n[1].shape[2]
    a = numpy.reshape(n[1], (ni * nj * nk), order='Fortran')
    a = numpy.reshape(a, (1, ni * nj * nk))
    array = ['walldistance', a, ni, nj, nk]
    array = Converter.initVars(array, 'wallglobalindex', 1)
    Converter.convertArrays2File([array], 'dist' + str(c) + '.v3d', 'bin_v3d')
    c += 1
Exemplo n.º 18
0
# - prepareIBMData (pyTree) -
import Converter.PyTree as C
import Generator.PyTree as G
import Connector.ToolboxIBM as IBM
import Post.PyTree as P
import Geom.PyTree as D
import Dist2Walls.PyTree as DTW
import KCore.test as test
N = 51
a = G.cart((0, 0, 0), (1. / (N - 1), 1. / (N - 1), 1. / (N - 1)), (N, N, N))
body = D.sphere((0.5, 0, 0), 0.1, N=20)
t = C.newPyTree(['Base', a])
tb = C.newPyTree(['Base', body])
tb = C.addState(tb, 'EquationDimension', 3)
tb = C.addState(tb, 'GoverningEquations', 'NSTurbulent')
t = DTW.distance2Walls(t, bodies=tb, loc='centers', type='ortho')
t = P.computeGrad(t, 'centers:TurbulentDistance')
t, tc = IBM.prepareIBMData(t, tb, DEPTH=2, frontType=1)
C.convertPyTree2File(t, 't.cgns')
C.convertPyTree2File(t, 'tc.cgns')
Exemplo n.º 19
0
t = C.newPyTree(['Base'])
t[2][1][2] = m
t = C.initVars(t, 'centers:cellN', 1.)
#
# Get the wall surfaces
#
walls = C.extractBCOfType(t, 'BCWall')
walls += C.extractBCOfType(t, 'BCWallViscous')
walls += C.extractBCOfType(t, 'BCWallInviscid')

# Convert the wall border to centers
bodies = C.node2Center(walls)
#
# Computes the distance field
#
t = DTW.distance2Walls(t, bodies, loc='centers', type='mininterf')
#
# Write the distance files for elsA
#

nodes = Internal.getNodesFromName(t, 'TurbulentDistance')
c = 0
for n in nodes:
    ni = n[1].shape[0]
    nj = n[1].shape[1]
    nk = n[1].shape[2]
    a = numpy.reshape(n[1], (ni * nj * nk), order='Fortran')
    a = numpy.reshape(a, (1, ni * nj * nk))
    array = ['walldistance', a, ni, nj, nk]
    array = Converter.initVars(array, 'wallglobalindex', 1)
    Converter.convertArrays2File([array], 'dist' + str(c) + '.v3d', 'bin_v3d')