PolyFEM
Loading...
Searching...
No Matches
Checkpoint.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
5
6#include <Eigen/Core>
7
8#include <filesystem>
9#include <memory>
10#include <string>
11
13{
14 class Mesh;
15 class MeshData;
16} // namespace polyfem::mesh
17
18namespace polyfem::io
19{
20 inline constexpr long CHECKPOINT_SCHEMA_VERSION = 1;
21
23 {
24 public:
26 std::string formulation;
27 long step = 0;
28 double time = 0;
29 double dt = 0;
31 long output_index = 0;
32 };
33
35 {
36 public:
37 CheckpointWriter(const std::filesystem::path &path, const json &config, const CheckpointMetadata &metadata);
39
42
43 void write_matrix(const std::string &path, const Eigen::MatrixXd &value);
44 void write_int_matrix(const std::string &path, const Eigen::MatrixXi &value);
45 void write_bytes(const std::string &path, const std::vector<unsigned char> &value);
46 void write_vector(const std::string &path, const std::vector<double> &value);
47 void write_int_vector(const std::string &path, const std::vector<int> &value);
48 void write_long_vector(const std::string &path, const std::vector<long> &value);
49 void write_string(const std::string &path, const std::string &value);
50 void write_long(const std::string &path, long value);
51 void write_double(const std::string &path, double value);
52 void write_attribute(const std::string &path, const std::string &name, long value);
53 void write_attribute(const std::string &path, const std::string &name, const std::string &value);
54
55 void write_mesh(const std::string &group, const mesh::Mesh &mesh);
56 void write_mesh(const std::string &group, const mesh::MeshData &mesh);
57 void embed_resources(const ResourceIO &resources);
58 void finalize();
59
60 private:
61 class Impl;
62 std::unique_ptr<Impl> impl_;
63 std::filesystem::path path_;
64 std::filesystem::path temporary_path_;
65 bool finalized_ = false;
66 };
67
69 {
70 public:
71 explicit CheckpointReader(const std::filesystem::path &path);
72
73 const std::filesystem::path &path() const { return path_; }
74 const CheckpointMetadata &metadata() const { return metadata_; }
75 const json &config() const { return config_; }
76 const ResourceIO &resources() const { return *resources_; }
77 std::unique_ptr<mesh::Mesh> read_mesh(const std::string &path, bool non_conforming = false) const;
78
79 Eigen::MatrixXd read_matrix(const std::string &path) const;
80 Eigen::MatrixXi read_int_matrix(const std::string &path) const;
81 std::vector<double> read_vector(const std::string &path) const;
82 std::vector<int> read_int_vector(const std::string &path) const;
83 std::vector<long> read_long_vector(const std::string &path) const;
84 std::string read_string(const std::string &path) const;
85 long read_long(const std::string &path) const;
86 double read_double(const std::string &path) const;
87 bool exists(const std::string &path) const { return io_->exists(path); }
88
89 private:
90 std::filesystem::path path_;
91 std::unique_ptr<const HDF5IO> io_;
92 std::unique_ptr<const ResourceIO> resources_;
95 };
96} // namespace polyfem::io
const std::filesystem::path & path() const
CheckpointMetadata metadata_
std::filesystem::path path_
std::unique_ptr< mesh::Mesh > read_mesh(const std::string &path, bool non_conforming=false) const
long read_long(const std::string &path) const
double read_double(const std::string &path) const
Eigen::MatrixXd read_matrix(const std::string &path) const
const ResourceIO & resources() const
bool exists(const std::string &path) const
std::unique_ptr< const ResourceIO > resources_
std::unique_ptr< const HDF5IO > io_
Eigen::MatrixXi read_int_matrix(const std::string &path) const
const json & config() const
std::vector< int > read_int_vector(const std::string &path) const
std::string read_string(const std::string &path) const
std::vector< double > read_vector(const std::string &path) const
const CheckpointMetadata & metadata() const
std::vector< long > read_long_vector(const std::string &path) const
CheckpointWriter & operator=(const CheckpointWriter &)=delete
std::unique_ptr< Impl > impl_
void write_matrix(const std::string &path, const Eigen::MatrixXd &value)
std::filesystem::path path_
CheckpointWriter(const CheckpointWriter &)=delete
void write_attribute(const std::string &path, const std::string &name, long value)
void write_double(const std::string &path, double value)
std::filesystem::path temporary_path_
void write_int_matrix(const std::string &path, const Eigen::MatrixXi &value)
void write_mesh(const std::string &group, const mesh::Mesh &mesh)
void write_bytes(const std::string &path, const std::vector< unsigned char > &value)
void write_long_vector(const std::string &path, const std::vector< long > &value)
CheckpointWriter(const std::filesystem::path &path, const json &config, const CheckpointMetadata &metadata)
void write_string(const std::string &path, const std::string &value)
void write_long(const std::string &path, long value)
void embed_resources(const ResourceIO &resources)
void write_int_vector(const std::string &path, const std::vector< int > &value)
void write_vector(const std::string &path, const std::vector< double > &value)
Read-only interface to a hierarchical collection of simulation resources.
Format-independent input used to construct a runtime Mesh.
Definition MeshData.hpp:12
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:50
constexpr long CHECKPOINT_SCHEMA_VERSION
nlohmann::json json
Definition Common.hpp:9