Merge pull request #3049 from atgeirr/fix-actnum-equals-manipulation

Fix ACTNUM manipulation with EQUALS
This commit is contained in:
Bård Skaflestad 2022-06-21 09:59:33 +02:00 committed by GitHub
commit 4d76351111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 255 additions and 23 deletions

View File

@ -695,6 +695,7 @@ if(ENABLE_ECL_INPUT)
opm/input/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.hpp
opm/input/eclipse/EclipseState/Grid/Fault.hpp
opm/input/eclipse/EclipseState/Grid/Box.hpp
opm/input/eclipse/EclipseState/Grid/FieldProps.hpp
opm/input/eclipse/EclipseState/Grid/FieldPropsManager.hpp
opm/input/eclipse/EclipseState/Grid/FaultFace.hpp
opm/input/eclipse/EclipseState/Grid/NNC.hpp

View File

@ -66,6 +66,7 @@ namespace Opm {
EclipseGrid(size_t nx, size_t ny, size_t nz,
double dx = 1.0, double dy = 1.0, double dz = 1.0);
explicit EclipseGrid(const GridDims& gd);
EclipseGrid(const std::array<int, 3>& dims ,
const std::vector<double>& coord ,

View File

@ -377,8 +377,11 @@ public:
/// Normal constructor for FieldProps.
FieldProps(const Deck& deck, const Phases& phases, const EclipseGrid& grid, const TableManager& table_arg);
/// Special case constructor used to process ACTNUM only.
FieldProps(const Deck& deck, const EclipseGrid& grid);
void reset_actnum(const std::vector<int>& actnum);
void apply_numerical_aquifers(const NumericalAquifers& numerical_aquifers);
@ -386,6 +389,7 @@ public:
const std::string& default_region() const;
std::vector<int> actnum();
const std::vector<int>& actnumRaw() const;
template <typename T>
static bool supported(const std::string& keyword);
@ -504,6 +508,7 @@ public:
static bool rst_cmp(const FieldProps& full_arg, const FieldProps& rst_arg);
private:
void scanGRIDSection(const GRIDSection& grid_section);
void scanGRIDSectionOnlyACTNUM(const GRIDSection& grid_section);
void scanEDITSection(const EDITSection& edit_section);
void scanPROPSSection(const PROPSSection& props_section);
void scanREGIONSSection(const REGIONSSection& regions_section);

View File

@ -21,6 +21,7 @@
#define _USE_MATH_DEFINES
#include <opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/input/eclipse/EclipseState/Grid/FieldProps.hpp>
#include <opm/common/ErrorMacros.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
@ -124,6 +125,25 @@ EclipseGrid::EclipseGrid(const std::string& fileName )
}
EclipseGrid::EclipseGrid(const GridDims& gd)
: GridDims(gd),
m_minpvMode(MinpvMode::ModeEnum::Inactive),
m_pinchoutMode(PinchMode::ModeEnum::TOPBOT),
m_multzMode(PinchMode::ModeEnum::TOP),
m_pinchGapMode(PinchMode::ModeEnum::GAP)
{
this->m_nactive = this->getCartesianSize();
this->active_volume = std::nullopt;
// Nothing else initialized. Leaving in particular as empty:
// m_actnum,
// m_global_to_active,
// m_active_to_global.
//
// EclipseGrid will only be usable for constructing Box objects with
// all cells active.
}
EclipseGrid::EclipseGrid(size_t nx, size_t ny , size_t nz,
double dx, double dy, double dz)
: GridDims(nx, ny, nz),
@ -478,6 +498,9 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum)
}
size_t EclipseGrid::activeIndex(size_t globalIndex) const {
if (m_global_to_active.empty()) {
return globalIndex;
}
if (m_global_to_active[ globalIndex] == -1) {
throw std::invalid_argument("Input argument does not correspond to an active cell");
@ -1145,23 +1168,15 @@ EclipseGrid::EclipseGrid(const Deck& deck, const int * actnum)
const std::vector<double>& zcorn = ZCORNKeyWord.getSIDoubleData();
const std::vector<double>& coord = COORDKeyWord.getSIDoubleData();
int * actnum = nullptr;
std::vector<int> actnumVector;
EclipseGrid topologyOnlyGrid(static_cast<GridDims&>(*this));
FieldProps fp(deck, topologyOnlyGrid);
const auto& actnumVector = fp.actnumRaw();
if (actnumVector.size() != this->getCartesianSize())
throw std::invalid_argument("ACTNUM vector has wrong size");
if (deck.hasKeyword<ParserKeywords::ACTNUM>()) {
const auto& actnumKeyword = deck.get<ParserKeywords::ACTNUM>().back();
actnumVector = actnumKeyword.getIntData();
OpmLog::info(fmt::format("\nCreating cornerpoint grid from keywords ZCORN, COORD and ACTNUM"));
if (actnumVector.size() != this->getCartesianSize())
throw std::invalid_argument("ACTNUM vector has wrong size");
actnum = actnumVector.data();
OpmLog::info(fmt::format("\nCreating cornerpoint grid from keywords ZCORN, COORD and ACTNUM"));
} else
OpmLog::info(fmt::format("\nCreating cornerpoint grid from keywords ZCORN and COORD"));
initCornerPointGrid( coord , zcorn, actnum);
initCornerPointGrid( coord , zcorn, actnumVector.data());
}
}
@ -1410,8 +1425,11 @@ std::vector<double> EclipseGrid::createDVector(const std::array<int,3>& dims, st
bool EclipseGrid::cellActive( size_t globalIndex ) const {
assertGlobalIndex( globalIndex );
return m_actnum[globalIndex]>0;
if (m_actnum.empty()) {
return true;
} else {
return m_actnum[globalIndex]>0;
}
}
bool EclipseGrid::cellActive( size_t i , size_t j , size_t k ) const {

View File

@ -15,6 +15,9 @@
You should have received a copy of the GNU General Public License along with
OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <opm/input/eclipse/EclipseState/Grid/FieldProps.hpp>
#include <functional>
#include <algorithm>
#include <unordered_map>
@ -46,7 +49,6 @@
#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/NumericalAquifers.hpp>
#include <opm/input/eclipse/EclipseState/Tables/TableManager.hpp>
#include "FieldProps.hpp"
#include "Operate.hpp"
@ -490,6 +492,32 @@ FieldProps::FieldProps(const Deck& deck, const Phases& phases, const EclipseGrid
}
// Special constructor ONLY used to get the correct ACTNUM.
// The grid argument should have all active cells.
FieldProps::FieldProps(const Deck& deck, const EclipseGrid& grid) :
active_size(grid.getNumActive()),
global_size(grid.getCartesianSize()),
unit_system(deck.getActiveUnitSystem()),
nx(grid.getNX()),
ny(grid.getNY()),
nz(grid.getNZ()),
m_phases(),
m_satfuncctrl(deck),
m_actnum(global_size, 1), // NB! activates all at start!
cell_volume(), // NB! empty for this purpose.
cell_depth(), // NB! empty for this purpose.
m_default_region(default_region_keyword(deck)),
grid_ptr(&grid),
tables() // NB! empty for this purpose.
{
if (this->active_size != this->global_size) {
throw std::logic_error("Programmer error: FieldProps special case processing for ACTNUM called with grid object that already had deactivated cells.");
}
if (DeckSection::hasGRID(deck))
this->scanGRIDSectionOnlyACTNUM(GRIDSection(deck));
}
void FieldProps::reset_actnum(const std::vector<int>& new_actnum) {
if (this->global_size != new_actnum.size())
@ -1148,6 +1176,11 @@ std::vector<int> FieldProps::actnum() {
}
const std::vector<int>& FieldProps::actnumRaw() const {
return m_actnum;
}
void FieldProps::scanGRIDSection(const GRIDSection& grid_section) {
Box box(*this->grid_ptr);
@ -1168,6 +1201,25 @@ void FieldProps::scanGRIDSection(const GRIDSection& grid_section) {
}
}
void FieldProps::scanGRIDSectionOnlyACTNUM(const GRIDSection& grid_section) {
Box box(*this->grid_ptr);
for (const auto& keyword : grid_section) {
const std::string& name = keyword.name();
if (name == "ACTNUM") {
this->handle_int_keyword(Fieldprops::keywords::GRID::int_keywords.at(name), keyword, box);
} else if (name == "EQUALS" || (Fieldprops::keywords::box_keywords.count(name) == 1)) {
this->handle_keyword(keyword, box);
}
}
const auto iter = this->int_data.find("ACTNUM");
if (iter == this->int_data.end()) {
m_actnum.assign(this->grid_ptr->getCartesianSize(), 1);
} else {
m_actnum = iter->second.data;
}
}
void FieldProps::scanEDITSection(const EDITSection& edit_section) {
Box box(*this->grid_ptr);
for (const auto& keyword : edit_section) {

View File

@ -20,14 +20,12 @@
#include <opm/input/eclipse/Deck/Deck.hpp>
#include <opm/input/eclipse/Deck/DeckKeyword.hpp>
#include <opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/input/eclipse/EclipseState/Grid/FieldProps.hpp>
#include <opm/input/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
#include <opm/input/eclipse/EclipseState/Runspec.hpp>
#include <opm/common/utility/Serializer.hpp>
#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/NumericalAquifers.hpp>
#include "FieldProps.hpp"
namespace Opm {

View File

@ -978,6 +978,111 @@ BOOST_AUTO_TEST_CASE(GridBoxActnum) {
}
}
/// Similar to createActnumBoxDeck(), but uses a corner point grid, and
/// also used EQUALS for re-activating a cell.
/// Creates a deck where the top-layer has ACTNUM = 0 and two partially
/// overlapping 2*2*2 boxes in the center, one [5,7]^3 and one [6,8]^3
/// have ACTNUM = 0, then the cell (7,7,7) is made active using EQUALS.
static Opm::Deck createActnumBoxDeck2() {
const char* deckData = "RUNSPEC\n"
"\n"
"DIMENS \n"
" 10 10 10 / \n"
"GRID\n"
"COORD\n"
" 726*1 / \n"
"ZCORN \n"
" 8000*1 / \n"
"PORO \n"
" 1000*0.15 /\n"
"EQUALS\n"
" ACTNUM 0 1 10 1 10 1 1 /\n" // disable top layer
"/ \n"
// start box
"BOX\n"
" 5 7 5 7 5 7 /\n"
"ACTNUM \n"
" 0 0 0 0 0 0 0 0 0\n"
" 0 0 0 0 0 0 0 0 0\n"
" 0 0 0 0 0 0 0 0 0\n"
"/\n"
"BOX\n" // don't need ENDBOX
" 6 8 6 8 6 8 /\n"
"ACTNUM \n"
" 27*0\n"
"/\n"
"ENDBOX\n"
"EQUALS\n"
" ACTNUM 1 7 7 7 7 7 7 /\n" // re-enable cell (7,7,7)
"/ \n"
"FLUXNUM\n"
"1000*0 /\n"
"EDIT\n"
"PORV\n"
"1000*1 /\n";
Opm::Parser parser;
return parser.parseString( deckData);
}
BOOST_AUTO_TEST_CASE(GridBoxActnum2) {
auto deck = createActnumBoxDeck2();
Opm::EclipseState es( deck);
const auto& fp = es.fieldProps();
const auto& grid = es.getInputGrid();
BOOST_CHECK_NO_THROW(fp.get_int("ACTNUM"));
size_t active = 10 * 10 * 10 // 1000
- (10 * 10 * 1) // - top layer
- ( 3 * 3 * 3) // - [5,7]^3 box
- ( 3 * 3 * 3) // - [6,8]^3 box
+ ( 2 * 2 * 2) // + inclusion/exclusion
+ 1; // cell (7,7,7)
BOOST_CHECK_NO_THROW(grid.getNumActive());
BOOST_CHECK_EQUAL(grid.getNumActive(), active);
BOOST_CHECK_EQUAL(es.getInputGrid().getNumActive(), active);
{
size_t active_index = 0;
// NB: The implementation of this test actually assumes that
// the loops are running with z as the outer and x as the
// inner direction.
for (size_t z = 0; z < grid.getNZ(); z++) {
for (size_t y = 0; y < grid.getNY(); y++) {
for (size_t x = 0; x < grid.getNX(); x++) {
if (z == 0)
BOOST_CHECK(!grid.cellActive(x, y, z));
else if (x == 6 && y == 6 && z == 6) {
BOOST_CHECK(grid.cellActive(x, y, z));
BOOST_CHECK_EQUAL( grid.activeIndex(x,y,z) , active_index );
size_t g = grid.getGlobalIndex( x,y,z );
BOOST_CHECK_EQUAL( grid.activeIndex(g) , active_index );
++active_index;
} else if (x >= 4 && x <= 6 && y >= 4 && y <= 6 && z >= 4 && z <= 6)
BOOST_CHECK(!grid.cellActive(x, y, z));
else if (x >= 5 && x <= 7 && y >= 5 && y <= 7 && z >= 5 && z <= 7)
BOOST_CHECK(!grid.cellActive(x, y, z));
else {
size_t g = grid.getGlobalIndex( x,y,z );
BOOST_CHECK(grid.cellActive(x, y, z));
BOOST_CHECK_EQUAL( grid.activeIndex(x,y,z) , active_index );
BOOST_CHECK_EQUAL( grid.activeIndex(g) , active_index );
active_index++;
}
}
}
}
BOOST_CHECK_THROW( grid.activeIndex(0,0,0) , std::invalid_argument );
}
}
BOOST_AUTO_TEST_CASE(GridActnumVia3D) {
auto deck = createActnumDeck();

View File

@ -48,7 +48,7 @@
#include <opm/input/eclipse/EclipseState/Runspec.hpp>
#include <opm/input/eclipse/Schedule/Schedule.hpp>
#include "src/opm/input/eclipse/EclipseState/Grid/FieldProps.hpp"
#include <opm/input/eclipse/EclipseState/Grid/FieldProps.hpp>
using namespace Opm;
@ -134,6 +134,58 @@ PERMX
}
BOOST_AUTO_TEST_CASE(CreateFieldPropsForActnum) {
std::string deck_string = R"(
GRID
BOX
1 3 1 3 1 1 /
ACTNUM
9*0 /
BOX
1 3 1 2 1 1 /
ACTNUM
6*1 /
ENDBOX
-- Re-enable (3,3,1)
EQUALS
ACTNUM 1 3 3 3 3 1 1 /
/
)";
Deck deck = Parser{}.parseString(deck_string);
EclipseGrid grid{GridDims{3, 3, 1}};
FieldProps fp(deck, grid);
std::vector<int> expected_actnum = { 1, 1, 1,
1, 1, 1,
0, 0, 1 };
auto actnum = fp.actnumRaw();
BOOST_CHECK_EQUAL_COLLECTIONS(actnum.begin(), actnum.end(), expected_actnum.begin(), expected_actnum.end());
}
BOOST_AUTO_TEST_CASE(CreateFieldPropsForActnumButNoActnumInDeck) {
std::string deck_string = R"(
GRID
)";
Deck deck = Parser{}.parseString(deck_string);
EclipseGrid grid{GridDims{3, 3, 1}};
FieldProps fp(deck, grid);
std::vector<int> expected_actnum = { 1, 1, 1,
1, 1, 1,
1, 1, 1 };
auto actnum = fp.actnumRaw();
BOOST_CHECK_EQUAL_COLLECTIONS(actnum.begin(), actnum.end(), expected_actnum.begin(), expected_actnum.end());
}
BOOST_AUTO_TEST_CASE(INVALID_COPY) {
std::string deck_string = R"(
GRID