/**************************************************************************/ /* File: blockjacobi.cpp */ /* Author: Joachim Schoeberl */ /* Date: 14. Aug. 2002 */ /**************************************************************************/ #include namespace ngla { using namespace ngla; template JacobiPrecond :: JacobiPrecond (const SparseMatrix & amat, const BitArray * ainner) : mat(amat), inner(ainner) { height = mat.Height(); invdiag = new TM[height]; for (int i = 0; i < height; i++) ngbla::CalcInverse (mat(i,i), invdiag[i]); } /// template JacobiPrecond :: ~JacobiPrecond () { delete invdiag; } /// template void JacobiPrecond :: MultAdd (double s, const BaseVector & x, BaseVector & y) const { const FlatVector fx = dynamic_cast &> (x).FV(); FlatVector fy = dynamic_cast &> (y).FV(); for (int i = 0; i < height; i++) fy(i) += s * (invdiag[i] * fx(i)); } /// template BaseVector * JacobiPrecond :: CreateVector () const { return mat.CreateVector(); } /// template void JacobiPrecond :: GSSmooth (BaseVector & x, const BaseVector & b) const { FlatVector fx = dynamic_cast &> (x).FV(); const FlatVector fb = dynamic_cast &> (b).FV(); for (int i = 0; i < height; i++) { TVX ax = mat.RowTimesVector (i, fx); fx(i) += invdiag[i] * (fb(i) - ax); } } /// template void JacobiPrecond :: GSSmoothBack (BaseVector & x, const BaseVector & b) const { FlatVector fx = dynamic_cast &> (x).FV(); const FlatVector fb = dynamic_cast &> (b).FV(); for (int i = height-1; i >= 0; i--) { TVX ax = mat.RowTimesVector (i, fx); fx(i) += invdiag[i] * (fb(i) - ax); } } /// template void JacobiPrecond :: GSSmoothNumbering (BaseVector & x, const BaseVector & b, const ARRAY & numbering, int forward) const { ; } template JacobiPrecondSymmetric :: JacobiPrecondSymmetric (const SparseMatrixSymmetric & amat, const BitArray * ainner) : JacobiPrecond (amat, ainner) { ; } /// template void JacobiPrecondSymmetric :: GSSmooth (BaseVector & x, const BaseVector & b) const { int i; FlatVector fx = dynamic_cast &> (x).FV(); const FlatVector fb = dynamic_cast &> (b).FV(); const SparseMatrixSymmetric & smat = dynamic_cast&> (this->mat); // x := b - L^t x for (i = 0; i < this->height; i++) { smat.AddRowTransToVectorNoDiag (i, -fx(i), fx); fx(i) = fb(i); } // x := (L+D)^{-1} x for (i = 0; i < this->height; i++) { TVX hv = fx(i) - smat.RowTimesVectorNoDiag (i, fx); fx(i) = this->invdiag[i] * hv; } } /// template void JacobiPrecondSymmetric :: GSSmoothBack (BaseVector & x, const BaseVector & b) const { int i; FlatVector fx = dynamic_cast &> (x).FV(); const FlatVector fb = dynamic_cast &> (b).FV(); const SparseMatrixSymmetric & smat = dynamic_cast&> (this->mat); for (i = this->height-1; i >= 0; i--) { fx(i) = fb(i) - smat.RowTimesVectorNoDiag (i, fx); } for (i = this->height-1; i >= 0; i--) { TVX val = this->invdiag[i] * fx(i); fx(i) = val; smat.AddRowTransToVectorNoDiag (i, -val, fx); } } /// template void JacobiPrecondSymmetric :: GSSmoothNumbering (BaseVector & x, const BaseVector & b, const ARRAY & numbering, int forward) const { ; } template class JacobiPrecond; template class JacobiPrecond; #if MAX_SYS_DIM >= 1 template class JacobiPrecond >; template class JacobiPrecond >; #endif #if MAX_SYS_DIM >= 2 template class JacobiPrecond >; template class JacobiPrecond >; #endif #if MAX_SYS_DIM >= 3 template class JacobiPrecond >; template class JacobiPrecond >; #endif #if MAX_SYS_DIM >= 4 template class JacobiPrecond >; template class JacobiPrecond >; #endif #if MAX_SYS_DIM >= 5 template class JacobiPrecond >; template class JacobiPrecond >; #endif #if MAX_SYS_DIM >= 6 template class JacobiPrecond >; template class JacobiPrecond >; #endif #if MAX_SYS_DIM >= 7 template class JacobiPrecond >; template class JacobiPrecond >; #endif #if MAX_SYS_DIM >= 8 template class JacobiPrecond >; template class JacobiPrecond >; #endif template class JacobiPrecondSymmetric; template class JacobiPrecondSymmetric; #if MAX_SYS_DIM >= 1 template class JacobiPrecondSymmetric >; template class JacobiPrecondSymmetric >; #endif #if MAX_SYS_DIM >= 2 template class JacobiPrecondSymmetric >; template class JacobiPrecondSymmetric >; #endif #if MAX_SYS_DIM >= 3 template class JacobiPrecondSymmetric >; template class JacobiPrecondSymmetric >; #endif #if MAX_SYS_DIM >= 4 template class JacobiPrecondSymmetric >; template class JacobiPrecondSymmetric >; #endif #if MAX_SYS_DIM >= 5 template class JacobiPrecondSymmetric >; template class JacobiPrecondSymmetric >; #endif #if MAX_SYS_DIM >= 6 template class JacobiPrecondSymmetric >; template class JacobiPrecondSymmetric >; #endif #if MAX_SYS_DIM >= 7 template class JacobiPrecondSymmetric >; template class JacobiPrecondSymmetric >; #endif #if MAX_SYS_DIM >= 8 template class JacobiPrecondSymmetric >; template class JacobiPrecondSymmetric >; #endif }