Whitespace cleanup and adding a check for #phases <= 3.

This commit is contained in:
Atgeirr Flø Rasmussen committed 2012-09-03 14:04:52 +02:00
1 parent e37f003cb5
commit 055f2d5f19
1 file changed
+170 -170
+170 -170
View File
@@ -40,14 +40,14 @@ namespace Opm
/// @param[out] porevol the pore volume by cell. /// @param[out] porevol the pore volume by cell.
void computePorevolume(const UnstructuredGrid& grid, void computePorevolume(const UnstructuredGrid& grid,
const double* porosity, const double* porosity,
std::vector<double>& porevol) std::vector<double>& porevol)
{ {
int num_cells = grid.number_of_cells; int num_cells = grid.number_of_cells;
porevol.resize(num_cells); porevol.resize(num_cells);
std::transform(porosity, porosity + num_cells, std::transform(porosity, porosity + num_cells,
grid.cell_volumes, grid.cell_volumes,
porevol.begin(), porevol.begin(),
std::multiplies<double>()); std::multiplies<double>());
} }
@@ -98,20 +98,20 @@ namespace Opm
/// For each phase p, we compute /// For each phase p, we compute
/// sat_vol_p = sum_i s_p_i pv_i /// sat_vol_p = sum_i s_p_i pv_i
void computeSaturatedVol(const std::vector<double>& pv, void computeSaturatedVol(const std::vector<double>& pv,
const std::vector<double>& s, const std::vector<double>& s,
double* sat_vol) double* sat_vol)
{ {
const int num_cells = pv.size(); const int num_cells = pv.size();
const int np = s.size()/pv.size(); const int np = s.size()/pv.size();
if (int(s.size()) != num_cells*np) { if (int(s.size()) != num_cells*np) {
THROW("Sizes of s and pv vectors do not match."); THROW("Sizes of s and pv vectors do not match.");
} }
std::fill(sat_vol, sat_vol + np, 0.0); std::fill(sat_vol, sat_vol + np, 0.0);
for (int c = 0; c < num_cells; ++c) { for (int c = 0; c < num_cells; ++c) {
for (int p = 0; p < np; ++p) { for (int p = 0; p < np; ++p) {
sat_vol[p] += pv[c]*s[np*c + p]; sat_vol[p] += pv[c]*s[np*c + p];
} }
} }
} }
@@ -123,28 +123,28 @@ namespace Opm
/// For each phase p, we compute /// For each phase p, we compute
/// aver_sat_p = (sum_i s_p_i pv_i) / (sum_i pv_i). /// aver_sat_p = (sum_i s_p_i pv_i) / (sum_i pv_i).
void computeAverageSat(const std::vector<double>& pv, void computeAverageSat(const std::vector<double>& pv,
const std::vector<double>& s, const std::vector<double>& s,
double* aver_sat) double* aver_sat)
{ {
const int num_cells = pv.size(); const int num_cells = pv.size();
const int np = s.size()/pv.size(); const int np = s.size()/pv.size();
if (int(s.size()) != num_cells*np) { if (int(s.size()) != num_cells*np) {
THROW("Sizes of s and pv vectors do not match."); THROW("Sizes of s and pv vectors do not match.");
} }
double tot_pv = 0.0; double tot_pv = 0.0;
// Note that we abuse the output array to accumulate the // Note that we abuse the output array to accumulate the
// saturated pore volumes. // saturated pore volumes.
std::fill(aver_sat, aver_sat + np, 0.0); std::fill(aver_sat, aver_sat + np, 0.0);
for (int c = 0; c < num_cells; ++c) { for (int c = 0; c < num_cells; ++c) {
tot_pv += pv[c]; tot_pv += pv[c];
for (int p = 0; p < np; ++p) { for (int p = 0; p < np; ++p) {
aver_sat[p] += pv[c]*s[np*c + p]; aver_sat[p] += pv[c]*s[np*c + p];
} }
} }
// Must divide by pore volumes to get saturations. // Must divide by pore volumes to get saturations.
for (int p = 0; p < np; ++p) { for (int p = 0; p < np; ++p) {
aver_sat[p] /= tot_pv; aver_sat[p] /= tot_pv;
} }
} }
@@ -161,38 +161,38 @@ namespace Opm
/// where P = s.size()/src.size(). /// where P = s.size()/src.size().
/// @param[out] produced must also point to a valid array with P elements. /// @param[out] produced must also point to a valid array with P elements.
void computeInjectedProduced(const IncompPropertiesInterface& props, void computeInjectedProduced(const IncompPropertiesInterface& props,
const std::vector<double>& s, const std::vector<double>& s,
const std::vector<double>& src, const std::vector<double>& src,
const double dt, const double dt,
double* injected, double* injected,
double* produced) double* produced)
{ {
const int num_cells = src.size(); const int num_cells = src.size();
const int np = s.size()/src.size(); const int np = s.size()/src.size();
if (int(s.size()) != num_cells*np) { if (int(s.size()) != num_cells*np) {
THROW("Sizes of s and src vectors do not match."); THROW("Sizes of s and src vectors do not match.");
} }
std::fill(injected, injected + np, 0.0); std::fill(injected, injected + np, 0.0);
std::fill(produced, produced + np, 0.0); std::fill(produced, produced + np, 0.0);
const double* visc = props.viscosity(); const double* visc = props.viscosity();
std::vector<double> mob(np); std::vector<double> mob(np);
for (int c = 0; c < num_cells; ++c) { for (int c = 0; c < num_cells; ++c) {
if (src[c] > 0.0) { if (src[c] > 0.0) {
injected[0] += src[c]*dt; injected[0] += src[c]*dt;
} else if (src[c] < 0.0) { } else if (src[c] < 0.0) {
const double flux = -src[c]*dt; const double flux = -src[c]*dt;
const double* sat = &s[np*c]; const double* sat = &s[np*c];
props.relperm(1, sat, &c, &mob[0], 0); props.relperm(1, sat, &c, &mob[0], 0);
double totmob = 0.0; double totmob = 0.0;
for (int p = 0; p < np; ++p) { for (int p = 0; p < np; ++p) {
mob[p] /= visc[p]; mob[p] /= visc[p];
totmob += mob[p]; totmob += mob[p];
} }
for (int p = 0; p < np; ++p) { for (int p = 0; p < np; ++p) {
produced[p] += (mob[p]/totmob)*flux; produced[p] += (mob[p]/totmob)*flux;
} }
} }
} }
} }
@@ -203,9 +203,9 @@ namespace Opm
/// @param[in] s saturation values (for all phases) /// @param[in] s saturation values (for all phases)
/// @param[out] totmob total mobilities. /// @param[out] totmob total mobilities.
void computeTotalMobility(const Opm::IncompPropertiesInterface& props, void computeTotalMobility(const Opm::IncompPropertiesInterface& props,
const std::vector<int>& cells, const std::vector<int>& cells,
const std::vector<double>& s, const std::vector<double>& s,
std::vector<double>& totmob) std::vector<double>& totmob)
{ {
std::vector<double> pmobc; std::vector<double> pmobc;
@@ -231,10 +231,10 @@ namespace Opm
/// @param[out] totmob total mobility /// @param[out] totmob total mobility
/// @param[out] omega fractional-flow weighted fluid densities. /// @param[out] omega fractional-flow weighted fluid densities.
void computeTotalMobilityOmega(const Opm::IncompPropertiesInterface& props, void computeTotalMobilityOmega(const Opm::IncompPropertiesInterface& props,
const std::vector<int>& cells, const std::vector<int>& cells,
const std::vector<double>& s, const std::vector<double>& s,
std::vector<double>& totmob, std::vector<double>& totmob,
std::vector<double>& omega) std::vector<double>& omega)
{ {
std::vector<double> pmobc; std::vector<double> pmobc;
@@ -331,33 +331,33 @@ namespace Opm
/// (+) positive inflow of first phase (water) /// (+) positive inflow of first phase (water)
/// (-) negative total outflow of both phases /// (-) negative total outflow of both phases
void computeTransportSource(const UnstructuredGrid& grid, void computeTransportSource(const UnstructuredGrid& grid,
const std::vector<double>& src, const std::vector<double>& src,
const std::vector<double>& faceflux, const std::vector<double>& faceflux,
const double inflow_frac, const double inflow_frac,
const Wells* wells, const Wells* wells,
const std::vector<double>& well_perfrates, const std::vector<double>& well_perfrates,
std::vector<double>& transport_src) std::vector<double>& transport_src)
{ {
int nc = grid.number_of_cells; int nc = grid.number_of_cells;
transport_src.resize(nc); transport_src.resize(nc);
// Source term and boundary contributions. // Source term and boundary contributions.
for (int c = 0; c < nc; ++c) { for (int c = 0; c < nc; ++c) {
transport_src[c] = 0.0; transport_src[c] = 0.0;
transport_src[c] += src[c] > 0.0 ? inflow_frac*src[c] : src[c]; 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) { for (int hf = grid.cell_facepos[c]; hf < grid.cell_facepos[c + 1]; ++hf) {
int f = grid.cell_faces[hf]; int f = grid.cell_faces[hf];
const int* f2c = &grid.face_cells[2*f]; const int* f2c = &grid.face_cells[2*f];
double bdy_influx = 0.0; double bdy_influx = 0.0;
if (f2c[0] == c && f2c[1] == -1) { if (f2c[0] == c && f2c[1] == -1) {
bdy_influx = -faceflux[f]; bdy_influx = -faceflux[f];
} else if (f2c[0] == -1 && f2c[1] == c) { } else if (f2c[0] == -1 && f2c[1] == c) {
bdy_influx = faceflux[f]; bdy_influx = faceflux[f];
} }
if (bdy_influx != 0.0) { if (bdy_influx != 0.0) {
transport_src[c] += bdy_influx > 0.0 ? inflow_frac*bdy_influx : bdy_influx; transport_src[c] += bdy_influx > 0.0 ? inflow_frac*bdy_influx : bdy_influx;
} }
} }
} }
// Well contributions. // Well contributions.
if (wells) { if (wells) {
@@ -392,52 +392,52 @@ namespace Opm
/// @param[in] face_flux signed per-face fluxes /// @param[in] face_flux signed per-face fluxes
/// @param[out] cell_velocity the estimated velocities. /// @param[out] cell_velocity the estimated velocities.
void estimateCellVelocity(const UnstructuredGrid& grid, void estimateCellVelocity(const UnstructuredGrid& grid,
const std::vector<double>& face_flux, const std::vector<double>& face_flux,
std::vector<double>& cell_velocity) std::vector<double>& cell_velocity)
{ {
const int dim = grid.dimensions; const int dim = grid.dimensions;
cell_velocity.clear(); cell_velocity.clear();
cell_velocity.resize(grid.number_of_cells*dim, 0.0); cell_velocity.resize(grid.number_of_cells*dim, 0.0);
for (int face = 0; face < grid.number_of_faces; ++face) { for (int face = 0; face < grid.number_of_faces; ++face) {
int c[2] = { grid.face_cells[2*face], grid.face_cells[2*face + 1] }; int c[2] = { grid.face_cells[2*face], grid.face_cells[2*face + 1] };
const double* fc = &grid.face_centroids[face*dim]; const double* fc = &grid.face_centroids[face*dim];
double flux = face_flux[face]; double flux = face_flux[face];
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
if (c[i] >= 0) { if (c[i] >= 0) {
const double* cc = &grid.cell_centroids[c[i]*dim]; const double* cc = &grid.cell_centroids[c[i]*dim];
for (int d = 0; d < dim; ++d) { for (int d = 0; d < dim; ++d) {
double v_contrib = fc[d] - cc[d]; double v_contrib = fc[d] - cc[d];
v_contrib *= flux/grid.cell_volumes[c[i]]; v_contrib *= flux/grid.cell_volumes[c[i]];
cell_velocity[c[i]*dim + d] += (i == 0) ? v_contrib : -v_contrib; cell_velocity[c[i]*dim + d] += (i == 0) ? v_contrib : -v_contrib;
} }
} }
} }
} }
} }
/// Extract a vector of water saturations from a vector of /// Extract a vector of water saturations from a vector of
/// interleaved water and oil saturations. /// interleaved water and oil saturations.
void toWaterSat(const std::vector<double>& sboth, void toWaterSat(const std::vector<double>& sboth,
std::vector<double>& sw) std::vector<double>& sw)
{ {
int num = sboth.size()/2; int num = sboth.size()/2;
sw.resize(num); sw.resize(num);
for (int i = 0; i < num; ++i) { for (int i = 0; i < num; ++i) {
sw[i] = sboth[2*i]; sw[i] = sboth[2*i];
} }
} }
/// Make a a vector of interleaved water and oil saturations from /// Make a a vector of interleaved water and oil saturations from
/// a vector of water saturations. /// a vector of water saturations.
void toBothSat(const std::vector<double>& sw, void toBothSat(const std::vector<double>& sw,
std::vector<double>& sboth) std::vector<double>& sboth)
{ {
int num = sw.size(); int num = sw.size();
sboth.resize(2*num); sboth.resize(2*num);
for (int i = 0; i < num; ++i) { for (int i = 0; i < num; ++i) {
sboth[2*i] = sw[i]; sboth[2*i] = sw[i];
sboth[2*i + 1] = 1.0 - sw[i]; sboth[2*i + 1] = 1.0 - sw[i];
} }
} }
@@ -450,30 +450,30 @@ namespace Opm
if (np != 2) { if (np != 2) {
THROW("wellsToSrc() requires a 2 phase case."); THROW("wellsToSrc() requires a 2 phase case.");
} }
src.resize(num_cells); src.resize(num_cells);
for (int w = 0; w < wells.number_of_wells; ++w) { for (int w = 0; w < wells.number_of_wells; ++w) {
const int cur = wells.ctrls[w]->current; const int cur = wells.ctrls[w]->current;
if (wells.ctrls[w]->num != 1) { if (wells.ctrls[w]->num != 1) {
MESSAGE("In wellsToSrc(): well has more than one control, all but current control will be ignored."); MESSAGE("In wellsToSrc(): well has more than one control, all but current control will be ignored.");
} }
if (wells.ctrls[w]->type[cur] != RESERVOIR_RATE) { if (wells.ctrls[w]->type[cur] != RESERVOIR_RATE) {
THROW("In wellsToSrc(): well is something other than RESERVOIR_RATE."); THROW("In wellsToSrc(): well is something other than RESERVOIR_RATE.");
} }
if (wells.well_connpos[w+1] - wells.well_connpos[w] != 1) { if (wells.well_connpos[w+1] - wells.well_connpos[w] != 1) {
THROW("In wellsToSrc(): well has multiple perforations."); THROW("In wellsToSrc(): well has multiple perforations.");
} }
for (int p = 0; p < np; ++p) { for (int p = 0; p < np; ++p) {
if (wells.ctrls[w]->distr[np*cur + p] != 1.0) { if (wells.ctrls[w]->distr[np*cur + p] != 1.0) {
THROW("In wellsToSrc(): well not controlled on total rate."); THROW("In wellsToSrc(): well not controlled on total rate.");
} }
} }
double flow = wells.ctrls[w]->target[cur]; double flow = wells.ctrls[w]->target[cur];
if (wells.type[w] == INJECTOR) { if (wells.type[w] == INJECTOR) {
flow *= wells.comp_frac[np*w + 0]; // Obtaining water rate for inflow source. flow *= wells.comp_frac[np*w + 0]; // Obtaining water rate for inflow source.
} }
const double cell = wells.well_cells[wells.well_connpos[w]]; const double cell = wells.well_cells[wells.well_connpos[w]];
src[cell] = flow; src[cell] = flow;
} }
} }
@@ -594,9 +594,10 @@ namespace Opm
int nw = well_bhp.size(); int nw = well_bhp.size();
ASSERT(nw == wells.number_of_wells); ASSERT(nw == wells.number_of_wells);
int np = props.numPhases(); int np = props.numPhases();
//if (props.numPhases() != 2) { const int max_np = 3;
// THROW("WellReport for now assumes two phase flow."); if (np > max_np) {
//} THROW("WellReport for now assumes #phases <= " << max_np);
}
const double* visc = props.viscosity(); const double* visc = props.viscosity();
std::vector<double> data_now; std::vector<double> data_now;
data_now.reserve(1 + 3*nw); data_now.reserve(1 + 3*nw);
@@ -606,8 +607,8 @@ namespace Opm
double well_rate_total = 0.0; double well_rate_total = 0.0;
double well_rate_water = 0.0; double well_rate_water = 0.0;
for (int perf = wells.well_connpos[w]; perf < wells.well_connpos[w + 1]; ++perf) { for (int perf = wells.well_connpos[w]; perf < wells.well_connpos[w + 1]; ++perf) {
const double perf_rate = unit::convert::to(well_perfrates[perf], const double perf_rate = unit::convert::to(well_perfrates[perf],
unit::cubic(unit::meter)/unit::day); unit::cubic(unit::meter)/unit::day);
well_rate_total += perf_rate; well_rate_total += perf_rate;
if (perf_rate > 0.0) { if (perf_rate > 0.0) {
// Injection. // Injection.
@@ -615,13 +616,13 @@ namespace Opm
} else { } else {
// Production. // Production.
const int cell = wells.well_cells[perf]; const int cell = wells.well_cells[perf];
double mob[np]; double mob[max_np];
props.relperm(1, &saturation[2*cell], &cell, mob, 0); props.relperm(1, &saturation[2*cell], &cell, mob, 0);
double tmob=0; double tmob = 0;
for(int i=0; i < np; ++i){ for(int i = 0; i < np; ++i) {
mob[i] /= visc[i]; mob[i] /= visc[i];
tmob += mob[i]; tmob += mob[i];
} }
const double fracflow = mob[0]/tmob; const double fracflow = mob[0]/tmob;
well_rate_water += perf_rate*fracflow; well_rate_water += perf_rate*fracflow;
} }
@@ -652,9 +653,10 @@ namespace Opm
int nw = well_bhp.size(); int nw = well_bhp.size();
ASSERT(nw == wells.number_of_wells); ASSERT(nw == wells.number_of_wells);
int np = props.numPhases(); int np = props.numPhases();
//if (props.numPhases() != 2) { const int max_np = 3;
// THROW("WellReport for now assumes two phase flow."); if (np > max_np) {
//} THROW("WellReport for now assumes #phases <= " << max_np);
}
std::vector<double> data_now; std::vector<double> data_now;
data_now.reserve(1 + 3*nw); data_now.reserve(1 + 3*nw);
data_now.push_back(time/unit::day); data_now.push_back(time/unit::day);
@@ -665,25 +667,23 @@ namespace Opm
for (int perf = wells.well_connpos[w]; perf < wells.well_connpos[w + 1]; ++perf) { 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); const double perf_rate = well_perfrates[perf]*(unit::day/unit::second);
well_rate_total += perf_rate; well_rate_total += perf_rate;
if (perf_rate > 0.0) { if (perf_rate > 0.0) {
// Injection. // Injection.
well_rate_water += perf_rate*wells.comp_frac[0]; well_rate_water += perf_rate*wells.comp_frac[0];
} else { } else {
// Production. // Production.
const int cell = wells.well_cells[perf]; const int cell = wells.well_cells[perf];
double mob[np]; double mob[max_np];
props.relperm(1, &s[2*cell], &cell, mob, 0); props.relperm(1, &s[2*cell], &cell, mob, 0);
double visc[np]; double visc[max_np];
props.viscosity(1, &p[cell], &z[2*cell], &cell, visc, 0); props.viscosity(1, &p[cell], &z[2*cell], &cell, visc, 0);
double tmob=0; double tmob = 0;
for(int i=0; i < np; ++i){ for(int i = 0; i < np; ++i) {
mob[i] /= visc[i]; mob[i] /= visc[i];
tmob += mob[i]; tmob += mob[i];
} }
const double fracflow = mob[0]/(tmob); const double fracflow = mob[0]/(tmob);
well_rate_water += perf_rate*fracflow; well_rate_water += perf_rate*fracflow;
//const double fracflow = mob[0]/(tmob);
//well_rate_water += perf_rate*fracflow;
} }
} }
data_now.push_back(well_rate_total); data_now.push_back(well_rate_total);