Skip to content

Commit

Permalink
extract diff boxes fn
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Sep 25, 2021
1 parent de2b3b8 commit 1f78283
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
33 changes: 33 additions & 0 deletions pyphare/pyphare/core/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pyphare/pyphare/pharesee/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions pyphare/pyphare/pharesee/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ def copy(self):
from copy import deepcopy
return deepcopy(self)

def __copy__(self):
return self.copy()



class PatchLevel:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
25 changes: 5 additions & 20 deletions tests/simulator/test_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1f78283

Please sign in to comment.