def fixWallXNegGeneral(idx, globaldata, nbhs, control, conditionNumber, aggressive, wallpoints, configData, hashtable): if control > 0: return globaldata else: control = control + 1 mynbhs = core.convertIndexToPoints(core.getNeighbours(idx, globaldata), globaldata) mychecknbhs = core.getXNegPointsWithInput(idx, globaldata, mynbhs, configData) finalnbhs = list(set(nbhs) - set(mynbhs)) finalnbhs = core.getXNegPointsWithInput(idx, globaldata, finalnbhs, configData) # print(finalnbhs) conditionSet = [] for itm in finalnbhs: checkset = [itm] + mychecknbhs newcheck = core.getConditionNumberWithInput( idx, globaldata, checkset, configData) if newcheck < conditionNumber: if not core.isNonAeroDynamicEvenBetter(idx, itm, globaldata, wallpoints): conditionSet.append([itm, newcheck]) if len(conditionSet) > 0: conditionSet.sort(key=lambda x: x[1]) globaldata = core.appendNeighbours(idx, globaldata, conditionSet[0][0], hashtable) fixWallXNegGeneral(idx, globaldata, nbhs, control, conditionNumber, aggressive, wallpoints, configData, hashtable) else: if aggressive == True: leftright = core.getLeftandRightPoint(idx, globaldata) currnbhs = core.convertIndexToPoints( core.getNeighbours(idx, globaldata), globaldata) nbhofnbh = [] leftright = leftright + currnbhs for itm in leftright: itm_real = core.getIndexFromPoint(itm, globaldata, hashtable) layernbhs = core.convertIndexToPoints( core.getNeighbours(itm_real, globaldata), globaldata) nbhofnbh = nbhofnbh + layernbhs nbhofnbh = list( set(nbhofnbh) - set([core.getPointXY(idx, globaldata)])) fixWallXNegGeneral(idx, globaldata, nbhofnbh, control, conditionNumber, False, wallpoints, configData, hashtable) else: return globaldata return globaldata
def triangleBalance3(globaldata, wallpoints, configData, badPoints, hashtable=None): WALL_THRESHOLD = int( configData["triangulate"]["leftright"]["wallThreshold"]) AGGRESSIVE_MAX_NEIGHBOURS = -int( configData["triangulate"]["leftright"]["aggressiveMaxNeighbours"]) previousType = 0 for _, idx in enumerate(tqdm(badPoints)): if idx > 0: flag = int(core.getFlag(idx, globaldata)) xposf, xnegf, _, _ = core.getFlags(idx, globaldata) ## Wall Points if flag == 0: previousType = 0 if xposf == 1 or xposf == 2: nbhs = core.convertIndexToPoints( core.getNeighbours(idx, globaldata), globaldata) # if idx not in core.getWallEndPoints(globaldata): if True: nbhs = nbhs + core.getLeftandRightPoint( idx, globaldata) nbhs = list(set(nbhs)) globaldata = fixWallXPosGeneral(idx, globaldata, nbhs, AGGRESSIVE_MAX_NEIGHBOURS, WALL_THRESHOLD, True, wallpoints, configData, hashtable) if xnegf == 1 or xnegf == 2: nbhs = core.convertIndexToPoints( core.getNeighbours(idx, globaldata), globaldata) # if idx not in core.getWallEndPoints(globaldata): if True: nbhs = nbhs + core.getLeftandRightPoint( idx, globaldata) nbhs = list(set(nbhs)) globaldata = fixWallXNegGeneral(idx, globaldata, nbhs, AGGRESSIVE_MAX_NEIGHBOURS, WALL_THRESHOLD, True, wallpoints, configData, hashtable) elif previousType == 0: break return globaldata
def fixYneg(idx, globaldata, nbhs, control, conditionNumber, aggressive, polygonData, wallpoints, configData): if control > 0: return globaldata else: control = control + 1 mynbhs = core.convertIndexToPoints(core.getNeighbours(idx, globaldata), globaldata) mychecknbhs = core.getYNegPointsWithInputLegacy( idx, globaldata, mynbhs, configData) finalnbhs = list(set(nbhs) - set(mynbhs)) finalnbhs = core.getYNegPointsWithInputLegacy(idx, globaldata, finalnbhs, configData) finalnbhs = core.getAeroPointsFromSet(idx, finalnbhs, globaldata, wallpoints) # print(finalnbhs) conditionSet = [] for itm in finalnbhs: checkset = [itm] + mychecknbhs newcheck = core.getConditionNumberDictionary( idx, globaldata, checkset, configData) if newcheck < conditionNumber: if not core.isNonAeroDynamicEvenBetter(idx, itm, globaldata, wallpoints): conditionSet.append([itm, newcheck]) if len(conditionSet) > 0: conditionSet.sort(key=lambda x: x[1]) globaldata = core.appendNeighbours(idx, globaldata, conditionSet[0][0]) fixYneg(idx, globaldata, nbhs, control, conditionNumber, aggressive, polygonData, wallpoints, configData) else: if aggressive == True: directnbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) nbhofnbh = [] for itm in directnbhs: itm_real = core.getIndexFromPoint(itm, globaldata) layernbhs = getNeighboursFromTriangle( itm_real, globaldata, polygonData) nbhofnbh = nbhofnbh + layernbhs nbhofnbh = list(set(nbhofnbh)) fixYneg(idx, globaldata, nbhofnbh, control, conditionNumber, False, polygonData, wallpoints, configData) else: return globaldata return globaldata
def main(): # Command Line Arguments parser = argparse.ArgumentParser() parser.add_argument("-i", "--input", const=str, nargs="?") parser.add_argument("-a", "--algorithm", nargs="+") args = parser.parse_args() log.info("Loading Data") log.debug("Arguments") log.debug(args) configData = core.getConfig() globaldata = core.getKeyVal("globaldata") hashtable = {} if globaldata == None: file1 = open(args.input or "preprocessorfile.txt", "r") data = file1.read() globaldata = ["start"] splitdata = data.split("\n") splitdata = splitdata[:-1] log.info("Processed Pre-Processor File") log.info("Converting to readable format") for _, itm in enumerate(tqdm(splitdata)): itm = itm.split(" ") itm.pop(-1) entry = itm hashtable["{},{}".format(entry[1], entry[2])] = int(entry[0]) globaldata.append(entry) else: globaldata.insert(0,"start") hashtable = core.generateHashtable(globaldata) # globaldata = core.cleanNeighbours(globaldata) wallpts = core.getWallPointArray(globaldata) algo1,algo2,algo3 = True,True,True if len(args.algorithm) == 3: algo = list(map(core.ConvertStringToBool,args.algorithm)) algo1 = algo[0] algo2 = algo[1] algo3 = algo[2] log.info("Generating Wall Polygons for Aerochecks") wallpts = core.generateWallPolygons(wallpts) log.info("Detected " + str(len(wallpts)) + " geometry(s).") log.info("Wall Polygon Generation Complete") log.info("Deleting Unneeded Wall Points (Except Left and Right Points)") globaldata = core.cleanWallPoints(globaldata) badPoints = [] with np.errstate(divide='ignore', invalid='ignore'): if algo1 == True: log.info("Triangulating") interiorpts = [] interiorpts.extend(range(1, len(globaldata))) interiorpts = core.convertPointToShapelyPoint(core.convertIndexToPoints(interiorpts,globaldata)) interiorpts = MultiPoint(interiorpts) interiortriangles = triangulate(interiorpts) log.info("Generated " + str(len(interiortriangles)) + " triangle(s).") polydata = balance.getPolygon(interiortriangles) log.info("Running Connectivity Check") globaldata,badPoints = core.connectivityCheck(globaldata, badPoints, configData, quick=True) log.info("Connectivity Check Done") log.info("Running Triangulation Balancing using Nischay's Triangle Neighbours") globaldata = balance.triangleBalance(globaldata, polydata, wallpts, configData, badPoints) log.info("Triangle Balancing Done") if algo2 == True: log.info("Running Connectivity Check") globaldata,badPoints = core.connectivityCheck(globaldata, badPoints, configData, quick=True) log.info("Connectivity Recheck Done") log.info("Running Triangulation Balancing using Kumar's Neighbours (Left and Right Mode)") globaldata = balance.triangleBalance2(globaldata, wallpts, configData, badPoints, hashtable) if algo3 == True: log.info("Running Connectivity Check") globaldata,badPoints = core.connectivityCheck(globaldata, badPoints, configData, quick=True) log.info("Running Triangulation Balancing using Kumar's Neighbours (General)") globaldata = balance.triangleBalance3(globaldata, wallpts, configData, badPoints, hashtable) log.info("Running Connectivity Recheck") globaldata,badPoints = core.connectivityCheck(globaldata, badPoints, configData, quick=True) log.warning("Total Number of Points unable to be fixed: {}".format(len(badPoints))) # log.info("Writing Deletion Points") # problempts = findDeletionPoints(globaldata) # globaldata = core.cleanNeighbours(globaldata) # core.writeConditionValuesForWall(globaldata, configData) globaldata.pop(0) core.setKeyVal("globaldata",globaldata) # with open("removal_points.txt", "w") as text_file: # for item1 in problempts: # text_file.writelines(["%s " % item1]) # text_file.writelines("\n") log.info("Writing Preprocessor File") with open("preprocessorfile_triangulate.txt", "w") as text_file: for item1 in globaldata: text_file.writelines(["%s " % item for item in item1]) text_file.writelines("\n") log.info("Done")
def generateReportConnectivity(globaldata): resultInterior = { "total": 0, "leastxpos": 0, "maxxpos": 0, "leastxneg": 0, "maxxneg": 0, "leastypos": 0, "maxypos": 0, "leastyneg": 0, "maxyneg": 0, "xposavg": 0, "xnegavg": 0, "yposavg": 0, "ynegavg": 0, "_init": False } resultOuter = { "total": 0, "leastxpos": 0, "maxxpos": 0, "leastxneg": 0, "maxxneg": 0, "xposavg": 0, "xnegavg": 0, "_init": False } resultWall = { "total": 0, "leastxpos": 0, "maxxpos": 0, "leastxneg": 0, "maxxneg": 0, "xposavg": 0, "xnegavg": 0, "_init": False } inxpos, inxneg, inypos, inyneg, ouxpos, ouxneg, waxpos, waxneg, interior, outer, wall = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 for idx, _ in enumerate(globaldata): if (idx > 1): flag = core.getFlag(idx, globaldata) ## Interior Point if (flag == 1): nbhs = core.convertIndexToPoints( core.getNeighbours(idx, globaldata), globaldata) curcord = core.getPointXY(idx, globaldata) xpos, xneg, ypos, yneg, _ = core.deltaNeighbourCalculationLegacy( nbhs, curcord, False, False) interior = interior + 1 inxpos = inxpos + xpos inxneg = inxneg + xneg inypos = inypos + ypos inyneg = inyneg + yneg if (resultInterior["_init"] == True): if (xpos < resultInterior["leastxpos"]): resultInterior["leastxpos"] = xpos if (resultInterior["maxxpos"] < xpos): resultInterior["maxxpos"] = xpos if (xneg < resultInterior["leastxneg"]): resultInterior["leastxneg"] = xneg if (resultInterior["maxxneg"] < xneg): resultInterior["maxxneg"] = xneg if (ypos < resultInterior["leastypos"]): resultInterior["leastypos"] = ypos if (resultInterior["maxypos"] < ypos): resultInterior["maxypos"] = ypos if (yneg < resultInterior["leastyneg"]): resultInterior["leastyneg"] = yneg if (resultInterior["maxyneg"] < yneg): resultInterior["maxyneg"] = yneg else: resultInterior["_init"] = True resultInterior["leastxpos"] = xpos resultInterior["leastxneg"] = xneg resultInterior["leastypos"] = ypos resultInterior["leastyneg"] = yneg #Wall Points if (flag == 0): nbhs = core.convertIndexToPoints( core.getNeighbours(idx, globaldata), globaldata) curcord = core.getPointXY(idx, globaldata) xpos, xneg, _, _, _ = core.deltaNeighbourCalculationLegacy( nbhs, curcord, False, False) wall = wall + 1 waxpos = waxpos + xpos waxneg = waxneg + xneg if (resultWall["_init"] == True): if (xpos < resultWall["leastxpos"]): resultWall["leastxpos"] = xpos if (resultWall["maxxpos"] < xpos): resultWall["maxxpos"] = xpos if (xneg < resultWall["leastxneg"]): resultWall["leastxneg"] = xneg if (resultWall["maxxneg"] < xneg): resultWall["maxxneg"] = xneg else: resultWall["_init"] = True resultWall["leastxpos"] = xpos resultWall["leastxneg"] = xneg #Outer Points if (flag == 2): nbhs = core.convertIndexToPoints( core.getNeighbours(idx, globaldata), globaldata) curcord = core.getPointXY(idx, globaldata) xpos, xneg, _, _, _ = core.deltaNeighbourCalculationLegacy( nbhs, curcord, False, False) outer = outer + 1 ouxpos = ouxpos + xpos ouxneg = ouxneg + xneg if (resultOuter["_init"] == True): if (xpos < resultOuter["leastxpos"]): resultOuter["leastxpos"] = xpos if (resultOuter["maxxpos"] < xpos): resultOuter["maxxpos"] = xpos if (xneg < resultOuter["leastxneg"]): resultOuter["leastxneg"] = xneg if (resultOuter["maxxneg"] < xneg): resultOuter["maxxneg"] = xneg else: resultOuter["_init"] = True resultOuter["leastxpos"] = xpos resultOuter["leastxneg"] = xneg resultInterior["xposavg"] = float(round(inxpos / interior, 2)) resultInterior["xnegavg"] = float(round(inxneg / interior, 2)) resultInterior["yposavg"] = float(round(inypos / interior, 2)) resultInterior["ynegavg"] = float(round(inyneg / interior, 2)) resultInterior["total"] = interior resultOuter["xposavg"] = float(round(ouxpos / outer, 2)) resultOuter["xnegavg"] = float(round(ouxneg / outer, 2)) resultOuter["total"] = outer resultWall["xposavg"] = float(round(waxpos / wall, 2)) resultWall["xnegavg"] = float(round(waxneg / wall, 2)) resultWall["total"] = wall return resultWall, resultInterior, resultOuter