dune-istl  2.4
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 "solvercategory.hh"
13 
14 
15 namespace Dune {
42  template<class X>
43  class ScalarProduct {
44  public:
46  typedef X domain_type;
47  typedef typename X::field_type field_type;
48 
53  virtual field_type dot (const X& x, const X& y) = 0;
54 
58  virtual double norm (const X& x) = 0;
59 
60 
62  virtual ~ScalarProduct () {}
63  };
64 
74  template<class X, class C, int c>
76  {
78  typedef C communication_type;
79 
80  enum {
83  };
84  };
85 
86 
87 
88  //=====================================================================
89  // Implementation for ISTL-matrix based operator
90  //=====================================================================
91 
93  template<class X>
94  class SeqScalarProduct : public ScalarProduct<X>
95  {
96  public:
98  typedef X domain_type;
99  typedef typename X::field_type field_type;
100 
103 
108  virtual field_type dot (const X& x, const X& y)
109  {
110  return x.dot(y);
111  }
112 
116  virtual double norm (const X& x)
117  {
118  return static_cast<double>(x.two_norm());
119  }
120  };
121 
122  template<class X, class C>
123  struct ScalarProductChooser<X,C,SolverCategory::sequential>
124  {
127 
128  enum {
131  };
132 
133  static ScalarProduct* construct(const C&)
134  {
135  return new ScalarProduct();
136  }
137  };
138 
139 
142 } // end namespace
143 
144 #endif
X::field_type field_type
Definition: scalarproducts.hh:99
Base class for scalar product and norm computation.
Definition: scalarproducts.hh:43
Definition: basearray.hh:19
virtual double 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:62
virtual double norm(const X &x)
Norm of a right-hand side vector. The vector must be consistent on the interior+border partition...
Definition: scalarproducts.hh:116
Categories for the solvers.
Definition: solvercategory.hh:17
X domain_type
export types, they come from the derived class
Definition: scalarproducts.hh:46
SeqScalarProduct< X > ScalarProduct
The type of the scalar product for the sequential case.
Definition: scalarproducts.hh:126
Category for sequential solvers.
Definition: solvercategory.hh:21
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:108
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...
The solver category.
Definition: scalarproducts.hh:82
static ScalarProduct * construct(const C &)
Definition: scalarproducts.hh:133
Definition: scalarproducts.hh:102
C communication_type
The type of the communication object.
Definition: scalarproducts.hh:78
Choose the approriate scalar product for a solver category.
Definition: scalarproducts.hh:75
Default implementation for the scalar case.
Definition: scalarproducts.hh:94
X domain_type
export types
Definition: scalarproducts.hh:98
X::field_type field_type
Definition: scalarproducts.hh:47