Dune Core Modules (2.8.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#include <memory>
12
15
16#include "bvector.hh"
17#include "solvercategory.hh"
18
19
20namespace Dune {
49 template<class X>
51 public:
53 typedef X domain_type;
54 typedef typename X::field_type field_type;
55 typedef typename FieldTraits<field_type>::real_type real_type;
56
61 virtual field_type dot (const X& x, const X& y) const
62 {
63 return x.dot(y);
64 }
65
69 virtual real_type norm (const X& x) const
70 {
71 return x.two_norm();
72 }
73
76 {
78 }
79
81 virtual ~ScalarProduct () {}
82 };
83
95 template<class X, class C>
97 {
98 public:
103 typedef X domain_type;
105 typedef typename X::field_type field_type;
106 typedef typename FieldTraits<field_type>::real_type real_type;
112
118 ParallelScalarProduct (std::shared_ptr<const communication_type> com, SolverCategory::Category cat)
119 : _communication(com), _category(cat)
120 {}
121
130 {}
131
132
137 virtual field_type dot (const X& x, const X& y) const override
138 {
139 field_type result(0);
140 _communication->dot(x,y,result); // explicitly loop and apply masking
141 return result;
142 }
143
147 virtual real_type norm (const X& x) const override
148 {
149 return _communication->norm(x);
150 }
151
153 virtual SolverCategory::Category category() const override
154 {
155 return _category;
156 }
157
158 private:
159 std::shared_ptr<const communication_type> _communication;
160 SolverCategory::Category _category;
161 };
162
164 template<class X>
166 {
167 using ScalarProduct<X>::ScalarProduct;
168 };
169
175 template<class X, class C>
177 {
178 public:
179 NonoverlappingSchwarzScalarProduct (std::shared_ptr<const C> comm) :
181
182 NonoverlappingSchwarzScalarProduct (const C& comm) :
184 };
185
197 template<class X, class C>
199 {
200 public:
201 OverlappingSchwarzScalarProduct (std::shared_ptr<const C> comm) :
203
204 OverlappingSchwarzScalarProduct (const C& comm) :
206 };
207
221 template<class X, class Comm>
222 std::shared_ptr<ScalarProduct<X>> makeScalarProduct(std::shared_ptr<const Comm> comm, SolverCategory::Category category)
223 {
224 switch(category)
225 {
227 return
228 std::make_shared<ScalarProduct<X>>();
229 default:
230 return
231 std::make_shared<ParallelScalarProduct<X,Comm>>(comm,category);
232 }
233 }
234
239 template<class X, class Comm>
240 std::shared_ptr<ScalarProduct<X>> createScalarProduct(const Comm& comm, SolverCategory::Category category)
241 { return makeScalarProduct<X>(stackobject_to_shared_ptr(comm), category); }
242
243} // end namespace Dune
244
245#endif
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Nonoverlapping Scalar Product with communication object.
Definition: scalarproducts.hh:177
Scalar product for overlapping Schwarz methods.
Definition: scalarproducts.hh:199
Scalar product for overlapping Schwarz methods.
Definition: scalarproducts.hh:97
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:137
virtual SolverCategory::Category category() const override
Category of the scalar product (see SolverCategory::Category)
Definition: scalarproducts.hh:153
C communication_type
The type of the communication object.
Definition: scalarproducts.hh:111
ParallelScalarProduct(const communication_type &com, SolverCategory::Category cat)
Definition: scalarproducts.hh:128
X domain_type
The type of the vector to compute the scalar product on.
Definition: scalarproducts.hh:103
ParallelScalarProduct(std::shared_ptr< const communication_type > com, SolverCategory::Category cat)
Definition: scalarproducts.hh:118
X::field_type field_type
The field type used by the vector type domain_type.
Definition: scalarproducts.hh:105
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:147
Base class for scalar product and norm computation.
Definition: scalarproducts.hh:50
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:61
virtual SolverCategory::Category category() const
Category of the scalar product (see SolverCategory::Category)
Definition: scalarproducts.hh:75
X domain_type
export types, they come from the derived class
Definition: scalarproducts.hh:53
virtual ~ScalarProduct()
every abstract base class has a virtual destructor
Definition: scalarproducts.hh:81
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:69
Default implementation for the scalar case.
Definition: scalarproducts.hh:166
A few common exception classes.
Dune namespace.
Definition: alignedallocator.hh:11
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:70
std::shared_ptr< ScalarProduct< X > > createScalarProduct(const Comm &comm, SolverCategory::Category category)
Definition: scalarproducts.hh:240
std::shared_ptr< ScalarProduct< X > > makeScalarProduct(std::shared_ptr< const Comm > comm, SolverCategory::Category category)
Choose the approriate scalar product for a solver category.
Definition: scalarproducts.hh:222
This file implements several utilities related to std::shared_ptr.
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 (Nov 12, 23:30, 2024)