Skip to content

[Examples] dustydisc setup#1868

Open
tdavidcl wants to merge 9 commits into
Shamrock-code:mainfrom
tdavidcl:dustydisc
Open

[Examples] dustydisc setup#1868
tdavidcl wants to merge 9 commits into
Shamrock-code:mainfrom
tdavidcl:dustydisc

Conversation

@tdavidcl

@tdavidcl tdavidcl commented Jun 6, 2026

Copy link
Copy Markdown
Member

No description provided.

@tdavidcl tdavidcl added the draft label Jun 6, 2026
@github-actions

github-actions Bot commented Jun 6, 2026

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

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Workflow report

workflow report corresponding to commit 8cd27ba
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 detailed output

❌ ruff-format

1 file reformatted, 218 files left unchanged

Suggested changes

Detailed changes :
diff --git a/examples/sph/run_dustydisc.py b/examples/sph/run_dustydisc.py
index 946607d6..1c5638cd 100644
--- a/examples/sph/run_dustydisc.py
+++ b/examples/sph/run_dustydisc.py
@@ -500,7 +500,6 @@ if ndust > 0:
             "extra_title": f"[$s_{{grain}}$ = {grain_size_si[jdust]:.2e} m]",
         }
 
-
     dust_slice_epsilon_plot = []
 
     for jdust in range(ndust):
@@ -831,8 +830,6 @@ class radial_profile_plot:
         self.profile_plot.render_all(self.plot_func)
 
 
-
-
 class vert_slices_plots:
     def __init__(self):
         self.profile_plot = AnalysisHelper(
@@ -1043,6 +1040,7 @@ class vert_slices_plots:
     def render_all(self):
         self.profile_plot.render_all(self.plot_func)
 
+
 if ndust > 0:
     rad_plot = radial_profile_plot()
     vert_plot = vert_slices_plots()

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 a new dusty SPH disc simulation example (run_dustydisc.py), centralizes matplotlib styling across examples via a new shamrock.matplotlib module, and adds dust-specific analysis and plotting helpers to the library. The review feedback highlights several critical issues: potential NameError and division-by-zero warnings in run_dustydisc.py when ndust = 0, console flooding from unprotected print statements in MPI parallel runs, and a potential division-by-zero in DensityPlots.py when gas density is zero.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +1167 to +1185
for jdust, p in enumerate(dust_column_density_plot):
p.render_all(
**p.render_args,
)


vertical_density_plot.render_all(
**vertical_density_plot.render_args,
)

for jdust, p in enumerate(dust_slice_density_plot):
p.render_all(
**p.render_args,
)

for jdust, p in enumerate(dust_slice_epsilon_plot):
p.render_all(
**p.render_args,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

These plotting loops will raise a NameError when ndust = 0 (the default value) because dust_column_density_plot, dust_slice_density_plot, and dust_slice_epsilon_plot are only defined inside if ndust > 0: blocks. Wrapping these loops in if ndust > 0: guards prevents this crash.

if ndust > 0:
    for jdust, p in enumerate(dust_column_density_plot):
        p.render_all(
            **p.render_args,
        )


vertical_density_plot.render_all(
    **vertical_density_plot.render_args,
)

if ndust > 0:
    for jdust, p in enumerate(dust_slice_density_plot):
        p.render_all(
            **p.render_args,
        )

    for jdust, p in enumerate(dust_slice_epsilon_plot):
        p.render_all(
            **p.render_args,
        )

Comment on lines +200 to +204
mrn_weight = grain_size ** (4 - mrn_pow)
mrn_weight *= grain_size_si < mrn_cutoff_si
mrn_weight = mrn_weight / np.sum(mrn_weight)

print(f"mrn_weight = {mrn_weight}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

When ndust = 0, grain_size is empty, which causes np.sum(mrn_weight) to be 0.0 and results in a division-by-zero RuntimeWarning. Wrapping this calculation in if ndust > 0: and protecting the print statement for MPI parallel runs prevents this warning and avoids console spam.

Suggested change
mrn_weight = grain_size ** (4 - mrn_pow)
mrn_weight *= grain_size_si < mrn_cutoff_si
mrn_weight = mrn_weight / np.sum(mrn_weight)
print(f"mrn_weight = {mrn_weight}")
if ndust > 0:
mrn_weight = grain_size ** (4 - mrn_pow)
mrn_weight *= grain_size_si < mrn_cutoff_si
mrn_weight = mrn_weight / np.sum(mrn_weight)
if shamrock.sys.world_rank() == 0:
print(f"mrn_weight = {mrn_weight}")
else:
mrn_weight = np.array([])

Comment on lines +213 to +221
epsilon_target = epsilon_base * mrn_weight[j]
print(f"epsilon_target = {epsilon_target} {j}")
s = np.sqrt(rho * epsilon_target)

print(
f"s = {s} {np.isnan(s).any()} epsilon_target = {epsilon_target} mrn_weight = {mrn_weight[j]}, rho = {rho}"
)

return s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

These print statements inside compute_sj_new_j are executed for every patch on every MPI rank during initialization. This can severely flood the console and degrade setup performance. They should be removed.

Suggested change
epsilon_target = epsilon_base * mrn_weight[j]
print(f"epsilon_target = {epsilon_target} {j}")
s = np.sqrt(rho * epsilon_target)
print(
f"s = {s} {np.isnan(s).any()} epsilon_target = {epsilon_target} mrn_weight = {mrn_weight[j]}, rho = {rho}"
)
return s
epsilon_target = epsilon_base * mrn_weight[j]
s = np.sqrt(rho * epsilon_target)
return s

Comment on lines +160 to +179
print(f"grains sizes = {grain_size_si_edges} [m]")
print(f"grains dens = {rho_grains_si_edges} [kg.m^-3]")

grain_size_edges = grain_size_si_edges * codeu.get("m")
rho_grains_edges = codeu.get("kg") * codeu.get("m", power=-3) * np.array(rho_grains_si_edges)

print(f"grains sizes = {grain_size_edges} [code u]")
print(f"grains dens = {rho_grains_edges} [code u]")

grain_size = np.sqrt(grain_size_edges[:-1] * grain_size_edges[1:])
rho_grains = np.sqrt(rho_grains_edges[:-1] * rho_grains_edges[1:])

grain_size_si = np.sqrt(grain_size_si_edges[:-1] * grain_size_si_edges[1:])
rho_grains_si = np.sqrt(rho_grains_si_edges[:-1] * rho_grains_si_edges[1:])

print(f"grains sizes = {grain_size_si} [m]")
print(f"grains dens = {rho_grains_si} [kg.m^-3]")

print(f"grains sizes = {grain_size} [code units]")
print(f"grains dens = {rho_grains} [code units]")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

These print statements are not protected by rank checks, which will cause duplicate output lines to be printed by every MPI process in parallel runs. Wrapping them with if shamrock.sys.world_rank() == 0: ensures clean console output.

if shamrock.sys.world_rank() == 0:
    print(f"grains sizes = {grain_size_si_edges} [m]")
    print(f"grains dens  = {rho_grains_si_edges} [kg.m^-3]")

grain_size_edges = grain_size_si_edges * codeu.get("m")
rho_grains_edges = codeu.get("kg") * codeu.get("m", power=-3) * np.array(rho_grains_si_edges)

if shamrock.sys.world_rank() == 0:
    print(f"grains sizes = {grain_size_edges} [code u]")
    print(f"grains dens  = {rho_grains_edges} [code u]")

grain_size = np.sqrt(grain_size_edges[:-1] * grain_size_edges[1:])
rho_grains = np.sqrt(rho_grains_edges[:-1] * rho_grains_edges[1:])

grain_size_si = np.sqrt(grain_size_si_edges[:-1] * grain_size_si_edges[1:])
rho_grains_si = np.sqrt(rho_grains_si_edges[:-1] * rho_grains_si_edges[1:])

if shamrock.sys.world_rank() == 0:
    print(f"grains sizes = {grain_size_si} [m]")
    print(f"grains dens  = {rho_grains_si} [kg.m^-3]")
    print(f"grains sizes = {grain_size} [code units]")
    print(f"grains dens  = {rho_grains} [code units]")

Comment on lines +57 to +61
tmp = rhod / rho

print(tmp.min(), tmp.max())
print(tmp)
return tmp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The raw division rhod / rho can trigger division-by-zero warnings/errors in regions where density is zero. Using np.divide with a where guard handles this robustly. Additionally, the leftover debug print statements should be removed to keep the library output clean.

Suggested change
tmp = rhod / rho
print(tmp.min(), tmp.max())
print(tmp)
return tmp
tmp = np.divide(rhod, rho, out=np.zeros_like(rhod), where=rho > 0)
return tmp

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant