| 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/io.hh> |
| 6 |
#include <dune/istl/bvector.hh> |
| 7 |
#include <dune/istl/operators.hh> |
| 8 |
#include <dune/common/fmatrix.hh> |
| 9 |
#include <dune/common/fvector.hh> |
| 10 |
#include <dune/common/timer.hh> |
| 11 |
#include <dune/istl/overlappingschwarz.hh> |
| 12 |
#include <dune/istl/solvers.hh> |
| 13 |
#include "laplacian.hh" |
| 14 |
|
| 15 |
#include <complex> |
| 16 |
#include <iterator> |
| 17 |
|
| 18 |
namespace Dune |
| 19 |
{ |
| 20 |
using Vec1 = BlockVector<FieldVector<double,1>>; |
| 21 |
using Vec2 = BlockVector<FieldVector<std::complex<double>,1>>; |
| 22 |
|
| 23 |
// explicit template instantiation of all iterative solvers |
| 24 |
|
| 25 |
// field_type = double |
| 26 |
template class InverseOperator<Vec1,Vec1>; |
| 27 |
template class LoopSolver<Vec1>; |
| 28 |
template class GradientSolver<Vec1>; |
| 29 |
template class CGSolver<Vec1>; |
| 30 |
template class BiCGSTABSolver<Vec1>; |
| 31 |
template class MINRESSolver<Vec1>; |
| 32 |
template class RestartedGMResSolver<Vec1>; |
| 33 |
template class RestartedFlexibleGMResSolver<Vec1>; |
| 34 |
template class GeneralizedPCGSolver<Vec1>; |
| 35 |
template class RestartedFCGSolver<Vec1>; |
| 36 |
template class CompleteFCGSolver<Vec1>; |
| 37 |
|
| 38 |
// field_type = complex<double> |
| 39 |
template class InverseOperator<Vec2,Vec2>; |
| 40 |
template class LoopSolver<Vec2>; |
| 41 |
template class GradientSolver<Vec2>; |
| 42 |
template class CGSolver<Vec2>; |
| 43 |
template class BiCGSTABSolver<Vec2>; |
| 44 |
template class MINRESSolver<Vec2>; |
| 45 |
template class RestartedGMResSolver<Vec2>; |
| 46 |
template class RestartedFlexibleGMResSolver<Vec2>; |
| 47 |
template class GeneralizedPCGSolver<Vec2>; |
| 48 |
template class RestartedFCGSolver<Vec2>; |
| 49 |
template class CompleteFCGSolver<Vec2>; |
| 50 |
|
| 51 |
} // end namespace Dune |
| 52 |
|
| 53 |
|
| 54 |
int main(int argc, char** argv) |
| 55 |
{ |
| 56 |
|
| 57 |
const int BS=1; |
| 58 |
int N=100; |
| 59 |
|
| 60 |
if(argc>1) |
| 61 |
N = atoi(argv[1]); |
| 62 |
std::cout << "testing for N=" << N << " BS=" << BS << std::endl; |
| 63 |
|
| 64 |
|
| 65 |
typedef Dune::FieldMatrix<double,BS,BS> MatrixBlock; |
| 66 |
typedef Dune::BCRSMatrix<MatrixBlock> BCRSMat; |
| 67 |
typedef Dune::FieldVector<double,BS> VectorBlock; |
| 68 |
typedef Dune::BlockVector<VectorBlock> BVector; |
| 69 |
typedef Dune::MatrixAdapter<BCRSMat,BVector,BVector> Operator; |
| 70 |
|
| 71 |
BCRSMat mat; |
| 72 |
const Operator fop(mat); |
| 73 |
BVector b(N*N), x(N*N); |
| 74 |
|
| 75 |
setupLaplacian(mat,N); |
| 76 |
b=0; |
| 77 |
x=100; |
| 78 |
Dune::Timer watch; |
| 79 |
|
| 80 |
watch.reset(); |
| 81 |
|
| 82 |
Dune::InverseOperatorResult res; |
| 83 |
x=1; |
| 84 |
mat.mv(x, b); |
| 85 |
x=0; |
| 86 |
Dune::SeqJac<BCRSMat,BVector,BVector> prec0(mat, 1,1.0); |
| 87 |
Dune::GeneralizedPCGSolver<BVector> solver0(fop, prec0, 1e-3,10,2); |
| 88 |
solver0.apply(x,b, res); |
| 89 |
|
| 90 |
b=0; |
| 91 |
x=1; |
| 92 |
mat.mv(x, b); |
| 93 |
x=0; |
| 94 |
|
| 95 |
Dune::CGSolver<BVector> solver1(fop, prec0, 1e-3,10,2); |
| 96 |
solver1.apply(x,b, res); |
| 97 |
|
| 98 |
b=0; |
| 99 |
x=1; |
| 100 |
mat.mv(x, b); |
| 101 |
x=99; |
| 102 |
|
| 103 |
Dune::BiCGSTABSolver<BVector> solver2(fop, prec0, 1e-3,10,2); |
| 104 |
solver2.apply(x,b, res); |
| 105 |
|
| 106 |
b=0; |
| 107 |
x=1; |
| 108 |
mat.mv(x, b); |
| 109 |
x=99; |
| 110 |
|
| 111 |
Dune::RestartedGMResSolver<BVector> solver3(fop, prec0, 1e-3,5,20,2); |
| 112 |
solver3.apply(x,b, res); |
| 113 |
|
| 114 |
b = 0; |
| 115 |
x = 1; |
| 116 |
mat.mv(x, b); |
| 117 |
x = 0; |
| 118 |
|
| 119 |
Dune::RestartedFCGSolver<BVector> solver4(fop, prec0, 1e-3,10,2); |
| 120 |
solver4.apply(x, b, res); |
| 121 |
|
| 122 |
b = 0; |
| 123 |
x = 1; |
| 124 |
mat.mv(x, b); |
| 125 |
x = 0; |
| 126 |
|
| 127 |
Dune::CompleteFCGSolver<BVector> solver5(fop, prec0, 1e-3,10,2); |
| 128 |
solver5.apply(x, b, res); |
| 129 |
|
| 130 |
b = 0; |
| 131 |
x = 1; |
| 132 |
mat.mv(x, b); |
| 133 |
x = 99; |
| 134 |
|
| 135 |
Dune::RestartedFlexibleGMResSolver<BVector> solver6(fop, prec0, 1e-3, 5, 20, 2); |
| 136 |
solver6.apply(x,b, res); |
| 137 |
|
| 138 |
return 0; |
| 139 |
} |