Skip to content

Commit

Permalink
:/
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Sep 11, 2024
1 parent 2e4e861 commit 686239f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 74 deletions.
29 changes: 4 additions & 25 deletions src/amr/data/field/initializers/samrai_hdf5_field_initializer.hpp
Original file line number Diff line number Diff line change
@@ -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 <memory>
#include <random>
#include <cassert>
#include <functional>

#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
{

Expand All @@ -45,15 +31,8 @@ template<typename Field_t, typename GridLayout>
void SamraiHDF5FieldInitializer<Field_t, GridLayout>::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<std::uint32_t, dimension> 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());
Expand All @@ -73,7 +52,7 @@ void SamraiHDF5FieldInitializer<Field_t, GridLayout>::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<c_ordering>(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));
}
Expand Down
17 changes: 2 additions & 15 deletions src/amr/data/initializers/samrai_hdf5_initializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,15 @@
#define _PHARE_AMR_DATA_INITIAZILIZERS_SAMRAI_HDF5_INITIALIZER_HPP_

#include <memory>
#include <random>
#include <cassert>
#include <functional>

#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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <memory>
#include <random>
#include <cassert>
#include <functional>

#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
Expand Down
12 changes: 9 additions & 3 deletions src/core/data/grid/gridlayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,24 +802,30 @@ namespace core
* This method only deals with **cell** indexes.
*/
template<typename T>
NO_DISCARD auto AMRToLocal(Point<T, dimension> AMRPoint) const
NO_DISCARD auto AMRToLocal(Point<T, dimension> const& AMRPoint,
Box<int, dimension> const& localbox) const
{
static_assert(std::is_integral_v<T>, "Error, must be MeshIndex (integral Point)");
Point<std::uint32_t, dimension> localPoint;

// 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<typename T>
NO_DISCARD auto AMRToLocal(Point<T, dimension> const& AMRPoint) const
{
return AMRToLocal(AMRPoint, AMRBox_);
}


/**
* @brief AMRToLocal returns the local Box associated with the given AMR one.
Expand Down
14 changes: 6 additions & 8 deletions tests/simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,23 @@ 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})
phare_mpi_python3_exec(9 4 diagnostics test_diagnostics.py ${CMAKE_CURRENT_BINARY_DIR})

# 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)
Expand Down
18 changes: 11 additions & 7 deletions tests/simulator/test_init_from_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
)

Expand All @@ -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


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

0 comments on commit 686239f

Please sign in to comment.