Fix bug in prodDD(), add test.

This commit is contained in:
Atgeirr Flø Rasmussen 2015-08-26 14:23:42 +02:00 committed by babrodtk
parent 51dde7cec5
commit 1f32594f79
2 changed files with 53 additions and 4 deletions

View File

@ -330,10 +330,11 @@ namespace Opm
{
assert(lhs.type_ == D);
assert(rhs.type_ == D);
AutoDiffMatrix retval = lhs;
for (int r = 0; r < lhs.rows_; ++r) {
retval.d_.diagonal().array() *= rhs.d_.diagonal().array();
}
AutoDiffMatrix retval;
retval.type_ = D;
retval.rows_ = lhs.rows_;
retval.cols_ = rhs.cols_;
retval.d_ = (lhs.d_.diagonal().array() * rhs.d_.diagonal().array()).matrix().asDiagonal();
return retval;
}

View File

@ -173,3 +173,51 @@ BOOST_AUTO_TEST_CASE(AdditionOps)
BOOST_CHECK(x == ss);
}
BOOST_AUTO_TEST_CASE(MultOps)
{
// Setup.
Mat z = Mat(AutoDiffMatrix::ZeroMatrix, 3);
Sp zs(3,3);
Mat i = Mat(AutoDiffMatrix::IdentityMatrix, 3);
Sp is(Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>::Identity(3,3).sparseView());
Eigen::Array<double, Eigen::Dynamic, 1> d1(3);
d1 << 0.2, 1.2, 13.4;
Mat d = Mat(d1.matrix().asDiagonal());
Sp ds = spdiag(d1);
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> s1(3,3);
s1 <<
1.0, 0.0, 2.0,
0.0, 1.0, 0.0,
0.0, 0.0, 2.0;
Sp ss(s1.sparseView());
Mat s = Mat(ss);
// Convert to Eigen::SparseMatrix
Sp x;
z.toSparse(x);
BOOST_CHECK(x == zs);
i.toSparse(x);
BOOST_CHECK(x == is);
d.toSparse(x);
BOOST_CHECK(x == ds);
s.toSparse(x);
BOOST_CHECK(x == ss);
// Multiply by diagonal matrix.
auto ztd = z * d;
ztd.toSparse(x);
BOOST_CHECK(x == zs*ds);
auto itd = i * d;
itd.toSparse(x);
BOOST_CHECK(x == is*ds);
auto dtd = d * d;
dtd.toSparse(x);
BOOST_CHECK(x == ds*ds);
auto std = s * d;
std.toSparse(x);
BOOST_CHECK(x == ss*ds);
}