Skip to content
Snippets Groups Projects
Commit 6f446ff0 authored by Oliver Sander's avatar Oliver Sander
Browse files

Add tests whether all-NaN FieldVector and FieldMatrices have NaN norms

Patch by Elias Pipping

FS 1147

[[Imported from SVN: r6921]]
parent 8200892c
No related branches found
No related tags found
No related merge requests found
...@@ -498,9 +498,50 @@ void test_invert () ...@@ -498,9 +498,50 @@ void test_invert ()
A.invert(); A.invert();
} }
// Make sure that a matrix with only NaN entries has norm NaN.
// Prior to r6819, the infinity_norm would be zero; see also FS #1147.
void
test_nan()
{
double mynan = 0.0/0.0;
Dune::FieldMatrix<double, 2, 2> m2(mynan);
assert(std::isnan(m2.infinity_norm()));
assert(std::isnan(m2.frobenius_norm()));
assert(std::isnan(m2.frobenius_norm2()));
Dune::FieldMatrix<double, 0, 2> m02(mynan);
assert(0.0 == m02.infinity_norm());
assert(0.0 == m02.frobenius_norm());
assert(0.0 == m02.frobenius_norm2());
Dune::FieldMatrix<double, 2, 0> m20(mynan);
assert(0.0 == m20.infinity_norm());
assert(0.0 == m20.frobenius_norm());
assert(0.0 == m20.frobenius_norm2());
}
// The computation of infinity_norm_real() was flawed from r6819 on
// until r6915.
void
test_infinity_norms()
{
std::complex<double> threefour(3.0, -4.0);
std::complex<double> eightsix(8.0, -6.0);
Dune::FieldMatrix<std::complex<double>, 2, 2> m;
m[0] = threefour;
m[1] = eightsix;
assert(std::abs(m.infinity_norm() -20.0) < 1e-10); // max(5+5, 10+10)
assert(std::abs(m.infinity_norm_real()-28.0) < 1e-10); // max(7+7, 14+14)
}
int main() int main()
{ {
try { try {
test_nan();
test_infinity_norms();
// test 1 x 1 matrices // test 1 x 1 matrices
test_matrix<float, 1, 1>(); test_matrix<float, 1, 1>();
ScalarOperatorTest<float>(); ScalarOperatorTest<float>();
......
...@@ -309,12 +309,48 @@ public: ...@@ -309,12 +309,48 @@ public:
} }
}; };
// Make sure that a vector with only NaN entries has norm NaN.
// Prior to r6914, the infinity_norm would be zero; see also FS #1147.
void
test_nan()
{
double mynan = 0.0/0.0;
Dune::FieldVector<double, 2> v2(mynan);
assert(std::isnan(v2.infinity_norm()));
assert(std::isnan(v2.one_norm()));
assert(std::isnan(v2.two_norm()));
assert(std::isnan(v2.two_norm2()));
Dune::FieldVector<double, 0> v0(mynan);
assert(0.0 == v0.infinity_norm());
assert(0.0 == v0.one_norm());
assert(0.0 == v0.two_norm());
assert(0.0 == v0.two_norm2());
}
void
test_infinity_norms()
{
std::complex<double> threefour(3.0, -4.0);
std::complex<double> eightsix(8.0, -6.0);
Dune::FieldVector<std::complex<double>, 2> v;
v[0] = threefour;
v[1] = eightsix;
assert(std::abs(v.infinity_norm() -10.0) < 1e-10); // max(5,10)
assert(std::abs(v.infinity_norm_real()-14.0) < 1e-10); // max(7,14)
}
int main() int main()
{ {
try { try {
FieldVectorTest<int, 3>(); FieldVectorTest<int, 3>();
FieldVectorTest<float, 3>(); FieldVectorTest<float, 3>();
FieldVectorTest<double, 3>(); FieldVectorTest<double, 3>();
test_nan();
test_infinity_norms();
} catch (Dune::Exception& e) { } catch (Dune::Exception& e) {
std::cerr << e << std::endl; std::cerr << e << std::endl;
return 1; return 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment