opm-simulators
SimulatorSerializer.hpp
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 
23 #include <opm/simulators/utils/ParallelCommunication.hpp>
24 
25 #include <array>
26 #include <string>
27 #include <vector>
28 
29 namespace Opm {
30 
31 class HDF5Serializer;
32 class IOConfig;
33 class 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 
56 public:
66  Parallel::Communication& comm,
67  const IOConfig& ioconfig,
68  const std::string& saveSpec,
69  int loadStep,
70  const std::string& saveFile,
71  const std::string& loadFile);
72 
74  bool shouldLoad() const { return loadStep_ > -1; }
75 
77  int loadStep() const { return loadStep_; }
78 
80  void save(SimulatorTimer& timer);
81 
83  void loadTimerInfo(SimulatorTimer& timer);
84 
86  void loadState();
87 
88 private:
90  void checkSerializedCmdLine(const std::string& current,
91  const std::string& stored);
92 
93 #if HAVE_HDF5
94  SerializableSim& simulator_;
95 #endif // HAVE_HDF5
96  Parallel::Communication& comm_;
97  int saveStride_ = 0;
98  int saveStep_ = -1;
99  int loadStep_ = -1;
100  std::string saveFile_;
101  std::string loadFile_;
102 };
103 
104 } // namespace Opm
105 
106 #endif // OPM_SIMULATOR_SERIALIZER_HEADER_INCLUDED
void save(SimulatorTimer &timer)
Save data to file if appropriate.
Definition: SimulatorSerializer.cpp:96
virtual std::array< std::string, 5 > getHeader() const =0
Get header info to save to file.
virtual const std::vector< int > & getCellMapping() const =0
Obtain local-to-global cell mapping.
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
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
void loadState()
Load state from file.
Definition: SimulatorSerializer.cpp:180
Class for (de-)serializing using HDF5.
Definition: HDF5Serializer.hpp:37
bool shouldLoad() const
Returns whether or not a state should be loaded.
Definition: SimulatorSerializer.hpp:74
void loadTimerInfo(SimulatorTimer &timer)
Loads time step info from file.
Definition: SimulatorSerializer.cpp:134
virtual void saveState(HDF5Serializer &serializer, const std::string &groupName) const =0
Save simulator state to file.
Class handling simulator serialization.
Definition: SimulatorSerializer.hpp:55
int loadStep() const
Returns step to load.
Definition: SimulatorSerializer.hpp:77
virtual void loadState(HDF5Serializer &serializer, const std::string &groupName)=0
Load simulator state from file.
Definition: SimulatorTimer.hpp:38
Abstract interface for simulator serialization ops.
Definition: SimulatorSerializer.hpp:36