SimulatorSerializer.hpp
Go to the documentation of this file.
1/*
2 Copyright 2023 Equinor ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_SIMULATOR_SERIALIZER_HEADER_INCLUDED
21#define OPM_SIMULATOR_SERIALIZER_HEADER_INCLUDED
22
24
25#include <array>
26#include <string>
27#include <vector>
28
29namespace Opm {
30
31class HDF5Serializer;
32class IOConfig;
33class SimulatorTimer;
34
37 virtual ~SerializableSim() = default;
38
40 virtual void loadState(HDF5Serializer& serializer,
41 const std::string& groupName) = 0;
42
44 virtual void saveState(HDF5Serializer& serializer,
45 const std::string& groupName) const = 0;
46
48 virtual std::array<std::string,5> getHeader() const = 0;
49
51 virtual const std::vector<int>& getCellMapping() const = 0;
52};
53
56public:
64 const IOConfig& ioconfig,
65 const std::string& saveSpec,
66 int loadStep,
67 const std::string& saveFile,
68 const std::string& loadFile);
69
71 bool shouldLoad() const { return loadStep_ > -1; }
72
74 int loadStep() const { return loadStep_; }
75
77 void save(SimulatorTimer& timer);
78
81
83 void loadState();
84
85private:
87 void checkSerializedCmdLine(const std::string& current,
88 const std::string& stored);
89
90 SerializableSim& simulator_;
92 int saveStride_ = 0;
93 int saveStep_ = -1;
94 int loadStep_ = -1;
95 std::string saveFile_;
96 std::string loadFile_;
97};
98
99} // namespace Opm
100
101#endif // OPM_SIMULATOR_SERIALIZER_HEADER_INCLUDED
Class for (de-)serializing using HDF5.
Definition: HDF5Serializer.hpp:37
Class handling simulator serialization.
Definition: SimulatorSerializer.hpp:55
void loadState()
Load state from file.
void loadTimerInfo(SimulatorTimer &timer)
Loads time step info from file.
bool shouldLoad() const
Returns whether or not a state should be loaded.
Definition: SimulatorSerializer.hpp:71
void save(SimulatorTimer &timer)
Save data to file if appropriate.
int loadStep() const
Returns step to load.
Definition: SimulatorSerializer.hpp:74
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: SimulatorTimer.hpp:39
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: BlackoilPhases.hpp:27
Abstract interface for simulator serialization ops.
Definition: SimulatorSerializer.hpp:36
virtual void loadState(HDF5Serializer &serializer, const std::string &groupName)=0
Load simulator state from file.
virtual const std::vector< int > & getCellMapping() const =0
Obtain local-to-global cell mapping.
virtual std::array< std::string, 5 > getHeader() const =0
Get header info to save to file.
virtual void saveState(HDF5Serializer &serializer, const std::string &groupName) const =0
Save simulator state to file.
virtual ~SerializableSim()=default