27#ifndef OPM_RESTART_HPP
28#define OPM_RESTART_HPP
46 template <
class Gr
idView>
47 static std::string magicRestartCookie_(
const GridView& gridView)
49 static const std::string gridName =
"blubb";
50 static const int dim = GridView::dimension;
52 int numVertices = gridView.size(
dim);
53 int numElements = gridView.size(0);
54 int numEdges = gridView.size(
dim - 1);
55 int numCPUs = gridView.comm().size();
56 int rank = gridView.comm().rank();
58 std::ostringstream oss;
59 oss <<
"eWoms restart file: "
60 <<
"gridName='" << gridName <<
"' "
61 <<
"numCPUs=" << numCPUs <<
" "
62 <<
"myRank=" << rank <<
" "
63 <<
"numElements=" << numElements <<
" "
64 <<
"numEdges=" << numEdges <<
" "
65 <<
"numVertices=" << numVertices;
72 static std::string restartFileName_(
int rank,
73 const std::string& outputDir,
74 const std::string& simName,
87 template <
class Simulator>
90 fileName_ = restartFileName_(simulator.
gridView().comm().rank(),
91 simulator.
problem().outputDir(),
96 openOutputStream(magicRestartCookie_(simulator.
gridView()));
103 {
return outStream_; }
120 template <
int codim,
class Serializer,
class Gr
idView>
123 std::ostringstream oss;
124 oss <<
"Entities: Codim " << codim;
125 std::string cookie = oss.str();
129 using Iterator =
typename GridView::template Codim<codim>::Iterator;
131 Iterator it = gridView.template begin<codim>();
132 const Iterator& endIt = gridView.template end<codim>();
133 for (; it != endIt; ++it) {
134 serializer.serializeEntity(outStream_, *it);
150 template <
class Simulator,
class Scalar>
153 fileName_ = restartFileName_(simulator.
gridView().comm().rank(),
154 simulator.
problem().outputDir(),
155 simulator.
problem().name(), t);
156 openInputStream(magicRestartCookie_(simulator.
gridView()));
164 {
return inStream_; }
181 template <
int codim,
class Deserializer,
class Gr
idView>
184 std::ostringstream oss;
185 oss <<
"Entities: Codim " << codim;
186 std::string cookie = oss.str();
192 using Iterator =
typename GridView::template Codim<codim>::Iterator;
193 Iterator it = gridView.template begin<codim>();
194 const Iterator& endIt = gridView.template end<codim>();
195 for (; it != endIt; ++it) {
196 if (!inStream_.good()) {
197 throw std::runtime_error(
"Restart file is corrupted");
200 std::getline(inStream_, curLine);
201 std::istringstream curLineStream(curLine);
202 deserializer.deserializeEntity(curLineStream, *it);
218 void openInputStream(
const std::string& cookie);
224 void openOutputStream(
const std::string& cookie);
226 std::string fileName_;
227 std::ifstream inStream_;
228 std::ofstream outStream_;
Load or save a state of a problem to/from the harddisk.
Definition: restart.hpp:41
std::istream & deserializeStream()
The input stream to read the data which ought to be deserialized.
Definition: restart.hpp:163
void serializeSectionEnd()
End of a section in the serialized output.
std::ostream & serializeStream()
The output stream to write the serialized data.
Definition: restart.hpp:102
void serializeBegin(Simulator &simulator)
Write the current state of the model to disk.
Definition: restart.hpp:88
void serializeEnd()
Finish the restart file.
const std::string & fileName() const
Returns the name of the file which is (de-)serialized.
Definition: restart.hpp:81
void serializeEntities(Serializer &serializer, const GridView &gridView)
Serialize all leaf entities of a codim in a gridView.
Definition: restart.hpp:121
void deserializeEntities(Deserializer &deserializer, const GridView &gridView)
Deserialize all leaf entities of a codim in a grid.
Definition: restart.hpp:182
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:151
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:92
Problem & problem()
Return the object which specifies the pysical setup of the simulation.
Definition: simulator.hh:291
const GridView & gridView() const
Return the grid view for which the simulation is done.
Definition: simulator.hh:272
Scalar time() const
Return the number of seconds of simulated time which have elapsed since the start time.
Definition: simulator.hh:343
static const int dim
Definition: structuredgridvanguard.hh:67
Definition: blackoilboundaryratevector.hh:37