From 5641876d1ded8166e11132a8fbb99fdf61c9da8b Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Tue, 7 Jun 2016 08:40:16 +0200 Subject: [PATCH 1/4] Fix two phase EQUIL initialization --- opm/core/simulator/initStateEquil_impl.hpp | 50 ++++++++++++---------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/opm/core/simulator/initStateEquil_impl.hpp b/opm/core/simulator/initStateEquil_impl.hpp index b3d750c34..20f56c5a4 100644 --- a/opm/core/simulator/initStateEquil_impl.hpp +++ b/opm/core/simulator/initStateEquil_impl.hpp @@ -767,28 +767,34 @@ namespace Opm double sat[BlackoilPhases::MaxNumPhases]; double threshold_sat = 1.0e-6; - sat[waterpos] = smax[waterpos]; - sat[gaspos] = smax[gaspos]; - sat[oilpos] = 1.0 - sat[waterpos] - sat[gaspos]; - if (sw > smax[waterpos]-threshold_sat ) { - sat[waterpos] = smax[waterpos]; - props.capPress(1, sat, &cell, pc, 0); - phase_pressures[oilpos][local_index] = phase_pressures[waterpos][local_index] + pc[waterpos]; - } else if (sg > smax[gaspos]-threshold_sat) { - sat[gaspos] = smax[gaspos]; - props.capPress(1, sat, &cell, pc, 0); - phase_pressures[oilpos][local_index] = phase_pressures[gaspos][local_index] - pc[gaspos]; - } - if (sg < smin[gaspos]+threshold_sat) { - sat[gaspos] = smin[gaspos]; - props.capPress(1, sat, &cell, pc, 0); - phase_pressures[gaspos][local_index] = phase_pressures[oilpos][local_index] + pc[gaspos]; - } - if (sw < smin[waterpos]+threshold_sat) { - sat[waterpos] = smin[waterpos]; - props.capPress(1, sat, &cell, pc, 0); - phase_pressures[waterpos][local_index] = phase_pressures[oilpos][local_index] - pc[waterpos]; - } + sat[oilpos] = 1.0; + if (water) { + sat[waterpos] = smax[waterpos]; + sat[oilpos] -= sat[waterpos]; + } + if (gas) { + sat[gaspos] = smax[gaspos]; + sat[oilpos] -= sat[gaspos]; + } + if (water && sw > smax[waterpos]-threshold_sat ) { + sat[waterpos] = smax[waterpos]; + props.capPress(1, sat, &cell, pc, 0); + phase_pressures[oilpos][local_index] = phase_pressures[waterpos][local_index] + pc[waterpos]; + } else if (gas && sg > smax[gaspos]-threshold_sat) { + sat[gaspos] = smax[gaspos]; + props.capPress(1, sat, &cell, pc, 0); + phase_pressures[oilpos][local_index] = phase_pressures[gaspos][local_index] - pc[gaspos]; + } + if (gas && sg < smin[gaspos]+threshold_sat) { + sat[gaspos] = smin[gaspos]; + props.capPress(1, sat, &cell, pc, 0); + phase_pressures[gaspos][local_index] = phase_pressures[oilpos][local_index] + pc[gaspos]; + } + if (water && sw < smin[waterpos]+threshold_sat) { + sat[waterpos] = smin[waterpos]; + props.capPress(1, sat, &cell, pc, 0); + phase_pressures[waterpos][local_index] = phase_pressures[oilpos][local_index] - pc[waterpos]; + } } return phase_saturations; } From 3247aaa557a994932ba3cae72a912cb0c5b25da0 Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Wed, 8 Jun 2016 09:11:42 +0200 Subject: [PATCH 2/4] Fix reference pressure for oil-water problem In opm-material the wetting phase is the reference phase for two-phase problems i.e water for oil-water system, but for flow it is always oil. Add oil capillary pressure value to shift the reference phase to oil --- .../props/satfunc/SaturationPropsFromDeck.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/opm/core/props/satfunc/SaturationPropsFromDeck.cpp b/opm/core/props/satfunc/SaturationPropsFromDeck.cpp index db7ab6221..bbeae6296 100644 --- a/opm/core/props/satfunc/SaturationPropsFromDeck.cpp +++ b/opm/core/props/satfunc/SaturationPropsFromDeck.cpp @@ -139,6 +139,7 @@ namespace Opm assert(cells != 0); const int np = numPhases(); + if (dpcds) { ExplicitArraysSatDerivativesFluidState fluidState(phaseUsage_); typedef ExplicitArraysSatDerivativesFluidState::Evaluation Evaluation; @@ -153,10 +154,13 @@ namespace Opm // copy the values calculated using opm-material to the target arrays for (int pcPhaseIdx = 0; pcPhaseIdx < np; ++pcPhaseIdx) { double sign = (pcPhaseIdx == BlackoilPhases::Aqua)? -1.0 : 1.0; - pc[np*i + pcPhaseIdx] = sign*capillaryPressures[pcPhaseIdx].value; - + // in opm-material the wetting phase is the reference phase + // for two-phase problems i.e water for oil-water system, + // but for flow it is always oil. Add oil (liquid) capillary pressure value + // to shift the reference phase to oil + pc[np*i + pcPhaseIdx] = capillaryPressures[BlackoilPhases::Liquid].value + sign * capillaryPressures[pcPhaseIdx].value; for (int satPhaseIdx = 0; satPhaseIdx < np; ++satPhaseIdx) - dpcds[np*np*i + satPhaseIdx*np + pcPhaseIdx] = sign*capillaryPressures[pcPhaseIdx].derivatives[satPhaseIdx]; + dpcds[np*np*i + satPhaseIdx*np + pcPhaseIdx] = capillaryPressures[BlackoilPhases::Liquid].derivatives[satPhaseIdx] + sign * capillaryPressures[pcPhaseIdx].derivatives[satPhaseIdx]; } } } else { @@ -172,7 +176,11 @@ namespace Opm // copy the values calculated using opm-material to the target arrays for (int pcPhaseIdx = 0; pcPhaseIdx < np; ++pcPhaseIdx) { double sign = (pcPhaseIdx == BlackoilPhases::Aqua)? -1.0 : 1.0; - pc[np*i + pcPhaseIdx] = sign*capillaryPressures[pcPhaseIdx]; + // in opm-material the wetting phase is the reference phase + // for two-phase problems i.e water for oil-water system, + // but for flow it is always oil. Add oil (liquid) capillary pressure value + // to shift the reference phase to oil + pc[np*i + pcPhaseIdx] = capillaryPressures[BlackoilPhases::Liquid] + sign * capillaryPressures[pcPhaseIdx]; } } } From cc100a621783b0070c8c13f6ad6c6dfd5005df6e Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Mon, 20 Jun 2016 11:14:36 +0200 Subject: [PATCH 3/4] Fix bug for OIL-GAS case - Differentiate between active and canonical phase index --- .../props/satfunc/SaturationPropsFromDeck.cpp | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/opm/core/props/satfunc/SaturationPropsFromDeck.cpp b/opm/core/props/satfunc/SaturationPropsFromDeck.cpp index bbeae6296..b800ca1e8 100644 --- a/opm/core/props/satfunc/SaturationPropsFromDeck.cpp +++ b/opm/core/props/satfunc/SaturationPropsFromDeck.cpp @@ -136,7 +136,8 @@ namespace Opm double* pc, double* dpcds) const { - assert(cells != 0); + assert(cells != 0); + assert(phaseUsage_.phase_used[BlackoilPhases::Liquid]); const int np = numPhases(); @@ -152,15 +153,25 @@ namespace Opm MaterialLaw::capillaryPressures(capillaryPressures, params, fluidState); // copy the values calculated using opm-material to the target arrays - for (int pcPhaseIdx = 0; pcPhaseIdx < np; ++pcPhaseIdx) { - double sign = (pcPhaseIdx == BlackoilPhases::Aqua)? -1.0 : 1.0; + for (int canonicalPhaseIdx = 0; canonicalPhaseIdx < BlackoilPhases::MaxNumPhases; ++canonicalPhaseIdx) { + // skip unused phases + if ( ! phaseUsage_.phase_used[canonicalPhaseIdx]) + continue; + const int pcPhaseIdx = phaseUsage_.phase_pos[canonicalPhaseIdx]; + + double sign = (canonicalPhaseIdx == BlackoilPhases::Aqua)? -1.0 : 1.0; // in opm-material the wetting phase is the reference phase // for two-phase problems i.e water for oil-water system, // but for flow it is always oil. Add oil (liquid) capillary pressure value // to shift the reference phase to oil - pc[np*i + pcPhaseIdx] = capillaryPressures[BlackoilPhases::Liquid].value + sign * capillaryPressures[pcPhaseIdx].value; - for (int satPhaseIdx = 0; satPhaseIdx < np; ++satPhaseIdx) - dpcds[np*np*i + satPhaseIdx*np + pcPhaseIdx] = capillaryPressures[BlackoilPhases::Liquid].derivatives[satPhaseIdx] + sign * capillaryPressures[pcPhaseIdx].derivatives[satPhaseIdx]; + pc[np*i + pcPhaseIdx] = capillaryPressures[BlackoilPhases::Liquid].value + sign * capillaryPressures[canonicalPhaseIdx].value; + for (int canonicalSatPhaseIdx = 0; canonicalSatPhaseIdx < BlackoilPhases::MaxNumPhases; ++canonicalSatPhaseIdx) { + if ( ! phaseUsage_.phase_used[canonicalSatPhaseIdx]) + continue; + + const int satPhaseIdx = phaseUsage_.phase_pos[canonicalSatPhaseIdx]; + dpcds[np*np*i + satPhaseIdx*np + pcPhaseIdx] = capillaryPressures[BlackoilPhases::Liquid].derivatives[canonicalSatPhaseIdx] + sign * capillaryPressures[canonicalPhaseIdx].derivatives[canonicalSatPhaseIdx]; + } } } } else { @@ -174,13 +185,18 @@ namespace Opm MaterialLaw::capillaryPressures(capillaryPressures, params, fluidState); // copy the values calculated using opm-material to the target arrays - for (int pcPhaseIdx = 0; pcPhaseIdx < np; ++pcPhaseIdx) { - double sign = (pcPhaseIdx == BlackoilPhases::Aqua)? -1.0 : 1.0; + for (int canonicalPhaseIdx = 0; canonicalPhaseIdx < BlackoilPhases::MaxNumPhases; ++canonicalPhaseIdx) { + // skip unused phases + if ( ! phaseUsage_.phase_used[canonicalPhaseIdx]) + continue; + + const int pcPhaseIdx = phaseUsage_.phase_pos[canonicalPhaseIdx]; + double sign = (canonicalPhaseIdx == BlackoilPhases::Aqua)? -1.0 : 1.0; // in opm-material the wetting phase is the reference phase // for two-phase problems i.e water for oil-water system, // but for flow it is always oil. Add oil (liquid) capillary pressure value // to shift the reference phase to oil - pc[np*i + pcPhaseIdx] = capillaryPressures[BlackoilPhases::Liquid] + sign * capillaryPressures[pcPhaseIdx]; + pc[np*i + pcPhaseIdx] = capillaryPressures[BlackoilPhases::Liquid] + sign * capillaryPressures[canonicalPhaseIdx]; } } } From 1d7e4146ed1169445bccddf6dc7e48956a743f1f Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Fri, 24 Jun 2016 13:36:05 +0200 Subject: [PATCH 4/4] Fixing some nitpicks --- opm/core/props/satfunc/SaturationPropsFromDeck.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/opm/core/props/satfunc/SaturationPropsFromDeck.cpp b/opm/core/props/satfunc/SaturationPropsFromDeck.cpp index b800ca1e8..48b1feb38 100644 --- a/opm/core/props/satfunc/SaturationPropsFromDeck.cpp +++ b/opm/core/props/satfunc/SaturationPropsFromDeck.cpp @@ -155,11 +155,12 @@ namespace Opm // copy the values calculated using opm-material to the target arrays for (int canonicalPhaseIdx = 0; canonicalPhaseIdx < BlackoilPhases::MaxNumPhases; ++canonicalPhaseIdx) { // skip unused phases - if ( ! phaseUsage_.phase_used[canonicalPhaseIdx]) + if ( ! phaseUsage_.phase_used[canonicalPhaseIdx]) { continue; + } const int pcPhaseIdx = phaseUsage_.phase_pos[canonicalPhaseIdx]; - double sign = (canonicalPhaseIdx == BlackoilPhases::Aqua)? -1.0 : 1.0; + const double sign = (canonicalPhaseIdx == BlackoilPhases::Aqua)? -1.0 : 1.0; // in opm-material the wetting phase is the reference phase // for two-phase problems i.e water for oil-water system, // but for flow it is always oil. Add oil (liquid) capillary pressure value