27#ifndef OPM_RESTART_HPP
28#define OPM_RESTART_HPP
30#include <dune/geometry/dimension.hh>
31#include <dune/grid/common/rangegenerators.hh>
50 template <
class Gr
idView>
51 static std::string magicRestartCookie_(
const GridView& gridView)
53 static const std::string gridName =
"blubb";
54 static const int dim = GridView::dimension;
56 const int numVertices = gridView.size(
dim);
57 const int numElements = gridView.size(0);
58 const int numEdges = gridView.size(
dim - 1);
59 const int numCPUs = gridView.comm().size();
60 const int rank = gridView.comm().rank();
62 std::ostringstream oss;
63 oss <<
"eWoms restart file: "
64 <<
"gridName='" << gridName <<
"' "
65 <<
"numCPUs=" << numCPUs <<
" "
66 <<
"myRank=" << rank <<
" "
67 <<
"numElements=" << numElements <<
" "
68 <<
"numEdges=" << numEdges <<
" "
69 <<
"numVertices=" << numVertices;
76 static std::string restartFileName_(
int rank,
77 const std::string& outputDir,
78 const std::string& simName,
91 template <
class Simulator>
94 fileName_ = restartFileName_(simulator.
gridView().comm().rank(),
95 simulator.
problem().outputDir(),
100 openOutputStream(magicRestartCookie_(simulator.
gridView()));
107 {
return outStream_; }
124 template <
int codim,
class Serializer,
class Gr
idView>
129 for (
const auto& entity : entities(gridView, Dune::Codim<codim>())) {
130 serializer.serializeEntity(outStream_, entity);
146 template <
class Simulator,
class Scalar>
149 fileName_ = restartFileName_(simulator.
gridView().comm().rank(),
150 simulator.
problem().outputDir(),
151 simulator.
problem().name(), t);
152 openInputStream(magicRestartCookie_(simulator.
gridView()));
160 {
return inStream_; }
177 template <
int codim,
class Deserializer,
class Gr
idView>
185 for (
const auto& entity : entities(gridView, Dune::Codim<codim>())) {
186 if (!inStream_.good()) {
187 throw std::runtime_error(
"Restart file is corrupted");
190 std::getline(inStream_, curLine);
191 std::istringstream curLineStream(curLine);
192 deserializer.deserializeEntity(curLineStream, entity);
208 void openInputStream(
const std::string& cookie);
214 void openOutputStream(
const std::string& cookie);
216 std::string fileName_;
217 std::ifstream inStream_;
218 std::ofstream outStream_;
Load or save a state of a problem to/from the harddisk.
Definition: restart.hpp:45
std::istream & deserializeStream()
The input stream to read the data which ought to be deserialized.
Definition: restart.hpp:159
void serializeSectionEnd()
End of a section in the serialized output.
std::ostream & serializeStream()
The output stream to write the serialized data.
Definition: restart.hpp:106
void serializeBegin(Simulator &simulator)
Write the current state of the model to disk.
Definition: restart.hpp:92
void serializeEnd()
Finish the restart file.
const std::string & fileName() const
Returns the name of the file which is (de-)serialized.
Definition: restart.hpp:85
void serializeEntities(Serializer &serializer, const GridView &gridView)
Serialize all leaf entities of a codim in a gridView.
Definition: restart.hpp:125
void deserializeEntities(Deserializer &deserializer, const GridView &gridView)
Deserialize all leaf entities of a codim in a grid.
Definition: restart.hpp:178
void deserializeSectionEnd()
End of a section in the serialized output.
void deserializeBegin(Simulator &simulator, Scalar t)
Start reading a restart file at a certain simulated time.
Definition: restart.hpp:147
void serializeSectionBegin(const std::string &cookie)
Start a new section in the serialized output.
void deserializeSectionBegin(const std::string &cookie)
Start reading a new section of the restart file.
void deserializeEnd()
Stop reading the restart file.
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:84
Problem & problem()
Return the object which specifies the pysical setup of the simulation.
Definition: simulator.hh:265
const GridView & gridView() const
Return the grid view for which the simulation is done.
Definition: simulator.hh:246
Scalar time() const
Return the number of seconds of simulated time which have elapsed since the start time.
Definition: simulator.hh:317
static constexpr int dim
Definition: structuredgridvanguard.hh:68
Definition: blackoilboundaryratevector.hh:39
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)