New class MinpvProcessor, and test.

This commit is contained in:
Atgeirr Flø Rasmussen
2014-08-25 15:20:01 +02:00
parent c6c66c58c6
commit f74a0bb3e6
3 changed files with 207 additions and 0 deletions

View File

@@ -180,6 +180,7 @@ list (APPEND TEST_SOURCE_FILES
tests/test_wellsgroup.cpp
tests/test_wellcollection.cpp
tests/test_timer.cpp
tests/test_minpvprocessor.cpp
)
# originally generated with the command:
@@ -248,6 +249,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/core/grid/FaceQuadrature.hpp
opm/core/grid/GridHelpers.hpp
opm/core/grid/GridManager.hpp
opm/core/grid/MinpvProcessor.hpp
opm/core/grid/cart_grid.h
opm/core/grid/cornerpoint_grid.h
opm/core/grid/cpgpreprocess/facetopology.h

View File

@@ -0,0 +1,136 @@
/*
Copyright 2014 SINTEF ICT, Applied Mathematics.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_MINPVPROCESSOR_HEADER_INCLUDED
#define OPM_MINPVPROCESSOR_HEADER_INCLUDED
#include <opm/core/utility/ErrorMacros.hpp>
#include <array>
namespace Opm
{
class MinpvProcessor
{
public:
MinpvProcessor(const int nx, const int ny, const int nz);
void process(const std::vector<double>& pv, const double minpv, double* zcorn);
private:
std::array<double, 8> getCellZcorn(const int i, const int j, const int k, const double* z);
void setCellZcorn(const int i, const int j, const int k, const std::array<double, 8>& cellz, double* z);
std::array<int, 3> dims_;
std::array<int, 3> delta_;
};
MinpvProcessor::MinpvProcessor(const int nx, const int ny, const int nz)
{
// Not doing init-list init since bracket-init not available
// for all compilers we support (gcc 4.4).
dims_ = {{ nx, ny, nz }};
delta_ = {{ 1, 2*nx, 4*nx*ny }};
}
void MinpvProcessor::process(const std::vector<double>& pv, const double minpv, double* zcorn)
{
// Algorithm:
// 1. Process each column of cells (with same i and j
// coordinates) from top (low k) to bottom (high k).
// 2. For each cell 'c' visited, check if its pore volume
// pv[c] is less than minpv.
// 3. If below the minpv threshold, move the lower four
// zcorn associated with the cell c to coincide with
// the upper four (so it becomes degenerate). Also move
// the higher four zcorn associated with the cell below
// to these values (so it gains the deleted volume).
// Check for sane input sizes.
const size_t log_size = dims_[0] * dims_[1] * dims_[2];
if (pv.size() != log_size) {
OPM_THROW(std::runtime_error, "Wrong size of PORV input, must have one element per logical cartesian cell.");
}
// Main loop.
for (int ii = 0; ii < dims_[0]; ++ii) {
for (int jj = 0; jj < dims_[1]; ++jj) {
for (int kk = 0; kk < dims_[2]; ++kk) {
const int c = ii + jj*dims_[0] + kk*dims_[0]*dims_[1];
if (pv[c] < minpv) {
// Move deeper (higher k) coordinates to lower k coordinates.
std::array<double, 8> cz = getCellZcorn(ii, jj, kk, zcorn);
for (int count = 0; count < 4; ++count) {
cz[count + 4] = cz[count];
}
setCellZcorn(ii, jj, kk, cz, const_cast<double*>(zcorn));
// Check if there is a cell below.
if (kk < dims_[2] - 1) {
// Set lower k coordinates of cell below to upper cells's coordinates.
std::array<double, 8> cz_below = getCellZcorn(ii, jj, kk + 1, zcorn);
for (int count = 0; count < 4; ++count) {
cz_below[count] = cz[count];
}
setCellZcorn(ii, jj, kk + 1, cz_below, const_cast<double*>(zcorn));
}
}
}
}
}
}
// Returns the eight z-values associated with a given cell.
// The ordering is such that i runs fastest. That is, with
// L = low and H = high:
// {LLL, HLL, LHL, HHL, LLH, HLH, LHH, HHH }.
std::array<double, 8> MinpvProcessor::getCellZcorn(const int i, const int j, const int k, const double* z)
{
const int ix = 2*(i*delta_[0] + j*delta_[1] + k*delta_[2]);
std::array<int, 8> ixs = {{ ix, ix + delta_[0],
ix + delta_[1], ix + delta_[1] + delta_[0],
ix + delta_[2], ix + delta_[2] + delta_[0],
ix + delta_[2] + delta_[1], ix + delta_[2] + delta_[1] + delta_[0] }};
std::array<double, 8> cellz;
for (int count = 0; count < 8; ++count) {
cellz[count] = z[ixs[count]];
}
return cellz;
}
void MinpvProcessor::setCellZcorn(const int i, const int j, const int k, const std::array<double, 8>& cellz, double* z)
{
const int ix = 2*(i*delta_[0] + j*delta_[1] + k*delta_[2]);
std::array<int, 8> ixs = {{ ix, ix + delta_[0],
ix + delta_[1], ix + delta_[1] + delta_[0],
ix + delta_[2], ix + delta_[2] + delta_[0],
ix + delta_[2] + delta_[1], ix + delta_[2] + delta_[1] + delta_[0] }};
for (int count = 0; count < 8; ++count) {
z[ixs[count]] = cellz[count];
}
}
} // namespace Opm
#endif // OPM_MINPVPROCESSOR_HEADER_INCLUDED

View File

@@ -0,0 +1,69 @@
/*
Copyright 2014 SINTEF ICT, Applied Mathematics.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#if HAVE_DYNAMIC_BOOST_TEST
#define BOOST_TEST_DYN_LINK
#endif
#define NVERBOSE // to suppress our messages when throwing
#define BOOST_TEST_MODULE MinpvProcessorTest
#include <boost/test/unit_test.hpp>
#include <opm/core/grid/MinpvProcessor.hpp>
BOOST_AUTO_TEST_CASE(Processing)
{
std::vector<double> zcorn = { 0, 0, 0, 0,
1, 1, 1, 1,
1, 1, 1, 1,
3, 3, 3, 3,
3, 3, 3, 3,
6, 6, 6, 6 };
std::vector<double> zcorn2after = { 0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
3, 3, 3, 3,
3, 3, 3, 3,
6, 6, 6, 6 };
std::vector<double> zcorn3after = { 0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
6, 6, 6, 6 };
std::vector<double> pv = { 1, 2, 3 };
Opm::MinpvProcessor mp1(1, 1, 3);
auto z1 = zcorn;
mp1.process(pv, 0.5, z1.data());
BOOST_CHECK_EQUAL_COLLECTIONS(z1.begin(), z1.end(), zcorn.begin(), zcorn.end());
Opm::MinpvProcessor mp2(1, 1, 3);
auto z2 = zcorn;
mp2.process(pv, 1.5, z2.data());
BOOST_CHECK_EQUAL_COLLECTIONS(z2.begin(), z2.end(), zcorn2after.begin(), zcorn2after.end());
Opm::MinpvProcessor mp3(1, 1, 3);
auto z3 = zcorn;
mp3.process(pv, 2.5, z3.data());
BOOST_CHECK_EQUAL_COLLECTIONS(z3.begin(), z3.end(), zcorn3after.begin(), zcorn3after.end());
}