Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkFEMLinearSystemWrapper.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkFEMLinearSystemWrapper.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/09/10 14:29:42 $
00007   Version:   $Revision: 1.22 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
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       /* , m_PrimaryMatrixSetupFunction(0), m_PrimaryVectorSetupFunction(0), m_PrimarySolutionSetupFunction(0) {} */
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    * Set the maximum number of entries permitted in a matrix
00110    * \param matrixIndex index of matrix to set value for
00111    * \param maxNonZeros maximum number of entries allowed in matrix
00112    * \note in general this function does nothing, however it may 
00113    *       redefined by the derived wrapper if necessary
00114    */
00115   //virtual void SetMaximumNonZeroValuesInMatrix(unsigned int maxNonZeroValues) = 0;
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    * Sets the function used to prepare the primary system matrix for numerical solving
00420    * \param SetupFunction pointer to function that stores the matrix to 
00421    * solve in the 0 matrix of the linear system
00422    */
00423   /*
00424   void SetPrimaryMatrixSetupFunction(void (*SetupFunction)(LinearSystemWrapper *lsw))
00425   { 
00426     m_PrimaryMatrixSetupFunction = SetupFunction; 
00427   }
00428   */
00429 
00430 
00431   /*
00432    * Sets the function used to prepare the primary system vector for numerical solving
00433    * \param SetupFunction pointer to function that stores the vector to
00434    * solve in the 0 vector of the linear system
00435    */
00436   /*
00437   void SetPrimaryVectorSetupFunction(void (*SetupFunction)(LinearSystemWrapper *lsw))
00438   { 
00439     m_PrimaryVectorSetupFunction = SetupFunction; 
00440   }
00441   */
00442 
00443   /*
00444    * Sets the function used to prepare the primary system solution for numerical solving
00445    * \param SetupFunction pointer to function that stores the solution 
00446    * in the 0 solution vector of the linear system
00447    */
00448   /*
00449   void SetPrimarySolutionSetupFunction(void (*SetupFunction)(LinearSystemWrapper *lsw))
00450   { 
00451     m_PrimarySolutionSetupFunction = SetupFunction; 
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    * Function used to prepare primary matrix for numerical solving 
00477    */
00478   //void (*m_PrimaryMatrixSetupFunction)(LinearSystemWrapper *lsw);
00479 
00480   /*
00481    * Function used to prepare primary vector for numerical solving 
00482    */
00483   /* void (*m_PrimaryVectorSetupFunction)(LinearSystemWrapper *lsw);*/
00484 
00485   /*
00486    * Function used to prepare primary matrix for numerical solving 
00487    */
00488   /* void (*m_PrimarySolutionSetupFunction)(LinearSystemWrapper *lsw); */
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 }} // end namespace itk::fem
00552 
00553 #endif // #ifndef __itkFEMLinearSystemWrapper_h
00554 

Generated at Sun Sep 23 12:32:50 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000