Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions opm/io/eclipse/ERst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <exception>
#include <iterator>
Expand Down Expand Up @@ -172,6 +173,29 @@ int ERst::occurrence_count(const std::string& name, int reportStepNumber) const
return count;
}

std::int64_t ERst::dataSize(const std::string& name, int reportStepNumber) const
{
if (!hasReportStepNumber(reportStepNumber)) {
OPM_THROW(std::invalid_argument,
fmt::format("Trying to get size of vectors of name {}"
" from non existing sequence {}", name, reportStepNumber));
}

std::int64_t size = 0;

auto range_it = arrIndexRange.find(reportStepNumber);

std::pair<int,int> indexRange = range_it->second;

for (int i=std::get<0>(indexRange); i<std::get<1>(indexRange);i++){
if (array_name[i] == name){
size += array_size[i];
}
}

return size;
}

void ERst::initUnified()
{
loadData("SEQNUM");
Expand Down
2 changes: 2 additions & 0 deletions opm/io/eclipse/ERst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <opm/io/eclipse/EclFile.hpp>

#include <cstddef>
#include <cstdint>
#include <ios>
#include <map>
#include <string>
Expand Down Expand Up @@ -71,6 +72,7 @@ class ERst : public EclFile
const std::vector<T>& getRestartData(int index, int reportStepNumber, const std::string& lgr_name);

int occurrence_count(const std::string& name, int reportStepNumber) const;
std::int64_t dataSize(const std::string& name, int reportStepNumber) const;
std::size_t numberOfReportSteps() const { return seqnum.size(); };

const std::vector<int>& listOfReportStepNumbers() const { return seqnum; }
Expand Down
41 changes: 41 additions & 0 deletions tests/test_ERst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,47 @@ BOOST_AUTO_TEST_CASE(TestERst_5b) {
}
}

BOOST_AUTO_TEST_CASE(TestERst_dataSize) {

std::string testRstFile = "LGR_TESTMOD.UNRST";

ERst rst1(testRstFile);

const int rstep = 0;

// PRESSURE is stored once for the global grid and once for each of the
// two LGRs, with 30, 128 and 192 elements.
BOOST_CHECK_EQUAL(rst1.occurrence_count("PRESSURE", rstep), 3);
BOOST_CHECK_EQUAL(rst1.dataSize("PRESSURE", rstep), 30 + 128 + 192);

// SEQNUM exists in the global grid only.
BOOST_CHECK_EQUAL(rst1.dataSize("SEQNUM", rstep), 1);

// Sum of all occurrences of a name must match the arrays reported for the
// global grid and the LGRs.
for (const auto& name : { std::string {"PRESSURE"}, std::string {"ICON"},
std::string {"INTEHEAD"}, std::string {"ZWEL"} })
{
std::int64_t size = 0;
for (const auto& grid : { std::string {"global"}, std::string {"LGR1"},
std::string {"LGR2"} })
{
for (const auto& array : rst1.listOfRstArrays(rstep, grid)) {
if (std::get<0>(array) == name) {
size += std::get<2>(array);
}
}
}

BOOST_CHECK_EQUAL(rst1.dataSize(name, rstep), size);
}

BOOST_CHECK_EQUAL(rst1.dataSize("XXXX", rstep), 0);

// Non existing report step number, as in occurrence_count()
BOOST_CHECK_THROW(rst1.dataSize("PRESSURE", 99), std::invalid_argument);
}

// ====================================================================

class RSet
Expand Down