CI test: last CFL dt stored in synchronized edges#

Checks that the SPH solver stores the last CFL timestep in the synchronized edges and that model.get_last_cfl_dts() exposes it:

  • without CFL detail, only the global "cfl_dt" edge exists,

  • with CFL detail, one "cfl_dt_<type>" edge per enabled CFL condition exists as well, and "cfl_dt" is their minimum,

  • the values are identical on every rank and survive a dump/reload.

SPH setup: generating particles ...
SPH setup: Nstep = 59 ( 5.9e+01 ) Ntotal = 59 ( 5.9e+01 rank min = 2.0e+04 max = 5.9e+01) rate = 5.900000e+01 N.s^-1
SPH setup: Nstep = 100 ( 1.0e+02 ) Ntotal = 159 ( 1.6e+02 rank min = 5.8e+04 max = 1.6e+02) rate = 1.590000e+02 N.s^-1
SPH setup: Nstep = 102 ( 1.0e+02 ) Ntotal = 261 ( 2.6e+02 rank min = 1.5e+04 max = 2.6e+02) rate = 2.610000e+02 N.s^-1
SPH setup: Nstep = 8 ( 8.0e+00 ) Ntotal = 269 ( 2.7e+02 rank min = 3.3e+04 max = 2.7e+02) rate = 2.690000e+02 N.s^-1
SPH setup: the generation step took : 0.013146215000000001 s
SPH setup: final particle count = 269 beginning injection ...
SPH setup: injected          269 / 269 => 100.0% | ranks with patchs = 1 / 1  <- global loop -> (msg count : 0)
SPH setup: the injection step took : 0.012309426 s
SPH setup: the setup took : 0.029039625000000003 s
---------------- t = 0, dt = 0 ----------------
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
    This can lead to high mpi overhead, try to increase the patch split crit
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.19599771799087468 unconverged cnt = 269
Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
    This can lead to high mpi overhead, try to increase the patch split crit
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.21559748978996215 unconverged cnt = 146
Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
    This can lead to high mpi overhead, try to increase the patch split crit
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.2371572387689584 unconverged cnt = 12
Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
    This can lead to high mpi overhead, try to increase the patch split crit
Warning: the unit system is not set                                           [sph::Config][rank=0]
---------------- t = 0, dt = 0.0006110884515229946 ----------------
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
    This can lead to high mpi overhead, try to increase the patch split crit
Warning: the unit system is not set                                           [sph::Config][rank=0]
last cfl dt (detail off): {'cfl_dt': 0.020786931140653973}
SPH setup: generating particles ...
SPH setup: Nstep = 59 ( 5.9e+01 ) Ntotal = 59 ( 5.9e+01 rank min = 3.4e+05 max = 5.9e+01) rate = 5.900000e+01 N.s^-1
SPH setup: Nstep = 100 ( 1.0e+02 ) Ntotal = 159 ( 1.6e+02 rank min = 2.3e+05 max = 1.6e+02) rate = 1.590000e+02 N.s^-1
SPH setup: Nstep = 102 ( 1.0e+02 ) Ntotal = 261 ( 2.6e+02 rank min = 2.2e+05 max = 2.6e+02) rate = 2.610000e+02 N.s^-1
SPH setup: Nstep = 8 ( 8.0e+00 ) Ntotal = 269 ( 2.7e+02 rank min = 8.5e+04 max = 2.7e+02) rate = 2.690000e+02 N.s^-1
SPH setup: the generation step took : 0.001952099 s
SPH setup: final particle count = 269 beginning injection ...
SPH setup: injected          269 / 269 => 100.0% | ranks with patchs = 1 / 1  <- global loop -> (msg count : 0)
SPH setup: the injection step took : 0.002739735 s
SPH setup: the setup took : 0.005366381 s
---------------- t = 0, dt = 0 ----------------
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
    This can lead to high mpi overhead, try to increase the patch split crit
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.19599771799087468 unconverged cnt = 269
Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
    This can lead to high mpi overhead, try to increase the patch split crit
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.21559748978996215 unconverged cnt = 146
Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
    This can lead to high mpi overhead, try to increase the patch split crit
Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
     largest h = 0.2371572387689584 unconverged cnt = 12
Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
    This can lead to high mpi overhead, try to increase the patch split crit
Warning: the unit system is not set                                           [sph::Config][rank=0]
---------------- t = 0, dt = 0.0006110884515229946 ----------------
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: the unit system is not set                                           [sph::Config][rank=0]
Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
    This can lead to high mpi overhead, try to increase the patch split crit
Warning: the unit system is not set                                           [sph::Config][rank=0]
last cfl dt (detail on): {'cfl_dt': 0.020786931140653973, 'cfl_dt_courant': 0.02145652566989449, 'cfl_dt_force': 0.020786931140653973, 'cfl_dt_sink_sink': 92.50265378943428}
last cfl dt test: OK

 14 import shamrock
 15
 16 DUMP_NAME = "last_cfl_dt_test.sham"
 17
 18
 19 def build_model(show_cfl_detail):
 20     ctx = shamrock.Context()
 21     ctx.pdata_layout_new()
 22
 23     model = shamrock.get_Model_SPH(context=ctx, vector_type="f64_3", sph_kernel="M4")
 24
 25     cfg = model.gen_default_config()
 26     cfg.set_self_gravity_none()
 27     cfg.set_artif_viscosity_Constant(alpha_u=1.0, alpha_AV=1.0, beta_AV=2.0)
 28     cfg.set_eos_isothermal(1.0)
 29     cfg.set_particle_mass(1e-3)
 30     cfg.set_boundary_periodic()
 31     cfg.set_show_cfl_detail(show_cfl_detail)
 32     model.set_solver_config(cfg)
 33
 34     model.init_scheduler(1000, 1)
 35
 36     dr = 0.1
 37     bmin = (-0.6, -0.6, -0.6)
 38     bmax = (0.6, 0.6, 0.6)
 39     model.resize_simulation_box(bmin, bmax)
 40
 41     setup = model.get_setup()
 42     gen = setup.make_generator_lattice_hcp(dr, bmin, bmax)
 43     setup.apply_setup(gen)
 44
 45     model.set_field_value_lambda_f64_3("vxyz", lambda r: (1.0, 0.0, 0.0))
 46
 47     model.add_sink(1.0, (0.1, 0.0, 0.0), (0.0, 0.05, 0.0), 0.05)
 48     model.add_sink(0.5, (-0.2, 0.1, 0.0), (0.0, -0.03, 0.0), 0.05)
 49
 50     return ctx, model
 51
 52
 53 def check_in_sync(cfl):
 54     s = str(sorted(cfl.items()))
 55     # Collective: every rank must call this
 56     hist = shamrock.algs.all_string_histogram([s], delimiter="\n", hash_based=False)
 57     if len(hist) != 1 or next(iter(hist.values())) != shamrock.sys.world_size():
 58         raise RuntimeError(f"last cfl dt not in sync across ranks: {hist}")
 59
 60
 61 def check_detail_off():
 62     ctx, model = build_model(show_cfl_detail=False)
 63
 64     cfl = model.get_last_cfl_dts()
 65     if cfl != {"cfl_dt": 0.0}:
 66         raise RuntimeError(f"expected only 'cfl_dt' = 0 before the first step, got {cfl}")
 67
 68     model.timestep()  # first step only computes the initial dt
 69     model.timestep()
 70
 71     cfl = model.get_last_cfl_dts()
 72     if shamrock.sys.world_rank() == 0:
 73         print("last cfl dt (detail off):", cfl)
 74
 75     if set(cfl.keys()) != {"cfl_dt"}:
 76         raise RuntimeError(f"expected only 'cfl_dt' without cfl detail, got {cfl}")
 77     if cfl["cfl_dt"] != model.get_dt():
 78         raise RuntimeError(f"cfl_dt={cfl['cfl_dt']} != next dt={model.get_dt()}")
 79
 80     check_in_sync(cfl)
 81
 82
 83 def check_detail_on():
 84     ctx, model = build_model(show_cfl_detail=True)
 85
 86     expected = {"cfl_dt", "cfl_dt_courant", "cfl_dt_force", "cfl_dt_sink_sink"}
 87
 88     cfl = model.get_last_cfl_dts()
 89     if cfl != {k: 0.0 for k in expected}:
 90         raise RuntimeError(f"expected {sorted(expected)} = 0 before the first step, got {cfl}")
 91
 92     model.timestep()
 93     model.timestep()
 94
 95     cfl = model.get_last_cfl_dts()
 96     if shamrock.sys.world_rank() == 0:
 97         print("last cfl dt (detail on):", cfl)
 98
 99     if set(cfl.keys()) != expected:
100         raise RuntimeError(f"expected keys {sorted(expected)}, got {sorted(cfl.keys())}")
101
102     detail_min = min(v for k, v in cfl.items() if k != "cfl_dt")
103     if cfl["cfl_dt"] != detail_min:
104         raise RuntimeError(f"cfl_dt={cfl['cfl_dt']} != min of per-type cfl dt={detail_min}")
105     if cfl["cfl_dt"] != model.get_dt():
106         raise RuntimeError(f"cfl_dt={cfl['cfl_dt']} != next dt={model.get_dt()}")
107
108     check_in_sync(cfl)
109
110     model.dump(DUMP_NAME)
111
112     del model
113     del ctx
114
115     ctx2 = shamrock.Context()
116     ctx2.pdata_layout_new()
117     model2 = shamrock.get_Model_SPH(context=ctx2, vector_type="f64_3", sph_kernel="M4")
118     model2.load_from_dump(DUMP_NAME)
119
120     cfl_reload = model2.get_last_cfl_dts()
121     if cfl_reload != cfl:
122         raise RuntimeError(
123             f"last cfl dt changed across dump/reload:\n  before={cfl}\n  after ={cfl_reload}"
124         )
125
126     check_in_sync(cfl_reload)
127
128
129 check_detail_off()
130 check_detail_on()
131
132 if shamrock.sys.world_rank() == 0:
133     print("last cfl dt test: OK")

Total running time of the script: (0 minutes 0.442 seconds)

Estimated memory usage: 217 MB

Gallery generated by Sphinx-Gallery