Skip to content

Commit

Permalink
serialized phare dict
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Oct 29, 2024
1 parent e61b34c commit 2f32ac1
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 7 deletions.
9 changes: 6 additions & 3 deletions res/cmake/dep/cppdict.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@


set(CPPDICT_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/cppdict)
set(CPPDICT_VERSION master)
phare_github_get_or_update(cppdict ${CPPDICT_SRCDIR} LaboratoryOfPlasmaPhysics/cppdict ${CPPDICT_VERSION})
if(NOT DEFINED PHARE_CPPDICT_VERION)
SET(PHARE_CPPDICT_VERION "superserial")
endif()

set(CPPDICT_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/cppdict)
# phare_github_get_or_update(cppdict ${CPPDICT_SRCDIR} LaboratoryOfPlasmaPhysics/cppdict ${PHARE_CPPDICT_VERION})
phare_github_get_or_update(cppdict ${CPPDICT_SRCDIR} PhilipDeegan/cppdict ${PHARE_CPPDICT_VERION})
7 changes: 5 additions & 2 deletions res/cmake/dep/highfive.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
set (PHARE_HAS_HIGHFIVE "0")
if(HighFive)

if(NOT DEFINED PHARE_HIGHFIVE_VERSION)
SET(PHARE_HIGHFIVE_VERSION "master")
endif()

set (HIGHFIVE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/highfive)
set (HIGHFIVE_VERSION master)

phare_github_get_or_update(HighFive ${HIGHFIVE_SRC} BlueBrain/HighFive ${HIGHFIVE_VERSION})
phare_github_get_or_update(HighFive ${HIGHFIVE_SRC} BlueBrain/HighFive ${PHARE_HIGHFIVE_VERSION})

include_directories(
${HIGHFIVE_SRC}/include
Expand Down
4 changes: 4 additions & 0 deletions res/cmake/dep/pybind.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ function(get_pybind)
set (PHARE_FLAGS ${PHARE_FLAGS} -fsized-deallocation)
endif()

if(NOT DEFINED PHARE_PYBIND11_VERSION)
SET(PHARE_PYBIND11_VERSION "master")
endif()

message("downloading subproject pybind11")
set(PYBIND11_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/pybind11)
set(PYBIND11_VERSION master)
Expand Down
8 changes: 6 additions & 2 deletions res/cmake/dep/samrai.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ if (NOT SAMRAI_FOUND)
if(DEFINED SAMRAI_ROOT)
find_package(SAMRAI PATHS ${SAMRAI_ROOT} REQUIRED)
else()
set(SAMRAI_VERSION develop)

if(NOT DEFINED PHARE_SAMRAI_VERSION)
SET(PHARE_SAMRAI_VERSION "develop")
endif()

set(SAMRAI_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/samrai)
set(SAMRAI_BIN ${CMAKE_CURRENT_BINARY_DIR}/subprojects/samrai)

phare_github_get_or_update(SAMRAI ${SAMRAI_SRCDIR} LLNL/SAMRAI ${SAMRAI_VERSION})
phare_github_get_or_update(SAMRAI ${SAMRAI_SRCDIR} LLNL/SAMRAI ${PHARE_SAMRAI_VERSION})

if (NOT CMAKE_BUILD_TYPE STREQUAL "Release")
# enable samrai assertions if not in release mode
Expand Down
12 changes: 12 additions & 0 deletions res/cmake/release.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# https://github.com/LLNL/SAMRAI/releases/tag/v-4-3-0
SET(PHARE_SAMRAI_VERSION "v4.3.0")

# https://github.com/pybind/pybind11/releases/tag/v2.13.6
SET(PHARE_PYBIND11_VERSION "v2.13.6")

# https://github.com/BlueBrain/HighFive/releases/tag/v2.10.0
SET(PHARE_HIGHFIVE_VERSION "v2.10.0")

# https://github.com/LaboratoryOfPlasmaPhysics/cppdict/releases/tag/v1.0.0
SET(PHARE_CPPDICT_VERION "v1.0.0")
29 changes: 29 additions & 0 deletions src/initializer/data_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "core/def.hpp"
#include "core/utilities/span.hpp"

#include "cppdict/include/dict/exp/serializer.hpp"

namespace PHARE
{
namespace initializer
Expand Down Expand Up @@ -52,6 +54,25 @@ namespace initializer
std::size_t, std::optional<std::size_t>, std::string,
InitFunction<1>, InitFunction<2>, InitFunction<3>>;

void inline dump_phare_dict(PHAREDict const& dict, std::string const& filename)
{
using Serializer
= cppdict::DictSerializer<bool, int, std::vector<int>, double, std::vector<double>,
std::size_t, std::optional<std::size_t>, std::string,
InitFunction<1>, InitFunction<2>, InitFunction<3>>;

Serializer{filename}(dict);
}

auto inline load_phare_dict(std::string const& filename)
{
using Deserializer
= cppdict::DictDeSerializer<bool, int, std::vector<int>, double, std::vector<double>,
std::size_t, std::optional<std::size_t>, std::string,
InitFunction<1>, InitFunction<2>, InitFunction<3>>;
return Deserializer{filename}();
}


class PHAREDictHandler
{
Expand All @@ -69,6 +90,14 @@ namespace initializer
return *phareDict;
}

void dump(std::string const& filename) const { dump_phare_dict(*phareDict, filename); }

static auto& load(std::string const& filename)
{
INSTANCE().phareDict = std::make_unique<PHAREDict>(); // reset
return (*INSTANCE().phareDict = load_phare_dict(filename)); // ?
}

private:
PHAREDictHandler() = default;
std::unique_ptr<PHAREDict> phareDict;
Expand Down
112 changes: 112 additions & 0 deletions tests/initializer/phare_dict.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

#include "phare_core.hpp"

#include "core/numerics/ion_updater/ion_updater.hpp"
#include "tests/core/data/vecfield/test_vecfield_fixtures.hpp"
#include "tests/core/data/tensorfield/test_tensorfield_fixtures.hpp"
#include "tests/initializer/init_functions.hpp"

using namespace PHARE::initializer::test_fn::func_1d;
using InitFunctionT = PHARE::initializer::InitFunction<1>;

PHARE::initializer::PHAREDict createDict()
{
PHARE::initializer::PHAREDict dict;
dict["ions"]["nbrPopulations"] = std::size_t{2};
dict["ions"]["pop0"]["name"] = std::string{"protons"};
dict["ions"]["pop0"]["mass"] = 1.;
dict["ions"]["pop0"]["particle_initializer"]["name"]
= std::string{"MaxwellianParticleInitializer"};
dict["ions"]["pop0"]["particle_initializer"]["density"] = static_cast<InitFunctionT>(density);

dict["ions"]["pop0"]["particle_initializer"]["bulk_velocity_x"]
= static_cast<InitFunctionT>(vx);

dict["ions"]["pop0"]["particle_initializer"]["bulk_velocity_y"]
= static_cast<InitFunctionT>(vy);

dict["ions"]["pop0"]["particle_initializer"]["bulk_velocity_z"]
= static_cast<InitFunctionT>(vz);


dict["ions"]["pop0"]["particle_initializer"]["thermal_velocity_x"]
= static_cast<InitFunctionT>(vthx);

dict["ions"]["pop0"]["particle_initializer"]["thermal_velocity_y"]
= static_cast<InitFunctionT>(vthy);

dict["ions"]["pop0"]["particle_initializer"]["thermal_velocity_z"]
= static_cast<InitFunctionT>(vthz);


dict["ions"]["pop0"]["particle_initializer"]["nbrPartPerCell"] = int{100};
dict["ions"]["pop0"]["particle_initializer"]["charge"] = -1.;
dict["ions"]["pop0"]["particle_initializer"]["basis"] = std::string{"Cartesian"};

dict["ions"]["pop1"]["name"] = std::string{"alpha"};
dict["ions"]["pop1"]["mass"] = 1.;
dict["ions"]["pop1"]["particle_initializer"]["name"]
= std::string{"MaxwellianParticleInitializer"};
dict["ions"]["pop1"]["particle_initializer"]["density"] = static_cast<InitFunctionT>(density);

dict["ions"]["pop1"]["particle_initializer"]["bulk_velocity_x"]
= static_cast<InitFunctionT>(vx);

dict["ions"]["pop1"]["particle_initializer"]["bulk_velocity_y"]
= static_cast<InitFunctionT>(vy);

dict["ions"]["pop1"]["particle_initializer"]["bulk_velocity_z"]
= static_cast<InitFunctionT>(vz);


dict["ions"]["pop1"]["particle_initializer"]["thermal_velocity_x"]
= static_cast<InitFunctionT>(vthx);

dict["ions"]["pop1"]["particle_initializer"]["thermal_velocity_y"]
= static_cast<InitFunctionT>(vthy);

dict["ions"]["pop1"]["particle_initializer"]["thermal_velocity_z"]
= static_cast<InitFunctionT>(vthz);


dict["ions"]["pop1"]["particle_initializer"]["nbrPartPerCell"] = int{100};
dict["ions"]["pop1"]["particle_initializer"]["charge"] = -1.;
dict["ions"]["pop1"]["particle_initializer"]["basis"] = std::string{"Cartesian"};

dict["electromag"]["name"] = std::string{"EM"};
dict["electromag"]["electric"]["name"] = std::string{"E"};
dict["electromag"]["magnetic"]["name"] = std::string{"B"};

dict["electromag"]["magnetic"]["initializer"]["x_component"] = static_cast<InitFunctionT>(bx);
dict["electromag"]["magnetic"]["initializer"]["y_component"] = static_cast<InitFunctionT>(by);
dict["electromag"]["magnetic"]["initializer"]["z_component"] = static_cast<InitFunctionT>(bz);

dict["electrons"]["pressure_closure"]["name"] = std::string{"isothermal"};
dict["electrons"]["pressure_closure"]["Te"] = 0.12;

return dict;
}



int main(int argc, char** argv)
{
std::string const filename = "pharedict.dat";
PHARE::initializer::dump_phare_dict(createDict(), filename);
// auto const dict = PHARE::initializer::load_phare_dict(filename);

auto const dict = PHARE::initializer::PHAREDictHandler::load(filename);

int r = 0;

r += dict["ions"]["nbrPopulations"].to<std::size_t>() != 2;

r += dict["ions"]["pop0"]["particle_initializer"]["nbrPartPerCell"].to<int>() != 100;
r += dict["ions"]["pop1"]["particle_initializer"]["nbrPartPerCell"].to<int>() != 100;

r += dict["electromag"]["magnetic"]["initializer"]["x_component"].isValue(); // NOT SERIALIZABLE

r += dict["electrons"]["pressure_closure"]["Te"].to<double>() != 0.12;

return r;
}

0 comments on commit 2f32ac1

Please sign in to comment.