2012-02-26 14:05:19 -06:00
|
|
|
/*
|
|
|
|
Copyright 2012 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 <opm/core/utility/miscUtilities.hpp>
|
2012-03-14 06:47:01 -05:00
|
|
|
#include <opm/core/utility/Units.hpp>
|
2012-03-14 03:51:08 -05:00
|
|
|
#include <opm/core/grid.h>
|
|
|
|
#include <opm/core/newwells.h>
|
|
|
|
#include <opm/core/fluid/IncompPropertiesInterface.hpp>
|
2012-05-15 05:50:02 -05:00
|
|
|
#include <opm/core/fluid/BlackoilPropertiesInterface.hpp>
|
2012-03-20 04:31:32 -05:00
|
|
|
#include <opm/core/fluid/RockCompressibility.hpp>
|
2012-02-26 14:05:19 -06:00
|
|
|
#include <opm/core/utility/ErrorMacros.hpp>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
2012-04-24 08:15:36 -05:00
|
|
|
#include <cmath>
|
2012-04-25 04:00:33 -05:00
|
|
|
#include <iterator>
|
2012-02-26 14:05:19 -06:00
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief Computes pore volume of all cells in a grid.
|
|
|
|
/// @param[in] grid a grid
|
2012-05-14 14:47:10 -05:00
|
|
|
/// @param[in] porosity array of grid.number_of_cells porosity values
|
2012-02-26 14:05:19 -06:00
|
|
|
/// @param[out] porevol the pore volume by cell.
|
|
|
|
void computePorevolume(const UnstructuredGrid& grid,
|
2012-05-14 14:47:10 -05:00
|
|
|
const double* porosity,
|
2012-02-26 14:05:19 -06:00
|
|
|
std::vector<double>& porevol)
|
|
|
|
{
|
|
|
|
int num_cells = grid.number_of_cells;
|
|
|
|
porevol.resize(num_cells);
|
2012-05-14 14:47:10 -05:00
|
|
|
std::transform(porosity, porosity + num_cells,
|
2012-02-26 14:05:19 -06:00
|
|
|
grid.cell_volumes,
|
|
|
|
porevol.begin(),
|
|
|
|
std::multiplies<double>());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-20 04:31:32 -05:00
|
|
|
/// @brief Computes pore volume of all cells in a grid, with rock compressibility effects.
|
|
|
|
/// @param[in] grid a grid
|
2012-05-14 14:47:10 -05:00
|
|
|
/// @param[in] porosity array of grid.number_of_cells porosity values
|
2012-03-20 04:31:32 -05:00
|
|
|
/// @param[in] rock_comp rock compressibility properties
|
|
|
|
/// @param[in] pressure pressure by cell
|
|
|
|
/// @param[out] porevol the pore volume by cell.
|
|
|
|
void computePorevolume(const UnstructuredGrid& grid,
|
2012-05-14 14:47:10 -05:00
|
|
|
const double* porosity,
|
2012-03-20 04:31:32 -05:00
|
|
|
const RockCompressibility& rock_comp,
|
|
|
|
const std::vector<double>& pressure,
|
|
|
|
std::vector<double>& porevol)
|
|
|
|
{
|
|
|
|
int num_cells = grid.number_of_cells;
|
|
|
|
porevol.resize(num_cells);
|
|
|
|
for (int i = 0; i < num_cells; ++i) {
|
2012-05-14 14:47:10 -05:00
|
|
|
porevol[i] = porosity[i]*grid.cell_volumes[i]*rock_comp.poroMult(pressure[i]);
|
2012-03-20 04:31:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-13 09:56:52 -05:00
|
|
|
/// @brief Computes total saturated volumes over all grid cells.
|
|
|
|
/// @param[in] pv the pore volume by cell.
|
|
|
|
/// @param[in] s saturation values (for all P phases)
|
|
|
|
/// @param[out] sat_vol must point to a valid array with P elements,
|
|
|
|
/// where P = s.size()/pv.size().
|
|
|
|
/// For each phase p, we compute
|
|
|
|
/// sat_vol_p = sum_i s_p_i pv_i
|
|
|
|
void computeSaturatedVol(const std::vector<double>& pv,
|
|
|
|
const std::vector<double>& s,
|
|
|
|
double* sat_vol)
|
|
|
|
{
|
|
|
|
const int num_cells = pv.size();
|
|
|
|
const int np = s.size()/pv.size();
|
|
|
|
if (int(s.size()) != num_cells*np) {
|
|
|
|
THROW("Sizes of s and pv vectors do not match.");
|
|
|
|
}
|
|
|
|
std::fill(sat_vol, sat_vol + np, 0.0);
|
|
|
|
for (int c = 0; c < num_cells; ++c) {
|
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
sat_vol[p] += pv[c]*s[np*c + p];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-09 04:44:21 -06:00
|
|
|
/// @brief Computes average saturations over all grid cells.
|
2012-03-13 09:56:52 -05:00
|
|
|
/// @param[in] pv the pore volume by cell.
|
2012-03-09 04:44:21 -06:00
|
|
|
/// @param[in] s saturation values (for all P phases)
|
|
|
|
/// @param[out] aver_sat must point to a valid array with P elements,
|
|
|
|
/// where P = s.size()/pv.size().
|
|
|
|
/// For each phase p, we compute
|
|
|
|
/// aver_sat_p = (sum_i s_p_i pv_i) / (sum_i pv_i).
|
|
|
|
void computeAverageSat(const std::vector<double>& pv,
|
|
|
|
const std::vector<double>& s,
|
|
|
|
double* aver_sat)
|
|
|
|
{
|
|
|
|
const int num_cells = pv.size();
|
|
|
|
const int np = s.size()/pv.size();
|
|
|
|
if (int(s.size()) != num_cells*np) {
|
|
|
|
THROW("Sizes of s and pv vectors do not match.");
|
|
|
|
}
|
|
|
|
double tot_pv = 0.0;
|
|
|
|
// Note that we abuse the output array to accumulate the
|
|
|
|
// saturated pore volumes.
|
|
|
|
std::fill(aver_sat, aver_sat + np, 0.0);
|
|
|
|
for (int c = 0; c < num_cells; ++c) {
|
|
|
|
tot_pv += pv[c];
|
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
aver_sat[p] += pv[c]*s[np*c + p];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Must divide by pore volumes to get saturations.
|
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
aver_sat[p] /= tot_pv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-13 09:56:52 -05:00
|
|
|
/// @brief Computes injected and produced volumes of all phases.
|
|
|
|
/// Note 1: assumes that only the first phase is injected.
|
|
|
|
/// Note 2: assumes that transport has been done with an
|
|
|
|
/// implicit method, i.e. that the current state
|
|
|
|
/// gives the mobilities used for the preceding timestep.
|
|
|
|
/// @param[in] props fluid and rock properties.
|
|
|
|
/// @param[in] s saturation values (for all P phases)
|
|
|
|
/// @param[in] src if < 0: total outflow, if > 0: first phase inflow.
|
|
|
|
/// @param[in] dt timestep used
|
|
|
|
/// @param[out] injected must point to a valid array with P elements,
|
|
|
|
/// where P = s.size()/src.size().
|
|
|
|
/// @param[out] produced must also point to a valid array with P elements.
|
|
|
|
void computeInjectedProduced(const IncompPropertiesInterface& props,
|
|
|
|
const std::vector<double>& s,
|
|
|
|
const std::vector<double>& src,
|
|
|
|
const double dt,
|
|
|
|
double* injected,
|
|
|
|
double* produced)
|
|
|
|
{
|
|
|
|
const int num_cells = src.size();
|
|
|
|
const int np = s.size()/src.size();
|
|
|
|
if (int(s.size()) != num_cells*np) {
|
|
|
|
THROW("Sizes of s and src vectors do not match.");
|
|
|
|
}
|
|
|
|
std::fill(injected, injected + np, 0.0);
|
|
|
|
std::fill(produced, produced + np, 0.0);
|
|
|
|
const double* visc = props.viscosity();
|
|
|
|
std::vector<double> mob(np);
|
|
|
|
for (int c = 0; c < num_cells; ++c) {
|
|
|
|
if (src[c] > 0.0) {
|
|
|
|
injected[0] += src[c]*dt;
|
|
|
|
} else if (src[c] < 0.0) {
|
|
|
|
const double flux = -src[c]*dt;
|
|
|
|
const double* sat = &s[np*c];
|
|
|
|
props.relperm(1, sat, &c, &mob[0], 0);
|
|
|
|
double totmob = 0.0;
|
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
mob[p] /= visc[p];
|
|
|
|
totmob += mob[p];
|
|
|
|
}
|
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
produced[p] += (mob[p]/totmob)*flux;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-09 04:44:21 -06:00
|
|
|
|
2012-02-26 14:05:19 -06:00
|
|
|
/// @brief Computes total mobility for a set of saturation values.
|
|
|
|
/// @param[in] props rock and fluid properties
|
2012-03-06 08:10:21 -06:00
|
|
|
/// @param[in] cells cells with which the saturation values are associated
|
2012-02-26 14:05:19 -06:00
|
|
|
/// @param[in] s saturation values (for all phases)
|
|
|
|
/// @param[out] totmob total mobilities.
|
|
|
|
void computeTotalMobility(const Opm::IncompPropertiesInterface& props,
|
|
|
|
const std::vector<int>& cells,
|
|
|
|
const std::vector<double>& s,
|
|
|
|
std::vector<double>& totmob)
|
|
|
|
{
|
2012-03-12 10:09:26 -05:00
|
|
|
std::vector<double> pmobc;
|
|
|
|
|
|
|
|
computePhaseMobilities(props, cells, s, pmobc);
|
|
|
|
|
|
|
|
const std::size_t np = props.numPhases();
|
|
|
|
const std::vector<int>::size_type nc = cells.size();
|
|
|
|
|
|
|
|
std::vector<double>(cells.size(), 0.0).swap(totmob);
|
|
|
|
|
|
|
|
for (std::vector<int>::size_type c = 0; c < nc; ++c) {
|
|
|
|
for (std::size_t p = 0; p < np; ++p) {
|
|
|
|
totmob[ c ] += pmobc[c*np + p];
|
|
|
|
}
|
|
|
|
}
|
2012-02-26 14:05:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief Computes total mobility and omega for a set of saturation values.
|
|
|
|
/// @param[in] props rock and fluid properties
|
2012-03-06 08:10:21 -06:00
|
|
|
/// @param[in] cells cells with which the saturation values are associated
|
2012-02-26 14:05:19 -06:00
|
|
|
/// @param[in] s saturation values (for all phases)
|
|
|
|
/// @param[out] totmob total mobility
|
2012-03-20 08:21:22 -05:00
|
|
|
/// @param[out] omega fractional-flow weighted fluid densities.
|
2012-02-26 14:05:19 -06:00
|
|
|
void computeTotalMobilityOmega(const Opm::IncompPropertiesInterface& props,
|
|
|
|
const std::vector<int>& cells,
|
|
|
|
const std::vector<double>& s,
|
|
|
|
std::vector<double>& totmob,
|
|
|
|
std::vector<double>& omega)
|
|
|
|
{
|
2012-03-12 10:18:02 -05:00
|
|
|
std::vector<double> pmobc;
|
|
|
|
|
|
|
|
computePhaseMobilities(props, cells, s, pmobc);
|
|
|
|
|
|
|
|
const std::size_t np = props.numPhases();
|
|
|
|
const std::vector<int>::size_type nc = cells.size();
|
|
|
|
|
|
|
|
std::vector<double>(cells.size(), 0.0).swap(totmob);
|
|
|
|
std::vector<double>(cells.size(), 0.0).swap(omega );
|
|
|
|
|
|
|
|
const double* rho = props.density();
|
|
|
|
for (std::vector<int>::size_type c = 0; c < nc; ++c) {
|
|
|
|
for (std::size_t p = 0; p < np; ++p) {
|
|
|
|
totmob[ c ] += pmobc[c*np + p];
|
|
|
|
omega [ c ] += pmobc[c*np + p] * rho[ p ];
|
|
|
|
}
|
|
|
|
|
|
|
|
omega[ c ] /= totmob[ c ];
|
|
|
|
}
|
2012-02-26 14:05:19 -06:00
|
|
|
}
|
|
|
|
|
2012-03-20 04:13:27 -05:00
|
|
|
|
|
|
|
/// @brief Computes phase mobilities for a set of saturation values.
|
|
|
|
/// @param[in] props rock and fluid properties
|
|
|
|
/// @param[in] cells cells with which the saturation values are associated
|
|
|
|
/// @param[in] s saturation values (for all phases)
|
|
|
|
/// @param[out] pmobc phase mobilities (for all phases).
|
2012-03-12 10:03:29 -05:00
|
|
|
void computePhaseMobilities(const Opm::IncompPropertiesInterface& props,
|
|
|
|
const std::vector<int>& cells,
|
|
|
|
const std::vector<double>& s ,
|
|
|
|
std::vector<double>& pmobc)
|
|
|
|
{
|
|
|
|
const std::vector<int>::size_type nc = cells.size();
|
|
|
|
const std::size_t np = props.numPhases();
|
|
|
|
|
|
|
|
ASSERT (s.size() == nc * np);
|
|
|
|
|
|
|
|
std::vector<double>(nc * np, 0.0).swap(pmobc );
|
|
|
|
double* dpmobc = 0;
|
|
|
|
props.relperm(static_cast<const int>(nc), &s[0], &cells[0],
|
|
|
|
&pmobc[0], dpmobc);
|
|
|
|
|
|
|
|
const double* mu = props.viscosity();
|
|
|
|
std::vector<double>::iterator lam = pmobc.begin();
|
|
|
|
for (std::vector<int>::size_type c = 0; c < nc; ++c) {
|
|
|
|
for (std::size_t p = 0; p < np; ++p, ++lam) {
|
|
|
|
*lam /= mu[ p ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-08 05:04:59 -05:00
|
|
|
|
2012-05-08 04:04:15 -05:00
|
|
|
/// Computes the fractional flow for each cell in the cells argument
|
|
|
|
/// @param[in] props rock and fluid properties
|
|
|
|
/// @param[in] cells cells with which the saturation values are associated
|
|
|
|
/// @param[in] saturations saturation values (for all phases)
|
|
|
|
/// @param[out] fractional_flow the fractional flow for each phase for each cell.
|
|
|
|
|
|
|
|
void computeFractionalFlow(const Opm::IncompPropertiesInterface& props,
|
|
|
|
const std::vector<int>& cells,
|
|
|
|
const std::vector<double>& saturations,
|
|
|
|
std::vector<double>& fractional_flows)
|
|
|
|
{
|
|
|
|
const int num_phases = props.numPhases();
|
2012-06-13 10:07:56 -05:00
|
|
|
|
|
|
|
computePhaseMobilities(props, cells, saturations, fractional_flows);
|
|
|
|
|
|
|
|
for (std::vector<int>::size_type i = 0; i < cells.size(); ++i) {
|
2012-05-08 04:04:15 -05:00
|
|
|
double phase_sum = 0.0;
|
|
|
|
for (int phase = 0; phase < num_phases; ++phase) {
|
2012-06-13 10:07:56 -05:00
|
|
|
phase_sum += fractional_flows[i * num_phases + phase];
|
2012-05-08 04:04:15 -05:00
|
|
|
}
|
|
|
|
for (int phase = 0; phase < num_phases; ++phase) {
|
2012-06-13 10:07:56 -05:00
|
|
|
fractional_flows[i * num_phases + phase] /= phase_sum;
|
2012-05-08 04:04:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-12 10:03:29 -05:00
|
|
|
|
2012-03-12 07:00:48 -05:00
|
|
|
/// Compute two-phase transport source terms from face fluxes,
|
|
|
|
/// and pressure equation source terms. This puts boundary flows
|
|
|
|
/// into the source terms for the transport equation.
|
|
|
|
/// \param[in] grid The grid used.
|
|
|
|
/// \param[in] src Pressure eq. source terms. The sign convention is:
|
|
|
|
/// (+) positive total inflow (positive velocity divergence)
|
|
|
|
/// (-) negative total outflow
|
|
|
|
/// \param[in] faceflux Signed face fluxes, typically the result from a flow solver.
|
2012-04-24 08:15:36 -05:00
|
|
|
/// \param[in] inflow_frac Fraction of inflow (boundary and source terms) that consists of first phase.
|
2012-03-12 07:00:48 -05:00
|
|
|
/// Example: if only water is injected, inflow_frac == 1.0.
|
|
|
|
/// Note: it is not possible (with this method) to use different fractions
|
|
|
|
/// for different inflow sources, be they source terms of boundary flows.
|
2012-04-24 08:15:36 -05:00
|
|
|
/// \param[in] wells Wells data structure.
|
|
|
|
/// \param[in] well_perfrates Volumetric flow rates per well perforation.
|
2012-03-12 07:00:48 -05:00
|
|
|
/// \param[out] transport_src The transport source terms. They are to be interpreted depending on sign:
|
|
|
|
/// (+) positive inflow of first phase (water)
|
|
|
|
/// (-) negative total outflow of both phases
|
|
|
|
void computeTransportSource(const UnstructuredGrid& grid,
|
|
|
|
const std::vector<double>& src,
|
|
|
|
const std::vector<double>& faceflux,
|
|
|
|
const double inflow_frac,
|
2012-04-24 08:15:36 -05:00
|
|
|
const Wells* wells,
|
|
|
|
const std::vector<double>& well_perfrates,
|
2012-03-12 07:00:48 -05:00
|
|
|
std::vector<double>& transport_src)
|
|
|
|
{
|
|
|
|
int nc = grid.number_of_cells;
|
|
|
|
transport_src.resize(nc);
|
2012-04-24 08:15:36 -05:00
|
|
|
// Source term and boundary contributions.
|
2012-03-12 07:00:48 -05:00
|
|
|
for (int c = 0; c < nc; ++c) {
|
|
|
|
transport_src[c] = 0.0;
|
|
|
|
transport_src[c] += src[c] > 0.0 ? inflow_frac*src[c] : src[c];
|
|
|
|
for (int hf = grid.cell_facepos[c]; hf < grid.cell_facepos[c + 1]; ++hf) {
|
|
|
|
int f = grid.cell_faces[hf];
|
|
|
|
const int* f2c = &grid.face_cells[2*f];
|
|
|
|
double bdy_influx = 0.0;
|
|
|
|
if (f2c[0] == c && f2c[1] == -1) {
|
|
|
|
bdy_influx = -faceflux[f];
|
|
|
|
} else if (f2c[0] == -1 && f2c[1] == c) {
|
|
|
|
bdy_influx = faceflux[f];
|
|
|
|
}
|
|
|
|
if (bdy_influx != 0.0) {
|
|
|
|
transport_src[c] += bdy_influx > 0.0 ? inflow_frac*bdy_influx : bdy_influx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-24 08:15:36 -05:00
|
|
|
|
|
|
|
// Well contributions.
|
|
|
|
if (wells) {
|
|
|
|
const int nw = wells->number_of_wells;
|
2012-05-02 02:24:34 -05:00
|
|
|
const int np = wells->number_of_phases;
|
|
|
|
if (np != 2) {
|
|
|
|
THROW("computeTransportSource() requires a 2 phase case.");
|
|
|
|
}
|
2012-04-24 08:15:36 -05:00
|
|
|
for (int w = 0; w < nw; ++w) {
|
2012-05-02 02:24:34 -05:00
|
|
|
const double* comp_frac = wells->comp_frac + np*w;
|
2012-04-24 08:15:36 -05:00
|
|
|
for (int perf = wells->well_connpos[w]; perf < wells->well_connpos[w + 1]; ++perf) {
|
|
|
|
const int perf_cell = wells->well_cells[perf];
|
|
|
|
double perf_rate = well_perfrates[perf];
|
|
|
|
if (perf_rate > 0.0) {
|
|
|
|
// perf_rate is a total inflow rate, we want a water rate.
|
|
|
|
if (wells->type[w] != INJECTOR) {
|
2012-04-24 08:18:19 -05:00
|
|
|
std::cout << "**** Warning: crossflow in well with index " << w << " ignored." << std::endl;
|
|
|
|
perf_rate = 0.0;
|
|
|
|
} else {
|
2012-05-02 02:24:34 -05:00
|
|
|
ASSERT(std::fabs(comp_frac[0] + comp_frac[1] - 1.0) < 1e-6);
|
|
|
|
perf_rate *= comp_frac[0];
|
2012-04-24 08:15:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
transport_src[perf_cell] += perf_rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-12 07:00:48 -05:00
|
|
|
}
|
|
|
|
|
2012-02-26 14:05:19 -06:00
|
|
|
/// @brief Estimates a scalar cell velocity from face fluxes.
|
|
|
|
/// @param[in] grid a grid
|
|
|
|
/// @param[in] face_flux signed per-face fluxes
|
|
|
|
/// @param[out] cell_velocity the estimated velocities.
|
|
|
|
void estimateCellVelocity(const UnstructuredGrid& grid,
|
|
|
|
const std::vector<double>& face_flux,
|
|
|
|
std::vector<double>& cell_velocity)
|
|
|
|
{
|
|
|
|
const int dim = grid.dimensions;
|
|
|
|
cell_velocity.clear();
|
|
|
|
cell_velocity.resize(grid.number_of_cells*dim, 0.0);
|
|
|
|
for (int face = 0; face < grid.number_of_faces; ++face) {
|
|
|
|
int c[2] = { grid.face_cells[2*face], grid.face_cells[2*face + 1] };
|
|
|
|
const double* fc = &grid.face_centroids[face*dim];
|
|
|
|
double flux = face_flux[face];
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
if (c[i] >= 0) {
|
|
|
|
const double* cc = &grid.cell_centroids[c[i]*dim];
|
|
|
|
for (int d = 0; d < dim; ++d) {
|
|
|
|
double v_contrib = fc[d] - cc[d];
|
|
|
|
v_contrib *= flux/grid.cell_volumes[c[i]];
|
|
|
|
cell_velocity[c[i]*dim + d] += (i == 0) ? v_contrib : -v_contrib;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Extract a vector of water saturations from a vector of
|
|
|
|
/// interleaved water and oil saturations.
|
|
|
|
void toWaterSat(const std::vector<double>& sboth,
|
|
|
|
std::vector<double>& sw)
|
|
|
|
{
|
|
|
|
int num = sboth.size()/2;
|
|
|
|
sw.resize(num);
|
|
|
|
for (int i = 0; i < num; ++i) {
|
|
|
|
sw[i] = sboth[2*i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Make a a vector of interleaved water and oil saturations from
|
|
|
|
/// a vector of water saturations.
|
|
|
|
void toBothSat(const std::vector<double>& sw,
|
|
|
|
std::vector<double>& sboth)
|
|
|
|
{
|
|
|
|
int num = sw.size();
|
|
|
|
sboth.resize(2*num);
|
|
|
|
for (int i = 0; i < num; ++i) {
|
|
|
|
sboth[2*i] = sw[i];
|
|
|
|
sboth[2*i + 1] = 1.0 - sw[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-14 03:51:08 -05:00
|
|
|
/// Create a src vector equivalent to a wells structure.
|
|
|
|
/// For this to be valid, the wells must be all rate-controlled and
|
|
|
|
/// single-perforation.
|
|
|
|
void wellsToSrc(const Wells& wells, const int num_cells, std::vector<double>& src)
|
|
|
|
{
|
2012-05-02 02:24:34 -05:00
|
|
|
const int np = wells.number_of_phases;
|
|
|
|
if (np != 2) {
|
|
|
|
THROW("wellsToSrc() requires a 2 phase case.");
|
|
|
|
}
|
2012-03-14 03:51:08 -05:00
|
|
|
src.resize(num_cells);
|
|
|
|
for (int w = 0; w < wells.number_of_wells; ++w) {
|
2012-05-03 06:45:19 -05:00
|
|
|
const int cur = wells.ctrls[w]->current;
|
2012-03-14 03:51:08 -05:00
|
|
|
if (wells.ctrls[w]->num != 1) {
|
2012-05-03 06:45:19 -05:00
|
|
|
MESSAGE("In wellsToSrc(): well has more than one control, all but current control will be ignored.");
|
2012-03-14 03:51:08 -05:00
|
|
|
}
|
2012-05-03 06:45:19 -05:00
|
|
|
if (wells.ctrls[w]->type[cur] != RESERVOIR_RATE) {
|
2012-05-02 02:24:34 -05:00
|
|
|
THROW("In wellsToSrc(): well is something other than RESERVOIR_RATE.");
|
2012-03-14 03:51:08 -05:00
|
|
|
}
|
|
|
|
if (wells.well_connpos[w+1] - wells.well_connpos[w] != 1) {
|
|
|
|
THROW("In wellsToSrc(): well has multiple perforations.");
|
|
|
|
}
|
2012-05-03 06:45:19 -05:00
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
if (wells.ctrls[w]->distr[np*cur + p] != 1.0) {
|
|
|
|
THROW("In wellsToSrc(): well not controlled on total rate.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
double flow = wells.ctrls[w]->target[cur];
|
|
|
|
if (wells.type[w] == INJECTOR) {
|
|
|
|
flow *= wells.comp_frac[np*w + 0]; // Obtaining water rate for inflow source.
|
|
|
|
}
|
2012-03-14 03:51:08 -05:00
|
|
|
const double cell = wells.well_cells[wells.well_connpos[w]];
|
2012-04-25 08:36:01 -05:00
|
|
|
src[cell] = flow;
|
2012-03-14 03:51:08 -05:00
|
|
|
}
|
|
|
|
}
|
2012-02-26 14:05:19 -06:00
|
|
|
|
2012-04-24 06:33:12 -05:00
|
|
|
|
2012-04-12 10:50:51 -05:00
|
|
|
void computeWDP(const Wells& wells, const UnstructuredGrid& grid, const std::vector<double>& saturations,
|
2012-04-25 05:37:30 -05:00
|
|
|
const double* densities, const double gravity, const bool per_grid_cell,
|
|
|
|
std::vector<double>& wdp)
|
2012-04-12 10:50:51 -05:00
|
|
|
{
|
2012-04-17 02:19:06 -05:00
|
|
|
const int nw = wells.number_of_wells;
|
2012-04-24 06:48:00 -05:00
|
|
|
const size_t np = per_grid_cell ?
|
|
|
|
saturations.size()/grid.number_of_cells
|
|
|
|
: saturations.size()/wells.well_connpos[nw];
|
2012-04-12 10:50:51 -05:00
|
|
|
// Simple for now:
|
2012-04-24 06:33:12 -05:00
|
|
|
for (int i = 0; i < nw; i++) {
|
2012-04-12 10:50:51 -05:00
|
|
|
double depth_ref = wells.depth_ref[i];
|
2012-04-24 06:33:12 -05:00
|
|
|
for (int j = wells.well_connpos[i]; j < wells.well_connpos[i + 1]; j++) {
|
2012-04-12 10:50:51 -05:00
|
|
|
int cell = wells.well_cells[j];
|
2012-04-24 06:33:12 -05:00
|
|
|
|
2012-04-12 10:50:51 -05:00
|
|
|
// Is this correct wrt. depth_ref?
|
2012-04-24 06:33:12 -05:00
|
|
|
double cell_depth = grid.cell_centroids[3 * cell + 2];
|
2012-04-13 03:32:36 -05:00
|
|
|
|
|
|
|
double saturation_sum = 0.0;
|
2012-04-24 06:33:12 -05:00
|
|
|
for (size_t p = 0; p < np; p++) {
|
|
|
|
if (!per_grid_cell) {
|
2012-04-24 06:36:32 -05:00
|
|
|
saturation_sum += saturations[j * np + p];
|
2012-04-24 06:33:12 -05:00
|
|
|
} else {
|
|
|
|
saturation_sum += saturations[np * cell + p];
|
2012-04-17 02:19:06 -05:00
|
|
|
}
|
2012-04-13 03:32:36 -05:00
|
|
|
}
|
2012-04-24 06:33:12 -05:00
|
|
|
if (saturation_sum == 0) {
|
2012-04-13 03:32:36 -05:00
|
|
|
saturation_sum = 1.0;
|
|
|
|
}
|
2012-04-12 10:50:51 -05:00
|
|
|
double density = 0.0;
|
2012-04-24 06:33:12 -05:00
|
|
|
for (size_t p = 0; p < np; p++) {
|
|
|
|
if (!per_grid_cell) {
|
2012-04-24 06:36:32 -05:00
|
|
|
density += saturations[j * np + p] * densities[p] / saturation_sum;
|
2012-04-24 06:33:12 -05:00
|
|
|
} else {
|
2012-04-17 02:19:06 -05:00
|
|
|
// Is this a smart way of doing it?
|
2012-04-24 06:33:12 -05:00
|
|
|
density += saturations[np * cell + p] * densities[p] / saturation_sum;
|
2012-04-17 02:19:06 -05:00
|
|
|
}
|
2012-04-12 10:50:51 -05:00
|
|
|
}
|
2012-04-24 06:33:12 -05:00
|
|
|
|
2012-04-12 10:50:51 -05:00
|
|
|
// Is the sign correct?
|
2012-04-25 05:37:30 -05:00
|
|
|
wdp.push_back(density * (cell_depth - depth_ref) * gravity);
|
2012-04-12 10:50:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-25 01:59:31 -05:00
|
|
|
|
|
|
|
|
2012-04-13 07:22:44 -05:00
|
|
|
void computeFlowRatePerWell(const Wells& wells, const std::vector<double>& flow_rates_per_cell,
|
2012-04-24 06:33:12 -05:00
|
|
|
std::vector<double>& flow_rates_per_well)
|
2012-04-13 07:22:44 -05:00
|
|
|
{
|
|
|
|
int index_in_flow_rates = 0;
|
2012-04-24 06:33:12 -05:00
|
|
|
for (int w = 0; w < wells.number_of_wells; w++) {
|
|
|
|
int number_of_cells = wells.well_connpos[w + 1] - wells.well_connpos[w];
|
2012-04-13 07:22:44 -05:00
|
|
|
double flow_sum = 0.0;
|
2012-04-24 06:33:12 -05:00
|
|
|
for (int i = 0; i < number_of_cells; i++) {
|
2012-04-13 07:22:44 -05:00
|
|
|
flow_sum += flow_rates_per_cell[index_in_flow_rates++];
|
|
|
|
}
|
|
|
|
flow_rates_per_well.push_back(flow_sum);
|
|
|
|
}
|
|
|
|
}
|
2012-03-14 06:47:01 -05:00
|
|
|
|
2012-05-08 05:04:59 -05:00
|
|
|
|
2012-05-08 05:23:58 -05:00
|
|
|
/// Computes the phase flow rate per well
|
|
|
|
/// \param[in] wells The wells for which the flow rate should be computed
|
|
|
|
/// \param[in] flow_rates_per_well_cell The total flow rate for each cell (ordered the same
|
|
|
|
/// way as the wells struct
|
|
|
|
/// \param[in] fractional_flows the fractional flow for each cell in each well
|
|
|
|
/// \param[out] phase_flow_per_well Will contain the phase flow per well
|
2012-05-08 04:04:15 -05:00
|
|
|
void computePhaseFlowRatesPerWell(const Wells& wells,
|
2012-05-08 05:23:58 -05:00
|
|
|
const std::vector<double>& flow_rates_per_well_cell,
|
2012-05-08 04:04:15 -05:00
|
|
|
const std::vector<double>& fractional_flows,
|
2012-05-08 05:23:58 -05:00
|
|
|
std::vector<double>& phase_flow_per_well)
|
2012-05-08 04:04:15 -05:00
|
|
|
{
|
|
|
|
const int np = wells.number_of_phases;
|
|
|
|
const int nw = wells.number_of_wells;
|
|
|
|
phase_flow_per_well.resize(nw * np);
|
|
|
|
for (int wix = 0; wix < nw; ++wix) {
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
|
|
|
// Reset vector
|
2012-05-08 05:03:50 -05:00
|
|
|
phase_flow_per_well[wix*np + phase] = 0.0;
|
2012-05-08 04:04:15 -05:00
|
|
|
}
|
|
|
|
for (int i = wells.well_connpos[wix]; i < wells.well_connpos[wix + 1]; ++i) {
|
2012-05-08 05:23:58 -05:00
|
|
|
const int cell = wells.well_cells[i];
|
2012-05-08 04:04:15 -05:00
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
2012-05-08 05:23:58 -05:00
|
|
|
phase_flow_per_well[wix * np + phase] += flow_rates_per_well_cell[i] * fractional_flows[cell * np + phase];
|
2012-05-08 04:04:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-26 14:05:19 -06:00
|
|
|
|
2012-04-25 01:59:31 -05:00
|
|
|
|
|
|
|
void Watercut::push(double time, double fraction, double produced)
|
|
|
|
{
|
|
|
|
data_.push_back(time);
|
|
|
|
data_.push_back(fraction);
|
|
|
|
data_.push_back(produced);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Watercut::write(std::ostream& os) const
|
|
|
|
{
|
|
|
|
int sz = data_.size() / 3;
|
|
|
|
for (int i = 0; i < sz; ++i) {
|
|
|
|
os << data_[3 * i] / Opm::unit::day << " "
|
|
|
|
<< data_[3 * i + 1] << " "
|
|
|
|
<< data_[3 * i + 2] << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-25 04:00:33 -05:00
|
|
|
void WellReport::push(const IncompPropertiesInterface& props,
|
|
|
|
const Wells& wells,
|
|
|
|
const std::vector<double>& saturation,
|
|
|
|
const double time,
|
|
|
|
const std::vector<double>& well_bhp,
|
|
|
|
const std::vector<double>& well_perfrates)
|
|
|
|
{
|
|
|
|
int nw = well_bhp.size();
|
|
|
|
ASSERT(nw == wells.number_of_wells);
|
|
|
|
if (props.numPhases() != 2) {
|
|
|
|
THROW("WellReport for now assumes two phase flow.");
|
|
|
|
}
|
|
|
|
const double* visc = props.viscosity();
|
|
|
|
std::vector<double> data_now;
|
2012-04-25 05:37:30 -05:00
|
|
|
data_now.reserve(1 + 3*nw);
|
|
|
|
data_now.push_back(time/unit::day);
|
2012-04-25 04:00:33 -05:00
|
|
|
for (int w = 0; w < nw; ++w) {
|
2012-04-25 05:37:30 -05:00
|
|
|
data_now.push_back(well_bhp[w]/(unit::barsa));
|
2012-04-25 04:00:33 -05:00
|
|
|
double well_rate_total = 0.0;
|
|
|
|
double well_rate_water = 0.0;
|
|
|
|
for (int perf = wells.well_connpos[w]; perf < wells.well_connpos[w + 1]; ++perf) {
|
2012-04-25 05:37:30 -05:00
|
|
|
const double perf_rate = well_perfrates[perf]*(unit::day/unit::second);
|
2012-04-25 04:00:33 -05:00
|
|
|
well_rate_total += perf_rate;
|
|
|
|
if (perf_rate > 0.0) {
|
|
|
|
// Injection.
|
2012-05-02 02:24:34 -05:00
|
|
|
well_rate_water += perf_rate*wells.comp_frac[0];
|
2012-04-25 04:00:33 -05:00
|
|
|
} else {
|
|
|
|
// Production.
|
|
|
|
const int cell = wells.well_cells[perf];
|
|
|
|
double mob[2];
|
|
|
|
props.relperm(1, &saturation[2*cell], &cell, mob, 0);
|
|
|
|
mob[0] /= visc[0];
|
|
|
|
mob[1] /= visc[1];
|
|
|
|
const double fracflow = mob[0]/(mob[0] + mob[1]);
|
|
|
|
well_rate_water += perf_rate*fracflow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data_now.push_back(well_rate_total);
|
2012-04-25 05:37:30 -05:00
|
|
|
if (well_rate_total == 0.0) {
|
|
|
|
data_now.push_back(0.0);
|
|
|
|
} else {
|
|
|
|
data_now.push_back(well_rate_water/well_rate_total);
|
|
|
|
}
|
2012-04-25 04:00:33 -05:00
|
|
|
}
|
|
|
|
data_.push_back(data_now);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-05-15 05:50:02 -05:00
|
|
|
void WellReport::push(const BlackoilPropertiesInterface& props,
|
|
|
|
const Wells& wells,
|
|
|
|
const std::vector<double>& p,
|
|
|
|
const std::vector<double>& z,
|
|
|
|
const std::vector<double>& s,
|
|
|
|
const double time,
|
|
|
|
const std::vector<double>& well_bhp,
|
|
|
|
const std::vector<double>& well_perfrates)
|
|
|
|
{
|
|
|
|
// TODO: refactor, since this is almost identical to the other push().
|
|
|
|
int nw = well_bhp.size();
|
|
|
|
ASSERT(nw == wells.number_of_wells);
|
|
|
|
if (props.numPhases() != 2) {
|
|
|
|
THROW("WellReport for now assumes two phase flow.");
|
|
|
|
}
|
|
|
|
std::vector<double> data_now;
|
|
|
|
data_now.reserve(1 + 3*nw);
|
|
|
|
data_now.push_back(time/unit::day);
|
|
|
|
for (int w = 0; w < nw; ++w) {
|
|
|
|
data_now.push_back(well_bhp[w]/(unit::barsa));
|
|
|
|
double well_rate_total = 0.0;
|
|
|
|
double well_rate_water = 0.0;
|
|
|
|
for (int perf = wells.well_connpos[w]; perf < wells.well_connpos[w + 1]; ++perf) {
|
|
|
|
const double perf_rate = well_perfrates[perf]*(unit::day/unit::second);
|
|
|
|
well_rate_total += perf_rate;
|
|
|
|
if (perf_rate > 0.0) {
|
|
|
|
// Injection.
|
|
|
|
well_rate_water += perf_rate*wells.comp_frac[0];
|
|
|
|
} else {
|
|
|
|
// Production.
|
|
|
|
const int cell = wells.well_cells[perf];
|
|
|
|
double mob[2];
|
|
|
|
props.relperm(1, &s[2*cell], &cell, mob, 0);
|
|
|
|
double visc[2];
|
|
|
|
props.viscosity(1, &p[cell], &z[2*cell], &cell, visc, 0);
|
|
|
|
mob[0] /= visc[0];
|
|
|
|
mob[1] /= visc[1];
|
|
|
|
const double fracflow = mob[0]/(mob[0] + mob[1]);
|
|
|
|
well_rate_water += perf_rate*fracflow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data_now.push_back(well_rate_total);
|
|
|
|
if (well_rate_total == 0.0) {
|
|
|
|
data_now.push_back(0.0);
|
|
|
|
} else {
|
|
|
|
data_now.push_back(well_rate_water/well_rate_total);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data_.push_back(data_now);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-04-25 04:00:33 -05:00
|
|
|
void WellReport::write(std::ostream& os) const
|
|
|
|
{
|
|
|
|
const int sz = data_.size();
|
|
|
|
for (int i = 0; i < sz; ++i) {
|
|
|
|
std::copy(data_[i].begin(), data_[i].end(), std::ostream_iterator<double>(os, "\t"));
|
|
|
|
os << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-25 01:59:31 -05:00
|
|
|
|
2012-02-26 14:05:19 -06:00
|
|
|
} // namespace Opm
|