diff --git a/pyphare/pyphare/core/box.py b/pyphare/pyphare/core/box.py index 15d5e571d..3b5faab6a 100644 --- a/pyphare/pyphare/core/box.py +++ b/pyphare/pyphare/core/box.py @@ -185,3 +185,36 @@ def copy(arr, replace): def amr_to_local(box, ref_box): return Box(box.lower - ref_box.lower, box.upper - ref_box.lower) + + + +def diff_boxes(self, slice1, slice2, box, atol=None): + if atol is not None: + ignore = np.isclose(slice1, slice2, atol=atol, rtol=0) + def _diff(slice0): + slice0[ignore] = 0 # set values which are within atol range to 0 + return slice0 + diff = np.abs(_diff(slice1.copy()) - _diff(slice2.copy())) + else: + diff = np.abs(slice1 - slice2) + + boxes = [] + if box.ndim == 1: + x1 = np.where(diff != 0) + for x in zip(x1): + x = x+box.lower[0] + boxes += [Box([x], [x])] + elif box.ndim == 2: + x1, y1 = np.where(diff != 0) + for x, y in zip(x1, y1): + x = x+box.lower[0] + y = y+box.lower[1] + boxes += [Box([x, y], [x, y])] + elif box.ndim == 3: + x1, y1, z1 = np.where(diff != 0) + for x, y, z in zip(x1, y1, z1): + x = x+box.lower[0] + y = y+box.lower[1] + z = y+box.lower[2] + boxes += [Box([x, y, z], [x, y, z])] + return boxes diff --git a/pyphare/pyphare/pharesee/geometry.py b/pyphare/pyphare/pharesee/geometry.py index 1f6a87b4f..d259fa8a6 100644 --- a/pyphare/pyphare/pharesee/geometry.py +++ b/pyphare/pyphare/pharesee/geometry.py @@ -298,7 +298,7 @@ def borders_per(box): if in_sides in shifts: # in_sides might be empty, so no borders for shift in shifts[in_sides]: - patch_copy = patch.copy() + patch_copy = copy(patch) shift_patch(patch_copy, shift) sorted_patches.append(patch_copy) diff --git a/pyphare/pyphare/pharesee/hierarchy.py b/pyphare/pyphare/pharesee/hierarchy.py index 57cdf9665..cfaf1dcb4 100644 --- a/pyphare/pyphare/pharesee/hierarchy.py +++ b/pyphare/pyphare/pharesee/hierarchy.py @@ -208,6 +208,9 @@ def copy(self): from copy import deepcopy return deepcopy(self) + def __copy__(self): + return self.copy() + class PatchLevel: diff --git a/src/amr/data/field/time_interpolate/field_linear_time_interpolate.h b/src/amr/data/field/time_interpolate/field_linear_time_interpolate.h index 75f5db7b3..93f4d2c6d 100644 --- a/src/amr/data/field/time_interpolate/field_linear_time_interpolate.h +++ b/src/amr/data/field/time_interpolate/field_linear_time_interpolate.h @@ -40,7 +40,7 @@ class FieldLinearTimeInterpolate : public SAMRAI::hier::TimeInterpolateOperator void timeInterpolate(SAMRAI::hier::PatchData& destData, SAMRAI::hier::Box const& where, - SAMRAI::hier::BoxOverlap const& /*overlap_*/, + SAMRAI::hier::BoxOverlap const& /*overlap*/, SAMRAI::hier::PatchData const& srcDataOld, SAMRAI::hier::PatchData const& srcDataNew) const override { diff --git a/tests/simulator/test_advance.py b/tests/simulator/test_advance.py index b3e35885c..0827fb1d3 100644 --- a/tests/simulator/test_advance.py +++ b/tests/simulator/test_advance.py @@ -250,7 +250,7 @@ def base_test_overlaped_fields_are_equal(self, datahier, coarsest_time): print("AssertionError", pd1.name, e) if self.rethrow_: raise e - return self._diffBoxes(slice1, slice2, box) + return boxm.diff_boxes(slice1, slice2, box) return checks @@ -410,6 +410,7 @@ def _test_field_coarsening_via_subcycles(self, dim, interp_order, refinement_box afterCoarse = np.copy(coarse_pdDataset) # change values that should be updated to make failure obvious + assert(dim < 3) # update if dim == 1: afterCoarse[dataBox.lower[0] : dataBox.upper[0] + 1] = -144123 if dim == 2: @@ -419,23 +420,7 @@ def _test_field_coarsening_via_subcycles(self, dim, interp_order, refinement_box coarsen(qty, coarse_pd, fine_pd, coarseBox, fine_pdDataset, afterCoarse) np.testing.assert_allclose(coarse_pdDataset, afterCoarse, atol=1e-16, rtol=0) - def _diffBoxes(self, slice1, slice2, box, atol=None): - if atol is not None: - ignore = np.isclose(slice1, slice2, atol=atol, rtol=0) - def _diff(slice0): - slice0[ignore] = 0 # set values which are within atol range to 0 - return slice0 - diff = np.abs(_diff(slice1.copy()) - _diff(slice2.copy())) - else: - diff = np.abs(slice1 - slice2) - where = np.where(diff != 0) - boxes = [] - x1, y1 = where - for x, y in zip(x1, y1): - x = x+box.lower[0] - y = y+box.lower[1] - boxes += [Box([x, y], [x, y])] - return boxes + def base_test_field_level_ghosts_via_subcycles_and_coarser_interpolation(self, L0_datahier, L0L1_datahier, quantities=None): @@ -463,7 +448,7 @@ def assert_time_in_hier(*ts): fine_subcycle_times = [] for fine_subcycle in range(global_vars.sim.level_step_nbr[fine_ilvl] + 1): - fine_subcycle_time = coarsest_time_before + (lvl_steps[fine_ilvl] * fine_subcycle) + fine_subcycle_time = coarsest_time_before + (lvl_steps[fine_ilvl] * fine_subcycle) assert_time_in_hier(fine_subcycle_time) fine_subcycle_times += [fine_subcycle_time] @@ -517,7 +502,7 @@ def assert_time_in_hier(*ts): print(f"FAIL level ghost subcycle_coarsening qty {qty}", e) if self.rethrow_: raise e - error_boxes += self._diffBoxes(fine_ghostbox_data, refinedInterpGhostBox_data, box, atol=1e-15) + error_boxes += boxm.diff_boxes(fine_ghostbox_data, refinedInterpGhostBox_data, box, atol=1e-15) checks += 1 if len(error_boxes): return error_boxes return checks