Constructors of *FromDeck classes now take an UnstructuredGrid.

This is a change from taking a vector containing the mapping to
deck-consistent logical cartesian indices. The mapping is contained
in the UnstructuredGrid::global_cell member, and may be null. The
change therefore saves the overhead of constructing a vector as a
copy of the data in the grid or (if null) as an identity mapping.
This commit is contained in:
Atgeirr Flø Rasmussen 2012-08-10 10:12:45 +02:00
parent abb4264b48
commit 9a23b8db74
13 changed files with 69 additions and 94 deletions

View File

@ -81,17 +81,7 @@ main(int argc, char** argv)
// Grid init // Grid init
grid.reset(new GridManager(*deck)); grid.reset(new GridManager(*deck));
// Rock and fluid init // Rock and fluid init
int nc = grid->c_grid()->number_of_cells; props.reset(new IncompPropertiesFromDeck(*deck, *grid->c_grid()));
std::vector<int> 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));
// check_well_controls = param.getDefault("check_well_controls", false); // check_well_controls = param.getDefault("check_well_controls", false);
// max_well_control_iterations = param.getDefault("max_well_control_iterations", 10); // max_well_control_iterations = param.getDefault("max_well_control_iterations", 10);
// Rock compressibility. // Rock compressibility.

View File

@ -178,17 +178,7 @@ main(int argc, char** argv)
// Grid init // Grid init
grid.reset(new Opm::GridManager(deck)); grid.reset(new Opm::GridManager(deck));
// Rock and fluid init // Rock and fluid init
int nc = grid->c_grid()->number_of_cells; props.reset(new Opm::BlackoilPropertiesFromDeck(deck, *grid->c_grid()));
std::vector<int> 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));
// Wells init. // Wells init.
wells.reset(new Opm::WellsManager(deck, *grid->c_grid(), props->permeability())); wells.reset(new Opm::WellsManager(deck, *grid->c_grid(), props->permeability()));
check_well_controls = param.getDefault("check_well_controls", false); check_well_controls = param.getDefault("check_well_controls", false);

View File

@ -309,17 +309,7 @@ main(int argc, char** argv)
// Grid init // Grid init
grid.reset(new Opm::GridManager(deck)); grid.reset(new Opm::GridManager(deck));
// Rock and fluid init // Rock and fluid init
int nc = grid->c_grid()->number_of_cells; props.reset(new Opm::IncompPropertiesFromDeck(deck, *grid->c_grid()));
std::vector<int> 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));
// Wells init. // Wells init.
wells.reset(new Opm::WellsManager(deck, *grid->c_grid(), props->permeability())); wells.reset(new Opm::WellsManager(deck, *grid->c_grid(), props->permeability()));
check_well_controls = param.getDefault("check_well_controls", false); check_well_controls = param.getDefault("check_well_controls", false);

View File

@ -38,19 +38,8 @@ int main(int argc, char** argv)
// Finally handle the wells // Finally handle the wells
WellsManager wells(parser, *grid.c_grid(), NULL); WellsManager wells(parser, *grid.c_grid(), NULL);
int nc = grid.c_grid()->number_of_cells;
std::vector<int> 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<double>("gravity", 0.0)}; double gravity[3] = {0.0, 0.0, parameters.getDefault<double>("gravity", 0.0)};
IncompPropertiesFromDeck incomp_properties(parser, global_cells); IncompPropertiesFromDeck incomp_properties(parser, *grid.c_grid());
RockCompressibility rock_comp(parser); RockCompressibility rock_comp(parser);

View File

@ -23,11 +23,11 @@ namespace Opm
{ {
BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck(const EclipseGridParser& deck, BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck(const EclipseGridParser& deck,
const std::vector<int>& global_cell) const UnstructuredGrid& grid)
{ {
rock_.init(deck, global_cell); rock_.init(deck, grid);
pvt_.init(deck); pvt_.init(deck);
satprops_.init(deck, global_cell); satprops_.init(deck, grid);
if (pvt_.numPhases() != satprops_.numPhases()) { if (pvt_.numPhases() != satprops_.numPhases()) {
THROW("BlackoilPropertiesBasic::BlackoilPropertiesBasic() - Inconsistent number of phases in pvt data (" THROW("BlackoilPropertiesBasic::BlackoilPropertiesBasic() - Inconsistent number of phases in pvt data ("
<< pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_.numPhases() << ")."); << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_.numPhases() << ").");

View File

@ -27,6 +27,8 @@
#include <opm/core/fluid/SaturationPropsFromDeck.hpp> #include <opm/core/fluid/SaturationPropsFromDeck.hpp>
#include <opm/core/eclipse/EclipseGridParser.hpp> #include <opm/core/eclipse/EclipseGridParser.hpp>
struct UnstructuredGrid;
namespace Opm namespace Opm
{ {
@ -35,12 +37,13 @@ namespace Opm
class BlackoilPropertiesFromDeck : public BlackoilPropertiesInterface class BlackoilPropertiesFromDeck : public BlackoilPropertiesInterface
{ {
public: public:
/// Construct from deck and cell mapping. /// Initialize from deck and grid.
/// \param deck eclipse input parser /// \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. /// to logical cartesian indices consistent with the deck.
BlackoilPropertiesFromDeck(const EclipseGridParser& deck, BlackoilPropertiesFromDeck(const EclipseGridParser& deck,
const std::vector<int>& global_cell); const UnstructuredGrid& grid);
/// Destructor. /// Destructor.
virtual ~BlackoilPropertiesFromDeck(); virtual ~BlackoilPropertiesFromDeck();

View File

@ -27,11 +27,11 @@ namespace Opm
{ {
IncompPropertiesFromDeck::IncompPropertiesFromDeck(const EclipseGridParser& deck, IncompPropertiesFromDeck::IncompPropertiesFromDeck(const EclipseGridParser& deck,
const std::vector<int>& global_cell) const UnstructuredGrid& grid)
{ {
rock_.init(deck, global_cell); rock_.init(deck, grid);
pvt_.init(deck); pvt_.init(deck);
satprops_.init(deck, global_cell); satprops_.init(deck, grid);
if (pvt_.numPhases() != satprops_.numPhases()) { if (pvt_.numPhases() != satprops_.numPhases()) {
THROW("IncompPropertiesFromDeck::IncompPropertiesFromDeck() - Inconsistent number of phases in pvt data (" THROW("IncompPropertiesFromDeck::IncompPropertiesFromDeck() - Inconsistent number of phases in pvt data ("
<< pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_.numPhases() << ")."); << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_.numPhases() << ").");

View File

@ -26,6 +26,8 @@
#include <opm/core/fluid/SaturationPropsFromDeck.hpp> #include <opm/core/fluid/SaturationPropsFromDeck.hpp>
#include <opm/core/eclipse/EclipseGridParser.hpp> #include <opm/core/eclipse/EclipseGridParser.hpp>
struct UnstructuredGrid;
namespace Opm namespace Opm
{ {
@ -43,12 +45,13 @@ namespace Opm
class IncompPropertiesFromDeck : public IncompPropertiesInterface class IncompPropertiesFromDeck : public IncompPropertiesInterface
{ {
public: public:
/// Construct from deck and cell mapping. /// Initialize from deck and grid.
/// \param deck eclipse input parser /// \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. /// to logical cartesian indices consistent with the deck.
IncompPropertiesFromDeck(const EclipseGridParser& deck, IncompPropertiesFromDeck(const EclipseGridParser& deck,
const std::vector<int>& global_cell); const UnstructuredGrid& grid);
/// Destructor. /// Destructor.
virtual ~IncompPropertiesFromDeck(); virtual ~IncompPropertiesFromDeck();

View File

@ -19,7 +19,7 @@
#include <opm/core/fluid/RockFromDeck.hpp> #include <opm/core/fluid/RockFromDeck.hpp>
#include <opm/core/grid.h>
#include <tr1/array> #include <tr1/array>
namespace Opm namespace Opm
@ -53,28 +53,29 @@ namespace Opm
/// Initialize from deck and cell mapping. /// Initialize from deck and cell mapping.
/// \param deck Deck input parser /// \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. /// to logical cartesian indices consistent with the deck.
void RockFromDeck::init(const EclipseGridParser& deck, void RockFromDeck::init(const EclipseGridParser& deck,
const std::vector<int>& global_cell) const UnstructuredGrid& grid)
{ {
assignPorosity(deck, global_cell); assignPorosity(deck, grid);
permfield_valid_.assign(global_cell.size(), false); permfield_valid_.assign(grid.number_of_cells, false);
const double perm_threshold = 0.0; // Maybe turn into parameter? 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, void RockFromDeck::assignPorosity(const EclipseGridParser& parser,
const std::vector<int>& 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")) { if (parser.hasField("PORO")) {
const std::vector<double>& poro = parser.getFloatingPointValue("PORO"); const std::vector<double>& poro = parser.getFloatingPointValue("PORO");
for (int c = 0; c < int(porosity_.size()); ++c) { 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, void RockFromDeck::assignPermeability(const EclipseGridParser& parser,
const std::vector<int>& global_cell, const UnstructuredGrid& grid,
double perm_threshold) double perm_threshold)
{ {
const int dim = 3; const int dim = 3;
const int num_global_cells = numGlobalCells(parser); const int num_global_cells = numGlobalCells(parser);
const int nc = grid.number_of_cells;
ASSERT (num_global_cells > 0); ASSERT (num_global_cells > 0);
permeability_.assign(dim * dim * global_cell.size(), 0.0); permeability_.assign(dim * dim * nc, 0.0);
std::vector<const std::vector<double>*> tensor; std::vector<const std::vector<double>*> tensor;
tensor.reserve(10); tensor.reserve(10);
@ -111,13 +114,13 @@ namespace Opm
// chosen) default value... // chosen) default value...
// //
if (tensor.size() > 1) { if (tensor.size() > 1) {
const int nc = global_cell.size(); const int* gc = grid.global_cell;
int off = 0; int off = 0;
for (int c = 0; c < nc; ++c, off += dim*dim) { for (int c = 0; c < nc; ++c, off += dim*dim) {
// SharedPermTensor K(dim, dim, &permeability_[off]); // SharedPermTensor K(dim, dim, &permeability_[off]);
int kix = 0; 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 i = 0; i < dim; ++i) {
for (int j = 0; j < dim; ++j, ++kix) { for (int j = 0; j < dim; ++j, ++kix) {

View File

@ -24,6 +24,7 @@
#include <opm/core/eclipse/EclipseGridParser.hpp> #include <opm/core/eclipse/EclipseGridParser.hpp>
#include <vector> #include <vector>
struct UnstructuredGrid;
namespace Opm namespace Opm
{ {
@ -34,12 +35,13 @@ namespace Opm
/// Default constructor. /// Default constructor.
RockFromDeck(); RockFromDeck();
/// Initialize from deck and cell mapping. /// Initialize from deck and grid.
/// \param deck Deck input parser /// \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. /// to logical cartesian indices consistent with the deck.
void init(const EclipseGridParser& deck, void init(const EclipseGridParser& deck,
const std::vector<int>& global_cell); const UnstructuredGrid& grid);
/// \return D, the number of spatial dimensions. Always 3 for deck input. /// \return D, the number of spatial dimensions. Always 3 for deck input.
int numDimensions() const int numDimensions() const
@ -69,9 +71,9 @@ namespace Opm
private: private:
void assignPorosity(const EclipseGridParser& parser, void assignPorosity(const EclipseGridParser& parser,
const std::vector<int>& global_cell); const UnstructuredGrid& grid);
void assignPermeability(const EclipseGridParser& parser, void assignPermeability(const EclipseGridParser& parser,
const std::vector<int>& global_cell, const UnstructuredGrid& grid,
const double perm_threshold); const double perm_threshold);
std::vector<double> porosity_; std::vector<double> porosity_;

View File

@ -18,6 +18,7 @@
*/ */
#include <opm/core/fluid/SaturationPropsFromDeck.hpp> #include <opm/core/fluid/SaturationPropsFromDeck.hpp>
#include <opm/core/grid.h>
#include <opm/core/fluid/blackoil/phaseUsageFromDeck.hpp> #include <opm/core/fluid/blackoil/phaseUsageFromDeck.hpp>
#include <opm/core/utility/buildUniformMonotoneTable.hpp> #include <opm/core/utility/buildUniformMonotoneTable.hpp>
#include <opm/core/utility/ErrorMacros.hpp> #include <opm/core/utility/ErrorMacros.hpp>
@ -33,7 +34,7 @@ namespace Opm
/// Initialize from deck. /// Initialize from deck.
void SaturationPropsFromDeck::init(const EclipseGridParser& deck, void SaturationPropsFromDeck::init(const EclipseGridParser& deck,
const std::vector<int>& global_cell) const UnstructuredGrid& grid)
{ {
phase_usage_ = phaseUsageFromDeck(deck); phase_usage_ = phaseUsageFromDeck(deck);
@ -49,10 +50,12 @@ namespace Opm
if (deck.hasField("SATNUM")) { if (deck.hasField("SATNUM")) {
const std::vector<int>& satnum = deck.getIntegerValue("SATNUM"); const std::vector<int>& satnum = deck.getIntegerValue("SATNUM");
satfuncs_expected = *std::max_element(satnum.begin(), satnum.end()); 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); cell_to_func_.resize(num_cells);
const int* gc = grid.global_cell;
for (int cell = 0; cell < num_cells; ++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;
} }
} }

View File

@ -25,6 +25,8 @@
#include <opm/core/fluid/blackoil/BlackoilPhases.hpp> #include <opm/core/fluid/blackoil/BlackoilPhases.hpp>
#include <vector> #include <vector>
struct UnstructuredGrid;
namespace Opm namespace Opm
{ {
@ -34,10 +36,13 @@ namespace Opm
/// Default constructor. /// Default constructor.
SaturationPropsFromDeck(); SaturationPropsFromDeck();
/// Initialize from deck. /// Initialize from deck and grid.
/// global_cell maps from grid cells to their original logical Cartesian indices. /// \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, void init(const EclipseGridParser& deck,
const std::vector<int>& global_cell); const UnstructuredGrid& grid);
/// \return P, the number of phases. /// \return P, the number of phases.
int numPhases() const; int numPhases() const;

View File

@ -24,6 +24,7 @@
#include <opm/core/eclipse/EclipseGridParser.hpp> #include <opm/core/eclipse/EclipseGridParser.hpp>
#include <opm/core/eclipse/EclipseGridInspector.hpp> #include <opm/core/eclipse/EclipseGridInspector.hpp>
#include <opm/core/fluid/BlackoilPropertiesFromDeck.hpp> #include <opm/core/fluid/BlackoilPropertiesFromDeck.hpp>
#include <opm/core/grid.h>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
@ -39,14 +40,10 @@ int main(int argc, char** argv)
// Parser. // Parser.
std::string ecl_file = param.get<std::string>("filename"); std::string ecl_file = param.get<std::string>("filename");
Opm::EclipseGridParser deck(ecl_file); Opm::EclipseGridParser deck(ecl_file);
Opm::EclipseGridInspector insp(deck); UnstructuredGrid grid;
std::tr1::array<int, 3> gs = insp.gridSize(); grid.number_of_cells = 1;
int num_cells = gs[0]*gs[1]*gs[2]; grid.global_cell = NULL;
std::vector<int> global_cell(num_cells); Opm::BlackoilPropertiesFromDeck props(deck, grid);
for (int i = 0; i < num_cells; ++i) {
global_cell[i] = i;
}
Opm::BlackoilPropertiesFromDeck props(deck, global_cell);
const int n = 1; const int n = 1;
double p[n] = { 150e5 }; double p[n] = { 150e5 };