DUNE PDELab (git)

scalarproducts.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_ISTL_SCALARPRODUCTS_HH
6#define DUNE_ISTL_SCALARPRODUCTS_HH
7
8#include <cmath>
9#include <complex>
10#include <iostream>
11#include <iomanip>
12#include <string>
13#include <memory>
14
17
18#include "bvector.hh"
19#include "solvercategory.hh"
20
21
22namespace Dune {
51 template<class X>
53 public:
55 typedef X domain_type;
56 typedef typename X::field_type field_type;
57 typedef typename FieldTraits<field_type>::real_type real_type;
58
63 virtual field_type dot (const X& x, const X& y) const
64 {
65 return x.dot(y);
66 }
67
71 virtual real_type norm (const X& x) const
72 {
73 return x.two_norm();
74 }
75
78 {
80 }
81
83 virtual ~ScalarProduct () {}
84 };
85
97 template<class X, class C>
99 {
100 public:
105 typedef X domain_type;
107 typedef typename X::field_type field_type;
108 typedef typename FieldTraits<field_type>::real_type real_type;
114
120 ParallelScalarProduct (std::shared_ptr<const communication_type> com, SolverCategory::Category cat)
121 : _communication(com), _category(cat)
122 {}
123
132 {}
133
134
139 field_type dot (const X& x, const X& y) const override
140 {
141 field_type result(0);
142 _communication->dot(x,y,result); // explicitly loop and apply masking
143 return result;
144 }
145
149 real_type norm (const X& x) const override
150 {
151 return _communication->norm(x);
152 }
153
156 {
157 return _category;
158 }
159
160 private:
161 std::shared_ptr<const communication_type> _communication;
162 SolverCategory::Category _category;
163 };
164
166 template<class X>
168 {
169 using ScalarProduct<X>::ScalarProduct;
170 };
171
177 template<class X, class C>
179 {
180 public:
181 NonoverlappingSchwarzScalarProduct (std::shared_ptr<const C> comm) :
183
184 NonoverlappingSchwarzScalarProduct (const C& comm) :
186 };
187
199 template<class X, class C>
201 {
202 public:
203 OverlappingSchwarzScalarProduct (std::shared_ptr<const C> comm) :
205
206 OverlappingSchwarzScalarProduct (const C& comm) :
208 };
209
223 template<class X, class Comm>
224 std::shared_ptr<ScalarProduct<X>> makeScalarProduct(std::shared_ptr<const Comm> comm, SolverCategory::Category category)
225 {
226 switch(category)
227 {
229 return
230 std::make_shared<ScalarProduct<X>>();
231 default:
232 return
233 std::make_shared<ParallelScalarProduct<X,Comm>>(comm,category);
234 }
235 }
236
241 template<class X, class Comm>
242 std::shared_ptr<ScalarProduct<X>> createScalarProduct(const Comm& comm, SolverCategory::Category category)
243 { return makeScalarProduct<X>(stackobject_to_shared_ptr(comm), category); }
244
245} // end namespace Dune
246
247#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:179
Scalar product for overlapping Schwarz methods.
Definition: scalarproducts.hh:201
Scalar product for overlapping Schwarz methods.
Definition: scalarproducts.hh:99
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:139
C communication_type
The type of the communication object.
Definition: scalarproducts.hh:113
ParallelScalarProduct(const communication_type &com, SolverCategory::Category cat)
Definition: scalarproducts.hh:130
X domain_type
The type of the vector to compute the scalar product on.
Definition: scalarproducts.hh:105
ParallelScalarProduct(std::shared_ptr< const communication_type > com, SolverCategory::Category cat)
Definition: scalarproducts.hh:120
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:149
SolverCategory::Category category() const override
Category of the scalar product (see SolverCategory::Category)
Definition: scalarproducts.hh:155
X::field_type field_type
The field type used by the vector type domain_type.
Definition: scalarproducts.hh:107
Base class for scalar product and norm computation.
Definition: scalarproducts.hh:52
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:63
virtual SolverCategory::Category category() const
Category of the scalar product (see SolverCategory::Category)
Definition: scalarproducts.hh:77
X domain_type
export types, they come from the derived class
Definition: scalarproducts.hh:55
virtual ~ScalarProduct()
every abstract base class has a virtual destructor
Definition: scalarproducts.hh:83
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:71
Default implementation for the scalar case.
Definition: scalarproducts.hh:168
A few common exception classes.
Dune namespace.
Definition: alignedallocator.hh:13
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
std::shared_ptr< ScalarProduct< X > > createScalarProduct(const Comm &comm, SolverCategory::Category category)
Definition: scalarproducts.hh:242
std::shared_ptr< ScalarProduct< X > > makeScalarProduct(std::shared_ptr< const Comm > comm, SolverCategory::Category category)
Choose the appropriate scalar product for a solver category.
Definition: scalarproducts.hh:224
This file implements several utilities related to std::shared_ptr.
Category
Definition: solvercategory.hh:23
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:25
@ nonoverlapping
Category for non-overlapping solvers.
Definition: solvercategory.hh:27
@ overlapping
Category for overlapping solvers.
Definition: solvercategory.hh:29
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)