コード例 #1
0
def outCore():
    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
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        z = CTK.t[2][nob][2][noz]
        ooc = Internal.getNodesFromName1(z, 'OutOfCore')
        if (len(ooc) == 0):
            # Save zone
            base = CTK.t[2][nob]
            name = '.' + base[0] + '#' + z[0] + '.cgns'
            t = C.newPyTree(['Base'])
            t[2][1][2].append(z)
            C.convertPyTree2File(t, name)
            # Replace zone
            bb = G.BB(z)
            bb[2].append(['OutOfCore', numpy.array([1]), [], \
                          'UserDefinedData_t'])
            bb = CPlot.addRender2Zone(bb, blending=0.2)
            CTK.replace(CTK.t, nob, noz, bb)
    CTK.saveTree()  # il est apres pour forcer le flush
    CTK.TXT.insert('START', 'Selected zones out of core.\n')
    CTK.t = C.fillMissingVariables(CTK.t)
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
コード例 #2
0
def createBBoxTree(t, method='AABB', weighting=0):
    """Return a bbox tree of t."""
    try:
        import Generator.PyTree as G
    except:
        raise ImportError("createBBoxTree requires Generator module.")
    # bounding box des zones locales
    tp = Internal.node2PyTree(t)
    bases = Internal.getBases(t)
    zb = []
    for b in bases:
        zones = Internal.getNodesFromType1(b, 'Zone_t')
        for z in zones:
            if not Distributed.isZoneSkeleton__(z):
                zbb = G.BB(z, method, weighting)
                # Clean up (zoneSubRegion)
                Internal._rmNodesFromType(zbb, 'ZoneSubRegion_t')
                zb.append(zbb)

    # Echanges des zones locales de bounding box
    # (allgather serialise automatiquement les donnees)
    zones = KCOMM.allgather(zb)

    # On les remplace dans l'arbre (par noms)
    tb = Distributed.setZonesInTree(t, zones)
    return tb
コード例 #3
0
def prepareCompositeChimeraData(t,
                                tc,
                                tblank,
                                noBaseOff,
                                DEPTH=2,
                                loc='centers',
                                NIT=1,
                                RotationCenter=None,
                                RotationAngle=None,
                                Translation=None):
    tBB = G.BB(tc)
    listOfOffBodyIntersectingNBZones = getListOfOffBodyIntersectingNBZones(
        tBB,
        noBaseOff,
        NIT=NIT,
        DEPTH=DEPTH,
        RotationCenter=RotationCenter,
        RotationAngle=RotationAngle,
        Translation=Translation)
    listOfSteadyOffBodyZones = getListOfSteadyOffBodyZones(
        tBB, noBaseOff, listOfOffBodyIntersectingNBZones)

    t, tc = prepareSteadyOffBodyChimeraData(
        t,
        tc,
        tblank,
        noBaseOff,
        tBB=tBB,
        DEPTH=2,
        loc='centers',
        NIT=NIT,
        RotationCenter=RotationCenter,
        RotationAngle=RotationAngle,
        Translation=Translation,
        listOfSteadyOffBodyZones=listOfSteadyOffBodyZones)

    t, tc = prepareMotionChimeraData(
        t,
        tc,
        tblank,
        noBaseOff,
        tBB=tBB,
        DEPTH=2,
        loc='centers',
        NIT=NIT,
        RotationCenter=RotationCenter,
        RotationAngle=RotationAngle,
        Translation=Translation,
        listOfSteadyOffBodyZones=listOfSteadyOffBodyZones,
        listOfOffBodyIntersectingNBZones=listOfOffBodyIntersectingNBZones)

    Internal._rmNodesByName(tc, Internal.__FlowSolutionNodes__)
    Internal._rmNodesByName(tc, Internal.__GridCoordinates__)
    return t, tc
コード例 #4
0
# - bboxIntersection (pyTree) -
import Generator.PyTree as G
import Transform.PyTree as T
import KCore.test as test

boxA = G.cartTetra((2,-1,0.5), (1,2,0.5), (2,2,2)) 

boxB = G.cartTetra((2,-1,0.5), (2,2,1), (2,2,2)) 
boxB  = T.rotate(boxB,(0,0,0),(10,5,-20))
AABB = G.BB(boxA)
OBB = G.BB(boxB, method='OBB')

intersect = G.bboxIntersection(AABB, AABB, tol=1e-10,isBB=True, method='AABB')
test.testO(intersect,1)

intersect = G.bboxIntersection(AABB, OBB, tol=1e-10, isBB=True, method='AABBOBB')
test.testO(intersect,2)

intersect = G.bboxIntersection(AABB, OBB, tol=1e-10, isBB=True, method='OBB')
test.testO(intersect,3)

コード例 #5
0
ファイル: BBPT_t1.py プロジェクト: MicK7/cassiopee_anaconda
# - BB (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Geom.PyTree as D
import KCore.test as test

s = D.circle((0, 0, 0), 1., N=100)
a = G.BB(s)
a[0] = 'bbox'
test.testT(a, 1)
コード例 #6
0
# - 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)
コード例 #7
0
def prepareSteadyOffBodyChimeraData(t,
                                    tc,
                                    tblank,
                                    noBaseOff,
                                    tBB=None,
                                    DEPTH=2,
                                    loc='centers',
                                    NIT=1,
                                    RotationCenter=[0, 0, 0],
                                    RotationAngle=[0, 0, 0.],
                                    Translation=[0, 0, 0],
                                    listOfSteadyOffBodyZones=None):

    if listOfSteadyOffBodyZones is None:
        raise ValueError(
            "prepareSteadyOffBodyChimeraData: listOfSteadyOffBodyZones is None."
        )
    # arbre de BBox des zones donneuses
    if tBB is None: tBB = G.BB(tc)  # BB des zones donneuses
    intersectionDict = X.getIntersectingDomains(tBB[2][noBaseOff])

    dictOfOffBodyZoneNb = {}
    for noz in range(len(tc[2][noBaseOff][2])):
        z = tc[2][noBaseOff][2][noz]
        if Internal.getType(z) == 'Zone_t': dictOfOffBodyZoneNb[z[0]] = noz

    dictOfOffBodyZoneNbRcv = {
    }  # t et tc peuvent ne pas avoir la meme structure
    for noz in range(len(t[2][noBaseOff][2])):
        z = t[2][noBaseOff][2][noz]
        if Internal.getType(z) == 'Zone_t': dictOfOffBodyZoneNbRcv[z[0]] = noz

    C._initVars(t[2][noBaseOff], "centers:cellN", 1.)
    t[2][noBaseOff] = X.applyBCOverlaps(t[2][noBaseOff], depth=DEPTH, loc=loc)
    C._cpVars(t[2][noBaseOff], "centers:cellN", tc[2][noBaseOff], "cellN")
    dictOfADT = {}  # preconditionnement
    for zname in listOfSteadyOffBodyZones:
        noz = dictOfOffBodyZoneNbRcv[zname]
        z = t[2][noBaseOff][2][noz]
        intersectingZones = intersectionDict[zname]
        donorZones = []
        hooks = []
        for znamed in intersectingZones:
            nozd = dictOfOffBodyZoneNb[znamed]
            zd = tc[2][noBaseOff][2][nozd]
            if znamed not in dictOfADT:
                hook0 = C.createHook(zd, 'adt')
                dictOfADT[znamed] = hook0
            hooks.append(dictOfADT[znamed])
            donorZones.append(zd)

        donorZones = X.setInterpData(z,donorZones,nature=1,penalty=1,loc='centers',storage='inverse',sameName=1,\
                                     hook=hooks, itype='chimera')
        for zd in donorZones:
            znamed = zd[0]
            nozd = dictOfOffBodyZoneNb[znamed]
            tc[2][noBaseOff][2][nozd] = zd

    for dnrname in dictOfADT:
        C.freeHook(dictOfADT[dnrname])
    return t, tc
コード例 #8
0
def prepareMotionChimeraData(t,
                             tc,
                             tblank,
                             noBaseOff,
                             tBB=None,
                             DEPTH=2,
                             loc='centers',
                             NIT=1,
                             RotationCenter=None,
                             RotationAngle=None,
                             Translation=None,
                             listOfSteadyOffBodyZones=None,
                             listOfOffBodyIntersectingNBZones=None):

    # arbre de BBox des zones donneuses
    if tBB is None: tBB = G.BB(tc)  # BB des zones donneuses

    if listOfOffBodyIntersectingNBZones is None:
        listOfOffBodyIntersectingNBZones = getListOfOffBodyIntersectingNBZones(
            tBB,
            noBaseOff,
            NIT=NIT,
            DEPTH=DEPTH,
            RotationCenter=RotationCenter,
            RotationAngle=RotationAngle,
            Translation=Translation)
        listOfSteadyOffBodyZones = getListOfSteadyOffBodyZones(
            tBB, noBaseOff, listOfOffBodyIntersectingNBZones)

    if listOfSteadyOffBodyZones is None:
        listOfSteadyOffBodyZones = getListOfSteadyOffBodyZones(
            tBB, noBaseOff, listOfOffBodyIntersectingNBZones)

    dimPb = Internal.getNodeFromName(t, 'EquationDimension')
    if dimPb is None:
        raise ValueError('EquationDimension is missing in input body tree.')
    dimPb = Internal.getValue(dimPb)
    if dimPb == 2:
        z0 = Internal.getNodeFromType2(t, 'Zone_t')
        dims = Internal.getZoneDim(z0)
        npts = dims[1] * dims[2] * dims[3]
        zmin = C.getValue(z0, 'CoordinateZ', 0)
        zmax = C.getValue(z0, 'CoordinateZ', npts - 1)
        dz = zmax - zmin
        # Creation du corps 2D pour le preprocessing IBC
        tblank = T.addkplane(tblank)
        tblank = T.contract(tblank, (0, 0, 0), (1, 0, 0), (0, 1, 0), dz)

    rotation = True
    translation = True
    if RotationAngle is None: rotation = False
    if Translation is None: translation = False
    if rotation is True and translation is True:
        raise ValueError(
            "ToolboxIBM: translation and rotation not yet possible together.")
    constantMotion = False
    if rotation:
        if len(RotationAngle) == 3 and isinstance(RotationAngle[0],
                                                  list) == False:
            constantMotion = True
    if translation:
        if len(Translation) == 3 and isinstance(Translation[0], list) == False:
            constantMotion = True

    xc0 = RotationCenter[0]
    yc0 = RotationCenter[1]
    zc0 = RotationCenter[2]

    C._initVars(t[2][noBaseOff], '{centers:cellNInit}={centers:cellN}')
    C._initVars(tc[2][noBaseOff], "{cellNInit}={cellN}")
    dictOfNearBodyBaseNb = {}
    dictOfNearBodyZoneNb = {}
    for nob in range(len(tc[2])):
        if nob != noBaseOff:
            base = tc[2][nob]
            if Internal.getType(base) == 'CGNSBase_t':
                for noz in range(len(base[2])):
                    zone = base[2][noz]
                    if Internal.getType(zone) == 'Zone_t':
                        zname = zone[0]
                        dictOfNearBodyZoneNb[zname] = noz
                        dictOfNearBodyBaseNb[zname] = nob

    dictOfOffBodyZoneNb = {}
    dictOfOffBodyADT = {}  # preconditionnement
    for noz in range(len(tc[2][noBaseOff][2])):
        z = tc[2][noBaseOff][2][noz]
        zname = z[0]
        if Internal.getType(z) == 'Zone_t':
            dictOfOffBodyZoneNb[zname] = noz
            if zname in listOfOffBodyIntersectingNBZones:
                zc = tc[2][noBaseOff][2][noz]
                hook0 = C.createHook(zc, 'adt')
                dictOfOffBodyADT[zname] = hook0

    C._initVars(tc, '{CoordinateXInit}={CoordinateX}')
    C._initVars(tc, '{CoordinateYInit}={CoordinateY}')
    C._initVars(tc, '{CoordinateZInit}={CoordinateZ}')
    C._initVars(t, '{CoordinateXInit}={CoordinateX}')
    C._initVars(t, '{CoordinateYInit}={CoordinateY}')
    C._initVars(t, '{CoordinateZInit}={CoordinateZ}')
    C._initVars(tBB, '{CoordinateXInit}={CoordinateX}')
    C._initVars(tBB, '{CoordinateYInit}={CoordinateY}')
    C._initVars(tBB, '{CoordinateZInit}={CoordinateZ}')

    if NIT > 1:
        for zc in Internal.getZones(tc):
            IDatas = Internal.getNodesFromName(zc, "ID_*")
            for ID in IDatas:
                name = ID[0].split('_')
                ID[0] = 'IDSteady_%s' % (name[1])

    tloc = C.newPyTree(['OffMotion'])
    for zr in t[2][noBaseOff][2]:
        if Internal.getType(zr) == 'Zone_t':
            znamer = zr[0]
            if znamer not in listOfSteadyOffBodyZones:
                # print " Zone de fond en mvt %s"%znamer
                tloc[2][1][2].append(zr)
            else:
                tloc[2][1][2].append(zr)
        tBBloc = G.BB(tloc)

    # a remonter dans l interface
    intersectionsDictOffOff = X.getIntersectingDomains(tBB[2][noBaseOff],
                                                       method='AABB',
                                                       taabb=tBB[2][noBaseOff])
    listOfIntersectionDictsNBNB = {}
    for nob in range(len(t[2])):
        if nob != noBaseOff and Internal.getType(t[2][nob]) == 'CGNSBase_t':
            intersectionsDictNB = X.getIntersectingDomains(tBB[2][nob],
                                                           method='AABB',
                                                           taabb=tBB[2][nob])
            listOfIntersectionDictsNBNB[nob] = intersectionsDictNB

    for it in range(NIT):
        print(' ------------------- Iteration %d ----------------------- ' %
              it)
        if constantMotion:
            if rotation:
                angleX = RotationAngle[0] * it
                angleY = RotationAngle[1] * it
                angleZ = RotationAngle[2] * it
                print('Rotation (degres) : (alphaX=%g,alphaY=%g,alphaZ=%g)' %
                      (angleX, angleY, angleZ))

            elif translation:
                tx = Translation[0]
                ty = Translation[1]
                tz = Translation[2]
        else:
            if rotation:
                angleX = RotationAngle[it][0]
                angleY = RotationAngle[it][1]
                angleZ = RotationAngle[it][2]
                print('Rotation (degres) : (alphaX=%g,alphaY=%g,alphaZ=%g)' %
                      (angleX, angleY, angleZ))

            elif translation:
                tx = Translation[it][0]
                ty = Translation[it][1]
                tz = Translation[it][2]

        if rotation:
            tblankM = T.rotate(tblank, (xc0, yc0, zc0),
                               (angleX, angleY, angleZ))
        elif translation:
            tblankM = T.translate(tblank, (tx, ty, tz))

        C._initVars(tloc, "{centers:cellN}={centers:cellNInit}")
        tloc = blankByIBCBodies(tloc,
                                tblankM,
                                'centers',
                                dim=dimPb,
                                gridType='composite')
        tloc = X.setHoleInterpolatedPoints(tloc, depth=DEPTH, loc='centers')
        for zloc in Internal.getZones(tloc):
            zname = zloc[0]
            nozloc = dictOfOffBodyZoneNb[zname]
            C._cpVars(zloc, 'centers:cellN', tc[2][noBaseOff][2][nozloc],
                      "cellN")

        dictOfMotionADT = {
        }  # ADT des blocs en mvt  a detruire a chq pas de temps

        # bases proches corps interpolees par le maillage de fond fixe + ses voisins
        for nob in range(len(t[2])):
            base = t[2][nob]
            if nob != noBaseOff and Internal.getType(base) == 'CGNSBase_t':
                if rotation:
                    T._rotate(base, (xc0, yc0, zc0), (angleX, angleY, angleZ))
                    T._rotate(tBB[2][nob], (xc0, yc0, zc0),
                              (angleX, angleY, angleZ))
                    T._rotate(tc[2][nob], (xc0, yc0, zc0),
                              (angleX, angleY, angleZ))
                elif translation:
                    T._translate(base, (tx, ty, tz))
                    T._translate(tBB[2][nob], (tx, ty, tz))
                    T._translate(tc[2][nob], (tx, ty, tz))

        tBBNB = Internal.rmNodesByName(tBB, tBB[2][noBaseOff][0])
        intersectionsDictOffNB = X.getIntersectingDomains(
            tBB[2][noBaseOff],
            t2=tBBNB,
            method='AABB',
            taabb=tBB[2][noBaseOff],
            taabb2=tBBNB)
        for nob in range(len(t[2])):
            base = t[2][nob]
            if nob != noBaseOff and Internal.getType(base) == 'CGNSBase_t':
                # test intersection entre maillage proche corps et maillage de fond
                intersectionsDictNBO = X.getIntersectingDomains(
                    tBB[2][nob],
                    t2=tBB[2][noBaseOff],
                    method='AABB',
                    taabb=tBB[2][nob],
                    taabb2=tBB[2][noBaseOff])

                print('Near-body base %s in motion' % (base[0]))
                intersectionsDictNBNB = listOfIntersectionDictsNBNB[nob]
                for zr in Internal.getZones(base):
                    if Internal.getNodesFromName(zr, "ov_ext*") != []:
                        znamer = zr[0]
                        donorZones = []
                        hooks = []
                        for znamed in intersectionsDictNBO[znamer]:
                            if znamed in dictOfOffBodyZoneNb:  # donneur=fond
                                nozd = dictOfOffBodyZoneNb[znamed]
                                zd = tc[2][noBaseOff][2][nozd]
                                hooks.append(dictOfOffBodyADT[znamed])
                                donorZones.append(zd)
                        for znamed in intersectionsDictNBNB[znamer]:
                            nozd = dictOfNearBodyZoneNb[znamed]
                            nobd = dictOfNearBodyBaseNb[znamed]
                            zd = tc[2][nobd][2][nozd]
                            if znamed not in dictOfMotionADT:
                                hook0 = C.createHook(zd, 'adt')
                                dictOfMotionADT[znamed] = hook0
                            hooks.append(dictOfMotionADT[znamed])
                            donorZones.append(zd)

                        donorZones = X.setInterpData(zr,donorZones,nature=1,penalty=1,loc='centers',storage='inverse',sameName=1,\
                                                     hook=hooks, itype='chimera')
                        for zd in donorZones:
                            znamed = zd[0]
                            if znamed in dictOfOffBodyZoneNb:
                                nozd = dictOfOffBodyZoneNb[znamed]
                                tc[2][noBaseOff][2][nozd] = zd
                            elif znamed in dictOfNearBodyZoneNb:
                                nozd = dictOfNearBodyZoneNb[znamed]
                                nobd = dictOfNearBodyBaseNb[znamed]
                                tc[2][nobd][2][nozd] = zd

        # base de fond : interpolee depuis ses zones voisines + zones proches corps
        # les donneurs proches corps mobiles sont deja deplaces
        # intersectionsDict = X.getIntersectingDomains(tBBloc,t2=tBB,method='AABB',taabb=tBBloc,taabb2=tBB)
        for zr in Internal.getZones(tloc):
            znamer = zr[0]
            if znamer not in listOfSteadyOffBodyZones:
                donorZones = []
                hooks = []
                for znamed in intersectionsDictOffOff[
                        znamer]:  # donneur=maillage de fond
                    nozd = dictOfOffBodyZoneNb[znamed]
                    zd = tc[2][noBaseOff][2][nozd]
                    if znamed not in dictOfOffBodyADT:
                        hook0 = C.createHook(zd, 'adt')
                        dictOfOffBodyADT[znamed] = hook0
                    hooks.append(dictOfOffBodyADT[znamed])
                    donorZones.append(zd)
                for znamed in intersectionsDictOffNB[znamer]:
                    nozd = dictOfNearBodyZoneNb[znamed]
                    nobd = dictOfNearBodyBaseNb[znamed]
                    zd = tc[2][nobd][2][nozd]
                    if znamed not in dictOfMotionADT:
                        hook0 = C.createHook(zd, 'adt')
                        dictOfMotionADT[znamed] = hook0
                    hooks.append(dictOfMotionADT[znamed])
                    donorZones.append(zd)

                # print 'Off-body motion zone %s'%znamer
                donorZones = X.setInterpData(zr,donorZones,nature=1,penalty=1,loc='centers',storage='inverse',sameName=1,\
                                             hook=hooks, itype='chimera')
                for zd in donorZones:
                    znamed = zd[0]
                    if znamed in dictOfOffBodyZoneNb:
                        nozd = dictOfOffBodyZoneNb[znamed]
                        tc[2][noBaseOff][2][nozd] = zd
                    elif znamed in dictOfNearBodyZoneNb:
                        nozd = dictOfNearBodyZoneNb[znamed]
                        nobd = dictOfNearBodyBaseNb[znamed]
                        tc[2][nobd][2][nozd] = zd

        for dnrname in dictOfMotionADT:
            C.freeHook(dictOfMotionADT[dnrname])

        # Reinit
        if NIT == 1:
            for dnrname in dictOfOffBodyADT:
                C.freeHook(dictOfOffBodyADT[dnrname])
            C._rmVars(tc, [
                "CoordinateX", "CoordinateY", "CoordinateZ", "cellNInit",
                "CoordinateXInit", "CoordinateYInit", "CoordinateZInit"
            ])
            C._initVars(t, '{CoordinateX}={CoordinateXInit}')
            C._initVars(t, '{CoordinateY}={CoordinateYInit}')
            C._initVars(t, '{CoordinateZ}={CoordinateZInit}')
            C._rmVars(t, [
                "centers:cellNInit", "CoordinateXInit", "CoordinateYInit",
                "CoordinateZInit"
            ])
            C._cpVars(tc, "cellN", t, 'centers:cellN')
            return t, tc

        else:
            for zc in Internal.getZones(tc):
                IDatas = Internal.getNodesFromName(zc, "ID_*")
                for ID in IDatas:
                    name = ID[0].split('_')
                    ID[0] = 'ID#%d_%s' % (it, name[1])

            if it == 5:
                C.convertPyTree2File(t, "t5.cgns")
                C.convertPyTree2File(tc, "tc5.cgns")
            C._initVars(tc[2][noBaseOff], "{cellN}={cellNInit}")  # reinit
            C._initVars(t[2][noBaseOff],
                        "{centers:cellN}={centers:cellNInit}")  # reinit
            C._initVars(tc, '{CoordinateX}={CoordinateXInit}')
            C._initVars(tc, '{CoordinateY}={CoordinateYInit}')
            C._initVars(tc, '{CoordinateZ}={CoordinateZInit}')
            C._initVars(t, '{CoordinateX}={CoordinateXInit}')
            C._initVars(t, '{CoordinateY}={CoordinateYInit}')
            C._initVars(t, '{CoordinateZ}={CoordinateZInit}')
            C._initVars(tBB, '{CoordinateX}={CoordinateXInit}')
            C._initVars(tBB, '{CoordinateY}={CoordinateYInit}')
            C._initVars(tBB, '{CoordinateZ}={CoordinateZInit}')

    for dnrname in dictOfOffBodyADT:
        C.freeHook(dictOfOffBodyADT[dnrname])

    C._rmVars(t, [
        "centers:cellNInit", "CoordinateXInit", "CoordinateYInit",
        "CoordinateZInit"
    ])
    C._initVars(tc[2][noBaseOff], "{cellN}={cellNInit}")
    C._cpVars(tc, "cellN", t, "centers:cellN")
    C._rmVars(
        tc,
        ["cellNInit", "CoordinateXInit", "CoordinateYInit", "CoordinateZInit"])
    return t, tc
コード例 #9
0
# - getIntersectingDomainsAABB (pyTree) -
import Generator.PyTree as G
import Converter.PyTree as C
import Connector.PyTree as X
import Transform.PyTree as T

a = G.cart((0, 0, 0), (1, 1, 1), (10, 10, 10))
b = G.cart((9., 0, 0), (1, 1, 1), (10, 10, 10))

Ni = 50
Nj = 50
Nk = 2
a = G.cart((0, 0, 0), (1. / (Ni - 1), 1. / (Nj - 1), 1), (Ni, Nj, Nk))
b = G.cart((0, 0, 0), (2. / (Ni - 1), 2. / (Nj - 1), 1), (Ni, Nj, Nk))
b[0] = 'cart2'
a = T.rotate(a, (0, 0, 0), (0, 0, 1), 10.)
a = T.translate(a, (0.5, 0.5, 0))

bb = G.BB([a, b])
ret = X.getIntersectingDomainsAABB(bb)
print(ret)
コード例 #10
0
def replaceText(event=None):
    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()
    # Recupere l'OBB de la selection
    Z = []
    dels = []
    for nz in nzs:
        nob = CTK.Nb[nz] + 1
        noz = CTK.Nz[nz]
        Z.append(CTK.t[2][nob][2][noz])
        dels.append(CTK.t[2][nob][0] + Internal.SEP1 +
                    CTK.t[2][nob][2][noz][0])
    nob0 = CTK.Nb[nzs[0]] + 1
    try:
        a = T.join(Z)
    except:
        a = Z[0]
    OBB = G.BB(a, method='OBB')

    P0 = C.getValue(OBB, 'GridCoordinates', 0)
    P1 = C.getValue(OBB, 'GridCoordinates', 1)
    P2 = C.getValue(OBB, 'GridCoordinates', 2)
    P3 = C.getValue(OBB, 'GridCoordinates', 4)
    v1 = Vector.sub(P1, P0)
    n1 = Vector.norm(v1)
    v2 = Vector.sub(P2, P0)
    n2 = Vector.norm(v2)
    v3 = Vector.sub(P3, P0)
    n3 = Vector.norm(v3)
    v1p = v1
    v2p = v2
    v3p = v3
    if abs(n1) < 1.e-12:
        v1 = Vector.cross(v2, v3)
        v1p = (0., 0., 0.)
    elif abs(n2) < 1.e-12:
        v2 = Vector.cross(v1, v3)
        v2p = (0., 0., 0.)
    elif abs(n3) < 1.e-12:
        v3 = Vector.cross(v2, v3)
        v3p = (0., 0., 0.)

    # Essaie de matcher les vecteur sur la vue p1,p2,p3
    # On suppose que dirCam doit etre e2, ...
    posCam = CPlot.getState('posCam')
    posEye = CPlot.getState('posEye')
    dirCam = CPlot.getState('dirCam')
    e2 = dirCam
    e3 = Vector.sub(posCam, posEye)
    e1 = Vector.cross(e2, e3)

    f1 = None
    f2 = None
    f3 = None
    Pt = P0
    s1 = Vector.dot(e1, v1)
    s2 = Vector.dot(e1, v2)
    s3 = Vector.dot(e1, v3)
    if abs(s1) > abs(s2) and abs(s1) > abs(s3):
        if s1 > 0: f1 = v1
        else:
            f1 = Vector.mul(-1., v1)
            Pt = Vector.add(Pt, v1p)
    elif abs(s2) > abs(s1) and abs(s2) > abs(s3):
        if s2 > 0: f1 = v2
        else:
            f1 = Vector.mul(-1., v2)
            Pt = Vector.add(Pt, v2p)
    elif abs(s3) > abs(s1) and abs(s3) > abs(s2):
        if s3 > 0: f1 = v3
        else:
            f1 = Vector.mul(-1., v3)
            Pt = Vector.add(Pt, v3p)
    s1 = Vector.dot(e2, v1)
    s2 = Vector.dot(e2, v2)
    s3 = Vector.dot(e2, v3)
    if abs(s1) > abs(s2) and abs(s1) > abs(s3):
        if s1 > 0: f2 = v1
        else:
            f2 = Vector.mul(-1., v1)
            Pt = Vector.add(Pt, v1p)
    elif abs(s2) > abs(s1) and abs(s2) > abs(s3):
        if s2 > 0: f2 = v2
        else:
            f2 = Vector.mul(-1., v2)
            Pt = Vector.add(Pt, v2p)
    elif abs(s3) > abs(s1) and abs(s3) > abs(s2):
        if s3 > 0: f2 = v3
        else:
            f2 = Vector.mul(-1., v3)
            Pt = Vector.add(Pt, v3p)
    s1 = Vector.dot(e3, v1)
    s2 = Vector.dot(e3, v2)
    s3 = Vector.dot(e3, v3)
    if abs(s1) > abs(s2) and abs(s1) > abs(s3):
        if s1 > 0: f3 = v1
        else:
            f3 = Vector.mul(-1., v1)
            Pt = Vector.add(Pt, v1p)
    elif abs(s2) > abs(s1) and abs(s2) > abs(s3):
        if s2 > 0: f3 = v2
        else:
            f3 = Vector.mul(-1., v2)
            Pt = Vector.add(Pt, v2p)
    elif abs(s3) > abs(s1) and abs(s3) > abs(s2):
        if s3 > 0: f3 = v3
        else:
            f3 = Vector.mul(-1., v3)
            Pt = Vector.add(Pt, v3p)
    (x0, y0, z0) = Pt
    n2 = Vector.norm(f2)

    # Cree le texte
    text = VARS[0].get()
    type = VARS[1].get()
    font = VARS[3].get()

    smoothness = VARS[2].get()
    smooth = 0
    if smoothness == 'Regular': smooth = 0
    elif smoothness == 'Smooth': smooth = 2
    elif smoothness == 'Very smooth': smooth = 4
    if type == '3D': a = D.text3D(text, smooth=smooth, font=font)
    elif type == '2D': a = D.text2D(text, smooth=smooth, font=font)
    elif type == '1D':
        a = D.text1D(text, smooth=smooth, font=font)
        a = C.convertArray2Tetra(a)
        a = T.join(a)
    BB = G.bbox(a)
    h2 = BB[4] - BB[1]

    # Scale, positionne le texte
    factor = n2 / h2
    a = T.homothety(a, (BB[0], BB[1], BB[2]), factor)
    a = T.translate(a, (x0 - BB[0], y0 - BB[1], z0 - BB[2]))
    a = T.rotate(a, (x0, y0, z0), ((1, 0, 0), (0, 1, 0), (0, 0, 1)),
                 ((f1, f2, f3)))

    CTK.t = CPlot.deleteSelection(CTK.t, CTK.Nb, CTK.Nz, nzs)
    CPlot.delete(dels)
    CTK.add(CTK.t, nob0, -1, a)
    #C._fillMissingVariables(CTK.t)
    CTK.TXT.insert('START', 'Text replaced.\n')
    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
    CTK.TKTREE.updateApp()
    CPlot.render()
コード例 #11
0
# - BB (pyTree) -
import Generator.PyTree as G
import Geom.PyTree as D
import KCore.test as test

s = D.circle((0,0,0), 1., N=100)
a = G.BB(s); a[0] = 'bbox'
test.testT(a, 1)