Skip to content

[SPH] prepare migration of EOS to solvergraph - #1938

Merged
tdavidcl merged 3 commits into
Shamrock-code:mainfrom
tdavidcl:eos_2_SPH
Jul 21, 2026
Merged

[SPH] prepare migration of EOS to solvergraph#1938
tdavidcl merged 3 commits into
Shamrock-code:mainfrom
tdavidcl:eos_2_SPH

Conversation

@tdavidcl

Copy link
Copy Markdown
Member

No description provided.

tdavidcl and others added 3 commits July 21, 2026 13:55
Use merged_xyzh for position-dependent EOS and allocate uint_g as scalar.

Co-authored-by: Cursor <cursoragent@cursor.com>
Remove unused RhoGetters, debug logging, and leftover locals/includes.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a runnable Sod shock-tube SPH example with plotting, checkpointing, and GIF generation. It also refactors SPH EOS evaluation from patch-wise getters to solvergraph spans and distributed kernels across multiple EOS variants.

Changes

SPH EOS and Sod shock-tube flow

Layer / File(s) Summary
Solvergraph EOS contract
src/shammodels/sph/include/.../ComputeEos.hpp, src/shammodels/sph/src/modules/ComputeEos.cpp
compute_eos_internal now receives solvergraph edges, optional input spans, explicit sizes, and mutable pressure and sound-speed output spans, while enforcing that either density or smoothing length is provided.
EOS kernel implementations
src/shammodels/sph/src/modules/ComputeEos.cpp
Isothermal, adiabatic, polytropic, locally isothermal, sink-potential, and Fermi EOS branches use solvergraph spans, distributed kernels, or device buffers to compute outputs.
EOS input wiring
src/shammodels/sph/src/modules/ComputeEos.cpp
compute_eos() prepares field references and derives gas density and internal energy for dust epsilon, dust s_j, and direct smoothing-length paths.
Sod simulation and analytic output
examples/sph/run_sod.py, src/shamphys/src/SodTube.cpp
Adds Sod-tube initialization, timestepping, periodic plots, checkpoints, GIF creation, and analytic comparison; initializes SodTube velocities and removes an unreachable fallback return.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SodSimulation
  participant ComputeEos
  participant DistributedKernel
  participant OutputFields
  participant SodTube
  SodSimulation->>ComputeEos: evaluate EOS during timestepping
  ComputeEos->>DistributedKernel: dispatch solvergraph spans
  DistributedKernel->>OutputFields: write pressure and soundspeed
  SodSimulation->>SodTube: sample analytic Sod solution
  SodSimulation->>OutputFields: save numerical and analytic plot frames
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No description was provided, so there is no meaningful summary to evaluate against the changes. Add a brief description of the EOS solvergraph migration and related example/module updates.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: refactoring EOS handling toward solvergraph in the SPH module.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks @tdavidcl for opening this PR!

You can do multiple things directly here:
1 - Comment pre-commit.ci run to run pre-commit checks.
2 - Comment pre-commit.ci autofix to apply fixes.
3 - Add label autofix.ci to fix authorship & pre-commit for every commit made.
4 - Add label light-ci to only trigger a reduced & faster version of the CI (need the full one before merge).
5 - Add label trigger-ci to create an empty commit to trigger the CI.

Once the workflow completes a message will appear displaying informations related to the run.

Also the PR gets automatically reviewed by gemini, you can:
1 - Comment /gemini review to trigger a review
2 - Comment /gemini summary for a summary
3 - Tag it using @gemini-code-assist either in the PR or in review comments on files

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/sph/run_sod.py`:
- Line 110: Replace the periodic boundary configuration in the run_sod setup by
using boundary conditions appropriate for a single-interface Sod shock tube,
matching the non-periodic behavior expected by SodTube and avoiding a seam
between the left and right states.
- Around line 159-166: Guard the GIF generation and display block containing
show_image_sequence, PillowWriter, ani.save, and plt.show with the existing
shamrock.sys.world_rank() == 0 condition, so only rank zero creates and displays
the animation while preserving the current behavior within that rank.

In `@src/shammodels/sph/src/modules/ComputeEos.cpp`:
- Around line 401-423: Update the FA2014 `eos_internal` lambda to handle an
empty sink list before calculating the potential: when `scount == 0`, apply the
same fallback behavior as `SolverEOS_LocallyIsothermalFA2014Extended` and return
without producing zero pressure or soundspeed. Preserve the existing potential
and EOS calculations for non-empty sink lists.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 83d17c98-977c-4074-aaab-4e57fa4ca062

📥 Commits

Reviewing files that changed from the base of the PR and between 9c3b91b and 7df87d7.

📒 Files selected for processing (4)
  • examples/sph/run_sod.py
  • src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp
  • src/shammodels/sph/src/modules/ComputeEos.cpp
  • src/shamphys/src/SodTube.cpp

Comment thread examples/sph/run_sod.py
cfg.set_artif_viscosity_VaryingCD10(
alpha_min=0.0, alpha_max=1, sigma_decay=0.1, alpha_u=1, beta_AV=2
)
cfg.set_boundary_periodic()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not use periodic boundaries for this single-interface Sod comparison.

The periodic seam places the high-pressure left state next to the low-pressure right state, creating a second Riemann problem absent from SodTube. Its waves will invalidate the analytic comparison. Configure boundaries consistent with the single shock-tube solution instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/sph/run_sod.py` at line 110, Replace the periodic boundary
configuration in the run_sod setup by using boundary conditions appropriate for
a single-interface Sod shock tube, matching the non-periodic behavior expected
by SodTube and avoiding a seam between the left and right states.

Comment thread examples/sph/run_sod.py
Comment on lines +159 to +166
glob_str = f"{dump_folder}sod_*.png"
ani = show_image_sequence(glob_str)

writer = PillowWriter(fps=15, metadata=dict(artist="Me"), bitrate=1800)
ani.save("_to_trash/sod.gif", writer=writer)

if shamrock.sys.world_rank() == 0:
plt.show()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Restrict GIF generation to rank zero.

Every rank reaches this block and writes _to_trash/sod.gif; concurrent writers can corrupt the artifact or fail. Wrap lines 159-166 in the existing world_rank() == 0 condition.

🧰 Tools
🪛 Ruff (0.15.21)

[warning] 162-162: Unnecessary dict() call (rewrite as a literal)

Rewrite as a literal

(C408)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/sph/run_sod.py` around lines 159 - 166, Guard the GIF generation and
display block containing show_image_sequence, PillowWriter, ani.save, and
plt.show with the existing shamrock.sys.world_rank() == 0 condition, so only
rank zero creates and displays the animation while preserving the current
behavior within that rank.

Comment on lines +401 to +423
auto eos_internal = [](Tvec R,
Tscal rho_a,
u32 scount,
auto spos,
auto smass,
Tscal G,
Tscal h_over_r,
Tscal &pressure,
Tscal &soundspeed) {
Tscal mpotential = 0;
for (u32 i = 0; i < scount; i++) {
Tvec s_r = spos[i] - R;
Tscal s_m = smass[i];
Tscal s_r_abs = sycl::length(s_r);
mpotential += G * s_m / s_r_abs;
}

P[item] = P_a;
cs[item] = cs_out;
});
Tscal cs_out = h_over_r * sycl::sqrt(mpotential);
Tscal P_a = EOS::pressure_from_cs(cs_out * cs_out, rho_a);

pressure = P_a;
soundspeed = cs_out;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

FA2014 branch lacks the zero-sink guard present in FA2014Extended.

Unlike SolverEOS_LocallyIsothermalFA2014Extended (Lines 531-534), this branch has no check for an empty sink list. With sink_cnt == 0 the potential loop leaves mpotential = 0, yielding cs_out = 0 and pressure = 0, which is unphysical and can trigger division-by-zero in downstream soundspeed-dependent computations (e.g. timestep control). Mirror the Extended branch's guard here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/shammodels/sph/src/modules/ComputeEos.cpp` around lines 401 - 423, Update
the FA2014 `eos_internal` lambda to handle an empty sink list before calculating
the potential: when `scount == 0`, apply the same fallback behavior as
`SolverEOS_LocallyIsothermalFA2014Extended` and return without producing zero
pressure or soundspeed. Preserve the existing potential and EOS calculations for
non-empty sink lists.

@github-actions

Copy link
Copy Markdown
Contributor

Workflow report

workflow report corresponding to commit 7df87d7
Commiter email is timothee.davidcleris@proton.me
GitHub page artifact URL GitHub page artifact link (can expire)

Pre-commit check report

Pre-commit check: ✅

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check for merge conflicts................................................Passed
check that executables have shebangs.....................................Passed
check that scripts with shebangs are executable..........................Passed
check for added large files..............................................Passed
check for case conflicts.................................................Passed
check for broken symlinks................................................Passed
check yaml...............................................................Passed
detect private key.......................................................Passed
No-tabs checker..........................................................Passed
Tabs remover.............................................................Passed
cmake-format.............................................................Passed
Validate GitHub Workflows................................................Passed
clang-format.............................................................Passed
ruff check...............................................................Passed
ruff format..............................................................Passed
Check doxygen headers....................................................Passed
Check license headers....................................................Passed
Check #pragma once.......................................................Passed
Check SYCL #include......................................................Passed
No ssh in git submodules remote..........................................Passed
No UTF-8 in files (except for authors)...................................Passed

Test pipeline can run.

Clang-tidy diff report


631 warnings generated.
Suppressed 632 warnings (631 in non-user code, 1 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

1225 warnings generated.
Suppressed 1226 warnings (1225 in non-user code, 1 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

Doxygen diff with main

Removed warnings : 50
New warnings : 9
Warnings count : 8058 → 8017 (-0.5%)

Detailed changes :
- src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:36: warning: Member Tscal (typedef) of class shammodels::sph::modules::ComputeEos is not documented.
+ src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:37: warning: Member Tscal (typedef) of class shammodels::sph::modules::ComputeEos is not documented.
- src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:37: warning: Member dim (variable) of class shammodels::sph::modules::ComputeEos is not documented.
- src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:38: warning: Member Kernel (typedef) of class shammodels::sph::modules::ComputeEos is not documented.
+ src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:38: warning: Member dim (variable) of class shammodels::sph::modules::ComputeEos is not documented.
+ src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:39: warning: Member Kernel (typedef) of class shammodels::sph::modules::ComputeEos is not documented.
- src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:40: warning: Member Config (typedef) of class shammodels::sph::modules::ComputeEos is not documented.
+ src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:41: warning: Member Config (typedef) of class shammodels::sph::modules::ComputeEos is not documented.
- src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:41: warning: Member Storage (typedef) of class shammodels::sph::modules::ComputeEos is not documented.
+ src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:42: warning: Member Storage (typedef) of class shammodels::sph::modules::ComputeEos is not documented.
- src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:43: warning: Member context (variable) of class shammodels::sph::modules::ComputeEos is not documented.
+ src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:44: warning: Member context (variable) of class shammodels::sph::modules::ComputeEos is not documented.
- src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:44: warning: Member solver_config (variable) of class shammodels::sph::modules::ComputeEos is not documented.
+ src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:45: warning: Member solver_config (variable) of class shammodels::sph::modules::ComputeEos is not documented.
- src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:45: warning: Member storage (variable) of class shammodels::sph::modules::ComputeEos is not documented.
+ src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:46: warning: Member storage (variable) of class shammodels::sph::modules::ComputeEos is not documented.
- src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:47: warning: Member ComputeEos(ShamrockCtx &context, Config &solver_config, Storage &storage) (function) of class shammodels::sph::modules::ComputeEos is not documented.
+ src/shammodels/sph/include/shammodels/sph/modules/ComputeEos.hpp:48: warning: Member ComputeEos(ShamrockCtx &context, Config &solver_config, Storage &storage) (function) of class shammodels::sph::modules::ComputeEos is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:100: warning: Compound RhoGetterSJ::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:101: warning: Member h (variable) of struct RhoGetterSJ::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:102: warning: Member buf_s_j (variable) of struct RhoGetterSJ::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:103: warning: Member nvar_dust (variable) of struct RhoGetterSJ::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:104: warning: Member pmass (variable) of struct RhoGetterSJ::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:105: warning: Member hfact (variable) of struct RhoGetterSJ::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:107: warning: Member operator()(u32 i) const (function) of struct RhoGetterSJ::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:121: warning: Member get_read_access(sham::EventList &depends_list) (function) of struct RhoGetterSJ is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:128: warning: Member complete_event_state(sycl::event e) (function) of struct RhoGetterSJ is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:31: warning: Compound RhoGetterBase is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:32: warning: Member buf_h (variable) of struct RhoGetterBase is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:33: warning: Member pmass (variable) of struct RhoGetterBase is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:34: warning: Member hfact (variable) of struct RhoGetterBase is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:36: warning: Compound RhoGetterBase::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:37: warning: Member h (variable) of struct RhoGetterBase::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:38: warning: Member pmass (variable) of struct RhoGetterBase::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:39: warning: Member hfact (variable) of struct RhoGetterBase::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:41: warning: Member operator()(u32 i) const (function) of struct RhoGetterBase::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:47: warning: Member get_read_access(sham::EventList &depends_list) (function) of struct RhoGetterBase is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:52: warning: Member complete_event_state(sycl::event e) (function) of struct RhoGetterBase is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:56: warning: Compound RhoGetterMonofluid is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:57: warning: Member buf_h (variable) of struct RhoGetterMonofluid is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:58: warning: Member buf_epsilon (variable) of struct RhoGetterMonofluid is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:59: warning: Member nvar_dust (variable) of struct RhoGetterMonofluid is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:60: warning: Member pmass (variable) of struct RhoGetterMonofluid is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:61: warning: Member hfact (variable) of struct RhoGetterMonofluid is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:63: warning: Compound RhoGetterMonofluid::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:64: warning: Member h (variable) of struct RhoGetterMonofluid::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:65: warning: Member buf_epsilon (variable) of struct RhoGetterMonofluid::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:66: warning: Member nvar_dust (variable) of struct RhoGetterMonofluid::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:67: warning: Member pmass (variable) of struct RhoGetterMonofluid::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:68: warning: Member hfact (variable) of struct RhoGetterMonofluid::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:70: warning: Member operator()(u32 i) const (function) of struct RhoGetterMonofluid::accessed is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:82: warning: Member get_read_access(sham::EventList &depends_list) (function) of struct RhoGetterMonofluid is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:89: warning: Member complete_event_state(sycl::event e) (function) of struct RhoGetterMonofluid is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:93: warning: Compound RhoGetterSJ is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:94: warning: Member buf_h (variable) of struct RhoGetterSJ is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:95: warning: Member buf_s_j (variable) of struct RhoGetterSJ is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:96: warning: Member nvar_dust (variable) of struct RhoGetterSJ is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:97: warning: Member pmass (variable) of struct RhoGetterSJ is not documented.
- src/shammodels/sph/src/modules/ComputeEos.cpp:98: warning: Member hfact (variable) of struct RhoGetterSJ is not documented.

@tdavidcl
tdavidcl merged commit f00dc5f into Shamrock-code:main Jul 21, 2026
166 of 170 checks passed
@tdavidcl
tdavidcl deleted the eos_2_SPH branch July 21, 2026 15:06
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 624 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/shammodels/sph/src/modules/ComputeEos.cpp 0.00% 622 Missing ⚠️
src/shamphys/src/SodTube.cpp 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant