From 66bb1fae8f745c014ad6349e55376d6ce8f0f491 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Fri, 10 Oct 2014 16:21:29 +0800 Subject: [PATCH 1/3] phaseIdx in this for statement is actual active phase index, should not active once again. --- .../FullyImplicitBlackoilSolver_impl.hpp | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp b/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp index a72fc4fc2..83347c67b 100644 --- a/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp +++ b/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp @@ -1740,18 +1740,16 @@ namespace { int oscillatePhase = 0; for (int phaseIdx= 0; phaseIdx < fluid_.numPhases(); ++ phaseIdx){ - if (active_[phaseIdx]) { - double relChange1 = std::fabs((residual_history[it][phaseIdx] - residual_history[it - 2][phaseIdx]) / - residual_history[it][phaseIdx]); - double relChange2 = std::fabs((residual_history[it][phaseIdx] - residual_history[it - 1][phaseIdx]) / - residual_history[it][phaseIdx]); - oscillatePhase += (relChange1 < relaxRelTol) && (relChange2 > relaxRelTol); + double relChange1 = std::fabs((residual_history[it][phaseIdx] - residual_history[it - 2][phaseIdx]) / + residual_history[it][phaseIdx]); + double relChange2 = std::fabs((residual_history[it][phaseIdx] - residual_history[it - 1][phaseIdx]) / + residual_history[it][phaseIdx]); + oscillatePhase += (relChange1 < relaxRelTol) && (relChange2 > relaxRelTol); - double relChange3 = std::fabs((residual_history[it - 1][phaseIdx] - residual_history[it - 2][phaseIdx]) / - residual_history[it - 2][phaseIdx]); - if (relChange3 > 1.e-3) { - stagnate = false; - } + double relChange3 = std::fabs((residual_history[it - 1][phaseIdx] - residual_history[it - 2][phaseIdx]) / + residual_history[it - 2][phaseIdx]); + if (relChange3 > 1.e-3) { + stagnate = false; } } From 5b28b380564df070b5c1b63697a612df6cf948cd Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Fri, 10 Oct 2014 17:01:05 +0800 Subject: [PATCH 2/3] make the for statement more readable. --- .../FullyImplicitBlackoilSolver_impl.hpp | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp b/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp index 83347c67b..32c1d4a81 100644 --- a/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp +++ b/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp @@ -1736,21 +1736,17 @@ namespace { return; } - stagnate = true; int oscillatePhase = 0; + const std::vector& F0 = residual_history[it]; + const std::vector& F1 = residual_history[it - 1]; + const std::vector& F2 = residual_history[it - 2]; + for (int p= 0; p < fluid_.numPhases(); ++p){ + const double d1 = std::abs((F0[p] - F2[p]) / F0[p]); + const double d2 = std::abs((F0[p] - F1[p]) / F0[p]); - for (int phaseIdx= 0; phaseIdx < fluid_.numPhases(); ++ phaseIdx){ - double relChange1 = std::fabs((residual_history[it][phaseIdx] - residual_history[it - 2][phaseIdx]) / - residual_history[it][phaseIdx]); - double relChange2 = std::fabs((residual_history[it][phaseIdx] - residual_history[it - 1][phaseIdx]) / - residual_history[it][phaseIdx]); - oscillatePhase += (relChange1 < relaxRelTol) && (relChange2 > relaxRelTol); + oscillatePhase += (d1 < relaxRelTol) && (relaxRelTol < d2); - double relChange3 = std::fabs((residual_history[it - 1][phaseIdx] - residual_history[it - 2][phaseIdx]) / - residual_history[it - 2][phaseIdx]); - if (relChange3 > 1.e-3) { - stagnate = false; - } + stagnate = ! (std::abs((F1[p] - F2[p]) / F2[p]) > 1.0e-3); } oscillate = (oscillatePhase > 1); From b183fdfa6dc9794c561db07be3ffcfae035fc422 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Sat, 11 Oct 2014 13:46:24 +0800 Subject: [PATCH 3/3] if all the phase are stagnate then stagnate will be true. --- opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp b/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp index 32c1d4a81..04bc8b6b0 100644 --- a/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp +++ b/opm/autodiff/FullyImplicitBlackoilSolver_impl.hpp @@ -1736,6 +1736,7 @@ namespace { return; } + stagnate = true; int oscillatePhase = 0; const std::vector& F0 = residual_history[it]; const std::vector& F1 = residual_history[it - 1]; @@ -1746,7 +1747,9 @@ namespace { oscillatePhase += (d1 < relaxRelTol) && (relaxRelTol < d2); - stagnate = ! (std::abs((F1[p] - F2[p]) / F2[p]) > 1.0e-3); + // Process is 'stagnate' unless at least one phase + // exhibits significant residual change. + stagnate = (stagnate && !(std::abs((F1[p] - F2[p]) / F2[p]) > 1.0e-3)); } oscillate = (oscillatePhase > 1);