| 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 |
#include <complex> |
| 4 |
#include <iostream> |
| 5 |
|
| 6 |
#include <dune/common/fmatrix.hh> |
| 7 |
#include <dune/common/fvector.hh> |
| 8 |
#include <dune/common/timer.hh> |
| 9 |
#include <dune/istl/bvector.hh> |
| 10 |
#include <dune/istl/io.hh> |
| 11 |
#include <dune/istl/operators.hh> |
| 12 |
#include <dune/istl/spqr.hh> |
| 13 |
|
| 14 |
#include "laplacian.hh" |
| 15 |
|
| 16 |
template <class FIELD_TYPE, int BS> |
| 17 |
void run(std::size_t N) |
| 18 |
{ |
| 19 |
#if HAVE_SUITESPARSE_SPQR |
| 20 |
std::cout << "testing for N=" << N << " BS=" << BS << std::endl; |
| 21 |
|
| 22 |
typedef Dune::FieldMatrix<FIELD_TYPE,BS,BS> MatrixBlock; |
| 23 |
typedef Dune::BCRSMatrix<MatrixBlock> BCRSMat; |
| 24 |
typedef Dune::FieldVector<FIELD_TYPE,BS> VectorBlock; |
| 25 |
typedef Dune::BlockVector<VectorBlock> Vector; |
| 26 |
typedef Dune::MatrixAdapter<BCRSMat,Vector,Vector> Operator; |
| 27 |
|
| 28 |
BCRSMat mat; |
| 29 |
Operator fop(mat); |
| 30 |
Vector b(N*N), x(N*N); |
| 31 |
|
| 32 |
setupLaplacian(mat,N); |
| 33 |
b=1; |
| 34 |
x=0; |
| 35 |
|
| 36 |
Dune::Timer watch; |
| 37 |
|
| 38 |
watch.reset(); |
| 39 |
|
| 40 |
Dune::SPQR<BCRSMat> solver(mat,1); |
| 41 |
|
| 42 |
Dune::InverseOperatorResult res; |
| 43 |
|
| 44 |
Dune::SPQR<BCRSMat> solver1; |
| 45 |
|
| 46 |
std::set<std::size_t> mrs; |
| 47 |
for(std::size_t s=0; s < N/2; ++s) |
| 48 |
mrs.insert(s); |
| 49 |
|
| 50 |
solver1.setSubMatrix(mat,mrs); |
| 51 |
solver1.setVerbosity(true); |
| 52 |
|
| 53 |
solver.apply(x,b,res); |
| 54 |
solver.free(); |
| 55 |
|
| 56 |
Vector residuum(N*N); |
| 57 |
residuum=0; |
| 58 |
fop.apply(x,residuum); |
| 59 |
residuum-=b; |
| 60 |
std::cout<<"Residuum : "<<residuum.two_norm()<<std::endl; |
| 61 |
|
| 62 |
solver1.apply(x,b,res); |
| 63 |
#endif |
| 64 |
} |
| 65 |
|
| 66 |
int main(int argc, char** argv) |
| 67 |
{ |
| 68 |
#if HAVE_SUITESPARSE_SPQR |
| 69 |
try |
| 70 |
{ |
| 71 |
std::size_t N=100; |
| 72 |
if (argc > 1) |
| 73 |
N = atoi(argv[1]); |
| 74 |
|
| 75 |
run<double,1>(N); |
| 76 |
run<double,2>(N); |
| 77 |
// run<std::complex<double>,1>(N); // does not work |
| 78 |
// run<std::complex<double>,2>(N); |
| 79 |
|
| 80 |
return 0; |
| 81 |
} |
| 82 |
catch(Dune::Exception &e) |
| 83 |
{ |
| 84 |
std::cerr << "Dune reported error: " << e << std::endl; |
| 85 |
} |
| 86 |
catch (...) |
| 87 |
{ |
| 88 |
std::cerr << "Unknown exception" << std::endl; |
| 89 |
} |
| 90 |
#else // HAVE_SUITESPARSE_SPQR |
| 91 |
std::cerr << "You need SuiteSparse's SPQR to run this test." << std::endl; |
| 92 |
return 77; |
| 93 |
#endif // HAVE_SUITESPARSE_SPQR |
| 94 |
} |