Added SimulatorState::getCellData()

This commit is contained in:
Joakim Hove 2016-02-22 10:49:04 +01:00
parent 6c5fae2f9d
commit 6ca10ea57d
2 changed files with 22 additions and 4 deletions

View File

@ -87,10 +87,10 @@ void SimulatorState::setCellDataComponent( const std::string& name , size_t comp
auto& data = cellData_[id]; auto& data = cellData_[id];
if (component >= num_phases_) if (component >= num_phases_)
throw std::invalid_argument("Invalid component"); throw std::invalid_argument("Invalid component");
if (cells.size() != values.size()) if (cells.size() != values.size())
throw std::invalid_argument("size mismatch between cells and values"); throw std::invalid_argument("size mismatch between cells and values");
/* This is currently quite broken; the setCellDataComponent /* This is currently quite broken; the setCellDataComponent
method assumes that the number of components in the field method assumes that the number of components in the field
we are currently focusing on has num_phases components in 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_) 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...) "); 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++) { for (size_t i = 0; i < cells.size(); i++) {
if (cells[i] < num_cells_) { if (cells[i] < num_cells_) {
auto field_index = cells[i] * num_phases_ + component; auto field_index = cells[i] * num_phases_ + component;
auto value = values[i]; auto value = values[i];
data[field_index] = value; data[field_index] = value;
} else { } else {
throw std::invalid_argument("Invalid cell number"); throw std::invalid_argument("Invalid cell number");
@ -113,3 +113,18 @@ void SimulatorState::setCellDataComponent( const std::string& name , size_t comp
} }
std::vector<double>& 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<double>& 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;
}

View File

@ -70,6 +70,9 @@ namespace Opm
size_t registerCellData( const std::string& name, const int components, const double initialValue = 0.0 ); 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 ); size_t registerFaceData( const std::string& name, const int components, const double initialValue = 0.0 );
std::vector<double>& getCellData( const std::string& name );
const std::vector<double>& getCellData( const std::string& name ) const;
private: private:
int num_cells_; int num_cells_;
int num_faces_; int num_faces_;