-
Notifications
You must be signed in to change notification settings - Fork 7
Add wall heat load engineering module #297
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
Conversation
Implements standalone Python module for analyzing wall heat loads from SIMPLE particle tracing results, enabling port placement optimization and heat flux visualization. New functionality: - WallHeatMap: Bins particle wall hits to heat flux (MW/m^2) from results.nc - PortOptimizer: Optimizes port placement to minimize heat exposure using scipy - Visualization: 2D matplotlib and 3D PyVista heat flux plots - VTK export: Export to ParaView for advanced visualization Module design: - Standalone operation: reads results.nc, no Fortran backend needed - 16 unit tests with mock data generation - Proper error handling and optional dependencies (scipy, pyvista) Code quality: - Functions under 50 lines (3 warnings at soft limit, 0 hard limit violations) - Total module size: 660 lines (within 1000 hard limit) - No stubs, placeholders, or print statements in library code - Type hints and comprehensive docstrings Related to #284
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||||||||
- Use final velocity p=v/v0 from zend[3] to weight particle energy - Heat flux: q = sum(p^2) * (P_alpha / N) / A_bin - Add energy_loss_fraction: accounts for collisional slowing down - lost_power now based on energy, not particle count - Add comprehensive physics documentation in DOC/wall-heat-loads.md - Update tests for new API with energy weighting verification
- Add compute_wall_area_from_chartmap() to calculate surface area using metric tensor from chartmap NetCDF file - Add compute_bin_areas_from_chartmap() for per-bin area calculation - Update WallHeatMap.from_netcdf() to accept optional chartmap_file - Fix zeta boundary handling: use one-sided differences at boundaries (Cartesian coords are not periodic within one field period) - Document guiding center limitation (~5-10 cm gyroradius smearing) - Add 10 comprehensive tests covering edge cases: - Single/high field periods, high/low aspect ratio - Grid convergence, reactor scale, small device scale
- Extract _compute_surface_element_grid() helper function - Fix compute_bin_areas_from_chartmap() to use correct zeta boundary handling (was using wrong periodic wrapping, now uses shared helper) - Tighten test tolerances from 5% to 1.5% (actual errors are 0.6-1.3%) - Reduce code duplication between area calculation functions
- Fix PortOptimizer to actually enforce exclusion zones via penalty (previously _in_exclusion_zone was defined but never used) - Enable optimizer tests (were permanently skipped with skipif(True)) - Add test_solve_single_port: verifies optimization finds low-flux region - Add test_solve_multiple_ports: verifies multiple ports work - Add test_solve_with_exclusion_zone: verifies exclusion is enforced
Changes from architect review: - Add bin_areas attribute with per-bin area from chartmap geometry - Add flux_error Monte Carlo error estimate (sigma = q / sqrt(N)) - Enforce max_flux_constraint in optimizer objective function - Fix exclusion zone to check full port extent (corners + center) - Document theta/zeta coordinate conventions in docstring - Fix coordinate mapping: chartmap theta [0,2pi] to heatmap [-pi,pi] - Fix zeta mapping: use modulo to map full torus to single period Tests added for all new features (34 tests pass).
Fixes from critical review: - Add validation for total_alpha_power_MW (must be positive) - Map theta from VMEC [0,2pi] to [-pi,pi] before histogram binning - Apply modulo 2pi to zeta (SIMPLE outputs cumulative angles) - Add warning when bin_areas sum < 90% of wall_area (resolution mismatch) - Handle zeta wrapping in integrated_flux_in_region for ports near zeta=0 Test improvements: - Mock data now uses realistic VMEC conventions: - theta in [0, 2pi] instead of [-pi, pi] - zeta in [0, 20*pi] to test cumulative angle handling - Added test_zeta_wrapping_in_region - Added test_invalid_alpha_power - Added test_large_angles_handled All 37 tests pass.
- Remove duplicate _get_max_flux_in_region method (use _get_peak_flux_in_region) - Add test_resolution_mismatch_warning for 90% area threshold - Document resolution matching requirement in DOC/wall-heat-loads.md 38 tests pass.
Summary
Adds standalone Python engineering module for wall heat load analysis from SIMPLE particle tracing results with energy-weighted flux calculation.
Physics features:
q = sum(p²) * (P_alpha/N) / A_binwhere p = v/v₀σ = q / √N_binEngineering capabilities:
WallHeatMap: Loads results.nc and computes heat flux distribution (MW/m²)PortOptimizer: Optimizes port placement using scipy differential evolutioncompute_wall_area_from_chartmap(): Accurate 3D surface area from metric tensorplot_heat_flux_2d()/plot_heat_flux_3d(): Visualization with port overlaysexport_to_vtk(): VTK export for ParaView analysisCoordinate handling:
Code quality:
Test coverage (38 tests):
Documentation:
Closes #284
Test plan