
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "_as_gen/sph/run_init_sim_from_other.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download__as_gen_sph_run_init_sim_from_other.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr__as_gen_sph_run_init_sim_from_other.py:


Init a simulation from another simulation
=========================================

.. GENERATED FROM PYTHON SOURCE LINES 5-15

.. code-block:: Python
   :lineno-start: 7



    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
    if not shamrock.sys.is_initialized():
        shamrock.change_loglevel(1)
        shamrock.sys.init("0:0")








.. GENERATED FROM PYTHON SOURCE LINES 17-18

Use shamrock documentation style for matplotlib

.. GENERATED FROM PYTHON SOURCE LINES 18-20

.. code-block:: Python
   :lineno-start: 18

    shamrock.matplotlib.set_shamrock_mpl_style()








.. GENERATED FROM PYTHON SOURCE LINES 21-22

Setup parameters

.. GENERATED FROM PYTHON SOURCE LINES 22-33

.. code-block:: Python
   :lineno-start: 23


    gamma = 5.0 / 3.0
    rho_g = 1

    bmin = (-0.6, -0.6, -0.6)
    bmax = (0.6, 0.6, 0.6)

    N_target = 1e4
    scheduler_split_val = int(2e7)
    scheduler_merge_val = 1








.. GENERATED FROM PYTHON SOURCE LINES 34-35

Deduced quantities

.. GENERATED FROM PYTHON SOURCE LINES 35-51

.. code-block:: Python
   :lineno-start: 35

    import numpy as np

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

    part_vol = vol_b / N_target

    # lattice volume
    HCP_PACKING_DENSITY = 0.74
    part_vol_lattice = HCP_PACKING_DENSITY * part_vol

    dr = (part_vol_lattice / ((4.0 / 3.0) * np.pi)) ** (1.0 / 3.0)

    pmass = -1








.. GENERATED FROM PYTHON SOURCE LINES 52-53

Setup

.. GENERATED FROM PYTHON SOURCE LINES 53-104

.. code-block:: Python
   :lineno-start: 54


    ctx = shamrock.Context()
    ctx.pdata_layout_new()

    model = shamrock.get_Model_SPH(context=ctx, vector_type="f64_3", sph_kernel="M4")

    cfg = model.gen_default_config()
    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_periodic()
    cfg.set_eos_adiabatic(gamma)
    cfg.print_status()
    model.set_solver_config(cfg)
    model.init_scheduler(scheduler_split_val, scheduler_merge_val)

    bmin, bmax = shamrock.math.get_ideal_hcp_box(dr, bmin, bmax)
    xm, ym, zm = bmin
    xM, yM, zM = bmax

    model.resize_simulation_box(bmin, bmax)

    setup = model.get_setup()
    gen = setup.make_generator_lattice_hcp(dr, bmin, bmax)
    setup.apply_setup(gen, insert_step=scheduler_split_val)


    xc, yc, zc = model.get_closest_part_to((0, 0, 0))

    if shamrock.sys.world_rank() == 0:
        print("closest part to (0,0,0) is in :", xc, yc, zc)


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

    totmass = rho_g * vol_b

    pmass = model.total_mass_to_part_mass(totmass)

    model.set_value_in_a_box("uint", "f64", 0, bmin, bmax)

    tot_u = pmass * model.get_sum("uint", "f64")
    if shamrock.sys.world_rank() == 0:
        print("total u :", tot_u)

    model.set_particle_mass(pmass)

    model.set_cfl_cour(0.1)
    model.set_cfl_force(0.1)






.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    ----- SPH Solver configuration ----- 
    [
        {
            "artif_viscosity": {
                "alpha_max": 1.0,
                "alpha_min": 0.0,
                "alpha_u": 1.0,
                "beta_AV": 2.0,
                "sigma_decay": 0.1,
                "type": "varying_cd10"
            },
            "boundary_config": {
                "bc_type": "periodic"
            },
            "cfl_config": {
                "cfl_cour": 0.0,
                "cfl_force": 0.0,
                "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",
                "eos_type": "adiabatic",
                "gamma": 1.6666666666666667
            },
            "epsilon_h": 1e-06,
            "ext_force_config": {
                "force_list": []
            },
            "gpart_mass": 0.0,
            "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": "two_stage",
            "particle_killing": [],
            "particle_reordering_step_freq": 1000,
            "save_dt_to_fields": false,
            "scheduler_config": {
                "merge_load_value": 0,
                "split_load_value": 0
            },
            "self_grav_config": {
                "softening_length": 1e-09,
                "softening_mode": "plummer",
                "type": "none"
            },
            "show_cfl_detail": false,
            "show_ghost_zone_graph": false,
            "show_neigh_stats": false,
            "smoothing_length_config": {
                "type": "density_based"
            },
            "tree_reduction_level": 3,
            "type_id": "sycl::vec<f64,3>",
            "unit_sys": null
        }
    ] 
    ------------------------------------ 
    SPH setup: generating particles ...  
    SPH setup: Nstep = 11520 ( 1.2e+04 ) Ntotal = 11520 ( 1.2e+04 rank min = 3.8e+06 max = 1.2e+04) rate = 1.152000e+04 N.s^-1  
    SPH setup: the generation step took : 0.007866488000000001 s  
    SPH setup: final particle count = 11520 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     : 6.09 us    (65.3%)  
    Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
     - strategy "psweep"      : max = 11520.0 min = 11520.0 factor = 1
     - strategy "round robin" : max = 10944.0 min = 10944.0 factor = 0.95  
    Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
        npatch = 1
        min = 11520
        max = 11520
        avg = 11520
        efficiency = 100.00%  
    Info: Scheduler step timings :                                                  [Scheduler][rank=0]
       metadata sync     : 1.67 us    (0.3%)
       patch tree reduce : 1.01 us    (0.2%)
       gen split merge   : 952.00 ns  (0.2%)
       split / merge op  : 0/0
       apply split merge : 782.00 ns  (0.2%)
       LB compute        : 458.21 us  (95.6%)
       LB move op cnt    : 0
       LB apply          : 12.79 us   (2.7%)  
    Info: patch count stable after 1 runs npatch = 1                      [DataInserterUtility][rank=0] 
    Info: ---------------------------------------------                   [DataInserterUtility][rank=0] 
    SPH setup: injected        11520 / 11520 => 100.0% | ranks with patchs = 1 / 1  <- global loop -> (msg count : 0)  
    SPH setup: the injection step took : 0.009307119 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 |   1.8% 0.0% |   337.11 MB |     5.29 MB |
    +------+--------------------+-------+-------------+-------------+-------------+  
    SPH setup: the setup took : 0.023459403 s  
    closest part to (0,0,0) is in : 0.0 0.0 0.0
    total u : 0.0




.. GENERATED FROM PYTHON SOURCE LINES 105-106

Single timestep to iterate the smoothing length

.. GENERATED FROM PYTHON SOURCE LINES 106-143

.. code-block:: Python
   :lineno-start: 106

    model.timestep()
    model.dump("init.sham")

    # here we can dump and load it into another context i we want like so
    ctx_data_source = shamrock.Context()
    ctx_data_source.pdata_layout_new()
    model_data_source = shamrock.get_Model_SPH(
        context=ctx_data_source, vector_type="f64_3", sph_kernel="M4"
    )
    model_data_source.load_from_dump("init.sham")

    # trigger rebalancing
    model_data_source.set_dt(0.0)
    model_data_source.timestep()

    # reset dt to 0 for the init of the next simulation
    model_data_source.set_dt(0.0)

    cfg = model_data_source.get_current_config()
    cfg.print_status()

    # now we feed the old context to the new model
    ctx_new = shamrock.Context()
    ctx_new.pdata_layout_new()

    model_new = shamrock.get_Model_SPH(context=ctx_new, vector_type="f64_3", sph_kernel="M4")
    model_new.set_solver_config(cfg)
    model_new.init_scheduler(scheduler_split_val, scheduler_merge_val)
    model_new.resize_simulation_box(bmin, bmax)

    setup = model_new.get_setup()
    gen = setup.make_generator_from_context(ctx_data_source)
    setup.apply_setup(gen, insert_step=scheduler_split_val)

    model_new.timestep()






.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    ---------------- t = 0, dt = 0 ---------------- 
    Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
     - strategy "psweep"      : max = 11520.0 min = 11520.0 factor = 1
     - strategy "round robin" : max = 10944.0 min = 10944.0 factor = 0.95  
    Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
        npatch = 1
        min = 11520
        max = 11520
        avg = 11520
        efficiency = 100.00%  
    Info: Scheduler step timings :                                                  [Scheduler][rank=0]
       metadata sync     : 35.37 us   (5.4%)
       patch tree reduce : 2.77 us    (0.4%)
       gen split merge   : 541.00 ns  (0.1%)
       split / merge op  : 0/0
       apply split merge : 851.00 ns  (0.1%)
       LB compute        : 583.23 us  (88.7%)
       LB move op cnt    : 0
       LB apply          : 12.72 us   (1.9%)  
    Info: Scheduler step timings :                                                  [Scheduler][rank=0]
       metadata sync     : 4.11 us    (73.1%)  
    Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
        This can lead to high mpi overhead, try to increase the patch split crit
        patch 0 high interf/patch volume: 0.39592013888888883  
    Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
         largest h = 0.03437860905706778 unconverged cnt = 11520   
    Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
        This can lead to high mpi overhead, try to increase the patch split crit
        patch 0 high interf/patch volume: 0.4238715277777777  
    Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
         largest h = 0.03781646996277456 unconverged cnt = 11520   
    Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
        This can lead to high mpi overhead, try to increase the patch split crit
        patch 0 high interf/patch volume: 0.4238715277777777  
    Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
         largest h = 0.041598116959052016 unconverged cnt = 11520   
    Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
        This can lead to high mpi overhead, try to increase the patch split crit
        patch 0 high interf/patch volume: 0.4506076388888888  
    Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
         largest h = 0.045757928654957224 unconverged cnt = 11520   
    Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
        This can lead to high mpi overhead, try to increase the patch split crit
        patch 0 high interf/patch volume: 0.5162326388888888  
    Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
         largest h = 0.05033372152045295 unconverged cnt = 11520   
    Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
        This can lead to high mpi overhead, try to increase the patch split crit
        patch 0 high interf/patch volume: 0.6863715277777777  
    Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
         largest h = 0.05536709367249825 unconverged cnt = 11520   
    Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
        This can lead to high mpi overhead, try to increase the patch split crit
        patch 0 high interf/patch volume: 0.6863715277777777  
    Warning: smoothing length is not converged, rerunning the iterator ...    [Smoothinglength][rank=0]
         largest h = 0.06090380303974808 unconverged cnt = 11520   
    Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
        This can lead to high mpi overhead, try to increase the patch split crit
        patch 0 high interf/patch volume: 0.7886284722222223  
    Warning: the unit system is not set                                           [sph::Config][rank=0] 
    Info: conservation infos :                                                     [sph::Model][rank=0]
        sum v = (0,0,0)
        sum a = (0,0,0)
        sum e = 0
        sum de = 0  
    Info: cfl dt = 1.7976931348623157e+308 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.7085e+04 | 11520 |      1 | 4.253e-01 | 0.0% |   0.9% 0.0% |   337.11 MB |     5.29 MB |
    +------+------------+-------+--------+-----------+------+-------------+-------------+-------------+  
    Info: estimated rate : 0 (tsim/hr)                                             [sph::Model][rank=0] 
    Info: Dumping state to init.sham                                                      [SPH][rank=0] 
    Info: Scheduler step timings :                                                  [Scheduler][rank=0]
       metadata sync     : 6.81 us    (60.1%)  
    Info: dump to init.sham                                                     [Shamrock Dump][rank=0]
                  - took 1.53 ms, bandwidth = 1.33 GB/s  
    Info: Loading state from dump init.sham                                               [SPH][rank=0] 
    Info: load dump from init.sham                                              [Shamrock Dump][rank=0]
                  - took 1.54 ms, bandwidth = 1.32 GB/s  
    ---------------- t = 0, dt = 0 ---------------- 
    Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
     - strategy "psweep"      : max = 11520.0 min = 11520.0 factor = 1
     - strategy "round robin" : max = 10944.0 min = 10944.0 factor = 0.95  
    Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
        npatch = 1
        min = 11520
        max = 11520
        avg = 11520
        efficiency = 100.00%  
    Info: Scheduler step timings :                                                  [Scheduler][rank=0]
       metadata sync     : 3.93 us    (1.0%)
       patch tree reduce : 1.28 us    (0.3%)
       gen split merge   : 641.00 ns  (0.2%)
       split / merge op  : 0/0
       apply split merge : 851.00 ns  (0.2%)
       LB compute        : 397.09 us  (96.5%)
       LB move op cnt    : 0
       LB apply          : 3.78 us    (0.9%)  
    Info: Scheduler step timings :                                                  [Scheduler][rank=0]
       metadata sync     : 2.77 us    (70.6%)  
    Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
        This can lead to high mpi overhead, try to increase the patch split crit
        patch 0 high interf/patch volume: 0.8190104166666667  
    Warning: the unit system is not set                                           [sph::Config][rank=0] 
    Info: conservation infos :                                                     [sph::Model][rank=0]
        sum v = (0,0,0)
        sum a = (0,0,0)
        sum e = 0
        sum de = 0  
    Info: cfl dt = 1.7976931348623157e+308 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    | 7.6915e+04 | 11520 |      1 | 1.498e-01 | 0.0% |   0.6% 0.0% |   337.11 MB |     5.29 MB |
    +------+------------+-------+--------+-----------+------+-------------+-------------+-------------+  
    Info: estimated rate : 0 (tsim/hr)                                             [sph::Model][rank=0] 
    ----- SPH Solver configuration ----- 
    [
        {
            "artif_viscosity": {
                "alpha_max": 1.0,
                "alpha_min": 0.0,
                "alpha_u": 1.0,
                "beta_AV": 2.0,
                "sigma_decay": 0.1,
                "type": "varying_cd10"
            },
            "boundary_config": {
                "bc_type": "periodic"
            },
            "cfl_config": {
                "cfl_cour": 0.1,
                "cfl_force": 0.1,
                "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",
                "eos_type": "adiabatic",
                "gamma": 1.6666666666666667
            },
            "epsilon_h": 1e-06,
            "ext_force_config": {
                "force_list": []
            },
            "gpart_mass": 0.00017268787196946227,
            "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": "two_stage",
            "particle_killing": [],
            "particle_reordering_step_freq": 1000,
            "save_dt_to_fields": false,
            "scheduler_config": {
                "merge_load_value": 1,
                "split_load_value": 20000000
            },
            "self_grav_config": {
                "softening_length": 1e-09,
                "softening_mode": "plummer",
                "type": "none"
            },
            "show_cfl_detail": false,
            "show_ghost_zone_graph": false,
            "show_neigh_stats": false,
            "smoothing_length_config": {
                "type": "density_based"
            },
            "tree_reduction_level": 3,
            "type_id": "sycl::vec<f64,3>",
            "unit_sys": null
        }
    ] 
    ------------------------------------ 
    SPH setup: generating particles ...  
    SPH setup: Nstep = 11520 ( 1.2e+04 ) Ntotal = 11520 ( 1.2e+04 rank min = 1.8e+06 max = 1.2e+04) rate = 1.152000e+04 N.s^-1  
    SPH setup: the generation step took : 0.008819926 s  
    SPH setup: final particle count = 11520 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     : 6.64 us    (62.3%)  
    Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
     - strategy "psweep"      : max = 11520.0 min = 11520.0 factor = 1
     - strategy "round robin" : max = 10944.0 min = 10944.0 factor = 0.95  
    Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
        npatch = 1
        min = 11520
        max = 11520
        avg = 11520
        efficiency = 100.00%  
    Info: Scheduler step timings :                                                  [Scheduler][rank=0]
       metadata sync     : 1.92 us    (0.5%)
       patch tree reduce : 1.02 us    (0.3%)
       gen split merge   : 722.00 ns  (0.2%)
       split / merge op  : 0/0
       apply split merge : 742.00 ns  (0.2%)
       LB compute        : 369.58 us  (96.8%)
       LB move op cnt    : 0
       LB apply          : 4.01 us    (1.0%)  
    Info: patch count stable after 1 runs npatch = 1                      [DataInserterUtility][rank=0] 
    Info: ---------------------------------------------                   [DataInserterUtility][rank=0] 
    SPH setup: injected        11520 / 11520 => 100.0% | ranks with patchs = 1 / 1  <- global loop -> (msg count : 0)  
    SPH setup: the injection step took : 0.0073359440000000005 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 |   1.1% 0.0% |   337.11 MB |     5.29 MB |
    +------+--------------------+-------+-------------+-------------+-------------+  
    SPH setup: the setup took : 0.020937726 s  
    ---------------- t = 0, dt = 0 ---------------- 
    Info: Summary (strategy = round robin):                                       [LoadBalance][rank=0]
     - strategy "psweep"      : max = 11520.0 min = 11520.0 factor = 1
     - strategy "round robin" : max = 10944.0 min = 10944.0 factor = 0.95  
    Info: Loadbalance stats :                                                     [LoadBalance][rank=0]
        npatch = 1
        min = 11520
        max = 11520
        avg = 11520
        efficiency = 100.00%  
    Info: Scheduler step timings :                                                  [Scheduler][rank=0]
       metadata sync     : 48.42 us   (6.9%)
       patch tree reduce : 26.42 us   (3.7%)
       gen split merge   : 841.00 ns  (0.1%)
       split / merge op  : 0/0
       apply split merge : 1.14 us    (0.2%)
       LB compute        : 599.30 us  (85.1%)
       LB move op cnt    : 0
       LB apply          : 13.87 us   (2.0%)  
    Info: Scheduler step timings :                                                  [Scheduler][rank=0]
       metadata sync     : 2.83 us    (69.1%)  
    Warning: High interface/patch volume ratio.                                  [InterfaceGen][rank=0]
        This can lead to high mpi overhead, try to increase the patch split crit
        patch 0 high interf/patch volume: 0.8190104166666667  
    Warning: the unit system is not set                                           [sph::Config][rank=0] 
    Info: conservation infos :                                                     [sph::Model][rank=0]
        sum v = (0,0,0)
        sum a = (0,0,0)
        sum e = 0
        sum de = 0  
    Info: cfl dt = 1.7976931348623157e+308 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    | 6.8113e+04 | 11520 |      1 | 1.691e-01 | 0.0% |   1.0% 0.0% |   337.11 MB |     5.29 MB |
    +------+------------+-------+--------+-----------+------+-------------+-------------+-------------+  
    Info: estimated rate : 0 (tsim/hr)                                             [sph::Model][rank=0] 

    <shamrock.model_sph.TimestepLog object at 0x7f4c64ed6830>



.. GENERATED FROM PYTHON SOURCE LINES 144-145

Recover data

.. GENERATED FROM PYTHON SOURCE LINES 145-147

.. code-block:: Python
   :lineno-start: 145

    dat = ctx_new.collect_data()





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Info: collected : 1 patches                                                [PatchScheduler][rank=0] 




.. GENERATED FROM PYTHON SOURCE LINES 148-149

Test h value

.. GENERATED FROM PYTHON SOURCE LINES 149-163

.. code-block:: Python
   :lineno-start: 149

    import numpy as np

    min_hpart = np.min(dat["hpart"])
    max_hpart = np.max(dat["hpart"])
    mean_hpart = np.mean(dat["hpart"])

    print(f"hpart min={min_hpart} max={max_hpart} delta={max_hpart - min_hpart}")

    assert np.abs(max_hpart - min_hpart) < 1e-15, "hpart delta is too large"

    expected_h = (0.06688949833401844 + 0.06688949833401873) / 2

    assert np.abs(min_hpart - expected_h) < 1e-15, "hpart is off the expected value"





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    hpart min=0.06688949833401846 max=0.06688949833401873 delta=2.7755575615628914e-16




.. GENERATED FROM PYTHON SOURCE LINES 164-165

Plot particle distrib

.. GENERATED FROM PYTHON SOURCE LINES 165-188

.. code-block:: Python
   :lineno-start: 165

    import matplotlib
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D

    fig = plt.figure(dpi=120)
    ax = fig.add_subplot(111, projection="3d")
    ax.set_xlim3d(bmin[0], bmax[0])
    ax.set_ylim3d(bmin[1], bmax[1])
    ax.set_zlim3d(bmin[2], bmax[2])

    cm = matplotlib.colormaps["viridis"]
    sc = ax.scatter(
        dat["xyz"][:, 0],
        dat["xyz"][:, 1],
        dat["xyz"][:, 2],
        s=1,
        vmin=mean_hpart - 1e-10,
        vmax=mean_hpart + 1e-10,
        c=dat["hpart"],
        cmap=cm,
    )
    plt.colorbar(sc)
    plt.show()



.. image-sg:: /_as_gen/sph/images/sphx_glr_run_init_sim_from_other_001.png
   :alt: run init sim from other
   :srcset: /_as_gen/sph/images/sphx_glr_run_init_sim_from_other_001.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

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

**Estimated memory usage:**  168 MB


.. _sphx_glr_download__as_gen_sph_run_init_sim_from_other.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: run_init_sim_from_other.ipynb <run_init_sim_from_other.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: run_init_sim_from_other.py <run_init_sim_from_other.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: run_init_sim_from_other.zip <run_init_sim_from_other.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
