Skip to content

[SPH] sheared wave setup - #1897

Draft
tdavidcl wants to merge 25 commits into
Shamrock-code:mainfrom
tdavidcl:sheared_wave
Draft

tdavidcl wants to merge 25 commits into
Shamrock-code:mainfrom
tdavidcl:sheared_wave

Conversation

@tdavidcl

Copy link
Copy Markdown
Member

No description provided.

@tdavidcl tdavidcl added the draft label Jun 25, 2026

@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 example script, run_sph_sheared_wave.py, for running an unstratified shearing box simulation in SPH, and updates BCConfig.hpp to parse shear_speed instead of speed from the JSON configuration. The review feedback highlights a large block of redundant, broken procedural code at the end of the example script that should be removed. Additionally, the reviewer suggests scaling the wave phase in vel_func to ensure perfect periodicity across adjusted box boundaries, and enabling the commented-out shearing box boundary conditions and external forces to align with the example's intended purpose.

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 +116 to +266
# %%
# Setup parameters



render_gif = True


import os

# Create the dump directory if it does not exist
if shamrock.sys.world_rank() == 0:
os.makedirs(dump_folder, exist_ok=True)

# %%
# Generate the config & init the scheduler
cfg = model.gen_default_config()
# cfg.set_artif_viscosity_Constant(alpha_u = 1, alpha_AV = 1, beta_AV = 2)
# cfg.set_artif_viscosity_VaryingMM97(alpha_min = 0.1,alpha_max = 1,sigma_decay = 0.1, alpha_u = 1, beta_AV = 2)
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_shearing_periodic((1, 0, 0), (0, 1, 0), shear_speed)
cfg.set_eos_adiabatic(gamma)
cfg.add_ext_force_shearing_box(Omega_0=Omega_0, eta=eta, q=q)
cfg.set_units(shamrock.UnitSystem())
cfg.print_status()
model.set_solver_config(cfg)

model.init_scheduler(int(1e7), 1)

model.resize_simulation_box(bmin, bmax)


# %%
# Add the particles & set fields values
# Note that every field that are not mentioned are set to zero
model.add_cube_fcc_3d(dr, bmin, bmax)

vol_b = (xM - xm) * (yM - ym) * (zM - zm)

totmass = rho * vol_b
# print("Total mass :", totmass)

pmass = model.total_mass_to_part_mass(totmass)

model.set_value_in_a_box("uint", "f64", 1, bmin, bmax)
# model.set_value_in_a_box("vxyz","f64_3", (-10,0,0) , bmin,bmax)

pen_sz = 0.1

mm = 1
MM = 0


def vel_func(r):
global mm, MM
x, y, z = r

s = (x - (xM + xm) / 2) / (xM - xm)
vel = (shear_speed) * s

mm = min(mm, vel)
MM = max(MM, vel)

return (0, vel, 0.0)
# return (1,0,0)


model.set_field_value_lambda_f64_3("vxyz", vel_func)
# print("Current part mass :", pmass)
model.set_particle_mass(pmass)


tot_u = pmass * model.get_sum("uint", "f64")
# print("total u :",tot_u)

print(f"v_shear = {shear_speed} | dv = {MM - mm}")


model.set_cfl_cour(0.3)
model.set_cfl_force(0.25)

# %%
# Perform the plot

from math import exp

import matplotlib.pyplot as plt
import numpy as np


def plot(iplot):
dic = ctx.collect_data()
fig, axs = plt.subplots(2, 1, figsize=(5, 8), sharex=True)
fig.suptitle("t = {:.2f}".format(model.get_time()))
axs[0].scatter(dic["xyz"][:, 0], dic["xyz"][:, 1], s=1)
axs[1].scatter(dic["xyz"][:, 0], dic["vxyz"][:, 1], s=1)

axs[0].set_ylabel("y")
axs[1].set_ylabel("vy")
axs[1].set_xlabel("x")

axs[0].set_xlim(xm - 0.1, xM + 0.1)
axs[0].set_ylim(ym - 0.1, yM + 0.1)

axs[1].set_xlim(xm - 0.1, xM + 0.1)
axs[1].set_ylim(shear_speed * 0.7, -shear_speed * 0.7)

plt.tight_layout()
plt.savefig(os.path.join(dump_folder, f"{sim_name}_{iplot:04}.png"))
plt.close(fig)


# %%
# Performing the timestep loop
model.timestep()

dt_stop = 0.02
for i in range(20):
t_target = i * dt_stop
# skip if the model is already past the target
if model.get_time() > t_target:
continue

model.evolve_until(i * dt_stop)

# Dump name is "dump_xxxx.sham" where xxxx is the timestep
model.do_vtk_dump(os.path.join(dump_folder, f"{sim_name}_{i:04}.vtk"), True)
plot(i)

####################################################
# Convert PNG sequence to Image sequence in mpl
####################################################

import matplotlib.animation as animation
from shamrock.utils.plot import show_image_sequence

# If the animation is not returned only a static image will be shown in the doc
glob_str = os.path.join(dump_folder, f"{sim_name}_*.png")
ani = show_image_sequence(glob_str, render_gif=render_gif)

if render_gif and shamrock.sys.world_rank() == 0:
# To save the animation using Pillow as a gif
# writer = animation.PillowWriter(fps=15,
# metadata=dict(artist='Me'),
# bitrate=1800)
# ani.save('scatter.gif', writer=writer)

# Show the animation
plt.show()

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

This entire block of procedural code at the bottom of the file appears to be a redundant/leftover version of the simulation setup. It is completely broken and will raise multiple NameErrors if executed because:

  1. Variables like shear_speed, gamma, Omega_0, eta, q, bmin, bmax, dr, rho, xm, xM, ym, yM, zm, zM are defined as class attributes of Simulation and are not available in the global scope.
  2. sim_name is used but never defined anywhere in the script.

Since the simulation is already successfully configured and run using the Simulation class on lines 35-114, this entire section (lines 116-266) should be removed. If you want to keep the plotting or animation functionality, it should be refactored as a callback method inside the Simulation class.

Comment on lines +64 to +70
def vel_func(self,r):
x, y, z = r

s = (x - (self.xM + self.xm) / 2) / (self.xM - self.xm)
vel = (self.shear_speed) * s

return (self.amplitude*np.sin(2.0*np.pi*(y+4*z)), vel, 0.0)

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 wave phase in vel_func is currently hardcoded as y + 4*z. Since the box boundaries are adjusted by get_ideal_hcp_box (which can slightly modify the box size to fit the HCP lattice), the actual box lengths in $y$ and $z$ may not be exactly $1.0$. This can lead to a wave that is not perfectly periodic, causing discontinuities at the boundaries.

To ensure perfect periodicity, scale the wave phase using the actual box dimensions and the wave parameters self.ny and self.nz.

Suggested change
def vel_func(self,r):
x, y, z = r
s = (x - (self.xM + self.xm) / 2) / (self.xM - self.xm)
vel = (self.shear_speed) * s
return (self.amplitude*np.sin(2.0*np.pi*(y+4*z)), vel, 0.0)
def vel_func(self, r):
x, y, z = r
s = (x - (self.xM + self.xm) / 2) / (self.xM - self.xm)
vel = self.shear_speed * s
phase = self.ny * (y - self.ym) / (self.yM - self.ym) + self.nz * (z - self.zm) / (self.zM - self.zm)
return (self.amplitude * np.sin(2.0 * np.pi * phase), vel, 0.0)

Comment on lines +88 to +91
#cfg.set_boundary_shearing_periodic((1, 0, 0), (0, 1, 0), self.shear_speed)
cfg.set_boundary_periodic()
cfg.set_eos_adiabatic(self.gamma)
#cfg.add_ext_force_shearing_box(Omega_0=self.Omega_0, eta=self.eta, q=self.q)

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 shearing box boundary conditions and external forces are currently commented out, and standard periodic boundaries are used instead. Since this example is intended to demonstrate a shearing box simulation (as described in the module docstring), these configurations should be enabled. If you want to run a standard periodic wave, consider creating a separate example or parameterizing this script.

@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 commented Aug 20, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

Copy link
Copy Markdown
Contributor

Workflow report

workflow report corresponding to commit d696f99
Commiter email is 37929162+mergify[bot]@users.noreply.github.com
You are using github private e-mail. This prevent proper tracing of who contributed what, please disable it (see Keep my email addresses private).

Light CI is enabled (the default for pull requests). This will only run the basic tests and not the full tests.
Full CI runs if the full-ci label is set, or automatically on Mergify merge-queue branches (mergify/merge-queue/*).
The merge gate job "on PR / all" is skipped in this case. Queue entry uses "on PR / all_light"; full CI runs in the merge queue.

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, 330 files left unchanged

❌ ruff-check

�[1m�[91mF821�[0m�[1m Undefined name `shear_speed`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:139:58
    �[1m�[94m|�[0m
�[1m�[94m137�[0m �[1m�[94m|�[0m     alpha_min=0.0, alpha_max=1, sigma_decay=0.1, alpha_u=1, beta_AV=2
�[1m�[94m138�[0m �[1m�[94m|�[0m )
�[1m�[94m139�[0m �[1m�[94m|�[0m cfg.set_boundary_shearing_periodic((1, 0, 0), (0, 1, 0), shear_speed)
    �[1m�[94m|�[0m                                                          �[1m�[91m^^^^^^^^^^^�[0m
�[1m�[94m140�[0m �[1m�[94m|�[0m cfg.set_eos_adiabatic(gamma)
�[1m�[94m141�[0m �[1m�[94m|�[0m cfg.add_ext_force_shearing_box(Omega_0=Omega_0, eta=eta, q=q)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `gamma`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:140:23
    �[1m�[94m|�[0m
�[1m�[94m138�[0m �[1m�[94m|�[0m )
�[1m�[94m139�[0m �[1m�[94m|�[0m cfg.set_boundary_shearing_periodic((1, 0, 0), (0, 1, 0), shear_speed)
�[1m�[94m140�[0m �[1m�[94m|�[0m cfg.set_eos_adiabatic(gamma)
    �[1m�[94m|�[0m                       �[1m�[91m^^^^^�[0m
�[1m�[94m141�[0m �[1m�[94m|�[0m cfg.add_ext_force_shearing_box(Omega_0=Omega_0, eta=eta, q=q)
�[1m�[94m142�[0m �[1m�[94m|�[0m cfg.set_units(shamrock.UnitSystem())
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `Omega_0`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:141:40
    �[1m�[94m|�[0m
�[1m�[94m139�[0m �[1m�[94m|�[0m cfg.set_boundary_shearing_periodic((1, 0, 0), (0, 1, 0), shear_speed)
�[1m�[94m140�[0m �[1m�[94m|�[0m cfg.set_eos_adiabatic(gamma)
�[1m�[94m141�[0m �[1m�[94m|�[0m cfg.add_ext_force_shearing_box(Omega_0=Omega_0, eta=eta, q=q)
    �[1m�[94m|�[0m                                        �[1m�[91m^^^^^^^�[0m
�[1m�[94m142�[0m �[1m�[94m|�[0m cfg.set_units(shamrock.UnitSystem())
�[1m�[94m143�[0m �[1m�[94m|�[0m cfg.print_status()
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `eta`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:141:53
    �[1m�[94m|�[0m
�[1m�[94m139�[0m �[1m�[94m|�[0m cfg.set_boundary_shearing_periodic((1, 0, 0), (0, 1, 0), shear_speed)
�[1m�[94m140�[0m �[1m�[94m|�[0m cfg.set_eos_adiabatic(gamma)
�[1m�[94m141�[0m �[1m�[94m|�[0m cfg.add_ext_force_shearing_box(Omega_0=Omega_0, eta=eta, q=q)
    �[1m�[94m|�[0m                                                     �[1m�[91m^^^�[0m
�[1m�[94m142�[0m �[1m�[94m|�[0m cfg.set_units(shamrock.UnitSystem())
�[1m�[94m143�[0m �[1m�[94m|�[0m cfg.print_status()
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `q`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:141:60
    �[1m�[94m|�[0m
�[1m�[94m139�[0m �[1m�[94m|�[0m cfg.set_boundary_shearing_periodic((1, 0, 0), (0, 1, 0), shear_speed)
�[1m�[94m140�[0m �[1m�[94m|�[0m cfg.set_eos_adiabatic(gamma)
�[1m�[94m141�[0m �[1m�[94m|�[0m cfg.add_ext_force_shearing_box(Omega_0=Omega_0, eta=eta, q=q)
    �[1m�[94m|�[0m                                                            �[1m�[91m^�[0m
�[1m�[94m142�[0m �[1m�[94m|�[0m cfg.set_units(shamrock.UnitSystem())
�[1m�[94m143�[0m �[1m�[94m|�[0m cfg.print_status()
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `bmin`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:148:29
    �[1m�[94m|�[0m
�[1m�[94m146�[0m �[1m�[94m|�[0m model.init_scheduler(int(1e7), 1)
�[1m�[94m147�[0m �[1m�[94m|�[0m
�[1m�[94m148�[0m �[1m�[94m|�[0m model.resize_simulation_box(bmin, bmax)
    �[1m�[94m|�[0m                             �[1m�[91m^^^^�[0m

�[1m�[91mF821�[0m�[1m Undefined name `bmax`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:148:35
    �[1m�[94m|�[0m
�[1m�[94m146�[0m �[1m�[94m|�[0m model.init_scheduler(int(1e7), 1)
�[1m�[94m147�[0m �[1m�[94m|�[0m
�[1m�[94m148�[0m �[1m�[94m|�[0m model.resize_simulation_box(bmin, bmax)
    �[1m�[94m|�[0m                                   �[1m�[91m^^^^�[0m

�[1m�[91mF821�[0m�[1m Undefined name `dr`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:154:23
    �[1m�[94m|�[0m
�[1m�[94m152�[0m �[1m�[94m|�[0m # Add the particles & set fields values
�[1m�[94m153�[0m �[1m�[94m|�[0m # Note that every field that are not mentioned are set to zero
�[1m�[94m154�[0m �[1m�[94m|�[0m model.add_cube_fcc_3d(dr, bmin, bmax)
    �[1m�[94m|�[0m                       �[1m�[91m^^�[0m
�[1m�[94m155�[0m �[1m�[94m|�[0m
�[1m�[94m156�[0m �[1m�[94m|�[0m vol_b = (xM - xm) * (yM - ym) * (zM - zm)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `bmin`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:154:27
    �[1m�[94m|�[0m
�[1m�[94m152�[0m �[1m�[94m|�[0m # Add the particles & set fields values
�[1m�[94m153�[0m �[1m�[94m|�[0m # Note that every field that are not mentioned are set to zero
�[1m�[94m154�[0m �[1m�[94m|�[0m model.add_cube_fcc_3d(dr, bmin, bmax)
    �[1m�[94m|�[0m                           �[1m�[91m^^^^�[0m
�[1m�[94m155�[0m �[1m�[94m|�[0m
�[1m�[94m156�[0m �[1m�[94m|�[0m vol_b = (xM - xm) * (yM - ym) * (zM - zm)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `bmax`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:154:33
    �[1m�[94m|�[0m
�[1m�[94m152�[0m �[1m�[94m|�[0m # Add the particles & set fields values
�[1m�[94m153�[0m �[1m�[94m|�[0m # Note that every field that are not mentioned are set to zero
�[1m�[94m154�[0m �[1m�[94m|�[0m model.add_cube_fcc_3d(dr, bmin, bmax)
    �[1m�[94m|�[0m                                 �[1m�[91m^^^^�[0m
�[1m�[94m155�[0m �[1m�[94m|�[0m
�[1m�[94m156�[0m �[1m�[94m|�[0m vol_b = (xM - xm) * (yM - ym) * (zM - zm)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `xM`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:156:10
    �[1m�[94m|�[0m
�[1m�[94m154�[0m �[1m�[94m|�[0m model.add_cube_fcc_3d(dr, bmin, bmax)
�[1m�[94m155�[0m �[1m�[94m|�[0m
�[1m�[94m156�[0m �[1m�[94m|�[0m vol_b = (xM - xm) * (yM - ym) * (zM - zm)
    �[1m�[94m|�[0m          �[1m�[91m^^�[0m
�[1m�[94m157�[0m �[1m�[94m|�[0m
�[1m�[94m158�[0m �[1m�[94m|�[0m totmass = rho * vol_b
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `xm`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:156:15
    �[1m�[94m|�[0m
�[1m�[94m154�[0m �[1m�[94m|�[0m model.add_cube_fcc_3d(dr, bmin, bmax)
�[1m�[94m155�[0m �[1m�[94m|�[0m
�[1m�[94m156�[0m �[1m�[94m|�[0m vol_b = (xM - xm) * (yM - ym) * (zM - zm)
    �[1m�[94m|�[0m               �[1m�[91m^^�[0m
�[1m�[94m157�[0m �[1m�[94m|�[0m
�[1m�[94m158�[0m �[1m�[94m|�[0m totmass = rho * vol_b
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `yM`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:156:22
    �[1m�[94m|�[0m
�[1m�[94m154�[0m �[1m�[94m|�[0m model.add_cube_fcc_3d(dr, bmin, bmax)
�[1m�[94m155�[0m �[1m�[94m|�[0m
�[1m�[94m156�[0m �[1m�[94m|�[0m vol_b = (xM - xm) * (yM - ym) * (zM - zm)
    �[1m�[94m|�[0m                      �[1m�[91m^^�[0m
�[1m�[94m157�[0m �[1m�[94m|�[0m
�[1m�[94m158�[0m �[1m�[94m|�[0m totmass = rho * vol_b
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `ym`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:156:27
    �[1m�[94m|�[0m
�[1m�[94m154�[0m �[1m�[94m|�[0m model.add_cube_fcc_3d(dr, bmin, bmax)
�[1m�[94m155�[0m �[1m�[94m|�[0m
�[1m�[94m156�[0m �[1m�[94m|�[0m vol_b = (xM - xm) * (yM - ym) * (zM - zm)
    �[1m�[94m|�[0m                           �[1m�[91m^^�[0m
�[1m�[94m157�[0m �[1m�[94m|�[0m
�[1m�[94m158�[0m �[1m�[94m|�[0m totmass = rho * vol_b
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `zM`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:156:34
    �[1m�[94m|�[0m
�[1m�[94m154�[0m �[1m�[94m|�[0m model.add_cube_fcc_3d(dr, bmin, bmax)
�[1m�[94m155�[0m �[1m�[94m|�[0m
�[1m�[94m156�[0m �[1m�[94m|�[0m vol_b = (xM - xm) * (yM - ym) * (zM - zm)
    �[1m�[94m|�[0m                                  �[1m�[91m^^�[0m
�[1m�[94m157�[0m �[1m�[94m|�[0m
�[1m�[94m158�[0m �[1m�[94m|�[0m totmass = rho * vol_b
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `zm`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:156:39
    �[1m�[94m|�[0m
�[1m�[94m154�[0m �[1m�[94m|�[0m model.add_cube_fcc_3d(dr, bmin, bmax)
�[1m�[94m155�[0m �[1m�[94m|�[0m
�[1m�[94m156�[0m �[1m�[94m|�[0m vol_b = (xM - xm) * (yM - ym) * (zM - zm)
    �[1m�[94m|�[0m                                       �[1m�[91m^^�[0m
�[1m�[94m157�[0m �[1m�[94m|�[0m
�[1m�[94m158�[0m �[1m�[94m|�[0m totmass = rho * vol_b
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `rho`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:158:11
    �[1m�[94m|�[0m
�[1m�[94m156�[0m �[1m�[94m|�[0m vol_b = (xM - xm) * (yM - ym) * (zM - zm)
�[1m�[94m157�[0m �[1m�[94m|�[0m
�[1m�[94m158�[0m �[1m�[94m|�[0m totmass = rho * vol_b
    �[1m�[94m|�[0m           �[1m�[91m^^^�[0m
�[1m�[94m159�[0m �[1m�[94m|�[0m # print("Total mass :", totmass)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `bmin`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:163:44
    �[1m�[94m|�[0m
�[1m�[94m161�[0m �[1m�[94m|�[0m pmass = model.total_mass_to_part_mass(totmass)
�[1m�[94m162�[0m �[1m�[94m|�[0m
�[1m�[94m163�[0m �[1m�[94m|�[0m model.set_value_in_a_box("uint", "f64", 1, bmin, bmax)
    �[1m�[94m|�[0m                                            �[1m�[91m^^^^�[0m
�[1m�[94m164�[0m �[1m�[94m|�[0m # model.set_value_in_a_box("vxyz","f64_3", (-10,0,0) , bmin,bmax)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `bmax`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:163:50
    �[1m�[94m|�[0m
�[1m�[94m161�[0m �[1m�[94m|�[0m pmass = model.total_mass_to_part_mass(totmass)
�[1m�[94m162�[0m �[1m�[94m|�[0m
�[1m�[94m163�[0m �[1m�[94m|�[0m model.set_value_in_a_box("uint", "f64", 1, bmin, bmax)
    �[1m�[94m|�[0m                                                  �[1m�[91m^^^^�[0m
�[1m�[94m164�[0m �[1m�[94m|�[0m # model.set_value_in_a_box("vxyz","f64_3", (-10,0,0) , bmin,bmax)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `xM`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:176:15
    �[1m�[94m|�[0m
�[1m�[94m174�[0m �[1m�[94m|�[0m     x, y, z = r
�[1m�[94m175�[0m �[1m�[94m|�[0m
�[1m�[94m176�[0m �[1m�[94m|�[0m     s = (x - (xM + xm) / 2) / (xM - xm)
    �[1m�[94m|�[0m               �[1m�[91m^^�[0m
�[1m�[94m177�[0m �[1m�[94m|�[0m     vel = (shear_speed) * s
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `xm`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:176:20
    �[1m�[94m|�[0m
�[1m�[94m174�[0m �[1m�[94m|�[0m     x, y, z = r
�[1m�[94m175�[0m �[1m�[94m|�[0m
�[1m�[94m176�[0m �[1m�[94m|�[0m     s = (x - (xM + xm) / 2) / (xM - xm)
    �[1m�[94m|�[0m                    �[1m�[91m^^�[0m
�[1m�[94m177�[0m �[1m�[94m|�[0m     vel = (shear_speed) * s
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `xM`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:176:32
    �[1m�[94m|�[0m
�[1m�[94m174�[0m �[1m�[94m|�[0m     x, y, z = r
�[1m�[94m175�[0m �[1m�[94m|�[0m
�[1m�[94m176�[0m �[1m�[94m|�[0m     s = (x - (xM + xm) / 2) / (xM - xm)
    �[1m�[94m|�[0m                                �[1m�[91m^^�[0m
�[1m�[94m177�[0m �[1m�[94m|�[0m     vel = (shear_speed) * s
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `xm`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:176:37
    �[1m�[94m|�[0m
�[1m�[94m174�[0m �[1m�[94m|�[0m     x, y, z = r
�[1m�[94m175�[0m �[1m�[94m|�[0m
�[1m�[94m176�[0m �[1m�[94m|�[0m     s = (x - (xM + xm) / 2) / (xM - xm)
    �[1m�[94m|�[0m                                     �[1m�[91m^^�[0m
�[1m�[94m177�[0m �[1m�[94m|�[0m     vel = (shear_speed) * s
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `shear_speed`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:177:12
    �[1m�[94m|�[0m
�[1m�[94m176�[0m �[1m�[94m|�[0m     s = (x - (xM + xm) / 2) / (xM - xm)
�[1m�[94m177�[0m �[1m�[94m|�[0m     vel = (shear_speed) * s
    �[1m�[94m|�[0m            �[1m�[91m^^^^^^^^^^^�[0m
�[1m�[94m178�[0m �[1m�[94m|�[0m
�[1m�[94m179�[0m �[1m�[94m|�[0m     mm = min(mm, vel)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `shear_speed`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:194:20
    �[1m�[94m|�[0m
�[1m�[94m192�[0m �[1m�[94m|�[0m # print("total u :",tot_u)
�[1m�[94m193�[0m �[1m�[94m|�[0m
�[1m�[94m194�[0m �[1m�[94m|�[0m print(f"v_shear = {shear_speed} | dv = {MM - mm}")
    �[1m�[94m|�[0m                    �[1m�[91m^^^^^^^^^^^�[0m

�[1m�[91mF821�[0m�[1m Undefined name `xm`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:219:21
    �[1m�[94m|�[0m
�[1m�[94m217�[0m �[1m�[94m|�[0m     axs[1].set_xlabel("x")
�[1m�[94m218�[0m �[1m�[94m|�[0m
�[1m�[94m219�[0m �[1m�[94m|�[0m     axs[0].set_xlim(xm - 0.1, xM + 0.1)
    �[1m�[94m|�[0m                     �[1m�[91m^^�[0m
�[1m�[94m220�[0m �[1m�[94m|�[0m     axs[0].set_ylim(ym - 0.1, yM + 0.1)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `xM`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:219:31
    �[1m�[94m|�[0m
�[1m�[94m217�[0m �[1m�[94m|�[0m     axs[1].set_xlabel("x")
�[1m�[94m218�[0m �[1m�[94m|�[0m
�[1m�[94m219�[0m �[1m�[94m|�[0m     axs[0].set_xlim(xm - 0.1, xM + 0.1)
    �[1m�[94m|�[0m                               �[1m�[91m^^�[0m
�[1m�[94m220�[0m �[1m�[94m|�[0m     axs[0].set_ylim(ym - 0.1, yM + 0.1)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `ym`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:220:21
    �[1m�[94m|�[0m
�[1m�[94m219�[0m �[1m�[94m|�[0m     axs[0].set_xlim(xm - 0.1, xM + 0.1)
�[1m�[94m220�[0m �[1m�[94m|�[0m     axs[0].set_ylim(ym - 0.1, yM + 0.1)
    �[1m�[94m|�[0m                     �[1m�[91m^^�[0m
�[1m�[94m221�[0m �[1m�[94m|�[0m
�[1m�[94m222�[0m �[1m�[94m|�[0m     axs[1].set_xlim(xm - 0.1, xM + 0.1)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `yM`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:220:31
    �[1m�[94m|�[0m
�[1m�[94m219�[0m �[1m�[94m|�[0m     axs[0].set_xlim(xm - 0.1, xM + 0.1)
�[1m�[94m220�[0m �[1m�[94m|�[0m     axs[0].set_ylim(ym - 0.1, yM + 0.1)
    �[1m�[94m|�[0m                               �[1m�[91m^^�[0m
�[1m�[94m221�[0m �[1m�[94m|�[0m
�[1m�[94m222�[0m �[1m�[94m|�[0m     axs[1].set_xlim(xm - 0.1, xM + 0.1)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `xm`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:222:21
    �[1m�[94m|�[0m
�[1m�[94m220�[0m �[1m�[94m|�[0m     axs[0].set_ylim(ym - 0.1, yM + 0.1)
�[1m�[94m221�[0m �[1m�[94m|�[0m
�[1m�[94m222�[0m �[1m�[94m|�[0m     axs[1].set_xlim(xm - 0.1, xM + 0.1)
    �[1m�[94m|�[0m                     �[1m�[91m^^�[0m
�[1m�[94m223�[0m �[1m�[94m|�[0m     axs[1].set_ylim(shear_speed * 0.7, -shear_speed * 0.7)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `xM`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:222:31
    �[1m�[94m|�[0m
�[1m�[94m220�[0m �[1m�[94m|�[0m     axs[0].set_ylim(ym - 0.1, yM + 0.1)
�[1m�[94m221�[0m �[1m�[94m|�[0m
�[1m�[94m222�[0m �[1m�[94m|�[0m     axs[1].set_xlim(xm - 0.1, xM + 0.1)
    �[1m�[94m|�[0m                               �[1m�[91m^^�[0m
�[1m�[94m223�[0m �[1m�[94m|�[0m     axs[1].set_ylim(shear_speed * 0.7, -shear_speed * 0.7)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `shear_speed`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:223:21
    �[1m�[94m|�[0m
�[1m�[94m222�[0m �[1m�[94m|�[0m     axs[1].set_xlim(xm - 0.1, xM + 0.1)
�[1m�[94m223�[0m �[1m�[94m|�[0m     axs[1].set_ylim(shear_speed * 0.7, -shear_speed * 0.7)
    �[1m�[94m|�[0m                     �[1m�[91m^^^^^^^^^^^�[0m
�[1m�[94m224�[0m �[1m�[94m|�[0m
�[1m�[94m225�[0m �[1m�[94m|�[0m     plt.tight_layout()
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `shear_speed`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:223:41
    �[1m�[94m|�[0m
�[1m�[94m222�[0m �[1m�[94m|�[0m     axs[1].set_xlim(xm - 0.1, xM + 0.1)
�[1m�[94m223�[0m �[1m�[94m|�[0m     axs[1].set_ylim(shear_speed * 0.7, -shear_speed * 0.7)
    �[1m�[94m|�[0m                                         �[1m�[91m^^^^^^^^^^^�[0m
�[1m�[94m224�[0m �[1m�[94m|�[0m
�[1m�[94m225�[0m �[1m�[94m|�[0m     plt.tight_layout()
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `sim_name`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:226:46
    �[1m�[94m|�[0m
�[1m�[94m225�[0m �[1m�[94m|�[0m     plt.tight_layout()
�[1m�[94m226�[0m �[1m�[94m|�[0m     plt.savefig(os.path.join(dump_folder, f"{sim_name}_{iplot:04}.png"))
    �[1m�[94m|�[0m                                              �[1m�[91m^^^^^^^^�[0m
�[1m�[94m227�[0m �[1m�[94m|�[0m     plt.close(fig)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `sim_name`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:244:52
    �[1m�[94m|�[0m
�[1m�[94m243�[0m �[1m�[94m|�[0m     # Dump name is "dump_xxxx.sham" where xxxx is the timestep
�[1m�[94m244�[0m �[1m�[94m|�[0m     model.do_vtk_dump(os.path.join(dump_folder, f"{sim_name}_{i:04}.vtk"), True)
    �[1m�[94m|�[0m                                                    �[1m�[91m^^^^^^^^�[0m
�[1m�[94m245�[0m �[1m�[94m|�[0m     plot(i)
    �[1m�[94m|�[0m

�[1m�[91mF821�[0m�[1m Undefined name `sim_name`�[0m
   �[1m�[94m--> �[0mexamples/sph/run_sph_sheared_wave.py:255:41
    �[1m�[94m|�[0m
�[1m�[94m254�[0m �[1m�[94m|�[0m # If the animation is not returned only a static image will be shown in the doc
�[1m�[94m255�[0m �[1m�[94m|�[0m glob_str = os.path.join(dump_folder, f"{sim_name}_*.png")
    �[1m�[94m|�[0m                                         �[1m�[91m^^^^^^^^�[0m
�[1m�[94m256�[0m �[1m�[94m|�[0m ani = show_image_sequence(glob_str, render_gif=render_gif)
    �[1m�[94m|�[0m

Found 40 errors (4 fixed, 36 remaining).

Suggested changes

Detailed changes :
diff --git a/examples/sph/run_sph_sheared_wave.py b/examples/sph/run_sph_sheared_wave.py
index f8fdc9d2..fd125410 100644
--- a/examples/sph/run_sph_sheared_wave.py
+++ b/examples/sph/run_sph_sheared_wave.py
@@ -7,9 +7,10 @@ This simple example shows how to run an unstratified shearing box simulation
 
 # sphinx_gallery_multi_image = "single"
 
-import shamrock
-from shamrock.utils.SimulationRunner import SimulationRunner, callback, simulation_setup
 import numpy as np
+from shamrock.utils.SimulationRunner import SimulationRunner, callback, simulation_setup
+
+import shamrock
 
 # If we use the shamrock executable to run this script instead of the python interpreter,
 # we should not initialize the system as the shamrock executable needs to handle specific MPI logic
@@ -32,9 +33,10 @@ model = shamrock.get_Model_SPH(context=ctx, vector_type="f64_3", sph_kernel="M4"
 
 dump_folder = "_to_trash/sph_sheared_wave"
 
+
 class Simulation(SimulationRunner):
     # Use the global vars defined at the top of the file
-    t_end = 15.
+    t_end = 15.0
     dump_prefix = dump_folder + "/" + "dump"
 
     # simulation parameters
@@ -56,18 +58,18 @@ class Simulation(SimulationRunner):
     q = 3.0 / 2.0
 
     # wave parameters
-    nx,ny,nz = 0, 1, 4
+    nx, ny, nz = 0, 1, 4
     amplitude = 1e-6
 
     shear_speed = -q * Omega_0 * (xM - xm)
 
-    def vel_func(self,r):
+    def vel_func(self, r):
         x, y, z = r
 
         s = (x - (self.xM + self.xm) / 2) / (self.xM - self.xm)
         vel = (self.shear_speed) * s
 
-        return (self.amplitude*np.sin(2.0*np.pi*(y+4*z)), vel, 0.0)
+        return (self.amplitude * np.sin(2.0 * np.pi * (y + 4 * z)), vel, 0.0)
 
     @callback(walltime_interval=30.0)  # Checkpoint the simulation every 30 seconds
     def checkpoint(self, icheckpoint):
@@ -85,10 +87,10 @@ class Simulation(SimulationRunner):
         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_shearing_periodic((1, 0, 0), (0, 1, 0), self.shear_speed)
+        # cfg.set_boundary_shearing_periodic((1, 0, 0), (0, 1, 0), self.shear_speed)
         cfg.set_boundary_periodic()
         cfg.set_eos_adiabatic(self.gamma)
-        #cfg.add_ext_force_shearing_box(Omega_0=self.Omega_0, eta=self.eta, q=self.q)
+        # cfg.add_ext_force_shearing_box(Omega_0=self.Omega_0, eta=self.eta, q=self.q)
         cfg.set_units(shamrock.UnitSystem())
         cfg.print_status()
         model.set_solver_config(cfg)
@@ -117,7 +119,6 @@ sim.run()
 # Setup parameters
 
 
-
 render_gif = True
 
 
@@ -202,13 +203,12 @@ model.set_cfl_force(0.25)
 from math import exp
 
 import matplotlib.pyplot as plt
-import numpy as np
 
 
 def plot(iplot):
     dic = ctx.collect_data()
     fig, axs = plt.subplots(2, 1, figsize=(5, 8), sharex=True)
-    fig.suptitle("t = {:.2f}".format(model.get_time()))
+    fig.suptitle(f"t = {model.get_time():.2f}")
     axs[0].scatter(dic["xyz"][:, 0], dic["xyz"][:, 1], s=1)
     axs[1].scatter(dic["xyz"][:, 0], dic["vxyz"][:, 1], s=1)
 
@@ -248,7 +248,7 @@ for i in range(20):
 # Convert PNG sequence to Image sequence in mpl
 ####################################################
 
-import matplotlib.animation as animation
+from matplotlib import animation
 from shamrock.utils.plot import show_image_sequence
 
 # If the animation is not returned only a static image will be shown in the doc

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