21 #ifndef SELDON_FILE_RELAXATION_MATVECT_CXX
41 template <
class T0,
class Prop0,
class Allocator0,
42 class T1,
class Storage1,
class Allocator1,
43 class T2,
class Storage2,
class Allocator2,
class T3>
47 const T3& omega,
int iter,
int type_ssor)
49 T1 temp, zero; T3 one;
56 #ifdef SELDON_CHECK_BOUNDS
59 throw WrongDim(
"SOR",
"Matrix must be squared.");
61 if (ma != X.GetM() || ma != B.GetM())
62 throw WrongDim(
"SOR",
"Matrix and vector dimensions are incompatible.");
65 long* ptr = A.GetPtr();
66 int* ind = A.GetInd();
71 if (type_ssor % 2 == 0)
72 for (
int i = 0; i < iter; i++)
73 for (
int j = 0; j < ma; j++)
79 temp += data[k] * X(ind[k]);
83 #ifdef SELDON_CHECK_BOUNDS
84 if ( (k >= ptr[j+1]) || (ind[k] != j) || (data[k] == zero))
86 " a non-null diagonal");
93 temp += data[k] * X(ind[k]);
97 X(j) = (one-omega) * X(j) + omega * (B(j) - temp) / ajj;
101 if (type_ssor % 3 == 0)
102 for (
int i = 0; i < iter; i++)
103 for (
int j = ma-1 ; j >= 0; j--)
109 temp += data[k] * X(ind[k]);
117 temp += data[k] * X(ind[k]);
121 X(j) = (one-omega) * X(j) + omega * (B(j) - temp) / ajj;
134 template <
class T0,
class Prop0,
class Allocator0,
135 class T1,
class Storage1,
class Allocator1,
136 class T2,
class Storage2,
class Allocator2,
class T3>
141 int iter,
int type_ssor)
143 T1 temp, zero; T3 one;
144 SetComplexZero(zero);
149 #ifdef SELDON_CHECK_BOUNDS
152 throw WrongDim(
"SOR",
"Matrix must be squared.");
154 if (ma != X.GetM() || ma != B.GetM())
155 throw WrongDim(
"SOR",
"Matrix and vector dimensions are incompatible.");
161 if (type_ssor % 2 == 0)
162 for (
int i = 0; i < iter; i++)
163 for (
int j = 0; j < ma; j++)
167 while (A.Index(j, k) < j)
169 temp += A.Value(j, k) * X(A.Index(j, k));
175 #ifdef SELDON_CHECK_BOUNDS
176 if ((A.Index(j, k) != j) || (ajj == zero))
178 "a non-null diagonal");
182 while (k < A.GetRowSize(j))
184 temp += A.Value(j, k) * X(A.Index(j, k));
188 X(j) = (one-omega) * X(j) + omega * (B(j) - temp) / ajj;
192 if (type_ssor % 3 == 0)
193 for (
int i = 0; i < iter; i++)
194 for (
int j = ma-1; j >= 0; j--)
198 while (A.Index(j, k) < j)
200 temp += A.Value(j, k) * X(A.Index(j, k));
206 while (k < A.GetRowSize(j))
208 temp += A.Value(j, k) * X(A.Index(j, k));
212 X(j) = (one-omega) * X(j) + omega * (B(j) - temp) / ajj;
225 template <
class T0,
class Prop0,
class Allocator0,
226 class T1,
class Storage1,
class Allocator1,
227 class T2,
class Storage2,
class Allocator2,
class T3>
231 const T3& omega,
int iter,
int type_ssor)
233 T1 temp, zero; T3 one;
234 SetComplexZero(zero);
239 #ifdef SELDON_CHECK_BOUNDS
242 throw WrongDim(
"SOR",
"Matrix must be squared.");
244 if (ma != X.GetM() || ma != B.GetM())
245 throw WrongDim(
"SOR",
"Matrix and vector dimensions are incompatible.");
248 long* ptr = A.GetPtr();
249 int* ind = A.GetInd();
250 T0* data = A.GetData();
261 T3 coef = (one - omega) / omega;
262 if (type_ssor % 2 == 0)
263 for (
int i = 0; i < iter; i++)
266 for (
int j = 0; j < ma; j++)
270 #ifdef SELDON_CHECK_BOUNDS
271 if ( (ptr[j] >= ptr[j+1]) || (ind[ptr[j]] != j) || (data[ptr[j]] == zero))
273 " a non-null diagonal");
277 for (
long k = ptr[j]+1; k < ptr[j+1]; k++)
278 temp += data[k] * X(ind[k]);
280 X(j) = coef * ajj * X(j) + B(j) - temp;
284 for (
int j = 0; j < ma; j++)
286 X(j) *= omega / data[ptr[j]];
287 for (
long k = ptr[j]+1; k < ptr[j+1]; k++)
288 X(ind[k]) -= data[k]*X(j);
295 if (type_ssor % 3 == 0)
296 for (
int i = 0; i < iter; i++)
299 for (
int j = ma-1; j >= 0; j--)
301 for (
long k = ptr[j]+1; k < ptr[j+1]; k++)
302 X(ind[k]) -= data[k]*X(j);
304 X(j) = B(j) + coef * data[ptr[j]] * X(j);
308 for (
int j = ma-1; j >= 0; j--)
312 for (
long k = ptr[j]+1; k < ptr[j+1]; k++)
313 temp += data[k]*X(ind[k]);
315 X(j) = (X(j) - temp) * omega / ajj;
329 template <
class T0,
class Prop0,
class Allocator0,
330 class T1,
class Storage1,
class Allocator1,
331 class T2,
class Storage2,
class Allocator2,
class T3>
335 const T3& omega,
int iter,
int type_ssor)
337 T1 temp, zero; T3 one;
338 SetComplexZero(zero);
343 #ifdef SELDON_CHECK_BOUNDS
346 throw WrongDim(
"SOR",
"Matrix must be squared.");
348 if (ma != X.GetM() || ma != B.GetM())
349 throw WrongDim(
"SOR",
"Matrix and vector dimensions are incompatible.");
361 T3 coef = (one - omega) / omega;
362 if (type_ssor % 2 == 0)
363 for (
int i = 0; i < iter; i++)
366 for (
int j = 0; j < ma; j++)
371 #ifdef SELDON_CHECK_BOUNDS
372 if ((A.Index(j, 0) != j) || (ajj == zero))
374 "a non-null diagonal");
377 for (
int k = 1; k < A.GetRowSize(j); k++)
378 temp += A.Value(j, k) * X(A.Index(j, k));
380 X(j) = coef * ajj * X(j) + B(j) - temp;
384 for (
int j = 0; j < ma; j++)
386 X(j) *= omega / A.Value(j, 0);
387 for (
int k = 1; k < A.GetRowSize(j); k++)
388 X(A.Index(j, k)) -= A.Value(j, k)*X(j);
395 if (type_ssor % 3 == 0)
396 for (
int i = 0; i < iter; i++)
399 for (
int j = ma-1; j >= 0; j--)
402 for (
int k = 1; k < A.GetRowSize(j); k++)
403 X(A.Index(j, k)) -= A.Value(j, k) * X(j);
405 X(j) = B(j) + coef * ajj * X(j);
409 for (
int j = ma-1; j >= 0; j--)
413 for (
int k = 1; k < A.GetRowSize(j); k++)
414 temp += A.Value(j, k)*X(A.Index(j, k));
416 X(j) = (X(j) - temp) * omega / ajj;
430 template <
class T0,
class Prop0,
class Allocator0,
431 class T1,
class Storage1,
class Allocator1,
432 class T2,
class Storage2,
class Allocator2,
class T3>
436 const T3& omega,
int iter,
int type_ssor)
439 SetComplexZero(zero);
444 #ifdef SELDON_CHECK_BOUNDS
447 throw WrongDim(
"SOR",
"Matrix must be squared.");
449 if (ma != X.GetM() || ma != B.GetM())
450 throw WrongDim(
"SOR",
"Matrix and vector dimensions are incompatible.");
453 long* ptr = A.GetPtr();
454 int* ind = A.GetInd();
455 T0* data = A.GetData();
465 T3 coef = (one - omega) / omega;
466 if (type_ssor % 2 == 0)
467 for (
int i = 0; i < iter; i++)
470 for (
int j = 0; j < ma; j++)
475 X(ind[k]) -= data[k]*X(j);
479 #ifdef SELDON_CHECK_BOUNDS
480 if ( (k >= ptr[j+1]) || (ind[k] != j) || (data[k] == zero))
482 " a non-null diagonal");
486 X(j) = B(j) + coef * ajj * X(j);
490 for (
int j = 0; j < ma; j++)
500 X(ind[k]) -= data[k]*X(j);
508 if (type_ssor % 3 == 0)
509 for (
int i = 0; i < iter; i++)
512 for (
int j = ma-1; j >= 0; j--)
517 X(ind[k]) -= data[k]*X(j);
521 #ifdef SELDON_CHECK_BOUNDS
522 if ( (k < ptr[j]) || (ind[k] != j) || (data[k] == zero) )
524 "a non-null diagonal");
527 X(j) = B(j) + coef*data[k]*X(j);
531 for (
int j = ma-1; j >= 0; j--)
537 X(j) *= omega/data[k];
541 X(ind[k]) -= data[k]*X(j);
557 template <
class T0,
class Prop0,
class Allocator0,
558 class T1,
class Storage1,
class Allocator1,
559 class T2,
class Storage2,
class Allocator2,
class T3>
563 const T3& omega,
int iter,
int type_ssor)
566 SetComplexZero(zero);
571 #ifdef SELDON_CHECK_BOUNDS
574 throw WrongDim(
"SOR",
"Matrix must be squared.");
576 if (ma != X.GetM() || ma != B.GetM())
577 throw WrongDim(
"SOR",
"Matrix and vector dimensions are incompatible.");
588 T3 coef = (one - omega) / omega;
589 if (type_ssor % 2 == 0)
590 for (
int i = 0; i < iter; i++)
593 for (
int j = 0; j < ma; j++)
596 while (A.Index(j, k) < j)
598 X(A.Index(j, k)) -= A.Value(j, k) * X(j);
604 #ifdef SELDON_CHECK_BOUNDS
605 if ((A.Index(j, k) != j) || (ajj == zero))
607 "a non-null diagonal");
610 X(j) = B(j) + coef * ajj * X(j);
614 for (
int j = 0; j < ma; j++)
617 while (A.Index(j, k) < j)
620 ajj = A.Value(j, k); k++;
622 while (k < A.GetColumnSize(j))
624 X(A.Index(j, k)) -= A.Value(j, k) * X(j);
632 if (type_ssor % 3 == 0)
633 for (
int i = 0; i < iter; i++)
636 for (
int j = ma-1; j >= 0; j--)
638 int k = A.GetColumnSize(j) - 1;
639 while (A.Index(j, k) > j)
641 X(A.Index(j, k)) -= A.Value(j, k) * X(j);
645 X(j) = B(j) + coef*A.Value(j, k)*X(j);
649 for (
int j = ma-1; j >= 0; j--)
651 int k = A.GetColumnSize(j) - 1;
652 while (A.Index(j, k) > j)
655 X(j) *= omega/A.Value(j, k);
659 X(A.Index(j, k)) -= A.Value(j, k) * X(j);
675 template <
class T0,
class Prop0,
class Allocator0,
676 class T1,
class Storage1,
class Allocator1,
677 class T2,
class Storage2,
class Allocator2,
class T3>
681 const T3& omega,
int iter,
int type_ssor)
683 T1 temp, zero; T3 one;
684 SetComplexZero(zero);
689 #ifdef SELDON_CHECK_BOUNDS
692 throw WrongDim(
"SOR",
"Matrix must be squared.");
694 if (ma != X.GetM() || ma != B.GetM())
695 throw WrongDim(
"SOR",
"Matrix and vector dimensions are incompatible.");
698 long* ptr = A.GetPtr();
699 int* ind = A.GetInd();
700 T0* data = A.GetData();
710 T3 coef = (one - omega) / omega;
711 if (type_ssor % 2 == 0)
712 for (
int i = 0; i < iter; i++)
715 for (
int j = 0; j < ma; j++)
717 #ifdef SELDON_CHECK_BOUNDS
718 if ( (ptr[j] >= ptr[j+1]) || (ind[ptr[j+1]-1] != j)
719 || (data[ptr[j+1]-1] == zero) )
721 "a non-null diagonal");
724 ajj = data[ptr[j+1]-1];
726 for (
long k = ptr[j]; k < ptr[j+1]-1; k++)
727 X(ind[k]) -= data[k] * X(j);
729 X(j) = coef * ajj * X(j) + B(j);
733 for (
int j = 0; j < ma; j++)
735 ajj = data[ptr[j+1]-1];
736 for (
long k = ptr[j]; k < ptr[j+1]-1; k++)
737 X(j) -= data[k] * X(ind[k]);
746 if (type_ssor % 3 == 0)
747 for (
int i = 0; i < iter; i++)
750 for (
int j = ma-1; j >= 0; j--)
753 ajj = data[ptr[j+1]-1];
754 for (
long k = ptr[j]; k < ptr[j+1]-1; k++)
755 temp -= data[k] * X(ind[k]);
757 X(j) = B(j) + coef * ajj * X(j) + temp;
761 for (
int j = ma-1; j >= 0; j--)
764 ajj = data[ptr[j+1]-1];
766 for (
long k = ptr[j]; k < ptr[j+1]-1; k++)
767 X(ind[k]) -= data[k] * X(j);
781 template <
class T0,
class Prop0,
class Allocator0,
782 class T1,
class Storage1,
class Allocator1,
783 class T2,
class Storage2,
class Allocator2,
class T3>
787 const T3& omega,
int iter,
int type_ssor)
789 T1 temp, zero; T3 one;
790 SetComplexZero(zero);
795 #ifdef SELDON_CHECK_BOUNDS
798 throw WrongDim(
"SOR",
"Matrix must be squared.");
800 if (ma != X.GetM() || ma != B.GetM())
801 throw WrongDim(
"SOR",
"Matrix and vector dimensions are incompatible.");
813 T3 coef = (one - omega) / omega;
814 if (type_ssor % 2 == 0)
815 for (
int i = 0; i < iter; i++)
818 for (
int j = 0; j < ma; j++)
820 int kmax = A.GetColumnSize(j)-1;
821 ajj = A.Value(j, kmax);
823 #ifdef SELDON_CHECK_BOUNDS
824 if ((A.Index(j, kmax) != j) || (ajj == zero))
826 "a non-null diagonal");
829 for (
int k = 0; k < kmax; k++)
830 X(A.Index(j, k)) -= A.Value(j, k) * X(j);
832 X(j) = coef * ajj * X(j) + B(j);
836 for (
int j = 0; j < ma; j++)
838 int kmax = A.GetColumnSize(j)-1;
839 ajj = A.Value(j, kmax);
840 for (
int k = 0; k < kmax; k++)
841 X(j) -= A.Value(j, k) * X(A.Index(j, k));
850 if (type_ssor % 3 == 0)
851 for (
int i = 0; i < iter; i++)
854 for (
int j = ma-1; j >= 0; j--)
857 int kmax = A.GetColumnSize(j)-1;
858 ajj = A.Value(j, kmax);
859 for (
int k = 0; k < kmax; k++)
860 temp -= A.Value(j, k) * X(A.Index(j, k));
862 X(j) = B(j) + coef * ajj * X(j) + temp;
866 for (
int j = ma-1; j >= 0; j--)
869 int kmax = A.GetColumnSize(j)-1;
870 ajj = A.Value(j, kmax);
872 for (
int k = 0; k < kmax; k++)
873 X(A.Index(j, k)) -= A.Value(j, k) * X(j);
884 template <
class T0,
class Prop0,
class Allocator0,
885 class T1,
class Storage1,
class Allocator1,
886 class T2,
class Storage2,
class Allocator2,
class T3>
887 void SorVector(
const SeldonTranspose& transM,
888 const Matrix<T0, Prop0, RowSparse, Allocator0>& A,
889 Vector<T2, Storage2, Allocator2>& X,
890 const Vector<T1, Storage1, Allocator1>& B,
891 const T3& omega,
int iter,
int type_ssor)
893 if (transM.NoTrans())
894 return SorVector(A, X, B, omega, iter, type_ssor);
896 Matrix<T0, Prop0, ColSparse, Allocator0> Ac;
897 Ac.SetData(A.GetN(), A.GetM(), A.GetDataSize(),
898 A.GetData(), A.GetPtr(), A.GetInd());
900 SorVector(Ac, X, B, omega, iter, type_ssor);
905 template <
class T0,
class Prop0,
class Allocator0,
906 class T1,
class Storage1,
class Allocator1,
907 class T2,
class Storage2,
class Allocator2,
class T3>
908 void SorVector(
const SeldonTranspose& transM,
909 const Matrix<T0, Prop0, ColSparse, Allocator0>& A,
910 Vector<T2, Storage2, Allocator2>& X,
911 const Vector<T1, Storage1, Allocator1>& B,
912 const T3& omega,
int iter,
int type_ssor)
914 if (transM.NoTrans())
915 return SorVector(A, X, B, omega, iter, type_ssor);
917 Matrix<T0, Prop0, RowSparse, Allocator0> Ac;
918 Ac.SetData(A.GetN(), A.GetM(), A.GetDataSize(),
919 A.GetData(), A.GetPtr(), A.GetInd());
921 SorVector(Ac, X, B, omega, iter, type_ssor);
926 template <
class T0,
class Prop0,
class Allocator0,
927 class T1,
class Storage1,
class Allocator1,
928 class T2,
class Storage2,
class Allocator2,
class T3>
929 void SorVector(
const SeldonTranspose& transM,
930 const Matrix<T0, Prop0, RowSymSparse, Allocator0>& A,
931 Vector<T2, Storage2, Allocator2>& X,
932 const Vector<T1, Storage1, Allocator1>& B,
933 const T3& omega,
int iter,
int type_ssor)
935 SorVector(A, X, B, omega, iter, type_ssor);
939 template <
class T0,
class Prop0,
class Allocator0,
940 class T1,
class Storage1,
class Allocator1,
941 class T2,
class Storage2,
class Allocator2,
class T3>
942 void SorVector(
const SeldonTranspose& transM,
943 const Matrix<T0, Prop0, ColSymSparse, Allocator0>& A,
944 Vector<T2, Storage2, Allocator2>& X,
945 const Vector<T1, Storage1, Allocator1>& B,
946 const T3& omega,
int iter,
int type_ssor)
948 SorVector(A, X, B, omega, iter, type_ssor);
952 template <
class T0,
class Prop0,
class Allocator0,
953 class T1,
class Storage1,
class Allocator1,
954 class T2,
class Storage2,
class Allocator2,
class T3>
955 void SorVector(
const SeldonTranspose& transM,
956 const Matrix<T0, Prop0, ArrayRowSparse, Allocator0>& A,
957 Vector<T2, Storage2, Allocator2>& X,
958 const Vector<T1, Storage1, Allocator1>& B,
959 const T3& omega,
int iter,
int type_ssor)
961 if (transM.NoTrans())
962 return SorVector(A, X, B, omega, iter, type_ssor);
964 Matrix<T0, Prop0, ArrayColSparse, Allocator0> Ac;
965 Ac.SetData(A.GetN(), A.GetM(), A.GetData());
967 SorVector(Ac, X, B, omega, iter, type_ssor);
972 template <
class T0,
class Prop0,
class Allocator0,
973 class T1,
class Storage1,
class Allocator1,
974 class T2,
class Storage2,
class Allocator2,
class T3>
975 void SorVector(
const SeldonTranspose& transM,
976 const Matrix<T0, Prop0, ArrayColSparse, Allocator0>& A,
977 Vector<T2, Storage2, Allocator2>& X,
978 const Vector<T1, Storage1, Allocator1>& B,
979 const T3& omega,
int iter,
int type_ssor)
981 if (transM.NoTrans())
982 return SorVector(A, X, B, omega, iter, type_ssor);
984 Matrix<T0, Prop0, ArrayRowSparse, Allocator0> Ac;
985 Ac.SetData(A.GetN(), A.GetM(), A.GetData());
987 SorVector(Ac, X, B, omega, iter, type_ssor);
992 template <
class T0,
class Prop0,
class Allocator0,
993 class T1,
class Storage1,
class Allocator1,
994 class T2,
class Storage2,
class Allocator2,
class T3>
995 void SorVector(
const SeldonTranspose& transM,
996 const Matrix<T0, Prop0, ArrayRowSymSparse, Allocator0>& A,
997 Vector<T2, Storage2, Allocator2>& X,
998 const Vector<T1, Storage1, Allocator1>& B,
999 const T3& omega,
int iter,
int type_ssor)
1001 SorVector(A, X, B, omega, iter, type_ssor);
1005 template <
class T0,
class Prop0,
class Allocator0,
1006 class T1,
class Storage1,
class Allocator1,
1007 class T2,
class Storage2,
class Allocator2,
class T3>
1008 void SorVector(
const SeldonTranspose& transM,
1009 const Matrix<T0, Prop0, ArrayColSymSparse, Allocator0>& A,
1010 Vector<T2, Storage2, Allocator2>& X,
1011 const Vector<T1, Storage1, Allocator1>& B,
1012 const T3& omega,
int iter,
int type_ssor)
1014 SorVector(A, X, B, omega, iter, type_ssor);
1019 #define SELDON_FILE_RELAXATION_MATVECT_CXX