def view(event=None): if CTK.t == []: return BCTypes = [] selection = WIDGETS['BCLB'].curselection() for s in selection: t = WIDGETS['BCLB'].get(s) if t not in Internal.KNOWNBCS: t = 'FamilySpecified:' + t BCTypes.append(t) if 'FamilySpecified:-All BC-' in BCTypes: BCTypes = ['*'] if CTK.__MAINTREE__ == 1: CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones() tp = Internal.appendBaseName2ZoneName(CTK.t, updateRef=False, separator=Internal.SEP1) CTK.dt = C.newPyTree(['Base', 'Edges']) active = [] for z in CTK.__MAINACTIVEZONES__: active.append(tp[2][CTK.Nb[z] + 1][2][CTK.Nz[z]]) Z = [] for t in BCTypes: Z += C.extractBCOfType(active, t, topTree=tp) if t == 'BCWall': # Dans ce cas, affiche tous les types de BCWall Z += C.extractBCOfType(active, 'BCWallInviscid') Z += C.extractBCOfType(active, 'BCWallViscous') Z += C.extractBCOfType(active, 'BCWallViscousIsoThermal') CTK.dt[2][1][2] += Z if VARS[7].get() == '1': # display les edges des zones en + exts = [] for z in active: ztype = Internal.getZoneType(z) if ztype == 1: zp = P.exteriorFacesStructured(z) exts += zp else: #zp = P.exteriorFaces(z) #zp = P.sharpEdges(zp) zp = [] exts += zp CTK.dt[2][2][2] += exts C._fillMissingVariables(CTK.dt) # bug exteriorFaces # Activate lenZ = len(CTK.dt[2][1][2]) lenExts = len(CTK.dt[2][2][2]) active = [(i, 1) for i in range(lenZ + lenExts)] for i in range(lenZ): active[i] = (i, 1) for i in range(lenExts): active[i + lenZ] = (i + lenZ, 0) CTK.display(CTK.dt, mainTree=CTK.DEFINEDBC) CPlot.setActiveZones(active) CPlot.setState(edgifyDeactivatedZones=1) else: lenZ = len(CTK.dt[2][1][2]) active = [(i, 1) for i in range(lenZ)] C._fillMissingVariables(CTK.dt) # si BCDataSet != fields CTK.display(CTK.dt, mainTree=CTK.DEFINEDBC) CPlot.setActiveZones(active) CPlot.setState(edgifyDeactivatedZones=0)
def check(): if CTK.t == []: return node = Internal.getNodeFromName(CTK.t, 'EquationDimension') if node is not None: ndim = Internal.getValue(node) else: CTK.TXT.insert('START', 'EquationDimension not found (tkState). Using 3D.\n') CTK.TXT.insert('START', 'Warning: ', 'Warning') ndim = 3 # Varie de 0 a 180 degres global __SPLITFACTOR__ splitFactor = 180. - WIDGETS['splitFactor'].get() * 180. / 100. __SPLITFACTOR__ = splitFactor wins = C.getEmptyBC(CTK.t, ndim, splitFactor) if CTK.__MAINTREE__ == 1: CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones() CTK.dt = C.newPyTree(['Base', 'Edges']) tp = Internal.appendBaseName2ZoneName(CTK.t, updateRef=False, separator=Internal.SEP1, trailing=Internal.SEP1) bases = Internal.getBases(tp) nb = 0 for b in bases: nodes = Internal.getNodesFromType1(b, 'Zone_t') nz = 0 for z in nodes: ztype = Internal.getZoneType(z) winz = wins[nb][nz] if ztype == 1: # structure for w in winz: imin = w[0] imax = w[1] jmin = w[2] jmax = w[3] kmin = w[4] kmax = w[5] zp = T.subzone(z, (imin, jmin, kmin), (imax, jmax, kmax)) CTK.dt[2][1][2].append(zp) else: # non structure for w in winz: zp = T.subzone(z, w, type='faces') CTK.dt[2][1][2].append(zp) nz += 1 nb += 1 if VARS[7].get() == '1': # display les edges des zones en + exts = [] zones = Internal.getZones(tp) for z in zones: ztype = Internal.getZoneType(z) if ztype == 1: zp = P.exteriorFacesStructured(z) exts += zp else: #zp = P.exteriorFaces(z); zp = P.sharpEdges(zp) zp = [] exts += zp CTK.dt[2][2][2] += exts #C._fillMissingVariables(CTK.dt) # bug exteriorFacesStruct # Activate lenZ = len(CTK.dt[2][1][2]) lenExts = len(exts) active = [(i, 1) for i in range(lenZ + lenExts)] for i in range(lenZ): active[i] = (i, 1) for i in range(lenExts): active[i + lenZ] = (i + lenZ, 0) CTK.display(CTK.dt, mainTree=CTK.UNDEFINEDBC) CPlot.setActiveZones(active) CPlot.setState(edgifyDeactivatedZones=1) else: lenZ = len(CTK.dt[2][1][2]) active = [(i, 1) for i in range(lenZ)] CTK.display(CTK.dt, mainTree=CTK.UNDEFINEDBC) CPlot.setActiveZones(active) # modifie la couleur du bouton l = len(Internal.getZones(CTK.dt)) if l == 0: TTK.setButtonGreen(WIDGETS['undefinedBC']) else: TTK.setButtonRed(WIDGETS['undefinedBC']) WIDGETS['undefinedBC'].update()
def setFilter(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 import re # Get filter type filterType = VARS[1].get() actionType = VARS[2].get() # Filter by name if filterType == 'By name': rexp = VARS[0].get() exp = re.compile(rexp) bases = CTK.t[2][1:] active = [] for b in bases: baseName = b[0] for z in b[2]: if z[3] == 'Zone_t': zoneName = baseName + '/' + z[0] i = CPlot.getCPlotNumber(CTK.t, b[0], z[0]) if exp.search(zoneName) is not None: active.append((i, 1)) else: active.append((i, 0)) if actionType == 'Activate': CPlot.setActiveZones(active) elif actionType == 'Deactivate': inactive = [] for i in active: if i[1] == 1: inactive.append((i[0], 0)) CPlot.setActiveZones(inactive) else: CPlot.setSelectedZones(active) CTK.TXT.insert('START', 'Filtered by name.\n') # Filter by number if filterType == 'By number': no = VARS[0].get() try: no = int(no) except: CTK.TXT.insert('START', 'Filter value must be int.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return bases = CTK.t[2][1:] active = [] c = 0 for b in bases: baseName = b[0] for z in b[2]: if z[3] == 'Zone_t': i = CPlot.getCPlotNumber(CTK.t, b[0], z[0]) if no == c: active.append((i, 1)) else: active.append((i, 0)) c += 1 if actionType == 'Activate': CPlot.setActiveZones(active) elif actionType == 'Deactivate': inactive = [] for i in active: if i[1] == 1: inactive.append((i[0], 0)) CPlot.setActiveZones(inactive) else: CPlot.setSelectedZones(active) CTK.TXT.insert('START', 'Filtered by number.\n') # Filter by size elif (filterType == 'By size >'): size = VARS[0].get() try: size = int(size) except: CTK.TXT.insert('START', 'Filter value must be int.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return bases = CTK.t[2][1:] active = [] for b in bases: for z in b[2]: if (z[3] == 'Zone_t'): dim = Internal.getZoneDim(z) if (dim[0] == 'Structured'): np = dim[1] * dim[2] * dim[3] else: np = dim[1] i = CPlot.getCPlotNumber(CTK.t, b[0], z[0]) if np > size: active.append((i, 1)) else: active.append((i, 0)) if (actionType == 'Activate'): CPlot.setActiveZones(active) elif (actionType == 'Deactivate'): inactive = [] for i in active: if (i[1] == 1): inactive.append((i[0], 0)) CPlot.setActiveZones(inactive) else: CPlot.setSelectedZones(active) CTK.TXT.insert('START', 'Filtered by size.\n') elif (filterType == 'By size <'): size = VARS[0].get() try: size = int(size) except: CTK.TXT.insert('START', 'Filter value must be int.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return bases = CTK.t[2][1:] active = [] for b in bases: for z in b[2]: if (z[3] == 'Zone_t'): dim = Internal.getZoneDim(z) if (dim[0] == 'Structured'): np = dim[1] * dim[2] * dim[3] else: np = dim[1] i = CPlot.getCPlotNumber(CTK.t, b[0], z[0]) if (np < size): active.append((i, 1)) else: active.append((i, 0)) if (actionType == 'Activate'): CPlot.setActiveZones(active) elif (actionType == 'Deactivate'): inactive = [] for i in active: if (i[1] == 1): inactive.append((i[0], 0)) CPlot.setActiveZones(inactive) else: CPlot.setSelectedZones(active) CTK.TXT.insert('START', 'Filtered by size.\n') elif (filterType == 'By MG lvl ='): lvl = VARS[0].get() try: lvl = int(lvl) except: CTK.TXT.insert('START', 'Filter value must be int.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return fac = 2**lvl bases = CTK.t[2][1:] active = [] for b in bases: for z in b[2]: if (z[3] == 'Zone_t'): dim = Internal.getZoneDim(z) i = CPlot.getCPlotNumber(CTK.t, b[0], z[0]) if (dim[0] == 'Structured'): celldim = dim[4] ni = dim[1] nj = dim[2] nk = dim[3] if (celldim == 2): if ((ni - 1) % fac == 0 and (nj - 1) % fac == 0): active.append((i, 1)) else: active.append((i, 0)) elif (celldim == 3): if ((ni - 1) % fac == 0 and (nj - 1) % fac == 0 and (nk - 1) % fac == 0): active.append((i, 1)) else: active.append((i, 0)) else: active.append((i, 0)) else: active.append((i, 0)) if (actionType == 'Activate'): CPlot.setActiveZones(active) elif (actionType == 'Deactivate'): inactive = [] for i in active: if (i[1] == 1): inactive.append((i[0], 0)) CPlot.setActiveZones(inactive) else: CPlot.setSelectedZones(active) CTK.TXT.insert('START', 'Filtered by multigrid level.\n') elif (filterType == 'By MG lvl !='): lvl = VARS[0].get() try: lvl = int(lvl) except: CTK.TXT.insert('START', 'Filter value must be int.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return fac = 2**lvl bases = CTK.t[2][1:] active = [] for b in bases: for z in b[2]: if (z[3] == 'Zone_t'): dim = Internal.getZoneDim(z) if (dim[0] == 'Structured'): celldim = dim[4] ni = dim[1] nj = dim[2] nk = dim[3] i = CPlot.getCPlotNumber(CTK.t, b[0], z[0]) if (celldim == 2): if ((ni - 1) % fac == 0 and (nj - 1) % fac == 0): active.append((i, 0)) else: active.append((i, 1)) elif (celldim == 3): if ((ni - 1) % fac == 0 and (nj - 1) % fac == 0 and (nk - 1) % fac == 0): active.append((i, 0)) else: active.append((i, 1)) else: active.append((i, 0)) else: active.append((i, 0)) if (actionType == 'Activate'): CPlot.setActiveZones(active) elif (actionType == 'Deactivate'): inactive = [] for i in active: if (i[1] == 1): inactive.append((i[0], 0)) CPlot.setActiveZones(inactive) else: CPlot.setSelectedZones(active) CTK.TXT.insert('START', 'Filtered by multigrid level.\n') elif (filterType == 'By proc'): myProc = VARS[0].get() try: myProc = int(myProc) except: CTK.TXT.insert('START', 'Filter value must be int.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return bases = CTK.t[2][1:] active = [] for b in bases: for z in b[2]: if (z[3] == 'Zone_t'): i = CPlot.getCPlotNumber(CTK.t, b[0], z[0]) proc = Internal.getNodesFromName(z, 'proc') if (proc != [] and proc[0][1][0, 0] == myProc): active.append((i, 1)) else: active.append((i, 0)) if (actionType == 'Activate'): CPlot.setActiveZones(active) elif (actionType == 'Deactivate'): inactive = [] for i in active: if (i[1] == 1): inactive.append((i[0], 0)) CPlot.setActiveZones(inactive) else: CPlot.setSelectedZones(active) CTK.TXT.insert('START', 'Filtered by proc.\n') elif (filterType == 'By priority'): prio = VARS[0].get() try: prio = int(prio) except: CTK.TXT.insert('START', 'Filter value must be int.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return bases = CTK.t[2][1:] active = [] for b in bases: prios = Internal.getNodesFromName2(b, 'Priority') if (prios != [] and prios[0][1][0, 0] == prio): for z in b[2]: if (z[3] == 'Zone_t'): i = CPlot.getCPlotNumber(CTK.t, b[0], z[0]) active.append((i, 1)) elif (prios == [] and prio == 0): for z in b[2]: if (z[3] == 'Zone_t'): i = CPlot.getCPlotNumber(CTK.t, b[0], z[0]) active.append((i, 1)) else: for z in b[2]: if (z[3] == 'Zone_t'): i = CPlot.getCPlotNumber(CTK.t, b[0], z[0]) active.append((i, 0)) if (actionType == 'Activate'): CPlot.setActiveZones(active) elif (actionType == 'Deactivate'): inactive = [] for i in active: if (i[1] == 1): inactive.append((i[0], 0)) CPlot.setActiveZones(inactive) else: CPlot.setSelectedZones(active) CTK.TXT.insert('START', 'Filtered by priority.\n') elif (filterType == 'By formula (and)' or filterType == 'By formula (or)'): if (filterType == 'By formula (and)'): testType = 0 else: testType = 1 formula = VARS[0].get() b1 = formula.find('{') b2 = formula.find('}') if (b1 == -1 or b2 == -1): CTK.TXT.insert('START', 'Filter value must be int.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return field = formula[b1 + 1:b2] # print field try: # try an eval ff = formula.replace('{' + field + '}', '12.') res = eval(ff) except: CTK.TXT.insert('START', 'Filter supports only simple formulas.\n') CTK.TXT.insert('START', 'Error: ', 'Error') return b1 = formula.find('==') formula1 = formula formula2 = formula if (b1 != -1): formula1 = formula.replace('==', '<=') formula2 = formula.replace('==', '>=') else: b1 = formula.find('=') if (b1 != -1): formula1 = formula.replace('=', '<=') formula2 = formula.replace('=', '>=') bases = CTK.t[2][1:] active = [] for b in bases: for z in b[2]: if (z[3] == 'Zone_t'): fmin = C.getMinValue(z, field) fmax = C.getMaxValue(z, field) ff = formula1.replace('{' + field + '}', str(fmin)) res1 = eval(ff) ff = formula2.replace('{' + field + '}', str(fmax)) res2 = eval(ff) i = CPlot.getCPlotNumber(CTK.t, b[0], z[0]) if (testType == 0): if (res1 == True and res2 == True): active.append((i, 1)) else: active.append((i, 0)) else: if (res1 == True or res2 == True): active.append((i, 1)) else: active.append((i, 0)) if actionType == 'Activate': CPlot.setActiveZones(active) elif actionType == 'Deactivate': inactive = [] for i in active: if (i[1] == 1): inactive.append((i[0], 0)) CPlot.setActiveZones(inactive) else: CPlot.setSelectedZones(active) CTK.TXT.insert('START', 'Filtered by formula.\n')