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)
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);
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));
156 template <
typename T>
class BdMatrix;
161 template <
typename T>
187 {
return solve(tv); }
195 unsigned int dimension;
198 template <
typename T>
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);
217 template <
typename T>
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)
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);
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);
T sum(const FS_Vector< dims, T > &fv)
const Vector< T > const Vector< T > & x
Abstract base class for all Preconditioners.
ILU0_Symm_BdMatrixPreconditioner(const Symm_BdMatrix< T > &A)
T & setval(const unsigned long i) const
provides basic Vector functionality but arithmetic operators (+=, - , *, /...).
const Vector< T > const Vector< T > const Vector< T > int T h
The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band str...
TVector< T > solve(TVector< T > x) const
Solve routine as sketched in the Templates book, Fig. 3.2.
tbci_traits< T >::const_refval_type get(const unsigned int, const unsigned int) const HOT
tbci_traits< T >::const_refval_type get(const unsigned long i) const
BVector< T * > bdiag
pointers to upper and lower diagonals
#define BCHK(cond, exc, txt, ind, rtval)
~ILU0_BdMatrixPreconditioner()
ILU0_Symm_BdMatrixPreconditioner()
void update(const Symm_BdMatrix< T > &A)
Matrix class with optimized Matrix-Vector multiplication for symmetrical Matrices.
TVector< T > solve(const Vector< T > &v) const
void resize(const T &, const unsigned int)
TVector< T > transSolve(TVector< T > tv) const
void update(const BdMatrix< T > &A)
ILU0_BdMatrixPreconditioner(const BdMatrix< T > &A)
TVector< T > transSolve(const Vector< T > &v) const
unsigned long size() const
BVector< unsigned > diagconf
configuration
TVector< T > solve(TVector< T > x) const
ILU0_BdMatrixPreconditioner()
TVector< T > transSolve(const Vector< T > &v) const
~ILU0_Symm_BdMatrixPreconditioner()
Temporary Base Class Idiom: Class TVector is used for temporary variables.
TVector< T > transSolve(TVector< T > tv) const
const Vector< T > Vector< T > Vector< T > Vector< T > & y
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > long int int char v
< find minimun of func on grid with resolution res
#define LIKELY(expr)
branch prediction note that we sometimes on purpose mark the unlikely possibility likely and vice ver...
TVector< T > solve(const Vector< T > &v) const