1 #ifndef ABLATELIBRARY_SERIALIZABLE_HPP
2 #define ABLATELIBRARY_SERIALIZABLE_HPP
31 [[nodiscard]]
virtual const std::string&
GetId()
const = 0;
39 virtual PetscErrorCode
Save(PetscViewer viewer, PetscInt sequenceNumber, PetscReal time) = 0;
47 virtual PetscErrorCode
Restore(PetscViewer viewer, PetscInt sequenceNumber, PetscReal time) = 0;
56 static PetscErrorCode
SaveKeyValue(PetscViewer viewer,
const char* name, PetscScalar value);
64 static PetscErrorCode
RestoreKeyValue(PetscViewer viewer,
const char* name, PetscScalar& value);
74 static inline PetscErrorCode
SaveKeyValue(PetscViewer viewer,
const char* name, T value) {
75 PetscFunctionBeginUser;
76 auto tempValue = (PetscScalar)value;
78 PetscFunctionReturn(0);
89 static inline PetscErrorCode
RestoreKeyValue(PetscViewer viewer,
const char* name, T& value) {
90 PetscFunctionBeginUser;
91 PetscScalar tempValue = {};
94 PetscFunctionReturn(0);
102 auto collectiveCount = std::count_if(types.begin(), types.end(), [](
auto& testProcess) {
103 auto serializable = std::dynamic_pointer_cast<ablate::io::Serializable>(testProcess);
104 return serializable != nullptr && serializable->Serialize() == SerializerType::collective;
106 auto serialCount = std::count_if(types.begin(), types.end(), [](
auto& testProcess) {
107 auto serializable = std::dynamic_pointer_cast<ablate::io::Serializable>(testProcess);
108 return serializable != nullptr && serializable->Serialize() == SerializerType::serial;
111 if (collectiveCount && serialCount) {
112 throw std::invalid_argument(
"All objects in DetermineSerializerType must be collective or serial");
113 }
else if (collectiveCount) {
114 return SerializerType::collective;
115 }
else if (serialCount) {
116 return SerializerType::serial;
118 return SerializerType::none;
Definition: serializable.hpp:13
static PetscErrorCode RestoreKeyValue(PetscViewer viewer, const char *name, PetscScalar &value)
Definition: serializable.cpp:26
virtual PetscErrorCode Restore(PetscViewer viewer, PetscInt sequenceNumber, PetscReal time)=0
virtual SerializerType Serialize() const
Definition: serializable.hpp:25
SerializerType
Definition: serializable.hpp:18
virtual const std::string & GetId() const =0
static SerializerType DetermineSerializerType(const T &types)
Definition: serializable.hpp:101
static PetscErrorCode SaveKeyValue(PetscViewer viewer, const char *name, T value)
Definition: serializable.hpp:74
static PetscErrorCode SaveKeyValue(PetscViewer viewer, const char *name, PetscScalar value)
Definition: serializable.cpp:5
virtual PetscErrorCode Save(PetscViewer viewer, PetscInt sequenceNumber, PetscReal time)=0
static PetscErrorCode RestoreKeyValue(PetscViewer viewer, const char *name, T &value)
Definition: serializable.hpp:89