From 86116bcc163f26437689826c7ca5785620ede66e Mon Sep 17 00:00:00 2001 From: Eytan Adler <63426601+eytanadler@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:57:15 -0400 Subject: [PATCH] New checks in combineGrids to enable maintaining full block names (#73) * New checks in combineGrids * Fix formatting --- cgnsutilities/cgnsutilities.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/cgnsutilities/cgnsutilities.py b/cgnsutilities/cgnsutilities.py index 8134ef3..d64fb32 100644 --- a/cgnsutilities/cgnsutilities.py +++ b/cgnsutilities/cgnsutilities.py @@ -3395,7 +3395,7 @@ def faceID(ptRange, blk): return grid -def combineGrids(grids, useOldNames=False): +def combineGrids(grids, useOldNames=False, useOldNumbers=False): """Method that takes in a list of grids and returns a new grid object containing all zones from each grid. The blocks are renamed as there could (almost most certainly) be conflicts between the zone @@ -3404,7 +3404,16 @@ def combineGrids(grids, useOldNames=False): If useOldNames=True we will preserve the domain names after merging the blocks, otherwise, we will replace all names by the filenames. + However, it will still update the block name's numbers. To preserve + the original numbers, set useOldNumbers=True. """ + # Check that no grids have the same name. If they do, they will + # overwrite each other when added to the grid dict. + gridNames = set() + for grid in grids: + if grid.name in gridNames: + raise RuntimeError(f"Two grids have the name {grid.name}, but grid names must be unique") + gridNames.add(grid.name) # Create a dictionary to contain grid objects with their names # as the corresponding keys @@ -3434,13 +3443,18 @@ def combineGrids(grids, useOldNames=False): # Loop over the blocks and obtain the name mapping for blk in grid.blocks: nBlock += 1 - if not useOldNames: - blockName = name + if useOldNames and useOldNumbers: + blockName = blk.name + if blockName in zoneMap.keys(): + raise RuntimeError( + f"Duplicate block name {blockName}, try without useOldNumbers or rename the block" + ) + elif useOldNames: + blockName = blk.name.split(".")[0] + f".{nBlock:05}" else: - blockName = blk.name.split(".")[0] - newName = blockName + f".{nBlock:05}" - zoneMap[blk.name] = newName - blk.name = newName + blockName = name + f".{nBlock:05}" + zoneMap[blk.name] = blockName + blk.name = blockName # Now loop back over the blocks, replacing the donorName using # the map we defined above