Skip to content

Commit

Permalink
New checks in combineGrids to enable maintaining full block names (#73)
Browse files Browse the repository at this point in the history
* New checks in combineGrids

* Fix formatting
  • Loading branch information
eytanadler authored Oct 16, 2024
1 parent efe1bd1 commit 86116bc
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions cgnsutilities/cgnsutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 86116bc

Please sign in to comment.