KASKADE 7 development version
Loading...
Searching...
No Matches
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> {
39 typedef typename DualPairing<X,Xstar>::field_type field_type;
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> {
50 typedef typename DualPairing<X,Xstar>::field_type field_type;
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
121 : A(A_)
122 {}
123
124 virtual void apply (X const& x, X& y) const override
125 {
126 A.mv(x,y);
127 }
128
129 virtual void applyscaleadd (field_type alpha, X const& x, X& y) const override
130 {
131 A.usmv(alpha,x,y);
132 }
133
138 virtual field_type applyDp(X const& x, X& y) const override
139 {
140 A.mv(x,y);
141 return dp(x,y);
142 }
143
147 virtual field_type dp(X const& x, X const& y) const override
148 {
149 return x*y;
150 }
151
152 private:
153 Matrix const& A;
154 };
155
163 template <class X, class Xstar>
165 {
166 public:
167 typedef typename X::field_type field_type;
168
177 SymmetricLinearOperatorWrapper(Dune::LinearOperator<X,Xstar> const& A_, DualPairing<X,Xstar> const& dualPairing_)
178 : A(A_), dualPairing(dualPairing_) {}
179
180 virtual void apply(X const& x, Xstar& y) const
181 {
182 A.apply(x,y);
183 }
184
185 virtual void applyscaleadd(field_type alpha, X const& x, Xstar& y) const
186 {
187 A.applyscaleadd(alpha,x,y);
188 }
189
193 virtual field_type dp(X const& x, Xstar const& y) const
194 {
195 return dualPairing(x,y);
196 }
197
198 private:
199 Dune::LinearOperator<X,Xstar> const& A;
200 DualPairing<X,Xstar> const& dualPairing;
201 };
202
203 //--------------------------------------------------------------------------------------------------
204
213 template <class X, class Xstar>
214 class SymmetricPreconditioner: public Dune::Preconditioner<X,Xstar>
215 {
216 public:
217 typedef typename X::field_type field_type;
218
224 virtual void pre(X& , Xstar& ) {}
225
231 virtual void post(X& x) {}
232
236 virtual field_type applyDp(X& x, Xstar const& y) = 0;
237
241 virtual bool requiresInitializedInput() const = 0;
242
248 virtual Dune::SolverCategory::Category category() const override
249 {
250 return Dune::SolverCategory::sequential;
251 }
252 };
253
258 template <class X>
260 {
261 public:
262 typedef typename X::field_type field_type;
263
264 virtual void apply (X& v, const X& d)
265 {
266 v = d;
267 }
268
272 virtual field_type applyDp(X& x, X const& y)
273 {
274 x = y;
275 return x.two_norm2();
276 }
277
281 virtual bool requiresInitializedInput() const
282 {
283 return false;
284 }
285 };
286
293 template <class X, class Xstar>
295 {
296 public:
297 typedef typename X::field_type field_type;
298
307 SymmetricPreconditionerWrapper(Dune::Preconditioner<X,Xstar>& B_, DualPairing<X,Xstar> const& dualPairing_)
308 : B(B_), dualPairing(dualPairing_) {}
309
310 virtual void pre(X& x, Xstar& y)
311 {
312 B.pre(x,y);
313 }
314
315 virtual void post(X& x)
316 {
317 B.post(x);
318 }
319
325 virtual void apply(X& x, Xstar const& y)
326 {
327 B.apply(x,y);
328 }
329
335 virtual field_type applyDp(X& x, Xstar const& y)
336 {
337 B.apply(x,y);
338 return dualPairing(x,y);
339 }
340
346 virtual bool requiresInitializedInput() const { return true; }
347
348 private:
349 Dune::Preconditioner<X,Xstar>& B;
350 DualPairing<X,Xstar> const& dualPairing;
351 };
352
353} // end of namespace Kaskade
354
355#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
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
virtual field_type applyDp(X const &x, X &y) const override
operator application Computes and returns the dual pairing .
virtual void applyscaleadd(field_type alpha, X const &x, X &y) const override
virtual void apply(X const &x, X &y) const override
virtual field_type dp(X const &x, X const &y) const override
returns the dual pairing with respect to which the operator is symmetric
SymmetricMatrixOperator(Matrix const &A_)
Constructor.
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.
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