Skip to content

Commit

Permalink
rebase/activate some 3d python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Oct 3, 2021
1 parent 8d93286 commit 4bcae8e
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 81 deletions.
2 changes: 0 additions & 2 deletions pyphare/pyphare/pharein/maxwellian_fluid_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ def validate(self, sim):
from ..core.box import Box
from pyphare.pharein import py_fn_wrapper

dl = np.array(sim.dl)
directions = all_directions[:sim.ndim]

domain_box = Box([0] * sim.ndim, np.asarray(sim.cells) - 1)
assert len(sim.origin) == domain_box.ndim

Expand Down
3 changes: 3 additions & 0 deletions tests/simulator/advance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ if(HighFive)
phare_mpi_python3_exec(9 ${PHARE_MPI_PROCS} advance-2d-fields test_fields_advance_2d.py ${CMAKE_CURRENT_BINARY_DIR})
phare_mpi_python3_exec(9 ${PHARE_MPI_PROCS} advance-2d-particles test_particles_advance_2d.py ${CMAKE_CURRENT_BINARY_DIR})

phare_mpi_python3_exec(9 ${PHARE_MPI_PROCS} advance-3d-fields test_fields_advance_3d.py ${CMAKE_CURRENT_BINARY_DIR})
phare_mpi_python3_exec(9 ${PHARE_MPI_PROCS} advance-3d-particles test_particles_advance_3d.py ${CMAKE_CURRENT_BINARY_DIR})

endif()

endif()
58 changes: 29 additions & 29 deletions tests/simulator/advance/test_fields_advance_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

ndim = 3
interp_orders = [1, 2, 3]
ppc = 25
ppc, cells = 10, 30

def per_interp(dic):
return [(interp, dic) for interp in interp_orders]
Expand All @@ -33,7 +33,7 @@ def test_overlaped_fields_are_equal(self, interp_order, refinement_boxes):
time_step_nbr=3
time_step=0.001
diag_outputs=f"phare_overlaped_fields_are_equal_{ndim}_{self.ddt_test_id()}"
datahier = self.getHierarchy(interp_order, refinement_boxes, "eb", diag_outputs=diag_outputs,
datahier = self.getHierarchy(interp_order, refinement_boxes, "eb", diag_outputs=diag_outputs, cells=cells,
time_step=time_step, time_step_nbr=time_step_nbr, ndim=ndim, nbr_part_per_cell=ppc)
self._test_overlaped_fields_are_equal(datahier, time_step_nbr, time_step)

Expand All @@ -49,38 +49,38 @@ def test_overlaped_fields_are_equal_with_min_max_patch_size_of_max_ghosts(self,
time_step=0.001
from pyphare.pharein.simulation import check_patch_size
diag_outputs=f"phare_overlaped_fields_are_equal_with_min_max_patch_size_of_max_ghosts/{ndim}/{interp_order}/{self.ddt_test_id()}"
largest_patch_size, smallest_patch_size = check_patch_size(ndim, interp_order=interp_order, cells=[60] * ndim)
datahier = self.getHierarchy(interp_order, refinement_boxes, "eb", diag_outputs=diag_outputs,
largest_patch_size, smallest_patch_size = check_patch_size(ndim, interp_order=interp_order, cells=[cells] * ndim)
datahier = self.getHierarchy(interp_order, refinement_boxes, "eb", diag_outputs=diag_outputs, cells=cells,
smallest_patch_size=smallest_patch_size, largest_patch_size=smallest_patch_size,
time_step=time_step, time_step_nbr=time_step_nbr, ndim=ndim, nbr_part_per_cell=ppc)
self._test_overlaped_fields_are_equal(datahier, time_step_nbr, time_step)


@data(
*per_interp(({"L0": {"B0": Box3D(10, 14)}})),
*per_interp(({"L0": {"B0": Box3D(10, 14), "B1": Box3D(15, 19)}})),
*per_interp(({"L0": {"B0": Box3D(6, 23)}})),
*per_interp(({"L0": {"B0": Box3D( 2, 12), "B1": Box3D(13, 25)}})),
*per_interp(({"L0": {"B0": Box3D( 5, 20)}, "L1": {"B0": Box3D(15, 19)}})),
*per_interp(({"L0": {"B0": Box3D( 5, 20)}, "L1": {"B0": Box3D(12, 38)}, "L2": {"B0": Box3D(30, 52)} })),
)
@unpack
def test_field_coarsening_via_subcycles(self, interp_order, refinement_boxes):
print(f"{self._testMethodName}_{ndim}d")
self._test_field_coarsening_via_subcycles(ndim, interp_order, refinement_boxes, dl=.3)


@data( # only supports a hierarchy with 2 levels
# *per_interp(({"L0": [Box3D(0, 4)]})), # fails?
*per_interp(({"L0": [Box3D(10, 14)]})),
*per_interp(({"L0": [Box3D(0, 4), Box3D(10, 14)]})),
*per_interp(({"L0": [Box3D(0, 4), Box3D(5, 9), Box3D(10, 14)]})),
*per_interp(({"L0": [Box3D(20, 24)]})),
# *per_interp(({"L0": [Box3D(30, 34)]})), # fails?
)
@unpack
def test_field_level_ghosts_via_subcycles_and_coarser_interpolation(self, interp_order, refinement_boxes):
self._test_field_level_ghosts_via_subcycles_and_coarser_interpolation(ndim, interp_order, refinement_boxes)
# @data(
# *per_interp(({"L0": {"B0": Box3D(10, 14)}})),
# *per_interp(({"L0": {"B0": Box3D(10, 14), "B1": Box3D(15, 19)}})),
# *per_interp(({"L0": {"B0": Box3D(6, 23)}})),
# *per_interp(({"L0": {"B0": Box3D( 2, 12), "B1": Box3D(13, 25)}})),
# *per_interp(({"L0": {"B0": Box3D( 5, 20)}, "L1": {"B0": Box3D(15, 19)}})),
# *per_interp(({"L0": {"B0": Box3D( 5, 20)}, "L1": {"B0": Box3D(12, 38)}, "L2": {"B0": Box3D(30, 52)} })),
# )
# @unpack
# def test_field_coarsening_via_subcycles(self, interp_order, refinement_boxes):
# print(f"{self._testMethodName}_{ndim}d")
# self._test_field_coarsening_via_subcycles(ndim, interp_order, refinement_boxes, dl=.3)


# @data( # only supports a hierarchy with 2 levels
# # *per_interp(({"L0": [Box3D(0, 4)]})), # fails?
# *per_interp(({"L0": [Box3D(10, 14)]})),
# *per_interp(({"L0": [Box3D(0, 4), Box3D(10, 14)]})),
# *per_interp(({"L0": [Box3D(0, 4), Box3D(5, 9), Box3D(10, 14)]})),
# *per_interp(({"L0": [Box3D(20, 24)]})),
# # *per_interp(({"L0": [Box3D(30, 34)]})), # fails?
# )
# @unpack
# def test_field_level_ghosts_via_subcycles_and_coarser_interpolation(self, interp_order, refinement_boxes):
# self._test_field_level_ghosts_via_subcycles_and_coarser_interpolation(ndim, interp_order, refinement_boxes)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions tests/simulator/advance/test_particles_advance_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_overlapped_particledatas_have_identical_particles(self, interp_order, r
self._test_overlapped_particledatas_have_identical_particles(
ndim, interp_order, refinement_boxes, ppc=ppc, cells=40, largest_patch_size=20)


@data(*interp_orders)
def test_L0_particle_number_conservation(self, interp):
self._test_L0_particle_number_conservation(ndim, interp, ppc=ppc)
Expand Down
3 changes: 2 additions & 1 deletion tests/simulator/advance/test_particles_advance_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

ndim = 3
interp_orders = [1, 2, 3]
ppc = 25
ppc = 10

def per_interp(dic):
return [(interp, dic) for interp in interp_orders]
Expand All @@ -33,6 +33,7 @@ def test_overlapped_particledatas_have_identical_particles(self, interp_order, r
self._test_overlapped_particledatas_have_identical_particles(
ndim, interp_order, refinement_boxes, ppc=ppc, cells=40, largest_patch_size=20)


@data(*interp_orders)
def test_L0_particle_number_conservation(self, interp):
self._test_L0_particle_number_conservation(ndim, interp, ppc=ppc)
Expand Down
3 changes: 3 additions & 0 deletions tests/simulator/initialize/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ if(HighFive)
phare_mpi_python3_exec(9 ${PHARE_MPI_PROCS} init-2d-fields test_fields_init_2d.py ${CMAKE_CURRENT_BINARY_DIR})
phare_mpi_python3_exec(9 ${PHARE_MPI_PROCS} init-2d-particles test_particles_init_2d.py ${CMAKE_CURRENT_BINARY_DIR})

phare_mpi_python3_exec(9 ${PHARE_MPI_PROCS} init-3d-fields test_fields_init_3d.py ${CMAKE_CURRENT_BINARY_DIR})
phare_mpi_python3_exec(9 ${PHARE_MPI_PROCS} init-3d-particles test_particles_init_3d.py ${CMAKE_CURRENT_BINARY_DIR})

endif()

endif()
28 changes: 14 additions & 14 deletions tests/simulator/initialize/test_fields_init_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ def test_B_is_as_provided_by_user(self, interp_order):
print(f"\n{self._testMethodName}_{ndim}d")
self._test_B_is_as_provided_by_user(ndim, interp_order, nbr_part_per_cell=ppc)

@data(*interp_orders)
def test_bulkvel_is_as_provided_by_user(self, interp_order):
print(f"\n{self._testMethodName}_{ndim}d")
self._test_bulkvel_is_as_provided_by_user(ndim, interp_order)

@data(*interp_orders)
def test_density_is_as_provided_by_user(self, interp_order):
print(f"\n{self._testMethodName}_{ndim}d")
self._test_density_is_as_provided_by_user(ndim, interp_order)

@data(*interp_orders)
def test_density_decreases_as_1overSqrtN(self, interp_order):
print(f"\n{self._testMethodName}_{ndim}d")
self._test_density_decreases_as_1overSqrtN(ndim, interp_order)
# @data(*interp_orders)
# def test_bulkvel_is_as_provided_by_user(self, interp_order):
# print(f"\n{self._testMethodName}_{ndim}d")
# self._test_bulkvel_is_as_provided_by_user(ndim, interp_order)

# @data(*interp_orders)
# def test_density_is_as_provided_by_user(self, interp_order):
# print(f"\n{self._testMethodName}_{ndim}d")
# self._test_density_is_as_provided_by_user(ndim, interp_order)

# @data(*interp_orders)
# def test_density_decreases_as_1overSqrtN(self, interp_order):
# print(f"\n{self._testMethodName}_{ndim}d")
# self._test_density_decreases_as_1overSqrtN(ndim, interp_order)


if __name__ == "__main__":
Expand Down
38 changes: 19 additions & 19 deletions tests/simulator/initialize/test_particles_init_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class InitializationTest(InitializationTest):
@data(*interp_orders)
def test_nbr_particles_per_cell_is_as_provided(self, interp_order):
print(f"{self._testMethodName}_{ndim}d")
self._test_nbr_particles_per_cell_is_as_provided(ndim, interp_order)
self._test_nbr_particles_per_cell_is_as_provided(ndim, interp_order, ppc, cells=30)


@data(
Expand Down Expand Up @@ -70,24 +70,24 @@ def test_domainparticles_have_correct_split_from_coarser_particle(



@data({"cells": 40, "smallest_patch_size": 20, "largest_patch_size": 20, "nbr_part_per_cell" : ppc})
def test_no_patch_ghost_on_refined_level_case(self, simInput):
print(f"\n{self._testMethodName}_{ndim}d")
now = self.datetime_now()
self._test_patch_ghost_on_refined_level_case(ndim, False, **simInput)
print(f"\n{self._testMethodName}_{ndim}d took {self.datetime_diff(now)} seconds")

@data({"cells": 40, "interp_order": 1, "nbr_part_per_cell" : ppc})
def test_has_patch_ghost_on_refined_level_case(self, simInput):
print(f"\n{self._testMethodName}_{ndim}d")
from pyphare.pharein.simulation import check_patch_size
diag_outputs=f"phare_overlaped_fields_are_equal_with_min_max_patch_size_of_max_ghosts_{ndim}_{self.ddt_test_id()}"
_, smallest_patch_size = check_patch_size(ndim, **simInput)
simInput["smallest_patch_size"] = smallest_patch_size
simInput["largest_patch_size"] = smallest_patch_size
now = self.datetime_now()
self._test_patch_ghost_on_refined_level_case(ndim, True, **simInput)
print(f"\n{self._testMethodName}_{ndim}d took {self.datetime_diff(now)} seconds")
# @data({"cells": 40, "smallest_patch_size": 20, "largest_patch_size": 20, "nbr_part_per_cell" : ppc})
# def test_no_patch_ghost_on_refined_level_case(self, simInput):
# print(f"\n{self._testMethodName}_{ndim}d")
# now = self.datetime_now()
# self._test_patch_ghost_on_refined_level_case(ndim, False, **simInput)
# print(f"\n{self._testMethodName}_{ndim}d took {self.datetime_diff(now)} seconds")

# @data({"cells": 40, "interp_order": 1, "nbr_part_per_cell" : ppc})
# def test_has_patch_ghost_on_refined_level_case(self, simInput):
# print(f"\n{self._testMethodName}_{ndim}d")
# from pyphare.pharein.simulation import check_patch_size
# diag_outputs=f"phare_overlaped_fields_are_equal_with_min_max_patch_size_of_max_ghosts_{ndim}_{self.ddt_test_id()}"
# _, smallest_patch_size = check_patch_size(ndim, **simInput)
# simInput["smallest_patch_size"] = smallest_patch_size
# simInput["largest_patch_size"] = smallest_patch_size
# now = self.datetime_now()
# self._test_patch_ghost_on_refined_level_case(ndim, True, **simInput)
# print(f"\n{self._testMethodName}_{ndim}d took {self.datetime_diff(now)} seconds")


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions tests/simulator/test_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def vthz(*xyz):
return mom_hier




def base_test_overlaped_fields_are_equal(self, datahier, coarsest_time):
checks = 0
for ilvl, overlaps in hierarchy_overlaps(datahier, coarsest_time).items():
Expand Down Expand Up @@ -420,6 +422,8 @@ def _test_field_coarsening_via_subcycles(self, dim, interp_order, refinement_box
if dim == 2:
afterCoarse[dataBox.lower[0] : dataBox.upper[0] + 1,
dataBox.lower[1] : dataBox.upper[1] + 1] = -144123
if dim == 3:
assert False

coarsen(qty, coarse_pd, fine_pd, coarseBox, fine_pdDataset, afterCoarse)
np.testing.assert_allclose(coarse_pdDataset, afterCoarse, atol=1e-16, rtol=0)
Expand Down
10 changes: 6 additions & 4 deletions tests/simulator/test_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ def reshape(patch_data, nGhosts):
for vexp, vact in zip((vxexp, vyexp, vzexp), (vxact, vyact, vzact)):
self.assertTrue(np.std(vexp-vact) < 1e-2)


if dim == 3:
assert False



Expand Down Expand Up @@ -451,6 +452,8 @@ def _test_density_is_as_provided_by_user(self, dim, interp_order):
print("sigma(user density - {} density) = {}".format(name, dev))
self.assertLess(dev, 3e-2, '{} has dev = {}'.format(name, dev)) # empirical value obtained from test prints

if dim == 3:
assert False



Expand Down Expand Up @@ -500,7 +503,6 @@ def _test_density_decreases_as_1overSqrtN(self, dim, interp_order):
plt.close("all")



plt.figure()
plt.plot(nbr_particles, noise/noise[0], label=r"$\sigma/\sigma_0$")
plt.plot(nbr_particles, 1/np.sqrt(nbr_particles/nbr_particles[0]), label=r"$1/sqrt(nppc/nppc0)$")
Expand All @@ -523,10 +525,10 @@ def _test_density_decreases_as_1overSqrtN(self, dim, interp_order):



def _test_nbr_particles_per_cell_is_as_provided(self, dim, interp_order, default_ppc=100):
def _test_nbr_particles_per_cell_is_as_provided(self, dim, interp_order, default_ppc=100, **kwargs):
ddt_test_id = self.ddt_test_id()
datahier = self.getHierarchy(interp_order, {"L0": {"B0": nDBox(dim, 10, 20)}}, "particles", ndim=dim,
diag_outputs=f"ppc/{dim}/{interp_order}/{ddt_test_id}")
diag_outputs=f"ppc/{dim}/{interp_order}/{ddt_test_id}", **kwargs)

for patch in datahier.level(0).patches:
pd = patch.patch_datas["protons_particles"]
Expand Down
24 changes: 12 additions & 12 deletions tests/simulator/test_python_concurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ def test_cmd(clazz, test_id):
if __name__ == "__main__":

test_classes_to_run = [
# SimulatorValidation,
# InitField1d,
# InitParticles1d,
# AdvanceField1d,
# AdvanceParticles1d,
# InitField2d,
# InitParticles2d,
# AdvanceField2d,
# AdvanceParticles2d,
SimulatorValidation,
InitField1d,
InitParticles1d,
AdvanceField1d,
AdvanceParticles1d,
InitField2d,
InitParticles2d,
AdvanceField2d,
AdvanceParticles2d,
InitField3d,
# InitParticles3d,
# AdvanceField3d,
# AdvanceParticles3d
InitParticles3d,
AdvanceField3d,
AdvanceParticles3d
]

tests = []
Expand Down

0 comments on commit 4bcae8e

Please sign in to comment.