Skip to content

[Doc] add Toro shock tests examples to sphinx#1646

Open
tdavidcl wants to merge 4 commits intoShamrock-code:mainfrom
tdavidcl:patch-2026-02-14-20-44
Open

[Doc] add Toro shock tests examples to sphinx#1646
tdavidcl wants to merge 4 commits intoShamrock-code:mainfrom
tdavidcl:patch-2026-02-14-20-44

Conversation

@tdavidcl
Copy link
Member

No description provided.

@github-actions
Copy link
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

@gemini-code-assist
Copy link

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 introduces new documentation examples for the shamrock library, specifically demonstrating the RAMSES solver's capabilities in simulating Toro shock tube problems. The addition provides a robust set of tests to compare different numerical schemes, such as various slope limiters and Riemann solvers, and visualize their impact on shock propagation. This enhances the validation and understanding of the solver's performance across different hydrodynamic scenarios.

Highlights

  • New Example Script: A new Python script, run_toro_shocks.py, has been added to the documentation examples.
  • Toro Shock Tube Tests: The script implements 7 different Toro shock tube test cases, providing a comprehensive set of initial conditions for hydrodynamic simulations.
  • Solver Comparison: It allows for the comparison of various slope limiters (none, vanleer, minmod) and Riemann solvers (rusanov, hll, hllc) within the RAMSES solver framework.
  • Visualization: The example includes functionality to generate plots and GIF animations of density, velocity, and pressure profiles over time, aiding in the analysis and understanding of the simulation results.
Changelog
  • doc/sphinx/examples/ramses/run_toro_shocks.py
    • Added new example script for Toro shock tests.
    • Implemented 7 different Toro initial conditions for hydrodynamic simulations.
    • Included functionality to compare various slope limiters and Riemann solvers.
    • Added plotting and GIF animation capabilities for simulation results.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 adds a new example script for running Toro shock tests. The script is well-structured, but there are several opportunities for improvement in terms of code clarity, maintainability, and adherence to Python best practices. I've provided suggestions to refactor if/elif chains into dictionaries, remove unused code, improve efficiency in numerical computations, and streamline repetitive code blocks. These changes will make the example easier to read and maintain.

Comment on lines +93 to +104
if slope_limiter == "none":
cfg.set_slope_lim_none()
elif slope_limiter == "vanleer":
cfg.set_slope_lim_vanleer_f()
elif slope_limiter == "vanleer_std":
cfg.set_slope_lim_vanleer_std()
elif slope_limiter == "vanleer_sym":
cfg.set_slope_lim_vanleer_sym()
elif slope_limiter == "minmod":
cfg.set_slope_lim_minmod()
else:
raise ValueError(f"Invalid slope limiter: {slope_limiter}")

Choose a reason for hiding this comment

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

medium

This if/elif chain for selecting the slope limiter can be refactored to use a dictionary that maps names to methods. This improves readability and makes it easier to add new limiters in the future.

    slope_limiter_map = {
        "none": cfg.set_slope_lim_none,
        "vanleer": cfg.set_slope_lim_vanleer_f,
        "vanleer_std": cfg.set_slope_lim_vanleer_std,
        "vanleer_sym": cfg.set_slope_lim_vanleer_sym,
        "minmod": cfg.set_slope_lim_minmod,
    }
    if slope_limiter in slope_limiter_map:
        slope_limiter_map[slope_limiter]()
    else:
        raise ValueError(f"Invalid slope limiter: {slope_limiter}")

Comment on lines +106 to +113
if riemann_solver == "rusanov":
cfg.set_riemann_solver_rusanov()
elif riemann_solver == "hll":
cfg.set_riemann_solver_hll()
elif riemann_solver == "hllc":
cfg.set_riemann_solver_hllc()
else:
raise ValueError(f"Invalid Riemann solver: {riemann_solver}")

Choose a reason for hiding this comment

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

medium

Similar to the slope limiter selection, this if/elif chain for the Riemann solver can be replaced with a dictionary for better maintainability and readability.

    riemann_solver_map = {
        "rusanov": cfg.set_riemann_solver_rusanov,
        "hll": cfg.set_riemann_solver_hll,
        "hllc": cfg.set_riemann_solver_hllc,
    }
    if riemann_solver in riemann_solver_map:
        riemann_solver_map[riemann_solver]()
    else:
        raise ValueError(f"Invalid Riemann solver: {riemann_solver}")

etot_R = p_R / (gamma - 1) + 0.5 * rho_R * vx_R**2

def rhoetot_map(rmin, rmax):
rho = rho_map(rmin, rmax)

Choose a reason for hiding this comment

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

medium

The variable rho is assigned but never used within the rhoetot_map function. This line should be removed to improve code clarity.

return etot_R

def rhovel_map(rmin, rmax):
rho = rho_map(rmin, rmax)

Choose a reason for hiding this comment

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

medium

The variable rho is assigned but never used within the rhovel_map function. This line should be removed.

Comment on lines +173 to +179
vx = np.array(rhov_vals)[:, 0] / np.array(rho_vals)
P = (np.array(rhoetot_vals) - 0.5 * np.array(rho_vals) * vx**2) * (gamma - 1)
results_dic = {
"rho": np.array(rho_vals),
"vx": np.array(vx),
"P": np.array(P),
}

Choose a reason for hiding this comment

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

medium

To improve efficiency and readability, you can convert the lists to NumPy arrays once at the beginning of the calculations. Also, np.array() is called on variables that are already NumPy arrays, which is redundant.

        rho_vals_np = np.array(rho_vals)
        vx = np.array(rhov_vals)[:, 0] / rho_vals_np
        P = (np.array(rhoetot_vals) - 0.5 * rho_vals_np * vx**2) * (gamma - 1)
        results_dic = {
            "rho": rho_vals_np,
            "vx": vx,
            "P": P,
        }

Comment on lines +204 to +217
for i in range(3):
axes[i].set_xlabel("$x$")
# axes[i].set_yscale("log")
axes[i].grid(True, alpha=0.3)

ax1, ax2, ax3 = axes
ax1.set_xlabel("$x$")
ax1.set_ylabel("$\\rho$")

ax2.set_xlabel("$x$")
ax2.set_ylabel("$v_x$")

ax3.set_xlabel("$x$")
ax3.set_ylabel("$P$")

Choose a reason for hiding this comment

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

medium

The setup for the plot axes can be simplified. Currently, you are setting the x-label multiple times. You can use a single loop to configure all axes, making the code more concise.

    ax1, ax2, ax3 = axes
    y_labels = ["$\\rho$", "$v_x$", "$P$"]
    for ax, y_label in zip(axes, y_labels):
        ax.set_xlabel("$x$")
        ax.set_ylabel(y_label)
        # ax.set_yscale("log")
        ax.grid(True, alpha=0.3)


arr_x = [x[0] for x in positions_plot]

import matplotlib.animation as animation

Choose a reason for hiding this comment

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

medium

According to PEP 8, imports should usually be at the top of the file. Please move import matplotlib.animation as animation to the top of the file with the other imports. This makes the code's dependencies clearer.

Comment on lines 298 to 304
run_and_plot(cases, 1, "minmod_hll")
run_and_plot(cases, 2, "minmod_hll")
run_and_plot(cases, 3, "minmod_hll")
run_and_plot(cases, 4, "minmod_hll")
run_and_plot(cases, 5, "minmod_hll")
run_and_plot(cases, 6, "minmod_hll")
run_and_plot(cases, 7, "minmod_hll")

Choose a reason for hiding this comment

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

medium

The repeated calls to run_and_plot for different test numbers can be simplified by using a loop. This makes the code more concise and easier to modify if the number of tests changes.

for test_number in range(1, 8):
    run_and_plot(cases, test_number, "minmod_hll")

@github-actions
Copy link
Contributor

Workflow report

workflow report corresponding to commit 34dca00
Commiter email is timothee.davidcleris@proton.me

Pre-commit check report

Some failures were detected in base source checks checks.
Check the On PR / Linting / Base source checks (pull_request) job in the tests for more detailled output

❌ ruff-format

1 file reformatted, 203 files left unchanged

Suggested changes

Detailed changes :
diff --git a/doc/sphinx/examples/ramses/run_toro_shocks.py b/doc/sphinx/examples/ramses/run_toro_shocks.py
index 4695888c..f434d4b0 100644
--- a/doc/sphinx/examples/ramses/run_toro_shocks.py
+++ b/doc/sphinx/examples/ramses/run_toro_shocks.py
@@ -315,18 +315,18 @@ def run_and_plot(cases, test_number, case_anim):
 # %%
 
 cases = [
-    #("none", "rusanov"),
-    #("none", "hll"),
-    #("none", "hllc"),
-    #("minmod", "rusanov"),
-    #("minmod", "hll"),
+    # ("none", "rusanov"),
+    # ("none", "hll"),
+    # ("none", "hllc"),
+    # ("minmod", "rusanov"),
+    # ("minmod", "hll"),
     ("minmod", "hllc"),
 ]
 
 cases_no_hllc = [
-    #("none", "rusanov"),
-    #("none", "hll"),
-    #("minmod", "rusanov"),
+    # ("none", "rusanov"),
+    # ("none", "hll"),
+    # ("minmod", "rusanov"),
     ("minmod", "hll"),
 ]
 

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