opm-common/opm/io/eclipse/OutputStream.hpp

456 lines
15 KiB
C++
Raw Permalink Normal View History

Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
/*
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 <array>
#include <chrono>
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
#include <ios>
#include <memory>
#include <string>
#include <vector>
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
namespace Opm { namespace EclIO {
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
class EclOutput;
}} // namespace Opm::EclIO
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
namespace Opm { namespace EclIO { namespace OutputStream {
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
struct Formatted { bool set; };
struct Unified { bool set; };
/// Abstract representation of an ECLIPSE-style result set.
struct ResultSet
{
/// Output directory. Commonly "." or location of run's .DATA file.
std::string outputDir;
/// Base name of simulation run.
std::string baseName;
};
/// File manager for "init" output streams.
class Init
{
public:
/// Constructor.
///
/// Opens file stream for writing.
///
/// \param[in] rset Output directory and base name of output stream.
///
/// \param[in] fmt Whether or not to create formatted output files.
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);
/// Write integer data to underlying output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<int>& data);
/// Write boolean data to underlying output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<bool>& data);
/// Write single precision floating point data to underlying
/// output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<float>& data);
/// Write double precision floating point data to underlying
/// output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<double>& data);
private:
/// Init file output stream.
std::unique_ptr<EclOutput> stream_;
/// Open output stream.
///
/// Writes to \c stream_.
///
/// \param[in] fname Filename of new output stream.
///
/// \param[in] formatted Whether or not to create a
/// formatted output file.
void open(const std::string& fname,
const bool formatted);
/// Access writable output stream.
EclOutput& stream();
/// Implementation function for public \c write overload set.
template <typename T>
void writeImpl(const std::string& kw,
const std::vector<T>& data);
};
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
/// File manager for restart output streams.
class Restart
{
public:
/// Constructor.
///
/// Opens file stream pertaining to restart of particular report
/// step and also outputs a SEQNUM record in the case of a unified
/// output stream.
///
/// Must be called before accessing the stream object through the
/// stream() member function.
///
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
/// \param[in] rset Output directory and base name of output stream.
///
/// \param[in] seqnum Sequence number of new report. One-based
/// report step ID.
///
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
/// \param[in] fmt Whether or not to create formatted output files.
///
/// \param[in] unif Whether or not to create unified output files.
explicit Restart(const ResultSet& rset,
const int seqnum,
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
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);
/// Generate a message string (keyword type 'MESS') in underlying
/// output stream.
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
///
/// \param[in] msg Message string (e.g., "STARTSOL").
void message(const std::string& msg);
/// Write integer data to underlying output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<int>& data);
/// Write boolean data to underlying output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<bool>& data);
/// Write single precision floating point data to underlying
/// output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<float>& data);
/// Write double precision floating point data to underlying
/// output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<double>& data);
/// Write unpadded string data to underlying output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<std::string>& data);
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
/// Write padded character data (8 characters per string)
/// to underlying output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<PaddedOutputString<8>>& data);
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
private:
/// Restart output stream.
std::unique_ptr<EclOutput> stream_;
/// Open unified output file and place stream's output indicator
/// in appropriate location.
///
/// Writes to \c stream_.
///
/// \param[in] fname Filename of output stream.
///
/// \param[in] formatted Whether or not to create a
/// formatted output file.
///
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
/// \param[in] seqnum Sequence number of new report. One-based
/// report step ID.
void openUnified(const std::string& fname,
const bool formatted,
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
const int seqnum);
/// Open new output stream.
///
/// Handles the case of separate output files or unified output file
/// that does not already exist. Writes to \c stream_.
///
/// \param[in] fname Filename of new output stream.
///
/// \param[in] formatted Whether or not to create a
/// formatted output file.
void openNew(const std::string& fname,
const bool formatted);
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
/// Open existing output file and place stream's output indicator
/// in appropriate location.
///
/// Writes to \c stream_.
///
/// \param[in] fname Filename of output stream.
///
/// \param[in] writePos Position at which to place stream's output
/// indicator. Use \code streampos{ streamoff{-1} } \endcode to
/// place output indicator at end of file (i.e, simple append).
void openExisting(const std::string& fname,
const bool formatted,
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
const std::streampos writePos);
/// Access writable output stream.
///
/// Must not be called prior to \c prepareStep.
EclOutput& stream();
/// Implementation function for public \c write overload set.
template <typename T>
void writeImpl(const std::string& kw,
const std::vector<T>& data);
};
/// File manager for RFT output streams
class RFT
{
public:
struct OpenExisting { bool set; };
/// Constructor.
///
/// Opens file stream for writing.
///
/// \param[in] rset Output directory and base name of output stream.
///
/// \param[in] fmt Whether or not to create formatted output files.
///
/// \param[in] existing Whether or not to open an existing output file.
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);
/// Write integer data to underlying output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<int>& data);
/// Write single precision floating point data to underlying
/// output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<float>& data);
/// Write padded character data (8 characters per string)
/// to underlying output stream.
///
/// \param[in] kw Name of output vector (keyword).
///
/// \param[in] data Output values.
void write(const std::string& kw,
const std::vector<PaddedOutputString<8>>& data);
private:
/// Init file output stream.
std::unique_ptr<EclOutput> stream_;
/// Open output stream.
///
/// Writes to \c stream_.
///
/// \param[in] fname Filename of new output stream.
///
/// \param[in] formatted Whether or not to create a
/// formatted output file.
///
/// \param[in] existing Whether or not to open an
/// existing output file (mode ios_base::app).
void open(const std::string& fname,
const bool formatted,
const bool existing);
/// Access writable output stream.
EclOutput& stream();
/// Implementation function for public \c write overload set.
template <typename T>
void writeImpl(const std::string& kw,
const std::vector<T>& data);
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
};
class SummarySpecification
{
public:
using StartTime = std::chrono::system_clock::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_;
/// Summary specification (SMSPEC) file output stream.
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);
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
/// Derive filename corresponding to output stream of particular result
/// set, with user-specified file extension.
///
/// Low-level string concatenation routine that does not know specific
/// relations between base names and file extensions. Handles details
/// of base name ending in a period (full stop) or having a name that
/// might otherwise appear to contain a file extension (e.g., CASE.01).
///
/// \param[in] rsetDescriptor Output directory and base name of result set.
///
/// \param[in] ext Filename extension.
///
/// \return outputDir/baseName.ext
std::string outputFileName(const ResultSet& rsetDescriptor,
const std::string& ext);
}}} // namespace Opm::EclIO::OutputStream
Restart Output: Add File Management Facility This commit introduces a new class, Opm::ecl::OutputStream::Restart that handles the details of opening restart output streams (all combinations of formatted/unformatted and unified/separate), as well as correctly positioning the stream 'put' indicator if we're opening an existing unified restart file. In most cases, this will be a simple append operation (std::ios_base::app), but there are some subtleties that require more precise control. The new class is befriended by EclOutput and ERst in order to access private member functions and data members of these classes. That is needed in order to handle file resize operations since some of the requisite information is only available in those two classes. We use Boost.Filesystem to implement file resize, as if by POSIX function ::truncate(), and also to simplify filename generation. These calls can be switched to std::filesystem once the project requires C++17. Intended use of the Restart class is Restart rst(resultSet, formatted, unified); rst.prepareStep(17); // Report step/SEQNUM 17. rst.write("INTEHEAD", ihead); // ... The 'prepareStep' operation opens the file stream (if needed) and also outputs a SEQNUM record in the case of a unified output stream. Moreover, the 'resultSet' is a pair of output directory and case's base name (e.g., "./mpi.np4/2019.05.14.01" and "NORNE_ATW2013") and the formatted/unified flags are bools wrapped in structures. The Restart class is intended to take over the role of the 'filename' string parameter of RestartIO::save(). Add a set of unit tests to demontrate usage and abilities of class Restart.
2019-05-27 06:03:57 -05:00
#endif // OPM_IO_OUTPUTSTREAM_HPP_INCLUDED