mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-12-25 08:41:00 -06:00
Fixed test_autodiffhelpers
This commit is contained in:
parent
3a9a153c22
commit
945593295d
@ -79,6 +79,7 @@ BOOST_AUTO_TEST_CASE(vertcatCollapseJacsTest)
|
|||||||
typedef AutoDiffBlock<double> ADB;
|
typedef AutoDiffBlock<double> ADB;
|
||||||
typedef ADB::V V;
|
typedef ADB::V V;
|
||||||
typedef ADB::M M;
|
typedef ADB::M M;
|
||||||
|
typedef Eigen::SparseMatrix<double> S;
|
||||||
|
|
||||||
// We will build a system with the block structure
|
// We will build a system with the block structure
|
||||||
// { 2, 0, 1 } (total of three columns) and { 1, 2, 1 } (row) sizes.
|
// { 2, 0, 1 } (total of three columns) and { 1, 2, 1 } (row) sizes.
|
||||||
@ -95,13 +96,17 @@ BOOST_AUTO_TEST_CASE(vertcatCollapseJacsTest)
|
|||||||
// First block.
|
// First block.
|
||||||
V val(1);
|
V val(1);
|
||||||
val << 10;
|
val << 10;
|
||||||
std::vector<M> jacs(3);
|
std::vector<M> jacs;
|
||||||
jacs[0] = M(1, 2);
|
jacs.reserve(3);
|
||||||
jacs[1] = M(1, 0);
|
S s1(1, 2);
|
||||||
jacs[2] = M(1, 1);
|
S s2(1, 0);
|
||||||
jacs[0].insert(0, 0) = 1.0;
|
S s3(1, 1);
|
||||||
jacs[0].insert(0, 1) = 2.0;
|
s1.insert(0, 0) = 1.0;
|
||||||
jacs[2].insert(0, 0) = 3.0;
|
s1.insert(0, 1) = 2.0;
|
||||||
|
s3.insert(0, 0) = 3.0;
|
||||||
|
jacs.push_back(M(s1));
|
||||||
|
jacs.push_back(M(s2));
|
||||||
|
jacs.push_back(M(s3));
|
||||||
v.push_back(ADB::function(val, jacs));
|
v.push_back(ADB::function(val, jacs));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@ -114,13 +119,17 @@ BOOST_AUTO_TEST_CASE(vertcatCollapseJacsTest)
|
|||||||
// Third block.
|
// Third block.
|
||||||
V val(1);
|
V val(1);
|
||||||
val << 13;
|
val << 13;
|
||||||
std::vector<M> jacs(3);
|
std::vector<M> jacs(0);
|
||||||
jacs[0] = M(1, 2);
|
jacs.reserve(3);
|
||||||
jacs[1] = M(1, 0);
|
S s1(1, 2);
|
||||||
jacs[2] = M(1, 1);
|
S s2(1, 0);
|
||||||
jacs[0].insert(0, 0) = 4.0;
|
S s3(1, 1);
|
||||||
jacs[0].insert(0, 1) = 5.0;
|
s1.insert(0, 0) = 4.0;
|
||||||
jacs[2].insert(0, 0) = 6.0;
|
s1.insert(0, 1) = 5.0;
|
||||||
|
s3.insert(0, 0) = 6.0;
|
||||||
|
jacs.push_back(M(s1));
|
||||||
|
jacs.push_back(M(s2));
|
||||||
|
jacs.push_back(M(s3));
|
||||||
v.push_back(ADB::function(val, jacs));
|
v.push_back(ADB::function(val, jacs));
|
||||||
}
|
}
|
||||||
std::vector<int> expected_block_pattern{ 2, 0, 1 };
|
std::vector<int> expected_block_pattern{ 2, 0, 1 };
|
||||||
@ -132,17 +141,20 @@ BOOST_AUTO_TEST_CASE(vertcatCollapseJacsTest)
|
|||||||
// Build expected results.
|
// Build expected results.
|
||||||
V expected_val(4);
|
V expected_val(4);
|
||||||
expected_val << 10, 11, 12, 13;
|
expected_val << 10, 11, 12, 13;
|
||||||
M expected_jac(4, 3);
|
S expected_jac_s(4, 3);
|
||||||
expected_jac.insert(0, 0) = 1.0;
|
expected_jac_s.insert(0, 0) = 1.0;
|
||||||
expected_jac.insert(0, 1) = 2.0;
|
expected_jac_s.insert(0, 1) = 2.0;
|
||||||
expected_jac.insert(0, 2) = 3.0;
|
expected_jac_s.insert(0, 2) = 3.0;
|
||||||
expected_jac.insert(3, 0) = 4.0;
|
expected_jac_s.insert(3, 0) = 4.0;
|
||||||
expected_jac.insert(3, 1) = 5.0;
|
expected_jac_s.insert(3, 1) = 5.0;
|
||||||
expected_jac.insert(3, 2) = 6.0;
|
expected_jac_s.insert(3, 2) = 6.0;
|
||||||
|
M expected_jac(expected_jac_s);
|
||||||
|
|
||||||
// Compare.
|
// Compare.
|
||||||
BOOST_CHECK((x.value() == expected_val).all());
|
BOOST_CHECK((x.value() == expected_val).all());
|
||||||
BOOST_CHECK(x.derivative()[0] == expected_jac);
|
S derivative;
|
||||||
|
x.derivative()[0].toSparse(derivative);
|
||||||
|
BOOST_CHECK(derivative == expected_jac_s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user