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:
00055 typedef LinearSystemWrapper Self;
00056
00058 typedef Solution Superclass;
00059
00061 typedef Self* Pointer;
00062
00064 typedef const Self* ConstPointer;
00065
00066 typedef std::vector<unsigned int> ColumnArray;
00067
00072 LinearSystemWrapper()
00073 : m_Order(0), m_NumberOfMatrices(1), m_NumberOfVectors(1), m_NumberOfSolutions(1) {}
00074
00075
00080 virtual ~LinearSystemWrapper() {};
00081
00086 virtual void Clean( void );
00087
00093 void SetSystemOrder(unsigned int N) { m_Order = N; }
00094
00098 unsigned int GetSystemOrder() const { return m_Order; }
00099
00104 void SetNumberOfMatrices(unsigned int nMatrices) { m_NumberOfMatrices = nMatrices; }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00118 unsigned int GetNumberOfMatrices() { return m_NumberOfMatrices; }
00119
00124 void SetNumberOfVectors(unsigned int nVectors) { m_NumberOfVectors = nVectors; }
00125
00129 unsigned int GetNumberOfVectors() { return m_NumberOfVectors; }
00130
00135 void SetNumberOfSolutions(unsigned int nSolutions) { m_NumberOfSolutions = nSolutions; }
00136
00140 unsigned int GetNumberOfSolutions() { return m_NumberOfSolutions; }
00141
00149 virtual void InitializeMatrix(unsigned int matrixIndex = 0) = 0;
00150
00151
00156 virtual bool IsMatrixInitialized(unsigned int matrixIndex = 0) = 0;
00157
00162 virtual void DestroyMatrix(unsigned int matrixIndex = 0) = 0;
00163
00170 virtual void InitializeVector(unsigned int vectorIndex = 0) = 0;
00171
00172
00177 virtual bool IsVectorInitialized(unsigned int vectorIndex = 0) = 0;
00178
00183 virtual void DestroyVector(unsigned int vectorIndex = 0) = 0;
00184
00191 virtual void InitializeSolution(unsigned int solutionIndex = 0) = 0;
00192
00197 virtual bool IsSolutionInitialized(unsigned int solutionIndex = 0) = 0;
00198
00202 virtual void DestroySolution(unsigned int solutionIndex = 0) = 0;
00203
00210 virtual Float GetMatrixValue(unsigned int i, unsigned int j, unsigned int matrixIndex = 0) const = 0;
00211
00219 virtual void SetMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex = 0) = 0;
00220
00228 virtual void AddMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex = 0) = 0;
00229
00242 virtual void GetColumnsOfNonZeroMatrixElementsInRow( unsigned int row, ColumnArray& cols, unsigned int matrixIndex = 0 );
00243
00249 virtual Float GetVectorValue(unsigned int i, unsigned int vectorIndex = 0) const = 0;
00250
00257 virtual void SetVectorValue(unsigned int i, Float value, unsigned int vectorIndex = 0) = 0;
00258
00265 virtual void AddVectorValue(unsigned int i, Float value, unsigned int vectorIndex = 0) = 0;
00266
00274 virtual void SetSolutionValue(unsigned int i, Float value, unsigned int solutionIndex = 0) = 0;
00275
00283 virtual void AddSolutionValue(unsigned int i, Float value, unsigned int solutionIndex = 0) = 0;
00284
00292 virtual void Solve(void) = 0;
00293
00299 virtual void SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2) = 0;
00300
00308 virtual void CopyMatrix(unsigned int matrixIndex1, unsigned int matrixIndex2);
00309
00315 virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2) = 0;
00316
00322 virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2) = 0;
00323
00324
00330 virtual void ScaleMatrix(Float scale, unsigned int matrixIndex = 0);
00331
00332
00338 void ScaleVector(Float scale, unsigned int vectorIndex = 0);
00339
00340
00346 void ScaleSolution(Float scale, unsigned int solutionIndex = 0);
00347
00354 virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex, unsigned int rightMatrixIndex) = 0;
00355
00362 virtual void AddMatrixMatrix(unsigned int matrixIndex1, unsigned int matrixIndex2);
00363
00370 virtual void AddVectorVector(unsigned int vectorIndex1, unsigned int vectorIndex2);
00371
00378 virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex);
00379
00385 virtual void CopySolution2Vector(unsigned int solutionIndex, unsigned int vectorIndex) = 0;
00386
00392 virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex) = 0;
00398 virtual void CopyVector(unsigned int vectorSource, unsigned int vectorDestination);
00399
00406 virtual void OptimizeMatrixStorage(unsigned int matrixIndex, unsigned int tempMatrixIndex);
00407
00413 virtual void ReverseCuthillMckeeOrdering(ColumnArray& newNumbering, unsigned int matrixIndex = 0);
00414
00415
00416
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 protected:
00453
00455 unsigned int m_Order;
00456
00460 unsigned int m_NumberOfMatrices;
00461
00465 unsigned int m_NumberOfVectors;
00466
00470 unsigned int m_NumberOfSolutions;
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487 private:
00488
00492 void CuthillMckeeOrdering(ColumnArray& newNumbering, int startingRow, unsigned int matrixIndex = 0);
00493
00494 void FollowConnectionsCuthillMckeeOrdering(unsigned int rowNumber, ColumnArray& rowDegree, ColumnArray& newNumbering, unsigned int nextRowNumber, unsigned int matrixIndex = 0);
00495
00497 LinearSystemWrapper(const LinearSystemWrapper&);
00498
00500 const LinearSystemWrapper& operator= (const LinearSystemWrapper&);
00501
00502 };
00503
00504
00505
00506 class FEMExceptionLinearSystem : public FEMException
00507 {
00508 public:
00514 FEMExceptionLinearSystem(const char *file, unsigned int lineNumber, std::string location, std::string moreDescription);
00515
00517 virtual ~FEMExceptionLinearSystem() throw() {}
00518
00520 itkTypeMacro(FEMExceptionLinearSystem,FEMException);
00521
00522 };
00523
00524 class FEMExceptionLinearSystemBounds : public FEMException
00525 {
00526 public:
00532 FEMExceptionLinearSystemBounds(const char *file, unsigned int lineNumber, std::string location, std::string moreDescription, unsigned int index1);
00533
00538 FEMExceptionLinearSystemBounds(const char *file, unsigned int lineNumber, std::string location, std::string moreDescription, unsigned int index1, unsigned int index2);
00539
00541 virtual ~FEMExceptionLinearSystemBounds() throw() {}
00542
00544 itkTypeMacro(FEMExceptionLinearSystem,FEMException);
00545
00546 };
00547
00548 }}
00549
00550 #endif // #ifndef __itkFEMLinearSystemWrapper_h