00001 00005 class Matrix(Type) : public HandleId 00006 00007 { 00008 00009 protected: 00010 00011 bool symm_storage; 00012 bool pivot_allowed; 00013 00014 bool is_factorized; 00015 FactType last_fact; 00016 PivotType last_pivtp; 00017 00018 int prod_work; 00019 int matvec_work; 00020 int fact_work; 00021 int forwback_work; 00022 int inv_work; 00023 int det_work; 00024 int jacobi_work; 00025 int sor_work; 00026 int ssor_work; 00027 00028 virtual void copy_matrix_attributes (const Matrix(Type)& X); 00029 virtual void reset (); 00030 00031 public: 00032 00033 00034 00035 Matrix(Type) (); 00036 00037 virtual ~Matrix(Type) (); 00038 00039 00040 00041 00042 bool symmetricStorage () { return symm_storage; } 00043 bool pivotingAllowed () { return pivot_allowed; } 00044 00045 virtual int getNoRows () const = 0; 00046 virtual int getNoColumns () const = 0; 00047 virtual int getNoNonzeroes () const = 0; 00048 virtual void size (int& m, int& n) const = 0; 00049 00050 virtual int getWork (const MatrixWork work_tp = MATVEC_WORK) const; 00051 virtual real getStorage() const = 0; 00052 00053 00054 00055 00056 virtual bool makeItSimilar (Handle(Matrix(Type))& M) const = 0; 00057 virtual bool redim (const Matrix(prm_Type)& pm) = 0; 00058 00059 virtual void optimizeDataStructure () {} 00060 00061 00062 00063 virtual bool redim (const VecSimple(int)& ivec, 00064 const VecSimple(int)& jvec, 00065 int new_nrows, 00066 int new_ncolumns) = 0; 00067 virtual void getIndexSet (VecSimple(int)& ivec, 00068 VecSimple(int)& jvec) const = 0; 00069 virtual bool validIndexSet (const VecSimple(int)& ivec, 00070 const VecSimple(int)& jvec, 00071 const int new_nrows, 00072 const int new_ncolumns) = 0; 00073 00074 00075 00076 00077 virtual Type& elm (int i, int j) = 0; 00078 00079 Matrix(Type)& operator = (const Matrix(Type)& X) 00080 { fill(X); return *this; } 00081 00082 Matrix(Type)& operator = (Type a) { fill(a); return *this; } 00083 00084 virtual void fill (const Matrix(Type)& X) = 0; 00085 virtual void fill (Type a) = 0; 00086 00087 virtual void convertFrom (Matrix(Type)& X); 00088 00089 virtual void assemble (const Mat(Type)& em, 00090 const VecSimple(int)& idx_row_trans, 00091 const VecSimple(int)& idx_col_trans, 00092 int elm_no); 00093 00094 00095 00096 00097 virtual void add 00098 (Matrix(Type)& bm, Matrix(Type)& cm) = 0; 00099 00100 virtual void add 00101 (Matrix(Type)& bm, char s, Matrix(Type)& cm) = 0; 00102 00103 virtual void add 00104 (Matrix(Type)& bm, Type b, Matrix(Type)& cm) = 0; 00105 00106 virtual void add 00107 (Type a, Matrix(Type)& bm, Type b, Matrix(Type)& cm) = 0; 00108 00109 virtual void mult (Type value) = 0; 00110 00111 virtual void prod 00112 ( 00113 const Vector(Type)& xb, 00114 Vector(Type)& yb, 00115 TransposeMode tpmode = NOT_TRANSPOSED, 00116 bool add_to_yb = false 00117 ) const = 0; 00118 00119 virtual void colManip 00120 ( 00121 LinEqConstraint& constraint_eq, 00122 Vec(Type)& vc, 00123 VecSimple(bool)& essential_dof 00124 ); 00125 00126 virtual void rowManip 00127 ( 00128 LinEqConstraint& constraint_eq, 00129 Vec(Type)& vc, 00130 VecSimple(bool)& essential_dof 00131 ); 00132 00133 00134 00135 00136 void resetFact (bool is_factorized = false, 00137 FactType last_fact = LU_FACT, 00138 PivotType last_pivtp = NO_PIVOT); 00139 00140 bool factorized () const { return is_factorized; } 00141 bool factorized (FactType& fact_tp, PivotType& pivot_tp) const; 00142 00143 00144 virtual bool factorize (const FactStrategy& fstrategy) = 0; 00145 virtual void forwBack (Vector(Type)& bb, Vector(Type)& xb) = 0; 00146 00147 00148 00149 00150 virtual void SSOR1it (Vector(Type)& xnew, const Vector(Type)& xold, 00151 const Vector(Type)& b, real omega, 00152 TransposeMode tpmode = NOT_TRANSPOSED) const = 0; 00153 virtual void SSORsolve (Vector(Type)& y, const Vector(Type)& c, 00154 real omega, 00155 TransposeMode tpmode = NOT_TRANSPOSED) const = 0; 00156 00157 virtual void SOR1it (Vector(Type)& xnew, const Vector(Type)& xold, 00158 const Vector(Type)& b, real omega, 00159 TransposeMode tpmode = NOT_TRANSPOSED) const = 0; 00160 virtual void SORsolve (Vector(Type)& y, const Vector(Type)& c, 00161 real omega, 00162 TransposeMode tpmode = NOT_TRANSPOSED) const = 0; 00163 00164 virtual void Jacobi1it (Vector(Type)& xnew, const Vector(Type)& xold, 00165 const Vector(Type)& b, 00166 TransposeMode tpmode = NOT_TRANSPOSED) const = 0; 00167 virtual void Jacobisolve (Vector(Type)& y, const Vector(Type)& c, 00168 TransposeMode tpmode = NOT_TRANSPOSED) const = 0; 00169 00170 00171 00172 00173 virtual void print (Os os, const char* header = NULL, 00174 int nentries_per_line = 3) const = 0; 00175 virtual void printAscii (Os os, const char* header = NULL) const =0; 00176 00177 virtual void scan (Is is) = 0; 00178 00179 virtual void save (const char* filename, const char* name = "X") const; 00180 virtual void load (const char* filename, const char* name = "X"); 00181 00182 CLASS_INFO 00183 00184 00185 DEF_VIRTUAL_CAST(MatBand(Type)) 00186 DEF_VIRTUAL_CAST(Mat(Type)) 00187 00188 DEF_VIRTUAL_CAST(MatStructSparse(Type)) 00189 DEF_VIRTUAL_CAST(MatSparse(Type)) 00190 DEF_VIRTUAL_CAST(MatDiag(Type)) 00191 DEF_VIRTUAL_CAST(MatTri(Type)) 00192 DEF_VIRTUAL_CAST(MatLapack(Type)) 00193 DEF_VIRTUAL_CAST(MatBandLapack(Type)) 00194 DEF_VIRTUAL_CAST(MatEBE(Type)) 00195 }; 00196 00197 00198 00199 00200 inline void add 00201 ( 00202 Matrix(Type)& A, 00203 Matrix(Type)& B, 00204 Matrix(Type)& C 00205 ) 00206 00207 { 00208 A.add(B,C); 00209 } 00210 00211 00212 00213 00214 inline void add 00215 ( 00216 Matrix(Type)& A, 00217 Matrix(Type)& B, 00218 char s, 00219 Matrix(Type)& C 00220 ) 00221 00222 { 00223 A.add(B,s,C); 00224 } 00225 00226 00227 00228 00229 inline void add 00230 ( 00231 Matrix(Type)& A, 00232 Matrix(Type)& B, 00233 Type b, 00234 Matrix(Type)& C 00235 ) 00236 00237 { 00238 A.add(B,b,C); 00239 } 00240 00241 00242 00243 00244 inline void add 00245 ( 00246 Matrix(Type)& A, 00247 Type a, 00248 Matrix(Type)& B, 00249 Type b, 00250 Matrix(Type)& C 00251 ) 00252 00253 { 00254 A.add(a,B,b,C); 00255 } 00256 00257 00258 00259 00260 inline void prod 00261 ( 00262 Vector(Type)& y, 00263 const Matrix(Type)& A, 00264 const Vector(Type)& x, 00265 TransposeMode tpmode = NOT_TRANSPOSED, 00266 bool add_to_yb = false 00267 ) 00268 00269 { 00270 if (&y == &x) { 00271 errorFP("prod (y,A,x)","y is identical to x (same adress) - illegal!"); 00272 } 00273 00274 A.prod (x, y, tpmode, add_to_yb); 00275 } 00276 00277 00278 #define ClassType Matrix(Type) 00279 #include <Handle.h> 00280 #undef ClassType 00281 00282 00283 00284 inline void add 00285 ( 00286 Handle(Matrix(Type)) am, 00287 Handle(Matrix(Type)) bm, 00288 Handle(Matrix(Type)) cm 00289 ) 00290 00291 { 00292 am->add (*bm, *cm); 00293 } 00294 00295 00296 00297 00298 00299 inline void add 00300 ( 00301 Handle(Matrix(Type)) am, 00302 Handle(Matrix(Type)) bm, 00303 char s, 00304 Handle(Matrix(Type)) cm 00305 00306 ) 00307 00308 { 00309 am->add(*bm,s,*cm); 00310 } 00311 00312 00313 00314 00315 inline void add 00316 ( 00317 Handle(Matrix(Type)) am, 00318 Handle(Matrix(Type)) bm, 00319 Type b, 00320 Handle(Matrix(Type)) cm 00321 ) 00322 00323 { 00324 am->add(*bm,b,*cm); 00325 } 00326 00327 00328 00329 00330 inline void add 00331 ( 00332 Handle(Matrix(Type)) am, 00333 Type a, 00334 Handle(Matrix(Type)) bm, 00335 Type b, 00336 Handle(Matrix(Type)) cm 00337 ) 00338 00339 { 00340 am->add(a,*bm,b,*cm); 00341 } 00342 00343 00344