[SPH] migrate compute omega from shamrock pre-history to modern age#1265
[SPH] migrate compute omega from shamrock pre-history to modern age#1265tdavidcl merged 1 commit intoShamrock-code:mainfrom
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @tdavidcl, 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 modernizes the compute_omega function within the SPH (Smoothed Particle Hydrodynamics) module. The primary goal is to transition the computation to a more efficient and scalable distributed kernel call mechanism. This refactoring streamlines the code, improves how data is handled through structured field references, and prepares the SPH computations for better performance in a distributed computing environment.
Highlights
- Modernized
compute_omegaFunction: Thecompute_omegafunction has been entirely refactored to utilize a modern distributed kernel call mechanism, moving away from an older, patch-data-centric approach. - Distributed Kernel Integration: The computation now leverages
sham::distributed_data_kernel_callfor parallel execution across distributed data, enhancing scalability and performance. - Improved Data Management: Introduction of
FieldRefsandDDPatchDataFieldRefprovides a more structured and efficient way to handle field data references within the solver graph. - Inlined Computation Logic: The core
omegacalculation logic, previously abstracted, is now directly embedded within a lambda function passed to the distributed kernel, making the computation more self-contained and explicit.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request refactors the compute_omega function to use the modern distributed_data_kernel_call infrastructure, which is a good step forward. The implementation correctly sets up the distributed call.
However, I've found a critical issue in the new kernel logic where it seems to be using an incorrect density value for the omega correction factor calculation. Specifically, it uses a theoretical density rho_ha instead of the summed SPH density rho_sum, and the latter is calculated but left unused. This will likely lead to incorrect physical results. My review includes a suggestion to fix this.
Please address this critical point to ensure the correctness of the simulation.
| using namespace shamrock::sph; | ||
|
|
||
| Tscal rho_ha = rho_h(part_mass, h_a, Kernel::hfactd); | ||
| Tscal omega_a = 1 + (h_a / (3 * rho_ha)) * part_omega_sum; | ||
| omega[id_a] = omega_a; |
There was a problem hiding this comment.
The calculation of omega_a appears to be using rho_ha (a theoretical density) instead of rho_sum (the actual SPH density summation). The variable rho_sum is calculated in the neighbor loop but is currently unused, which strongly suggests it should be used here. Using rho_sum is consistent with the standard SPH formulation for the variable smoothing length correction factor.
Additionally, a check should be added to prevent division by zero when rho_sum is zero (e.g., for isolated particles), in which case omega_a should be 1.
| using namespace shamrock::sph; | |
| Tscal rho_ha = rho_h(part_mass, h_a, Kernel::hfactd); | |
| Tscal omega_a = 1 + (h_a / (3 * rho_ha)) * part_omega_sum; | |
| omega[id_a] = omega_a; | |
| Tscal omega_a = 1.0; | |
| if (rho_sum > 0.0) { | |
| omega_a = 1.0 + (h_a / (3.0 * rho_sum)) * part_omega_sum; | |
| } | |
| omega[id_a] = omega_a; |
Workflow reportworkflow report corresponding to commit 94080df Pre-commit check reportPre-commit check: ✅ Test pipeline can run. Clang-tidy diff reportNo relevant changes found. You should now go back to your normal life and enjoy a hopefully sunny day while waiting for the review. Doxygen diff with
|
No description provided.