From 90b99db4b6b65c9c090d4dbacae2c098f0051ef1 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Wed, 15 Nov 2023 16:09:24 +0000 Subject: [PATCH] [PDI] Allow restarting simulations from a previously saved hdf5 file --- .../bump_on_tail/bumpontail_fem_uniform.cpp | 37 ++++++++--- .../bump_on_tail/bumpontail_fft.cpp | 37 ++++++++--- .../geometryXVx/bump_on_tail/pdi_out.yml.hpp | 6 +- .../geometryXVx/landau/landau_fem_uniform.cpp | 37 ++++++++--- simulations/geometryXVx/landau/landau_fft.cpp | 37 ++++++++--- .../geometryXVx/landau/pdi_out.yml.hpp | 6 +- .../geometryXVx/sheath/pdi_out.yml.hpp | 6 +- simulations/geometryXVx/sheath/sheath.cpp | 37 ++++++++--- src/geometryXVx/initialization/CMakeLists.txt | 2 + src/geometryXVx/initialization/README.md | 3 + .../initialization/restartinitialization.cpp | 17 +++++ .../initialization/restartinitialization.hpp | 45 +++++++++++++ .../time_integration/itimesolver.hpp | 19 +++++- src/geometryXVx/time_integration/predcorr.cpp | 11 ++-- src/geometryXVx/time_integration/predcorr.hpp | 28 +++++++- tests/geometryXVx/CMakeLists.txt | 4 +- tests/geometryXVx/bump_on_tail/CMakeLists.txt | 14 ++++ .../bump_on_tail/test_bumpontail_restart.sh | 65 +++++++++++++++++++ tests/geometryXVx/landau/CMakeLists.txt | 14 ++++ .../geometryXVx/landau/test_landau_restart.sh | 64 ++++++++++++++++++ tests/geometryXVx/sheath/CMakeLists.txt | 10 +++ .../geometryXVx/sheath/test_sheath_restart.sh | 65 +++++++++++++++++++ 22 files changed, 503 insertions(+), 61 deletions(-) create mode 100644 src/geometryXVx/initialization/README.md create mode 100644 src/geometryXVx/initialization/restartinitialization.cpp create mode 100644 src/geometryXVx/initialization/restartinitialization.hpp create mode 100644 tests/geometryXVx/bump_on_tail/test_bumpontail_restart.sh create mode 100644 tests/geometryXVx/landau/test_landau_restart.sh create mode 100644 tests/geometryXVx/sheath/CMakeLists.txt create mode 100644 tests/geometryXVx/sheath/test_sheath_restart.sh diff --git a/simulations/geometryXVx/bump_on_tail/bumpontail_fem_uniform.cpp b/simulations/geometryXVx/bump_on_tail/bumpontail_fem_uniform.cpp index a3857ca8a..ea2dcc650 100644 --- a/simulations/geometryXVx/bump_on_tail/bumpontail_fem_uniform.cpp +++ b/simulations/geometryXVx/bump_on_tail/bumpontail_fem_uniform.cpp @@ -30,6 +30,7 @@ #include "params.yaml.hpp" #include "pdi_out.yml.hpp" #include "predcorr.hpp" +#include "restartinitialization.hpp" #include "singlemodeperturbinitialization.hpp" #include "species_info.hpp" #include "spline_interpolator.hpp" @@ -54,6 +55,7 @@ int main(int argc, char** argv) { ddc::ScopeGuard scope(argc, argv); + long int iter_start(0); PC_tree_t conf_voicexx; if (argc == 2) { conf_voicexx = PC_parse_path(fs::path(argv[1]).c_str()); @@ -63,8 +65,15 @@ int main(int argc, char** argv) file << params_yaml; return EXIT_SUCCESS; } + } else if (argc == 4) { + if (argv[1] == std::string_view("--iter-restart")) { + iter_start = std::strtol(argv[2], NULL, 10); + conf_voicexx = PC_parse_path(fs::path(argv[3]).c_str()); + } } else { cerr << "usage: " << argv[0] << " [--dump-config] " << endl; + cerr << "or to perform a restart" << argv[0] << " [--iter-restart] " + << endl; return EXIT_FAILURE; } PC_errhandler(PC_NULL_HANDLER); @@ -155,11 +164,23 @@ int main(int argc, char** argv) std::move(mean_velocity_bot)); init_fequilibrium(allfequilibrium); DFieldSpXVx allfdistribu(meshSpXVx); - SingleModePerturbInitialization const - init(allfequilibrium, - ddc::discrete_space().perturb_modes(), - ddc::discrete_space().perturb_amplitudes()); - init(allfdistribu); + + PC_tree_t conf_pdi = PC_parse_string(PDI_CFG); + PDI_init(conf_pdi); + + ddc::expose_to_pdi("iter_start", iter_start); + + double time_start(0); + if (iter_start == 0) { + SingleModePerturbInitialization const + init(allfequilibrium, + ddc::discrete_space().perturb_modes(), + ddc::discrete_space().perturb_amplitudes()); + init(allfdistribu); + } else { + RestartInitialization const restart(iter_start, time_start); + restart(allfdistribu); + } // --> Algorithm info double const deltat = PCpp_double(conf_voicexx, ".Algorithm.deltat"); @@ -169,10 +190,6 @@ int main(int argc, char** argv) double const time_diag = PCpp_double(conf_voicexx, ".Output.time_diag"); int const nbstep_diag = int(time_diag / deltat); - PC_tree_t conf_pdi = PC_parse_string(PDI_CFG); - - PDI_init(conf_pdi); - ConstantExtrapolationBoundaryValue bv_x_min(x_min); ConstantExtrapolationBoundaryValue bv_x_max(x_max); @@ -230,7 +247,7 @@ int main(int argc, char** argv) steady_clock::time_point const start = steady_clock::now(); - predcorr(allfdistribu, deltat, nbiter); + predcorr(allfdistribu, time_start, deltat, nbiter); steady_clock::time_point const end = steady_clock::now(); diff --git a/simulations/geometryXVx/bump_on_tail/bumpontail_fft.cpp b/simulations/geometryXVx/bump_on_tail/bumpontail_fft.cpp index f059f53d7..a14935d08 100644 --- a/simulations/geometryXVx/bump_on_tail/bumpontail_fft.cpp +++ b/simulations/geometryXVx/bump_on_tail/bumpontail_fft.cpp @@ -26,6 +26,7 @@ #include "params.yaml.hpp" #include "pdi_out.yml.hpp" #include "predcorr.hpp" +#include "restartinitialization.hpp" #include "singlemodeperturbinitialization.hpp" #include "species_info.hpp" #include "spline_interpolator.hpp" @@ -50,6 +51,7 @@ int main(int argc, char** argv) { ddc::ScopeGuard scope(argc, argv); + long int iter_start(0); PC_tree_t conf_voicexx; if (argc == 2) { conf_voicexx = PC_parse_path(fs::path(argv[1]).c_str()); @@ -59,8 +61,15 @@ int main(int argc, char** argv) file << params_yaml; return EXIT_SUCCESS; } + } else if (argc == 4) { + if (argv[1] == std::string_view("--iter-restart")) { + iter_start = std::strtol(argv[2], NULL, 10); + conf_voicexx = PC_parse_path(fs::path(argv[3]).c_str()); + } } else { cerr << "usage: " << argv[0] << " [--dump-config] " << endl; + cerr << "or to perform a restart" << argv[0] << " [--iter-restart] " + << endl; return EXIT_FAILURE; } PC_errhandler(PC_NULL_HANDLER); @@ -147,11 +156,23 @@ int main(int argc, char** argv) std::move(mean_velocity_bot)); init_fequilibrium(allfequilibrium); DFieldSpXVx allfdistribu(meshSpXVx); - SingleModePerturbInitialization const - init(allfequilibrium, - ddc::discrete_space().perturb_modes(), - ddc::discrete_space().perturb_amplitudes()); - init(allfdistribu); + + PC_tree_t conf_pdi = PC_parse_string(PDI_CFG); + PDI_init(conf_pdi); + + ddc::expose_to_pdi("iter_start", iter_start); + + double time_start(0); + if (iter_start == 0) { + SingleModePerturbInitialization const + init(allfequilibrium, + ddc::discrete_space().perturb_modes(), + ddc::discrete_space().perturb_amplitudes()); + init(allfdistribu); + } else { + RestartInitialization const restart(iter_start, time_start); + restart(allfdistribu); + } // --> Algorithm info double const deltat = PCpp_double(conf_voicexx, ".Algorithm.deltat"); @@ -161,10 +182,6 @@ int main(int argc, char** argv) double const time_diag = PCpp_double(conf_voicexx, ".Output.time_diag"); int const nbstep_diag = int(time_diag / deltat); - PC_tree_t conf_pdi = PC_parse_string(PDI_CFG); - - PDI_init(conf_pdi); - ConstantExtrapolationBoundaryValue bv_x_min(x_min); ConstantExtrapolationBoundaryValue bv_x_max(x_max); @@ -219,7 +236,7 @@ int main(int argc, char** argv) steady_clock::time_point const start = steady_clock::now(); - predcorr(allfdistribu, deltat, nbiter); + predcorr(allfdistribu, time_start, deltat, nbiter); steady_clock::time_point const end = steady_clock::now(); diff --git a/simulations/geometryXVx/bump_on_tail/pdi_out.yml.hpp b/simulations/geometryXVx/bump_on_tail/pdi_out.yml.hpp index 5622255c5..8ec9c1e4d 100644 --- a/simulations/geometryXVx/bump_on_tail/pdi_out.yml.hpp +++ b/simulations/geometryXVx/bump_on_tail/pdi_out.yml.hpp @@ -5,6 +5,7 @@ constexpr char const* const PDI_CFG = R"PDI_CFG( Nx : int Nvx : int iter : int + iter_start : int time_saved : double nbstep_diag: int iter_saved : int @@ -55,7 +56,7 @@ constexpr char const* const PDI_CFG = R"PDI_CFG( on_data: iter: - set: - - iter_saved: '${iter}/${nbstep_diag}' + - iter_saved: '${iter_start} + ${iter}/${nbstep_diag}' on_finalize: - release: [iter_saved] decl_hdf5: @@ -68,5 +69,8 @@ constexpr char const* const PDI_CFG = R"PDI_CFG( when: '${iter} % ${nbstep_diag} = 0' collision_policy: replace_and_warn write: [time_saved, fdistribu, electrostatic_potential] + - file: 'VOICEXX_${iter_start:05}.h5' + on_event: restart + read: [time_saved, fdistribu] #trace: ~ )PDI_CFG"; diff --git a/simulations/geometryXVx/landau/landau_fem_uniform.cpp b/simulations/geometryXVx/landau/landau_fem_uniform.cpp index 75d10cca1..9c7c8ce99 100644 --- a/simulations/geometryXVx/landau/landau_fem_uniform.cpp +++ b/simulations/geometryXVx/landau/landau_fem_uniform.cpp @@ -29,6 +29,7 @@ #include "params.yaml.hpp" #include "pdi_out.yml.hpp" #include "predcorr.hpp" +#include "restartinitialization.hpp" #include "singlemodeperturbinitialization.hpp" #include "species_info.hpp" #include "spline_interpolator.hpp" @@ -53,6 +54,7 @@ int main(int argc, char** argv) { ddc::ScopeGuard scope(argc, argv); + long int iter_start(0); PC_tree_t conf_voicexx; if (argc == 2) { conf_voicexx = PC_parse_path(fs::path(argv[1]).c_str()); @@ -62,8 +64,15 @@ int main(int argc, char** argv) file << params_yaml; return EXIT_SUCCESS; } + } else if (argc == 4) { + if (argv[1] == std::string_view("--iter-restart")) { + iter_start = std::strtol(argv[2], NULL, 10); + conf_voicexx = PC_parse_path(fs::path(argv[3]).c_str()); + } } else { cerr << "usage: " << argv[0] << " [--dump-config] " << endl; + cerr << "or to perform a restart" << argv[0] << " [--iter-restart] " + << endl; return EXIT_FAILURE; } PC_errhandler(PC_NULL_HANDLER); @@ -153,11 +162,23 @@ int main(int argc, char** argv) std::move(mean_velocity_eq)); init_fequilibrium(allfequilibrium); DFieldSpXVx allfdistribu(meshSpXVx); - SingleModePerturbInitialization const - init(allfequilibrium, - ddc::discrete_space().perturb_modes(), - ddc::discrete_space().perturb_amplitudes()); - init(allfdistribu); + + PC_tree_t conf_pdi = PC_parse_string(PDI_CFG); + PDI_init(conf_pdi); + + ddc::expose_to_pdi("iter_start", iter_start); + + double time_start(0); + if (iter_start == 0) { + SingleModePerturbInitialization const + init(allfequilibrium, + ddc::discrete_space().perturb_modes(), + ddc::discrete_space().perturb_amplitudes()); + init(allfdistribu); + } else { + RestartInitialization const restart(iter_start, time_start); + restart(allfdistribu); + } // --> Algorithm info double const deltat = PCpp_double(conf_voicexx, ".Algorithm.deltat"); @@ -167,10 +188,6 @@ int main(int argc, char** argv) double const time_diag = PCpp_double(conf_voicexx, ".Output.time_diag"); int const nbstep_diag = int(time_diag / deltat); - PC_tree_t conf_pdi = PC_parse_string(PDI_CFG); - - PDI_init(conf_pdi); - ConstantExtrapolationBoundaryValue bv_x_min(x_min); ConstantExtrapolationBoundaryValue bv_x_max(x_max); @@ -229,7 +246,7 @@ int main(int argc, char** argv) steady_clock::time_point const start = steady_clock::now(); - predcorr(allfdistribu, deltat, nbiter); + predcorr(allfdistribu, time_start, deltat, nbiter); steady_clock::time_point const end = steady_clock::now(); diff --git a/simulations/geometryXVx/landau/landau_fft.cpp b/simulations/geometryXVx/landau/landau_fft.cpp index a4ce39ef9..7b288e30a 100644 --- a/simulations/geometryXVx/landau/landau_fft.cpp +++ b/simulations/geometryXVx/landau/landau_fft.cpp @@ -26,6 +26,7 @@ #include "params.yaml.hpp" #include "pdi_out.yml.hpp" #include "predcorr.hpp" +#include "restartinitialization.hpp" #include "singlemodeperturbinitialization.hpp" #include "species_info.hpp" #include "spline_interpolator.hpp" @@ -50,6 +51,7 @@ int main(int argc, char** argv) { ddc::ScopeGuard scope(argc, argv); + long int iter_start(0); PC_tree_t conf_voicexx; if (argc == 2) { conf_voicexx = PC_parse_path(fs::path(argv[1]).c_str()); @@ -59,8 +61,15 @@ int main(int argc, char** argv) file << params_yaml; return EXIT_SUCCESS; } + } else if (argc == 4) { + if (argv[1] == std::string_view("--iter-restart")) { + iter_start = std::strtol(argv[2], NULL, 10); + conf_voicexx = PC_parse_path(fs::path(argv[3]).c_str()); + } } else { cerr << "usage: " << argv[0] << " [--dump-config] " << endl; + cerr << "or to perform a restart" << argv[0] << " [--iter-restart] " + << endl; return EXIT_FAILURE; } PC_errhandler(PC_NULL_HANDLER); @@ -150,11 +159,23 @@ int main(int argc, char** argv) std::move(mean_velocity_eq)); init_fequilibrium(allfequilibrium); DFieldSpXVx allfdistribu(meshSpXVx); - SingleModePerturbInitialization const - init(allfequilibrium, - ddc::discrete_space().perturb_modes(), - ddc::discrete_space().perturb_amplitudes()); - init(allfdistribu); + + PC_tree_t conf_pdi = PC_parse_string(PDI_CFG); + PDI_init(conf_pdi); + + ddc::expose_to_pdi("iter_start", iter_start); + + double time_start(0); + if (iter_start == 0) { + SingleModePerturbInitialization const + init(allfequilibrium, + ddc::discrete_space().perturb_modes(), + ddc::discrete_space().perturb_amplitudes()); + init(allfdistribu); + } else { + RestartInitialization const restart(iter_start, time_start); + restart(allfdistribu); + } // --> Algorithm info double const deltat = PCpp_double(conf_voicexx, ".Algorithm.deltat"); @@ -164,10 +185,6 @@ int main(int argc, char** argv) double const time_diag = PCpp_double(conf_voicexx, ".Output.time_diag"); int const nbstep_diag = int(time_diag / deltat); - PC_tree_t conf_pdi = PC_parse_string(PDI_CFG); - - PDI_init(conf_pdi); - ConstantExtrapolationBoundaryValue bv_x_min(x_min); ConstantExtrapolationBoundaryValue bv_x_max(x_max); @@ -222,7 +239,7 @@ int main(int argc, char** argv) steady_clock::time_point const start = steady_clock::now(); - predcorr(allfdistribu, deltat, nbiter); + predcorr(allfdistribu, time_start, deltat, nbiter); steady_clock::time_point const end = steady_clock::now(); diff --git a/simulations/geometryXVx/landau/pdi_out.yml.hpp b/simulations/geometryXVx/landau/pdi_out.yml.hpp index f3ac9ec03..82adabf44 100644 --- a/simulations/geometryXVx/landau/pdi_out.yml.hpp +++ b/simulations/geometryXVx/landau/pdi_out.yml.hpp @@ -5,6 +5,7 @@ constexpr char const* const PDI_CFG = R"PDI_CFG( Nx : int Nvx : int iter : int + iter_start : int time_saved : double nbstep_diag: int iter_saved : int @@ -55,7 +56,7 @@ constexpr char const* const PDI_CFG = R"PDI_CFG( on_data: iter: - set: - - iter_saved: '${iter}/${nbstep_diag}' + - iter_saved: '${iter_start} + ${iter}/${nbstep_diag}' on_finalize: - release: [iter_saved] decl_hdf5: @@ -68,5 +69,8 @@ constexpr char const* const PDI_CFG = R"PDI_CFG( when: '${iter} % ${nbstep_diag} = 0' collision_policy: replace_and_warn write: [time_saved, fdistribu, electrostatic_potential] + - file: 'VOICEXX_${iter_start:05}.h5' + on_event: restart + read: [time_saved, fdistribu] #trace: ~ )PDI_CFG"; diff --git a/simulations/geometryXVx/sheath/pdi_out.yml.hpp b/simulations/geometryXVx/sheath/pdi_out.yml.hpp index 323db7a4d..60ed6f5b0 100644 --- a/simulations/geometryXVx/sheath/pdi_out.yml.hpp +++ b/simulations/geometryXVx/sheath/pdi_out.yml.hpp @@ -5,6 +5,7 @@ constexpr char const* const PDI_CFG = R"PDI_CFG( Nx : int Nvx : int iter : int + iter_start : int time_saved : double nbstep_diag: int iter_saved : int @@ -89,7 +90,7 @@ constexpr char const* const PDI_CFG = R"PDI_CFG( on_data: iter: - set: - - iter_saved: '${iter}/${nbstep_diag}' + - iter_saved: '${iter_start} + ${iter}/${nbstep_diag}' on_finalize: - release: [iter_saved] decl_hdf5: @@ -129,5 +130,8 @@ constexpr char const* const PDI_CFG = R"PDI_CFG( when: '${iter} % ${nbstep_diag} = 0' collision_policy: replace_and_warn write: [time_saved, fdistribu, electrostatic_potential] + - file: 'VOICEXX_${iter_start:05}.h5' + on_event: restart + read: [time_saved, fdistribu] #trace: ~ )PDI_CFG"; diff --git a/simulations/geometryXVx/sheath/sheath.cpp b/simulations/geometryXVx/sheath/sheath.cpp index a38ffae20..eb581917b 100644 --- a/simulations/geometryXVx/sheath/sheath.cpp +++ b/simulations/geometryXVx/sheath/sheath.cpp @@ -37,6 +37,7 @@ #include "paraconfpp.hpp" #include "pdi_out.yml.hpp" #include "predcorr.hpp" +#include "restartinitialization.hpp" #include "sheath.yaml.hpp" #include "singlemodeperturbinitialization.hpp" #include "species_info.hpp" @@ -53,6 +54,7 @@ int main(int argc, char** argv) { ddc::ScopeGuard scope(argc, argv); + long int iter_start(0); PC_tree_t conf_voicexx; if (argc == 2) { conf_voicexx = PC_parse_path(fs::path(argv[1]).c_str()); @@ -62,8 +64,15 @@ int main(int argc, char** argv) file << params_yaml; return EXIT_SUCCESS; } + } else if (argc == 4) { + if (argv[1] == std::string_view("--iter-restart")) { + iter_start = std::strtol(argv[2], NULL, 10); + conf_voicexx = PC_parse_path(fs::path(argv[3]).c_str()); + } } else { cerr << "usage: " << argv[0] << " [--dump-config] " << endl; + cerr << "or to perform a restart" << argv[0] << " [--iter-restart] " + << endl; return EXIT_FAILURE; } PC_errhandler(PC_NULL_HANDLER); @@ -153,11 +162,23 @@ int main(int argc, char** argv) std::move(mean_velocity_eq)); init_fequilibrium(allfequilibrium); DFieldSpXVx allfdistribu(meshSpXVx); - SingleModePerturbInitialization const - init(allfequilibrium, - ddc::discrete_space().perturb_modes(), - ddc::discrete_space().perturb_amplitudes()); - init(allfdistribu); + + PC_tree_t conf_pdi = PC_parse_string(PDI_CFG); + PDI_init(conf_pdi); + + ddc::expose_to_pdi("iter_start", iter_start); + + double time_start(0); + if (iter_start == 0) { + SingleModePerturbInitialization const + init(allfequilibrium, + ddc::discrete_space().perturb_modes(), + ddc::discrete_space().perturb_amplitudes()); + init(allfdistribu); + } else { + RestartInitialization const restart(iter_start, time_start); + restart(allfdistribu); + } // --> Algorithm info double const deltat = PCpp_double(conf_voicexx, ".Algorithm.deltat"); @@ -167,10 +188,6 @@ int main(int argc, char** argv) double const time_diag = PCpp_double(conf_voicexx, ".Output.time_diag"); int const nbstep_diag = int(time_diag / deltat); - PC_tree_t conf_pdi = PC_parse_string(PDI_CFG); - - PDI_init(conf_pdi); - ConstantExtrapolationBoundaryValue bv_x_min(x_min); ConstantExtrapolationBoundaryValue bv_x_max(x_max); @@ -294,7 +311,7 @@ int main(int argc, char** argv) steady_clock::time_point const start = steady_clock::now(); - predcorr(allfdistribu, deltat, nbiter); + predcorr(allfdistribu, time_start, deltat, nbiter); steady_clock::time_point const end = steady_clock::now(); diff --git a/src/geometryXVx/initialization/CMakeLists.txt b/src/geometryXVx/initialization/CMakeLists.txt index 7697c2b2e..542536fba 100644 --- a/src/geometryXVx/initialization/CMakeLists.txt +++ b/src/geometryXVx/initialization/CMakeLists.txt @@ -5,6 +5,7 @@ foreach(GEOMETRY_VARIANT IN LISTS GEOMETRY_XVx_VARIANTS_LIST) add_library("initialization_${GEOMETRY_VARIANT}" STATIC maxwellianequilibrium.cpp bumpontailequilibrium.cpp + restartinitialization.cpp singlemodeperturbinitialization.cpp ) @@ -20,6 +21,7 @@ target_include_directories("initialization_${GEOMETRY_VARIANT}" target_link_libraries("initialization_${GEOMETRY_VARIANT}" PUBLIC DDC::DDC + DDC::PDI_Wrapper gslx::speciesinfo gslx::geometry_${GEOMETRY_VARIANT} gslx::utils diff --git a/src/geometryXVx/initialization/README.md b/src/geometryXVx/initialization/README.md new file mode 100644 index 000000000..e75a20e34 --- /dev/null +++ b/src/geometryXVx/initialization/README.md @@ -0,0 +1,3 @@ +# Initializatin methods + +Initialization methods define the value of the distribution function at the start of the simulation. For instance, these methods allows for initializing the distribution function as a perturbed maxwellian, or to read the values from a previous simulation. \ No newline at end of file diff --git a/src/geometryXVx/initialization/restartinitialization.cpp b/src/geometryXVx/initialization/restartinitialization.cpp new file mode 100644 index 000000000..bc9b2f734 --- /dev/null +++ b/src/geometryXVx/initialization/restartinitialization.cpp @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MIT + +#include + +#include "restartinitialization.hpp" + +RestartInitialization::RestartInitialization(int iter_start, double& time_start) + : m_iter_start(iter_start) + , m_time_start(time_start) +{ +} + +DSpanSpXVx RestartInitialization::operator()(DSpanSpXVx const allfdistribu) const +{ + ddc::PdiEvent("restart").with("time_saved", m_time_start).with("fdistribu", allfdistribu); + return allfdistribu; +} \ No newline at end of file diff --git a/src/geometryXVx/initialization/restartinitialization.hpp b/src/geometryXVx/initialization/restartinitialization.hpp new file mode 100644 index 000000000..875cac2c0 --- /dev/null +++ b/src/geometryXVx/initialization/restartinitialization.hpp @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: MIT + +#pragma once + +#include + +#include +#include + +#include "iinitialization.hpp" + +/** + * @brief A class that initializes the distribution function from a previous simulation. + * + * + * A class that triggers a PDI event to read the values of + * a distribution function saved in a hdf5 file. These + * values are copied to the field that represents the + * distribution function. + */ +class RestartInitialization : public IInitialization +{ +private: + int m_iter_start; /* iteration number to perform the restart from */ + double& m_time_start; /* corresponding simulation time */ + +public: + /** + * @brief Create an initialization object. + * @param[in] iter_start An integer representing the number of iteration already performed to produce the distribution function used to initialize the current simulation. + * @param[in] time_start The physical time corresponding to iter_start. + */ + RestartInitialization(int iter_start, double& time_start); + + ~RestartInitialization() override = default; + + /** + * @brief Triggers a PDI event to fill the distribution function with values from a hdf5 file. + * @param[in, out] allfdistribu On input: the distribution function not initialized. + * On output: the distribution function initialized with the values + * read from an external file. + * @return The initialized distribution function. + */ + DSpanSpXVx operator()(DSpanSpXVx allfdistribu) const override; +}; \ No newline at end of file diff --git a/src/geometryXVx/time_integration/itimesolver.hpp b/src/geometryXVx/time_integration/itimesolver.hpp index 17a3d4bc8..f9d9fd2c3 100644 --- a/src/geometryXVx/time_integration/itimesolver.hpp +++ b/src/geometryXVx/time_integration/itimesolver.hpp @@ -4,10 +4,27 @@ #include +/** + * @brief An abstract class for solving a Boltzmann-Poisson system of equations. + */ class ITimeSolver { public: virtual ~ITimeSolver() = default; - virtual DSpanSpXVx operator()(DSpanSpXVx allfdistribu, double dt, int steps = 1) const = 0; + /** + * @brief Operator for solving the Boltzmann-Poisson system. + * @param[in, out] allfdistribu On input : the initial value of the distribution function. + * On output : the value of the distribution function after solving + * the Boltzmann-Poisson system a given number of iterations. + * @param[in] time_start The physical time at the start of the simulation. + * @param[in] dt The timestep. + * @param[in] steps The number of iterations to be performed by the solver. + * @return The distribution function after solving the system. + */ + virtual DSpanSpXVx operator()( + DSpanSpXVx allfdistribu, + double time_start, + double dt, + int steps = 1) const = 0; }; diff --git a/src/geometryXVx/time_integration/predcorr.cpp b/src/geometryXVx/time_integration/predcorr.cpp index 8b0a53791..09440ae7b 100644 --- a/src/geometryXVx/time_integration/predcorr.cpp +++ b/src/geometryXVx/time_integration/predcorr.cpp @@ -16,8 +16,11 @@ PredCorr::PredCorr(IBoltzmannSolver const& boltzmann_solver, IPoissonSolver cons { } -DSpanSpXVx PredCorr::operator()(DSpanSpXVx const allfdistribu, double const dt, int const steps) - const +DSpanSpXVx PredCorr::operator()( + DSpanSpXVx const allfdistribu, + double const time_start, + double const dt, + int const steps) const { // electrostatic potential and electric field (depending only on x) DFieldX electrostatic_potential(allfdistribu.domain()); @@ -30,7 +33,7 @@ DSpanSpXVx PredCorr::operator()(DSpanSpXVx const allfdistribu, double const dt, int iter = 0; for (; iter < steps; ++iter) { - double const iter_time = iter * dt; + double const iter_time = time_start + iter * dt; // computation of the electrostatic potential at time tn and // the associated electric field @@ -55,7 +58,7 @@ DSpanSpXVx PredCorr::operator()(DSpanSpXVx const allfdistribu, double const dt, m_boltzmann_solver(allfdistribu, electric_field, dt); } - double const final_time = iter * dt; + double const final_time = time_start + iter * dt; m_poisson_solver(electrostatic_potential, electric_field, allfdistribu); ddc::PdiEvent("last_iteration") .with("iter", iter) diff --git a/src/geometryXVx/time_integration/predcorr.hpp b/src/geometryXVx/time_integration/predcorr.hpp index dcff0908f..057ceda8b 100644 --- a/src/geometryXVx/time_integration/predcorr.hpp +++ b/src/geometryXVx/time_integration/predcorr.hpp @@ -9,6 +9,16 @@ class IPoissonSolver; class IBoltzmannSolver; +/** + * @brief A class that solves a Boltzmann-Poisson system of equations using a predictor-corrector scheme. + * + * A class that solves a Boltzmann-Poisson system with + * a predictor corrector scheme. This scheme consists in + * estimating the electric potential after a time interval + * of a half-timestep. This potential is then used to compute + * the value of the distribution function at time t+dt, where + * dt is the timestep. + */ class PredCorr : public ITimeSolver { private: @@ -17,9 +27,25 @@ class PredCorr : public ITimeSolver IPoissonSolver const& m_poisson_solver; public: + /** + * @brief Creates an instance of the predictor-corrector class. + * @param[in] boltzmann_solver A solver for a Boltzmann equation. + * @param[in] poisson_solver A solver for a Poisson equation. + */ PredCorr(IBoltzmannSolver const& boltzmann_solver, IPoissonSolver const& poisson_solver); ~PredCorr() override = default; - DSpanSpXVx operator()(DSpanSpXVx allfdistribu, double dt, int steps = 1) const override; + /** + * @brief Solves the Boltzmann-Poisson system. + * @param[in, out] allfdistribu On input : the initial value of the distribution function. + * On output : the value of the distribution function after solving + * the Boltzmann-Poisson system a given number of iterations. + * @param[in] time_start The physical time at the start of the simulation. + * @param[in] dt The timestep. + * @param[in] steps The number of iterations to be performed by the predictor-corrector. + * @return The distribution function after solving the system. + */ + DSpanSpXVx operator()(DSpanSpXVx allfdistribu, double time_start, double dt, int steps = 1) + const override; }; diff --git a/tests/geometryXVx/CMakeLists.txt b/tests/geometryXVx/CMakeLists.txt index f2f744b6a..003feafa2 100644 --- a/tests/geometryXVx/CMakeLists.txt +++ b/tests/geometryXVx/CMakeLists.txt @@ -50,7 +50,7 @@ add_subdirectory(bump_on_tail) add_subdirectory(landau) - +add_subdirectory(sheath) foreach(GEOMETRY_VARIANT IN LISTS GEOMETRY_XVx_VARIANTS_LIST) add_executable(spline_quadrature_tests_${GEOMETRY_VARIANT} @@ -71,4 +71,4 @@ foreach(GEOMETRY_VARIANT IN LISTS GEOMETRY_XVx_VARIANTS_LIST) gtest_discover_tests(spline_quadrature_tests_${GEOMETRY_VARIANT} TEST_SUFFIX "_${GEOMETRY_VARIANT}") -endforeach() \ No newline at end of file +endforeach() diff --git a/tests/geometryXVx/bump_on_tail/CMakeLists.txt b/tests/geometryXVx/bump_on_tail/CMakeLists.txt index cddab723b..1f1c37af4 100644 --- a/tests/geometryXVx/bump_on_tail/CMakeLists.txt +++ b/tests/geometryXVx/bump_on_tail/CMakeLists.txt @@ -12,6 +12,13 @@ add_test(NAME TestSimulationBumpontailFFT "fft") set_property(TEST TestSimulationBumpontailFFT PROPERTY TIMEOUT 200) +add_test(NAME TestSimulationBumpontailRestartFFT_XVx + COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/test_bumpontail_restart.sh" + "${PROJECT_SOURCE_DIR}" + "$" + "restart") +set_property(TEST TestSimulationBumpontailRestartFFT_XVx PROPERTY TIMEOUT 200) + add_test(NAME TestSimulationBumpontailFemUniform_xperiod_vx COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/test_bumpontail.sh" "${PROJECT_SOURCE_DIR}" @@ -19,3 +26,10 @@ add_test(NAME TestSimulationBumpontailFemUniform_xperiod_vx "$" "fem") set_property(TEST TestSimulationBumpontailFemUniform_xperiod_vx PROPERTY TIMEOUT 200) + +add_test(NAME TestSimulationBumpontailRestartFemUniform_xperiod_vx + COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/test_bumpontail_restart.sh" + "${PROJECT_SOURCE_DIR}" + "$" + "restart") +set_property(TEST TestSimulationBumpontailRestartFemUniform_xperiod_vx PROPERTY TIMEOUT 200) diff --git a/tests/geometryXVx/bump_on_tail/test_bumpontail_restart.sh b/tests/geometryXVx/bump_on_tail/test_bumpontail_restart.sh new file mode 100644 index 000000000..b348bfcbb --- /dev/null +++ b/tests/geometryXVx/bump_on_tail/test_bumpontail_restart.sh @@ -0,0 +1,65 @@ +#!/bin/bash +set -xe + +if [ $# -ne 3 ] +then + echo "Usage: $0 " + exit 1 +fi +VOICEXX_SRCDIR="$1" +VOICEXX_EXEC="$2" +SIMULATION_NAME="$3" + +OUTDIR="${PWD}/${SIMULATION_NAME}" + +TMPDIR="$(mktemp -p "${PWD}" -d run-XXXXXXXXXX)" +function finish { + rm -rf "${TMPDIR}" +} +trap finish EXIT QUIT ABRT KILL SEGV TERM STOP + +cd "$(dirname "$0")" +TESTDIR="${PWD}" + +cd "${TMPDIR}" + +RSTDIR="${TMPDIR}/RST" +mkdir "${RSTDIR}" +cd "${RSTDIR}" + +"${VOICEXX_EXEC}" "--dump-config" "${PWD}/bumpontail.yaml" +sed -i 's/^ x_size: .*/ x_size: 16/' bumpontail.yaml +sed -i 's/^ vx_size: .*/ vx_size: 16/' bumpontail.yaml +sed -i 's/^ nbiter: .*/ nbiter: 10/' bumpontail.yaml +sed -i 's/^ deltat: .*/ deltat: 0.125/' bumpontail.yaml +sed -i 's/^ time_diag: .*/ time_diag: 0.25/' bumpontail.yaml + +"${VOICEXX_EXEC}" "${PWD}/bumpontail.yaml" + +cd "${TMPDIR}" +cp "${RSTDIR}/VOICEXX_initstate.h5" . +cp "${RSTDIR}/VOICEXX_00003.h5" . +cp "${RSTDIR}/bumpontail.yaml" bumpontail_restart.yaml + +"${VOICEXX_EXEC}" --iter-restart 3 "${PWD}/bumpontail_restart.yaml" +sed -i 's/^ nbiter: .*/ nbiter: 2/' bumpontail_restart.yaml +sed -i 's/^ time_diag: .*/ time_diag: 0.5/' bumpontail_restart.yaml + +h5ls -d ${PWD}/VOICEXX_00006.h5/time_saved ${RSTDIR}/VOICEXX_00005.h5/time_saved +command="h5diff ${PWD}/VOICEXX_00005.h5 ${RSTDIR}/VOICEXX_00005.h5 time_saved" +eval $command +if [ $? -ne 0 ]; then + exit 1 +fi + +command="h5diff ${PWD}/VOICEXX_00005.h5 ${RSTDIR}/VOICEXX_00005.h5 electrostatic_potential" +eval $command +if [ $? -ne 0 ]; then + exit 1 +fi + +command="h5diff ${PWD}/VOICEXX_00005.h5 ${RSTDIR}/VOICEXX_00005.h5 fdistribu" +eval $command +if [ $? -ne 0 ]; then + exit 1 +fi \ No newline at end of file diff --git a/tests/geometryXVx/landau/CMakeLists.txt b/tests/geometryXVx/landau/CMakeLists.txt index e7217d9cb..650dd675b 100644 --- a/tests/geometryXVx/landau/CMakeLists.txt +++ b/tests/geometryXVx/landau/CMakeLists.txt @@ -12,6 +12,13 @@ add_test(NAME TestSimulationLandauFFT_XVx "fft") set_property(TEST TestSimulationLandauFFT_XVx PROPERTY TIMEOUT 200) +add_test(NAME TestSimulationLandauRestartFFT_XVx + COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/test_landau_restart.sh" + "${PROJECT_SOURCE_DIR}" + "$" + "restart") +set_property(TEST TestSimulationLandauRestartFFT_XVx PROPERTY TIMEOUT 200) + add_test(NAME TestSimulationLandauFemUniform_xperiod_vx COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/test_landau.sh" "${PROJECT_SOURCE_DIR}" @@ -19,3 +26,10 @@ add_test(NAME TestSimulationLandauFemUniform_xperiod_vx "$" "fem") set_property(TEST TestSimulationLandauFemUniform_xperiod_vx PROPERTY TIMEOUT 200) + +add_test(NAME TestSimulationLandauRestartFemUniform_xperiod_vx + COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/test_landau_restart.sh" + "${PROJECT_SOURCE_DIR}" + "$" + "restart") +set_property(TEST TestSimulationLandauRestartFemUniform_xperiod_vx PROPERTY TIMEOUT 200) \ No newline at end of file diff --git a/tests/geometryXVx/landau/test_landau_restart.sh b/tests/geometryXVx/landau/test_landau_restart.sh new file mode 100644 index 000000000..a28b9d0b7 --- /dev/null +++ b/tests/geometryXVx/landau/test_landau_restart.sh @@ -0,0 +1,64 @@ +#!/bin/bash +set -xe + +if [ $# -ne 3 ] +then + echo "Usage: $0 " + exit 1 +fi +VOICEXX_SRCDIR="$1" +VOICEXX_EXEC="$2" +SIMULATION_NAME="$3" + +OUTDIR="${PWD}/${SIMULATION_NAME}" + +TMPDIR="$(mktemp -p "${PWD}" -d run-XXXXXXXXXX)" +function finish { + rm -rf "${TMPDIR}" +} +trap finish EXIT QUIT ABRT KILL SEGV TERM STOP + +cd "$(dirname "$0")" +TESTDIR="${PWD}" + +cd "${TMPDIR}" + +RSTDIR="${TMPDIR}/RST" +mkdir "${RSTDIR}" +cd "${RSTDIR}" + +"${VOICEXX_EXEC}" "--dump-config" "${PWD}/landau.yaml" +sed -i 's/^ x_size: .*/ x_size: 16/' landau.yaml +sed -i 's/^ vx_size: .*/ vx_size: 16/' landau.yaml +sed -i 's/^ nbiter: .*/ nbiter: 10/' landau.yaml +sed -i 's/^ deltat: .*/ deltat: 0.125/' landau.yaml +sed -i 's/^ time_diag: .*/ time_diag: 0.25/' landau.yaml + +"${VOICEXX_EXEC}" "${PWD}/landau.yaml" + +cd "${TMPDIR}" +cp "${RSTDIR}/VOICEXX_initstate.h5" . +cp "${RSTDIR}/VOICEXX_00003.h5" . +cp "${RSTDIR}/landau.yaml" landau_restart.yaml + +"${VOICEXX_EXEC}" --iter-restart 3 "${PWD}/landau_restart.yaml" +sed -i 's/^ nbiter: .*/ nbiter: 2/' landau_restart.yaml +sed -i 's/^ time_diag: .*/ time_diag: 0.5/' landau_restart.yaml + +command="h5diff ${PWD}/VOICEXX_00005.h5 ${RSTDIR}/VOICEXX_00005.h5 time_saved" +eval $command +if [ $? -ne 0 ]; then + exit 1 +fi + +command="h5diff ${PWD}/VOICEXX_00005.h5 ${RSTDIR}/VOICEXX_00005.h5 electrostatic_potential" +eval $command +if [ $? -ne 0 ]; then + exit 1 +fi + +command="h5diff ${PWD}/VOICEXX_00005.h5 ${RSTDIR}/VOICEXX_00005.h5 fdistribu" +eval $command +if [ $? -ne 0 ]; then + exit 1 +fi \ No newline at end of file diff --git a/tests/geometryXVx/sheath/CMakeLists.txt b/tests/geometryXVx/sheath/CMakeLists.txt new file mode 100644 index 000000000..37aa543dd --- /dev/null +++ b/tests/geometryXVx/sheath/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: MIT + +cmake_minimum_required(VERSION 3.15) + +add_test(NAME TestSimulationSheathRestart_xperiod_vx + COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/test_sheath_restart.sh" + "${PROJECT_SOURCE_DIR}" + "$" + "restart") +set_property(TEST TestSimulationSheathRestart_xperiod_vx PROPERTY TIMEOUT 200) diff --git a/tests/geometryXVx/sheath/test_sheath_restart.sh b/tests/geometryXVx/sheath/test_sheath_restart.sh new file mode 100644 index 000000000..09706a9d6 --- /dev/null +++ b/tests/geometryXVx/sheath/test_sheath_restart.sh @@ -0,0 +1,65 @@ +#!/bin/bash +set -xe + +if [ $# -ne 3 ] +then + echo "Usage: $0 " + exit 1 +fi +VOICEXX_SRCDIR="$1" +VOICEXX_EXEC="$2" +SIMULATION_NAME="$3" + +OUTDIR="${PWD}/${SIMULATION_NAME}" + +TMPDIR="$(mktemp -p "${PWD}" -d run-XXXXXXXXXX)" +function finish { + rm -rf "${TMPDIR}" +} +trap finish EXIT QUIT ABRT KILL SEGV TERM STOP + +cd "$(dirname "$0")" +TESTDIR="${PWD}" + +cd "${TMPDIR}" + +RSTDIR="${TMPDIR}/RST" +mkdir "${RSTDIR}" +cd "${RSTDIR}" + +"${VOICEXX_EXEC}" "--dump-config" "${PWD}/sheath.yaml" +sed -i 's/^ x_size: .*/ x_size: 16/' sheath.yaml +sed -i 's/^ vx_size: .*/ vx_size: 16/' sheath.yaml +sed -i 's/^ nbiter: .*/ nbiter: 10/' sheath.yaml +sed -i 's/^ deltat: .*/ deltat: 0.125/' sheath.yaml +sed -i 's/^ time_diag: .*/ time_diag: 0.25/' sheath.yaml + +"${VOICEXX_EXEC}" "${PWD}/sheath.yaml" + +cd "${TMPDIR}" +cp "${RSTDIR}/VOICEXX_initstate.h5" . +cp "${RSTDIR}/VOICEXX_00003.h5" . +cp "${RSTDIR}/sheath.yaml" sheath_restart.yaml + +"${VOICEXX_EXEC}" --iter-restart 3 "${PWD}/sheath_restart.yaml" +sed -i 's/^ nbiter: .*/ nbiter: 2/' sheath_restart.yaml +sed -i 's/^ time_diag: .*/ time_diag: 0.5/' sheath_restart.yaml + +h5ls -d ${PWD}/VOICEXX_00006.h5/time_saved ${RSTDIR}/VOICEXX_00005.h5/time_saved +command="h5diff ${PWD}/VOICEXX_00005.h5 ${RSTDIR}/VOICEXX_00005.h5 time_saved" +eval $command +if [ $? -ne 0 ]; then + exit 1 +fi + +command="h5diff ${PWD}/VOICEXX_00005.h5 ${RSTDIR}/VOICEXX_00005.h5 electrostatic_potential" +eval $command +if [ $? -ne 0 ]; then + exit 1 +fi + +command="h5diff ${PWD}/VOICEXX_00005.h5 ${RSTDIR}/VOICEXX_00005.h5 fdistribu" +eval $command +if [ $? -ne 0 ]; then + exit 1 +fi \ No newline at end of file