00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkFEMLinearSystemWrapper_h
00019 #define __itkFEMLinearSystemWrapper_h
00020
00021 #include "itkMacro.h"
00022 #include "itkFEMSolution.h"
00023 #include "itkFEMException.h"
00024
00025 #include <vector>
00026 #include <typeinfo>
00027 #include <string>
00028
00029 namespace itk {
00030 namespace fem {
00031
00032
00051 class LinearSystemWrapper : public Solution
00052 {
00053 public:
00054
00056 typedef LinearSystemWrapper Self;
00057
00059 typedef Solution Superclass;
00060
00062 typedef Self* Pointer;
00063
00065 typedef const Self* ConstPointer;
00066
00067 typedef std::vector<unsigned int> ColumnArray;
00068
00073 LinearSystemWrapper()
00074 : m_Order(0), m_NumberOfMatrices(1), m_NumberOfVectors(1), m_NumberOfSolutions(1) {}
00075
00077
00082 virtual ~LinearSystemWrapper() {};
00083
00088 virtual void Clean( void );
00089
00095 void SetSystemOrder(unsigned int N) { m_Order = N; }
00096
00100 unsigned int GetSystemOrder() const { return m_Order; }
00101
00106 void SetNumberOfMatrices(unsigned int nMatrices) { m_NumberOfMatrices = nMatrices; }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00120 unsigned int GetNumberOfMatrices() { return m_NumberOfMatrices; }
00121
00126 void SetNumberOfVectors(unsigned int nVectors) { m_NumberOfVectors = nVectors; }
00127
00131 unsigned int GetNumberOfVectors() { return m_NumberOfVectors; }
00132
00137 void SetNumberOfSolutions(unsigned int nSolutions) { m_NumberOfSolutions = nSolutions; }
00138
00142 unsigned int GetNumberOfSolutions() { return m_NumberOfSolutions; }
00143
00151 virtual void InitializeMatrix(unsigned int matrixIndex = 0) = 0;
00152
00153
00158 virtual bool IsMatrixInitialized(unsigned int matrixIndex = 0) = 0;
00159
00164 virtual void DestroyMatrix(unsigned int matrixIndex = 0) = 0;
00165
00172 virtual void InitializeVector(unsigned int vectorIndex = 0) = 0;
00173
00174
00179 virtual bool IsVectorInitialized(unsigned int vectorIndex = 0) = 0;
00180
00185 virtual void DestroyVector(unsigned int vectorIndex = 0) = 0;
00186
00193 virtual void InitializeSolution(unsigned int solutionIndex = 0) = 0;
00194
00199 virtual bool IsSolutionInitialized(unsigned int solutionIndex = 0) = 0;
00200
00204 virtual void DestroySolution(unsigned int solutionIndex = 0) = 0;
00205
00212 virtual Float GetMatrixValue(unsigned int i, unsigned int j, unsigned int matrixIndex = 0) const = 0;
00213
00221 virtual void SetMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex = 0) = 0;
00222
00230 virtual void AddMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex = 0) = 0;
00231
00244 virtual void GetColumnsOfNonZeroMatrixElementsInRow( unsigned int row, ColumnArray& cols, unsigned int matrixIndex = 0 );
00245
00251 virtual Float GetVectorValue(unsigned int i, unsigned int vectorIndex = 0) const = 0;
00252
00259 virtual void SetVectorValue(unsigned int i, Float value, unsigned int vectorIndex = 0) = 0;
00260
00267 virtual void AddVectorValue(unsigned int i, Float value, unsigned int vectorIndex = 0) = 0;
00268
00276 virtual void SetSolutionValue(unsigned int i, Float value, unsigned int solutionIndex = 0) = 0;
00277
00285 virtual void AddSolutionValue(unsigned int i, Float value, unsigned int solutionIndex = 0) = 0;
00286
00294 virtual void Solve(void) = 0;
00295
00301 virtual void SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2) = 0;
00302
00310 virtual void CopyMatrix(unsigned int matrixIndex1, unsigned int matrixIndex2);
00311
00317 virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2) = 0;
00318
00324 virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2) = 0;
00325
00326
00332 virtual void ScaleMatrix(Float scale, unsigned int matrixIndex = 0);
00333
00334
00340 void ScaleVector(Float scale, unsigned int vectorIndex = 0);
00341
00342
00348 void ScaleSolution(Float scale, unsigned int solutionIndex = 0);
00349
00356 virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex, unsigned int rightMatrixIndex) = 0;
00357
00364 virtual void AddMatrixMatrix(unsigned int matrixIndex1, unsigned int matrixIndex2);
00365
00372 virtual void AddVectorVector(unsigned int vectorIndex1, unsigned int vectorIndex2);
00373
00380 virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex);
00381
00387 virtual void CopySolution2Vector(unsigned int solutionIndex, unsigned int vectorIndex) = 0;
00388
00394 virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex) = 0;
00395
00401 virtual void CopyVector(unsigned int vectorSource, unsigned int vectorDestination);
00402
00409 virtual void OptimizeMatrixStorage(unsigned int matrixIndex, unsigned int tempMatrixIndex);
00410
00416 virtual void ReverseCuthillMckeeOrdering(ColumnArray& newNumbering, unsigned int matrixIndex = 0);
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455 protected:
00456
00458 unsigned int m_Order;
00459
00463 unsigned int m_NumberOfMatrices;
00464
00468 unsigned int m_NumberOfVectors;
00469
00473 unsigned int m_NumberOfSolutions;
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 private:
00491
00495 void CuthillMckeeOrdering(ColumnArray& newNumbering, int startingRow, unsigned int matrixIndex = 0);
00496
00497 void FollowConnectionsCuthillMckeeOrdering(unsigned int rowNumber, ColumnArray& rowDegree, ColumnArray& newNumbering, unsigned int nextRowNumber, unsigned int matrixIndex = 0);
00498
00500 LinearSystemWrapper(const LinearSystemWrapper&);
00501
00503 const LinearSystemWrapper& operator= (const LinearSystemWrapper&);
00504
00505 };
00506
00507
00508
00509 class FEMExceptionLinearSystem : public FEMException
00510 {
00511 public:
00517 FEMExceptionLinearSystem(const char *file, unsigned int lineNumber, std::string location, std::string moreDescription);
00518
00520 virtual ~FEMExceptionLinearSystem() throw() {}
00521
00523 itkTypeMacro(FEMExceptionLinearSystem,FEMException);
00524
00525 };
00526
00527 class FEMExceptionLinearSystemBounds : public FEMException
00528 {
00529 public:
00535 FEMExceptionLinearSystemBounds(const char *file, unsigned int lineNumber, std::string location, std::string moreDescription, unsigned int index1);
00536
00541 FEMExceptionLinearSystemBounds(const char *file, unsigned int lineNumber, std::string location, std::string moreDescription, unsigned int index1, unsigned int index2);
00542
00544 virtual ~FEMExceptionLinearSystemBounds() throw() {}
00545
00547 itkTypeMacro(FEMExceptionLinearSystem,FEMException);
00548
00549 };
00550
00551 }}
00552
00553 #endif // #ifndef __itkFEMLinearSystemWrapper_h
00554