Note
Go to the end to download the full example code.
Test the Phantom dump writer#
This example compares a phantom dump with one reproduced by Shamrock.
8 import shamrock
9
10 # If we use the shamrock executable to run this script instead of the python interpreter,
11 # we should not initialize the system as the shamrock executable needs to handle specific MPI logic
12 if not shamrock.sys.is_initialized():
13 shamrock.change_loglevel(1)
14 shamrock.sys.init("0:0")
15
16
17 print("-----------------------------------------------------------")
18 print("---------------- Dump compare utility -----------------")
19 print("-----------------------------------------------------------")
Load a reference dump
23 filename = input("Which phantom dump do you want to test ?")
24 dump_ref = shamrock.load_phantom_dump(filename)
25
26 dump_ref.print_state()
Start a SPH simulation from the phantom dump
30 ctx = shamrock.Context()
31 ctx.pdata_layout_new()
32 model = shamrock.get_Model_SPH(context=ctx, vector_type="f64_3", sph_kernel="M4")
33
34 cfg = model.gen_config_from_phantom_dump(dump_ref)
35 # Set the solver config to be the one stored in cfg
36 model.set_solver_config(cfg)
37 # Print the solver config
38 model.get_current_config().print_status()
39
40 model.init_scheduler(int(1e8), 1)
41
42 model.init_from_phantom_dump(dump_ref)
43
44 dump_2 = model.make_phantom_dump()
45 dump_2.print_state()
46
47 print("-----------------------------------------------------------")
48 print("----------------- Comparing the dumps -----------------")
49 print("-----------------------------------------------------------")
50 result_comp = shamrock.compare_phantom_dumps(dump_ref, dump_2)
51 print(f"Compare phantom dump result : {result_comp}")
52 print("-----------------------------------------------------------")
53 print("------------------------ Done -------------------------")
54 print("-----------------------------------------------------------")
55
56 if not result_comp:
57 exit("Dump mismatch reported")
Estimated memory usage: 0 MB