Loading...
Searching...
No Matches
SimulatorSerializer.hpp
/*
Copyright 2023 Equinor ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_SIMULATOR_SERIALIZER_HEADER_INCLUDED
#define OPM_SIMULATOR_SERIALIZER_HEADER_INCLUDED
#include <opm/simulators/utils/ParallelCommunication.hpp>
#include <array>
#include <string>
#include <vector>
namespace Opm {
class HDF5Serializer;
class IOConfig;
class SimulatorTimer;
struct SerializableSim {
virtual ~SerializableSim() = default;
virtual void loadState(HDF5Serializer& serializer,
const std::string& groupName) = 0;
virtual void saveState(HDF5Serializer& serializer,
const std::string& groupName) const = 0;
virtual std::array<std::string,5> getHeader() const = 0;
virtual const std::vector<int>& getCellMapping() const = 0;
};
class SimulatorSerializer {
public:
SimulatorSerializer(SerializableSim& simulator,
Parallel::Communication& comm,
const IOConfig& ioconfig,
const std::string& saveSpec,
int loadStep,
const std::string& saveFile,
const std::string& loadFile);
bool shouldLoad() const { return loadStep_ > -1; }
int loadStep() const { return loadStep_; }
void save(SimulatorTimer& timer);
void loadTimerInfo(SimulatorTimer& timer);
void loadState();
private:
void checkSerializedCmdLine(const std::string& current,
const std::string& stored);
#if HAVE_HDF5
SerializableSim& simulator_;
#endif // HAVE_HDF5
Parallel::Communication& comm_;
int saveStride_ = 0;
int saveStep_ = -1;
int loadStep_ = -1;
std::string saveFile_;
std::string loadFile_;
};
} // namespace Opm
#endif // OPM_SIMULATOR_SERIALIZER_HEADER_INCLUDED
Opm::HDF5Serializer
Class for (de-)serializing using HDF5.
Definition HDF5Serializer.hpp:37
Opm::SimulatorSerializer::loadState
void loadState()
Load state from file.
Definition SimulatorSerializer.cpp:180
Opm::SimulatorSerializer::loadTimerInfo
void loadTimerInfo(SimulatorTimer &timer)
Loads time step info from file.
Definition SimulatorSerializer.cpp:134
Opm::SimulatorSerializer::shouldLoad
bool shouldLoad() const
Returns whether or not a state should be loaded.
Definition SimulatorSerializer.hpp:74
Opm::SimulatorSerializer::save
void save(SimulatorTimer &timer)
Save data to file if appropriate.
Definition SimulatorSerializer.cpp:96
Opm::SimulatorSerializer::loadStep
int loadStep() const
Returns step to load.
Definition SimulatorSerializer.hpp:77
Opm::SimulatorSerializer::SimulatorSerializer
SimulatorSerializer(SerializableSim &simulator, Parallel::Communication &comm, const IOConfig &ioconfig, const std::string &saveSpec, int loadStep, const std::string &saveFile, const std::string &loadFile)
Constructor inits parameters.
Definition SimulatorSerializer.cpp:44
Opm::SimulatorTimer
Definition SimulatorTimer.hpp:39
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::SerializableSim
Abstract interface for simulator serialization ops.
Definition SimulatorSerializer.hpp:36
Opm::SerializableSim::loadState
virtual void loadState(HDF5Serializer &serializer, const std::string &groupName)=0
Load simulator state from file.
Opm::SerializableSim::getCellMapping
virtual const std::vector< int > & getCellMapping() const =0
Obtain local-to-global cell mapping.
Opm::SerializableSim::getHeader
virtual std::array< std::string, 5 > getHeader() const =0
Get header info to save to file.
Opm::SerializableSim::saveState
virtual void saveState(HDF5Serializer &serializer, const std::string &groupName) const =0
Save simulator state to file.