From 976bfdab3507e5480e364f598925caf99e205905 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 19 Mar 2018 10:41:01 +0100 Subject: [PATCH 1/5] Use opm-internal algorithm for volume calculation --- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 2 +- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 26 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp index 14f973904..0fcbb2ae2 100644 --- a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -181,9 +181,9 @@ namespace Opm { Value m_pinch; PinchMode::ModeEnum m_pinchoutMode; PinchMode::ModeEnum m_multzMode; + std::vector volume_cache mutable; mutable std::vector< int > activeMap; bool m_circle = false; - /* The internal class grid_ptr is a a std::unique_ptr with special copy semantics. The purpose of implementing this is diff --git a/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp b/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp index 7c7546309..00c4e8fe2 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -61,7 +61,8 @@ namespace Opm { m_minpvMode(MinpvMode::ModeEnum::Inactive), m_pinch("PINCH"), m_pinchoutMode(PinchMode::ModeEnum::TOPBOT), - m_multzMode(PinchMode::ModeEnum::TOP) + m_multzMode(PinchMode::ModeEnum::TOP), + volume_cache(dims[0] * dims[1] * dims[2], -1) { initCornerPointGrid( dims, coord , zcorn , actnum , mapaxes ); } @@ -78,7 +79,8 @@ namespace Opm { m_minpvMode(MinpvMode::ModeEnum::Inactive), m_pinch("PINCH"), m_pinchoutMode(PinchMode::ModeEnum::TOPBOT), - m_multzMode(PinchMode::ModeEnum::TOP) + m_multzMode(PinchMode::ModeEnum::TOP), + volume_cache(dims[0] * dims[1] * dims[2], -1) { ecl_grid_type * new_ptr = ecl_grid_load_case__( filename.c_str() , false ); if (new_ptr) @@ -100,6 +102,7 @@ namespace Opm { m_pinch("PINCH"), m_pinchoutMode(PinchMode::ModeEnum::TOPBOT), m_multzMode(PinchMode::ModeEnum::TOP), + volume_cache(dims[0] * dims[1] * dims[2], -1) m_grid( ecl_grid_alloc_rectangular(nx, ny, nz, dx, dy, dz, NULL) ) { } @@ -110,7 +113,8 @@ namespace Opm { m_minpvMode( src.m_minpvMode ), m_pinch( src.m_pinch ), m_pinchoutMode( src.m_pinchoutMode ), - m_multzMode( src.m_multzMode ) + m_multzMode( src.m_multzMode ), + volume_cache(dims[0] * dims[1] * dims[2], -1) { const int * actnum_data = (actnum.empty()) ? nullptr : actnum.data(); m_grid.reset( ecl_grid_alloc_processed_copy( src.c_ptr(), zcorn , actnum_data )); @@ -163,7 +167,8 @@ namespace Opm { m_minpvMode(MinpvMode::ModeEnum::Inactive), m_pinch("PINCH"), m_pinchoutMode(PinchMode::ModeEnum::TOPBOT), - m_multzMode(PinchMode::ModeEnum::TOP) + m_multzMode(PinchMode::ModeEnum::TOP), + volume_cache(dims[0] * dims[1] * dims[2], -1) { const std::array dims = getNXYZ(); @@ -728,7 +733,18 @@ namespace Opm { double EclipseGrid::getCellVolume(size_t globalIndex) const { assertGlobalIndex( globalIndex ); - return ecl_grid_get_cell_volume1( c_ptr() , static_cast(globalIndex)); + if (volume_cache[global_index] < 0) { + std::vector x(8,0); + std::vector y(8,0); + std::vector z(8,0); + + for (int i=0; i < 8; i++) + ecl_grid_gell_corner_xyz1(c_ptr(), static_cast(globalIndex), i, &x.data()[i], &y.data()[i], &z.data()[i]); + + + volume_cache[i] = calc_cell_volume(x,y,z); + } + return volume_cache[global_index]; } From 98e3bbcf1db3a43d8ad80a3f1e1952ba18e939e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Fri, 29 Jun 2018 12:28:38 +0200 Subject: [PATCH 2/5] Changes to make the code compile and run. --- .../eclipse/EclipseState/Grid/EclipseGrid.hpp | 2 +- .../eclipse/EclipseState/Grid/EclipseGrid.cpp | 35 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp index 0fcbb2ae2..c870471ce 100644 --- a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -181,7 +181,7 @@ namespace Opm { Value m_pinch; PinchMode::ModeEnum m_pinchoutMode; PinchMode::ModeEnum m_multzMode; - std::vector volume_cache mutable; + mutable std::vector volume_cache; mutable std::vector< int > activeMap; bool m_circle = false; /* diff --git a/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp b/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp index 00c4e8fe2..d2a209091 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -57,12 +58,13 @@ namespace Opm { const std::vector& zcorn , const int * actnum, const double * mapaxes) - : m_minpvValue(0), + : GridDims(dims), + m_minpvValue(0), m_minpvMode(MinpvMode::ModeEnum::Inactive), m_pinch("PINCH"), m_pinchoutMode(PinchMode::ModeEnum::TOPBOT), m_multzMode(PinchMode::ModeEnum::TOP), - volume_cache(dims[0] * dims[1] * dims[2], -1) + volume_cache(dims[0] * dims[1] * dims[2], -1.0) { initCornerPointGrid( dims, coord , zcorn , actnum , mapaxes ); } @@ -79,8 +81,7 @@ namespace Opm { m_minpvMode(MinpvMode::ModeEnum::Inactive), m_pinch("PINCH"), m_pinchoutMode(PinchMode::ModeEnum::TOPBOT), - m_multzMode(PinchMode::ModeEnum::TOP), - volume_cache(dims[0] * dims[1] * dims[2], -1) + m_multzMode(PinchMode::ModeEnum::TOP) { ecl_grid_type * new_ptr = ecl_grid_load_case__( filename.c_str() , false ); if (new_ptr) @@ -91,6 +92,8 @@ namespace Opm { m_nx = ecl_grid_get_nx( c_ptr() ); m_ny = ecl_grid_get_ny( c_ptr() ); m_nz = ecl_grid_get_nz( c_ptr() ); + + volume_cache.resize(m_nx * m_ny * m_nz, -1.0); } @@ -102,7 +105,7 @@ namespace Opm { m_pinch("PINCH"), m_pinchoutMode(PinchMode::ModeEnum::TOPBOT), m_multzMode(PinchMode::ModeEnum::TOP), - volume_cache(dims[0] * dims[1] * dims[2], -1) + volume_cache(nx * ny * nz, -1.0), m_grid( ecl_grid_alloc_rectangular(nx, ny, nz, dx, dy, dz, NULL) ) { } @@ -114,7 +117,7 @@ namespace Opm { m_pinch( src.m_pinch ), m_pinchoutMode( src.m_pinchoutMode ), m_multzMode( src.m_multzMode ), - volume_cache(dims[0] * dims[1] * dims[2], -1) + volume_cache(src.volume_cache.size(), -1.0) { const int * actnum_data = (actnum.empty()) ? nullptr : actnum.data(); m_grid.reset( ecl_grid_alloc_processed_copy( src.c_ptr(), zcorn , actnum_data )); @@ -168,7 +171,7 @@ namespace Opm { m_pinch("PINCH"), m_pinchoutMode(PinchMode::ModeEnum::TOPBOT), m_multzMode(PinchMode::ModeEnum::TOP), - volume_cache(dims[0] * dims[1] * dims[2], -1) + volume_cache(m_nx * m_ny * m_nz, -1.0) { const std::array dims = getNXYZ(); @@ -733,24 +736,22 @@ namespace Opm { double EclipseGrid::getCellVolume(size_t globalIndex) const { assertGlobalIndex( globalIndex ); - if (volume_cache[global_index] < 0) { + if (volume_cache[globalIndex] < 0.0) { + // Calculate cell volume and put it in the cache. std::vector x(8,0); std::vector y(8,0); std::vector z(8,0); - - for (int i=0; i < 8; i++) - ecl_grid_gell_corner_xyz1(c_ptr(), static_cast(globalIndex), i, &x.data()[i], &y.data()[i], &z.data()[i]); - - - volume_cache[i] = calc_cell_volume(x,y,z); + for (int i=0; i < 8; i++) { + ecl_grid_get_cell_corner_xyz1(c_ptr(), static_cast(globalIndex), i, &x.data()[i], &y.data()[i], &z.data()[i]); + } + volume_cache[globalIndex] = calculateCellVol(x,y,z); } - return volume_cache[global_index]; + return volume_cache[globalIndex]; } double EclipseGrid::getCellVolume(size_t i , size_t j , size_t k) const { - assertIJK(i,j,k); - return ecl_grid_get_cell_volume3( c_ptr() , static_cast(i),static_cast(j),static_cast(k)); + return getCellVolume(getGlobalIndex(i, j, k)); } double EclipseGrid::getCellThicknes(size_t i , size_t j , size_t k) const { From 6eb363e8e13ed24cf8b4c3d58b9acbd02120dcba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Fri, 29 Jun 2018 14:11:09 +0200 Subject: [PATCH 3/5] Also use OPM cell volume calc in comparison program. --- src/opm/test_util/EclFilesComparator.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/opm/test_util/EclFilesComparator.cpp b/src/opm/test_util/EclFilesComparator.cpp index f85d9cde7..2984a22f5 100644 --- a/src/opm/test_util/EclFilesComparator.cpp +++ b/src/opm/test_util/EclFilesComparator.cpp @@ -18,6 +18,7 @@ #include #include +#include #include @@ -405,6 +406,20 @@ void RegressionTest::deviationsForCell(double val1, double val2, const std::stri +namespace { + double getCellVolume(const ecl_grid_type* ecl_grid, const int globalIndex) { + std::vector x(8, 0.0); + std::vector y(8, 0.0); + std::vector z(8, 0.0); + for (int i = 0; i < 8; i++) { + ecl_grid_get_cell_corner_xyz1(ecl_grid, globalIndex, i, &x.data()[i], &y.data()[i], &z.data()[i]); + } + return calculateCellVol(x,y,z); + } +} + + + void RegressionTest::gridCompare(const bool volumecheck) const { double absTolerance = getAbsTolerance(); double relTolerance = getRelTolerance(); @@ -442,8 +457,8 @@ void RegressionTest::gridCompare(const bool volumecheck) const { << (active1 ? "active" : "inactive") << " in first grid, but " << (active2 ? "active" : "inactive") << " in second grid."); } - const double cellVolume1 = ecl_grid_get_cell_volume1(ecl_grid1, cell); - const double cellVolume2 = ecl_grid_get_cell_volume1(ecl_grid2, cell); + const double cellVolume1 = getCellVolume(ecl_grid1, cell); + const double cellVolume2 = getCellVolume(ecl_grid2, cell); Deviation dev = calculateDeviations(cellVolume1, cellVolume2); if (dev.abs > absTolerance && dev.rel > relTolerance) { int i, j, k; @@ -580,8 +595,8 @@ void IntegrationTest::setCellVolumes() { << "\nThe number of active cells differ."); } for (unsigned int cell = 0; cell < globalGridCount1; ++cell) { - const double cellVolume1 = ecl_grid_get_cell_volume1(ecl_grid1, cell); - const double cellVolume2 = ecl_grid_get_cell_volume1(ecl_grid2, cell); + const double cellVolume1 = getCellVolume(ecl_grid1, cell); + const double cellVolume2 = getCellVolume(ecl_grid2, cell); Deviation dev = calculateDeviations(cellVolume1, cellVolume2); if (dev.abs > absTolerance && dev.rel > relTolerance) { int i, j, k; From 1e4e56538099b3ef8cf566c19774b1e1672ec72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Mon, 2 Jul 2018 00:08:16 +0200 Subject: [PATCH 4/5] Address review comment: do not call data() needlessly. --- src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp b/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp index d2a209091..5c1cdd43c 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -742,7 +742,7 @@ namespace Opm { std::vector y(8,0); std::vector z(8,0); for (int i=0; i < 8; i++) { - ecl_grid_get_cell_corner_xyz1(c_ptr(), static_cast(globalIndex), i, &x.data()[i], &y.data()[i], &z.data()[i]); + ecl_grid_get_cell_corner_xyz1(c_ptr(), static_cast(globalIndex), i, &x[i], &y[i], &z[i]); } volume_cache[globalIndex] = calculateCellVol(x,y,z); } From 1b8e1b3197109682116209e8d4fd1404be58e7a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Mon, 2 Jul 2018 00:08:36 +0200 Subject: [PATCH 5/5] Fix test failure by reinstating IJK check. --- src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp b/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp index 5c1cdd43c..1c727b130 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -751,6 +751,7 @@ namespace Opm { double EclipseGrid::getCellVolume(size_t i , size_t j , size_t k) const { + assertIJK(i,j,k); return getCellVolume(getGlobalIndex(i, j, k)); }