Split Combined Vector ID Calculation Out to Helpers

This commit introduces new helper functions

    int EclIO::combineSummaryNumbers(int, int)
    tuple<int, int> EclIO::splitSummaryNumber(int)

that know about the relation

    combined = n1 + 32768*(n2 + 10)

This relation is typically used to combine one-based region IDs for
inter-region flows into a single 'NUMS' entry in the summary file.
This commit is contained in:
Bård Skaflestad
2022-01-14 11:29:38 +01:00
parent 4a8f432b10
commit 4b2a37a39e
4 changed files with 41 additions and 2 deletions

View File

@@ -37,6 +37,17 @@ namespace Opm { namespace EclIO {
bool isFormatted(const std::string& filename);
bool is_number(const std::string& numstr);
/// Compute the linearly combined summary vector ID number from two
/// constituents.
///
/// Constituents are *typically* one-based region IDs, but at least one
/// of the two could be a component ID too.
int combineSummaryNumbers(const int n1, const int n2);
/// Split a combined summary vector ID ('NUMS' entry) into its original
/// two constituent IDs.
std::tuple<int,int> splitSummaryNumber(const int n);
std::tuple<int, int> block_size_data_binary(eclArrType arrType);
std::tuple<int, int, int> block_size_data_formatted(eclArrType arrType);

View File

@@ -1220,8 +1220,7 @@ std::string ESmry::makeKeyString(const std::string& keywordArg, const std::strin
if ((str34 == "FR") || (str34 == "FT") || (str45 == "FR") || (str45 == "FT")) {
// NUMS = R1 + 32768*(R2 + 10)
const auto r1 = num % (1UL << 15);
const auto r2 = (num / (1UL << 15)) - 10;
const auto& [r1, r2] = splitSummaryNumber(num);
return fmt::format("{}:{}-{}", keywordArg, r1, r2);
}

View File

@@ -103,6 +103,18 @@ bool Opm::EclIO::isEOF(std::fstream* fileH)
}
}
int Opm::EclIO::combineSummaryNumbers(const int n1, const int n2)
{
return n1 + (1 << 15)*(n2 + 10);
}
std::tuple<int, int> Opm::EclIO::splitSummaryNumber(const int n)
{
const auto n1 = n % (1 << 15);
const auto n2 = (n / (1 << 15)) - 10;
return { n1, n2 };
}
std::tuple<int, int> Opm::EclIO::block_size_data_binary(eclArrType arrType)
{

View File

@@ -530,3 +530,20 @@ BOOST_AUTO_TEST_CASE(TestEcl_Write_CHAR) {
BOOST_CHECK(std::get<1>(arrayList[0]) == Opm::EclIO::C0NN);
}
}
BOOST_AUTO_TEST_CASE(CombinedVectorID) {
BOOST_CHECK_EQUAL(combineSummaryNumbers(1, 2), 393'217);
BOOST_CHECK_EQUAL(combineSummaryNumbers(10, 1), 360'458);
{
const auto [n1, n2] = splitSummaryNumber(393'217);
BOOST_CHECK_EQUAL(n1, 1);
BOOST_CHECK_EQUAL(n2, 2);
}
{
const auto [n1, n2] = splitSummaryNumber(360'458);
BOOST_CHECK_EQUAL(n1, 10);
BOOST_CHECK_EQUAL(n2, 1);
}
}