22#ifndef TBCI_SOLVER_ILU0PRECOND_H
23#define TBCI_SOLVER_ILU0PRECOND_H
25#include "tbci/solver/precond.h"
72 unsigned int dimension;
80 if (pivots.size() != matrix->rows())
81 pivots.
resize(matrix->rows());
83 STD__ cerr <<
"\n NULL pointer encountered! \n" <<
STD__ flush;
84 for (
unsigned int i=0;
i<matrix->rows(); ++
i)
85 pivots(
i) =
T(1.0)/(*matrix)(
i,
i);
87 conf.resize(matrix->conf);
88 dimension = matrix->dimension;
89 rowPtr.resize(matrix->rowPtr);
96 unsigned int* confPtr;
100 const unsigned int csize = conf.size();
104 for (
unsigned int i=0;
i<dimension; ++
i)
105 y.setval(
i) = pivots(
i)*
y.get(
i);
116 for (
int g = 0; g < (int)dimension; ++g) {
119 for (
unsigned int i=0; (
i<csize) && ((cnfi = conf(
i)) <= g);) {
120 elementPtr = rowPtr(g - cnfi) + ++
i;
121 sum += (*elementPtr) *
y.get(g - cnfi);
124 y.setval(g) = pivots(g) * (
y.get(g) -
sum);
131 for (
int h = dimension-2;
h >= 0; --
h)
133 confPtr = conf.vecptr();
134 elementPtr = rowPtr(
h) +1;
137 while (elementPtr != rowPtr(
h+1)) {
138 sum += (*elementPtr) *
y.get(
h + (*confPtr));
143 y.setval(
h) -= pivots(
h) *
sum;
156template <
typename T>
class BdMatrix;
187 {
return solve(tv); }
195 unsigned int dimension;
206 if (pivots.size() != dimension)
207 pivots.resize(dimension);
208 BCHK(pivots.size() == 0,
VecErr,
"ILU0_BdMPrecond::update: Null ptr", 0,);
209 for (
unsigned i = 0;
i < dimension; ++
i)
210 pivots.set(
i) =
T(1.0) / A.
get(
i,
i);
223 BCHK(dimension !=
y.size(),
VecErr,
"ILU0_BdMPrecond::solve: Dims don't match", dimension,
y);
226 if (bdconf.size() == 0) {
227 for (
unsigned int i=0;
i<dimension; ++
i)
228 y.setval(
i) *= pivots.get(
i);
238 y.setval(0) = pivots.get(0) * (
y.get(0));
240 const unsigned int bsize = bdconf.size();
241 for (
h = 1;
h < (int)dimension; ++
h) {
243 for (
unsigned int i=0;
i < bsize && (bdi = bdconf.get(
i)) <=
h; ++
i)
244 sum += (*(ldiag.get(bdi) +
h-bdi)) *
y.get (
h-bdi);
245 y.setval(
h) = pivots.get(
h) * (
y.get(
h) -
sum);
253 for (
h = dimension-2;
h >= 0; --
h) {
255 for (
unsigned int i=0;
i < bsize && (bdi = bdconf.get(
i))+
h < (
int)dimension; ++
i)
256 sum += (*(udiag.get(bdi) +
h)) *
y.get(bdi +
h);
257 y.setval(
h) -= pivots.get(
h) *
sum;
const Vector< T > const Vector< T > & x
const Vector< T > const Vector< T > const Vector< T > int T h
#define BCHK(cond, exc, txt, ind, rtval)
#define LIKELY(expr)
branch prediction note that we sometimes on purpose mark the unlikely possibility likely and vice ver...
provides basic Vector functionality but arithmetic operators (+=, - , *, /...).
The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band str...
tbci_traits< T >::const_refval_type get(const unsigned int, const unsigned int) const HOT
BVector< T * > bdiag
pointers to upper and lower diagonals
BVector< unsigned > diagconf
configuration
TVector< T > solve(const Vector< T > &v) const
ILU0_BdMatrixPreconditioner()
TVector< T > transSolve(TVector< T > tv) const
ILU0_BdMatrixPreconditioner(const BdMatrix< T > &A)
TVector< T > solve(TVector< T > x) const
Solve routine as sketched in the Templates book, Fig. 3.2.
TVector< T > transSolve(const Vector< T > &v) const
void update(const BdMatrix< T > &A)
~ILU0_BdMatrixPreconditioner()
TVector< T > transSolve(const Vector< T > &v) const
ILU0_Symm_BdMatrixPreconditioner(const Symm_BdMatrix< T > &A)
TVector< T > solve(TVector< T > x) const
TVector< T > transSolve(TVector< T > tv) const
void update(const Symm_BdMatrix< T > &A)
~ILU0_Symm_BdMatrixPreconditioner()
TVector< T > solve(const Vector< T > &v) const
ILU0_Symm_BdMatrixPreconditioner()
Matrix class with optimized Matrix-Vector multiplication for symmetrical Matrices.
void resize(const T &, const unsigned int)
Temporary Base Class Idiom: Class TVector is used for temporary variables.
T sum(const FS_Vector< dims, T > &fv)