From f53b7e09ea2e2d6c0104fd4538f104c5a0408864 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Fri, 25 Apr 2014 19:25:43 +0200 Subject: [PATCH] EclipseWriter: Write restart files this means we now write the current solution to the Eclipse output files. TODO: summary files. (this depends on having a well-model.) --- ewoms/io/eclipsewriter.hh | 58 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/ewoms/io/eclipsewriter.hh b/ewoms/io/eclipsewriter.hh index 79f635c78..63825ca5a 100644 --- a/ewoms/io/eclipsewriter.hh +++ b/ewoms/io/eclipsewriter.hh @@ -31,38 +31,28 @@ #include -#if HAVE_DUNE_CORNERPOINT -#include -#endif - #include #include +#include #include #include #include #include #include -// forward declaration of Dune::CpGrid -namespace Dune { -class CpGrid; -} - namespace Ewoms { template class EclipseWriter; +template +class EclGridManager; + // we need to use specialization here because we need to call -// Dune::CpGrid specific methods (i.e. methods which are not part of -// the Dune Grid Interface and which never will be). This would cause -// the compiler to bail out if a grid different than Dune::CpGrid was -// used. (one could also take advantage of the HAVE_DUNE_CORNERPOINT -// macro, but even then the compiler would fail if dune-cornerpoint -// was available but a different grid type was chosen...) +// EclGridManager-specific methods. // this is the stub class for non-cornerpoint grids -template +template class EclipseWriterHelper { friend class EclipseWriter; @@ -70,13 +60,14 @@ class EclipseWriterHelper static void writeHeaders_(EclipseWriter &writer) { OPM_THROW(std::logic_error, - "Eclipse binary output requires to use Dune::CpGrid"); + "Eclipse binary output requires to use Dune::EclGridManager (is: " + << Dune::className()); } }; // this is the "real" code for cornerpoint grids template -class EclipseWriterHelper +class EclipseWriterHelper > { friend class EclipseWriter; @@ -92,7 +83,6 @@ class EclipseWriterHelper OPM_THROW(std::logic_error, "Eclipse binary output requires the ERT libraries"); #else - // set the index of the first time step written to 0... writer.reportStepIdx_ = 0; @@ -142,7 +132,7 @@ class EclipseWriter : public BaseOutputWriter typedef BaseOutputWriter::ScalarBuffer ScalarBuffer; typedef BaseOutputWriter::VectorBuffer VectorBuffer; - friend class EclipseWriterHelper; + friend class EclipseWriterHelper; public: EclipseWriter(const Simulator &simulator) @@ -184,7 +174,7 @@ public: void beginWrite(double t) { if (enableEclipseOutput_() && reportStepIdx_ == 0) - EclipseWriterHelper::writeHeaders_(*this); + EclipseWriterHelper::writeHeaders_(*this); } /* @@ -220,7 +210,7 @@ public: */ void attachScalarElementData(ScalarBuffer &buf, std::string name) { - attachedBuffers_.push_back(&buf); + attachedBuffers_.push_back(std::pair(name, &buf)); } /* @@ -245,19 +235,31 @@ public: */ void endWrite(bool onlyDiscard = false) { - if (onlyDiscard) { + if (onlyDiscard || !enableEclipseOutput_()) { // detach all buffers attachedBuffers_.resize(0); - - --reportStepIdx_; - return; } -#warning "TODO: write the restart file!" + ErtRestartFile restartFile(simulator_, reportStepIdx_); + restartFile.writeHeader(simulator_, reportStepIdx_); + + ErtSolution solution(restartFile); + auto bufIt = attachedBuffers_.begin(); + const auto &bufEndIt = attachedBuffers_.end(); + for (; bufIt != bufEndIt; ++ bufIt) { + const std::string &name = bufIt->first; + const ScalarBuffer &buffer = *bufIt->second; + + ErtKeyword bufKeyword(name, buffer); + solution.add(bufKeyword); + } // detach all buffers attachedBuffers_.resize(0); + + // next time we take the next report step + ++ reportStepIdx_; } /*! @@ -316,7 +318,7 @@ private: double curTime_; int reportStepIdx_; - std::list attachedBuffers_; + std::list > attachedBuffers_; }; } // namespace Ewoms