mirror of
https://git.gfz-potsdam.de/naaice/poet.git
synced 2025-12-15 12:28:22 +01:00
feat: Implement checkpointing
Co-authored-by: hmars-t <hmars-t@users.noreply.github.com>
This commit is contained in:
parent
e94eadd5cb
commit
4a3a3e3b6b
@ -1,8 +1,27 @@
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
cli11
|
||||
QUIET
|
||||
GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git
|
||||
GIT_TAG v2.4.2
|
||||
)
|
||||
|
||||
FetchContent_Declare(
|
||||
highfive
|
||||
QUIET
|
||||
GIT_REPOSITORY https://github.com/highfive-devs/highfive.git
|
||||
GIT_TAG v3.0.0
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(cli11)
|
||||
FetchContent_MakeAvailable(highfive)
|
||||
|
||||
add_library(POETLib
|
||||
Init/InitialList.cpp
|
||||
Init/GridInit.cpp
|
||||
Init/DiffusionInit.cpp
|
||||
Init/ChemistryInit.cpp
|
||||
IO/checkpoint.cpp
|
||||
DataStructures/Field.cpp
|
||||
Transport/DiffusionModule.cpp
|
||||
Chemistry/ChemistryModule.cpp
|
||||
@ -30,18 +49,10 @@ target_link_libraries(
|
||||
PUBLIC RRuntime
|
||||
PUBLIC IPhreeqcPOET
|
||||
PUBLIC tug
|
||||
PUBLIC MPI::MPI_C
|
||||
PUBLIC MPI::MPI_C
|
||||
PUBLIC HighFive::HighFive
|
||||
)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
cli11
|
||||
QUIET
|
||||
GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git
|
||||
GIT_TAG v2.4.2
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(cli11)
|
||||
|
||||
# add_library(poetlib
|
||||
# Base/Grid.cpp
|
||||
|
||||
9
src/IO/Datatypes.hpp
Normal file
9
src/IO/Datatypes.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <DataStructures/Field.hpp>
|
||||
|
||||
struct Checkpoint_s {
|
||||
poet::Field &field;
|
||||
uint32_t iteration;
|
||||
};
|
||||
8
src/IO/HDF5Functions.hpp
Normal file
8
src/IO/HDF5Functions.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "Datatypes.hpp"
|
||||
|
||||
int write_checkpoint(const std::string &file_path, struct Checkpoint_s &&checkpoint);
|
||||
|
||||
int read_checkpoint(const std::string &file_path, struct Checkpoint_s &checkpoint);
|
||||
28
src/IO/checkpoint.cpp
Normal file
28
src/IO/checkpoint.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "IO/Datatypes.hpp"
|
||||
#include <cstdint>
|
||||
#include <highfive/H5Easy.hpp>
|
||||
|
||||
int write_checkpoint(const std::string &file_path, struct Checkpoint_s &&checkpoint){
|
||||
|
||||
// TODO: errorhandling
|
||||
H5Easy::File file(file_path, H5Easy::File::Overwrite);
|
||||
|
||||
|
||||
H5Easy::dump(file, "/MetaParam/Iterations", checkpoint.iteration);
|
||||
H5Easy::dump(file, "/Grid/Names", checkpoint.field.GetProps());
|
||||
H5Easy::dump(file, "/Grid/Chemistry", checkpoint.field.As2DVector());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read_checkpoint(const std::string &file_path, struct Checkpoint_s &checkpoint){
|
||||
|
||||
H5Easy::File file(file_path, H5Easy::File::ReadOnly);
|
||||
|
||||
checkpoint.iteration = H5Easy::load<uint32_t>(file, "/MetaParam/Iterations");
|
||||
|
||||
checkpoint.field = H5Easy::load<std::vector<std::vector<double>>>(file, "/Grid/Chemistry");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
14
src/poet.cpp
14
src/poet.cpp
@ -26,6 +26,8 @@
|
||||
#include "CLI/CLI.hpp"
|
||||
#include "Chemistry/ChemistryModule.hpp"
|
||||
#include "DataStructures/Field.hpp"
|
||||
#include "IO/Datatypes.hpp"
|
||||
#include "IO/HDF5Functions.hpp"
|
||||
#include "Init/InitialList.hpp"
|
||||
#include "Transport/DiffusionModule.hpp"
|
||||
|
||||
@ -393,6 +395,18 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, const RuntimeParameters ¶ms,
|
||||
// store_result is TRUE)
|
||||
call_master_iter_end(R, diffusion.getField(), chem.getField());
|
||||
|
||||
// TODO: write checkpoint
|
||||
// checkpoint struct --> field and iteration
|
||||
|
||||
if (iter == 1) {
|
||||
write_checkpoint("checkpoint1.hdf5",
|
||||
{.field = chem.getField(), .iteration = iter});
|
||||
} else if (iter == 2) {
|
||||
Checkpoint_s checkpoint_read{.field = chem.getField()};
|
||||
read_checkpoint("checkpoint1.hdf5", checkpoint_read);
|
||||
iter = checkpoint_read.iteration;
|
||||
}
|
||||
|
||||
diffusion.getField().update(chem.getField());
|
||||
|
||||
MSG("End of *coupling* iteration " + std::to_string(iter) + "/" +
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user