00001 #ifndef __AbsTriDiagonalLS_H__ 00002 #define __AbsTriDiagonalLS_H__ 00003 00004 00029 #include <stdio.h> 00030 #include "RTriDiagonalMatrix.hpp" 00031 #include "RealVector.hpp" 00032 00033 class AbsTriDiagonalLS 00034 { 00035 protected: 00036 00037 int N; 00038 00039 RTriDiagonalMatrix* A; 00040 RealVector* x; 00041 00042 RealVector* b; 00043 00044 public: 00045 00046 AbsTriDiagonalLS(int asize) 00047 { 00048 N=asize; 00049 00050 x= new RealVector(N); 00051 b= new RealVector(N); 00052 00053 A= new RTriDiagonalMatrix(N); 00054 } 00055 00056 virtual ~AbsTriDiagonalLS(){ delete A; delete x; delete b;} 00057 00058 virtual void initFreezing(int val=0){} 00059 virtual void freeze(int item, int val=0){} // freezing used later for marking identity diagonal only values 00060 00061 virtual void loadA(RTriDiagonalMatrix* m){ A->load(m); } 00062 virtual void loadMatrix(RealVector* u1, RealVector* d1, RealVector* l1){ A->load(u1,d1,l1); } 00063 virtual void loadX(RealVector* data){ x->load(data); } 00064 virtual void loadB(RealVector* data){ b->load(data); } 00065 00066 virtual int size(){ return (3*N-2); } 00067 00068 virtual int getWidth(){ return N; } 00069 virtual int getHeight(){ return N; } 00070 00071 virtual RealVector* getX(){ return x; } 00072 virtual RealVector* getB(){ return b; } 00073 00074 virtual RTriDiagonalMatrix* getA(){ return A; } 00075 00076 virtual bool solve()=0; // SOLVING to define later 00077 00078 virtual bool solve(RealVector* aX, RealVector* aB) // A not changed 00079 { 00080 loadX(aX); 00081 loadB(aB); 00082 00083 return solve(); 00084 } 00085 00086 virtual bool solve(RTriDiagonalMatrix* aA, RealVector* aX, RealVector* aB) // new system 00087 { 00088 loadA(aA); 00089 00090 loadX(aX); 00091 loadB(aB); 00092 00093 return solve(); 00094 } 00095 00096 00097 virtual RealVector* evaluate(RealVector* aX, RealVector* aB) 00098 { 00099 solve(aX, aB); 00100 00101 return getX(); 00102 } 00103 00104 virtual RealVector* evaluate(RTriDiagonalMatrix* aA, RealVector* aX, RealVector* aB) 00105 { 00106 solve(aA, aX, aB); 00107 00108 return getX(); 00109 } 00110 00111 virtual void output() 00112 { 00113 printf("Linear System\n"); 00114 A->output(); 00115 printf("x: "); x->output(); 00116 printf("b: "); b->output(); 00117 } 00118 00119 virtual void output(FILE* file) 00120 { 00121 fprintf(file, "Linear System\n"); 00122 A->output(file); 00123 fprintf(file, "x: "); x->output(file); 00124 fprintf(file, "b: "); b->output(file); 00125 } 00126 }; 00127 00128 #endif 00129 00130 00131