dune-istl  2.7.0
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 <dune/common/exceptions.hh>
13 
14 #include "bvector.hh"
15 #include "solvercategory.hh"
16 
17 
18 namespace Dune {
47  template<class X>
48  class ScalarProduct {
49  public:
51  typedef X domain_type;
52  typedef typename X::field_type field_type;
53  typedef typename FieldTraits<field_type>::real_type real_type;
54 
59  virtual field_type dot (const X& x, const X& y) const
60  {
61  return x.dot(y);
62  }
63 
67  virtual real_type norm (const X& x) const
68  {
69  return x.two_norm();
70  }
71 
74  {
76  }
77 
79  virtual ~ScalarProduct () {}
80  };
81 
93  template<class X, class C>
95  {
96  public:
101  typedef X domain_type;
103  typedef typename X::field_type field_type;
104  typedef typename FieldTraits<field_type>::real_type real_type;
110 
117  : _communication(com), _category(cat)
118  {}
119 
124  virtual field_type dot (const X& x, const X& y) const override
125  {
126  field_type result(0);
127  _communication.dot(x,y,result); // explicitly loop and apply masking
128  return result;
129  }
130 
134  virtual real_type norm (const X& x) const override
135  {
136  return _communication.norm(x);
137  }
138 
140  virtual SolverCategory::Category category() const override
141  {
142  return _category;
143  }
144 
145  private:
146  const communication_type& _communication;
147  SolverCategory::Category _category;
148  };
149 
151  template<class X>
152  class SeqScalarProduct : public ScalarProduct<X>
153  {
155  };
156 
162  template<class X, class C>
164  {
165  public:
167  ParallelScalarProduct<X,C>(comm,SolverCategory::nonoverlapping) {}
168  };
169 
181  template<class X, class C>
183  {
184  public:
186  ParallelScalarProduct<X,C>(comm,SolverCategory::overlapping) {}
187  };
188 
202  template<class X, class Comm>
203  std::shared_ptr<ScalarProduct<X>> createScalarProduct(const Comm& comm, SolverCategory::Category category)
204  {
205  switch(category)
206  {
208  return
209  std::make_shared<ScalarProduct<X>>();
210  default:
211  return
212  std::make_shared<ParallelScalarProduct<X,Comm>>(comm,category);
213  }
214  }
215 
216 } // end namespace Dune
217 
218 #endif
Dune::ScalarProduct::category
virtual SolverCategory::Category category() const
Category of the scalar product (see SolverCategory::Category)
Definition: scalarproducts.hh:73
Dune::OverlappingSchwarzScalarProduct::OverlappingSchwarzScalarProduct
OverlappingSchwarzScalarProduct(const C &comm)
Definition: scalarproducts.hh:185
Dune::SolverCategory::sequential
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:23
Dune::ScalarProduct::dot
virtual field_type dot(const X &x, const X &y) const
Dot product of two vectors. It is assumed that the vectors are consistent on the interior+border part...
Definition: scalarproducts.hh:59
Dune::createScalarProduct
std::shared_ptr< ScalarProduct< X > > createScalarProduct(const Comm &comm, SolverCategory::Category category)
Choose the approriate scalar product for a solver category.
Definition: scalarproducts.hh:203
Dune::ScalarProduct::real_type
FieldTraits< field_type >::real_type real_type
Definition: scalarproducts.hh:53
Dune::SolverCategory
Categories for the solvers.
Definition: solvercategory.hh:19
Dune::ParallelScalarProduct::ParallelScalarProduct
ParallelScalarProduct(const communication_type &com, SolverCategory::Category cat)
Definition: scalarproducts.hh:116
Dune::SeqScalarProduct
Default implementation for the scalar case.
Definition: scalarproducts.hh:152
Dune::ScalarProduct::~ScalarProduct
virtual ~ScalarProduct()
every abstract base class has a virtual destructor
Definition: scalarproducts.hh:79
Dune::NonoverlappingSchwarzScalarProduct::NonoverlappingSchwarzScalarProduct
NonoverlappingSchwarzScalarProduct(const C &comm)
Definition: scalarproducts.hh:166
Dune::ScalarProduct
Base class for scalar product and norm computation.
Definition: scalarproducts.hh:48
Dune::ParallelScalarProduct::norm
virtual real_type norm(const X &x) const override
Norm of a right-hand side vector. The vector must be consistent on the interior+border partition.
Definition: scalarproducts.hh:134
Dune::ScalarProduct::field_type
X::field_type field_type
Definition: scalarproducts.hh:52
Dune::ParallelScalarProduct::category
virtual SolverCategory::Category category() const override
Category of the scalar product (see SolverCategory::Category)
Definition: scalarproducts.hh:140
Dune::OverlappingSchwarzScalarProduct
Scalar product for overlapping Schwarz methods.
Definition: scalarproducts.hh:182
Dune
Definition: allocator.hh:7
Dune::ParallelScalarProduct::communication_type
C communication_type
The type of the communication object.
Definition: scalarproducts.hh:109
Dune::NonoverlappingSchwarzScalarProduct
Nonoverlapping Scalar Product with communication object.
Definition: scalarproducts.hh:163
Dune::ScalarProduct::norm
virtual real_type norm(const X &x) const
Norm of a right-hand side vector. The vector must be consistent on the interior+border partition.
Definition: scalarproducts.hh:67
solvercategory.hh
Dune::ScalarProduct::domain_type
X domain_type
export types, they come from the derived class
Definition: scalarproducts.hh:51
Dune::ParallelScalarProduct
Scalar product for overlapping Schwarz methods.
Definition: scalarproducts.hh:94
Dune::ParallelScalarProduct::domain_type
X domain_type
The type of the vector to compute the scalar product on.
Definition: scalarproducts.hh:101
Dune::ParallelScalarProduct::real_type
FieldTraits< field_type >::real_type real_type
Definition: scalarproducts.hh:104
Dune::SolverCategory::Category
Category
Definition: solvercategory.hh:21
Dune::ParallelScalarProduct::dot
virtual field_type dot(const X &x, const X &y) const override
Dot product of two vectors. It is assumed that the vectors are consistent on the interior+border part...
Definition: scalarproducts.hh:124
bvector.hh
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Dune::ParallelScalarProduct::field_type
X::field_type field_type
The field type used by the vector type domain_type.
Definition: scalarproducts.hh:103