-
Notifications
You must be signed in to change notification settings - Fork 18
[GSPH 3/7] SR physics mode core #1525
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
|
Thanks @Guo-astro for opening this PR! You can do multiple things directly here: Once the workflow completes a message will appear displaying informations related to the run. Also the PR gets automatically reviewed by gemini, you can: |
Summary of ChangesHello @Guo-astro, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly extends the GSPH simulation capabilities by integrating Special Relativistic hydrodynamics. It provides the core infrastructure, algorithms, and data structures necessary to model high-velocity, high-energy astrophysical phenomena where relativistic effects are paramount. The changes introduce a new physics mode that fundamentally alters how variables are conserved, how density is calculated, and how forces are computed, moving beyond the limitations of Newtonian approximations. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces the core components for Special Relativistic (SR) GSPH, which is a significant addition to the codebase. The new physics mode includes configurations, field naming conventions, EOS computations, force kernels, primitive recovery mechanisms, and timestepping logic tailored for SR hydrodynamics. The overall structure is well-organized, with clear separation of concerns into different header and source files. All original comments have been retained as they do not contradict the provided rules and offer valuable feedback on numerical stability, adherence to the referenced physics formulation, potential inefficiencies, and general code quality. Addressing these will improve the correctness, robustness, and maintainability of the SR-GSPH implementation.
|
/gemini review |
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.
Code Review
This pull request introduces the core components for Special Relativistic (SR) GSPH, including configuration, equation of state, field definitions, force computation, primitive recovery, and time stepping. The implementation is comprehensive and follows the formulation from Kitajima et al. (2025).
My review focuses on ensuring numerical stability, performance, and consistency in documentation and code structure. I've identified a few critical areas where unsafe calculations could lead to NaN values, a high-severity performance issue due to an unnecessary device-host-device data copy, and several medium-severity inconsistencies in documentation and code structure that should be addressed to improve maintainability.
Overall, this is a solid contribution that lays the foundation for SR simulations. Addressing the feedback will make the implementation more robust and easier to maintain.
src/shammodels/gsph/include/shammodels/gsph/physics/sr/SRForceKernel.hpp
Show resolved
Hide resolved
45e892a to
0cb6e28
Compare
Core Infrastructure: - PhysicsMode base class for strategy pattern implementation - ForceKernelBase for common force computation interface - PhysicsModeFactory for creating physics mode instances - FieldNames.hpp as SSOT for field naming Modular Components: - BoundaryHandler: boundary condition processing - BuildTrees: tree construction - ComputeCFL: CFL timestep calculation - ComputeGradients: gradient computation - ComputeOmega: omega factor computation - GhostCommunicator: MPI ghost communication - IterateSmoothingLengthVolume: h-iteration - NeighbourCache: caching neighbor interactions - FunctorNode: generic functor nodes Refactors the monolithic GSPH Solver into modular components, preparing for physics mode decoupling (Newtonian vs SR).
The ForceKernelBase template class was designed as a Template Method pattern base but was never used - NewtonianForceKernel and SRForceKernel are standalone implementations with their own buffer management appropriate for their physics. The hardcoded CommonBuffers design (buf_density, buf_pressure, etc.) does not accommodate SR physics which requires distinct lab-frame vs rest-frame field naming (N_LABFRAME, LORENTZ_FACTOR, ENTHALPY, etc.).
These fields have physics-specific meanings: - Newtonian: single frame quantities - SR: lab-frame vs rest-frame distinction Each physics mode now defines its own field constants with appropriate semantic names in their respective FieldNames headers.
Headers: - NewtonianConfig: solver configuration for Newtonian hydro - NewtonianEOS: ideal gas equation of state interface - NewtonianFieldNames: field naming constants - NewtonianForceKernel: force computation interface - NewtonianMode: PhysicsMode implementation for Newtonian hydro - NewtonianTimestepper: CFL-based timestepping - forces.hpp: force math functions - ReconstructConfig: interface reconstruction settings - RiemannConfig: Riemann solver configuration Riemann Solvers: - RiemannBase: abstract Riemann solver interface - HLL: Harten-Lax-van Leer approximate Riemann solver - Iterative: exact iterative Riemann solver Sources: - Complete implementations for all Newtonian components This implements the Newtonian physics mode for GSPH using the strategy pattern for physics decoupling.
Energy fields have physics-specific meanings and are now defined directly in NewtonianFieldNames.hpp rather than imported from the common FieldNames.hpp.
Headers: - SRConfig: solver configuration for SR hydro - SREOS: relativistic equation of state interface - SRFieldNames: field naming constants for SR fields - SRForceKernel: force computation interface for SR - SRMode: PhysicsMode implementation for SR hydro - SRPrimitiveRecovery: conservative to primitive variable recovery - SRTimestepper: relativistic CFL-based timestepping - forces.hpp: SR force math functions Sources: - SREOS.cpp: relativistic EOS implementation - SRForceKernel.cpp: SR force kernel implementation - SRPrimitiveRecovery.cpp: Newton-Raphson primitive recovery - SRTimestepper.cpp: SR timestep computation This implements the core SR physics components for GSPH.
SR physics defines its own XYZ, VXYZ, AXYZ, UINT, DUINT constants directly rather than importing from the common FieldNames.hpp. This clarifies the physical meaning (lab-frame quantities for SR).
Recovery Methods: - RecoveryBase: abstract interface for primitive recovery - NewtonRaphson: Newton-Raphson iterative recovery algorithm Riemann Solvers: - RiemannBase: abstract SR Riemann solver interface - Exact: exact relativistic Riemann solver (Pons 2000) Mode Implementation: - SRMode.cpp: complete SR physics mode orchestration - Ghost field setup for SR variables - Primitive recovery from conserved variables - Force computation with relativistic corrections - Integration of SR equations This completes the Special Relativistic GSPH implementation following Kitajima 2024 formulation.
Solver Changes: - Solver.hpp/cpp: Refactored to use PhysicsMode strategy pattern - SolverConfig.hpp/cpp: Updated config for physics mode selection - Model.hpp/cpp: Updated model registration Storage & IO: - SolverStorage.hpp: Updated field storage for physics modes - VTKDump.hpp/cpp: Physics-aware VTK output Python Bindings: - pyGSPHModel.cpp: Extended bindings for SR configuration - physics_mode selection (newtonian/sr) - SR-specific parameters (gamma, initial conditions) Build System: - CMakeLists.txt: Updated for new physics module structure This integrates the modular physics modes into the GSPH solver, enabling runtime selection between Newtonian and SR physics.
Newtonian Tests: - sod_tube_gsph.py: Sod shock tube validation - blast_wave_gsph.py: Extreme blast wave test SR Tests (Kitajima 2024 benchmark suite): - problem1_sod.py: Relativistic Sod shock tube - problem2_blast.py: Relativistic blast wave - problem3_strong_blast.py: Strong relativistic blast - problem4_ultra_relativistic.py: Ultra-relativistic regime - problem5_tangent_velocity.py: Tangential velocity test - problem6_2d_sod.py: 2D relativistic Sod tube - problem7_kh_instability.py: Kelvin-Helmholtz instability Common: - sr/__init__.py: SR test utilities - kitajima_plotting.py: Plotting helpers for Kitajima benchmarks All tests use: - ctx.collect_data() for direct memory access (no pyvista) - Strict tolerances (~1e-8) for regression testing - Analytic solutions for validation
Unit Tests: - GSPHForceTests.cpp: Update for new physics structure - GSPHRiemannTests.cpp: Update Riemann solver tests SPH Module Fixes: - IterateSmoothingLengthDensity: Improve h-iteration logging - BasicSPHGhosts.cpp: Fix ghost handling Math: - sphkernels.hpp: Minor kernel fixes MHD Placeholder: - MHDConfig.hpp: Placeholder for future MHD physics mode
- NewtonianMode: add compute_omega_newtonian() using standard SPH (no c_smooth) - SRMode: use SRIterateSmoothingLength with Kitajima volume-based approach - Remove shared ComputeOmega module (each mode now owns this) - Remove legacy UpdateDerivs (replaced by NewtonianForceKernel) - Move IterateSmoothingLengthVolume to physics/sr/SRIterateSmoothingLength - Update CMakeLists.txt sources This fixes the density/pressure error regression caused by c_smooth=1.2 being incorrectly applied to Newtonian mode.
…ult (1.0) SR's volume-based h-iteration (Kitajima Eq. 232-233) requires c_smooth > 1 to smooth h variation across discontinuities. The SR-specific value was defined in SRConfig but not transferred to the shared config.
The Riemann solver and force computation code has been moved to the physics/newtonian/ and physics/sr/ directories. The math/ folder contained duplicate/orphaned code that is no longer used.
Remove deprecated include of math/riemann/iterative.hpp (now deleted) and update hllc_solver call to use solve_hll from the new location in physics/newtonian/riemann/HLL.hpp.
The Kitajima formulation requires multiplying each pairwise contribution by the neighbor's baryon number ν_j: <νᵢ dSᵢ/dt> = -Σⱼ νⱼ P* V² [∇ᵢW - ∇ⱼW] The previous code was missing this factor, causing forces to be systematically too weak and resulting in incorrect pressure profiles (~3x too low in Problem 5 tangent velocity test).
… 371" This reverts commit 2a6bcc427fc6b31083d876b88ee0264e0cf90027.
9f509de to
2a8b20e
Compare
Run buildbot/update_authors.py to add --no git blame-- annotations to author headers as required by CI checks.
Remove SolverCallbacks struct and have PhysicsMode evaluate nodes directly via storage.solver_graph. This aligns with solvergraph design: - Branching happens at init time (node registration) - Flow is visible as graph structure - No runtime callback creation Changes: - Register Solver method nodes in init_solver_graph() - Delete SolverCallbacks struct from PhysicsMode.hpp - Update evolve_timestep() signature (remove callbacks param) - NewtonianMode/SRMode evaluate nodes directly via storage.solver_graph Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
Adds the core components for Special Relativistic (SR) GSPH.
Headers
SRConfig: solver configuration for SR hydroSREOS: relativistic equation of state interfaceSRFieldNames: field naming constants for SR fieldsSRForceKernel: force computation interface for SRSRMode: PhysicsMode implementation for SR hydroSRPrimitiveRecovery: conservative to primitive variable recoverySRTimestepper: relativistic CFL-based timesteppingforces.hpp: SR force math functionsSources
SREOS.cpp: relativistic EOS implementationSRForceKernel.cpp: SR force kernel implementationSRPrimitiveRecovery.cpp: Newton-Raphson primitive recoverySRTimestepper.cpp: SR timestep computationPhysics Background
Implements Special Relativistic hydrodynamics following Kitajima 2024 formulation with volume-based SPH.
Dependencies
Depends on #1523 (core infrastructure)