Promote 'CharArrayNullTerm' to EclIO::PaddedOutputString

Space-padded vectors of N (usually 8) characters is the typical
representation of character data in ECLIPSE output files.  Support
this type natively in the ECLIPSE IO library.
This commit is contained in:
Bård Skaflestad 2019-05-24 16:03:09 +02:00
parent 82b0a2d82b
commit 725ac521ba
9 changed files with 47 additions and 44 deletions

View File

@ -280,7 +280,6 @@ if(ENABLE_ECL_OUTPUT)
tests/test_AggregateMSWData.cpp tests/test_AggregateMSWData.cpp
tests/test_AggregateConnectionData.cpp tests/test_AggregateConnectionData.cpp
tests/test_ArrayDimChecker.cpp tests/test_ArrayDimChecker.cpp
tests/test_CharArrayNullTerm.cpp
tests/test_EclipseIO.cpp tests/test_EclipseIO.cpp
tests/test_DoubHEAD.cpp tests/test_DoubHEAD.cpp
tests/test_InteHEAD.cpp tests/test_InteHEAD.cpp
@ -288,6 +287,7 @@ if(ENABLE_ECL_OUTPUT)
tests/test_LogiHEAD.cpp tests/test_LogiHEAD.cpp
tests/test_OutputStream.cpp tests/test_OutputStream.cpp
tests/test_regionCache.cpp tests/test_regionCache.cpp
tests/test_PaddedOutputString.cpp
tests/test_Restart.cpp tests/test_Restart.cpp
tests/test_RFT.cpp tests/test_RFT.cpp
tests/test_Solution.cpp tests/test_Solution.cpp
@ -577,6 +577,7 @@ if(ENABLE_ECL_OUTPUT)
opm/io/eclipse/ERft.hpp opm/io/eclipse/ERft.hpp
opm/io/eclipse/ERst.hpp opm/io/eclipse/ERst.hpp
opm/io/eclipse/ESmry.hpp opm/io/eclipse/ESmry.hpp
opm/io/eclipse/PaddedOutputString.hpp
opm/io/eclipse/OutputStream.hpp opm/io/eclipse/OutputStream.hpp
opm/output/data/Cells.hpp opm/output/data/Cells.hpp
opm/output/data/Solution.hpp opm/output/data/Solution.hpp
@ -591,7 +592,6 @@ if(ENABLE_ECL_OUTPUT)
opm/output/eclipse/AggregateConnectionData.hpp opm/output/eclipse/AggregateConnectionData.hpp
opm/output/eclipse/AggregateMSWData.hpp opm/output/eclipse/AggregateMSWData.hpp
opm/output/eclipse/AggregateWellData.hpp opm/output/eclipse/AggregateWellData.hpp
opm/output/eclipse/CharArrayNullTerm.hpp
opm/output/eclipse/DoubHEAD.hpp opm/output/eclipse/DoubHEAD.hpp
opm/output/eclipse/EclipseGridInspector.hpp opm/output/eclipse/EclipseGridInspector.hpp
opm/output/eclipse/EclipseIO.hpp opm/output/eclipse/EclipseIO.hpp

View File

@ -17,8 +17,8 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>. along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OPM_CHARARRAY_HEADER_HPP #ifndef OPM_PADDEDOUTPUTSTRING_HEADER_HPP
#define OPM_CHARARRAY_HEADER_HPP #define OPM_PADDEDOUTPUTSTRING_HEADER_HPP
#include <algorithm> #include <algorithm>
#include <array> #include <array>
@ -26,7 +26,7 @@
#include <cstddef> #include <cstddef>
#include <string> #include <string>
namespace Opm { namespace RestartIO { namespace Helpers { namespace Opm { namespace EclIO {
/// Null-terminated, left adjusted, space padded array of N characters. /// Null-terminated, left adjusted, space padded array of N characters.
/// ///
@ -36,30 +36,30 @@ namespace Opm { namespace RestartIO { namespace Helpers {
/// ///
/// \tparam N Number of characters. /// \tparam N Number of characters.
template <std::size_t N> template <std::size_t N>
class CharArrayNullTerm class PaddedOutputString
{ {
public: public:
CharArrayNullTerm() PaddedOutputString()
{ {
this->clear(); this->clear();
} }
explicit CharArrayNullTerm(const std::string& s) explicit PaddedOutputString(const std::string& s)
: CharArrayNullTerm() : PaddedOutputString()
{ {
this->copy_in(s.c_str(), s.size()); this->copy_in(s.c_str(), s.size());
} }
~CharArrayNullTerm() = default; ~PaddedOutputString() = default;
CharArrayNullTerm(const CharArrayNullTerm& rhs) = default; PaddedOutputString(const PaddedOutputString& rhs) = default;
CharArrayNullTerm(CharArrayNullTerm&& rhs) = default; PaddedOutputString(PaddedOutputString&& rhs) = default;
CharArrayNullTerm& operator=(const CharArrayNullTerm& rhs) = default; PaddedOutputString& operator=(const PaddedOutputString& rhs) = default;
CharArrayNullTerm& operator=(CharArrayNullTerm&& rhs) = default; PaddedOutputString& operator=(PaddedOutputString&& rhs) = default;
/// Assign from \code std::string \endcode. /// Assign from \code std::string \endcode.
CharArrayNullTerm& operator=(const std::string& s) PaddedOutputString& operator=(const std::string& s)
{ {
this->clear(); this->clear();
this->copy_in(s.data(), s.size()); this->copy_in(s.data(), s.size());
@ -99,5 +99,5 @@ namespace Opm { namespace RestartIO { namespace Helpers {
} }
}; };
}}} // Opm::RestartIO::Helpers }} // Opm::EclIO
#endif // CHARARRAY_HEADER #endif // OPM_PADDEDOUTPUTSTRING_HEADER_HPP

View File

@ -20,9 +20,10 @@
#ifndef OPM_AGGREGATE_GROUP_DATA_HPP #ifndef OPM_AGGREGATE_GROUP_DATA_HPP
#define OPM_AGGREGATE_GROUP_DATA_HPP #define OPM_AGGREGATE_GROUP_DATA_HPP
#include <opm/output/eclipse/CharArrayNullTerm.hpp>
#include <opm/output/eclipse/WindowedArray.hpp> #include <opm/output/eclipse/WindowedArray.hpp>
#include <opm/io/eclipse/PaddedOutputString.hpp>
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#include <vector> #include <vector>
@ -80,7 +81,7 @@ namespace Opm { namespace RestartIO { namespace Helpers {
return this->xGroup_.data(); return this->xGroup_.data();
} }
const std::vector<CharArrayNullTerm<8>>& getZGroup() const const std::vector<EclIO::PaddedOutputString<8>>& getZGroup() const
{ {
return this->zGroup_.data(); return this->zGroup_.data();
} }
@ -158,7 +159,7 @@ namespace Opm { namespace RestartIO { namespace Helpers {
WindowedArray<double> xGroup_; WindowedArray<double> xGroup_;
/// Aggregate 'ZWEL' array (Character) for all wells. /// Aggregate 'ZWEL' array (Character) for all wells.
WindowedArray<CharArrayNullTerm<8>> zGroup_; WindowedArray<EclIO::PaddedOutputString<8>> zGroup_;
/// Maximum number of wells in a group. /// Maximum number of wells in a group.
int nWGMax_; int nWGMax_;

View File

@ -21,7 +21,6 @@
#define OPM_AGGREGATE_MSW_DATA_HPP #define OPM_AGGREGATE_MSW_DATA_HPP
#include <opm/output/data/Wells.hpp> #include <opm/output/data/Wells.hpp>
#include <opm/output/eclipse/CharArrayNullTerm.hpp>
#include <opm/output/eclipse/WindowedArray.hpp> #include <opm/output/eclipse/WindowedArray.hpp>
#include <string> #include <string>

View File

@ -20,9 +20,10 @@
#ifndef OPM_AGGREGATE_WELL_DATA_HPP #ifndef OPM_AGGREGATE_WELL_DATA_HPP
#define OPM_AGGREGATE_WELL_DATA_HPP #define OPM_AGGREGATE_WELL_DATA_HPP
#include <opm/output/eclipse/CharArrayNullTerm.hpp>
#include <opm/output/eclipse/WindowedArray.hpp> #include <opm/output/eclipse/WindowedArray.hpp>
#include <opm/io/eclipse/PaddedOutputString.hpp>
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#include <vector> #include <vector>
@ -74,7 +75,7 @@ namespace Opm { namespace RestartIO { namespace Helpers {
} }
/// Retrieve Character Well Data Array. /// Retrieve Character Well Data Array.
const std::vector<CharArrayNullTerm<8>>& getZWell() const const std::vector<EclIO::PaddedOutputString<8>>& getZWell() const
{ {
return this->zWell_.data(); return this->zWell_.data();
} }
@ -92,7 +93,7 @@ namespace Opm { namespace RestartIO { namespace Helpers {
WindowedArray<double> xWell_; WindowedArray<double> xWell_;
/// Aggregate 'ZWEL' array (Character) for all wells. /// Aggregate 'ZWEL' array (Character) for all wells.
WindowedArray<CharArrayNullTerm<8>> zWell_; WindowedArray<EclIO::PaddedOutputString<8>> zWell_;
/// Maximum number of groups in model. /// Maximum number of groups in model.
int nWGMax_; int nWGMax_;

View File

@ -410,12 +410,12 @@ namespace {
} }
Opm::RestartIO::Helpers::WindowedArray< Opm::RestartIO::Helpers::WindowedArray<
Opm::RestartIO::Helpers::CharArrayNullTerm<8> Opm::EclIO::PaddedOutputString<8>
> >
allocate(const std::vector<int>& inteHead) allocate(const std::vector<int>& inteHead)
{ {
using WV = Opm::RestartIO::Helpers::WindowedArray< using WV = Opm::RestartIO::Helpers::WindowedArray<
Opm::RestartIO::Helpers::CharArrayNullTerm<8> Opm::EclIO::PaddedOutputString<8>
>; >;
return WV { return WV {

View File

@ -750,12 +750,12 @@ namespace {
} }
Opm::RestartIO::Helpers::WindowedArray< Opm::RestartIO::Helpers::WindowedArray<
Opm::RestartIO::Helpers::CharArrayNullTerm<8> Opm::EclIO::PaddedOutputString<8>
> >
allocate(const std::vector<int>& inteHead) allocate(const std::vector<int>& inteHead)
{ {
using WV = Opm::RestartIO::Helpers::WindowedArray< using WV = Opm::RestartIO::Helpers::WindowedArray<
Opm::RestartIO::Helpers::CharArrayNullTerm<8> Opm::EclIO::PaddedOutputString<8>
>; >;
return WV { return WV {

View File

@ -32,6 +32,8 @@
#include <opm/output/eclipse/libECLRestart.hpp> #include <opm/output/eclipse/libECLRestart.hpp>
#include <opm/io/eclipse/PaddedOutputString.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp> #include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp> #include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
@ -168,7 +170,7 @@ namespace {
} }
std::vector<const char*> std::vector<const char*>
serialize_ZWEL(const std::vector<Opm::RestartIO::Helpers::CharArrayNullTerm<8>>& zwel) serialize_ZWEL(const std::vector<EclIO::PaddedOutputString<8>>& zwel)
{ {
std::vector<const char*> data(zwel.size(), nullptr); std::vector<const char*> data(zwel.size(), nullptr);
std::size_t it = 0; std::size_t it = 0;

View File

@ -1,36 +1,36 @@
#define BOOST_TEST_MODULE Aggregate_Well_Data #define BOOST_TEST_MODULE Padded_Output_String
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <opm/output/eclipse/CharArrayNullTerm.hpp> #include <opm/io/eclipse/PaddedOutputString.hpp>
// Convenience alias. // Convenience alias.
template <std::size_t N> template <std::size_t N>
using AChar = ::Opm::RestartIO::Helpers::CharArrayNullTerm<N>; using PadString = ::Opm::EclIO::PaddedOutputString<N>;
// ===================================================================== // =====================================================================
BOOST_AUTO_TEST_SUITE(AChar8) BOOST_AUTO_TEST_SUITE(PadString8)
BOOST_AUTO_TEST_CASE (Basic_Operations) BOOST_AUTO_TEST_CASE (Basic_Operations)
{ {
// Default Constructor // Default Constructor
{ {
const auto s = AChar<8>{}; const auto s = PadString<8>{};
BOOST_CHECK_EQUAL(s.c_str(), std::string(8, ' ')); BOOST_CHECK_EQUAL(s.c_str(), std::string(8, ' '));
} }
// Construct from Constant String // Construct from Constant String
{ {
const auto s = AChar<8>{"Inj-1"}; const auto s = PadString<8>{"Inj-1"};
BOOST_CHECK_EQUAL(s.c_str(), std::string{"Inj-1 "}); BOOST_CHECK_EQUAL(s.c_str(), std::string{"Inj-1 "});
} }
// Copy Construction // Copy Construction
{ {
const auto s1 = AChar<8>{"Inj-1"}; const auto s1 = PadString<8>{"Inj-1"};
const auto s2 = s1; const auto s2 = s1;
BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "}); BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "});
@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE (Basic_Operations)
// Move Construction // Move Construction
{ {
auto s1 = AChar<8>{"Inj-1"}; auto s1 = PadString<8>{"Inj-1"};
const auto s2 = std::move(s1); const auto s2 = std::move(s1);
BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "}); BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "});
@ -46,8 +46,8 @@ BOOST_AUTO_TEST_CASE (Basic_Operations)
// Assignment Operator // Assignment Operator
{ {
const auto s1 = AChar<8>{"Inj-1"}; const auto s1 = PadString<8>{"Inj-1"};
auto s2 = AChar<8>{"Prod-2"}; auto s2 = PadString<8>{"Prod-2"};
s2 = s1; s2 = s1;
BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "}); BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "});
@ -55,8 +55,8 @@ BOOST_AUTO_TEST_CASE (Basic_Operations)
// Move Assignment Operator // Move Assignment Operator
{ {
auto s1 = AChar<8>{"Inj-1"}; auto s1 = PadString<8>{"Inj-1"};
auto s2 = AChar<8>{"Prod-2"}; auto s2 = PadString<8>{"Prod-2"};
s2 = std::move(s1); s2 = std::move(s1);
BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "}); BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "});
@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE (Basic_Operations)
// Assign std::string // Assign std::string
{ {
auto s = AChar<8>{"@Hi Hoo@"}; auto s = PadString<8>{"@Hi Hoo@"};
s = "Prod-2"; s = "Prod-2";
BOOST_CHECK_EQUAL(s.c_str(), std::string{"Prod-2 "}); BOOST_CHECK_EQUAL(s.c_str(), std::string{"Prod-2 "});
@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE (String_Shortening)
{ {
// Construct from string of more than N characters // Construct from string of more than N characters
{ {
const auto s = AChar<10>{ const auto s = PadString<10>{
"String too long" "String too long"
}; };
@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE (String_Shortening)
// Assign string of more than N characters // Assign string of more than N characters
{ {
auto s = AChar<11>{}; auto s = PadString<11>{};
s = "This string has too many characters"; s = "This string has too many characters";