mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Use free function for multi-phase upwinding.
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include <opm/autodiff/WellStateFullyImplicitBlackoil.hpp>
|
#include <opm/autodiff/WellStateFullyImplicitBlackoil.hpp>
|
||||||
#include <opm/autodiff/BlackoilModelParameters.hpp>
|
#include <opm/autodiff/BlackoilModelParameters.hpp>
|
||||||
#include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>
|
#include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>
|
||||||
|
#include <opm/autodiff/multiPhaseUpwind.hpp>
|
||||||
|
|
||||||
namespace Opm {
|
namespace Opm {
|
||||||
|
|
||||||
@@ -401,58 +402,22 @@ namespace Opm {
|
|||||||
Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> multiPhaseUpwind(const std::vector<ADB>& head_diff,
|
Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> multiPhaseUpwind(const std::vector<ADB>& head_diff,
|
||||||
const V& transmissibility)
|
const V& transmissibility)
|
||||||
{
|
{
|
||||||
// Based on the paper "Upstream Differencing for Multiphase Flow in Reservoir Simulation",
|
assert(numPhases() == 3);
|
||||||
// by Yann Brenier and Jérôme Jaffré,
|
|
||||||
// SIAM J. Numer. Anal., 28(3), 685–696.
|
|
||||||
// DOI:10.1137/0728036
|
|
||||||
|
|
||||||
// Using the data members:
|
|
||||||
// total_flux_
|
|
||||||
// sd_.rq[].mob
|
|
||||||
|
|
||||||
// Notation based on paper cited above.
|
|
||||||
const int num_connections = head_diff[0].size();
|
const int num_connections = head_diff[0].size();
|
||||||
Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> upwind(num_connections, numPhases());
|
Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> upwind(num_connections, numPhases());
|
||||||
using ValueAndIndex = std::pair<double, int>;
|
|
||||||
const int num_phases = numPhases();
|
|
||||||
std::vector<ValueAndIndex> g(num_phases);
|
|
||||||
std::vector<double> theta(num_phases);
|
|
||||||
for (int conn = 0; conn < num_connections; ++conn) {
|
for (int conn = 0; conn < num_connections; ++conn) {
|
||||||
const double q = total_flux_[conn];
|
const double q = total_flux_[conn];
|
||||||
const double t = transmissibility[conn];
|
const double t = transmissibility[conn];
|
||||||
const int a = ops_.connection_cells(conn, 0); // first cell of connection
|
const int a = ops_.connection_cells(conn, 0); // first cell of connection
|
||||||
const int b = ops_.connection_cells(conn, 1); // second cell of connection
|
const int b = ops_.connection_cells(conn, 1); // second cell of connection
|
||||||
|
auto up = connectionMultiPhaseUpwind(
|
||||||
// Get and sort the g values (also called "weights" in the paper) for this connection.
|
{{ head_diff[0].value()[conn], head_diff[1].value()[conn], head_diff[2].value()[conn] }},
|
||||||
for (int phase_idx = 0; phase_idx < num_phases; ++phase_idx) {
|
{{ sd_.rq[0].mob.value()[a], sd_.rq[1].mob.value()[a], sd_.rq[2].mob.value()[a]}},
|
||||||
g[phase_idx] = ValueAndIndex(head_diff[phase_idx].value()[conn], phase_idx);
|
{{ sd_.rq[0].mob.value()[b], sd_.rq[1].mob.value()[b], sd_.rq[2].mob.value()[b]}},
|
||||||
}
|
t,
|
||||||
std::sort(g.begin(), g.end());
|
q);
|
||||||
|
for (int ii = 0; ii < numPhases(); ++ii) {
|
||||||
// Compute theta and r.
|
upwind(conn, ii) = up[ii];
|
||||||
// Paper notation: subscript l -> ell (for read/searchability)
|
|
||||||
// Note that since we index phases from 0, r is one less than in the paper.
|
|
||||||
int r = -1;
|
|
||||||
for (int ell = 0; ell < num_phases; ++ell) {
|
|
||||||
theta[ell] = q;
|
|
||||||
for (int j = 0; j < num_phases; ++j) {
|
|
||||||
if (j < ell) {
|
|
||||||
theta[ell] += t * (g[ell].first - g[j].first) * sd_.rq[g[j].second].mob.value()[b];
|
|
||||||
}
|
|
||||||
if (j > ell) {
|
|
||||||
theta[ell] += t * (g[ell].first - g[j].first) * sd_.rq[g[j].second].mob.value()[a];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (theta[ell] <= 0.0) {
|
|
||||||
r = ell;
|
|
||||||
} else {
|
|
||||||
break; // r is correct, no need to continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int ell = 0; ell < num_phases; ++ell) {
|
|
||||||
const int phase_idx = g[ell].second;
|
|
||||||
upwind(conn, phase_idx) = ell > r ? 1.0 : -1.0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return upwind;
|
return upwind;
|
||||||
|
|||||||
Reference in New Issue
Block a user