45 : _serializable(serializable), _iBlock(0), _size(0), _fileName(fileName)
61 return _serializable.
getBlock(_iBlock++, sizeBlock, loadingMode);
64template<
bool includeLogOutputDir>
67 validateFileName(fileName);
68 std::ifstream istr(getFullFileName<includeLogOutputDir>(fileName).c_str());
80template<
bool includeLogOutputDir>
83 validateFileName(fileName);
88 std::ofstream ostr (getFullFileName<includeLogOutputDir>(fileName).c_str());
115 if (enforceRecompute || _size == 0) {
120void Serializer::validateFileName(std::string &fileName)
122 if (fileName ==
"") {
123 fileName = _fileName;
125 if (fileName ==
"") {
126 fileName =
"Serializable";
130template<
bool includeLogOutputDir>
131const std::string Serializer::getFullFileName(
const std::string& fileName)
133 if constexpr(includeLogOutputDir){
144template<
bool includeLogOutputDir>
148 return tmpSerializer.
save<includeLogOutputDir>();
151template<
bool includeLogOutputDir>
155 return tmpSerializer.
load<includeLogOutputDir>();
161 return tmpSerializer.
save(buffer);
167 return tmpSerializer.
load(buffer);
Base class for serializable objects of constant size. For dynamic size use BufferSerializable.
virtual bool * getBlock(const std::size_t iBlock, std::size_t &sizeBlock, const bool loadingMode=false)=0
Returns the address of the i-th block and its size.
virtual std::size_t getSerializableSize() const =0
Returns the binary size of the data to be saved.
bool save(std::string fileName="", const bool enforceUint=false)
Save Serializable into file fileName
bool load(std::string fileName="", const bool enforceUint=false)
Load Serializable from file fileName
Class for writing, reading, sending and receiving Serializable objects.
void resetCounter()
Resets the _iBlock counter.
std::size_t getSize() const
Returns the total memory size in bits.
bool load(std::string fileName="", const bool enforceUint=false)
Loads a file and pushes the data into the serialized class. Always in parallel, i....
bool save(std::string fileName="", const bool enforceUint=false)
Save _serializable into file filename. Always in parallel, i.e. one file per rank.
void computeSize(const bool enforceRecompute=false)
computes _size based on the individual definition of getBlock()
Serializer(Serializable &serializable, std::string fileName="")
Constructor.
bool * getNextBlock(std::size_t &sizeBlock, const bool loadingMode)
Returns pointer to the memory of the current block and increments iBlock
std::string getLogOutDir() const
These functions help you to create file names.
Wrapper functions that simplify the use of MPI.
Directories & directories()
Top level namespace for all of OpenLB.
void serializer2buffer(Serializer &serializer, std::uint8_t *buffer)
processes data from a serializer to a given buffer
std::string createParallelFileName(std::string name, bool withSize=true)
for parallel io, e.g. adds "_rank0000001" for rank=1, and optional "_size0000016" if withSize==true
void serializer2ostr(Serializer &serializer, std::ostream &ostr, bool enforceUint=false)
processes data from a serializer to a given ostr, always in parallel
void buffer2serializer(Serializer &serializer, const std::uint8_t *buffer)
processes a buffer to a serializer
void istr2serializer(Serializer &serializer, std::istream &istr, bool enforceUint=false)
processes an istr to a serializer, always in parallel
Definition of singletons: global, publicly available information.