Skip to content

Commit

Permalink
add sanity checks (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrp089 committed Aug 1, 2022
1 parent 45112eb commit 4fd9cc5
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions Python/site-packages/sv_rom_extract_results/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,20 @@ def project_results_to_centerline(self):
# centerline points
points = v2n(self.geos['cent'].GetPoints().GetData())

# all branch ids in centerline
ids_cent = np.unique(arrays_cent['BranchId']).tolist()
ids_cent.remove(-1)

# loop all result fields
for f in self.params.data_names:
if f not in self.results:
continue

# check if ROM branch has same ids as centerline
ids_rom = list(self.results[f].keys())
ids_rom.sort()
assert ids_cent == ids_rom, 'Centerline and ROM results have different branch ids'

# initialize output arrays
array_f = np.zeros((arrays_cent['Path'].shape[0], len(self.params.times)))
n_outlet = np.zeros(arrays_cent['Path'].shape[0])
Expand All @@ -222,9 +231,17 @@ def project_results_to_centerline(self):

# map results to branches
path_1d_res, f_res = res_rom_to_path(path_centerline, res_br)
else:
raise ValueError('Unknown ROM model order ' + str(self.params.model_order))

# map 1d results to centerline using paths
f_cent = interp1d(path_1d_res, f_res.T, fill_value='extrapolate')(path_cent).T
assert np.isclose(path_1d_res[0], 0.0), 'ROM branch path does not start at 0'
assert np.isclose(path_cent[0], 0.0), 'Centerline branch path does not start at 0'
msg = 'ROM results and centerline have different branch path lengths'
assert np.isclose(path_1d_res[-1], path_cent[-1]), msg

# interpolate ROM onto centerline
# limit to interval [0,1] to avoid extrapolation error interp1d due to slightly incompatible lenghts
f_cent = interp1d(path_1d_res / path_1d_res[-1], f_res.T)(path_cent / path_cent[-1]).T

# store results of this path
array_f[arrays_cent['BranchId'] == br] = f_cent[:, self.params.time_indices]
Expand Down Expand Up @@ -260,9 +277,11 @@ def project_results_to_centerline(self):
elif self.params.model_order == 1:
f0 = res_br_u[sorted(res_br_u.keys())[-1]][-1][self.params.time_indices]
f1 = res_br[0][0][self.params.time_indices]
else:
raise ValueError('Unknown ROM model order ' + str(self.params.model_order))

# map 1d results to centerline using paths
array_f[jc_cent] += interp1d([0, 1], np.vstack((f0, f1)).T, fill_value='extrapolate')(jc_path).T
array_f[jc_cent] += interp1d([0, 1], np.vstack((f0, f1)).T)(jc_path).T

# count number of outlets of this junction
n_outlet[jc_cent] += 1
Expand Down

0 comments on commit 4fd9cc5

Please sign in to comment.