-
Notifications
You must be signed in to change notification settings - Fork 0
Resolved TODO in compare_cavity_external.py #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,3 +39,5 @@ validation/references/ | |
| # Example/optimiser output directories (all crates) | ||
| outputs/ | ||
| report/ | ||
| .venv/ | ||
| venv/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| import numpy as np | ||
| import matplotlib.pyplot as plt | ||
| from pathlib import Path | ||
| from scipy.interpolate import RectBivariateSpline | ||
|
|
||
| # Add validation directory to path | ||
| sys.path.insert(0, str(Path(__file__).parent)) | ||
|
|
@@ -104,8 +105,28 @@ def compare_solutions(cfd_python_result, external_result, Re: float): | |
| # Ensure same grid size | ||
| if cfd_python_result["u"].shape != ext_sol["u"].shape: | ||
| print(f"WARN: Grid size mismatch: cfd_python {cfd_python_result['u'].shape} vs external {ext_sol['u'].shape}") | ||
| # TODO: Interpolate if needed | ||
| return None | ||
|
|
||
| # Interpolate external result onto cfd_python grid | ||
| x_ext = ext_solver.x | ||
| y_ext = ext_solver.y | ||
| x_cfd = cfd_python_result["x"] | ||
| y_cfd = cfd_python_result["y"] | ||
|
|
||
| u_spline = RectBivariateSpline(y_ext, x_ext, ext_sol["u"]) | ||
| v_spline = RectBivariateSpline(y_ext, x_ext, ext_sol["v"]) | ||
| p_spline = RectBivariateSpline(y_ext, x_ext, ext_sol["p"]) | ||
|
|
||
| ext_sol["u"] = u_spline(y_cfd, x_cfd) | ||
| ext_sol["v"] = v_spline(y_cfd, x_cfd) | ||
| ext_sol["p"] = p_spline(y_cfd, x_cfd) | ||
|
|
||
| # Update centerlines | ||
| mid_x_idx = len(x_cfd) // 2 | ||
| mid_y_idx = len(y_cfd) // 2 | ||
| ext_sol["u_centerline"] = ext_sol["u"][:, mid_x_idx] | ||
| ext_sol["v_centerline"] = ext_sol["v"][mid_y_idx, :] | ||
|
|
||
| print("INFO: Interpolated external result onto cfd_python grid using RectBivariateSpline") | ||
|
Comment on lines
+108
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shape mismatch bug: After interpolation,
This will raise a runtime error when the grid sizes differ. 🐛 Proposed fix: pass interpolated coordinates or skip external field plots when interpolatedOne approach is to track whether interpolation occurred and use the appropriate coordinates: if cfd_python_result["u"].shape != ext_sol["u"].shape:
print(f"WARN: Grid size mismatch: cfd_python {cfd_python_result['u'].shape} vs external {ext_sol['u'].shape}")
# Interpolate external result onto cfd_python grid
x_ext = ext_solver.x
y_ext = ext_solver.y
x_cfd = cfd_python_result["x"]
y_cfd = cfd_python_result["y"]
u_spline = RectBivariateSpline(y_ext, x_ext, ext_sol["u"])
v_spline = RectBivariateSpline(y_ext, x_ext, ext_sol["v"])
p_spline = RectBivariateSpline(y_ext, x_ext, ext_sol["p"])
ext_sol["u"] = u_spline(y_cfd, x_cfd)
ext_sol["v"] = v_spline(y_cfd, x_cfd)
ext_sol["p"] = p_spline(y_cfd, x_cfd)
# Update centerlines
mid_x_idx = len(x_cfd) // 2
mid_y_idx = len(y_cfd) // 2
ext_sol["u_centerline"] = ext_sol["u"][:, mid_x_idx]
ext_sol["v_centerline"] = ext_sol["v"][mid_y_idx, :]
+
+ # Store interpolated grid coordinates for plotting
+ ext_sol["_interpolated"] = True
+ ext_sol["_x"] = x_cfd
+ ext_sol["_y"] = y_cfd
+ else:
+ ext_sol["_interpolated"] = False
print("INFO: Interpolated external result onto cfd_python grid using RectBivariateSpline")Then update 🤖 Prompt for AI Agents |
||
|
|
||
| # Compute L2 errors | ||
| u_diff = cfd_python_result["u"] - ext_sol["u"] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the interpolation logic correctly resamples the external solution fields (
u,v,p) onto the CFD grid, the plotting functionplot_comparisonwill fail with a dimension mismatch error. This is becauseplot_comparisonuses the grid coordinates from theext_solverobject (ext_solver.X,ext_solver.Y,ext_solver.x,ext_solver.y), which are not updated after interpolation.To fix this, you should also update these grid attributes on the
ext_solverobject to match the CFD grid on which the external solution has been interpolated. This will ensure that subsequent plotting calls use consistent data and grid dimensions.