ITK  6.0.0
Insight Toolkit
VNLSparseLUSolverTraits.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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#ifndef VNLSparseLUSolverTraits_h
19#define VNLSparseLUSolverTraits_h
20
21#include "vnl/vnl_vector.h"
22#include "vnl/vnl_sparse_matrix.h"
23#include "vnl/algo/vnl_sparse_lu.h"
24
41template <typename T = double>
43{
44public:
45 using ValueType = T;
46 using MatrixType = vnl_sparse_matrix<ValueType>;
47 using VectorType = vnl_vector<ValueType>;
48 using SolverType = vnl_sparse_lu;
49
51 static bool
53 {
54 return true;
55 }
56
58 static MatrixType
59 InitializeSparseMatrix(const unsigned int & iN)
60 {
61 return MatrixType(iN, iN);
62 }
63
65 static MatrixType
66 InitializeSparseMatrix(const unsigned int & iRow, const unsigned int & iCol)
67 {
68 return MatrixType(iRow, iCol);
69 }
70
72 static VectorType
73 InitializeVector(const unsigned int & iN)
74 {
75 return VectorType(iN);
76 }
77
79 static void
80 FillMatrix(MatrixType & iA, const unsigned int & iR, const unsigned int & iC, const ValueType & iV)
81 {
82 iA(iR, iC) = iV;
83 }
84
86 static void
87 AddToMatrix(MatrixType & iA, const unsigned int & iR, const unsigned int & iC, const ValueType & iV)
88 {
89 iA(iR, iC) += iV;
90 }
91
93 static bool
94 Solve(const MatrixType & iA, const VectorType & iB, VectorType & oX)
95 {
96 SolverType solver(iA);
97 Solve(solver, iB, oX);
98
99 return true;
100 }
101
104 static bool
105 Solve(const MatrixType & iA,
106 const VectorType & iBx,
107 const VectorType & iBy,
108 const VectorType & iBz,
109 VectorType & oX,
110 VectorType & oY,
111 VectorType & oZ)
112 {
113 SolverType solver(iA);
114 Solve(solver, iBx, iBy, iBz, oX, oY, oZ);
115
116 return true;
117 }
118
120 static bool
121 Solve(const MatrixType & iA, const VectorType & iBx, const VectorType & iBy, VectorType & oX, VectorType & oY)
122 {
123 SolverType solver(iA);
124 Solve(solver, iBx, iBy, oX, oY);
125
126 return true;
127 }
128
130 static void
131 Solve(SolverType & solver, const VectorType & iB, VectorType & oX)
132 {
133 oX = solver.solve(iB);
134 }
135
138 static void
140 const VectorType & iBx,
141 const VectorType & iBy,
142 const VectorType & iBz,
143 VectorType & oX,
144 VectorType & oY,
145 VectorType & oZ)
146 {
147 oX = solver.solve(iBx);
148 oY = solver.solve(iBy);
149 oZ = solver.solve(iBz);
150 }
151
154 static void
155 Solve(SolverType & solver, const VectorType & iBx, const VectorType & iBy, VectorType & oX, VectorType & oY)
156 {
157 oX = solver.solve(iBx);
158 oY = solver.solve(iBy);
159 }
160};
161
162#endif
Generic interface for sparse LU solver.
static MatrixType InitializeSparseMatrix(const unsigned int &iRow, const unsigned int &iCol)
initialize a sparse matrix of size iRow x iCol
static void Solve(SolverType &solver, const VectorType &iBx, const VectorType &iBy, VectorType &oX, VectorType &oY)
Solve the linear systems: , factoring the internal matrix if needed.
static bool Solve(const MatrixType &iA, const VectorType &iB, VectorType &oX)
Solve the linear system .
vnl_vector< ValueType > VectorType
vnl_sparse_matrix< ValueType > MatrixType
static void Solve(SolverType &solver, const VectorType &iB, VectorType &oX)
Solve the linear system factoring the internal matrix if needed.
static MatrixType InitializeSparseMatrix(const unsigned int &iN)
initialize a square sparse matrix of size iN x iN
static void FillMatrix(MatrixType &iA, const unsigned int &iR, const unsigned int &iC, const ValueType &iV)
iA[iR][iC] = iV
static bool Solve(const MatrixType &iA, const VectorType &iBx, const VectorType &iBy, const VectorType &iBz, VectorType &oX, VectorType &oY, VectorType &oZ)
Solve the linear systems: , , .
static bool Solve(const MatrixType &iA, const VectorType &iBx, const VectorType &iBy, VectorType &oX, VectorType &oY)
Solve the linear systems: , .
static VectorType InitializeVector(const unsigned int &iN)
initialize a vector of size iN
static void Solve(SolverType &solver, const VectorType &iBx, const VectorType &iBy, const VectorType &iBz, VectorType &oX, VectorType &oY, VectorType &oZ)
Solve the linear systems: , , factoring the internal matrix if needed.
static void AddToMatrix(MatrixType &iA, const unsigned int &iR, const unsigned int &iC, const ValueType &iV)
iA[iR][iC] += iV