Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bbf7e64
docs: Complete Phase 7 - documentation and examples
shaia Jan 3, 2026
c3b6df9
refactor(examples): Clean up channel_flow.py
shaia Jan 3, 2026
3a39100
fix(examples): Prevent division by zero in lid_driven_cavity_advanced
shaia Jan 3, 2026
dd7e1b4
style(examples): Use consistent import style for cfd_python
shaia Jan 3, 2026
19473b1
docs: Update CHANGELOG with all migration phases and fix import style
shaia Jan 3, 2026
7fb3ec4
fix(examples): Correct comment/code mismatch in error_handling.py
shaia Jan 3, 2026
bfde1a0
docs(examples): Clarify code behavior in channel_flow and error_handling
shaia Jan 3, 2026
1e68816
refactor: Use explicit MRO filtering instead of slice
shaia Jan 3, 2026
5101082
docs: Clarify Poiseuille flow formula in channel_flow example
shaia Jan 3, 2026
5a61b7e
style: Use consistent import style in test_errors.py
shaia Jan 3, 2026
c3e0e25
fix: Use simulation results for statistics in channel_flow example
shaia Jan 3, 2026
d2665ea
style: Use OSError consistently instead of IOError
shaia Jan 3, 2026
607b578
docs: Clarify synthetic fields in derived_fields.py example
shaia Jan 3, 2026
255dd5f
docs: Fix misleading no-slip BC comment in channel_flow.py
shaia Jan 3, 2026
a4e5858
fix: Correct exception constructor parameter order in error_handling.py
shaia Jan 3, 2026
732e775
fix: Fix example scripts for cross-platform compatibility
shaia Jan 3, 2026
8f39580
feat: Add matplotlib visualization example
shaia Jan 3, 2026
cb73ed6
refactor: Write all example outputs to examples/output/ directory
shaia Jan 3, 2026
8ec62d0
docs: Add Rankine vortex explanation to visualization example
shaia Jan 3, 2026
1a4d434
docs: Add physics explanations to all example files
shaia Jan 3, 2026
40db79c
fix: Correct lid_driven_cavity_advanced convergence tracking
shaia Jan 3, 2026
05dfb46
docs: Add missing examples to examples/README.md
shaia Jan 3, 2026
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ src/cfd_lib/
*.vtu
*.pvd

# Example output files
examples/output/
*.csv

# IDE
.vscode/
.idea/
Expand Down
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added

#### Backend Availability API (Phase 5)

- `BACKEND_SCALAR`, `BACKEND_SIMD`, `BACKEND_OMP`, `BACKEND_CUDA` constants
- `backend_is_available(backend)` - Check if backend is available at runtime
- `backend_get_name(backend)` - Get human-readable backend name
- `list_solvers_by_backend(backend)` - List solvers for specific backend
- `get_available_backends()` - List all available backend names

#### Derived Fields & Statistics (Phase 3)

- `calculate_field_stats(data)` - Compute min, max, avg, sum for a field
- `compute_velocity_magnitude(u, v, nx, ny)` - Compute velocity magnitude field
- `compute_flow_statistics(u, v, p, nx, ny)` - Comprehensive flow statistics

#### Error Handling API (Phase 4)

- Python exception hierarchy: `CFDError`, `CFDMemoryError`, `CFDInvalidError`, `CFDIOError`, `CFDUnsupportedError`, `CFDDivergedError`, `CFDMaxIterError`
- `raise_for_status(status_code, context)` - Raise appropriate exception for status codes
- Exception classes integrate with Python standard exceptions (e.g., `CFDMemoryError` inherits from `MemoryError`)

#### CPU Features Detection (Phase 6)

- `SIMD_NONE`, `SIMD_AVX2`, `SIMD_NEON` constants
- `get_simd_arch()` - Get SIMD architecture constant
- `get_simd_name()` - Get SIMD architecture name ("avx2", "neon", "none")
- `has_avx2()`, `has_neon()`, `has_simd()` - Check CPU SIMD capabilities
- `create_grid_stretched(nx, ny, xmin, xmax, ymin, ymax, beta)` - Stretched grid with hyperbolic cosine distribution

#### CI/Build System (Phase 2.5)

- Dual-variant wheel builds supporting both CPU-only and CUDA-enabled configurations
- Matrix build strategy in CI for separate CPU and CUDA wheel artifacts
- Support for CFD library v0.1.6 modular backend libraries

#### Documentation & Examples (Phase 7)

- Comprehensive README with full API reference
- New example scripts demonstrating cfd_python features:
- `lid_driven_cavity_advanced.py`: Complete cavity simulation with convergence monitoring
- `channel_flow.py`: Channel flow with parabolic inlet and analytical validation
- `vtk_output.py`: VTK output for ParaView visualization
- `solver_comparison.py`: Backend performance comparison and benchmarking
- `backend_detection.py`: CPU feature and backend availability detection
- `boundary_conditions.py`: Boundary condition API usage patterns
- `derived_fields.py`: Computing velocity magnitude and flow statistics
- `error_handling.py`: Error handling best practices
- New test suites:
- `test_backend_availability.py` - Backend constants and functions
- `test_derived_fields.py` - Statistics and velocity magnitude
- `test_errors.py` - Exception classes and raise_for_status
- `test_cpu_features.py` - SIMD detection and grid stretching
- `test_abi_compatibility.py` - NULL handling and stress tests

### Changed
- Updated build system to link modular CFD libraries (cfd_api, cfd_core, cfd_scalar, cfd_simd, cfd_omp, cfd_cuda)
- Migrated to CUDA 12.0.0 from 12.6.2 for better stability and compatibility
Expand Down
120 changes: 91 additions & 29 deletions MIGRATION_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ This document outlines the required changes to update cfd-python bindings to wor

## Current State

- **cfd-python version:** 0.1.0 (outdated)
- **cfd-python version:** 0.2.0 (compatible with CFD v0.1.6)
- **Target CFD library:** v0.1.6
- **Status:** BROKEN - will not compile against current CFD library
- **Status:** ✅ COMPLETE - All migration phases finished

## What's New in v0.1.6

Expand Down Expand Up @@ -457,37 +457,44 @@ cpu_features_t cfd_get_cpu_features(void);

**Actual effort:** < 0.5 days

### Phase 7: Documentation & Tests (Required)
### Phase 7: Documentation & Tests (Required) ✅ COMPLETED

**Priority:** P1 - Required for release

**Tasks:**

- [ ] **7.1 Update README**
- Installation instructions
- API changes documentation
- Migration guide for users
- Backend availability examples
**Status:** Completed on 2026-01-03

- [ ] **7.2 Update Python docstrings**
- All new functions
- BC examples
- Error handling examples
- Backend detection examples

- [ ] **7.3 Add comprehensive tests**
- Test all BC types
- Test error handling
- Test derived fields
- Test with different backends
- Test backend availability API
**Tasks:**

- [ ] **7.4 Update examples**
- BC usage examples
- Derived fields examples
- Backend detection examples
- [x] **7.1 Update README**
- Complete API reference for all v0.1.6 features
- Boundary conditions documentation with examples
- Backend availability API documentation
- Error handling with exception classes
- CPU features detection
- Migration guide from v0.1.0

- [x] **7.2 Update Python docstrings**
- Comprehensive module docstring in `__init__.py`
- All BC functions, types, and edges documented
- Error handling API documented
- Backend availability API documented
- CPU features API documented

- [x] **7.3 Add comprehensive tests**
- `test_boundary_conditions.py` - All BC types and backends
- `test_backend_availability.py` - Backend constants and functions
- `test_derived_fields.py` - Statistics and velocity magnitude
- `test_errors.py` - Exception classes and raise_for_status
- `test_cpu_features.py` - SIMD detection and grid stretching
- `test_abi_compatibility.py` - NULL handling and stress tests

- [x] **7.4 Update examples**
- `boundary_conditions.py` - BC types, backends, inlet/outlet
- `backend_detection.py` - CPU features, solver/BC backends
- `derived_fields.py` - Statistics, velocity magnitude, VTK output
- `error_handling.py` - Exception classes, raise_for_status
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

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

The MIGRATION_PLAN.md lists only 4 examples in Phase 7.4 (boundary_conditions.py, backend_detection.py, derived_fields.py, error_handling.py), but the PR description mentions 8 examples total, including channel_flow.py, lid_driven_cavity_advanced.py, solver_comparison.py, and vtk_output.py. The migration plan should be updated to include all examples that were actually added.

Suggested change
- `error_handling.py` - Exception classes, raise_for_status
- `error_handling.py` - Exception classes, raise_for_status
- `channel_flow.py` - Canonical channel flow simulation with post-processing
- `lid_driven_cavity_advanced.py` - Advanced lid-driven cavity setup with configurable parameters
- `solver_comparison.py` - Compare different solver backends and configurations
- `vtk_output.py` - Standalone VTK output example for visualization pipelines

Copilot uses AI. Check for mistakes.

**Estimated effort:** 2 days
**Actual effort:** < 0.5 days

---

Expand Down Expand Up @@ -569,9 +576,9 @@ find_library(CFD_LIBRARY cfd_library) # Unified library name
| Phase 4: Error Handling | ~~1 day~~ ✅ < 0.5 days | 4 days |
| Phase 5: Backend Availability (v0.1.6) | ✅ 0.5 days | 4.5 days |
| Phase 6: CPU Features | ~~1 day~~ ✅ < 0.5 days | 5 days |
| Phase 7: Docs & Tests | 2 days | 7 days |
| Phase 7: Docs & Tests | ~~2 days~~ ✅ < 0.5 days | 5.5 days |

**Total estimated effort:** ~~9-10 days~~ ~7 days (5 days completed)
**Total estimated effort:** ~~9-10 days~~ ~5.5 days ✅ ALL PHASES COMPLETE

---

Expand Down Expand Up @@ -694,3 +701,58 @@ While `_exceptions.py` has type hints, the C extension functions lack type stubs
2. **Standardize coordinate naming** across grid functions
3. **Consider IntEnum** for constant groups (SIMD, BC types, backends)
4. **Optional high-level wrappers** for BC operations (Phase 8 candidate)

---

## Phase 7 (CFD ROADMAP) Status: Python Integration

This section tracks progress on Phase 7 from the main CFD library ROADMAP.md, which covers Python integration.

### 7.1 Python Bindings (P1)

| Task | Status | Notes |
|------|--------|-------|
| Complete C extension module | ✅ Done | `cfd_python.c` with Stable ABI (Py_LIMITED_API 3.9+) |
| NumPy array integration | ⚠️ Partial | Functions accept/return Python lists; NumPy conversion at Python layer |
| Pythonic API design | ✅ Done | Snake_case naming, native Python types, exception hierarchy |
| Type hints and stubs | ❌ Pending | Phase 8 in cfd-python ROADMAP - `.pyi` stubs not yet created |
| Pre-built wheels (manylinux, macOS, Windows) | ✅ Done | CI builds wheels for all platforms; CUDA variant for Linux/Windows |

**C Extension Module Features:**
- Grid creation (uniform and stretched)
- Flow field operations
- Solver registry and creation
- Simulation API (`run_simulation`, `run_simulation_step`)
- Boundary conditions (all types: Neumann, Dirichlet, no-slip, inlet, outlet)
- Derived fields and statistics
- Error handling with Python exceptions
- Backend availability API (Scalar, SIMD, OMP, CUDA)
- CPU features detection (AVX2, NEON)

### 7.2 High-level Python API (P1)

| Task | Status | Notes |
|------|--------|-------|
| Problem definition classes | ❌ Pending | Not yet implemented |
| Mesh generation helpers | ⚠️ Partial | `create_grid`, `create_grid_stretched` available |
| Post-processing utilities | ⚠️ Partial | `compute_velocity_magnitude`, `compute_flow_statistics` available |
| Jupyter notebook integration | ❌ Pending | Not yet implemented |

**What's Available:**
- Low-level C bindings exposed directly to Python
- Exception hierarchy for error handling (`CFDError` and subclasses)
- `raise_for_status()` helper for checking C library return codes

**What's Missing:**
- High-level `Simulation` class for problem setup
- `BoundaryConditions` builder/context manager pattern
- Integration with matplotlib/visualization in notebooks
- Problem templates (lid-driven cavity, channel flow, etc.)

### Summary

Phase 7.1 (Python Bindings) is **largely complete** - the C extension module is functional, builds wheels for all platforms, and provides a working Python API. The main gaps are:
1. Type stubs for IDE support (Phase 8 in cfd-python)
2. NumPy direct integration (currently uses list conversion)

Phase 7.2 (High-level Python API) is **not started** - the current API exposes C functions directly without high-level Pythonic wrappers or classes.
Loading
Loading