KASKADE 7 development version
symmetricOperators.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2013-2019 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef SYMMETRICOPERATORS_HH
14#define SYMMETRICOPERATORS_HH
15
16#include "dune/istl/preconditioners.hh"
17
18namespace Kaskade
19{
24 template <class X, class Xstar>
26 public:
27 typedef X domain_type;
28 typedef typename X::field_type field_type;
29
30 virtual field_type operator()(X const& x, Xstar const& y) const = 0;
31 };
32
37 template <class X, class Xstar>
38 class DefaultDualPairing: public DualPairing<X,Xstar> {
40 public:
41 virtual field_type operator()(X const& x, Xstar const& y) const { return x*y; }
42 };
43
48 template <class X, class Xstar>
49 class ZeroDualPairing: public DualPairing<X,Xstar> {
51 public:
52 virtual field_type operator()(X const& , Xstar const& ) const { return 0; }
53 };
54
55 //--------------------------------------------------------------------------------------------------
56
67 template <class X, class Xstar>
68 class SymmetricLinearOperator: public Dune::LinearOperator<X,Xstar>
69 {
70 public:
71 typedef typename X::field_type field_type;
72
73
81 virtual field_type applyDp(X const& x, Xstar& y) const
82 {
83
84 this->apply(x,y);
85 return dp(x,y);
86 }
87
91 virtual field_type dp(X const& x, Xstar const& y) const = 0;
92
98 virtual Dune::SolverCategory::Category category() const override
99 {
100 return Dune::SolverCategory::sequential;
101 }
102 };
103
108 template <class X, class Matrix>
110 {
111 public:
112 typedef typename X::field_type field_type;
113
114 SymmetricMatrixOperator(Matrix const& A_)
115 : A(A_)
116 {}
117
118 virtual void apply (X const& x, X& y) const
119 {
120 A.mv(x,y);
121 }
122
123 virtual void applyscaleadd (field_type alpha, X const& x, X& y) const
124 {
125 A.usmv(alpha,x,y);
126 }
127
132 virtual field_type applyDp(X const& x, X& y) const
133 {
134 A.mv(x,y);
135 return dp(x,y);
136 }
137
141 virtual field_type dp(X const& x, X const& y) const
142 {
143 return x*y;
144 }
145
146 private:
147 Matrix const& A;
148 };
149
157 template <class X, class Xstar>
159 {
160 public:
161 typedef typename X::field_type field_type;
162
171 SymmetricLinearOperatorWrapper(Dune::LinearOperator<X,Xstar> const& A_, DualPairing<X,Xstar> const& dualPairing_)
172 : A(A_), dualPairing(dualPairing_) {}
173
174 virtual void apply(X const& x, Xstar& y) const
175 {
176 A.apply(x,y);
177 }
178
179 virtual void applyscaleadd(field_type alpha, X const& x, Xstar& y) const
180 {
181 A.applyscaleadd(alpha,x,y);
182 }
183
187 virtual field_type dp(X const& x, Xstar const& y) const
188 {
189 return dualPairing(x,y);
190 }
191
192 private:
193 Dune::LinearOperator<X,Xstar> const& A;
194 DualPairing<X,Xstar> const& dualPairing;
195 };
196
197 //--------------------------------------------------------------------------------------------------
198
207 template <class X, class Xstar>
208 class SymmetricPreconditioner: public Dune::Preconditioner<X,Xstar>
209 {
210 public:
211 typedef typename X::field_type field_type;
212
218 virtual void pre(X& , Xstar& ) {}
219
225 virtual void post(X& x) {}
226
230 virtual field_type applyDp(X& x, Xstar const& y) = 0;
231
235 virtual bool requiresInitializedInput() const = 0;
236
242 virtual Dune::SolverCategory::Category category() const override
243 {
244 return Dune::SolverCategory::sequential;
245 }
246 };
247
252 template <class X>
254 {
255 public:
256 typedef typename X::field_type field_type;
257
258 virtual void apply (X& v, const X& d)
259 {
260 v = d;
261 }
262
266 virtual field_type applyDp(X& x, X const& y)
267 {
268 x = y;
269 return x.two_norm2();
270 }
271
275 virtual bool requiresInitializedInput() const
276 {
277 return false;
278 }
279 };
280
287 template <class X, class Xstar>
289 {
290 public:
291 typedef typename X::field_type field_type;
292
301 SymmetricPreconditionerWrapper(Dune::Preconditioner<X,Xstar>& B_, DualPairing<X,Xstar> const& dualPairing_)
302 : B(B_), dualPairing(dualPairing_) {}
303
304 virtual void pre(X& x, Xstar& y)
305 {
306 B.pre(x,y);
307 }
308
309 virtual void post(X& x)
310 {
311 B.post(x);
312 }
313
319 virtual void apply(X& x, Xstar const& y)
320 {
321 B.apply(x,y);
322 }
323
329 virtual field_type applyDp(X& x, Xstar const& y)
330 {
331 B.apply(x,y);
332 return dualPairing(x,y);
333 }
334
340 virtual bool requiresInitializedInput() const { return true; }
341
342 private:
343 Dune::Preconditioner<X,Xstar>& B;
344 DualPairing<X,Xstar> const& dualPairing;
345 };
346
347} // end of namespace Kaskade
348
349#endif
Default implementation of dual pairing (relies on scalar product operator * being defined)
virtual field_type operator()(X const &x, Xstar const &y) const
Abstract base class for dual pairing of and its dual space .
virtual field_type operator()(X const &x, Xstar const &y) const =0
The trivial (identity) preconditioner.
virtual bool requiresInitializedInput() const
Returns true if the target vector x has to be initialized to zero before calling apply or applyDp.
virtual void apply(X &v, const X &d)
virtual field_type applyDp(X &x, X const &y)
Computes and returns .
Interface for symmetric linear operators.
virtual field_type dp(X const &x, Xstar const &y) const =0
returns the dual pairing with respect to which the operator is symmetric
virtual field_type applyDp(X const &x, Xstar &y) const
operator application Computes and returns the dual pairing .
virtual Dune::SolverCategory::Category category() const override
returns the category of the operator
Wrapper class to present (hopefully) symmetric linear operators in the SymmetricLinearOperator interf...
SymmetricLinearOperatorWrapper(Dune::LinearOperator< X, Xstar > const &A_, DualPairing< X, Xstar > const &dualPairing_)
Constructor.
virtual field_type dp(X const &x, Xstar const &y) const
returns the dual pairing with respect to which the operator is symmetric
virtual void applyscaleadd(field_type alpha, X const &x, Xstar &y) const
virtual void apply(X const &x, Xstar &y) const
A symmetric operator represented by a matrix.
virtual void apply(X const &x, X &y) const
virtual void applyscaleadd(field_type alpha, X const &x, X &y) const
virtual field_type applyDp(X const &x, X &y) const
operator application Computes and returns the dual pairing .
virtual field_type dp(X const &x, X const &y) const
returns the dual pairing with respect to which the operator is symmetric
Interface for symmetric preconditioners.
virtual bool requiresInitializedInput() const =0
Returns true if the target vector x has to be initialized to zero before calling apply or applyDp.
virtual void post(X &x)
Preconditioner cleanup.
virtual field_type applyDp(X &x, Xstar const &y)=0
Computes and returns .
virtual Dune::SolverCategory::Category category() const override
returns the category of the operator
virtual void pre(X &, Xstar &)
Preconditioner preparation.
Wrapper class presenting a symmetric preconditioner interface for any preconditioner.
SymmetricPreconditionerWrapper(Dune::Preconditioner< X, Xstar > &B_, DualPairing< X, Xstar > const &dualPairing_)
Constructor.
virtual void pre(X &x, Xstar &y)
Preconditioner preparation.
virtual bool requiresInitializedInput() const
Returns true if the target vector x has to be initialized to zero before calling apply or applyDp.
virtual field_type applyDp(X &x, Xstar const &y)
Computes and returns .
virtual void apply(X &x, Xstar const &y)
Computes .
virtual void post(X &x)
Preconditioner cleanup.
Zero dual pairing implementation (mainly useful whenever a dual pairing is needed for formal language...
virtual field_type operator()(X const &, Xstar const &) const