From ad81cc6a3790aef427191cd0b6da9f5b409d6793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Wed, 22 Jan 2014 12:53:05 +0100 Subject: [PATCH 01/10] Initial version of segmented well model. This computes pressure differences with respect to the bottom-hole pressure for each well perforation, based on the well flows. It is explicit and not implicit, using the previous time step's flow rates to calculate the necessary densities. --- CMakeLists_files.cmake | 2 + opm/autodiff/SegmentedWellModel.cpp | 162 ++++++++++++++++++++++++++++ opm/autodiff/SegmentedWellModel.hpp | 55 ++++++++++ 3 files changed, 219 insertions(+) create mode 100644 opm/autodiff/SegmentedWellModel.cpp create mode 100644 opm/autodiff/SegmentedWellModel.hpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index a7b7a1b1a..cfbd1072e 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -30,6 +30,7 @@ list (APPEND MAIN_SOURCE_FILES opm/autodiff/BlackoilPropsAdInterface.cpp opm/autodiff/FullyImplicitBlackoilSolver.cpp opm/autodiff/ImpesTPFAAD.cpp + opm/autodiff/SegmentedWellModel.cpp opm/autodiff/SimulatorCompressibleAd.cpp opm/autodiff/SimulatorFullyImplicitBlackoil.cpp opm/autodiff/SimulatorIncompTwophaseAd.cpp @@ -82,6 +83,7 @@ list (APPEND PUBLIC_HEADER_FILES opm/autodiff/GeoProps.hpp opm/autodiff/ImpesTPFAAD.hpp opm/autodiff/FullyImplicitBlackoilSolver.hpp + opm/autodiff/SegmentedWellModel.hpp opm/autodiff/SimulatorCompressibleAd.hpp opm/autodiff/SimulatorFullyImplicitBlackoil.hpp opm/autodiff/SimulatorIncompTwophaseAd.hpp diff --git a/opm/autodiff/SegmentedWellModel.cpp b/opm/autodiff/SegmentedWellModel.cpp new file mode 100644 index 000000000..e0ce7dc51 --- /dev/null +++ b/opm/autodiff/SegmentedWellModel.cpp @@ -0,0 +1,162 @@ +/* + 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 . +*/ + +#include +#include +#include +#include +#include +#include +#include + +std::vector Opm::SegmentedWellModel::computeConnectionPressureDelta(const Wells& wells, + const WellState& wstate, + const PhaseUsage& phase_usage, + const std::vector& b_perf, + const std::vector& rsmax_perf, + const std::vector& rvmax_perf, + const std::vector& z_perf, + const std::vector& surf_dens, + const double gravity) +{ + // Verify that we have consistent input. + const int np = wells.number_of_phases; + const int nw = wells.number_of_wells; + const int nperf = wells.well_connpos[nw]; + if (wells.number_of_phases != phase_usage.num_phases) { + OPM_THROW(std::logic_error, "Inconsistent input: wells vs. phase_usage."); + } + if (surf_dens.size() != size_t(wells.number_of_phases)) { + OPM_THROW(std::logic_error, "Inconsistent input: surf_dens vs. phase_usage."); + } + if (nperf*np != int(wstate.perfRates().size())) { + OPM_THROW(std::logic_error, "Inconsistent input: wells vs. wstate."); + } + if (nperf*np != int(b_perf.size())) { + OPM_THROW(std::logic_error, "Inconsistent input: wells vs. b_perf."); + } + if (nperf != int(z_perf.size())) { + OPM_THROW(std::logic_error, "Inconsistent input: wells vs. z_perf."); + } + if ((!rsmax_perf.empty()) || (!rvmax_perf.empty())) { + // Need both oil and gas phases. + if (!phase_usage.phase_used[BlackoilPhases::Liquid]) { + OPM_THROW(std::logic_error, "Oil phase inactive, but non-empty rsmax_perf or rvmax_perf."); + } + if (!phase_usage.phase_used[BlackoilPhases::Vapour]) { + OPM_THROW(std::logic_error, "Gas phase inactive, but non-empty rsmax_perf or rvmax_perf."); + } + } + + // Algorithm: + + // We'll assume the perforations are given in order from top to + // bottom for each well. By top and bottom we do not necessarily + // mean in a geometric sense (depth), but in a topological sense: + // the 'top' perforation is nearest to the surface topologically. + // Our goal is to compute a pressure delta for each perforation. + + // 1. Compute the flow (in surface volume units for each + // component) exiting up the wellbore from each perforation, + // taking into account flow from lower in the well, and + // in/out-flow at each perforation. + std::vector q_out_perf(nperf*np); + for (int w = 0; w < nw; ++w) { + // Iterate over well perforations from bottom to top. + for (int perf = wells.well_connpos[w+1] - 1; perf >= wells.well_connpos[w]; --perf) { + for (int phase = 0; phase < np; ++phase) { + if (perf == wells.well_connpos[w+1]) { + // This is the bottom perforation. No flow from below. + q_out_perf[perf*np + phase] = 0.0; + } else { + // Set equal to flow from below. + q_out_perf[perf*np + phase] = q_out_perf[(perf+1)*np + phase]; + } + // Subtract outflow through perforation. + q_out_perf[perf*np + phase] -= wstate.perfRates()[perf*np + phase]; + } + } + } + + // 2. Compute the component mix at each perforation as the + // absolute values of the surface rates divided by their sum. + // Then compute volume ratios (formation factors) for each perforation. + // Finally compute densities for the segments associated with each perforation. + const int gaspos = phase_usage.phase_pos[BlackoilPhases::Vapour]; + const int oilpos = phase_usage.phase_pos[BlackoilPhases::Liquid]; + std::vector mix(np); + std::vector x(np); + std::vector dens(nperf); + for (int w = 0; w < nw; ++w) { + for (int perf = wells.well_connpos[w]; perf < wells.well_connpos[w+1]; ++perf) { + // Find component mix. + const double tot_surf_rate = std::accumulate(q_out_perf.begin() + np*perf, + q_out_perf.begin() + np*(perf+1), 0.0); + if (tot_surf_rate != 0.0) { + for (int phase = 0; phase < np; ++phase) { + mix[phase] = std::fabs(q_out_perf[perf*np + phase]/tot_surf_rate); + } + } else { + // No flow => use well specified fractions for mix. + std::copy(wells.comp_frac + w*np, wells.comp_frac + (w+1)*np, mix.begin()); + } + // Compute volume ratio. + x = mix; + double rs = 0.0; + double rv = 0.0; + if (!rsmax_perf.empty() && mix[oilpos] > 0.0) { + // Subtract gas in oil from gas mixture + rs = std::min(mix[gaspos]/mix[oilpos], rsmax_perf[perf]); + x[gaspos] = mix[gaspos] - mix[oilpos]*rs; + } + if (!rvmax_perf.empty() && mix[gaspos] > 0.0) { + // Subtract oil in gas from oil mixture + rv = std::min(mix[oilpos]/mix[gaspos], rvmax_perf[perf]); + x[oilpos] = mix[oilpos] - mix[gaspos]*rv; + } + double volrat = 0.0; + for (int phase = 0; phase < np; ++phase) { + volrat += x[phase] / (b_perf[perf*np + phase] * (1.0 - rs*rv)); + } + // Compute segment density. + dens[perf] = std::inner_product(surf_dens.begin(), surf_dens.end(), mix.begin(), 0.0) / volrat; + } + } + + // 3. Compute pressure differences between perforations. + // dp_perf will contain the pressure difference between a + // perforation and the one above it, except for the first + // perforation for each well, for which it will be the + // difference to the reference (bhp) depth. + std::vector dp_perf(nperf); + for (int w = 0; w < nw; ++w) { + for (int perf = wells.well_connpos[w]; perf < wells.well_connpos[w+1]; ++perf) { + const double z_above = perf == 0 ? wells.depth_ref[w] : z_perf[perf - 1]; + const double dz = z_perf[perf] - z_above; + dp_perf[perf] = dz * dens[perf] * gravity; + } + } + + // 4. Compute pressure differences to the reference point (bhp) by + // accumulating the already computed adjacent pressure + // differences, storing the result in dp_perf. + std::partial_sum(dp_perf.begin(), dp_perf.end(), dp_perf.begin()); + + return dp_perf; +} diff --git a/opm/autodiff/SegmentedWellModel.hpp b/opm/autodiff/SegmentedWellModel.hpp new file mode 100644 index 000000000..4aa1badfd --- /dev/null +++ b/opm/autodiff/SegmentedWellModel.hpp @@ -0,0 +1,55 @@ +/* + 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 . +*/ + +#ifndef OPM_SEGMENTEDWELLMODEL_HEADER_INCLUDED +#define OPM_SEGMENTEDWELLMODEL_HEADER_INCLUDED + +#include + +struct Wells; + +namespace Opm +{ + + class WellState; + class PhaseUsage; + + + /// A class giving a well model, by which we mean a way to compute + /// the pressure deltas of each perforation and the bottom-hole + /// pressure. This class contains an explicit model, that uses a + /// different density for each well segment, that is between each + /// pair of perforations. + class SegmentedWellModel + { + public: + static std::vector computeConnectionPressureDelta(const Wells& wells, + const WellState& wstate, + const PhaseUsage& phase_usage, + const std::vector& b_perf, + const std::vector& rsmax_perf, + const std::vector& rvmax_perf, + const std::vector& z_perf, + const std::vector& surf_dens, + const double gravity); + }; + +} // namespace Opm + +#endif // OPM_SEGMENTEDWELLMODEL_HEADER_INCLUDED From aa5d9d255b2c4a5da608f9bde4d0b51fdc4e3941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Wed, 22 Jan 2014 12:56:08 +0100 Subject: [PATCH 02/10] Added a test program for SegmentedWellModel. The only currently tested case is a simple water injector. --- CMakeLists_files.cmake | 1 + tests/test_segmentedwellmodel.cpp | 84 +++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/test_segmentedwellmodel.cpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index cfbd1072e..28dd5565a 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -46,6 +46,7 @@ list (APPEND TEST_SOURCE_FILES tests/test_span.cpp tests/test_syntax.cpp tests/test_scalar_mult.cpp + tests/test_segmentedwellmodel.cpp ) list (APPEND TEST_DATA_FILES diff --git a/tests/test_segmentedwellmodel.cpp b/tests/test_segmentedwellmodel.cpp new file mode 100644 index 000000000..fe5e0594d --- /dev/null +++ b/tests/test_segmentedwellmodel.cpp @@ -0,0 +1,84 @@ +/* + 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 . +*/ + + +#include + +#if HAVE_DYNAMIC_BOOST_TEST +#define BOOST_TEST_DYN_LINK +#endif + +#define BOOST_TEST_MODULE SegmentedWellModelTest + +#include +#include +#include +#include +#include + +#include + +#include + +using namespace Opm; + +BOOST_AUTO_TEST_CASE(TestPressureDeltas) +{ + // Simple water injector. + const int np = 3; + const int nperf = 4; + const double ref_depth = 1000.0; + const double comp_frac[np] = { 1.0, 0.0, 0.0 }; + const int cells[nperf] = { 0, 1, 2, 3 }; + const double WI[nperf] = { 1.0, 1.0, 1.0, 1.0 }; + const char *name = "INJECTOR"; + Wells* wells = create_wells(np, 1, nperf); + BOOST_REQUIRE(wells != NULL); + const int ok = add_well(INJECTOR, ref_depth, nperf, comp_frac, cells, WI, name, wells); + BOOST_REQUIRE(ok); + std::vector rates = { 1.0, 0.0, 0.0, + 1.0, 0.0, 0.0, + 1.5, 0.0, 0.0, + 1.5, 0.0, 0.0 }; + WellState wellstate; + wellstate.perfRates() = rates; + PhaseUsage pu; + pu.num_phases = 3; + pu.phase_used[0] = true; + pu.phase_used[1] = true; + pu.phase_used[2] = true; + pu.phase_pos[0] = 0; + pu.phase_pos[1] = 1; + pu.phase_pos[2] = 2; + const std::vector b_perf = { 2.0, 3.0, 100.0, + 2.0, 3.5, 110.0, + 2.0, 4.0, 120.0, + 2.0, 4.5, 130.0 }; + const std::vector rsmax_perf; + const std::vector rvmax_perf; + const std::vector z_perf = { 1100.0, 1200.0, 1300.0, 1400.0 }; + const std::vector surf_dens = { 1000.0, 800.0, 10.0 }; + const double gravity = Opm::unit::gravity; + const std::vector dp = SegmentedWellModel::computeConnectionPressureDelta(*wells, wellstate, pu, b_perf, rsmax_perf, rvmax_perf, z_perf, surf_dens, gravity); + const std::vector answer = { 2e5*gravity, 4e5*gravity, 6e5*gravity, 8e5*gravity }; + BOOST_REQUIRE_EQUAL(dp.size(), answer.size()); + for (size_t i = 0; i < dp.size(); ++i) { + BOOST_CHECK_CLOSE(dp[i], answer[i], 1e-8); + } +} From ac6209640b90f86a217c25bf339ede9a9a235408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Wed, 22 Jan 2014 13:55:22 +0100 Subject: [PATCH 03/10] Documented interface for SegmentedWellModel. --- opm/autodiff/SegmentedWellModel.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/opm/autodiff/SegmentedWellModel.hpp b/opm/autodiff/SegmentedWellModel.hpp index 4aa1badfd..06aefabc8 100644 --- a/opm/autodiff/SegmentedWellModel.hpp +++ b/opm/autodiff/SegmentedWellModel.hpp @@ -39,6 +39,17 @@ namespace Opm class SegmentedWellModel { public: + /// Compute pressure deltas. + /// Notation: N = number of perforations, P = number of phases. + /// \param[in] wells struct with static well info + /// \param[in] wstate dynamic well solution information, only perfRates() is used + /// \param[in] phase_usage specifies which phases are active and not + /// \param[in] b_perf inverse ('little b') formation volume factor, size NP, P values per perforation + /// \param[in] rsmax_perf saturation point for rs (gas in oil) at each perforation, size N + /// \param[in] rvmax_perf saturation point for rv (oil in gas) at each perforation, size N + /// \param[in] z_perf depth values for each perforation, size N + /// \param[in] surf_dens surface densities for active components, size P + /// \param[in] gravity gravity acceleration constant static std::vector computeConnectionPressureDelta(const Wells& wells, const WellState& wstate, const PhaseUsage& phase_usage, From 98371f660f33718f2d58263f357b31b0bcc2edca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Thu, 23 Jan 2014 12:40:54 +0100 Subject: [PATCH 04/10] Fix mixture calculation for volatile oil case. --- opm/autodiff/SegmentedWellModel.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/opm/autodiff/SegmentedWellModel.cpp b/opm/autodiff/SegmentedWellModel.cpp index e0ce7dc51..80d39df8e 100644 --- a/opm/autodiff/SegmentedWellModel.cpp +++ b/opm/autodiff/SegmentedWellModel.cpp @@ -121,18 +121,22 @@ std::vector Opm::SegmentedWellModel::computeConnectionPressureDelta(cons double rs = 0.0; double rv = 0.0; if (!rsmax_perf.empty() && mix[oilpos] > 0.0) { - // Subtract gas in oil from gas mixture rs = std::min(mix[gaspos]/mix[oilpos], rsmax_perf[perf]); - x[gaspos] = mix[gaspos] - mix[oilpos]*rs; } if (!rvmax_perf.empty() && mix[gaspos] > 0.0) { - // Subtract oil in gas from oil mixture rv = std::min(mix[oilpos]/mix[gaspos], rvmax_perf[perf]); - x[oilpos] = mix[oilpos] - mix[gaspos]*rv; + } + if (rs != 0.0) { + // Subtract gas in oil from gas mixture + x[gaspos] = (mix[gaspos] - mix[oilpos]*rs)/(1.0 - rs*rv); + } + if (rv != 0.0) { + // Subtract oil in gas from oil mixture + x[oilpos] = (mix[oilpos] - mix[gaspos]*rv)/(1.0 - rs*rv);; } double volrat = 0.0; for (int phase = 0; phase < np; ++phase) { - volrat += x[phase] / (b_perf[perf*np + phase] * (1.0 - rs*rv)); + volrat += x[phase] / b_perf[perf*np + phase]; } // Compute segment density. dens[perf] = std::inner_product(surf_dens.begin(), surf_dens.end(), mix.begin(), 0.0) / volrat; From a4b2044e1492adea32b3436560801b57057eee34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Thu, 23 Jan 2014 12:42:17 +0100 Subject: [PATCH 05/10] Modified test case to match MRST test case. --- tests/test_segmentedwellmodel.cpp | 52 ++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/tests/test_segmentedwellmodel.cpp b/tests/test_segmentedwellmodel.cpp index fe5e0594d..1edc92629 100644 --- a/tests/test_segmentedwellmodel.cpp +++ b/tests/test_segmentedwellmodel.cpp @@ -42,20 +42,28 @@ BOOST_AUTO_TEST_CASE(TestPressureDeltas) { // Simple water injector. const int np = 3; - const int nperf = 4; - const double ref_depth = 1000.0; - const double comp_frac[np] = { 1.0, 0.0, 0.0 }; - const int cells[nperf] = { 0, 1, 2, 3 }; - const double WI[nperf] = { 1.0, 1.0, 1.0, 1.0 }; - const char *name = "INJECTOR"; - Wells* wells = create_wells(np, 1, nperf); + const int nperf = 10; + const double ref_depth = 0.0; + const double comp_frac_w[np] = { 1.0, 0.0, 0.0 }; + const double comp_frac_o[np] = { 0.0, 1.0, 0.0 }; + const int cells[nperf/2] = { 0, 1, 2, 3, 4 }; + const double WI[nperf/2] = { 1.0, 1.0, 1.0, 1.0 }; + Wells* wells = create_wells(np, 2, nperf); BOOST_REQUIRE(wells != NULL); - const int ok = add_well(INJECTOR, ref_depth, nperf, comp_frac, cells, WI, name, wells); + int ok = add_well(INJECTOR, ref_depth, nperf/2, comp_frac_w, cells, WI, "INJ", wells); + BOOST_REQUIRE(ok); + ok = add_well(PRODUCER, ref_depth, nperf/2, comp_frac_o, cells, WI, "PROD", wells); BOOST_REQUIRE(ok); std::vector rates = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, - 1.5, 0.0, 0.0, - 1.5, 0.0, 0.0 }; + 1.0, 0.0, 0.0, + 1.0, 0.0, 0.0, + 1.0, 0.0, 0.0, + 1.0, 0.0, 0.0, + 1.0, 0.0, 0.0, + 1.0, 0.0, 0.0, + 1.0, 0.0, 0.0, + 1.0, 0.0, 0.0 }; WellState wellstate; wellstate.perfRates() = rates; PhaseUsage pu; @@ -66,18 +74,26 @@ BOOST_AUTO_TEST_CASE(TestPressureDeltas) pu.phase_pos[0] = 0; pu.phase_pos[1] = 1; pu.phase_pos[2] = 2; - const std::vector b_perf = { 2.0, 3.0, 100.0, - 2.0, 3.5, 110.0, - 2.0, 4.0, 120.0, - 2.0, 4.5, 130.0 }; - const std::vector rsmax_perf; - const std::vector rvmax_perf; - const std::vector z_perf = { 1100.0, 1200.0, 1300.0, 1400.0 }; + const std::vector b_perf = { 2.0, 3.0, 100, + 2.1, 3.3, 110, + 2.2, 3.6, 120, + 2.3, 4.0, 130, + 2.4, 4.5, 140, + 2.0, 3.0, 100, + 2.1, 3.3, 110, + 2.2, 3.6, 120, + 2.3, 4.0, 130, + 2.4, 4.5, 140 }; + const std::vector rsmax_perf = { 50, 50, 50, 50, 50, 50, 50, 50, 50, 50 }; + const std::vector rvmax_perf = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 }; + const std::vector z_perf = { 10, 30, 50, 70, 90, 10, 30, 50, 70, 90 }; const std::vector surf_dens = { 1000.0, 800.0, 10.0 }; const double gravity = Opm::unit::gravity; const std::vector dp = SegmentedWellModel::computeConnectionPressureDelta(*wells, wellstate, pu, b_perf, rsmax_perf, rvmax_perf, z_perf, surf_dens, gravity); - const std::vector answer = { 2e5*gravity, 4e5*gravity, 6e5*gravity, 8e5*gravity }; + const std::vector answer = { 20e3*gravity, 62e3*gravity, 106e3*gravity, 152e3*gravity, 200e3*gravity, + 20e3*gravity, 62e3*gravity, 106e3*gravity, 152e3*gravity, 200e3*gravity }; BOOST_REQUIRE_EQUAL(dp.size(), answer.size()); + // for (auto p : dp) { std::cout << p << std::endl; } for (size_t i = 0; i < dp.size(); ++i) { BOOST_CHECK_CLOSE(dp[i], answer[i], 1e-8); } From 5d386f2a4982d1c90ad159b532bb4183a4ad0823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Thu, 23 Jan 2014 12:42:57 +0100 Subject: [PATCH 06/10] Bugfixes in treatment of perforation depths and final accumulation. --- opm/autodiff/SegmentedWellModel.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/opm/autodiff/SegmentedWellModel.cpp b/opm/autodiff/SegmentedWellModel.cpp index 80d39df8e..4432ab99a 100644 --- a/opm/autodiff/SegmentedWellModel.cpp +++ b/opm/autodiff/SegmentedWellModel.cpp @@ -25,6 +25,7 @@ #include #include + std::vector Opm::SegmentedWellModel::computeConnectionPressureDelta(const Wells& wells, const WellState& wstate, const PhaseUsage& phase_usage, @@ -151,7 +152,7 @@ std::vector Opm::SegmentedWellModel::computeConnectionPressureDelta(cons std::vector dp_perf(nperf); for (int w = 0; w < nw; ++w) { for (int perf = wells.well_connpos[w]; perf < wells.well_connpos[w+1]; ++perf) { - const double z_above = perf == 0 ? wells.depth_ref[w] : z_perf[perf - 1]; + const double z_above = perf == wells.well_connpos[w] ? wells.depth_ref[w] : z_perf[perf - 1]; const double dz = z_perf[perf] - z_above; dp_perf[perf] = dz * dens[perf] * gravity; } @@ -160,7 +161,12 @@ std::vector Opm::SegmentedWellModel::computeConnectionPressureDelta(cons // 4. Compute pressure differences to the reference point (bhp) by // accumulating the already computed adjacent pressure // differences, storing the result in dp_perf. - std::partial_sum(dp_perf.begin(), dp_perf.end(), dp_perf.begin()); + // This accumulation must be done per well. + for (int w = 0; w < nw; ++w) { + const auto beg = dp_perf.begin() + wells.well_connpos[w]; + const auto end = dp_perf.begin() + wells.well_connpos[w + 1]; + std::partial_sum(beg, end, beg); + } return dp_perf; } From f9ea03fe67f09d92c94419dd47f8feaa14604e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Fri, 24 Jan 2014 15:54:01 +0100 Subject: [PATCH 07/10] Renamed SegmentedWellModel->WellDensitySegmented. --- CMakeLists_files.cmake | 6 +++--- ...WellModel.cpp => WellDensitySegmented.cpp} | 20 +++++++++---------- ...WellModel.hpp => WellDensitySegmented.hpp} | 8 ++++---- ...odel.cpp => test_welldensitysegmented.cpp} | 6 +++--- 4 files changed, 20 insertions(+), 20 deletions(-) rename opm/autodiff/{SegmentedWellModel.cpp => WellDensitySegmented.cpp} (93%) rename opm/autodiff/{SegmentedWellModel.hpp => WellDensitySegmented.hpp} (94%) rename tests/{test_segmentedwellmodel.cpp => test_welldensitysegmented.cpp} (93%) diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 28dd5565a..cba690427 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -30,12 +30,12 @@ list (APPEND MAIN_SOURCE_FILES opm/autodiff/BlackoilPropsAdInterface.cpp opm/autodiff/FullyImplicitBlackoilSolver.cpp opm/autodiff/ImpesTPFAAD.cpp - opm/autodiff/SegmentedWellModel.cpp opm/autodiff/SimulatorCompressibleAd.cpp opm/autodiff/SimulatorFullyImplicitBlackoil.cpp opm/autodiff/SimulatorIncompTwophaseAd.cpp opm/autodiff/TransportSolverTwophaseAd.cpp opm/autodiff/BlackoilPropsAdFromDeck.cpp + opm/autodiff/WellDensitySegmented.cpp ) # originally generated with the command: @@ -46,7 +46,7 @@ list (APPEND TEST_SOURCE_FILES tests/test_span.cpp tests/test_syntax.cpp tests/test_scalar_mult.cpp - tests/test_segmentedwellmodel.cpp + tests/test_welldensitysegmented.cpp ) list (APPEND TEST_DATA_FILES @@ -84,9 +84,9 @@ list (APPEND PUBLIC_HEADER_FILES opm/autodiff/GeoProps.hpp opm/autodiff/ImpesTPFAAD.hpp opm/autodiff/FullyImplicitBlackoilSolver.hpp - opm/autodiff/SegmentedWellModel.hpp opm/autodiff/SimulatorCompressibleAd.hpp opm/autodiff/SimulatorFullyImplicitBlackoil.hpp opm/autodiff/SimulatorIncompTwophaseAd.hpp opm/autodiff/TransportSolverTwophaseAd.hpp + opm/autodiff/WellDensitySegmented.hpp ) diff --git a/opm/autodiff/SegmentedWellModel.cpp b/opm/autodiff/WellDensitySegmented.cpp similarity index 93% rename from opm/autodiff/SegmentedWellModel.cpp rename to opm/autodiff/WellDensitySegmented.cpp index 4432ab99a..f033cd1b8 100644 --- a/opm/autodiff/SegmentedWellModel.cpp +++ b/opm/autodiff/WellDensitySegmented.cpp @@ -17,7 +17,7 @@ along with OPM. If not, see . */ -#include +#include #include #include #include @@ -26,15 +26,15 @@ #include -std::vector Opm::SegmentedWellModel::computeConnectionPressureDelta(const Wells& wells, - const WellState& wstate, - const PhaseUsage& phase_usage, - const std::vector& b_perf, - const std::vector& rsmax_perf, - const std::vector& rvmax_perf, - const std::vector& z_perf, - const std::vector& surf_dens, - const double gravity) +std::vector Opm::WellDensitySegmented::computeConnectionPressureDelta(const Wells& wells, + const WellState& wstate, + const PhaseUsage& phase_usage, + const std::vector& b_perf, + const std::vector& rsmax_perf, + const std::vector& rvmax_perf, + const std::vector& z_perf, + const std::vector& surf_dens, + const double gravity) { // Verify that we have consistent input. const int np = wells.number_of_phases; diff --git a/opm/autodiff/SegmentedWellModel.hpp b/opm/autodiff/WellDensitySegmented.hpp similarity index 94% rename from opm/autodiff/SegmentedWellModel.hpp rename to opm/autodiff/WellDensitySegmented.hpp index 06aefabc8..228262311 100644 --- a/opm/autodiff/SegmentedWellModel.hpp +++ b/opm/autodiff/WellDensitySegmented.hpp @@ -17,8 +17,8 @@ along with OPM. If not, see . */ -#ifndef OPM_SEGMENTEDWELLMODEL_HEADER_INCLUDED -#define OPM_SEGMENTEDWELLMODEL_HEADER_INCLUDED +#ifndef OPM_WELLDENSITYSEGMENTED_HEADER_INCLUDED +#define OPM_WELLDENSITYSEGMENTED_HEADER_INCLUDED #include @@ -36,7 +36,7 @@ namespace Opm /// pressure. This class contains an explicit model, that uses a /// different density for each well segment, that is between each /// pair of perforations. - class SegmentedWellModel + class WellDensitySegmented { public: /// Compute pressure deltas. @@ -63,4 +63,4 @@ namespace Opm } // namespace Opm -#endif // OPM_SEGMENTEDWELLMODEL_HEADER_INCLUDED +#endif // OPM_WELLDENSITYSEGMENTED_HEADER_INCLUDED diff --git a/tests/test_segmentedwellmodel.cpp b/tests/test_welldensitysegmented.cpp similarity index 93% rename from tests/test_segmentedwellmodel.cpp rename to tests/test_welldensitysegmented.cpp index 1edc92629..158d7f74a 100644 --- a/tests/test_segmentedwellmodel.cpp +++ b/tests/test_welldensitysegmented.cpp @@ -24,9 +24,9 @@ #define BOOST_TEST_DYN_LINK #endif -#define BOOST_TEST_MODULE SegmentedWellModelTest +#define BOOST_TEST_MODULE WellDensitySegmentedTest -#include +#include #include #include #include @@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(TestPressureDeltas) const std::vector z_perf = { 10, 30, 50, 70, 90, 10, 30, 50, 70, 90 }; const std::vector surf_dens = { 1000.0, 800.0, 10.0 }; const double gravity = Opm::unit::gravity; - const std::vector dp = SegmentedWellModel::computeConnectionPressureDelta(*wells, wellstate, pu, b_perf, rsmax_perf, rvmax_perf, z_perf, surf_dens, gravity); + const std::vector dp = WellDensitySegmented::computeConnectionPressureDelta(*wells, wellstate, pu, b_perf, rsmax_perf, rvmax_perf, z_perf, surf_dens, gravity); const std::vector answer = { 20e3*gravity, 62e3*gravity, 106e3*gravity, 152e3*gravity, 200e3*gravity, 20e3*gravity, 62e3*gravity, 106e3*gravity, 152e3*gravity, 200e3*gravity }; BOOST_REQUIRE_EQUAL(dp.size(), answer.size()); From 924080d8dca5c1aa15579699a7511ec69b7127bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Mon, 27 Jan 2014 08:32:24 +0100 Subject: [PATCH 08/10] Proper memorymanagement in test program. --- tests/test_welldensitysegmented.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_welldensitysegmented.cpp b/tests/test_welldensitysegmented.cpp index 158d7f74a..b5ece7608 100644 --- a/tests/test_welldensitysegmented.cpp +++ b/tests/test_welldensitysegmented.cpp @@ -35,6 +35,7 @@ #include #include +#include using namespace Opm; @@ -48,11 +49,11 @@ BOOST_AUTO_TEST_CASE(TestPressureDeltas) const double comp_frac_o[np] = { 0.0, 1.0, 0.0 }; const int cells[nperf/2] = { 0, 1, 2, 3, 4 }; const double WI[nperf/2] = { 1.0, 1.0, 1.0, 1.0 }; - Wells* wells = create_wells(np, 2, nperf); - BOOST_REQUIRE(wells != NULL); - int ok = add_well(INJECTOR, ref_depth, nperf/2, comp_frac_w, cells, WI, "INJ", wells); + std::shared_ptr wells(create_wells(np, 2, nperf), destroy_wells); + BOOST_REQUIRE(wells); + int ok = add_well(INJECTOR, ref_depth, nperf/2, comp_frac_w, cells, WI, "INJ", wells.get()); BOOST_REQUIRE(ok); - ok = add_well(PRODUCER, ref_depth, nperf/2, comp_frac_o, cells, WI, "PROD", wells); + ok = add_well(PRODUCER, ref_depth, nperf/2, comp_frac_o, cells, WI, "PROD", wells.get()); BOOST_REQUIRE(ok); std::vector rates = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, From 38a48dd14979f4552a73fc952abf5a01cc53b213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Mon, 27 Jan 2014 10:42:17 +0100 Subject: [PATCH 09/10] Fix indexing error in if-test. --- opm/autodiff/WellDensitySegmented.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/autodiff/WellDensitySegmented.cpp b/opm/autodiff/WellDensitySegmented.cpp index f033cd1b8..5ba38e87b 100644 --- a/opm/autodiff/WellDensitySegmented.cpp +++ b/opm/autodiff/WellDensitySegmented.cpp @@ -82,7 +82,7 @@ std::vector Opm::WellDensitySegmented::computeConnectionPressureDelta(co // Iterate over well perforations from bottom to top. for (int perf = wells.well_connpos[w+1] - 1; perf >= wells.well_connpos[w]; --perf) { for (int phase = 0; phase < np; ++phase) { - if (perf == wells.well_connpos[w+1]) { + if (perf == wells.well_connpos[w+1] - 1) { // This is the bottom perforation. No flow from below. q_out_perf[perf*np + phase] = 0.0; } else { From d5ebe3c685d9a36a7602d96be233bf77a1883b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Mon, 27 Jan 2014 10:42:35 +0100 Subject: [PATCH 10/10] Use correct number of items in initialiser. --- tests/test_welldensitysegmented.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_welldensitysegmented.cpp b/tests/test_welldensitysegmented.cpp index b5ece7608..a845c0fde 100644 --- a/tests/test_welldensitysegmented.cpp +++ b/tests/test_welldensitysegmented.cpp @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(TestPressureDeltas) const double comp_frac_w[np] = { 1.0, 0.0, 0.0 }; const double comp_frac_o[np] = { 0.0, 1.0, 0.0 }; const int cells[nperf/2] = { 0, 1, 2, 3, 4 }; - const double WI[nperf/2] = { 1.0, 1.0, 1.0, 1.0 }; + const double WI[nperf/2] = { 1.0, 1.0, 1.0, 1.0, 1.0 }; std::shared_ptr wells(create_wells(np, 2, nperf), destroy_wells); BOOST_REQUIRE(wells); int ok = add_well(INJECTOR, ref_depth, nperf/2, comp_frac_w, cells, WI, "INJ", wells.get());