From 6ca10ea57dd0a3e54ec38e80be943f7ef60cda6d Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 22 Feb 2016 10:49:04 +0100 Subject: [PATCH] Added SimulatorState::getCellData() --- opm/core/simulator/SimulatorState.cpp | 23 +++++++++++++++++++---- opm/core/simulator/SimulatorState.hpp | 3 +++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/opm/core/simulator/SimulatorState.cpp b/opm/core/simulator/SimulatorState.cpp index 45d7d3c8..c1763b9d 100644 --- a/opm/core/simulator/SimulatorState.cpp +++ b/opm/core/simulator/SimulatorState.cpp @@ -87,10 +87,10 @@ void SimulatorState::setCellDataComponent( const std::string& name , size_t comp auto& data = cellData_[id]; if (component >= num_phases_) throw std::invalid_argument("Invalid component"); - + if (cells.size() != values.size()) throw std::invalid_argument("size mismatch between cells and values"); - + /* This is currently quite broken; the setCellDataComponent method assumes that the number of components in the field we are currently focusing on has num_phases components in @@ -99,12 +99,12 @@ void SimulatorState::setCellDataComponent( const std::string& name , size_t comp */ if (data.size() != num_phases_ * num_cells_) throw std::invalid_argument("Can currently only be used on fields with num_components == num_phases (i.e. saturation...) "); - + for (size_t i = 0; i < cells.size(); i++) { if (cells[i] < num_cells_) { auto field_index = cells[i] * num_phases_ + component; auto value = values[i]; - + data[field_index] = value; } else { throw std::invalid_argument("Invalid cell number"); @@ -113,3 +113,18 @@ void SimulatorState::setCellDataComponent( const std::string& name , size_t comp } +std::vector& SimulatorState::getCellData( const std::string& name ) { + const auto iter = std::find( cellDataNames_.begin() , cellDataNames_.end() , name); + int id = iter - cellDataNames_.begin(); + auto& data = cellData_[id]; + return data; +} + + +const std::vector& SimulatorState::getCellData( const std::string& name ) const { + const auto iter = std::find( cellDataNames_.begin() , cellDataNames_.end() , name); + int id = iter - cellDataNames_.begin(); + const auto& data = cellData_[id]; + return data; +} + diff --git a/opm/core/simulator/SimulatorState.hpp b/opm/core/simulator/SimulatorState.hpp index e3dd9d3c..dbb8f132 100644 --- a/opm/core/simulator/SimulatorState.hpp +++ b/opm/core/simulator/SimulatorState.hpp @@ -70,6 +70,9 @@ namespace Opm size_t registerCellData( const std::string& name, const int components, const double initialValue = 0.0 ); size_t registerFaceData( const std::string& name, const int components, const double initialValue = 0.0 ); + + std::vector& getCellData( const std::string& name ); + const std::vector& getCellData( const std::string& name ) const; private: int num_cells_; int num_faces_;