Remove non-AD overload of muWat().

The AD version is made a little smarter, detecting the
case of input with no derivatives. Existing use of the
non-AD rewritten.
This commit is contained in:
Atgeirr Flø Rasmussen 2015-03-02 13:10:41 +01:00
parent 5a390f0d27
commit 965be0471f
5 changed files with 15 additions and 65 deletions

View File

@ -311,30 +311,6 @@ BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(const BlackoilPropsAdFromDeck&
// ------ Viscosity ------
/// Water viscosity.
/// \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 viscosity values.
V BlackoilPropsAdFromDeck::muWat(const V& pw,
const V& T,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Water]) {
OPM_THROW(std::runtime_error, "Cannot call muWat(): water phase not present.");
}
const int n = cells.size();
mapPvtRegions(cells);
assert(pw.size() == n);
V mu(n);
V dmudp(n);
V dmudr(n);
const double* rs = 0;
props_[phase_usage_.phase_pos[Water]]->mu(n, pvt_region_.data(), pw.data(), T.data(), rs,
mu.data(), dmudp.data(), dmudr.data());
return mu;
}
/// Oil viscosity.
/// \param[in] po Array of n oil pressure values.
@ -437,13 +413,17 @@ BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(const BlackoilPropsAdFromDeck&
props_[phase_usage_.phase_pos[Water]]->mu(n, pvt_region_.data(), pw.value().data(), T.value().data(), rs,
mu.data(), dmudp.data(), dmudr.data());
ADB::M dmudp_diag = spdiag(dmudp);
const int num_blocks = pw.numBlocks();
std::vector<ADB::M> jacs(num_blocks);
for (int block = 0; block < num_blocks; ++block) {
fastSparseProduct(dmudp_diag, pw.derivative()[block], jacs[block]);
if (pw.derivative().empty()) {
return ADB::constant(mu);
} else {
ADB::M dmudp_diag = spdiag(dmudp);
const int num_blocks = pw.numBlocks();
std::vector<ADB::M> jacs(num_blocks);
for (int block = 0; block < num_blocks; ++block) {
fastSparseProduct(dmudp_diag, pw.derivative()[block], jacs[block]);
}
return ADB::function(mu, jacs);
}
return ADB::function(mu, jacs);
}
/// Oil viscosity.

View File

@ -134,15 +134,6 @@ namespace Opm
// ------ Viscosity ------
/// Water viscosity.
/// \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 viscosity values.
V muWat(const V& pw,
const V& T,
const Cells& cells) const;
/// Oil viscosity.
/// \param[in] po Array of n oil pressure values.
/// \param[in] T Array of n temperature values.

View File

@ -94,16 +94,6 @@ namespace Opm
// ------ Viscosity ------
/// Water viscosity.
/// \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 viscosity values.
virtual
V muWat(const V& pw,
const V& T,
const Cells& cells) const = 0;
/// Oil viscosity.
/// \param[in] po Array of n oil pressure values.
/// \param[in] T Array of n temperature values.

View File

@ -553,20 +553,7 @@ namespace {
V ImpesTPFAAD::fluidMu(const int phase, const V& p, const V& T, const std::vector<int>& cells) const
{
switch (phase) {
case Water:
return fluid_.muWat(p, T, cells);
case Oil: {
V dummy_rs = V::Zero(p.size(), 1) * p;
std::vector<PhasePresence> cond(dummy_rs.size());
return fluid_.muOil(p, T, dummy_rs, cond, cells);
}
case Gas:
return fluid_.muGas(p, T, cells);
default:
OPM_THROW(std::runtime_error, "Unknown phase index " << phase);
}
return fluidMu(phase, ADB::constant(p), ADB::constant(T), cells).value();
}

View File

@ -129,6 +129,7 @@ BOOST_FIXTURE_TEST_CASE(ViscosityValue, TestFixture<SetupSimple>)
const Opm::BlackoilPropsAdFromDeck::Cells cells(5, 0);
typedef Opm::BlackoilPropsAdFromDeck::V V;
typedef Opm::BlackoilPropsAdFromDeck::ADB ADB;
V Vpw;
Vpw.resize(cells.size());
@ -143,7 +144,7 @@ BOOST_FIXTURE_TEST_CASE(ViscosityValue, TestFixture<SetupSimple>)
BOOST_REQUIRE_EQUAL(Vpw.size(), cells.size());
const Opm::BlackoilPropsAdFromDeck::V VmuWat = boprops_ad.muWat(Vpw, T, cells);
const V VmuWat = boprops_ad.muWat(ADB::constant(Vpw), ADB::constant(T), cells).value();
BOOST_REQUIRE_EQUAL(Vpw.size(), cells.size());
@ -159,6 +160,7 @@ BOOST_FIXTURE_TEST_CASE(ViscosityAD, TestFixture<SetupSimple>)
const Opm::BlackoilPropsAdFromDeck::Cells cells(5, 0);
typedef Opm::BlackoilPropsAdFromDeck::V V;
typedef Opm::BlackoilPropsAdFromDeck::ADB ADB;
V Vpw;
Vpw.resize(cells.size());
@ -173,7 +175,7 @@ BOOST_FIXTURE_TEST_CASE(ViscosityAD, TestFixture<SetupSimple>)
typedef Opm::BlackoilPropsAdFromDeck::ADB ADB;
const V VmuWat = boprops_ad.muWat(Vpw, T, cells);
const V VmuWat = boprops_ad.muWat(ADB::constant(Vpw), ADB::constant(T), cells).value();
for (V::Index i = 0, n = Vpw.size(); i < n; ++i) {
const std::vector<int> bp(1, grid.c_grid()->number_of_cells);