From 2558d44326fc60f044a07966dd225a945025e38a Mon Sep 17 00:00:00 2001 From: deegan Date: Fri, 25 Oct 2024 10:49:35 +0200 Subject: [PATCH] keep pyattrs on compute_from_hier --- .../pharesee/hierarchy/hierarchy_utils.py | 9 +++--- tests/simulator/test_run.py | 28 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py b/pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py index 95926cd3c..487dc8605 100644 --- a/pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py +++ b/pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py @@ -192,15 +192,16 @@ def new_patchdatas_from(compute, patchdatas, layout, id, **kwargs): def new_patches_from(compute, hierarchies, ilvl, t, **kwargs): reference_hier = hierarchies[0] new_patches = [] - patch_nbr = len(reference_hier.level(ilvl, time=t).patches) - for ip in range(patch_nbr): - current_patch = reference_hier.level(ilvl, time=t).patches[ip] + ref_patches = reference_hier.level(ilvl, time=t).patches + for ip, current_patch in enumerate(ref_patches): layout = current_patch.layout patch_datas = extract_patchdatas(hierarchies, ilvl, t, ip) new_patch_datas = new_patchdatas_from( compute, patch_datas, layout, id=current_patch.id, **kwargs ) - new_patches.append(Patch(new_patch_datas, current_patch.id)) + new_patches.append( + Patch(new_patch_datas, current_patch.id, attrs=current_patch.attrs) + ) return new_patches diff --git a/tests/simulator/test_run.py b/tests/simulator/test_run.py index f8a4e687e..f935e9768 100644 --- a/tests/simulator/test_run.py +++ b/tests/simulator/test_run.py @@ -1,26 +1,22 @@ #!/usr/bin/env python3 +import numpy as np from pathlib import Path +import matplotlib as mpl import pyphare.pharein as ph +from pyphare.cpp import cpp_lib from pyphare.simulator.simulator import Simulator, startMPI from pyphare.pharesee.run import Run - -import numpy as np - -import matplotlib as mpl - -mpl.use("Agg") - -from pyphare.cpp import cpp_lib from tests.simulator import SimulatorTest +mpl.use("Agg") cpp = cpp_lib() startMPI() time_step = 0.005 -final_time = 0.1 +final_time = 0.05 time_step_nbr = int(final_time / time_step) timestamps = np.arange(0, final_time + 0.01, 0.05) diag_dir = "phare_outputs/test_run" @@ -224,15 +220,25 @@ def test_run(self): sim = config() self.register_diag_dir_for_cleanup(diag_dir) Simulator(sim).run().reset() + + run = Run(diag_dir) + B = run.GetB(timestamps[-1], all_primal=False) + self.assertTrue(B.levels()[0].patches[0].attrs) + + B = run.GetB(timestamps[-1]) + self.assertTrue(B.levels()[0].patches[0].attrs) + if cpp.mpi_rank() == 0: plot(diag_dir) for time in timestamps: for q in ["divb", "Ranks", "N", "jz"]: assert_file_exists_with_size_at_least(plot_file_for_qty(q, time)) - + for c in ["x", "y", "z"]: - assert_file_exists_with_size_at_least(plot_file_for_qty(f"b{c}", time)) + assert_file_exists_with_size_at_least( + plot_file_for_qty(f"b{c}", time) + ) cpp.mpi_barrier()