diff --git a/examples/sim_2p_incomp_reorder.cpp b/examples/sim_2p_incomp_reorder.cpp index 6cac703b..4b42abb1 100644 --- a/examples/sim_2p_incomp_reorder.cpp +++ b/examples/sim_2p_incomp_reorder.cpp @@ -81,17 +81,7 @@ main(int argc, char** argv) // Grid init grid.reset(new GridManager(*deck)); // Rock and fluid init - int nc = grid->c_grid()->number_of_cells; - std::vector global_cell(nc); - const int* gc = grid->c_grid()->global_cell; - if (gc != 0) { - std::copy(gc, gc + nc, global_cell.begin()); - } else { - for (int cell = 0; cell < nc; ++cell) { - global_cell[cell] = cell; - } - } - props.reset(new IncompPropertiesFromDeck(*deck, global_cell)); + props.reset(new IncompPropertiesFromDeck(*deck, *grid->c_grid())); // check_well_controls = param.getDefault("check_well_controls", false); // max_well_control_iterations = param.getDefault("max_well_control_iterations", 10); // Rock compressibility. diff --git a/examples/sim_wateroil.cpp b/examples/sim_wateroil.cpp index 82f82fa1..479594b6 100644 --- a/examples/sim_wateroil.cpp +++ b/examples/sim_wateroil.cpp @@ -178,17 +178,7 @@ main(int argc, char** argv) // Grid init grid.reset(new Opm::GridManager(deck)); // Rock and fluid init - int nc = grid->c_grid()->number_of_cells; - std::vector global_cell(nc); - const int* gc = grid->c_grid()->global_cell; - if (gc != 0) { - std::copy(gc, gc + nc, global_cell.begin()); - } else { - for (int cell = 0; cell < nc; ++cell) { - global_cell[cell] = cell; - } - } - props.reset(new Opm::BlackoilPropertiesFromDeck(deck, global_cell)); + props.reset(new Opm::BlackoilPropertiesFromDeck(deck, *grid->c_grid())); // Wells init. wells.reset(new Opm::WellsManager(deck, *grid->c_grid(), props->permeability())); check_well_controls = param.getDefault("check_well_controls", false); diff --git a/examples/spu_2p.cpp b/examples/spu_2p.cpp index c8406598..2c6eea43 100644 --- a/examples/spu_2p.cpp +++ b/examples/spu_2p.cpp @@ -309,17 +309,7 @@ main(int argc, char** argv) // Grid init grid.reset(new Opm::GridManager(deck)); // Rock and fluid init - int nc = grid->c_grid()->number_of_cells; - std::vector global_cell(nc); - const int* gc = grid->c_grid()->global_cell; - if (gc != 0) { - std::copy(gc, gc + nc, global_cell.begin()); - } else { - for (int cell = 0; cell < nc; ++cell) { - global_cell[cell] = cell; - } - } - props.reset(new Opm::IncompPropertiesFromDeck(deck, global_cell)); + props.reset(new Opm::IncompPropertiesFromDeck(deck, *grid->c_grid())); // Wells init. wells.reset(new Opm::WellsManager(deck, *grid->c_grid(), props->permeability())); check_well_controls = param.getDefault("check_well_controls", false); diff --git a/examples/wells_example.cpp b/examples/wells_example.cpp index 2da110f3..1c523420 100644 --- a/examples/wells_example.cpp +++ b/examples/wells_example.cpp @@ -38,19 +38,8 @@ int main(int argc, char** argv) // Finally handle the wells WellsManager wells(parser, *grid.c_grid(), NULL); - int nc = grid.c_grid()->number_of_cells; - std::vector global_cells(nc); - const int* gc = grid.c_grid()->global_cell; - if (gc != 0) { - std::copy(gc, gc + nc, global_cells.begin()); - } else { - for (int cell = 0; cell < nc; ++cell) { - global_cells[cell] = cell; - } - } - double gravity[3] = {0.0, 0.0, parameters.getDefault("gravity", 0.0)}; - IncompPropertiesFromDeck incomp_properties(parser, global_cells); + IncompPropertiesFromDeck incomp_properties(parser, *grid.c_grid()); RockCompressibility rock_comp(parser); diff --git a/opm/core/fluid/BlackoilPropertiesFromDeck.cpp b/opm/core/fluid/BlackoilPropertiesFromDeck.cpp index 0eb23cb0..004e6f88 100644 --- a/opm/core/fluid/BlackoilPropertiesFromDeck.cpp +++ b/opm/core/fluid/BlackoilPropertiesFromDeck.cpp @@ -23,11 +23,11 @@ namespace Opm { BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck(const EclipseGridParser& deck, - const std::vector& global_cell) + const UnstructuredGrid& grid) { - rock_.init(deck, global_cell); + rock_.init(deck, grid); pvt_.init(deck); - satprops_.init(deck, global_cell); + satprops_.init(deck, grid); if (pvt_.numPhases() != satprops_.numPhases()) { THROW("BlackoilPropertiesBasic::BlackoilPropertiesBasic() - Inconsistent number of phases in pvt data (" << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_.numPhases() << ")."); diff --git a/opm/core/fluid/BlackoilPropertiesFromDeck.hpp b/opm/core/fluid/BlackoilPropertiesFromDeck.hpp index 9c20b568..a2a6c3de 100644 --- a/opm/core/fluid/BlackoilPropertiesFromDeck.hpp +++ b/opm/core/fluid/BlackoilPropertiesFromDeck.hpp @@ -27,6 +27,8 @@ #include #include +struct UnstructuredGrid; + namespace Opm { @@ -35,12 +37,13 @@ namespace Opm class BlackoilPropertiesFromDeck : public BlackoilPropertiesInterface { public: - /// Construct from deck and cell mapping. - /// \param deck eclipse input parser - /// \param global_cell mapping from cell indices (typically from a processed grid) + /// Initialize from deck and grid. + /// \param deck Deck input parser + /// \param grid Grid to which property object applies, needed for the + /// mapping from cell indices (typically from a processed grid) /// to logical cartesian indices consistent with the deck. BlackoilPropertiesFromDeck(const EclipseGridParser& deck, - const std::vector& global_cell); + const UnstructuredGrid& grid); /// Destructor. virtual ~BlackoilPropertiesFromDeck(); diff --git a/opm/core/fluid/IncompPropertiesFromDeck.cpp b/opm/core/fluid/IncompPropertiesFromDeck.cpp index e61e13c8..570154bf 100644 --- a/opm/core/fluid/IncompPropertiesFromDeck.cpp +++ b/opm/core/fluid/IncompPropertiesFromDeck.cpp @@ -27,11 +27,11 @@ namespace Opm { IncompPropertiesFromDeck::IncompPropertiesFromDeck(const EclipseGridParser& deck, - const std::vector& global_cell) + const UnstructuredGrid& grid) { - rock_.init(deck, global_cell); + rock_.init(deck, grid); pvt_.init(deck); - satprops_.init(deck, global_cell); + satprops_.init(deck, grid); if (pvt_.numPhases() != satprops_.numPhases()) { THROW("IncompPropertiesFromDeck::IncompPropertiesFromDeck() - Inconsistent number of phases in pvt data (" << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_.numPhases() << ")."); diff --git a/opm/core/fluid/IncompPropertiesFromDeck.hpp b/opm/core/fluid/IncompPropertiesFromDeck.hpp index d17dd1b7..68623e5c 100644 --- a/opm/core/fluid/IncompPropertiesFromDeck.hpp +++ b/opm/core/fluid/IncompPropertiesFromDeck.hpp @@ -26,6 +26,8 @@ #include #include +struct UnstructuredGrid; + namespace Opm { @@ -43,12 +45,13 @@ namespace Opm class IncompPropertiesFromDeck : public IncompPropertiesInterface { public: - /// Construct from deck and cell mapping. - /// \param deck eclipse input parser - /// \param global_cell mapping from cell indices (typically from a processed grid) + /// Initialize from deck and grid. + /// \param deck Deck input parser + /// \param grid Grid to which property object applies, needed for the + /// mapping from cell indices (typically from a processed grid) /// to logical cartesian indices consistent with the deck. IncompPropertiesFromDeck(const EclipseGridParser& deck, - const std::vector& global_cell); + const UnstructuredGrid& grid); /// Destructor. virtual ~IncompPropertiesFromDeck(); diff --git a/opm/core/fluid/RockFromDeck.cpp b/opm/core/fluid/RockFromDeck.cpp index 94777904..6568e8cc 100644 --- a/opm/core/fluid/RockFromDeck.cpp +++ b/opm/core/fluid/RockFromDeck.cpp @@ -19,7 +19,7 @@ #include - +#include #include namespace Opm @@ -53,28 +53,29 @@ namespace Opm /// Initialize from deck and cell mapping. /// \param deck Deck input parser - /// \param global_cell mapping from cell indices (typically from a processed grid) + /// \param grid grid to which property object applies, needed for the + /// mapping from cell indices (typically from a processed grid) /// to logical cartesian indices consistent with the deck. void RockFromDeck::init(const EclipseGridParser& deck, - const std::vector& global_cell) + const UnstructuredGrid& grid) { - assignPorosity(deck, global_cell); - permfield_valid_.assign(global_cell.size(), false); + assignPorosity(deck, grid); + permfield_valid_.assign(grid.number_of_cells, false); const double perm_threshold = 0.0; // Maybe turn into parameter? - assignPermeability(deck, global_cell, perm_threshold); + assignPermeability(deck, grid, perm_threshold); } void RockFromDeck::assignPorosity(const EclipseGridParser& parser, - const std::vector& global_cell) + const UnstructuredGrid& grid) { - porosity_.assign(global_cell.size(), 1.0); - + porosity_.assign(grid.number_of_cells, 1.0); + const int* gc = grid.global_cell; if (parser.hasField("PORO")) { const std::vector& poro = parser.getFloatingPointValue("PORO"); - for (int c = 0; c < int(porosity_.size()); ++c) { - porosity_[c] = poro[global_cell[c]]; + const int deck_pos = (gc == NULL) ? c : gc[c]; + porosity_[c] = poro[deck_pos]; } } } @@ -82,14 +83,16 @@ namespace Opm void RockFromDeck::assignPermeability(const EclipseGridParser& parser, - const std::vector& global_cell, + const UnstructuredGrid& grid, double perm_threshold) { const int dim = 3; const int num_global_cells = numGlobalCells(parser); + const int nc = grid.number_of_cells; + ASSERT (num_global_cells > 0); - permeability_.assign(dim * dim * global_cell.size(), 0.0); + permeability_.assign(dim * dim * nc, 0.0); std::vector*> tensor; tensor.reserve(10); @@ -111,13 +114,13 @@ namespace Opm // chosen) default value... // if (tensor.size() > 1) { - const int nc = global_cell.size(); - int off = 0; + const int* gc = grid.global_cell; + int off = 0; for (int c = 0; c < nc; ++c, off += dim*dim) { // SharedPermTensor K(dim, dim, &permeability_[off]); int kix = 0; - const int glob = global_cell[c]; + const int glob = (gc == NULL) ? c : gc[c]; for (int i = 0; i < dim; ++i) { for (int j = 0; j < dim; ++j, ++kix) { diff --git a/opm/core/fluid/RockFromDeck.hpp b/opm/core/fluid/RockFromDeck.hpp index abd9c14c..65027e42 100644 --- a/opm/core/fluid/RockFromDeck.hpp +++ b/opm/core/fluid/RockFromDeck.hpp @@ -24,6 +24,7 @@ #include #include +struct UnstructuredGrid; namespace Opm { @@ -34,12 +35,13 @@ namespace Opm /// Default constructor. RockFromDeck(); - /// Initialize from deck and cell mapping. + /// Initialize from deck and grid. /// \param deck Deck input parser - /// \param global_cell mapping from cell indices (typically from a processed grid) + /// \param grid Grid to which property object applies, needed for the + /// mapping from cell indices (typically from a processed grid) /// to logical cartesian indices consistent with the deck. void init(const EclipseGridParser& deck, - const std::vector& global_cell); + const UnstructuredGrid& grid); /// \return D, the number of spatial dimensions. Always 3 for deck input. int numDimensions() const @@ -69,9 +71,9 @@ namespace Opm private: void assignPorosity(const EclipseGridParser& parser, - const std::vector& global_cell); + const UnstructuredGrid& grid); void assignPermeability(const EclipseGridParser& parser, - const std::vector& global_cell, + const UnstructuredGrid& grid, const double perm_threshold); std::vector porosity_; diff --git a/opm/core/fluid/SaturationPropsFromDeck.cpp b/opm/core/fluid/SaturationPropsFromDeck.cpp index 89f81278..36cf8364 100644 --- a/opm/core/fluid/SaturationPropsFromDeck.cpp +++ b/opm/core/fluid/SaturationPropsFromDeck.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -33,7 +34,7 @@ namespace Opm /// Initialize from deck. void SaturationPropsFromDeck::init(const EclipseGridParser& deck, - const std::vector& global_cell) + const UnstructuredGrid& grid) { phase_usage_ = phaseUsageFromDeck(deck); @@ -49,10 +50,12 @@ namespace Opm if (deck.hasField("SATNUM")) { const std::vector& satnum = deck.getIntegerValue("SATNUM"); satfuncs_expected = *std::max_element(satnum.begin(), satnum.end()); - int num_cells = global_cell.size(); + const int num_cells = grid.number_of_cells; cell_to_func_.resize(num_cells); + const int* gc = grid.global_cell; for (int cell = 0; cell < num_cells; ++cell) { - cell_to_func_[cell] = satnum[global_cell[cell]] - 1; + const int deck_pos = (gc == NULL) ? cell : gc[cell]; + cell_to_func_[cell] = satnum[deck_pos] - 1; } } diff --git a/opm/core/fluid/SaturationPropsFromDeck.hpp b/opm/core/fluid/SaturationPropsFromDeck.hpp index 7c8be8d4..b83a1271 100644 --- a/opm/core/fluid/SaturationPropsFromDeck.hpp +++ b/opm/core/fluid/SaturationPropsFromDeck.hpp @@ -25,6 +25,8 @@ #include #include +struct UnstructuredGrid; + namespace Opm { @@ -34,10 +36,13 @@ namespace Opm /// Default constructor. SaturationPropsFromDeck(); - /// Initialize from deck. - /// global_cell maps from grid cells to their original logical Cartesian indices. + /// Initialize from deck and grid. + /// \param deck Deck input parser + /// \param grid Grid to which property object applies, needed for the + /// mapping from cell indices (typically from a processed grid) + /// to logical cartesian indices consistent with the deck. void init(const EclipseGridParser& deck, - const std::vector& global_cell); + const UnstructuredGrid& grid); /// \return P, the number of phases. int numPhases() const; diff --git a/tests/bo_resprop_test.cpp b/tests/bo_resprop_test.cpp index 316bd9f3..5bf3aea1 100644 --- a/tests/bo_resprop_test.cpp +++ b/tests/bo_resprop_test.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -39,14 +40,10 @@ int main(int argc, char** argv) // Parser. std::string ecl_file = param.get("filename"); Opm::EclipseGridParser deck(ecl_file); - Opm::EclipseGridInspector insp(deck); - std::tr1::array gs = insp.gridSize(); - int num_cells = gs[0]*gs[1]*gs[2]; - std::vector global_cell(num_cells); - for (int i = 0; i < num_cells; ++i) { - global_cell[i] = i; - } - Opm::BlackoilPropertiesFromDeck props(deck, global_cell); + UnstructuredGrid grid; + grid.number_of_cells = 1; + grid.global_cell = NULL; + Opm::BlackoilPropertiesFromDeck props(deck, grid); const int n = 1; double p[n] = { 150e5 };