solver.hpp 1.58 KB
Newer Older
1
// Software License for MTL
2
3
//
// Copyright (c) 2007 The Trustees of Indiana University.
4
//               2008 Dresden University of Technology and the Trustees of Indiana University.
5
//               2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
6
7
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
8
//
9
// This file is part of the Matrix Template Library
10
//
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// See also license.mtl.txt in the distribution.

#ifndef ITL_PC_SOLVER_INCLUDE
#define ITL_PC_SOLVER_INCLUDE

#include <boost/mpl/bool.hpp>
#include <boost/numeric/mtl/vector/assigner.hpp>
#include <boost/numeric/mtl/interface/vpt.hpp>

namespace itl { namespace pc {

/// Helper class for delayed (i.e. copy-free) evaluation of preconditioners
template <typename PC, typename Vector, bool adjoint= false>
struct solver
  : mtl::vector::assigner<solver<PC, Vector> >
{
    typedef PC  pc_type;

    /// Constructor taking preconditioner and source vector
    solver(const pc_type& P, const Vector& x) : P(P), x(x) {}

    /// Assign result to vector \p y, if possible without copying
    template <typename VectorOut>
    void assign_to(VectorOut& y) const
35
    {
36
	mtl::vampir_trace<5055> tracer;
37
38
	assign_to(y, boost::mpl::bool_<adjoint>());
    }
39
40
41
42
43

  protected:

    template <typename VectorOut>
    void assign_to(VectorOut& y, boost::mpl::false_) const
44
45
    {	P.solve(x, y);    }

46
47
    template <typename VectorOut>
    void assign_to(VectorOut& y, boost::mpl::true_) const
48
    {	P.adjoint_solve(x, y);    }
49

50
    const pc_type&        P;
51
52
53
54
55
56
    const Vector&         x;
};

}} // namespace itl::pc

#endif // ITL_PC_SOLVER_INCLUDE