Skip to content

Commit

Permalink
Merge pull request PetroleumCyberneticsGroup#50 from PetroleumCyberne…
Browse files Browse the repository at this point in the history
…ticsGroup/feature/get-cellnum-from-H5-reader

Feature/get cellnum from h5 reader
  • Loading branch information
einar90 authored Dec 22, 2016
2 parents 85359e3 + 68d0ec5 commit e99373c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion FieldOpt/FieldOpt-WellIndexCalculator
38 changes: 36 additions & 2 deletions FieldOpt/Hdf5SummaryReader/hdf5_summary_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,47 @@

using namespace H5;
Hdf5SummaryReader::Hdf5SummaryReader(const std::string file_path)
: GROUP_NAME_RESTART(("RESTART")), DATASET_NAME_TIMES("TIMES"),
GROUP_NAME_FLOW_TRANSPORT("FLOW_TRANSPORT"), DATASET_NAME_WELL_STATES("WELL_STATES")
: GROUP_NAME_RESTART("RESTART"),
DATASET_NAME_TIMES("TIMES"),
GROUP_NAME_FLOW_TRANSPORT("FLOW_TRANSPORT"),
DATASET_NAME_ACTIVE_CELLS("ACTIVE_CELLS"),
DATASET_NAME_WELL_STATES("WELL_STATES")
{
readTimeVector(file_path);
readActiveCells(file_path);
readWellStates(file_path);
}

void Hdf5SummaryReader::readActiveCells(std::string file_path) {
// Read the file
H5File file(file_path, H5F_ACC_RDONLY);
Group group = Group(file.openGroup(GROUP_NAME_FLOW_TRANSPORT));
DataSet dataset = DataSet(group.openDataSet(DATASET_NAME_ACTIVE_CELLS));

DataSpace dataspace = dataset.getSpace();
hsize_t dims[2];

auto rank = dataspace.getSimpleExtentDims(dims, NULL);
// Uncomment to debug:
// std::cout << "dataset rank = " << rank << ", dimensions "
// << (unsigned long)(dims[0]) << " x "
// << (unsigned long)(dims[1]) << std::endl;

// Define hyperslab
hsize_t count[2] = { dims[0], 1 };
hsize_t offset[2] = { 0, 0 };
dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );

// Size of selected colum + define memory space
hsize_t col_sz[1] = { dims[0] };
DataSpace mspace( 1, col_sz );

std::vector<int> vector;
vector.resize(dims[0]);
dataset.read(vector.data(), PredType::NATIVE_INT, mspace, dataspace);
active_cells_ = vector;
}

void Hdf5SummaryReader::readTimeVector(std::string file_path) {
// Read the file
H5File file(file_path, H5F_ACC_RDONLY);
Expand Down
8 changes: 8 additions & 0 deletions FieldOpt/Hdf5SummaryReader/hdf5_summary_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class Hdf5SummaryReader {
*/
const std::vector<double> &times_steps() const { return times_; }

/*!
* Get the vector containing defining active cells.
*/
const std::vector<int> &active_cells() const { return active_cells_; }

/*!
* Get the number of wells found in the summary.
*/
Expand Down Expand Up @@ -185,6 +190,7 @@ class Hdf5SummaryReader {
const H5std_string DATASET_NAME_TIMES; //!< The name of the dataset containing the time step vector in the HDF5 file.
const H5std_string GROUP_NAME_FLOW_TRANSPORT; //!< The name of the flow transport group in the HDF5 file.
const H5std_string DATASET_NAME_WELL_STATES; //!< The name of the dataset containing the well states in the HDF5 file.
const H5std_string DATASET_NAME_ACTIVE_CELLS; //!< The name of the dataset containing active cells vector.

/*!
* The wstype_t datatype represents the datatype in which well states are stored in the HDF5 file. Each element
Expand Down Expand Up @@ -243,13 +249,15 @@ class Hdf5SummaryReader {
};

void readTimeVector(std::string file_path); //!< Read the time vector from the HDF5 summary file.
void readActiveCells(std::string file_path); //!< Read vector defining which cells are active from the HDF5 summary file.
void readWellStates(std::string file_path); //!< Read all well state information from the HDF5 summary file.
void parseWsVector(std::vector<wstype_t> &wsvec); //!< Populate well_states_ by creating well_data and perforation_data objects from the wstype_t vector.
well_data parseWellState(std::vector<wstype_t> &ws, int wnr); //!< Parse the states for a single well and create a well_data object.

int nwells_; //!< Number of wells in summary.
int ntimes_; //!< Number of time steps in the summary.
int nphases_; //!< Number of phases in the model
std::vector<int> active_cells_; //!< Vector defining active cells (size equal to total number of cells) .
std::vector<double> times_; //!< Vector containing all time steps.

/*!
Expand Down
10 changes: 10 additions & 0 deletions FieldOpt/Hdf5SummaryReader/tests/test_hdf5_summary_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ namespace {
}
}

TEST_F(Hdf5SummaryReaderTest, ActiveCellVector) {
auto reader = Hdf5SummaryReader(file_path);
std::vector<int> active_cells = reader.active_cells();

for (int i = 0; i < active_cells.size(); ++i) {
// std::cout << active_cells[i] << std::endl;
EXPECT_EQ(active_cells[i], i);
}
}

TEST_F(Hdf5SummaryReaderTest, IntegerData) {
auto reader = Hdf5SummaryReader(file_path);
int expected_types[5] = {1, -1, -1, -1, -1};
Expand Down

0 comments on commit e99373c

Please sign in to comment.