Skip to content

Commit

Permalink
Fix Script: 2D/3D
Browse files Browse the repository at this point in the history
There is no generic way from the data we write to find this out,
without breaking corner cases such as one-block in one direction.
  • Loading branch information
ax3l committed Apr 5, 2022
1 parent 71bc104 commit b89ec98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Docs/source/usage/workflows/plot_distribution_mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ can be used to read the data:
import plot_distribution_mapping as pdm
sim_knapsack = pdm.SimData('LBC_knapsack.txt', # Data directory
[2800] # Files to process
[2800], # Files to process
is_3D=False # if this is a 2D sim
)
sim_sfc = pdm.SimData('LBC_sfc.txt', [2800])
Expand Down
11 changes: 5 additions & 6 deletions Tools/PostProcessing/plot_distribution_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ class SimData:
"""
Structure for easy access to load costs reduced diagnostics
"""
def __init__(self, directory, prange):
def __init__(self, directory, prange, is_3D):
"""
Set data-containing dir, data range; load data
"""
self.is_3D = is_3D
self._get_costs_reduced_diagnostics(directory, prange)

def __call__(self, i):
Expand Down Expand Up @@ -110,8 +111,6 @@ def _get_costs_reduced_diagnostics(self, directory, prange):
j_is_int = all([el.is_integer() for el in j/j_blocking_factor])
k_is_int = all([el.is_integer() for el in k/k_blocking_factor])

is_3D = i_is_int and j_is_int and k_is_int

for key in self.keys:
row = np.where(key == steps)[0][0]
costs = data[row, 0::n_data_fields].astype(float)
Expand All @@ -121,8 +120,8 @@ def _get_costs_reduced_diagnostics(self, directory, prange):
kcoords = k.astype(int)//k_blocking_factor

# Fill in cost array
shape = (kmax+1, jmax+1, imax+1)[:2+is_3D]
coords = [coord[:2+is_3D] for coord in zip(kcoords, jcoords, icoords)]
shape = (kmax+1, jmax+1, imax+1)[:2+self.is_3D]
coords = [coord[:2+self.is_3D] for coord in zip(kcoords, jcoords, icoords)]

cost_arr = np.full(shape, 0.0)
rank_arr = np.full(shape, -1)
Expand All @@ -139,7 +138,7 @@ def dfs(corner, pos, prev):
edges = list(rank_arr[corner[0]:pos[0]+1, pos[1], pos[2]]) \
+ list(rank_arr[pos[0], corner[1]:pos[1]+1, pos[2]]) \
+ list(rank_arr[pos[0], pos[1], corner[2]:pos[2]+1]) \
if is_3D else \
if self.is_3D else \
list(rank_arr[corner[0]:pos[0]+1, pos[1]]) \
+ list(rank_arr[pos[0], corner[1]:pos[1]+1])
if visited[pos] or not set(edges).issubset(set([prev, -1])): return
Expand Down

0 comments on commit b89ec98

Please sign in to comment.