ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkFEMLinearSystemWrapperVNL.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef __itkFEMLinearSystemWrapperVNL_h
20 #define __itkFEMLinearSystemWrapperVNL_h
22 #include "vnl/vnl_sparse_matrix.h"
23 #include "vnl/vnl_vector.h"
24 #include <vnl/vnl_sparse_matrix_linear_system.h>
25 #include <vnl/algo/vnl_lsqr.h>
26 #include <vector>
27 
28 namespace itk
29 {
30 namespace fem
31 {
40 {
41 public:
42 
43  /* values stored in matrices & vectors */
45 
46  /* superclass */
48 
49  /* matrix typedef */
50  typedef vnl_sparse_matrix<Float> MatrixRepresentation;
51 
52  /* matrix holder typedef */
53  typedef std::vector<MatrixRepresentation *> MatrixHolder;
54 
55  /* constructor & destructor */
57  {
58  }
59  virtual ~LinearSystemWrapperVNL();
60 
61  /* memory management routines */
62  virtual void InitializeMatrix(unsigned int matrixIndex);
63 
64  virtual bool IsMatrixInitialized(unsigned int matrixIndex);
65 
66  virtual void DestroyMatrix(unsigned int matrixIndex);
67 
68  virtual void InitializeVector(unsigned int vectorIndex);
69 
70  virtual bool IsVectorInitialized(unsigned int vectorIndex);
71 
72  virtual void DestroyVector(unsigned int vectorIndex);
73 
74  virtual void InitializeSolution(unsigned int solutionIndex);
75 
76  virtual bool IsSolutionInitialized(unsigned int solutionIndex);
77 
78  virtual void DestroySolution(unsigned int solutionIndex);
79 
80  virtual void SetMaximumNonZeroValuesInMatrix(unsigned int, unsigned int)
81  {
82  }
83 
84  /* assembly & solving routines */
85  virtual Float GetMatrixValue(unsigned int i, unsigned int j,
86  unsigned int matrixIndex) const
87  {
88  return ( *( ( *m_Matrices )[matrixIndex] ) )(i, j);
89  }
90  virtual void SetMatrixValue(unsigned int i, unsigned int j, Float value,
91  unsigned int matrixIndex)
92  {
93  ( *( ( *m_Matrices )[matrixIndex] ) )(i, j) = value;
94  }
95  virtual void AddMatrixValue(unsigned int i, unsigned int j, Float value,
96  unsigned int matrixIndex)
97  {
98  ( *( ( *m_Matrices )[matrixIndex] ) )(i, j) += value;
99  }
100  virtual Float GetVectorValue(unsigned int i,
101  unsigned int vectorIndex) const
102  {
103  return ( *( ( *m_Vectors )[vectorIndex] ) )[i];
104  }
105  virtual void SetVectorValue(unsigned int i, Float value,
106  unsigned int vectorIndex)
107  {
108  ( *( ( *m_Vectors )[vectorIndex] ) )(i) = value;
109  }
110  virtual void AddVectorValue(unsigned int i, Float value,
111  unsigned int vectorIndex)
112  {
113  ( *( ( *m_Vectors )[vectorIndex] ) )(i) += value;
114  }
115  virtual Float GetSolutionValue(unsigned int i, unsigned int solutionIndex) const;
116 
117  virtual void SetSolutionValue(unsigned int i, Float value,
118  unsigned int solutionIndex)
119  {
120  ( *( ( *m_Solutions )[solutionIndex] ) )(i) = value;
121  }
122  virtual void AddSolutionValue(unsigned int i, Float value,
123  unsigned int solutionIndex)
124  {
125  ( *( ( *m_Solutions )[solutionIndex] ) )(i) += value;
126  }
127  virtual void Solve(void);
128 
129  /* matrix & vector manipulation routines */
130  virtual void ScaleMatrix(Float scale, unsigned int matrixIndex);
131 
132  virtual void SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2);
133 
134  virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2);
135 
136  virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2);
137 
138  virtual void CopySolution2Vector(unsigned solutionIndex, unsigned int vectorIndex);
139 
140  virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex);
141 
142  virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex,
143  unsigned int rightMatrixIndex);
144 
145  virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex);
146 
147 private:
148 
150  // std::vector< vnl_sparse_matrix<Float>* > *m_Matrices;
152 
154  std::vector<vnl_vector<Float> *> *m_Vectors;
155 
157  std::vector<vnl_vector<Float> *> *m_Solutions;
158 };
159 }
160 } // end namespace itk::fem
161 
162 #endif
163