KASKADE 7 development version
partialDirectPreconditioner.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2002-2012 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef PARTIAL_DIRECT_PRECONDITIONER_HH
14#define PARTIAL_DIRECT_PRECONDITIONER_HH
15
16#include <dune/istl/preconditioners.hh>
17#include <dune/istl/solvercategory.hh>
18
19#include "fem/istlinterface.hh"
21
22namespace Kaskade
23{
24
50 template <class Op>
51 class PartialDirectPreconditioner: public Dune::Preconditioner<typename Op::Domain, typename Op::Range>
52 {
53 typedef typename Op::Domain Domain;
54 typedef typename Op::Domain Range;
55 typedef typename GetScalar<Domain>::type Scalar;
56
57 public:
58 static int const category = Dune::SolverCategory::sequential;
59
66 PartialDirectPreconditioner(Op const& op, size_t first, size_t last,
68 {
69 MatrixAsTriplet<Scalar> A = op.template get<MatrixAsTriplet<Scalar> >();
70
71 // Delete all the off-diagonal entries whose indices are not
72 // contained in [first,last)x[first,last).
73 size_t out = 0;
74 for (size_t in=0; in<A.nnz(); ++in)
75 if (A.ridx[in]==A.cidx[in] || (A.ridx[in]>=first && A.ridx[in]<last && A.cidx[in]>=first && A.cidx[in]<last)) {
76 A.ridx[out] = A.ridx[in];
77 A.cidx[out] = A.cidx[in];
78 A.data[out] = A.data[in];
79 ++out;
80 }
81 A.ridx.erase(A.ridx.begin()+out,A.ridx.end());
82 A.cidx.erase(A.cidx.begin()+out,A.cidx.end());
83 A.data.erase(A.data.begin()+out,A.data.end());
84
85 solver.reset(getFactorization(directType,A,typename Factorization<Scalar>::Options(matprop)).release());
86 }
87
88 virtual void pre(Domain&, Range&) {}
89 virtual void post (Domain&) {}
90
91 virtual void apply (Domain& x, Range const& y) {
92 std::vector<Scalar> b(y.dim());
93 y.write(b.begin());
94 solver->solve(b);
95 x.read(b.begin());
96 }
97
98 private:
99 std::unique_ptr<Factorization<Scalar> > solver;
100 };
101
102} // namespace Kaskade
103#endif
size_t nnz() const
Definition: triplet.hh:254
std::vector< SparseIndexInt > ridx
row indices
Definition: triplet.hh:669
std::vector< SparseIndexInt > cidx
column indices
Definition: triplet.hh:671
std::vector< Scalar > data
data
Definition: triplet.hh:673
DEPRECATED A partial direct preconditioner applicable to assembled operators.
PartialDirectPreconditioner(Op const &op, size_t first, size_t last, DirectType directType=DirectType::UMFPACK, MatrixProperties matprop=MatrixProperties::SYMMETRIC)
virtual void apply(Domain &x, Range const &y)
std::unique_ptr< Factorization< Scalar > > getFactorization(DirectType directType, MatrixAsTriplet< Scalar, Index > const &A, FactorizationOptions options)
Creates a factorization of the given triplet matrix.
DirectType
Available direct solvers for linear equation systems.
Definition: enums.hh:35
@ UMFPACK
UMFPack from SuiteSparse, using 32 bit integer indices.
MatrixProperties
Characterizations of sparse matrix properties.
Definition: enums.hh:76
The Options struct allows to specify several options of factorization.
!std ::is_same< decltype(hasFieldType< Type >(0)), TypeNotFound >::value ::type type