Class documentation of Concepts

Loading...
Searching...
No Matches
compositions.hh
Go to the documentation of this file.
1
6#ifndef compositions_hh
7#define compositions_hh
8
10#include "basics/exceptions.hh"
11#include "space/space.hh"
12#include "function/basis.hh"
13#include "function/vector.hh"
14#include "basics/debug.hh"
15
16// debugging
17#define ComposeConstr_D 0
18#define ComposeAppl_D 0
19#define SchurComplContr_D 0
20
21namespace concepts {
22
23 // forward declaration
24 template<class F>
25 class SparseMatrix;
26
27 template<class F>
28 class DenseMatrix;
29
30 template<class F>
31 class Matrix;
32
33 template<class F>
34 class HashedSparseMatrix;
35
36 // ************************************************************** Operator **
37
41 template<class F>
42 class Operator : public virtual OutputOperator {
43 public:
45 typedef F type;
47 typedef typename Realtype<F>::type r_type;
49 typedef typename Cmplxtype<F>::type c_type;
50
51 Operator(uint dimX, uint dimY) : dimX_(dimX), dimY_(dimY) {}
52 virtual ~Operator() {}
53
85
88 virtual void operator()();
89
93 virtual inline const uint dimX() const { return dimX_; }
94
98 virtual inline const uint dimY() const { return dimY_; }
99
100 virtual void show_messages() { }
101 protected:
102 virtual std::ostream& info(std::ostream& os) const;
104 uint dimX_, dimY_;
105 };
106
107 // *********************************************************** VecOperator **
108
114 template<class F>
115 class VecOperator : public Operator<F> {
116 public:
118 typedef typename Realtype<F>::type r_type;
120 typedef typename Cmplxtype<F>::type c_type;
121
123
124 virtual void operator()(const Function<r_type>& fncY, Function<F>& fncX);
125 virtual void operator()(const Function<c_type>& fncY,
127
159
166 protected:
167 virtual std::ostream& info(std::ostream& os) const;
171 virtual void apply_(const Vector<F>& fncY, Vector<F>& fncX) = 0;
174 virtual void apply_() = 0;
175 };
176
177 // *************************************************************** Compose **
178
189 template<class F, class H = F>
190 class Compose : public Operator<F> {
191 public:
193 inline Compose(Operator<F>& A, Operator<H>& B);
194
197 inline void operator()(const Function<F>& fncY, Function<F>& fncX);
198
207 bool collapse(Matrix<F>& dest) const;
208 protected:
209 virtual std::ostream& info(std::ostream& os) const;
210 private:
212 Operator<F>& A_;
214 Operator<H>& B_;
216 Vector<F> f_;
217
218 void collapse_(DenseMatrix<F>& A, DenseMatrix<H>& B, Matrix<F>& dest) const;
219 };
220
221 template<class F, class H>
223 : Operator<F>(A.dimX(), B.dimY()), A_(A), B_(B), f_(B.dimX()) {
224 DEBUGL(ComposeConstr_D,
225 "A is (" << A.dimX() << "x" << A.dimY() << ") *" <<
226 "B is (" << B.dimX() << "x" << B.dimY() << ")");
227 conceptsAssert(A.dimY() == B.dimX(), Assertion());
228 }
229
230 template<class F, class H>
232 {
233 DEBUGL(ComposeAppl_D, *this);
234 conceptsAssert3(fncY.dim() == this->dimY_, Assertion(),
235 "fncY.dim = " << fncY.dim() << ", dimY = " << this->dimY());
236 conceptsAssert3(fncX.dim() == this->dimX(), Assertion(),
237 "fncX.dim = " << fncX.dim() << ", dimX = " << this->dimX());
238 DEBUGL(ComposeAppl_D, "y = " << fncY);
239 B_(fncY, f_);
240 DEBUGL(ComposeAppl_D, "f = " << f_);
241 A_(f_, fncX);
242 DEBUGL(ComposeAppl_D, "x = " << fncX);
243 }
244
245 // ************************************************************** Multiple **
246
250 template<class F>
251 class Multiple : public Operator<F> {
252 public:
254 typedef typename Realtype<F>::type r_type;
256 typedef typename Cmplxtype<F>::type c_type;
257
258 Multiple(Operator<F>& A, F a)
259 : Operator<F>(A.dimX(), A.dimY()), A_(A), a_(a) {}
260
269 {
270 apply_(fncY, fncX);
271 }
272 inline void operator()(const Function<c_type>& fncY,
274 apply_(fncY, fncX);
275 }
276
277 protected:
278 virtual std::ostream& info(std::ostream& os) const;
279 private:
281 Operator<F>& A_;
283 F a_;
284
285 template<class H, class I>
286 inline void apply_(const Function<H>& fncY, Function<I>& fncX);
287 };
288
289 template<class F>
290 template<class H, class I>
292 conceptsAssert(fncY.dim() == this->dimY(), Assertion());
293 conceptsAssert(fncX.dim() == this->dimX(), Assertion());
294 A_(fncY, fncX);
295 if (a_ != 1.0)
296 fncX *= a_;
297 }
298
299 // ***************************************************************** LiCoI **
300
305 template<class F>
306 class LiCoI : public Operator<F> {
307 public:
309 typedef typename Realtype<F>::type r_type;
311 typedef typename Cmplxtype<F>::type c_type;
312
313 LiCoI(Operator<F>& A, F a = 1.0, F b = 1.0)
314 : Operator<F>(A.dimX(), A.dimY()), A_(A), a_(a), b_(b) {}
315
324 virtual void operator()(const Function<c_type>& fncY,
326
343 bool collapse(Matrix<F>& dest, const F fact = 1.0) const;
344 protected:
345 virtual std::ostream& info(std::ostream& os) const;
346 private:
348 Operator<F>& A_;
350 F a_;
352 F b_;
353 };
354
355 // ****************************************************************** LiCo **
356
363 template<class F>
364 class LiCo : public Operator<F> {
365 public:
367 typedef typename Realtype<F>::type r_type;
369 typedef typename Cmplxtype<F>::type c_type;
370
379 LiCo(Operator<F>& A, Operator<F>& B, F a = 1.0, F b = 1.0) :
380 Operator<F>(A.dimX(), A.dimY()), A_(A), B_(B), a_(a), b_(b) {
381 conceptsAssert(A.dimX() == B.dimX(), Assertion());
382 conceptsAssert(A.dimY() == B.dimY(), Assertion());
383 }
384
394 {
395 apply_(fncY, fncX);
396 }
398 {
399 apply_(fncY, fncX);
400 }
401
417 bool collapse(Matrix<F>& dest, const F fact = 1.0) const;
418 protected:
419 virtual std::ostream& info(std::ostream& os) const;
420 private:
422 Operator<F>& A_;
424 Operator<F>& B_;
426 F a_;
428 F b_;
429
430 template<class H, class I>
431 inline void apply_(const Function<H>& fncY, Function<I>& fncX);
432 };
433
434 template<class F>
435 template<class H, class I>
437 conceptsAssert(this->dimX() == fncX.dim(), Assertion());
438 conceptsAssert(this->dimY() == fncY.dim(), Assertion());
439 A_(fncY, fncX);
440 fncX *= a_;
441 Vector<I> f(this->dimX()); // Intermediate vector
442 B_(fncY, f);
443 fncX.add(f, b_);
444 }
445
446 // ************************************************************ SchurCompl **
447
456 template<class F>
457 class SchurCompl : public LiCo<F> {
458 public:
462 virtual ~SchurCompl() {
463 delete D_; delete C_;
464 }
465 private:
467 Compose<F> *C_, *D_;
468 };
469
470 template<class F>
473 : LiCo<F>(A_BB,
474 *(D_ = new Compose<F>(A_BI,
475 *(C_ = new Compose<F>(A_II_inv, A_IB)))
476 ), 1.0, -1.0)
477 {
478 DEBUGL(SchurComplContr_D, "A_II_inv = " <<
480 DEBUGL(SchurComplContr_D, "A_IB = " <<
482 DEBUGL(SchurComplContr_D, "A_BI = " <<
484 DEBUGL(SchurComplContr_D, "A_BB = " <<
486 DEBUGL(SchurComplContr_D, "C_ = AII^-1 * AIB = " <<
487 (DenseMatrix<F>(SparseMatrix<F>(*C_, true))));
488 DEBUGL(SchurComplContr_D, "D_ = ABI * AII^-1 * AIB = " <<
489 (DenseMatrix<F>(SparseMatrix<F>(*D_, true))));
490 DEBUGL(SchurComplContr_D, "S_ = A_BB - A_BI * A_II^-1 * A_IB = " <<
491 (DenseMatrix<F>(SparseMatrix<F>(*this, true))));
492 }
493
494} // namespace concepts
495
496#endif // compositions_hh
bool collapse(Matrix< F > &dest) const
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Compose(Operator< F > &A, Operator< H > &B)
Constructor.
virtual void operator()(const Function< c_type > &fncY, Function< c_type > &fncX)
Cmplxtype< F >::type c_type
Real type of data type.
bool collapse(Matrix< F > &dest, const F fact=1.0) const
virtual void operator()(const Function< r_type > &fncY, Function< F > &fncX)
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Realtype< F >::type r_type
Real type of data type.
void operator()(const Function< r_type > &fncY, Function< F > &fncX)
bool collapse(Matrix< F > &dest, const F fact=1.0) const
Cmplxtype< F >::type c_type
Real type of data type.
Realtype< F >::type r_type
Real type of data type.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
LiCo(Operator< F > &A, Operator< F > &B, F a=1.0, F b=1.0)
void operator()(const Function< c_type > &fncY, Function< c_type > &fncX)
Cmplxtype< F >::type c_type
Real type of data type.
Realtype< F >::type r_type
Real type of data type.
void operator()(const Function< r_type > &fncY, Function< F > &fncX)
void operator()(const Function< c_type > &fncY, Function< c_type > &fncX)
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual const uint dimY() const
virtual void operator()(const Function< c_type > &fncY, Function< c_type > &fncX)
Realtype< F >::type r_type
Real type of data type.
F type
Type of data, e.g. matrix entries.
Cmplxtype< F >::type c_type
Real type of data type.
virtual const uint dimX() const
virtual void operator()()
virtual void operator()(const Function< r_type > &fncY, Function< F > &fncX)
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
uint dimX_
Dimension of image space and the source space.
SchurCompl(Operator< F > &A_II_inv, Operator< F > &A_IB, Operator< F > &A_BI, Operator< F > &A_BB)
Constructor.
Realtype< F >::type r_type
Real type of data type.
virtual void apply_()=0
void operator()(const Matrix< r_type > &mX, Matrix< F > &mY)
Application method to real matrices. Calls function apply()
virtual void apply_(const Vector< F > &fncY, Vector< F > &fncX)=0
Cmplxtype< F >::type c_type
Real type of data type.
virtual void operator()(const Function< c_type > &fncY, Function< c_type > &fncX)
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
void operator()()
Application method without second argument. Used for parallel solvers.
virtual void operator()(const Vector< c_type > &fncY, Vector< c_type > &fncX)
virtual void operator()(const Vector< r_type > &fncY, Vector< F > &fncX)
void operator()(const Matrix< c_type > &mX, Matrix< c_type > &mY)
Application method to complex matrices. Calls apply_()
#define conceptsAssert(cond, exc)
#define DEBUGL(doit, msg)
Definition debug.hh:40
#define conceptsAssert3(cond, exc, msg)
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320