1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #include "config.h"
4
5 // include this first to see whether it includes all necessary headers itself
6 #include <dune/istl/scaledidmatrix.hh>
7
8 #include <iostream>
9 #include <algorithm>
10
11 #include <dune/common/fvector.hh>
12 #include <dune/common/exceptions.hh>
13
14 using namespace Dune;
15
16
17 template<class K, int n>
test_matrix()18 void test_matrix()
19 {
20 ScaledIdentityMatrix<K,n> A(1);
21 FieldVector<K,n> f;
22 FieldVector<K,n> v;
23
24 // assign matrix
25 A=2;
26
27 // assign vector
28 f = 1;
29 v = 2;
30
31 // matrix vector product
32 A.umv(v,f);
33
34
35 // test norms
36 A.frobenius_norm();
37 A.frobenius_norm2();
38 A.infinity_norm();
39 A.infinity_norm_real();
40
41 std::sort(v.begin(), v.end());
42
43 // print matrix
44 std::cout << A << std::endl;
45 // print vector
46 std::cout << f << std::endl;
47
48 // Construction of FieldMatrix from ScaledIdentityMatrix
49 [[maybe_unused]] FieldMatrix<K,n,n> AFM = FieldMatrix<K,n,n>(A);
50 }
51
main()52 int main()
53 {
54 try {
55 test_matrix<float, 1>();
56 test_matrix<double, 1>();
57 //test_matrix<int, 10>(); Does not compile with icc because there is no std::sqrt(int) std::fabs(int)
58 test_matrix<double, 5>();
59 }
60 catch (Dune::Exception & e)
61 {
62 std::cerr << "Exception: " << e << std::endl;
63 }
64 }
65