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