| 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/exceptions.hh> |
| 8 |
|
| 9 |
#include <dune/common/simd/loop.hh> |
| 10 |
|
| 11 |
#include <dune/istl/bvector.hh> |
| 12 |
#include <dune/istl/bcrsmatrix.hh> |
| 13 |
#include <dune/istl/io.hh> |
| 14 |
|
| 15 |
#include <dune/istl/preconditioners.hh> |
| 16 |
|
| 17 |
#include "hilbertmatrix.hh" |
| 18 |
|
| 19 |
|
| 20 |
template< template< class, class, class, int ... > class _Prec, class MatrixBlock, class VectorBlock > |
| 21 |
void testDecomposition ( int n ) |
| 22 |
{ |
| 23 |
using BlockMatrix = Dune::BCRSMatrix< MatrixBlock >; |
| 24 |
using BlockVector = Dune::BlockVector< VectorBlock >; |
| 25 |
|
| 26 |
using Prec = _Prec< BlockMatrix, BlockVector, BlockVector >; |
| 27 |
|
| 28 |
BlockMatrix A; |
| 29 |
setupHilbertMatrix( A, n ); |
| 30 |
|
| 31 |
Prec prec( A, 1.0 ); |
| 32 |
|
| 33 |
for ( int i = 0; i < n; ++i ) |
| 34 |
{ |
| 35 |
BlockVector x( n ), y( n ), b( n ); |
| 36 |
y = 0.0; |
| 37 |
y[ i ] = 1.0; |
| 38 |
A.mv( y, b ); |
| 39 |
prec.pre( x, b ); |
| 40 |
prec.apply( x, b ); |
| 41 |
prec.post( x ); |
| 42 |
|
| 43 |
y -= x; |
| 44 |
if ( Dune::Simd::anyTrue(y.two_norm() > 1e-8) ) |
| 45 |
DUNE_THROW( Dune::Exception, "Method Prec::apply() returned wrong value!"); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
int main(int argc, char** argv) |
| 51 |
try { |
| 52 |
|
| 53 |
testDecomposition< Dune::SeqILDL, double, double >( 4 ); |
| 54 |
testDecomposition< Dune::SeqILU, double, double >( 4 ); |
| 55 |
testDecomposition< Dune::SeqILDL, Dune::FieldMatrix<double,1,1>, Dune::FieldVector<double,1> >( 4 ); |
| 56 |
testDecomposition< Dune::SeqILU, Dune::FieldMatrix<double,1,1>, Dune::FieldVector<double,1> >( 4 ); |
| 57 |
testDecomposition<Dune::SeqILU, Dune::LoopSIMD<double, 4>, Dune::LoopSIMD<double, 4>>( 4 ); |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |
| 61 |
catch(Dune::Exception &e) |
| 62 |
{ |
| 63 |
std::cerr << "Dune reported error: " << e << std::endl; |
| 64 |
} |
| 65 |
catch (...) |
| 66 |
{ |
| 67 |
std::cerr << "Unknown exception" << std::endl; |
| 68 |
} |