00001
00002
00003 #ifndef _DSSOLVER_H__
00004 #define _DSSOLVER_H__
00005
00006 #include "DSSAfx.h"
00007 #include "SparseConectivityMtx.h"
00008 #include "IntArrayList.h"
00009
00010 #include "SparseGridMtxPD.h"
00011
00012 DSS_NAMESPASE_BEGIN
00013
00014 enum eDSMatrixType
00015 {
00016 eDSSparseMatrix = 0,
00017 eDSSkylineMatrix = 1
00018 };
00019
00020 enum eDSSolverType
00021 {
00022 eDSSFactorizationLDLT = 0,
00023 eDSSFactorizationLLT = 1,
00024 eDSSFactorizationLU = 2,
00025 eDSSFactorizationLDLTIncomplete = 3,
00026 eDSSFactorizationLLTIncomplete = 4,
00027 eDSSDiagonalScaling = 5,
00028 eDSSFastCG = 6
00029 };
00030
00031
00032
00033
00034
00035
00036 struct ISolver
00037 {
00038
00039
00040
00041
00042
00043 virtual long Initialize (unsigned char run_code ,eDSSolverType solverType = eDSSFactorizationLDLT, eDSMatrixType matrixType = eDSSparseMatrix) = 0;
00044
00045
00046
00047 virtual BOOL SetOrderingType(Ordering::Type otype) = 0;
00048
00049
00050 virtual BOOL LoadMatrix (ULONG neq,unsigned char block_size,double * a,ULONG * ci,ULONG * adr ) = 0;
00051 virtual BOOL LoadMatrix (SparseMatrixF* sm,unsigned char block_size) = 0;
00052 virtual BOOL SetMatrixPattern(SparseMatrixF* smt,unsigned char block_size) = 0;
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 virtual BOOL LoadMCN (ULONG n_blocks,unsigned char block_size,long * mcn, BOOL bIsSchur ) = 0;
00067
00068
00069
00070
00071
00072 virtual BOOL PreFactorize ( ) = 0;
00073
00074
00075 virtual void LoadZeros() = 0;
00076
00077
00078 virtual BOOL LoadNumbers (SparseMatrixF* sm) = 0;
00079
00080
00081 virtual BOOL AddNumbers (double alfa,SparseMatrixF* smtx) = 0;
00082
00083
00084 virtual BOOL ScaleMatrix(double alfa) = 0;
00085
00086 virtual SparseMatrixF* GetSparseMatrix() = 0;
00087
00088
00089 virtual BOOL ReFactorize ( ) = 0;
00090
00091
00092
00093
00094 virtual BOOL Factorize ( ) = 0;
00095
00096
00097
00098
00099 virtual BOOL Solve (double * r,double * f ) = 0;
00100
00101
00102
00103 virtual double GetFactorizationError() = 0;
00104
00105
00106 virtual void Dispose() = 0;
00107
00108
00109 virtual long Close ( ) = 0;
00110
00111 virtual void SetMT(MathTracer* MT) = 0;
00112
00113 virtual BOOL IsFactorized() = 0;
00114 virtual BOOL IsAllocated() = 0;
00115 virtual BOOL IsInitialized() = 0;
00116
00117 virtual ~ISolver(){};
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 virtual void condense(double *a,double *lhs,double *rhs,long tc) = 0;
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 virtual void GetA12block(double *pA12) = 0;
00150
00151
00152 virtual void MulMatrixByVector(double *b, double *c) = 0;
00153
00154
00155 virtual int PreCG(double* b, double* x,double epsilon,int max_iter) = 0;
00156
00157
00158 virtual int CG(double* b, double* x,double epsilon,int max_iter) = 0;
00159
00160 enum eState
00161 {
00162 None = 0,
00163 Initialized = 1,
00164 Allocated = 2,
00165 Factorized = 3,
00166 ErrorInMCN = -1
00167 };
00168 };
00169
00170
00171
00172
00173 class DSSolver : public ISolver
00174 {
00175 MathTracer MT;
00176 MathTracer* eMT;
00177
00178 SparseMatrixF m_sm;
00179 SparseGridMtx* act_matrix;
00180 SparseGridMtx* matrix;
00181 SparseGridMtxPD* matrixPD;
00182 char str[512];
00183 ISolver::eState m_eState;
00184
00185 eDSSolverType SolverType;
00186 eDSMatrixType MatrixType;
00187 unsigned char run_code;
00188
00189
00190 double* tmpR;
00191 IntArrayList* dom_order;
00192
00193
00194 unsigned char blockSize;
00195 long n_blocks;
00196 long neq;
00197 Ordering* mcn;
00198
00199
00200 LargeVector matrixD;
00201 SparseGridMtx* orig_matrix;
00202
00203
00204 IntArrayList* fixed;
00205 IntArrayList* lncn;
00206
00207 Ordering::Type OrderingType;
00208 BOOL m_bIsSchur;
00209
00210 public:
00211 DSSolver(MathTracer* pMT = NULL);
00212
00213 virtual ~DSSolver();
00214 virtual long Initialize (unsigned char run_code ,eDSSolverType solverType = eDSSFactorizationLDLT, eDSMatrixType matrixType = eDSSparseMatrix);
00215 virtual void SetMT(MathTracer* pMT);
00216 virtual void Dispose();
00217
00218 virtual BOOL SetOrderingType(Ordering::Type otype);
00219 virtual BOOL LoadMatrix(unsigned long neq,unsigned char block_size,double * a,unsigned long * ci,unsigned long * adr );
00220 virtual BOOL LoadMatrix(SparseMatrixF* smt,unsigned char block_size);
00221 virtual BOOL SetMatrixPattern(SparseMatrixF* smt,unsigned char block_size);
00222
00223 virtual BOOL IsFactorized();
00224 virtual BOOL IsAllocated();
00225 virtual BOOL IsInitialized();
00226 virtual BOOL IsSchur();
00227
00228 virtual BOOL Factorize ( );
00229 virtual BOOL PreFactorize();
00230
00231 virtual void LoadZeros();
00232 virtual BOOL LoadNumbers (SparseMatrixF* sm);
00233 virtual BOOL AddNumbers (double alfa,SparseMatrixF* smtx);
00234 virtual BOOL ScaleMatrix(double alfa);
00235 virtual SparseMatrixF* GetSparseMatrix();
00236
00237 virtual double& ElementAt(int i, int j);
00238
00239 virtual BOOL ReFactorize( );
00240
00241 virtual BOOL Solve (double * r, double * f );
00242 virtual long Close ( );
00243
00244 void StartSolverWriteInfo();
00245 void EndSolverWriteInfo();
00246
00247 void SetSM(SparseMatrixF* sm);
00248 virtual double GetFactorizationError();
00249
00250
00251
00252
00253
00254 virtual BOOL LoadMCN (ULONG n_blocks,unsigned char block_size,long * mcn, BOOL bIsSchur );
00255
00256 virtual BOOL LoadMCN (IntArrayList& mcn);
00257
00258 IntArrayList* GetFixedBlocks() { return this->fixed; }
00259 IntArrayList* GetFixedDOFs() { return this->lncn; }
00260
00261 virtual void condense(double *a,double *lhs,double *rhs,long tc);
00262
00263 void GetA12block(double *pA12);
00264
00265
00266 void MulMatrixByVector(double *b, double *c);
00267
00268 int PreCG(double* b, double* x,double epsilon,int max_iter);
00269
00270
00271 int CG(double* b, double* x,double epsilon,int max_iter);
00272
00273 private:
00274 BOOL LoadMCN_int(IntArrayList* mcn_order);
00275 void ExpandMCN(IntArrayList& mcn);
00276 SparseGridMtx* CreateNewSparseGridMtx(IntArrayList* fixed = NULL);
00277 void WriteFactorizationInfo();
00278 BOOL CreateFixedArray(long no_noncondensed_DOFs);
00279 BOOL PreFactorizeSchur();
00280 void StoreFixedLastPermutation_dom_order();
00281 };
00282
00283 DSS_NAMESPASE_END
00284
00285 #endif //_DSSOLVER_H__