Remove extra overloads of bWat(), bOil() and bGas().

Remaining method is the one taking AD objects. This modification
required changes to a few more places than anticipated:
  - RateConverter
  - FullyImplicitBlackoilSolver::computeWellConnectionPressures()
In these places, the call now is a little more complex and there
might be a very minor performance loss, until we optimize the
bX() functions to check for the no-derivatives case.
This commit is contained in:
Atgeirr Flø Rasmussen 2015-03-03 14:33:19 +01:00
parent 1195ced57a
commit fbf06c06e7
6 changed files with 27 additions and 293 deletions

View File

@ -428,119 +428,6 @@ BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(const BlackoilPropsAdFromDeck&
// ------ Formation volume factor (b) ------ // ------ Formation volume factor (b) ------
/// Water formation volume factor.
/// \param[in] pw Array of n water pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V BlackoilPropsAdFromDeck::bWat(const V& pw,
const V& T,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Water]) {
OPM_THROW(std::runtime_error, "Cannot call bWat(): water phase not present.");
}
const int n = cells.size();
mapPvtRegions(cells);
assert(pw.size() == n);
V b(n);
V dbdp(n);
V dbdr(n);
const double* rs = 0;
props_[phase_usage_.phase_pos[Water]]->b(n, pvt_region_.data(), pw.data(), T.data(), rs,
b.data(), dbdp.data(), dbdr.data());
return b;
}
/// Oil formation volume factor.
/// \param[in] po Array of n oil pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] rs Array of n gas solution factor values.
/// \param[in] cond Array of n taxonomies classifying fluid condition.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V BlackoilPropsAdFromDeck::bOil(const V& po,
const V& T,
const V& rs,
const std::vector<PhasePresence>& cond,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Oil]) {
OPM_THROW(std::runtime_error, "Cannot call bOil(): oil phase not present.");
}
const int n = cells.size();
mapPvtRegions(cells);
assert(po.size() == n);
V b(n);
V dbdp(n);
V dbdr(n);
props_[phase_usage_.phase_pos[Oil]]->b(n, pvt_region_.data(), po.data(), T.data(), rs.data(), &cond[0],
b.data(), dbdp.data(), dbdr.data());
return b;
}
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V BlackoilPropsAdFromDeck::bGas(const V& pg,
const V& T,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call bGas(): gas phase not present.");
}
const int n = cells.size();
mapPvtRegions(cells);
assert(pg.size() == n);
V b(n);
V dbdp(n);
V dbdr(n);
const double* rs = 0;
props_[phase_usage_.phase_pos[Gas]]->b(n, pvt_region_.data(), pg.data(), T.data(), rs,
b.data(), dbdp.data(), dbdr.data());
return b;
}
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V BlackoilPropsAdFromDeck::bGas(const V& pg,
const V& T,
const V& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
}
const int n = cells.size();
mapPvtRegions(cells);
assert(pg.size() == n);
V b(n);
V dbdp(n);
V dbdr(n);
props_[phase_usage_.phase_pos[Gas]]->b(n, pvt_region_.data(), pg.data(), T.data(), rv.data(), &cond[0],
b.data(), dbdp.data(), dbdr.data());
return b;
}
/// Water formation volume factor. /// Water formation volume factor.
/// \param[in] pw Array of n water pressure values. /// \param[in] pw Array of n water pressure values.
@ -615,39 +502,6 @@ BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(const BlackoilPropsAdFromDeck&
return ADB::function(b, jacs); return ADB::function(b, jacs);
} }
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
ADB BlackoilPropsAdFromDeck::bGas(const ADB& pg,
const ADB& T,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
}
const int n = cells.size();
mapPvtRegions(cells);
assert(pg.size() == n);
V b(n);
V dbdp(n);
V dbdr(n);
const double* rv = 0;
props_[phase_usage_.phase_pos[Gas]]->b(n, pvt_region_.data(), pg.value().data(), T.value().data(), rv,
b.data(), dbdp.data(), dbdr.data());
ADB::M dbdp_diag = spdiag(dbdp);
const int num_blocks = pg.numBlocks();
std::vector<ADB::M> jacs(num_blocks);
for (int block = 0; block < num_blocks; ++block) {
fastSparseProduct(dbdp_diag, pg.derivative()[block], jacs[block]);
}
return ADB::function(b, jacs);
}
/// Gas formation volume factor. /// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values. /// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values. /// \param[in] T Array of n temperature values.

View File

@ -171,50 +171,6 @@ namespace Opm
// ------ Formation volume factor (b) ------ // ------ Formation volume factor (b) ------
/// Water formation volume factor.
/// \param[in] pw Array of n water pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V bWat(const V& pw,
const V& T,
const Cells& cells) const;
/// Oil formation volume factor.
/// \param[in] po Array of n oil pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] rs Array of n gas solution factor values.
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V bOil(const V& po,
const V& T,
const V& rs,
const std::vector<PhasePresence>& cond,
const Cells& cells) const;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V bGas(const V& pg,
const V& T,
const Cells& cells) const;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V bGas(const V& pg,
const V& T,
const V& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const;
/// Water formation volume factor. /// Water formation volume factor.
/// \param[in] pw Array of n water pressure values. /// \param[in] pw Array of n water pressure values.
/// \param[in] T Array of n temperature values. /// \param[in] T Array of n temperature values.
@ -237,15 +193,6 @@ namespace Opm
const std::vector<PhasePresence>& cond, const std::vector<PhasePresence>& cond,
const Cells& cells) const; const Cells& cells) const;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
ADB bGas(const ADB& pg,
const ADB& T,
const Cells& cells) const;
/// Gas formation volume factor. /// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values. /// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values. /// \param[in] T Array of n temperature values.

View File

@ -134,54 +134,6 @@ namespace Opm
// ------ Formation volume factor (b) ------ // ------ Formation volume factor (b) ------
/// Water formation volume factor.
/// \param[in] pw Array of n water pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
virtual
V bWat(const V& pw,
const V& T,
const Cells& cells) const = 0;
/// Oil formation volume factor.
/// \param[in] po Array of n oil pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] rs Array of n gas solution factor values.
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
virtual
V bOil(const V& po,
const V& T,
const V& rs,
const std::vector<PhasePresence>& cond,
const Cells& cells) const = 0;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
virtual
V bGas(const V& pg,
const V& T,
const Cells& cells) const = 0;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
virtual
V bGas(const V& pg,
const V& T,
const V& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const = 0;
/// Water formation volume factor. /// Water formation volume factor.
/// \param[in] pw Array of n water pressure values. /// \param[in] pw Array of n water pressure values.
/// \param[in] T Array of n temperature values. /// \param[in] T Array of n temperature values.
@ -209,17 +161,7 @@ namespace Opm
/// Gas formation volume factor. /// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values. /// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values. /// \param[in] T Array of n temperature values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values. /// \param[in] rv Array of n vapor oil/gas ratios.
/// \return Array of n formation volume factor values.
virtual
ADB bGas(const ADB& pg,
const ADB& T,
const Cells& cells) const = 0;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] T Array of n temperature values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell. /// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values. /// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values. /// \return Array of n formation volume factor values.

View File

@ -658,11 +658,12 @@ namespace detail {
} }
// Use cell values for the temperature as the wells don't knows its temperature yet. // Use cell values for the temperature as the wells don't knows its temperature yet.
const V perf_temp = subset(state.temperature.value(), well_cells); const ADB perf_temp = subset(state.temperature, well_cells);
// Compute b, rsmax, rvmax values for perforations. // Compute b, rsmax, rvmax values for perforations.
// Evaluate the properties using average well block pressures // Evaluate the properties using average well block pressures
// and cell values for rs, rv, phase condition and temperature. // and cell values for rs, rv, phase condition and temperature.
const ADB avg_press_ad = ADB::constant(avg_press);
std::vector<PhasePresence> perf_cond(nperf); std::vector<PhasePresence> perf_cond(nperf);
const std::vector<PhasePresence>& pc = phaseCondition(); const std::vector<PhasePresence>& pc = phaseCondition();
for (int perf = 0; perf < nperf; ++perf) { for (int perf = 0; perf < nperf; ++perf) {
@ -673,21 +674,21 @@ namespace detail {
std::vector<double> rsmax_perf(nperf, 0.0); std::vector<double> rsmax_perf(nperf, 0.0);
std::vector<double> rvmax_perf(nperf, 0.0); std::vector<double> rvmax_perf(nperf, 0.0);
if (pu.phase_used[BlackoilPhases::Aqua]) { if (pu.phase_used[BlackoilPhases::Aqua]) {
const V bw = fluid_.bWat(avg_press, perf_temp, well_cells); const V bw = fluid_.bWat(avg_press_ad, perf_temp, well_cells).value();
b.col(pu.phase_pos[BlackoilPhases::Aqua]) = bw; b.col(pu.phase_pos[BlackoilPhases::Aqua]) = bw;
} }
assert(active_[Oil]); assert(active_[Oil]);
const V perf_so = subset(state.saturation[pu.phase_pos[Oil]].value(), well_cells); const V perf_so = subset(state.saturation[pu.phase_pos[Oil]].value(), well_cells);
if (pu.phase_used[BlackoilPhases::Liquid]) { if (pu.phase_used[BlackoilPhases::Liquid]) {
const V perf_rs = subset(state.rs.value(), well_cells); const ADB perf_rs = subset(state.rs, well_cells);
const V bo = fluid_.bOil(avg_press, perf_temp, perf_rs, perf_cond, well_cells); const V bo = fluid_.bOil(avg_press_ad, perf_temp, perf_rs, perf_cond, well_cells).value();
b.col(pu.phase_pos[BlackoilPhases::Liquid]) = bo; b.col(pu.phase_pos[BlackoilPhases::Liquid]) = bo;
const V rssat = fluidRsSat(avg_press, perf_so, well_cells); const V rssat = fluidRsSat(avg_press, perf_so, well_cells);
rsmax_perf.assign(rssat.data(), rssat.data() + nperf); rsmax_perf.assign(rssat.data(), rssat.data() + nperf);
} }
if (pu.phase_used[BlackoilPhases::Vapour]) { if (pu.phase_used[BlackoilPhases::Vapour]) {
const V perf_rv = subset(state.rv.value(), well_cells); const ADB perf_rv = subset(state.rv, well_cells);
const V bg = fluid_.bGas(avg_press, perf_temp, perf_rv, perf_cond, well_cells); const V bg = fluid_.bGas(avg_press_ad, perf_temp, perf_rv, perf_cond, well_cells).value();
b.col(pu.phase_pos[BlackoilPhases::Vapour]) = bg; b.col(pu.phase_pos[BlackoilPhases::Vapour]) = bg;
const V rvsat = fluidRvSat(avg_press, perf_so, well_cells); const V rvsat = fluidRvSat(avg_press, perf_so, well_cells);
rvmax_perf.assign(rvsat.data(), rvsat.data() + nperf); rvmax_perf.assign(rvsat.data(), rvsat.data() + nperf);

View File

@ -586,20 +586,7 @@ namespace {
V ImpesTPFAAD::fluidFvf(const int phase, const V& p, const V& T, const std::vector<int>& cells) const V ImpesTPFAAD::fluidFvf(const int phase, const V& p, const V& T, const std::vector<int>& cells) const
{ {
switch (phase) { return fluidFvf(phase, ADB::constant(p), ADB::constant(T), cells).value();
case Water:
return fluid_.bWat(p, T, cells);
case Oil: {
V dummy_rs = V::Zero(p.size(), 1) * p;
std::vector<PhasePresence> cond(dummy_rs.size());
return fluid_.bOil(p, T, dummy_rs, cond, cells);
}
case Gas:
return fluid_.bGas(p, T, cells);
default:
OPM_THROW(std::runtime_error, "Unknown phase index " << phase);
}
} }
@ -614,11 +601,13 @@ namespace {
case Oil: { case Oil: {
ADB dummy_rs = V::Zero(p.size(), 1) * p; ADB dummy_rs = V::Zero(p.size(), 1) * p;
std::vector<PhasePresence> cond(dummy_rs.size()); std::vector<PhasePresence> cond(dummy_rs.size());
return fluid_.bOil(p, T, dummy_rs, cond, cells); return fluid_.bOil(p, T, dummy_rs, cond, cells);
} }
case Gas: case Gas: {
return fluid_.bGas(p, T, cells); ADB dummy_rv = V::Zero(p.size(), 1) * p;
std::vector<PhasePresence> cond(dummy_rv.size());
return fluid_.bGas(p, T, dummy_rv, cond, cells);
}
default: default:
OPM_THROW(std::runtime_error, "Unknown phase index " << phase); OPM_THROW(std::runtime_error, "Unknown phase index " << phase);
} }

View File

@ -326,6 +326,7 @@ namespace Opm {
calcCoeff(const Input& in, const RegionId r, Coeff& coeff) calcCoeff(const Input& in, const RegionId r, Coeff& coeff)
{ {
typedef typename Property::V V; typedef typename Property::V V;
typedef typename Property::ADB ADB;
const PhaseUsage& pu = props_.phaseUsage(); const PhaseUsage& pu = props_.phaseUsage();
const V& p = getRegPress(r); const V& p = getRegPress(r);
@ -341,7 +342,7 @@ namespace Opm {
if (Details::PhaseUsed::water(pu)) { if (Details::PhaseUsed::water(pu)) {
// q[w]_r = q[w]_s / bw // q[w]_r = q[w]_s / bw
const V& bw = props_.bWat(p, T, c); const V& bw = props_.bWat(ADB::constant(p), ADB::constant(T), c).value();
coeff[iw] = 1.0 / bw(0); coeff[iw] = 1.0 / bw(0);
} }
@ -354,7 +355,7 @@ namespace Opm {
if (Details::PhaseUsed::oil(pu)) { if (Details::PhaseUsed::oil(pu)) {
// q[o]_r = 1/(bo * (1 - rs*rv)) * (q[o]_s - rv*q[g]_s) // q[o]_r = 1/(bo * (1 - rs*rv)) * (q[o]_s - rv*q[g]_s)
const V& bo = props_.bOil(p, T, m.rs, m.cond, c); const V& bo = props_.bOil(ADB::constant(p), ADB::constant(T), ADB::constant(m.rs), m.cond, c).value();
const double den = bo(0) * detR; const double den = bo(0) * detR;
coeff[io] += 1.0 / den; coeff[io] += 1.0 / den;
@ -367,7 +368,7 @@ namespace Opm {
if (Details::PhaseUsed::gas(pu)) { if (Details::PhaseUsed::gas(pu)) {
// q[g]_r = 1/(bg * (1 - rs*rv)) * (q[g]_s - rs*q[o]_s) // q[g]_r = 1/(bg * (1 - rs*rv)) * (q[g]_s - rs*q[o]_s)
const V& bg = props_.bGas(p, T, m.rv, m.cond, c); const V& bg = props_.bGas(ADB::constant(p), ADB::constant(T), ADB::constant(m.rv), m.cond, c).value();
const double den = bg(0) * detR; const double den = bg(0) * detR;
coeff[ig] += 1.0 / den; coeff[ig] += 1.0 / den;