Dune Core Modules (2.6.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
13
14#include "bvector.hh"
15#include "solvercategory.hh"
16
17
18namespace Dune {
45 template<class X>
47 public:
49 typedef X domain_type;
50 typedef typename X::field_type field_type;
51 typedef typename FieldTraits<field_type>::real_type real_type;
52
57 virtual field_type dot (const X& x, const X& y) = 0;
58
62 virtual real_type norm (const X& x) = 0;
63
66#if DUNE_ISTL_SUPPORT_OLD_CATEGORY_INTERFACE
67 {
68 DUNE_THROW(Dune::Exception,"It is necessary to implement the category method in a derived classes, in the future this method will pure virtual.");
69 }
70#else
71 = 0;
72#endif
73
75 virtual ~ScalarProduct () {}
76 };
77
78 //=====================================================================
79 // Implementation for ISTL-matrix based operator
80 //=====================================================================
81
83 template<class X>
85 {
86 public:
88 typedef X domain_type;
89 typedef typename X::field_type field_type;
90 typedef typename FieldTraits<field_type>::real_type real_type;
91
96 virtual field_type dot (const X& x, const X& y)
97 {
98 return x.dot(y);
99 }
100
104 virtual real_type norm (const X& x)
105 {
106 return x.two_norm();
107 }
108
111 {
113 }
114
115 };
116
122 template<class X, class C>
124 {
125 public:
127 typedef X domain_type;
129 typedef typename X::field_type field_type;
131 typedef typename FieldTraits<field_type>::real_type real_type;
134
140 : communication(com)
141 {}
142
147 virtual field_type dot (const X& x, const X& y)
148 {
149 field_type result(0);
150 communication.dot(x,y,result);
151 return result;
152 }
153
157 virtual real_type norm (const X& x)
158 {
159 return communication.norm(x);
160 }
161
164 {
166 }
167
170 void make_consistent (X& x) const
171 {
172 communication.copyOwnerToAll(x,x);
173 }
174
175 private:
176 const communication_type& communication;
177 };
178
190 template<class X, class C>
192 {
193 public:
198 typedef X domain_type;
200 typedef typename X::field_type field_type;
201 typedef typename FieldTraits<field_type>::real_type real_type;
207
213 : communication(com)
214 {}
215
220 virtual field_type dot (const X& x, const X& y)
221 {
222 field_type result(0);
223 communication.dot(x,y,result);
224 return result;
225 }
226
230 virtual real_type norm (const X& x)
231 {
232 return communication.norm(x);
233 }
234
237 {
239 }
240
241 private:
242 const communication_type& communication;
243 };
244
258 template<class X, class Comm>
259 std::shared_ptr<ScalarProduct<X>> createScalarProduct(const Comm& comm, SolverCategory::Category category)
260 {
261 switch(category)
262 {
264 return
265 std::make_shared<SeqScalarProduct<X>>();
267 return
268 std::make_shared<NonoverlappingSchwarzScalarProduct<X,Comm>>(comm);
270 return
271 std::make_shared<OverlappingSchwarzScalarProduct<X,Comm>>(comm);
272 default:
273 DUNE_THROW(InvalidStateException, "unknown solver category");
274 }
275 }
276
277} // end namespace Dune
278
279#endif
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Base class for Dune-Exceptions.
Definition: exceptions.hh:94
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:279
Nonoverlapping Scalar Product with communication object.
Definition: scalarproducts.hh:124
virtual SolverCategory::Category category() const
Category of the scalar product (see SolverCategory::Category)
Definition: scalarproducts.hh:163
FieldTraits< field_type >::real_type real_type
The real-type of the range.
Definition: scalarproducts.hh:131
X domain_type
The type of the domain.
Definition: scalarproducts.hh:127
X::field_type field_type
The type of the range.
Definition: scalarproducts.hh:129
C communication_type
The type of the communication object.
Definition: scalarproducts.hh:133
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:157
void make_consistent(X &x) const
make additive vector consistent
Definition: scalarproducts.hh:170
virtual field_type dot(const X &x, const X &y)
Dot product of two vectors. It is assumed that the vectors are consistent on the interior+border part...
Definition: scalarproducts.hh:147
NonoverlappingSchwarzScalarProduct(const communication_type &com)
Constructor.
Definition: scalarproducts.hh:139
Scalar product for overlapping schwarz methods.
Definition: scalarproducts.hh:192
C communication_type
The type of the communication object.
Definition: scalarproducts.hh:206
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:230
virtual SolverCategory::Category category() const
Category of the scalar product (see SolverCategory::Category)
Definition: scalarproducts.hh:236
virtual field_type dot(const X &x, const X &y)
Dot product of two vectors. It is assumed that the vectors are consistent on the interior+border part...
Definition: scalarproducts.hh:220
X domain_type
The type of the vector to compute the scalar product on.
Definition: scalarproducts.hh:198
X::field_type field_type
The field type used by the vector type domain_type.
Definition: scalarproducts.hh:200
OverlappingSchwarzScalarProduct(const communication_type &com)
Constructor needs to know the grid.
Definition: scalarproducts.hh:212
Base class for scalar product and norm computation.
Definition: scalarproducts.hh:46
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...
X domain_type
export types, they come from the derived class
Definition: scalarproducts.hh:49
virtual SolverCategory::Category category() const =0
Category of the scalar product (see SolverCategory::Category)
virtual ~ScalarProduct()
every abstract base class has a virtual destructor
Definition: scalarproducts.hh:75
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.
Default implementation for the scalar case.
Definition: scalarproducts.hh:85
X domain_type
export types
Definition: scalarproducts.hh:88
virtual SolverCategory::Category category() const
Category of the scalar product (see SolverCategory::Category)
Definition: scalarproducts.hh:110
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:104
virtual field_type dot(const X &x, const X &y)
Dot product of two vectors. In the complex case, the first argument is conjugated....
Definition: scalarproducts.hh:96
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:10
std::shared_ptr< ScalarProduct< X > > createScalarProduct(const Comm &comm, SolverCategory::Category category)
Choose the approriate scalar product for a solver category.
Definition: scalarproducts.hh:259
Category
Definition: solvercategory.hh:21
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:23
@ nonoverlapping
Category for non-overlapping solvers.
Definition: solvercategory.hh:25
@ overlapping
Category for overlapping solvers.
Definition: solvercategory.hh:27
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)