Add RFT Output Stream
This commit introduces a new output stream, 'RFT', that is intended as a new backend for writing RFT files. At present this supports integer, float, and PaddedOutputString<8> element types since those are the types needed for basic RFT data. We will extend the element support if needed for PLT and/or Segment data. We support formatted and unformatted output streams and distinguish between opening a new stream and opening an existing output stream (essentially between open modes ios_base::out and ios_base::app). Add unit tests to exercise the possible combinations.
This commit is contained in:
parent
4388c9d72f
commit
a281a3c6f4
@ -276,6 +276,87 @@ namespace Opm { namespace EclIO { namespace OutputStream {
|
||||
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);
|
||||
};
|
||||
|
||||
/// Derive filename corresponding to output stream of particular result
|
||||
/// set, with user-specified file extension.
|
||||
///
|
||||
|
@ -59,6 +59,11 @@ namespace {
|
||||
|
||||
return ext.str();
|
||||
}
|
||||
|
||||
std::string rft(const bool formatted)
|
||||
{
|
||||
return formatted ? "FRFT" : "RFT";
|
||||
}
|
||||
} // namespace FileExtension
|
||||
|
||||
namespace Open
|
||||
@ -128,6 +133,31 @@ namespace {
|
||||
};
|
||||
}
|
||||
} // namespace Restart
|
||||
|
||||
namespace Rft
|
||||
{
|
||||
std::unique_ptr<Opm::EclIO::EclOutput>
|
||||
writeNew(const std::string& filename,
|
||||
const bool isFmt)
|
||||
{
|
||||
return std::unique_ptr<Opm::EclIO::EclOutput> {
|
||||
new Opm::EclIO::EclOutput {
|
||||
filename, isFmt, std::ios_base::out
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
std::unique_ptr<Opm::EclIO::EclOutput>
|
||||
writeExisting(const std::string& filename,
|
||||
const bool isFmt)
|
||||
{
|
||||
return std::unique_ptr<Opm::EclIO::EclOutput> {
|
||||
new Opm::EclIO::EclOutput {
|
||||
filename, isFmt, std::ios_base::app
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace Rft
|
||||
} // namespace Open
|
||||
} // Anonymous namespace
|
||||
|
||||
@ -396,6 +426,84 @@ namespace Opm { namespace EclIO { namespace OutputStream {
|
||||
|
||||
}}}
|
||||
|
||||
// =====================================================================
|
||||
|
||||
Opm::EclIO::OutputStream::RFT::
|
||||
RFT(const ResultSet& rset,
|
||||
const Formatted& fmt,
|
||||
const OpenExisting& existing)
|
||||
{
|
||||
const auto fname = outputFileName(rset, FileExtension::rft(fmt.set));
|
||||
|
||||
this->open(fname, fmt.set, existing.set);
|
||||
}
|
||||
|
||||
Opm::EclIO::OutputStream::RFT::~RFT()
|
||||
{}
|
||||
|
||||
Opm::EclIO::OutputStream::RFT::RFT(RFT&& rhs)
|
||||
: stream_{ std::move(rhs.stream_) }
|
||||
{}
|
||||
|
||||
Opm::EclIO::OutputStream::RFT&
|
||||
Opm::EclIO::OutputStream::RFT::operator=(RFT&& rhs)
|
||||
{
|
||||
this->stream_ = std::move(rhs.stream_);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
Opm::EclIO::OutputStream::RFT::
|
||||
write(const std::string& kw, const std::vector<int>& data)
|
||||
{
|
||||
this->writeImpl(kw, data);
|
||||
}
|
||||
|
||||
void
|
||||
Opm::EclIO::OutputStream::RFT::
|
||||
write(const std::string& kw, const std::vector<float>& data)
|
||||
{
|
||||
this->writeImpl(kw, data);
|
||||
}
|
||||
|
||||
void
|
||||
Opm::EclIO::OutputStream::RFT::
|
||||
write(const std::string& kw,
|
||||
const std::vector<PaddedOutputString<8>>& data)
|
||||
{
|
||||
this->writeImpl(kw, data);
|
||||
}
|
||||
|
||||
void
|
||||
Opm::EclIO::OutputStream::RFT::
|
||||
open(const std::string& fname,
|
||||
const bool formatted,
|
||||
const bool existing)
|
||||
{
|
||||
this->stream_ = existing
|
||||
? Open::Rft::writeExisting(fname, formatted)
|
||||
: Open::Rft::writeNew (fname, formatted);
|
||||
}
|
||||
|
||||
Opm::EclIO::EclOutput&
|
||||
Opm::EclIO::OutputStream::RFT::stream()
|
||||
{
|
||||
return *this->stream_;
|
||||
}
|
||||
|
||||
namespace Opm { namespace EclIO { namespace OutputStream {
|
||||
|
||||
template <typename T>
|
||||
void RFT::writeImpl(const std::string& kw,
|
||||
const std::vector<T>& data)
|
||||
{
|
||||
this->stream().write(kw, data);
|
||||
}
|
||||
|
||||
}}} // namespace Opm::EclIO::OutputStream
|
||||
|
||||
// =====================================================================
|
||||
|
||||
std::string
|
||||
Opm::EclIO::OutputStream::outputFileName(const ResultSet& rsetDescriptor,
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <opm/io/eclipse/EclFile.hpp>
|
||||
#include <opm/io/eclipse/EclOutput.hpp>
|
||||
#include <opm/io/eclipse/ERst.hpp>
|
||||
#include <opm/io/eclipse/PaddedOutputString.hpp>
|
||||
|
||||
#include <opm/io/eclipse/EclIOdata.hpp>
|
||||
|
||||
@ -1085,3 +1086,647 @@ BOOST_AUTO_TEST_CASE(Formatted_Separate)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() // Class_Restart
|
||||
|
||||
// ==========================================================================
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(Class_RFT)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Unformatted_New)
|
||||
{
|
||||
using Char8 = ::Opm::EclIO::PaddedOutputString<8>;
|
||||
|
||||
const auto rset = RSet("CASE");
|
||||
const auto fmt = ::Opm::EclIO::OutputStream::Formatted{ false };
|
||||
const auto exist = ::Opm::EclIO::OutputStream::RFT::OpenExisting{ false };
|
||||
|
||||
{
|
||||
auto rft = ::Opm::EclIO::OutputStream::RFT {
|
||||
rset, fmt, exist
|
||||
};
|
||||
|
||||
rft.write("I", std::vector<int> {1, 7, 2, 9});
|
||||
rft.write("S", std::vector<float> {3.1f, 4.1f, 59.265f});
|
||||
rft.write("Z", std::vector<Char8> {
|
||||
Char8{" Hello "}, Char8{" World "}
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto fname = ::Opm::EclIO::OutputStream::
|
||||
outputFileName(rset, "RFT");
|
||||
|
||||
auto rft = ::Opm::EclIO::EclFile{fname};
|
||||
|
||||
BOOST_CHECK(rft.hasKey("I"));
|
||||
BOOST_CHECK(rft.hasKey("S"));
|
||||
BOOST_CHECK(rft.hasKey("Z"));
|
||||
BOOST_CHECK(!rft.hasKey("C"));
|
||||
|
||||
{
|
||||
const auto vectors = rft.getList();
|
||||
const auto expect_vectors = std::vector<Opm::EclIO::EclFile::EclEntry>{
|
||||
Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4},
|
||||
Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2},
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(),
|
||||
expect_vectors.begin(),
|
||||
expect_vectors.end());
|
||||
}
|
||||
|
||||
rft.loadData();
|
||||
|
||||
{
|
||||
const auto& I = rft.get<int>("I");
|
||||
const auto expect_I = std::vector<int>{ 1, 7, 2, 9 };
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(),
|
||||
expect_I.begin(),
|
||||
expect_I.end());
|
||||
}
|
||||
|
||||
{
|
||||
const auto& S = rft.get<float>("S");
|
||||
const auto expect_S = std::vector<float>{
|
||||
3.1f, 4.1f, 59.265f,
|
||||
};
|
||||
|
||||
check_is_close(S, expect_S);
|
||||
}
|
||||
|
||||
{
|
||||
const auto& Z = rft.get<std::string>("Z");
|
||||
const auto expect_Z = std::vector<std::string>{
|
||||
" Hello", " World" // Trailing blanks trimmed
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(),
|
||||
expect_Z.begin(), expect_Z.end());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto rft = ::Opm::EclIO::OutputStream::RFT {
|
||||
rset, fmt, exist
|
||||
};
|
||||
|
||||
rft.write("I2", std::vector<int> {11, 22, 33});
|
||||
rft.write("S2", std::vector<float> {2.71f, 828.1f, 8.218f});
|
||||
rft.write("Z2", std::vector<Char8> {
|
||||
Char8{"Good B"}, Char8{" ye"}, Char8{ "W0rlD" },
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto fname = ::Opm::EclIO::OutputStream::
|
||||
outputFileName(rset, "RFT");
|
||||
|
||||
auto rft = ::Opm::EclIO::EclFile{fname};
|
||||
|
||||
BOOST_CHECK(!rft.hasKey("I"));
|
||||
BOOST_CHECK(!rft.hasKey("S"));
|
||||
BOOST_CHECK(!rft.hasKey("Z"));
|
||||
|
||||
BOOST_CHECK(rft.hasKey("I2"));
|
||||
BOOST_CHECK(rft.hasKey("S2"));
|
||||
BOOST_CHECK(rft.hasKey("Z2"));
|
||||
|
||||
{
|
||||
const auto vectors = rft.getList();
|
||||
const auto expect_vectors = std::vector<Opm::EclIO::EclFile::EclEntry>{
|
||||
Opm::EclIO::EclFile::EclEntry{"I2", Opm::EclIO::eclArrType::INTE, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"S2", Opm::EclIO::eclArrType::REAL, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"Z2", Opm::EclIO::eclArrType::CHAR, 3},
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(),
|
||||
expect_vectors.begin(),
|
||||
expect_vectors.end());
|
||||
}
|
||||
|
||||
rft.loadData();
|
||||
|
||||
{
|
||||
const auto& I = rft.get<int>("I2");
|
||||
const auto expect_I = std::vector<int>{ 11, 22, 33 };
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(),
|
||||
expect_I.begin(),
|
||||
expect_I.end());
|
||||
}
|
||||
|
||||
{
|
||||
const auto& S = rft.get<float>("S2");
|
||||
const auto expect_S = std::vector<float>{
|
||||
2.71f, 828.1f, 8.218f,
|
||||
};
|
||||
|
||||
check_is_close(S, expect_S);
|
||||
}
|
||||
|
||||
{
|
||||
const auto& Z = rft.get<std::string>("Z2");
|
||||
const auto expect_Z = std::vector<std::string>{
|
||||
"Good B", " ye", "W0rlD"
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(),
|
||||
expect_Z.begin(), expect_Z.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Unformatted_Existing)
|
||||
{
|
||||
using Char8 = ::Opm::EclIO::PaddedOutputString<8>;
|
||||
|
||||
const auto rset = RSet("CASE");
|
||||
const auto fmt = ::Opm::EclIO::OutputStream::Formatted{ false };
|
||||
const auto exist = ::Opm::EclIO::OutputStream::RFT::OpenExisting{ true };
|
||||
|
||||
{
|
||||
auto rft = ::Opm::EclIO::OutputStream::RFT {
|
||||
rset, fmt, exist
|
||||
};
|
||||
|
||||
rft.write("I", std::vector<int> {1, 7, 2, 9});
|
||||
rft.write("S", std::vector<float> {3.1f, 4.1f, 59.265f});
|
||||
rft.write("Z", std::vector<Char8> {
|
||||
Char8{" Hello "}, Char8{" World "}
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto fname = ::Opm::EclIO::OutputStream::
|
||||
outputFileName(rset, "RFT");
|
||||
|
||||
auto rft = ::Opm::EclIO::EclFile{fname};
|
||||
|
||||
BOOST_CHECK(rft.hasKey("I"));
|
||||
BOOST_CHECK(rft.hasKey("S"));
|
||||
BOOST_CHECK(rft.hasKey("Z"));
|
||||
|
||||
BOOST_CHECK(!rft.hasKey("C"));
|
||||
|
||||
{
|
||||
const auto vectors = rft.getList();
|
||||
const auto expect_vectors = std::vector<Opm::EclIO::EclFile::EclEntry>{
|
||||
Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4},
|
||||
Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2},
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(),
|
||||
expect_vectors.begin(),
|
||||
expect_vectors.end());
|
||||
}
|
||||
|
||||
rft.loadData();
|
||||
|
||||
{
|
||||
const auto& I = rft.get<int>("I");
|
||||
const auto expect_I = std::vector<int>{ 1, 7, 2, 9 };
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(),
|
||||
expect_I.begin(),
|
||||
expect_I.end());
|
||||
}
|
||||
|
||||
{
|
||||
const auto& S = rft.get<float>("S");
|
||||
const auto expect_S = std::vector<float>{
|
||||
3.1f, 4.1f, 59.265f,
|
||||
};
|
||||
|
||||
check_is_close(S, expect_S);
|
||||
}
|
||||
|
||||
{
|
||||
const auto& Z = rft.get<std::string>("Z");
|
||||
const auto expect_Z = std::vector<std::string>{
|
||||
" Hello", " World" // Trailing blanks trimmed
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(),
|
||||
expect_Z.begin(), expect_Z.end());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto rft = ::Opm::EclIO::OutputStream::RFT {
|
||||
rset, fmt, exist
|
||||
};
|
||||
|
||||
rft.write("I2", std::vector<int> {11, 22, 33});
|
||||
rft.write("S2", std::vector<float> {2.71f, 828.1f, 8.218f});
|
||||
rft.write("Z2", std::vector<Char8> {
|
||||
Char8{"Good B"}, Char8{" ye"}, Char8{ "W0rlD" },
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto fname = ::Opm::EclIO::OutputStream::
|
||||
outputFileName(rset, "RFT");
|
||||
|
||||
auto rft = ::Opm::EclIO::EclFile{fname};
|
||||
|
||||
BOOST_CHECK(rft.hasKey("I"));
|
||||
BOOST_CHECK(rft.hasKey("S"));
|
||||
BOOST_CHECK(rft.hasKey("Z"));
|
||||
BOOST_CHECK(rft.hasKey("I2"));
|
||||
BOOST_CHECK(rft.hasKey("S2"));
|
||||
BOOST_CHECK(rft.hasKey("Z2"));
|
||||
|
||||
BOOST_CHECK(!rft.hasKey("C"));
|
||||
|
||||
{
|
||||
const auto vectors = rft.getList();
|
||||
const auto expect_vectors = std::vector<Opm::EclIO::EclFile::EclEntry>{
|
||||
Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4},
|
||||
Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2},
|
||||
Opm::EclIO::EclFile::EclEntry{"I2", Opm::EclIO::eclArrType::INTE, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"S2", Opm::EclIO::eclArrType::REAL, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"Z2", Opm::EclIO::eclArrType::CHAR, 3},
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(),
|
||||
expect_vectors.begin(),
|
||||
expect_vectors.end());
|
||||
}
|
||||
|
||||
rft.loadData();
|
||||
|
||||
{
|
||||
const auto& I = rft.get<int>("I");
|
||||
const auto expect_I = std::vector<int>{ 1, 7, 2, 9 };
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(),
|
||||
expect_I.begin(),
|
||||
expect_I.end());
|
||||
}
|
||||
|
||||
{
|
||||
const auto& S = rft.get<float>("S");
|
||||
const auto expect_S = std::vector<float>{
|
||||
3.1f, 4.1f, 59.265f,
|
||||
};
|
||||
|
||||
check_is_close(S, expect_S);
|
||||
}
|
||||
|
||||
{
|
||||
const auto& Z = rft.get<std::string>("Z");
|
||||
const auto expect_Z = std::vector<std::string>{
|
||||
" Hello", " World" // Trailing blanks trimmed
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(),
|
||||
expect_Z.begin(), expect_Z.end());
|
||||
}
|
||||
{
|
||||
const auto& I = rft.get<int>("I2");
|
||||
const auto expect_I = std::vector<int>{ 11, 22, 33 };
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(),
|
||||
expect_I.begin(),
|
||||
expect_I.end());
|
||||
}
|
||||
|
||||
{
|
||||
const auto& S = rft.get<float>("S2");
|
||||
const auto expect_S = std::vector<float>{
|
||||
2.71f, 828.1f, 8.218f,
|
||||
};
|
||||
|
||||
check_is_close(S, expect_S);
|
||||
}
|
||||
|
||||
{
|
||||
const auto& Z = rft.get<std::string>("Z2");
|
||||
const auto expect_Z = std::vector<std::string>{
|
||||
"Good B", " ye", "W0rlD"
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(),
|
||||
expect_Z.begin(), expect_Z.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Formatted_New)
|
||||
{
|
||||
using Char8 = ::Opm::EclIO::PaddedOutputString<8>;
|
||||
|
||||
const auto rset = RSet("CASE");
|
||||
const auto fmt = ::Opm::EclIO::OutputStream::Formatted{ true };
|
||||
const auto exist = ::Opm::EclIO::OutputStream::RFT::OpenExisting{ false };
|
||||
|
||||
{
|
||||
auto rft = ::Opm::EclIO::OutputStream::RFT {
|
||||
rset, fmt, exist
|
||||
};
|
||||
|
||||
rft.write("I", std::vector<int> {1, 7, 2, 9});
|
||||
rft.write("S", std::vector<float> {3.1f, 4.1f, 59.265f});
|
||||
rft.write("Z", std::vector<Char8> {
|
||||
Char8{" Hello "}, Char8{" World "}
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto fname = ::Opm::EclIO::OutputStream::
|
||||
outputFileName(rset, "FRFT");
|
||||
|
||||
auto rft = ::Opm::EclIO::EclFile{fname};
|
||||
|
||||
BOOST_CHECK(rft.hasKey("I"));
|
||||
BOOST_CHECK(rft.hasKey("S"));
|
||||
BOOST_CHECK(rft.hasKey("Z"));
|
||||
BOOST_CHECK(!rft.hasKey("C"));
|
||||
|
||||
{
|
||||
const auto vectors = rft.getList();
|
||||
const auto expect_vectors = std::vector<Opm::EclIO::EclFile::EclEntry>{
|
||||
Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4},
|
||||
Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2},
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(),
|
||||
expect_vectors.begin(),
|
||||
expect_vectors.end());
|
||||
}
|
||||
|
||||
rft.loadData();
|
||||
|
||||
{
|
||||
const auto& I = rft.get<int>("I");
|
||||
const auto expect_I = std::vector<int>{ 1, 7, 2, 9 };
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(),
|
||||
expect_I.begin(),
|
||||
expect_I.end());
|
||||
}
|
||||
|
||||
{
|
||||
const auto& S = rft.get<float>("S");
|
||||
const auto expect_S = std::vector<float>{
|
||||
3.1f, 4.1f, 59.265f,
|
||||
};
|
||||
|
||||
check_is_close(S, expect_S);
|
||||
}
|
||||
|
||||
{
|
||||
const auto& Z = rft.get<std::string>("Z");
|
||||
const auto expect_Z = std::vector<std::string>{
|
||||
" Hello", " World" // Trailing blanks trimmed
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(),
|
||||
expect_Z.begin(), expect_Z.end());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto rft = ::Opm::EclIO::OutputStream::RFT {
|
||||
rset, fmt, exist
|
||||
};
|
||||
|
||||
rft.write("I2", std::vector<int> {11, 22, 33});
|
||||
rft.write("S2", std::vector<float> {2.71f, 828.1f, 8.218f});
|
||||
rft.write("Z2", std::vector<Char8> {
|
||||
Char8{"Good B"}, Char8{" ye"}, Char8{ "W0rlD" },
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto fname = ::Opm::EclIO::OutputStream::
|
||||
outputFileName(rset, "FRFT");
|
||||
|
||||
auto rft = ::Opm::EclIO::EclFile{fname};
|
||||
|
||||
BOOST_CHECK(!rft.hasKey("I"));
|
||||
BOOST_CHECK(!rft.hasKey("S"));
|
||||
BOOST_CHECK(!rft.hasKey("Z"));
|
||||
|
||||
BOOST_CHECK(rft.hasKey("I2"));
|
||||
BOOST_CHECK(rft.hasKey("S2"));
|
||||
BOOST_CHECK(rft.hasKey("Z2"));
|
||||
|
||||
{
|
||||
const auto vectors = rft.getList();
|
||||
const auto expect_vectors = std::vector<Opm::EclIO::EclFile::EclEntry>{
|
||||
Opm::EclIO::EclFile::EclEntry{"I2", Opm::EclIO::eclArrType::INTE, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"S2", Opm::EclIO::eclArrType::REAL, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"Z2", Opm::EclIO::eclArrType::CHAR, 3},
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(),
|
||||
expect_vectors.begin(),
|
||||
expect_vectors.end());
|
||||
}
|
||||
|
||||
rft.loadData();
|
||||
|
||||
{
|
||||
const auto& I = rft.get<int>("I2");
|
||||
const auto expect_I = std::vector<int>{ 11, 22, 33 };
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(),
|
||||
expect_I.begin(),
|
||||
expect_I.end());
|
||||
}
|
||||
|
||||
{
|
||||
const auto& S = rft.get<float>("S2");
|
||||
const auto expect_S = std::vector<float>{
|
||||
2.71f, 828.1f, 8.218f,
|
||||
};
|
||||
|
||||
check_is_close(S, expect_S);
|
||||
}
|
||||
|
||||
{
|
||||
const auto& Z = rft.get<std::string>("Z2");
|
||||
const auto expect_Z = std::vector<std::string>{
|
||||
"Good B", " ye", "W0rlD"
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(),
|
||||
expect_Z.begin(), expect_Z.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Formatted_Existing)
|
||||
{
|
||||
using Char8 = ::Opm::EclIO::PaddedOutputString<8>;
|
||||
|
||||
const auto rset = RSet("CASE");
|
||||
const auto fmt = ::Opm::EclIO::OutputStream::Formatted{ true };
|
||||
const auto exist = ::Opm::EclIO::OutputStream::RFT::OpenExisting{ true };
|
||||
|
||||
{
|
||||
auto rft = ::Opm::EclIO::OutputStream::RFT {
|
||||
rset, fmt, exist
|
||||
};
|
||||
|
||||
rft.write("I", std::vector<int> {1, 7, 2, 9});
|
||||
rft.write("S", std::vector<float> {3.1f, 4.1f, 59.265f});
|
||||
rft.write("Z", std::vector<Char8> {
|
||||
Char8{" Hello "}, Char8{" World "}
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto fname = ::Opm::EclIO::OutputStream::
|
||||
outputFileName(rset, "FRFT");
|
||||
|
||||
auto rft = ::Opm::EclIO::EclFile{fname};
|
||||
|
||||
BOOST_CHECK(rft.hasKey("I"));
|
||||
BOOST_CHECK(rft.hasKey("S"));
|
||||
BOOST_CHECK(rft.hasKey("Z"));
|
||||
|
||||
BOOST_CHECK(!rft.hasKey("C"));
|
||||
|
||||
{
|
||||
const auto vectors = rft.getList();
|
||||
const auto expect_vectors = std::vector<Opm::EclIO::EclFile::EclEntry>{
|
||||
Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4},
|
||||
Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2},
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(),
|
||||
expect_vectors.begin(),
|
||||
expect_vectors.end());
|
||||
}
|
||||
|
||||
rft.loadData();
|
||||
|
||||
{
|
||||
const auto& I = rft.get<int>("I");
|
||||
const auto expect_I = std::vector<int>{ 1, 7, 2, 9 };
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(),
|
||||
expect_I.begin(),
|
||||
expect_I.end());
|
||||
}
|
||||
|
||||
{
|
||||
const auto& S = rft.get<float>("S");
|
||||
const auto expect_S = std::vector<float>{
|
||||
3.1f, 4.1f, 59.265f,
|
||||
};
|
||||
|
||||
check_is_close(S, expect_S);
|
||||
}
|
||||
|
||||
{
|
||||
const auto& Z = rft.get<std::string>("Z");
|
||||
const auto expect_Z = std::vector<std::string>{
|
||||
" Hello", " World" // Trailing blanks trimmed
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(),
|
||||
expect_Z.begin(), expect_Z.end());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto rft = ::Opm::EclIO::OutputStream::RFT {
|
||||
rset, fmt, exist
|
||||
};
|
||||
|
||||
rft.write("I2", std::vector<int> {11, 22, 33});
|
||||
rft.write("S2", std::vector<float> {2.71f, 828.1f, 8.218f});
|
||||
rft.write("Z2", std::vector<Char8> {
|
||||
Char8{"Good B"}, Char8{" ye"}, Char8{ "W0rlD" },
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto fname = ::Opm::EclIO::OutputStream::
|
||||
outputFileName(rset, "FRFT");
|
||||
|
||||
auto rft = ::Opm::EclIO::EclFile{fname};
|
||||
|
||||
BOOST_CHECK(rft.hasKey("I"));
|
||||
BOOST_CHECK(rft.hasKey("S"));
|
||||
BOOST_CHECK(rft.hasKey("Z"));
|
||||
BOOST_CHECK(rft.hasKey("I2"));
|
||||
BOOST_CHECK(rft.hasKey("S2"));
|
||||
BOOST_CHECK(rft.hasKey("Z2"));
|
||||
|
||||
BOOST_CHECK(!rft.hasKey("C"));
|
||||
|
||||
{
|
||||
const auto vectors = rft.getList();
|
||||
const auto expect_vectors = std::vector<Opm::EclIO::EclFile::EclEntry>{
|
||||
Opm::EclIO::EclFile::EclEntry{"I", Opm::EclIO::eclArrType::INTE, 4},
|
||||
Opm::EclIO::EclFile::EclEntry{"S", Opm::EclIO::eclArrType::REAL, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"Z", Opm::EclIO::eclArrType::CHAR, 2},
|
||||
Opm::EclIO::EclFile::EclEntry{"I2", Opm::EclIO::eclArrType::INTE, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"S2", Opm::EclIO::eclArrType::REAL, 3},
|
||||
Opm::EclIO::EclFile::EclEntry{"Z2", Opm::EclIO::eclArrType::CHAR, 3},
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vectors.begin(), vectors.end(),
|
||||
expect_vectors.begin(),
|
||||
expect_vectors.end());
|
||||
}
|
||||
|
||||
rft.loadData();
|
||||
|
||||
{
|
||||
const auto& I = rft.get<int>("I");
|
||||
const auto expect_I = std::vector<int>{ 1, 7, 2, 9 };
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(),
|
||||
expect_I.begin(),
|
||||
expect_I.end());
|
||||
}
|
||||
|
||||
{
|
||||
const auto& S = rft.get<float>("S");
|
||||
const auto expect_S = std::vector<float>{
|
||||
3.1f, 4.1f, 59.265f,
|
||||
};
|
||||
|
||||
check_is_close(S, expect_S);
|
||||
}
|
||||
|
||||
{
|
||||
const auto& Z = rft.get<std::string>("Z");
|
||||
const auto expect_Z = std::vector<std::string>{
|
||||
" Hello", " World" // Trailing blanks trimmed
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(),
|
||||
expect_Z.begin(), expect_Z.end());
|
||||
}
|
||||
{
|
||||
const auto& I = rft.get<int>("I2");
|
||||
const auto expect_I = std::vector<int>{ 11, 22, 33 };
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(I.begin(), I.end(),
|
||||
expect_I.begin(),
|
||||
expect_I.end());
|
||||
}
|
||||
|
||||
{
|
||||
const auto& S = rft.get<float>("S2");
|
||||
const auto expect_S = std::vector<float>{
|
||||
2.71f, 828.1f, 8.218f,
|
||||
};
|
||||
|
||||
check_is_close(S, expect_S);
|
||||
}
|
||||
|
||||
{
|
||||
const auto& Z = rft.get<std::string>("Z2");
|
||||
const auto expect_Z = std::vector<std::string>{
|
||||
"Good B", " ye", "W0rlD"
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(Z.begin(), Z.end(),
|
||||
expect_Z.begin(), expect_Z.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() // Class_RFT
|
||||
|
Loading…
Reference in New Issue
Block a user