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