dune-istl
2.2.0
|
00001 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 // vi: set et ts=4 sw=2 sts=2: 00003 #ifndef DUNE_ISTLOPERATORS_HH 00004 #define DUNE_ISTLOPERATORS_HH 00005 00006 #include<cmath> 00007 #include<complex> 00008 #include<iostream> 00009 #include<iomanip> 00010 #include<string> 00011 00012 #include"solvercategory.hh" 00013 00014 00015 namespace Dune { 00016 00039 //===================================================================== 00040 // Abstract operator interface 00041 //===================================================================== 00042 00043 00061 template<class X, class Y> 00062 class LinearOperator { 00063 public: 00065 typedef X domain_type; 00067 typedef Y range_type; 00069 typedef typename X::field_type field_type; 00070 00075 virtual void apply (const X& x, Y& y) const = 0; 00076 00078 virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const = 0; 00079 00081 virtual ~LinearOperator () {} 00082 }; 00083 00084 00093 template<class M, class X, class Y> 00094 class AssembledLinearOperator : public LinearOperator<X,Y> { 00095 public: 00097 typedef M matrix_type; 00098 typedef X domain_type; 00099 typedef Y range_type; 00100 typedef typename X::field_type field_type; 00101 00103 virtual const M& getmat () const = 0; 00104 00106 virtual ~AssembledLinearOperator () {} 00107 }; 00108 00109 00110 00111 //===================================================================== 00112 // Implementation for ISTL-matrix based operator 00113 //===================================================================== 00114 00120 template<class M, class X, class Y> 00121 class MatrixAdapter : public AssembledLinearOperator<M,X,Y> 00122 { 00123 public: 00125 typedef M matrix_type; 00126 typedef X domain_type; 00127 typedef Y range_type; 00128 typedef typename X::field_type field_type; 00129 00131 enum {category=SolverCategory::sequential}; 00132 00134 MatrixAdapter (const M& A) : _A_(A) {} 00135 00137 virtual void apply (const X& x, Y& y) const 00138 { 00139 _A_.mv(x,y); 00140 } 00141 00143 virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const 00144 { 00145 _A_.usmv(alpha,x,y); 00146 } 00147 00149 virtual const M& getmat () const 00150 { 00151 return _A_; 00152 } 00153 00154 private: 00155 const M& _A_; 00156 }; 00157 00160 } // end namespace 00161 00162 #endif