Loading...
Searching...
No Matches
OutputStream.hpp
/*
Copyright (c) 2019 Equinor ASA
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_IO_OUTPUTSTREAM_HPP_INCLUDED
#define OPM_IO_OUTPUTSTREAM_HPP_INCLUDED
#include <opm/io/eclipse/PaddedOutputString.hpp>
#include <opm/common/utility/TimeService.hpp>
#include <array>
#include <chrono>
#include <ios>
#include <memory>
#include <string>
#include <vector>
namespace Opm { namespace EclIO {
class EclOutput;
}} // namespace Opm::EclIO
namespace Opm { namespace EclIO { namespace OutputStream {
struct Formatted { bool set; };
struct Unified { bool set; };
struct ResultSet
{
std::string outputDir;
std::string baseName;
};
class Init
{
public:
explicit Init(const ResultSet& rset,
const Formatted& fmt);
~Init();
Init(const Init& rhs) = delete;
Init(Init&& rhs);
Init& operator=(const Init& rhs) = delete;
Init& operator=(Init&& rhs);
void write(const std::string& kw,
const std::vector<int>& data);
void write(const std::string& kw,
const std::vector<bool>& data);
void write(const std::string& kw,
const std::vector<float>& data);
void write(const std::string& kw,
const std::vector<double>& data);
void write(const std::string& kw,
const std::vector<PaddedOutputString<8>>& data);
void message(const std::string& msg);
private:
std::unique_ptr<EclOutput> stream_;
void open(const std::string& fname,
const bool formatted);
EclOutput& stream();
template <typename T>
void writeImpl(const std::string& kw,
const std::vector<T>& data);
};
class Restart
{
public:
explicit Restart(const ResultSet& rset,
const int seqnum,
const Formatted& fmt,
const Unified& unif);
~Restart();
Restart(const Restart& rhs) = delete;
Restart(Restart&& rhs);
Restart& operator=(const Restart& rhs) = delete;
Restart& operator=(Restart&& rhs);
void message(const std::string& msg);
void write(const std::string& kw,
const std::vector<int>& data);
void write(const std::string& kw,
const std::vector<bool>& data);
void write(const std::string& kw,
const std::vector<float>& data);
void write(const std::string& kw,
const std::vector<double>& data);
void write(const std::string& kw,
const std::vector<std::string>& data);
void write(const std::string& kw,
const std::vector<PaddedOutputString<8>>& data);
private:
std::unique_ptr<EclOutput> stream_;
void openUnified(const std::string& fname,
const bool formatted,
const int seqnum);
void openNew(const std::string& fname,
const bool formatted);
void openExisting(const std::string& fname,
const bool formatted,
const std::streampos writePos);
EclOutput& stream();
template <typename T>
void writeImpl(const std::string& kw,
const std::vector<T>& data);
};
class RFT
{
public:
struct OpenExisting { bool set; };
explicit RFT(const ResultSet& rset,
const Formatted& fmt,
const OpenExisting& existing);
~RFT();
RFT(const RFT& rhs) = delete;
RFT(RFT&& rhs);
RFT& operator=(const RFT& rhs) = delete;
RFT& operator=(RFT&& rhs);
void write(const std::string& kw,
const std::vector<int>& data);
void write(const std::string& kw,
const std::vector<float>& data);
void write(const std::string& kw,
const std::vector<PaddedOutputString<8>>& data);
private:
std::unique_ptr<EclOutput> stream_;
void open(const std::string& fname,
const bool formatted,
const bool existing);
EclOutput& stream();
template <typename T>
void writeImpl(const std::string& kw,
const std::vector<T>& data);
};
class SummarySpecification
{
public:
using StartTime = time_point;
enum class UnitConvention
{
Metric = 1,
Field = 2,
Lab = 3,
Pvt_M = 4,
};
struct RestartSpecification
{
std::string root;
int step;
};
class Parameters
{
public:
void add(const std::string& keyword,
const std::string& wgname,
const int num,
const std::string& unit);
friend class SummarySpecification;
private:
std::vector<PaddedOutputString<8>> keywords{};
std::vector<PaddedOutputString<8>> wgnames{};
std::vector<int> nums{};
std::vector<PaddedOutputString<8>> units{};
};
explicit SummarySpecification(const ResultSet& rset,
const Formatted& fmt,
const UnitConvention uconv,
const std::array<int,3>& cartDims,
const RestartSpecification& restart,
const StartTime start);
~SummarySpecification();
SummarySpecification(const SummarySpecification& rhs) = delete;
SummarySpecification(SummarySpecification&& rhs);
SummarySpecification& operator=(const SummarySpecification& rhs) = delete;
SummarySpecification& operator=(SummarySpecification&& rhs);
void write(const Parameters& params);
private:
int unit_;
int restartStep_;
std::array<int,3> cartDims_;
StartTime startDate_;
std::vector<PaddedOutputString<8>> restart_;
std::unique_ptr<EclOutput> stream_;
void rewindStream();
void flushStream();
EclOutput& stream();
};
std::unique_ptr<EclOutput>
createSummaryFile(const ResultSet& rset,
const int seqnum,
const Formatted& fmt,
const Unified& unif);
std::string outputFileName(const ResultSet& rsetDescriptor,
const std::string& ext);
}}} // namespace Opm::EclIO::OutputStream
#endif // OPM_IO_OUTPUTSTREAM_HPP_INCLUDED
Opm::EclIO::EclOutput
Definition EclOutput.hpp:38
Opm::EclIO::OutputStream::Init::write
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
Definition OutputStream.cpp:237
Opm::EclIO::OutputStream::Init::message
void message(const std::string &msg)
Definition OutputStream.cpp:271
Opm::EclIO::OutputStream::Init::Init
Init(const ResultSet &rset, const Formatted &fmt)
Constructor.
Definition OutputStream.cpp:212
Opm::EclIO::OutputStream::RFT::write
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
Definition OutputStream.cpp:516
Opm::EclIO::OutputStream::RFT::RFT
RFT(const ResultSet &rset, const Formatted &fmt, const OpenExisting &existing)
Constructor.
Definition OutputStream.cpp:490
Opm::EclIO::OutputStream::Restart::Restart
Restart(const ResultSet &rset, const int seqnum, const Formatted &fmt, const Unified &unif)
Constructor.
Definition OutputStream.cpp:304
Opm::EclIO::OutputStream::Restart::message
void message(const std::string &msg)
Generate a message string (keyword type 'MESS') in underlying output stream.
Definition OutputStream.cpp:343
Opm::EclIO::OutputStream::Restart::write
void write(const std::string &kw, const std::vector< int > &data)
Write integer data to underlying output stream.
Definition OutputStream.cpp:350
Opm::EclIO::OutputStream::SummarySpecification::Parameters
Definition OutputStream.hpp:396
Opm::EclIO::PaddedOutputString
Null-terminated, left adjusted, space padded array of N characters.
Definition PaddedOutputString.hpp:40
Opm::unit
Definition of various units.
Definition Units.hpp:84
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Opm::EclIO::OutputStream::Formatted
Definition OutputStream.hpp:41
Opm::EclIO::OutputStream::RFT::OpenExisting
Definition OutputStream.hpp:299
Opm::EclIO::OutputStream::ResultSet
Abstract representation of an ECLIPSE-style result set.
Definition OutputStream.hpp:46
Opm::EclIO::OutputStream::ResultSet::baseName
std::string baseName
Base name of simulation run.
Definition OutputStream.hpp:51
Opm::EclIO::OutputStream::ResultSet::outputDir
std::string outputDir
Output directory. Commonly "." or location of run's .DATA file.
Definition OutputStream.hpp:48
Opm::EclIO::OutputStream::SummarySpecification::RestartSpecification
Definition OutputStream.hpp:390
Opm::EclIO::OutputStream::Unified
Definition OutputStream.hpp:42