dune-istl  3.0-git
scalarproducts.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_ISTL_SCALARPRODUCTS_HH
4 #define DUNE_ISTL_SCALARPRODUCTS_HH
5 
6 #include <cmath>
7 #include <complex>
8 #include <iostream>
9 #include <iomanip>
10 #include <string>
11 
12 #include "bvector.hh"
13 #include "solvercategory.hh"
14 
15 
16 namespace Dune {
43  template<class X>
44  class ScalarProduct {
45  public:
47  typedef X domain_type;
48  typedef typename X::field_type field_type;
49  typedef typename FieldTraits<field_type>::real_type real_type;
50 
55  virtual field_type dot (const X& x, const X& y) = 0;
56 
60  virtual real_type norm (const X& x) = 0;
61 
63  virtual ~ScalarProduct () {}
64  };
65 
75  template<class X, class C, int c>
77  {
79  typedef C communication_type;
80 
81  enum {
83  solverCategory=c
84  };
85  };
86 
87 
88 
89  //=====================================================================
90  // Implementation for ISTL-matrix based operator
91  //=====================================================================
92 
94  template<class X>
95  class SeqScalarProduct : public ScalarProduct<X>
96  {
97  public:
99  typedef X domain_type;
100  typedef typename X::field_type field_type;
101  typedef typename FieldTraits<field_type>::real_type real_type;
102 
104  enum {category=SolverCategory::sequential};
105 
110  virtual field_type dot (const X& x, const X& y)
111  {
112  return x.dot(y);
113  }
114 
118  virtual real_type norm (const X& x)
119  {
120  return x.two_norm();
121  }
122  };
123 
124  template<class X, class C>
125  struct ScalarProductChooser<X,C,SolverCategory::sequential>
126  {
129 
130  enum {
133  };
134 
135  static ScalarProduct* construct(const C&)
136  {
137  return new ScalarProduct();
138  }
139  };
140 
141 
144 } // end namespace
145 
146 #endif
Default implementation for the scalar case.
Definition: scalarproducts.hh:95
X::field_type field_type
Definition: scalarproducts.hh:48
Category for sequential solvers.
Definition: solvercategory.hh:21
Categories for the solvers.
Definition: solvercategory.hh:17
virtual field_type dot(const X &x, const X &y)=0
Dot product of two vectors. It is assumed that the vectors are consistent on the interior+border part...
static ScalarProduct * construct(const C &)
Definition: scalarproducts.hh:135
C communication_type
The type of the communication object.
Definition: scalarproducts.hh:79
FieldTraits< field_type >::real_type real_type
Definition: scalarproducts.hh:49
Definition: basearray.hh:19
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Choose the approriate scalar product for a solver category.
Definition: scalarproducts.hh:76
SeqScalarProduct< X > ScalarProduct
The type of the scalar product for the sequential case.
Definition: scalarproducts.hh:128
virtual real_type norm(const X &x)
Norm of a right-hand side vector. The vector must be consistent on the interior+border partition...
Definition: scalarproducts.hh:118
FieldTraits< field_type >::real_type real_type
Definition: scalarproducts.hh:101
X domain_type
export types
Definition: scalarproducts.hh:99
virtual field_type dot(const X &x, const X &y)
Dot product of two vectors. In the complex case, the first argument is conjugated. It is assumed that the vectors are consistent on the interior+border partition.
Definition: scalarproducts.hh:110
X domain_type
export types, they come from the derived class
Definition: scalarproducts.hh:47
X::field_type field_type
Definition: scalarproducts.hh:100
Base class for scalar product and norm computation.
Definition: scalarproducts.hh:44
virtual real_type norm(const X &x)=0
Norm of a right-hand side vector. The vector must be consistent on the interior+border partition...
virtual ~ScalarProduct()
every abstract base class has a virtual destructor
Definition: scalarproducts.hh:63