Using Shamrock SPH rendering module#

This example demonstrates how to use the Shamrock SPH rendering module to render the density field or the velocity field of a SPH simulation.

The test simulation to showcase the rendering module

13 import glob
14 import json
15 import os  # for makedirs
16
17 import matplotlib
18 import matplotlib.pyplot as plt
19 import numpy as np
20
21 import shamrock
22 from shamrock import NeighCacheStrategy
23
24 # If we use the shamrock executable to run this script instead of the python interpreter,
25 # we should not initialize the system as the shamrock executable needs to handle specific MPI logic
26 if not shamrock.sys.is_initialized():
27     shamrock.change_loglevel(1)
28     shamrock.sys.init("0:0")

Use shamrock documentation style for matplotlib

33 shamrock.matplotlib.set_shamrock_mpl_style()

Setup units

39 si = shamrock.UnitSystem()
40 sicte = shamrock.Constants(si)
41 codeu = shamrock.UnitSystem(
42     unit_time=sicte.second(),
43     unit_length=sicte.au(),
44     unit_mass=sicte.sol_mass(),
45 )
46 ucte = shamrock.Constants(codeu)
47 G = ucte.G()
48 c = ucte.c()

List parameters

 53 # Resolution
 54 Npart = 100000
 55
 56 # Domain decomposition parameters
 57 scheduler_split_val = int(1.0e7)  # split patches with more than 1e7 particles
 58 scheduler_merge_val = scheduler_split_val // 16
 59
 60 # Disc parameter
 61 center_mass = 1e6  # [sol mass]
 62 disc_mass = 0.001  # [sol mass]
 63 Rg = G * center_mass / (c * c)  # [au]
 64 rin = 4.0 * Rg  # [au]
 65 rout = 10 * rin  # [au]
 66 r0 = rin  # [au]
 67
 68 H_r_0 = 0.05
 69 q = 0.75
 70 p = 3.0 / 2.0
 71
 72 Tin = 2 * np.pi * np.sqrt(rin * rin * rin / (G * center_mass))
 73 if shamrock.sys.world_rank() == 0:
 74     print(" Orbital period : ", Tin, " [seconds]")
 75
 76 # Sink parameters
 77 center_racc = rin / 2.0  # [au]
 78 inclination = 30.0 * np.pi / 180.0
 79
 80
 81 # Viscosity parameter
 82 alpha_AV = 1.0e-3 / 0.08
 83 alpha_u = 1.0
 84 beta_AV = 2.0
 85
 86 # Integrator parameters
 87 C_cour = 0.3
 88 C_force = 0.25
 89
 90
 91 # Disc profiles
 92 def sigma_profile(r):
 93     sigma_0 = 1.0  # We do not care as it will be renormalized
 94     return sigma_0 * (r / r0) ** (-p)
 95
 96
 97 def kep_profile(r):
 98     return (G * center_mass / r) ** 0.5
 99
100
101 def omega_k(r):
102     return kep_profile(r) / r
103
104
105 def cs_profile(r):
106     cs_in = (H_r_0 * r0) * omega_k(r0)
107     return ((r / r0) ** (-q)) * cs_in
Orbital period :  247.58972132551145  [seconds]

Utility functions and quantities deduced from the base one

113 # Deduced quantities
114 pmass = disc_mass / Npart
115
116 bsize = rout * 2
117 bmin = (-bsize, -bsize, -bsize)
118 bmax = (bsize, bsize, bsize)
119
120 cs0 = cs_profile(r0)
121
122
123 def rot_profile(r):
124     return ((kep_profile(r) ** 2) - (2 * p + q) * cs_profile(r) ** 2) ** 0.5
125
126
127 def H_profile(r):
128     H = cs_profile(r) / omega_k(r)
129     # fact = (2.**0.5) * 3. # factor taken from phantom, to fasten thermalizing
130     fact = 1.0
131     return fact * H

Start the context The context holds the data of the code We then init the layout of the field (e.g. the list of fields used by the solver)

Attach a SPH model to the context

145 model = shamrock.get_Model_SPH(context=ctx, vector_type="f64_3", sph_kernel="M4")
146
147 # Generate the default config
148 cfg = model.gen_default_config()
149 cfg.set_artif_viscosity_ConstantDisc(alpha_u=alpha_u, alpha_AV=alpha_AV, beta_AV=beta_AV)
150 cfg.set_eos_locally_isothermalLP07(cs0=cs0, q=q, r0=r0)
151
152 # cfg.add_ext_force_point_mass(center_mass, center_racc)
153
154 cfg.add_kill_sphere(center=(0, 0, 0), radius=bsize)  # kill particles outside the simulation box
155 # cfg.add_ext_force_lense_thirring(
156 #     central_mass=center_mass,
157 #     Racc=rin,
158 #     a_spin=0.9,
159 #     dir_spin=(np.sin(inclination), np.cos(inclination), 0.0),
160 # )
161
162 cfg.set_units(codeu)
163 cfg.set_particle_mass(pmass)
164 # Set the CFL
165 cfg.set_cfl_cour(C_cour)
166 cfg.set_cfl_force(C_force)
167
168 # On a chaotic disc, we disable to two stage search to avoid giant leaves
169 cfg.set_tree_reduction_level(6)
170 cfg.set_neigh_cache_strategy(NeighCacheStrategy.SingleStage)
171
172 # Enable this to debug the neighbor counts
173 # cfg.set_show_neigh_stats(True)
174
175 # Standard way to set the smoothing length (e.g. Price et al. 2018)
176 cfg.set_smoothing_length_density_based()
177
178 # Standard density based smoothing length but with a neighbor count limit
179 # Use it if you have large slowdowns due to giant particles
180 # I recommend to use it if you have a circumbinary discs as the issue is very likely to happen
181 # cfg.set_smoothing_length_density_based_neigh_lim(500)
182
183 cfg.set_scheduler_config(split_load_value=scheduler_split_val, merge_load_value=scheduler_merge_val)
184
185 # Set the solver config to be the one stored in cfg
186 model.set_solver_config(cfg)
187
188 # Print the solver config
189 model.get_current_config().print_status()
190
191 # Init the scheduler & fields
192 model.init()
193
194 # Set the simulation box size
195 model.resize_simulation_box(bmin, bmax)
196
197 # Create the setup
198
199 setup = model.get_setup()
200 gen_disc = setup.make_generator_disc_mc(
201     part_mass=pmass,
202     disc_mass=disc_mass,
203     r_in=rin,
204     r_out=rout,
205     sigma_profile=sigma_profile,
206     H_profile=H_profile,
207     rot_profile=rot_profile,
208     cs_profile=cs_profile,
209     random_seed=666,
210     init_h_factor=0.03,
211 )
----- SPH Solver configuration -----
[
    {
        "artif_viscosity": {
            "alpha_AV": 0.0125,
            "alpha_u": 1.0,
            "beta_AV": 2.0,
            "type": "constant_disc"
        },
        "boundary_config": {
            "bc_type": "free"
        },
        "cfl_config": {
            "cfl_cour": 0.3,
            "cfl_force": 0.25,
            "cfl_multiplier_stiffness": 2.0,
            "eta_sink": 0.05
        },
        "combined_dtdiv_divcurlv_compute": false,
        "debug_dump_filename": "",
        "do_debug_dump": false,
        "dust_config": {
            "ballabio_ts_limiter": false,
            "drag_mode": {
                "type": "none"
            },
            "evol_mode": {
                "type": "none"
            },
            "mode": {
                "type": "none"
            }
        },
        "enable_particle_reordering": false,
        "eos_config": {
            "Tvec": "f64_3",
            "cs0": 5.0099720102500086e-05,
            "eos_type": "locally_isothermal_lp07",
            "q": 0.75,
            "r0": 0.039483717675779136
        },
        "epsilon_h": 1e-06,
        "ext_force_config": {
            "force_list": []
        },
        "gpart_mass": 1e-08,
        "h_iter_per_subcycles": 50,
        "h_max_subcycles_count": 100,
        "htol_up_coarse_cycle": 1.1,
        "htol_up_fine_cycle": 1.1,
        "kernel_id": "M4<f64>",
        "mhd_config": {
            "mhd_type": "none"
        },
        "neigh_cache_strategy": "single_stage",
        "particle_killing": [
            {
                "center": [
                    0.0,
                    0.0,
                    0.0
                ],
                "radius": 0.7896743535155827,
                "type": "sphere"
            }
        ],
        "particle_reordering_step_freq": 1000,
        "save_dt_to_fields": false,
        "scheduler_config": {
            "merge_load_value": 625000,
            "split_load_value": 10000000
        },
        "self_grav_config": {
            "softening_length": 1e-09,
            "softening_mode": "plummer",
            "type": "none"
        },
        "show_cfl_detail": false,
        "show_ghost_stats": false,
        "show_ghost_zone_graph": false,
        "show_neigh_stats": false,
        "smoothing_length_config": {
            "type": "density_based"
        },
        "tree_reduction_level": 6,
        "type_id": "sycl::vec<f64,3>",
        "unit_sys": {
            "unit_current": 1.0,
            "unit_length": 149597870700.0,
            "unit_lumint": 1.0,
            "unit_mass": 1.98847e+30,
            "unit_qte": 1.0,
            "unit_temperature": 1.0,
            "unit_time": 1.0
        }
    }
]
------------------------------------
Warning: make_generator_disc_mc: with the current EOS, cs_profile is ignored     [SPHSetup][rank=0]

Show the dot graph of the setup

G node_0 GeneratorMCDisc node_2 Simulation node_0->node_2


Apply the setup

219 setup.apply_setup(gen_disc)
220
221 model.do_vtk_dump("init_disc.vtk", True)
222
223 model.change_htolerances(coarse=1.3, fine=1.1)
224 model.timestep()
225 model.change_htolerances(coarse=1.1, fine=1.1)
226
227 for i in range(5):
228     model.timestep()
SPH setup: generating particles ...
SPH setup: Nstep = 100000 ( 1.0e+05 ) Ntotal = 100000 ( 1.0e+05 rank min = 3.3e+05 max = 1.0e+05) rate = 1.000000e+05 N.s^-1
SPH setup: the generation step took : 0.32587365 s
SPH setup: final particle count = 100000 beginning injection ...
Info: ---------------------------------------------                   [DataInserterUtility][rank=0]
Info: Compute load ...                                                [DataInserterUtility][rank=0]
Info: run scheduler step ...                                          [DataInserterUtility][rank=0]
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 8.13 us    (44.3%)
Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
 - strategy "psweep"      : max = 100000.0 min = 100000.0 factor = 1
 - strategy "round robin" : max = 95000.0 min = 95000.0 factor = 0.95
Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
    npatch = 1
    min = 100000
    max = 100000
    avg = 100000
    efficiency = 100.00%
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 832.00 ns  (0.2%)
   patch tree reduce : 2.75 us    (0.7%)
   gen split merge   : 1.07 us    (0.3%)
   split / merge op  : 0/0
   apply split merge : 981.00 ns  (0.2%)
   LB compute        : 394.63 us  (95.4%)
   LB move op cnt    : 0
   LB apply          : 10.53 us   (2.5%)
Info: patch count stable after 1 runs npatch = 1                      [DataInserterUtility][rank=0]
Info: ---------------------------------------------                   [DataInserterUtility][rank=0]
SPH setup: injected       100000 / 100000 => 100.0% | ranks with patchs = 1 / 1  <- global loop -> (msg count : 0)
SPH setup: the injection step took : 0.010098947 s
Info: injection perf report:                                                    [SPH setup][rank=0]
+======+====================+=======+=============+=============+=============+
| rank | rank get (sum/max) |  MPI  | alloc d% h% | mem (max) d | mem (max) h |
+======+====================+=======+=============+=============+=============+
| 0    |      0.00s / 0.00s | 0.00s |   0.9% 0.0% |     1.26 GB |     5.29 MB |
+------+--------------------+-------+-------------+-------------+-------------+
SPH setup: the setup took : 0.362951436 s
Info: dump to init_disc.vtk                                                      [VTK Dump][rank=0]
              - took 15.28 ms, bandwidth = 366.52 MB/s
---------------- t = 0, dt = 0 ----------------
Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
 - strategy "psweep"      : max = 100000.0 min = 100000.0 factor = 1
 - strategy "round robin" : max = 95000.0 min = 95000.0 factor = 0.95
Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
    npatch = 1
    min = 100000
    max = 100000
    avg = 100000
    efficiency = 100.00%
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 7.09 us    (2.6%)
   patch tree reduce : 1.99 us    (0.7%)
   gen split merge   : 1.00 us    (0.4%)
   split / merge op  : 0/0
   apply split merge : 1.16 us    (0.4%)
   LB compute        : 246.27 us  (92.0%)
   LB move op cnt    : 0
   LB apply          : 3.61 us    (1.3%)
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 1.36 us    (68.3%)
Info: free boundaries skipping geometry update                            [PositionUpdated][rank=0]
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.00842468441837221 unconverged cnt = 100000
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.010952089743883873 unconverged cnt = 100000
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.014237716667049035 unconverged cnt = 100000
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.018509031667163747 unconverged cnt = 100000
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.01929060877867953 unconverged cnt = 99998
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.021971836788908673 unconverged cnt = 99993
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.024488793028083 unconverged cnt = 99984
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.027955494402627575 unconverged cnt = 99962
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.02795549440262757 unconverged cnt = 99887
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.027955494402627575 unconverged cnt = 99557
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.02795549440262757 unconverged cnt = 96003
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.027955494402627575 unconverged cnt = 69781
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.02795549440262757 unconverged cnt = 24346
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.027955494402627575 unconverged cnt = 717
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.02795549440262757 unconverged cnt = 4
Info: conservation infos :                                                     [sph::Model][rank=0]
    sum v = (-1.1037629463476045e-09,-2.3562445373832147e-10,0)
    sum a = (-3.4400125570365275e-27,2.7422691667357975e-28,-1.3810872204981368e-26)
    sum e = 1.5742919589839518e-10
    sum de = 1.2138173474500554e-31
Info: cfl dt = 0.016895707644876492 cfl multiplier : 0.01                      [sph::Model][rank=0]
Info: Timestep perf report:                                                    [sph::Model][rank=0]
+======+============+========+========+===========+======+=============+=============+=============+
| rank | rate (N/s) |  Nobj  | Npatch |   tstep   | MPI  | alloc d% h% | mem (max) d | mem (max) h |
+======+============+========+========+===========+======+=============+=============+=============+
| 0    | 2.5328e+04 | 100000 |      1 | 3.948e+00 | 0.0% |   0.2% 0.0% |     1.26 GB |     5.29 MB |
+------+------------+--------+--------+-----------+------+-------------+-------------+-------------+
Info: estimated rate : 0 (tsim/hr)                                             [sph::Model][rank=0]
---------------- t = 0, dt = 0.016895707644876492 ----------------
Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
 - strategy "psweep"      : max = 100000.0 min = 100000.0 factor = 1
 - strategy "round robin" : max = 95000.0 min = 95000.0 factor = 0.95
Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
    npatch = 1
    min = 100000
    max = 100000
    avg = 100000
    efficiency = 100.00%
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 6.61 us    (2.4%)
   patch tree reduce : 1.79 us    (0.6%)
   gen split merge   : 922.00 ns  (0.3%)
   split / merge op  : 0/0
   apply split merge : 1.08 us    (0.4%)
   LB compute        : 258.71 us  (92.8%)
   LB move op cnt    : 0
   LB apply          : 3.83 us    (1.4%)
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 1.52 us    (69.1%)
Info: free boundaries skipping geometry update                            [PositionUpdated][rank=0]
Info: conservation infos :                                                     [sph::Model][rank=0]
    sum v = (-1.1037629463476802e-09,-2.3562445373830643e-10,2.9593213594697117e-28)
    sum a = (-2.6559776852342656e-27,6.4162745754513255e-28,-3.5151867311053465e-27)
    sum e = 1.5742919595579528e-10
    sum de = -5.298955500738431e-31
Info: cfl dt = 0.5744280998263126 cfl multiplier : 0.34                        [sph::Model][rank=0]
Info: Timestep perf report:                                                    [sph::Model][rank=0]
+======+============+========+========+===========+======+=============+=============+=============+
| rank | rate (N/s) |  Nobj  | Npatch |   tstep   | MPI  | alloc d% h% | mem (max) d | mem (max) h |
+======+============+========+========+===========+======+=============+=============+=============+
| 0    | 1.7309e+05 | 100000 |      1 | 5.777e-01 | 0.0% |   0.1% 0.0% |     1.26 GB |     5.29 MB |
+------+------------+--------+--------+-----------+------+-------------+-------------+-------------+
Info: estimated rate : 105.28067988128441 (tsim/hr)                            [sph::Model][rank=0]
---------------- t = 0.016895707644876492, dt = 0.5744280998263126 ----------------
Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
 - strategy "psweep"      : max = 100000.0 min = 100000.0 factor = 1
 - strategy "round robin" : max = 95000.0 min = 95000.0 factor = 0.95
Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
    npatch = 1
    min = 100000
    max = 100000
    avg = 100000
    efficiency = 100.00%
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 6.70 us    (2.2%)
   patch tree reduce : 1.60 us    (0.5%)
   gen split merge   : 1.05 us    (0.3%)
   split / merge op  : 0/0
   apply split merge : 1.02 us    (0.3%)
   LB compute        : 289.45 us  (93.6%)
   LB move op cnt    : 0
   LB apply          : 3.72 us    (1.2%)
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 1.32 us    (69.1%)
Info: free boundaries skipping geometry update                            [PositionUpdated][rank=0]
Info: conservation infos :                                                     [sph::Model][rank=0]
    sum v = (-1.103762946347632e-09,-2.356244537385315e-10,2.7772092758100374e-27)
    sum a = (-1.1186128859677103e-27,2.2668719250893213e-27,-4.0678757291887775e-27)
    sum e = 1.5742926220868435e-10
    sum de = 9.89518731301857e-31
Info: cfl dt = 0.9162781187463197 cfl multiplier : 0.56                        [sph::Model][rank=0]
Info: Timestep perf report:                                                    [sph::Model][rank=0]
+======+============+========+========+===========+======+=============+=============+=============+
| rank | rate (N/s) |  Nobj  | Npatch |   tstep   | MPI  | alloc d% h% | mem (max) d | mem (max) h |
+======+============+========+========+===========+======+=============+=============+=============+
| 0    | 1.6390e+05 | 100000 |      1 | 6.101e-01 | 0.0% |   0.1% 0.0% |     1.26 GB |     5.29 MB |
+------+------------+--------+--------+-----------+------+-------------+-------------+-------------+
Info: estimated rate : 3389.2924432149407 (tsim/hr)                            [sph::Model][rank=0]
---------------- t = 0.5913238074711891, dt = 0.9162781187463197 ----------------
Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
 - strategy "psweep"      : max = 100000.0 min = 100000.0 factor = 1
 - strategy "round robin" : max = 95000.0 min = 95000.0 factor = 0.95
Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
    npatch = 1
    min = 100000
    max = 100000
    avg = 100000
    efficiency = 100.00%
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 7.06 us    (2.2%)
   patch tree reduce : 1.86 us    (0.6%)
   gen split merge   : 922.00 ns  (0.3%)
   split / merge op  : 0/0
   apply split merge : 1.21 us    (0.4%)
   LB compute        : 297.38 us  (93.4%)
   LB move op cnt    : 0
   LB apply          : 3.92 us    (1.2%)
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 1.18 us    (65.2%)
Info: free boundaries skipping geometry update                            [PositionUpdated][rank=0]
Info: conservation infos :                                                     [sph::Model][rank=0]
    sum v = (-1.1037629463475636e-09,-2.3562445373847983e-10,-1.153658874160357e-26)
    sum a = (5.447480642029219e-28,-1.0270274485458392e-28,-1.36054667152722e-26)
    sum e = 1.5742936050084334e-10
    sum de = -5.867165019643428e-31
Info: cfl dt = 1.1065632170012132 cfl multiplier : 0.7066666666666667          [sph::Model][rank=0]
Info: Timestep perf report:                                                    [sph::Model][rank=0]
+======+============+========+========+===========+======+=============+=============+=============+
| rank | rate (N/s) |  Nobj  | Npatch |   tstep   | MPI  | alloc d% h% | mem (max) d | mem (max) h |
+======+============+========+========+===========+======+=============+=============+=============+
| 0    | 1.4990e+05 | 100000 |      1 | 6.671e-01 | 0.0% |   0.1% 0.0% |     1.26 GB |     5.29 MB |
+------+------------+--------+--------+-----------+------+-------------+-------------+-------------+
Info: estimated rate : 4944.711906212834 (tsim/hr)                             [sph::Model][rank=0]
---------------- t = 1.5076019262175087, dt = 1.1065632170012132 ----------------
Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
 - strategy "psweep"      : max = 100000.0 min = 100000.0 factor = 1
 - strategy "round robin" : max = 95000.0 min = 95000.0 factor = 0.95
Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
    npatch = 1
    min = 100000
    max = 100000
    avg = 100000
    efficiency = 100.00%
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 6.33 us    (2.3%)
   patch tree reduce : 2.02 us    (0.7%)
   gen split merge   : 972.00 ns  (0.4%)
   split / merge op  : 0/0
   apply split merge : 1.11 us    (0.4%)
   LB compute        : 249.81 us  (92.5%)
   LB move op cnt    : 0
   LB apply          : 4.05 us    (1.5%)
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 1.54 us    (70.6%)
Info: free boundaries skipping geometry update                            [PositionUpdated][rank=0]
Info: conservation infos :                                                     [sph::Model][rank=0]
    sum v = (-1.1037629463475898e-09,-2.356244537384002e-10,-3.011202127489038e-27)
    sum a = (-1.0090279984166853e-27,1.4283093073075639e-27,-2.3505164286306834e-28)
    sum e = 1.574294272173938e-10
    sum de = -5.216682180926639e-31
Info: cfl dt = 1.2064459048405338 cfl multiplier : 0.8044444444444444          [sph::Model][rank=0]
Info: Timestep perf report:                                                    [sph::Model][rank=0]
+======+============+========+========+===========+======+=============+=============+=============+
| rank | rate (N/s) |  Nobj  | Npatch |   tstep   | MPI  | alloc d% h% | mem (max) d | mem (max) h |
+======+============+========+========+===========+======+=============+=============+=============+
| 0    | 1.8129e+05 | 100000 |      1 | 5.516e-01 | 0.0% |   0.1% 0.0% |     1.26 GB |     5.29 MB |
+------+------------+--------+--------+-----------+------+-------------+-------------+-------------+
Info: estimated rate : 7222.079065573224 (tsim/hr)                             [sph::Model][rank=0]
---------------- t = 2.614165143218722, dt = 1.2064459048405338 ----------------
Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
 - strategy "psweep"      : max = 100000.0 min = 100000.0 factor = 1
 - strategy "round robin" : max = 95000.0 min = 95000.0 factor = 0.95
Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
    npatch = 1
    min = 100000
    max = 100000
    avg = 100000
    efficiency = 100.00%
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 5.87 us    (2.1%)
   patch tree reduce : 1.81 us    (0.7%)
   gen split merge   : 1.22 us    (0.4%)
   split / merge op  : 0/0
   apply split merge : 1.28 us    (0.5%)
   LB compute        : 256.60 us  (93.0%)
   LB move op cnt    : 0
   LB apply          : 3.62 us    (1.3%)
Info: Scheduler step timings :                                                  [Scheduler][rank=0]
   metadata sync     : 1.50 us    (68.8%)
Info: free boundaries skipping geometry update                            [PositionUpdated][rank=0]
Info: conservation infos :                                                     [sph::Model][rank=0]
    sum v = (-1.1037629463476351e-09,-2.356244537382959e-10,1.4374149114905478e-26)
    sum a = (-1.0217334926254999e-27,-1.0360271736104161e-27,-1.4484263398048535e-27)
    sum e = 1.574294582851666e-10
    sum de = 5.607585774326486e-31
Info: cfl dt = 1.2628849169540057 cfl multiplier : 0.8696296296296296          [sph::Model][rank=0]
Info: Timestep perf report:                                                    [sph::Model][rank=0]
+======+============+========+========+===========+======+=============+=============+=============+
| rank | rate (N/s) |  Nobj  | Npatch |   tstep   | MPI  | alloc d% h% | mem (max) d | mem (max) h |
+======+============+========+========+===========+======+=============+=============+=============+
| 0    | 1.6891e+05 | 100000 |      1 | 5.920e-01 | 0.0% |   0.0% 0.0% |     1.26 GB |     5.29 MB |
+------+------------+--------+--------+-----------+------+-------------+-------------+-------------+
Info: estimated rate : 7336.156689634448 (tsim/hr)                             [sph::Model][rank=0]

Usual cartesian rendering

234 ext = rout * 1.5
235 center = (0.0, 0.0, 0.0)
236 delta_x = (ext * 2, 0, 0.0)
237 delta_y = (0.0, ext * 2, 0.0)
238 nx = 1024
239 ny = 1024
240 nr = 1024
241 ntheta = 1024
242
243 arr_rho = model.render_cartesian_column_integ(
244     "rho",
245     "f64",
246     center=center,
247     delta_x=delta_x,
248     delta_y=delta_y,
249     nx=nx,
250     ny=ny,
251 )
252
253 arr_vxyz = model.render_cartesian_column_integ(
254     "vxyz",
255     "f64_3",
256     center=center,
257     delta_x=delta_x,
258     delta_y=delta_y,
259     nx=nx,
260     ny=ny,
261 )
262
263
264 def plot_rho_integ(metadata, arr_rho):
265     ext = metadata["extent"]
266
267     my_cmap = matplotlib.colormaps["gist_heat"].copy()  # copy the default cmap
268     my_cmap.set_bad(color="black")
269
270     res = plt.imshow(
271         arr_rho, cmap=my_cmap, origin="lower", extent=ext, norm="log", vmin=1e-6, vmax=1e-2
272     )
273
274     plt.xlabel("x")
275     plt.ylabel("y")
276     plt.title(f"t = {metadata['time']:0.3f} [seconds]")
277
278     cbar = plt.colorbar(res, extend="both")
279     cbar.set_label(r"$\int \rho \, \mathrm{d}z$ [code unit]")
280
281
282 def plot_vz_integ(metadata, arr_vz):
283     ext = metadata["extent"]
284
285     # if you want an adaptive colorbar
286     v_ext = np.max(arr_vz)
287     v_ext = max(v_ext, np.abs(np.min(arr_vz)))
288     # v_ext = 1e-6
289
290     res = plt.imshow(arr_vz, cmap="seismic", origin="lower", extent=ext, vmin=-v_ext, vmax=v_ext)
291     plt.xlabel("x")
292     plt.ylabel("y")
293     plt.title(f"t = {metadata['time']:0.3f} [seconds]")
294
295     cbar = plt.colorbar(res, extend="both")
296     cbar.set_label(r"$\int v_z \, \mathrm{d}z$ [code unit]")
297
298
299 metadata = {"extent": [-ext, ext, -ext, ext], "time": model.get_time()}
300
301 dpi = 200
302
303 plt.figure(dpi=dpi)
304 plot_rho_integ(metadata, arr_rho)
305
306 plt.figure(dpi=dpi)
307 plot_vz_integ(metadata, arr_vxyz[:, :, 2])
  • t = 3.821 [seconds]
  • t = 3.821 [seconds]
Info: compute_column_integ field_name: rho, rays count: 1048576      [sph::CartesianRender][rank=0]
Info: compute_column_integ took 1.40 s                               [sph::CartesianRender][rank=0]
Info: compute_column_integ field_name: vxyz, rays count: 1048576     [sph::CartesianRender][rank=0]
Info: compute_column_integ took 1.43 s                               [sph::CartesianRender][rank=0]

Cylindrical rendering

313 def make_cylindrical_coords(nr, ntheta):
314     """
315     Generate a list of positions in cylindrical coordinates (r, theta)
316     spanning [0, ext*2] x [-pi, pi] for use with the rendering module.
317
318     Returns:
319         list: List of [x, y, z] coordinate lists
320     """
321
322     # Create the cylindrical coordinate grid
323     r_vals = np.linspace(0, ext, nr)
324     theta_vals = np.linspace(-np.pi, np.pi, ntheta)
325
326     # Create meshgrid
327     r_grid, theta_grid = np.meshgrid(r_vals, theta_vals)
328
329     # Convert to Cartesian coordinates (z = 0 for a disc in the xy-plane)
330     x_grid = r_grid * np.cos(theta_grid)
331     y_grid = r_grid * np.sin(theta_grid)
332     z_grid = np.zeros_like(r_grid)
333
334     # Flatten and stack to create list of positions
335     positions = np.column_stack([x_grid.ravel(), y_grid.ravel(), z_grid.ravel()])
336
337     return [tuple(pos) for pos in positions]
338
339
340 def positions_to_rays(positions):
341     return [shamrock.math.Ray_f64_3(tuple(position), (0.0, 0.0, 1.0)) for position in positions]
342
343
344 positions_cylindrical = make_cylindrical_coords(nr, ntheta)
345 rays_cylindrical = positions_to_rays(positions_cylindrical)
346
347
348 arr_rho_cylindrical = model.render_column_integ("rho", "f64", rays_cylindrical)
349
350 arr_rho_pos = model.render_slice("rho", "f64", positions_cylindrical)
351
352
353 def plot_rho_integ_cylindrical(metadata, arr_rho_cylindrical):
354     ext = metadata["extent"]
355
356     my_cmap = matplotlib.colormaps["gist_heat"].copy()  # copy the default cmap
357     my_cmap.set_bad(color="black")
358
359     arr_rho_cylindrical = np.array(arr_rho_cylindrical).reshape(nr, ntheta)
360
361     res = plt.imshow(
362         arr_rho_cylindrical,
363         cmap=my_cmap,
364         origin="lower",
365         extent=ext,
366         norm="log",
367         vmin=1e-6,
368         vmax=1e-2,
369         aspect="auto",
370     )
371     plt.xlabel("r")
372     plt.ylabel(r"$\theta$")
373     plt.title(f"t = {metadata['time']:0.3f} [seconds]")
374     cbar = plt.colorbar(res, extend="both")
375     cbar.set_label(r"$\int \rho \, \mathrm{d}z$ [code unit]")
376
377
378 def plot_rho_slice_cylindrical(metadata, arr_rho_pos):
379     ext = metadata["extent"]
380
381     my_cmap = matplotlib.colormaps["gist_heat"].copy()  # copy the default cmap
382     my_cmap.set_bad(color="black")
383
384     arr_rho_pos = np.array(arr_rho_pos).reshape(nr, ntheta)
385
386     res = plt.imshow(
387         arr_rho_pos, cmap=my_cmap, origin="lower", extent=ext, norm="log", vmin=1e-8, aspect="auto"
388     )
389     plt.xlabel("r")
390     plt.ylabel(r"$\theta$")
391     plt.title(f"t = {metadata['time']:0.3f} [seconds]")
392     cbar = plt.colorbar(res, extend="both")
393     cbar.set_label(r"$\rho$ [code unit]")
394
395
396 metadata = {"extent": [0, ext, -np.pi, np.pi], "time": model.get_time()}
397
398 plt.figure(dpi=dpi)
399 plot_rho_integ_cylindrical(metadata, arr_rho_cylindrical)
400
401 plt.figure(dpi=dpi)
402 plot_rho_slice_cylindrical(metadata, arr_rho_pos)
403
404 plt.show()
  • t = 3.821 [seconds]
  • t = 3.821 [seconds]
Info: compute_column_integ field_name: rho, rays count: 1048576      [sph::CartesianRender][rank=0]
Info: compute_column_integ took 1.87 s                               [sph::CartesianRender][rank=0]
Info: compute_slice field_name: rho, positions count: 1048576        [sph::CartesianRender][rank=0]
Info: compute_slice took 820.33 ms                                   [sph::CartesianRender][rank=0]

Cylindrical rendering with custom getter (vtheta but with a mask)

409 positions_cylindrical = make_cylindrical_coords(nr, ntheta)
410 rays_cylindrical = positions_to_rays(positions_cylindrical)
411
412
413 def custom_getter(size, dic_out):
414     x = dic_out["xyz"][:, 0]
415     y = dic_out["xyz"][:, 1]
416     z = dic_out["xyz"][:, 2]
417     vx = dic_out["vxyz"][:, 0]
418     vy = dic_out["vxyz"][:, 1]
419     vz = dic_out["vxyz"][:, 2]
420
421     v_theta = np.zeros(size)
422     for i in range(size):
423         e_theta = np.array([-y[i], x[i], 0])
424         e_theta /= np.linalg.norm(e_theta) + 1e-9  # Avoid division by zero
425         v_theta[i] = np.dot(e_theta, np.array([vx[i], vy[i], vz[i]]))
426
427         if x[i] > 0.2:
428             v_theta[i] = 0.0  # To show that we have full control on the rendering
429
430     return v_theta
431
432
433 arr_vtheta_cylindrical = model.render_column_integ("custom", "f64", rays_cylindrical, custom_getter)
434 arr_vtheta_pos = model.render_slice("custom", "f64", positions_cylindrical, custom_getter)
435
436
437 def plot_vtheta_integ_cylindrical(metadata, arr_vtheta_cylindrical):
438     ext = metadata["extent"]
439
440     my_cmap = matplotlib.colormaps["gist_heat"].copy()  # copy the default cmap
441     my_cmap.set_bad(color="black")
442
443     arr_vtheta_cylindrical = np.array(arr_vtheta_cylindrical).reshape(nr, ntheta)
444
445     res = plt.imshow(
446         arr_vtheta_cylindrical,
447         cmap=my_cmap,
448         origin="lower",
449         extent=ext,
450         norm="log",
451         vmin=1e-7,
452         vmax=1e-5,
453         aspect="auto",
454     )
455     plt.xlabel("r")
456     plt.ylabel(r"$\theta$")
457     plt.title(f"t = {metadata['time']:0.3f} [seconds]")
458     cbar = plt.colorbar(res, extend="both")
459     cbar.set_label(r"$\int v_\theta \, \mathrm{d}z$ [code unit]")
460
461
462 def plot_vtheta_slice_cylindrical(metadata, arr_vtheta_pos):
463     ext = metadata["extent"]
464
465     my_cmap = matplotlib.colormaps["gist_heat"].copy()  # copy the default cmap
466     my_cmap.set_bad(color="black")
467
468     arr_vtheta_pos = np.array(arr_vtheta_pos).reshape(nr, ntheta)
469
470     res = plt.imshow(
471         arr_vtheta_pos,
472         cmap=my_cmap,
473         origin="lower",
474         extent=ext,
475         norm="log",
476         vmin=1e-8,
477         aspect="auto",
478     )
479     plt.xlabel("r")
480     plt.ylabel(r"$\theta$")
481     plt.title(f"t = {metadata['time']:0.3f} [seconds]")
482     cbar = plt.colorbar(res, extend="both")
483     cbar.set_label(r"$v_\theta$ [code unit]")
484
485
486 metadata = {"extent": [0, ext, -np.pi, np.pi], "time": model.get_time()}
487
488 plt.figure(dpi=dpi)
489 plot_vtheta_integ_cylindrical(metadata, arr_vtheta_cylindrical)
490
491 plt.figure(dpi=dpi)
492 plot_vtheta_slice_cylindrical(metadata, arr_vtheta_pos)
493
494 plt.show()
  • t = 3.821 [seconds]
  • t = 3.821 [seconds]
Info: compute_column_integ field_name: custom, rays count: 1048576   [sph::CartesianRender][rank=0]
sph::RenderFieldGetter compute custom field took :  0.389261151 s
Info: compute_column_integ took 2.28 s                               [sph::CartesianRender][rank=0]
Info: compute_slice field_name: custom, positions count: 1048576     [sph::CartesianRender][rank=0]
sph::RenderFieldGetter compute custom field took :  0.394139874 s
Info: compute_slice took 1.21 s                                      [sph::CartesianRender][rank=0]

Azymuthal rendering

499 H_r_render = H_r_0 * 4
500
501
502 def make_azymuthal_coords(nr, nz):
503     """
504     Generate a list of positions in cylindrical coordinates (r, theta)
505     spanning [0, ext*2] x [-pi, pi] for use with the rendering module.
506
507     Returns:
508         list: List of [x, y, z] coordinate lists
509     """
510
511     # Create the cylindrical coordinate grid
512     r_vals = np.linspace(0, ext, nr)
513     z_vals = np.linspace(-ext * H_r_render, ext * H_r_render, nz)
514
515     # Create meshgrid
516     r_grid, z_grid = np.meshgrid(r_vals, z_vals)
517
518     # Flatten and stack to create list of positions
519     positions = np.column_stack([r_grid.ravel(), z_grid.ravel()])
520
521     return [tuple(pos) for pos in positions]
522
523
524 def make_ring_rays(positions):
525     def position_to_ring_ray(position):
526         r = position[0]
527         z = position[1]
528         e_x = (1.0, 0.0, 0.0)
529         e_y = (0.0, 1.0, 0.0)
530         center = (0.0, 0.0, z)
531         return shamrock.math.RingRay_f64_3(center, r, e_x, e_y)
532
533     return [position_to_ring_ray(position) for position in positions]
534
535
536 def make_slice_coord_for_azymuthal(positions):
537     def position_to_ring_ray(position):
538         r = position[0]
539         z = position[1]
540         e_x = (1.0, 0.0, 0.0)
541         e_y = (0.0, 1.0, 0.0)
542         center = (0.0, 0.0, z)
543         return (r, 0.0, z)
544
545     return [position_to_ring_ray(position) for position in positions]
546
547
548 nr = 1024
549 nz = 1024
550
551 positions_azymuthal = make_azymuthal_coords(nr, nz)
552 ring_rays_azymuthal = make_ring_rays(positions_azymuthal)
553 slice_coords_azymuthal = make_slice_coord_for_azymuthal(positions_azymuthal)
554
555 arr_rho_azymuthal = model.render_azymuthal_integ("rho", "f64", ring_rays_azymuthal)
556 arr_rho_slice_azymuthal = model.render_slice("rho", "f64", slice_coords_azymuthal)
557
558 arr_vxyz_azymuthal = model.render_azymuthal_integ("vxyz", "f64_3", ring_rays_azymuthal)
559 arr_vxyz_slice_azymuthal = model.render_slice("vxyz", "f64_3", slice_coords_azymuthal)
560
561
562 def plot_rho_integ_azymuthal(metadata, arr_rho_azymuthal):
563     ext = metadata["extent"]
564
565     my_cmap = matplotlib.colormaps["gist_heat"].copy()  # copy the default cmap
566     my_cmap.set_bad(color="black")
567
568     arr_rho_azymuthal = np.array(arr_rho_azymuthal).reshape(nr, nz)
569
570     res = plt.imshow(
571         arr_rho_azymuthal, cmap=my_cmap, origin="lower", extent=ext, norm="log", vmin=1e-5, vmax=1
572     )
573     plt.xlabel("r")
574     plt.ylabel("z")
575     plt.title(f"t = {metadata['time']:0.3f} [seconds]")
576     cbar = plt.colorbar(res, extend="both")
577     cbar.set_label(r"$\int \rho \, \mathrm{d}\theta$ [code unit]")
578
579
580 def plot_rho_slice_azymuthal(metadata, arr_rho_slice_azymuthal):
581     ext = metadata["extent"]
582
583     my_cmap = matplotlib.colormaps["gist_heat"].copy()  # copy the default cmap
584     my_cmap.set_bad(color="black")
585
586     arr_rho_slice_azymuthal = np.array(arr_rho_slice_azymuthal).reshape(nr, nz)
587
588     res = plt.imshow(
589         arr_rho_slice_azymuthal,
590         cmap=my_cmap,
591         origin="lower",
592         extent=ext,
593         norm="log",
594         vmin=1e-5,
595         vmax=1,
596     )
597     plt.xlabel("r")
598     plt.ylabel("z")
599     plt.title(f"t = {metadata['time']:0.3f} [seconds]")
600     cbar = plt.colorbar(res, extend="both")
601     cbar.set_label(r"$\rho$ [code unit]")
602
603
604 def plot_vz_integ_azymuthal(metadata, arr_vxyz_azymuthal):
605     ext = metadata["extent"]
606
607     my_cmap = matplotlib.colormaps["seismic"].copy()  # copy the default cmap
608     my_cmap.set_bad(color="black")
609
610     arr_vz_azymuthal = np.array(arr_vxyz_azymuthal).reshape(nr, nz, 3)[:, :, 2]
611
612     res = plt.imshow(
613         arr_vz_azymuthal, cmap=my_cmap, origin="lower", extent=ext, vmin=-1e-6, vmax=1e-6
614     )
615     plt.xlabel("r")
616     plt.ylabel("z")
617     plt.title(f"t = {metadata['time']:0.3f} [seconds]")
618     cbar = plt.colorbar(res, extend="both")
619     cbar.set_label(r"$\int v_z \, \mathrm{d}\theta$ [code unit]")
620
621
622 def plot_vz_slice_azymuthal(metadata, arr_vxyz_slice_azymuthal):
623     ext = metadata["extent"]
624
625     my_cmap = matplotlib.colormaps["seismic"].copy()  # copy the default cmap
626     my_cmap.set_bad(color="black")
627
628     arr_vz_slice_azymuthal = np.array(arr_vxyz_slice_azymuthal).reshape(nr, nz, 3)[:, :, 2]
629
630     res = plt.imshow(
631         arr_vz_slice_azymuthal, cmap=my_cmap, origin="lower", extent=ext, vmin=-5e-6, vmax=5e-6
632     )
633     plt.xlabel("r")
634     plt.ylabel("z")
635     plt.title(f"t = {metadata['time']:0.3f} [seconds]")
636     cbar = plt.colorbar(res, extend="both")
637     cbar.set_label(r"$v_z$ [code unit]")
638
639
640 metadata = {"extent": [0, ext, -ext * H_r_render, ext * H_r_render], "time": model.get_time()}
641 fig_size = (6, 3)
642 plt.figure(dpi=dpi, figsize=fig_size)
643 plot_rho_integ_azymuthal(metadata, arr_rho_azymuthal)
644
645 plt.figure(dpi=dpi, figsize=fig_size)
646 plot_rho_slice_azymuthal(metadata, arr_rho_slice_azymuthal)
647
648 plt.figure(dpi=dpi, figsize=fig_size)
649 plot_vz_integ_azymuthal(metadata, arr_vxyz_azymuthal)
650
651 plt.figure(dpi=dpi, figsize=fig_size)
652 plot_vz_slice_azymuthal(metadata, arr_vxyz_slice_azymuthal)
653
654 plt.show()
  • t = 3.821 [seconds]
  • t = 3.821 [seconds]
  • t = 3.821 [seconds]
  • t = 3.821 [seconds]
Info: compute_azymuthal_integ field_name: rho, ring_rays count: 1048576  [sph::CartesianRender][rank=0]
Info: compute_azymuthal_integ took 26.43 s                           [sph::CartesianRender][rank=0]
Info: compute_slice field_name: rho, positions count: 1048576        [sph::CartesianRender][rank=0]
Info: compute_slice took 259.19 ms                                   [sph::CartesianRender][rank=0]
Info: compute_azymuthal_integ field_name: vxyz, ring_rays count: 1048576  [sph::CartesianRender][rank=0]
Info: compute_azymuthal_integ took 26.83 s                           [sph::CartesianRender][rank=0]
Info: compute_slice field_name: vxyz, positions count: 1048576       [sph::CartesianRender][rank=0]
Info: compute_slice took 343.26 ms                                   [sph::CartesianRender][rank=0]

Total running time of the script: (1 minutes 27.832 seconds)

Estimated memory usage: 1915 MB

Gallery generated by Sphinx-Gallery