diff --git a/src/amr/data/field/initializers/samrai_hdf5_field_initializer.hpp b/src/amr/data/field/initializers/samrai_hdf5_field_initializer.hpp index 470edd773..bb0184a74 100644 --- a/src/amr/data/field/initializers/samrai_hdf5_field_initializer.hpp +++ b/src/amr/data/field/initializers/samrai_hdf5_field_initializer.hpp @@ -1,30 +1,16 @@ #ifndef _PHARE_AMR_DATA_FIELD_INITIAZILIZERS_SAMRAI_HDF5_INITIALIZER_HPP_ #define _PHARE_AMR_DATA_FIELD_INITIAZILIZERS_SAMRAI_HDF5_INITIALIZER_HPP_ -#include -#include #include -#include -#include "core/def.hpp" -#include "core/logger.hpp" #include "core/data/grid/gridlayoutdefs.hpp" #include "core/data/ndarray/ndarray_vector.hpp" -#include "core/hybrid/hybrid_quantities.hpp" + #include "core/utilities/types.hpp" -#include "core/data/ions/particle_initializers/particle_initializer.hpp" -#include "core/data/particles/particle.hpp" -#include "initializer/data_provider.hpp" #include "core/utilities/point/point.hpp" -#include "hdf5/detail/h5/h5_file.hpp" - - -#include "SAMRAI/hier/PatchDataRestartManager.h" - #include "amr/data/initializers/samrai_hdf5_initializer.hpp" - namespace PHARE::amr { @@ -45,15 +31,8 @@ template void SamraiHDF5FieldInitializer::load(Field_t& field, GridLayout const& layout) const { - bool static constexpr c_ordering = false; - - auto const local_cell = [&](auto const& box, auto const& point) { - core::Point localPoint; - auto localStart = layout.physicalStartIndex(core::QtyCentering::dual, core::Direction::X); - for (std::size_t i = 0; i < dimension; ++i) - localPoint[i] = point[i] - (box.lower[i] - localStart); - return localPoint; - }; + auto const local_cell + = [&](auto const& box, auto const& point) { return layout.AMRToLocal(point, box); }; auto const& dest_box = layout.AMRBox(); auto const& centering = layout.centering(field.physicalQuantity()); @@ -73,7 +52,7 @@ void SamraiHDF5FieldInitializer::load(Field_t& field, src_box.upper[i] - src_box.lower[i] + (GridLayout::nbrGhosts() * 2) + (centering[i] == core::QtyCentering::primal ? 1 : 0)); })}}; - auto data_view = core::make_array_view(data.data(), *lcl_src_box.shape()); + auto data_view = core::make_array_view(data.data(), *lcl_src_box.shape()); for (auto const& point : overlap_box) field(local_cell(dest_box, point)) = data_view(local_cell(src_box, point)); } diff --git a/src/amr/data/initializers/samrai_hdf5_initializer.hpp b/src/amr/data/initializers/samrai_hdf5_initializer.hpp index e3f1f2fb2..c2c0c4305 100644 --- a/src/amr/data/initializers/samrai_hdf5_initializer.hpp +++ b/src/amr/data/initializers/samrai_hdf5_initializer.hpp @@ -2,28 +2,15 @@ #define _PHARE_AMR_DATA_INITIAZILIZERS_SAMRAI_HDF5_INITIALIZER_HPP_ #include -#include #include -#include -#include "core/data/grid/gridlayoutdefs.hpp" -#include "core/hybrid/hybrid_quantities.hpp" -#include "core/utilities/types.hpp" -#include "core/data/ions/particle_initializers/particle_initializer.hpp" -#include "core/data/particles/particle.hpp" -#include "initializer/data_provider.hpp" -#include "core/utilities/point/point.hpp" #include "core/def.hpp" -#include "core/logger.hpp" - +#include "core/utilities/types.hpp" +#include "core/utilities/box/box.hpp" #include "hdf5/detail/h5/h5_file.hpp" #include "SAMRAI/tbox/HDFDatabase.h" -#include "amr/utilities/box/amr_box.hpp" - -#include "SAMRAI/hier/PatchDataRestartManager.h" - namespace PHARE::amr { diff --git a/src/amr/data/particles/initializers/samrai_hdf5_particle_initializer.hpp b/src/amr/data/particles/initializers/samrai_hdf5_particle_initializer.hpp index 514af9257..2cbb30339 100644 --- a/src/amr/data/particles/initializers/samrai_hdf5_particle_initializer.hpp +++ b/src/amr/data/particles/initializers/samrai_hdf5_particle_initializer.hpp @@ -1,28 +1,15 @@ #ifndef _PHARE_AMR_DATA_PARTICLE_INITIAZILIZERS_SAMRAI_HDF5_INITIALIZER_HPP_ #define _PHARE_AMR_DATA_PARTICLE_INITIAZILIZERS_SAMRAI_HDF5_INITIALIZER_HPP_ -#include -#include #include -#include -#include "core/def.hpp" -#include "core/logger.hpp" -#include "core/utilities/box/box.hpp" - -#include "core/data/grid/gridlayoutdefs.hpp" -#include "core/hybrid/hybrid_quantities.hpp" #include "core/utilities/types.hpp" -#include "core/data/ions/particle_initializers/particle_initializer.hpp" -#include "core/data/particles/particle.hpp" -#include "initializer/data_provider.hpp" +#include "core/utilities/box/box.hpp" #include "core/utilities/point/point.hpp" - - -#include "hdf5/detail/h5/h5_file.hpp" +#include "core/data/ions/particle_initializers/particle_initializer.hpp" #include "core/data/particles/particle_packer.hpp" -#include "amr/data/field/initializers/samrai_hdf5_field_initializer.hpp" +#include "amr/data/initializers/samrai_hdf5_initializer.hpp" namespace PHARE::amr diff --git a/src/core/data/grid/gridlayout.hpp b/src/core/data/grid/gridlayout.hpp index d0f076f0a..564bf909c 100644 --- a/src/core/data/grid/gridlayout.hpp +++ b/src/core/data/grid/gridlayout.hpp @@ -802,7 +802,8 @@ namespace core * This method only deals with **cell** indexes. */ template - NO_DISCARD auto AMRToLocal(Point AMRPoint) const + NO_DISCARD auto AMRToLocal(Point const& AMRPoint, + Box const& localbox) const { static_assert(std::is_integral_v, "Error, must be MeshIndex (integral Point)"); Point localPoint; @@ -810,16 +811,21 @@ namespace core // any direction, it's the same because we want cells auto localStart = physicalStartIndex(QtyCentering::dual, Direction::X); - // for (auto i = 0u; i < dimension; ++i) { - int local = AMRPoint[i] - (AMRBox_.lower[i] - localStart); + int local = AMRPoint[i] - (localbox.lower[i] - localStart); assert(local >= 0); localPoint[i] = local; } return localPoint; } + template + NO_DISCARD auto AMRToLocal(Point const& AMRPoint) const + { + return AMRToLocal(AMRPoint, AMRBox_); + } + /** * @brief AMRToLocal returns the local Box associated with the given AMR one. diff --git a/tests/simulator/CMakeLists.txt b/tests/simulator/CMakeLists.txt index 3a22a667c..72d6f1296 100644 --- a/tests/simulator/CMakeLists.txt +++ b/tests/simulator/CMakeLists.txt @@ -14,11 +14,10 @@ add_no_mpi_python3_test(periodicity test_init_periodicity.py ${CMAKE_CURRENT_BIN if(HighFive) ## These test use dump diagnostics so require HighFive! - phare_python3_exec(9 diagnostics test_diagnostics.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2 - phare_python3_exec(9 restarts test_restarts.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2 - phare_python3_exec(9 run test_run.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2 - - # phare_python3_exec(9 tagging test_tagging.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2 + phare_python3_exec(9 diagnostics test_diagnostics.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2 + phare_python3_exec(9 restarts test_restarts.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2 + phare_python3_exec(9 run test_run.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2 + # phare_python3_exec(9 tagging test_tagging.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2 if(testMPI) phare_mpi_python3_exec(9 3 diagnostics test_diagnostics.py ${CMAKE_CURRENT_BINARY_DIR}) @@ -26,13 +25,12 @@ if(HighFive) # doesn't make sense in serial phare_mpi_python3_exec(9 3 load_balancing test_load_balancing.py ${CMAKE_CURRENT_BINARY_DIR}) + + phare_mpi_python3_exec(9 2 initing test_init_from_restart.py ${CMAKE_CURRENT_BINARY_DIR}) endif(testMPI) phare_python3_exec(11, test_diagnostic_timestamps test_diagnostic_timestamps.py ${CMAKE_CURRENT_BINARY_DIR}) - if(NOT lowResourceTests) - phare_python3_exec(9 initing test_init_from_restart.py ${CMAKE_CURRENT_BINARY_DIR}) - endif() endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.py ${CMAKE_CURRENT_BINARY_DIR}/config.py @ONLY) diff --git a/tests/simulator/test_init_from_restart.py b/tests/simulator/test_init_from_restart.py index 48efb7b2e..f18da1433 100644 --- a/tests/simulator/test_init_from_restart.py +++ b/tests/simulator/test_init_from_restart.py @@ -15,19 +15,21 @@ from tests.diagnostic import dump_all_diags timestep = 0.001 -first_mpi_size = 4 +time_step_nbr = 1 +first_mpi_size = 1 ppc = 100 cells = 200 first_out = "phare_outputs/reinit/first" secnd_out = "phare_outputs/reinit/secnd" -timestamps = np.array([timestep * 4]) +timestamps = [0] # np.array([timestep * 2, timestep * 4]) +restart_idx = Z = 0 simInitArgs = dict( - largest_patch_size=100, - time_step_nbr=5, + # largest_patch_size=100, + time_step_nbr=time_step_nbr, time_step=timestep, cells=cells, dl=0.3, - init_options=dict(dir=f"{first_out}/00000.00400", mpi_size=first_mpi_size), + init_options=dict(dir=f"{first_out}/00000.00{Z}00", mpi_size=first_mpi_size), diag_options=dict(format="phareh5", options=dict(dir=secnd_out, mode="overwrite")), ) @@ -38,7 +40,7 @@ def setup_model(sim): alpha={"mass": 4.0, "charge": 1, "nbr_part_per_cell": ppc}, ) ph.ElectronModel(closure="isothermal", Te=0.12) - dump_all_diags(model.populations, timestamps) + dump_all_diags(model.populations, timestamps=timestamps) return model @@ -68,7 +70,7 @@ def test_reinit(self): phut.assert_fp_any_all_close(a, b) def get_merged(hier): - return single_patch_per_level_per_pop_from(datahier0) + return single_patch_per_level_per_pop_from(hier) ds = [get_merged(datahier0), get_merged(datahier1)] for key in ["alpha", "protons"]: @@ -78,6 +80,7 @@ def get_merged(hier): def run_first_sim(): + """uses params from tests_restarts.py""" simput = copy.deepcopy(test_restarts.simArgs) simput["restart_options"]["dir"] = first_out simput["restart_options"]["timestamps"] = timestamps @@ -88,6 +91,7 @@ def run_first_sim(): def launch(): + """Launch secondary process to run first simulation to avoid initalizing MPI now""" cmd = f"mpirun -n {first_mpi_size} python3 -O tests/simulator/test_init_from_restart.py lol" proc = subprocess.run(cmd.split(" "), check=True, capture_output=True) return (proc.stdout + proc.stderr).decode().strip()