Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/performance-benchmarking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ jobs:
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update
sudo apt-get install -y valgrind linux-tools-common
sudo apt-get install -y valgrind linux-tools-common libfontconfig1-dev
fi

- name: Build benchmarks
run: cargo build --release --bench comprehensive_cfd_benchmarks
run: cargo build --release --bench performance_benchmarks

- name: Run comprehensive benchmarks
if: github.event.inputs.benchmark_type == 'comprehensive' || github.event_name != 'workflow_dispatch'
run: |
cargo bench --bench comprehensive_cfd_benchmarks | tee benchmark_results.txt
cargo bench --bench performance_benchmarks | tee benchmark_results.txt

- name: Run regression detection benchmarks
if: github.event.inputs.benchmark_type == 'regression' || github.event_name == 'schedule'
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ report/
*.dll
*.so
*.dylib
.venv/

# Python compilation artifacts
__pycache__/
*.pyc
*.pyo
*.pyd
Binary file removed validation/__pycache__/__init__.cpython-313.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
27 changes: 25 additions & 2 deletions validation/compare_cavity_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,31 @@ 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
print("Interpolating cfd_python results to match external reference grid...")
from scipy.interpolate import RectBivariateSpline

# cfd_python arrays are (ny, nx), RectBivariateSpline expects (x, y)
# So we transpose the CFD result fields (.T) for interpolation
interp_u = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["u"].T)
interp_v = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["v"].T)
interp_p = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["p"].T)

# Evaluate on the external grid. Note that ext_solver.x and ext_solver.y are 1D arrays
new_u = interp_u(ext_solver.x, ext_solver.y).T
new_v = interp_v(ext_solver.x, ext_solver.y).T
new_p = interp_p(ext_solver.x, ext_solver.y).T

cfd_python_result["u"] = new_u
cfd_python_result["v"] = new_v
cfd_python_result["p"] = new_p
Comment on lines +108 to +123
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The local import of scipy could lead to an unhandled ImportError if the optional dependency is not installed, causing the script to crash. It's better to wrap this in a try...except block for graceful error handling.

Additionally, the interpolation logic is duplicated for the u, v, and p fields. This can be refactored into a loop to make the code more concise and easier to maintain.

Here is a suggestion that addresses both points:

Suggested change
from scipy.interpolate import RectBivariateSpline
# cfd_python arrays are (ny, nx), RectBivariateSpline expects (x, y)
# So we transpose the CFD result fields (.T) for interpolation
interp_u = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["u"].T)
interp_v = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["v"].T)
interp_p = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["p"].T)
# Evaluate on the external grid. Note that ext_solver.x and ext_solver.y are 1D arrays
new_u = interp_u(ext_solver.x, ext_solver.y).T
new_v = interp_v(ext_solver.x, ext_solver.y).T
new_p = interp_p(ext_solver.x, ext_solver.y).T
cfd_python_result["u"] = new_u
cfd_python_result["v"] = new_v
cfd_python_result["p"] = new_p
try:
from scipy.interpolate import RectBivariateSpline
except ImportError:
print("WARN: scipy is not installed, cannot interpolate grids. Skipping comparison.")
return None
x_src, y_src = cfd_python_result["x"], cfd_python_result["y"]
x_dst, y_dst = ext_solver.x, ext_solver.y
for field in ["u", "v", "p"]:
# cfd_python arrays are (ny, nx), but RectBivariateSpline expects z of shape (nx, ny),
# so we transpose the field. The result is (nx_dst, ny_dst), so we transpose back.
interpolator = RectBivariateSpline(x_src, y_src, cfd_python_result[field].T)
cfd_python_result[field] = interpolator(x_dst, y_dst).T


# Also interpolate centerlines using 1D interpolation
cfd_python_result["u_centerline"] = np.interp(ext_solver.y, cfd_python_result["y"], cfd_python_result["u_centerline"])
cfd_python_result["v_centerline"] = np.interp(ext_solver.x, cfd_python_result["x"], cfd_python_result["v_centerline"])

# Update coordinates to match the external grid for proper plotting
cfd_python_result["x"] = ext_solver.x
cfd_python_result["y"] = ext_solver.y

# Compute L2 errors
u_diff = cfd_python_result["u"] - ext_sol["u"]
Expand Down
Loading