| 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/bvector.hh> |
| 6 |
#include<dune/istl/superlu.hh> |
| 7 |
#include<dune/istl/preconditioners.hh> |
| 8 |
#include<dune/istl/solvers.hh> |
| 9 |
#include<dune/istl/operators.hh> |
| 10 |
#include <dune/common/fmatrix.hh> |
| 11 |
#include <dune/common/fvector.hh> |
| 12 |
#include "laplacian.hh" |
| 13 |
|
| 14 |
int main(int argc, char** argv) |
| 15 |
{ |
| 16 |
const int BS=1; |
| 17 |
int N=100; |
| 18 |
|
| 19 |
if(argc>1) |
| 20 |
N = atoi(argv[1]); |
| 21 |
std::cout << "testing for N=" << N << " BS=" << BS << std::endl; |
| 22 |
|
| 23 |
typedef Dune::FieldMatrix<double,BS,BS> MatrixBlock; |
| 24 |
typedef Dune::BCRSMatrix<MatrixBlock> BCRSMat; |
| 25 |
typedef Dune::FieldVector<double,BS> VectorBlock; |
| 26 |
typedef Dune::BlockVector<VectorBlock> BVector; |
| 27 |
typedef Dune::MatrixAdapter<BCRSMat,BVector,BVector> Operator; |
| 28 |
|
| 29 |
BCRSMat mat; |
| 30 |
Operator fop(mat); |
| 31 |
BVector b(N*N), x(N*N); |
| 32 |
|
| 33 |
setupLaplacian(mat,N); |
| 34 |
b=0; |
| 35 |
x=100; |
| 36 |
|
| 37 |
Dune::InverseOperatorResult res, res1; |
| 38 |
x=1; |
| 39 |
mat.mv(x, b); |
| 40 |
x=0; |
| 41 |
Dune::SeqJac<BCRSMat,BVector,BVector> prec0(mat, 1,1.0); |
| 42 |
Dune::LoopSolver<BVector> solver0(fop, prec0, 1e-3,10,0); |
| 43 |
Dune::InverseOperator2Preconditioner<Dune::LoopSolver<BVector>> |
| 44 |
prec(solver0); |
| 45 |
Dune::LoopSolver<BVector> solver(fop, prec, 1e-8,10,2); |
| 46 |
solver.apply(x,b,res); |
| 47 |
|
| 48 |
x=1; |
| 49 |
mat.mv(x, b); |
| 50 |
x=0; |
| 51 |
std::cout<<"solver1"<<std::endl; |
| 52 |
Dune::LoopSolver<BVector> solver1(fop, prec0, 1e-8,100,2); |
| 53 |
solver1.apply(x,b,res1); |
| 54 |
|
| 55 |
if(res1.iterations!=res.iterations*10) |
| 56 |
{ |
| 57 |
std::cerr<<"Convergence rates do not match!"<<std::endl; |
| 58 |
return 1; |
| 59 |
} |
| 60 |
return 0; |
| 61 |
} |