-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4777c7
commit e721d2a
Showing
13 changed files
with
501 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#ifndef _PHARE_AMR_DATA_ELECTROMAG_ELECTROMAG_INITIALIZER_HPP_ | ||
#define _PHARE_AMR_DATA_ELECTROMAG_ELECTROMAG_INITIALIZER_HPP_ | ||
|
||
// #include "core/data/electromag/electromag.hpp" | ||
|
||
#include "core/data/vecfield/vecfield_initializer.hpp" | ||
#include "amr/data/field/initializers/samrai_hdf5_field_initializer.hpp" | ||
#include "initializer/data_provider.hpp" | ||
|
||
|
||
#include <array> | ||
|
||
namespace PHARE::amr | ||
{ | ||
|
||
template<typename Electromag_t, typename GridLayout> | ||
class ElectromagInitializer | ||
{ | ||
public: | ||
virtual void init(Electromag_t& /*em*/, GridLayout const& /*layout*/) const { /*noop*/ } | ||
virtual ~ElectromagInitializer() {} | ||
}; | ||
|
||
template<typename Electromag_t, typename GridLayout> | ||
class ElectromagUserFuncInitializer : public ElectromagInitializer<Electromag_t, GridLayout> | ||
{ | ||
using VecFieldInit = core::VecFieldInitializer<Electromag_t::dimension>; | ||
|
||
public: | ||
ElectromagUserFuncInitializer(initializer::PHAREDict const& dict) | ||
: Binit_{dict["magnetic"]["initializer"]} | ||
{ | ||
} | ||
virtual ~ElectromagUserFuncInitializer() {} | ||
|
||
void init(Electromag_t& em, GridLayout const& layout) const override | ||
{ | ||
Binit_.initialize(em.B, layout); | ||
} | ||
|
||
VecFieldInit Binit_; | ||
}; | ||
|
||
|
||
/* | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/EM_B_y##default/d_box | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/EM_B_x##default/field_EM_B_x | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/EM_B_y##default/field_EM_B_y | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/EM_B_z##default/field_EM_B_z | ||
*/ | ||
|
||
|
||
template<typename Electromag_t, typename GridLayout> | ||
class ElectromagSamraiH5Initializer : public ElectromagInitializer<Electromag_t, GridLayout> | ||
{ | ||
using vecfield_type = typename Electromag_t::vecfield_type; | ||
using field_type = typename vecfield_type::field_type; | ||
|
||
|
||
public: | ||
ElectromagSamraiH5Initializer(initializer::PHAREDict const& dict) | ||
: dict_{dict} | ||
{ | ||
} | ||
virtual ~ElectromagSamraiH5Initializer() {} | ||
|
||
void init(Electromag_t& em, GridLayout const& layout) const override | ||
{ | ||
for (auto& field : em.B) | ||
SamraiHDF5FieldInitializer<field_type, GridLayout>{}.load(field, layout); | ||
} | ||
|
||
initializer::PHAREDict const dict_; | ||
}; | ||
|
||
|
||
|
||
class ElectromagInitializerFactory | ||
{ | ||
public: | ||
template<typename Electromag_t, typename GridLayout> | ||
NO_DISCARD static std::unique_ptr<ElectromagInitializer<Electromag_t, GridLayout>> | ||
create(initializer::PHAREDict const& dict) | ||
{ | ||
if (dict["magnetic"]["initializer"].contains("x_component")) | ||
return std::make_unique<ElectromagUserFuncInitializer<Electromag_t, GridLayout>>(dict); | ||
else | ||
return std::make_unique<ElectromagSamraiH5Initializer<Electromag_t, GridLayout>>(dict); | ||
} | ||
}; | ||
|
||
} // namespace PHARE::amr | ||
|
||
#endif // _PHARE_AMR_DATA_ELECTROMAG_ELECTROMAG_INITIALIZER_HPP_ |
56 changes: 56 additions & 0 deletions
56
src/amr/data/field/initializers/samrai_hdf5_field_initializer.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#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/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 "hdf5/detail/h5/h5_file.hpp" | ||
|
||
|
||
#include "SAMRAI/hier/PatchDataRestartManager.h" | ||
|
||
#include "amr/data/initializers/samrai_hdf5_initializer.hpp" | ||
|
||
|
||
namespace PHARE::amr | ||
{ | ||
|
||
|
||
template<typename Field_t, typename GridLayout> | ||
class SamraiHDF5FieldInitializer // no virtual classes needed (yet) | ||
{ | ||
public: | ||
static constexpr auto dimension = GridLayout::dimension; | ||
|
||
SamraiHDF5FieldInitializer() {} | ||
|
||
void load(Field_t& Field, GridLayout const& layout) const; | ||
}; | ||
|
||
|
||
|
||
template<typename Field_t, typename GridLayout> | ||
void SamraiHDF5FieldInitializer<Field_t, GridLayout>::load(Field_t& field, | ||
GridLayout const& layout) const | ||
{ | ||
PHARE_LOG_LINE_STR("SamraiHDF5FieldInitializer::loadParticles"); | ||
} | ||
|
||
|
||
|
||
} // namespace PHARE::amr | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
#ifndef _PHARE_AMR_DATA_INITIAZILIZERS_SAMRAI_HDF5_INITIALIZER_HPP_ | ||
#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 "hdf5/detail/h5/h5_file.hpp" | ||
#include "amr/utilities/box/amr_box.hpp" | ||
|
||
#include "SAMRAI/hier/PatchDataRestartManager.h" | ||
|
||
|
||
namespace PHARE::amr | ||
{ | ||
|
||
/* | ||
example paths | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/protons##default/d_box | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/protons##default/d_ghost_box | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/protons##default/d_ghosts | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/protons##default/d_timestamp | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/protons##default/domainParticles_charge | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/protons##default/domainParticles_delta | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/protons##default/domainParticles_iCell | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/protons##default/domainParticles_v | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/protons##default/domainParticles_weight | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/EM_B_y##default/d_box | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/EM_B_x##default/field_EM_B_x | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/EM_B_y##default/field_EM_B_y | ||
/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/EM_B_z##default/field_EM_B_z | ||
*/ | ||
|
||
|
||
template<typename ParticleArray, typename GridLayout> | ||
class SamraiH5Interface | ||
{ | ||
struct SamraiHDF5File; // : PHARE::hdf5::h5::HighFiveFile; | ||
|
||
public: | ||
static SamraiH5Interface& INSTANCE() | ||
{ | ||
static SamraiH5Interface i; | ||
return i; | ||
} | ||
|
||
void populate_from(std::string const& dir, int const& idx, int const& mpi_size); | ||
|
||
NO_DISCARD auto static getRestartFileFullPath(std::string path, int const& idx, | ||
int const& mpi_size, int const& rank) | ||
{ | ||
return path // | ||
+ "/restore." + SAMRAI::tbox::Utilities::intToString(idx, 6) // | ||
+ "/nodes." + SAMRAI::tbox::Utilities::nodeToString(mpi_size) // | ||
+ "/proc." + SAMRAI::tbox::Utilities::processorToString(rank); | ||
} | ||
|
||
|
||
|
||
private: | ||
std::vector<std::unique_ptr<SamraiHDF5File>> restart_files; | ||
std::unordered_map<std::string, std::string> box2dataset; | ||
}; | ||
|
||
template<typename ParticleArray, typename GridLayout> | ||
struct SamraiH5Interface<ParticleArray, GridLayout>::SamraiHDF5File : public hdf5::h5::HighFiveFile | ||
{ | ||
using Super = hdf5::h5::HighFiveFile; | ||
using Box_t = core::Box<int, ParticleArray::dimension>; | ||
|
||
SamraiHDF5File(std::string const& filepath) | ||
: Super{filepath, HighFive::File::ReadOnly, /*para=*/false} | ||
{ | ||
// auto box_type = box_compound_type(); | ||
// box_type.commit(file(), "d_box"); | ||
|
||
// getBoxFromPath("/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/" | ||
// "EM_B_y##default/d_box"); | ||
} | ||
|
||
|
||
|
||
/* | ||
DATASET "d_box" { | ||
DATATYPE H5T_COMPOUND { | ||
H5T_STD_I32BE "dim"; | ||
H5T_ARRAY { [3] H5T_STD_I32BE } "lo"; | ||
H5T_ARRAY { [3] H5T_STD_I32BE } "hi"; | ||
} | ||
DATASPACE SIMPLE { ( 1 ) / ( 1 ) } | ||
DATA { | ||
(0): { | ||
1, | ||
[ 0, 0, 0 ], | ||
[ 199, 0, 0 ] | ||
} | ||
} | ||
ATTRIBUTE "Type" { | ||
DATATYPE H5T_STD_I8BE | ||
DATASPACE SCALAR | ||
DATA { | ||
(0): 2 | ||
} | ||
} | ||
} | ||
*/ | ||
|
||
struct BoxData | ||
{ | ||
std::int32_t dim; | ||
std::array<std::int32_t, 3> lo; | ||
std::array<std::int32_t, 3> hi; | ||
}; | ||
|
||
// struct BoxData | ||
// { | ||
// int dim; | ||
// int lo0, lo1, lo2; | ||
// int hi0, hi1, hi2; | ||
// }; | ||
|
||
HighFive::CompoundType static box_compound_type() | ||
{ | ||
return {{"dim", HighFive::create_datatype<std::int32_t>()}, | ||
{"lo", HighFive::create_datatype<std::array<std::int32_t, 3>>()}, | ||
{"hi", HighFive::create_datatype<std::array<std::int32_t, 3>>()}}; | ||
} | ||
|
||
auto getBoxFromPath(std::string const& path) const | ||
{ | ||
// auto const& data = Super::read_data_set<int>(path); | ||
// PHARE_LOG_LINE_STR(data.size()); | ||
std::vector<BoxData> boxes; | ||
Super::file().getDataSet(path).read(boxes); | ||
assert(boxes.size() == 1); | ||
|
||
// auto const& bx = boxes[0]; | ||
// return Box_t{core::as_sized_array<ParticleArray::dimension>(bx.lo0, bx.lo1, bx.lo2), | ||
// core::as_sized_array<ParticleArray::dimension>(bx.hi0, bx.hi1, bx.hi2)}; | ||
|
||
return Box_t{core::sized_array<ParticleArray::dimension>(boxes[0].lo), | ||
core::sized_array<ParticleArray::dimension>(boxes[0].hi)}; | ||
} | ||
}; | ||
|
||
|
||
|
||
template<typename ParticleArray, typename GridLayout> | ||
void SamraiH5Interface<ParticleArray, GridLayout>::populate_from(std::string const& dir, | ||
int const& idx, | ||
int const& mpi_size) | ||
{ | ||
for (int rank = 0; rank < mpi_size; ++rank) | ||
{ | ||
auto const hdf5_filepath = getRestartFileFullPath(dir, idx, mpi_size, rank); | ||
|
||
hdf5::h5::HighFiveFile h5File{hdf5_filepath, HighFive::File::ReadOnly, /*para=*/false}; | ||
|
||
PHARE_LOG_LINE_STR("SamraiH5Interface::populate_from"); | ||
|
||
auto groups = h5File.scan_for_groups({"level_0000", "domainParticles_charge"}); | ||
|
||
for (auto const& g : groups) | ||
{ | ||
PHARE_LOG_LINE_STR(g); | ||
} | ||
|
||
restart_files.emplace_back(std::make_unique<SamraiHDF5File>(hdf5_filepath)); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
} // namespace PHARE::amr | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.