Debian Codegraph @

dune/istl/test/matrixutilstest.cc

raw
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #include <dune/istl/matrixutils.hh>
6 #include <dune/istl/bcrsmatrix.hh>
7 #include <dune/common/fmatrix.hh>
8 #include <dune/common/stdstreams.hh>
9 #include "laplacian.hh"
10
11 int main(int argc, char** argv)
12 {
13 Dune::FieldMatrix<double,4,7> fmatrix;
14
15 int ret=0;
16
17 if(4*7!=countNonZeros(fmatrix)) {
18 Dune::derr<<"Counting nonzeros of fieldMatrix failed!"<<std::endl;
19 ret++;
20 }
21
22 const int N=4;
23
24 // Test sparse matrix with scalar entries
25 Dune::BCRSMatrix<double> slaplace;
26 setupLaplacian(slaplace, N);
27
28 if(N*N*5-4*2-(N-2)*4!=countNonZeros(slaplace)) {
29 ++ret;
30 Dune::derr<<"Counting nonzeros of BCRSMatrix<double> failed!"<<std::endl;
31 }
32
33 typedef Dune::BCRSMatrix<Dune::FieldMatrix<double,1,1> > BMatrix;
34
35 BMatrix laplace;
36 setupLaplacian(laplace, N);
37
38 if(N*N*5-4*2-(N-2)*4!=countNonZeros(laplace)) {
39 ++ret;
40 Dune::derr<<"Counting nonzeros of BCRSMatrix failed!"<<std::endl;
41 }
42
43 Dune::BCRSMatrix<Dune::FieldMatrix<double,4,7> > blaplace;
44 setupLaplacian(blaplace,N);
45
46 if((N*N*5-4*2-(N-2)*4)*4*7!=countNonZeros(blaplace)) {
47 ++ret;
48 Dune::derr<<"Counting nonzeros of block BCRSMatrix failed!"<<std::endl;
49 }
50
51 Dune::BCRSMatrix<Dune::FieldMatrix<double,4,7> > bblaplace;
52 bblaplace.setSize(N*N,N*N, N*N*5);
53 bblaplace.setBuildMode(Dune::BCRSMatrix<Dune::FieldMatrix<double,4,7> >::row_wise);
54 setupLaplacian(bblaplace,N);
55
56 if((N*N*5-4*2-(N-2)*4)*4*7!=countNonZeros(bblaplace)) {
57 ++ret;
58 Dune::derr<<"Counting nonzeros of block BCRSMatrix failed!"<<std::endl;
59 }
60
61 return ret;
62 }