--- /dev/null
+//---------------------------- sparse_matrix_vector_01.cc ---------------------------
+// vector_11.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+// Version:
+//
+// Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- sparse_matrix_vector_01.cc ---------------------------
+
+
+// check SparseMatrix::vmult
+
+#include "../tests.h"
+#include <lac/vector.h>
+#include <lac/sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (Vector<double> &v,
+ Vector<double> &w)
+{
+ // set some entries in the
+ // matrix. actually, set them all
+ SparsityPattern sp (v.size(),v.size(),v.size());
+ for (unsigned int i=0; i<v.size(); ++i)
+ for (unsigned int j=0; j<v.size(); ++j)
+ sp.add (i,j);
+ sp.compress ();
+
+ // then create a matrix from that
+ SparseMatrix<double> m(sp);
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ m.set (i,j, i+2*j);
+
+ for (unsigned int i=0; i<v.size(); ++i)
+ v(i) = i;
+
+ v.compress ();
+ w.compress ();
+
+ // w:=Mv
+ m.vmult (w,v);
+
+ // make sure we get the expected result
+ for (unsigned int i=0; i<v.size(); ++i)
+ {
+ Assert (v(i) == i, ExcInternalError());
+
+ double result = 0;
+ for (unsigned int j=0; j<m.m(); ++j)
+ result += (i+2*j)*j;
+ Assert (w(i) == result, ExcInternalError());
+ }
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+ std::ofstream logfile("sparse_matrix_vector_01.output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+
+ try
+ {
+ Vector<double> v (100);
+ Vector<double> w (100);
+ test (v,w);
+ }
+ catch (std::exception &exc)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Exception on processing: " << std::endl
+ << exc.what() << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+
+ return 1;
+ }
+ catch (...)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Unknown exception!" << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ return 1;
+ };
+}
--- /dev/null
+//---------------------------- sparse_matrix_vector_02.cc ---------------------------
+// vector_11.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+// Version:
+//
+// Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- sparse_matrix_vector_02.cc ---------------------------
+
+
+// check SparseMatrix::Tvmult
+
+#include "../tests.h"
+#include <lac/vector.h>
+#include <lac/sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (Vector<double> &v,
+ Vector<double> &w)
+{
+ // set some entries in the
+ // matrix. actually, set them all
+ SparsityPattern sp (v.size(),v.size(),v.size());
+ for (unsigned int i=0; i<v.size(); ++i)
+ for (unsigned int j=0; j<v.size(); ++j)
+ sp.add (i,j);
+ sp.compress ();
+
+ // then create a matrix from that
+ SparseMatrix<double> m(sp);
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ m.set (i,j, i+2*j);
+
+ for (unsigned int i=0; i<v.size(); ++i)
+ v(i) = i;
+
+ v.compress ();
+ w.compress ();
+
+ // w:=Mv
+ m.Tvmult (w,v);
+
+ // make sure we get the expected result
+ for (unsigned int i=0; i<v.size(); ++i)
+ {
+ Assert (v(i) == i, ExcInternalError());
+
+ double result = 0;
+ for (unsigned int j=0; j<m.m(); ++j)
+ result += (j+2*i)*j;
+ Assert (w(i) == result, ExcInternalError());
+ }
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+ std::ofstream logfile("sparse_matrix_vector_02.output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+
+ try
+ {
+ Vector<double> v (100);
+ Vector<double> w (100);
+ test (v,w);
+ }
+ catch (std::exception &exc)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Exception on processing: " << std::endl
+ << exc.what() << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+
+ return 1;
+ }
+ catch (...)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Unknown exception!" << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ return 1;
+ };
+}
--- /dev/null
+//---------------------------- sparse_matrix_vector_03.cc ---------------------------
+// vector_11.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+// Version:
+//
+// Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- sparse_matrix_vector_03.cc ---------------------------
+
+
+// check SparseMatrix::vmult_add
+
+#include "../tests.h"
+#include <lac/vector.h>
+#include <lac/sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (Vector<double> &v,
+ Vector<double> &w)
+{
+ // set some entries in the
+ // matrix. actually, set them all
+ SparsityPattern sp (v.size(),v.size(),v.size());
+ for (unsigned int i=0; i<v.size(); ++i)
+ for (unsigned int j=0; j<v.size(); ++j)
+ sp.add (i,j);
+ sp.compress ();
+
+ // then create a matrix from that
+ SparseMatrix<double> m(sp);
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ m.set (i,j, i+2*j);
+
+ for (unsigned int i=0; i<v.size(); ++i)
+ {
+ v(i) = i;
+ w(i) = i;
+ }
+
+ v.compress ();
+ w.compress ();
+
+ // w:=Mv
+ m.vmult_add (w,v);
+
+ // make sure we get the expected result
+ for (unsigned int i=0; i<v.size(); ++i)
+ {
+ Assert (v(i) == i, ExcInternalError());
+
+ double result = 0;
+ for (unsigned int j=0; j<m.m(); ++j)
+ result += (i+2*j)*j;
+ Assert (w(i) == i+result, ExcInternalError());
+ }
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+ std::ofstream logfile("sparse_matrix_vector_03.output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+
+ try
+ {
+ Vector<double> v (100);
+ Vector<double> w (100);
+ test (v,w);
+ }
+ catch (std::exception &exc)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Exception on processing: " << std::endl
+ << exc.what() << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+
+ return 1;
+ }
+ catch (...)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Unknown exception!" << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ return 1;
+ };
+}
--- /dev/null
+//---------------------------- sparse_matrix_vector_04.cc ---------------------------
+// vector_11.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+// Version:
+//
+// Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- sparse_matrix_vector_04.cc ---------------------------
+
+
+// check SparseMatrix::Tvmult_add
+
+#include "../tests.h"
+#include <lac/vector.h>
+#include <lac/sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (Vector<double> &v,
+ Vector<double> &w)
+{
+ // set some entries in the
+ // matrix. actually, set them all
+ SparsityPattern sp (v.size(),v.size(),v.size());
+ for (unsigned int i=0; i<v.size(); ++i)
+ for (unsigned int j=0; j<v.size(); ++j)
+ sp.add (i,j);
+ sp.compress ();
+
+ // then create a matrix from that
+ SparseMatrix<double> m(sp);
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ m.set (i,j, i+2*j);
+
+ for (unsigned int i=0; i<v.size(); ++i)
+ {
+ v(i) = i;
+ w(i) = i;
+ }
+
+ v.compress ();
+ w.compress ();
+
+ // w:=Mv
+ m.Tvmult_add (w,v);
+
+ // make sure we get the expected result
+ for (unsigned int i=0; i<v.size(); ++i)
+ {
+ Assert (v(i) == i, ExcInternalError());
+
+ double result = 0;
+ for (unsigned int j=0; j<m.m(); ++j)
+ result += (j+2*i)*j;
+ Assert (w(i) == i+result, ExcInternalError());
+ }
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+ std::ofstream logfile("sparse_matrix_vector_04.output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+
+ try
+ {
+ Vector<double> v (100);
+ Vector<double> w (100);
+ test (v,w);
+ }
+ catch (std::exception &exc)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Exception on processing: " << std::endl
+ << exc.what() << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+
+ return 1;
+ }
+ catch (...)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Unknown exception!" << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ return 1;
+ };
+}
--- /dev/null
+//---------------------------- sparse_matrix_vector_05.cc ---------------------------
+// vector_11.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+// Version:
+//
+// Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- sparse_matrix_vector_05.cc ---------------------------
+
+
+// check SparseMatrix::matrix_scalar_product
+
+#include "../tests.h"
+#include <lac/vector.h>
+#include <lac/sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (Vector<double> &v,
+ Vector<double> &w)
+{
+ // set some entries in the
+ // matrix. actually, set them all
+ SparsityPattern sp (v.size(),v.size(),v.size());
+ for (unsigned int i=0; i<v.size(); ++i)
+ for (unsigned int j=0; j<v.size(); ++j)
+ sp.add (i,j);
+ sp.compress ();
+
+ // then create a matrix from that
+ SparseMatrix<double> m(sp);
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ m.set (i,j, i+2*j);
+
+ for (unsigned int i=0; i<v.size(); ++i)
+ {
+ v(i) = i;
+ w(i) = i+1;
+ }
+
+ v.compress ();
+ w.compress ();
+
+ // <w,Mv>
+ const double s = m.matrix_scalar_product (w,v);
+
+ // make sure we get the expected result
+ for (unsigned int i=0; i<v.size(); ++i)
+ {
+ Assert (v(i) == i, ExcInternalError());
+ Assert (w(i) == i+1, ExcInternalError());
+ }
+
+ double result = 0;
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ result += (i+2*j)*j*(i+1);
+
+ Assert (s == result, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+ std::ofstream logfile("sparse_matrix_vector_05.output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+
+ try
+ {
+ Vector<double> v (100);
+ Vector<double> w (100);
+ test (v,w);
+ }
+ catch (std::exception &exc)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Exception on processing: " << std::endl
+ << exc.what() << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+
+ return 1;
+ }
+ catch (...)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Unknown exception!" << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ return 1;
+ };
+}
--- /dev/null
+//---------------------------- sparse_matrix_vector_06.cc ---------------------------
+// vector_11.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+// Version:
+//
+// Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- sparse_matrix_vector_06.cc ---------------------------
+
+
+// check SparseMatrix::matrix_norm_square
+
+#include "../tests.h"
+#include <lac/vector.h>
+#include <lac/sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (Vector<double> &v)
+{
+ // set some entries in the
+ // matrix. actually, set them all
+ SparsityPattern sp (v.size(),v.size(),v.size());
+ for (unsigned int i=0; i<v.size(); ++i)
+ for (unsigned int j=0; j<v.size(); ++j)
+ sp.add (i,j);
+ sp.compress ();
+
+ // then create a matrix from that
+ SparseMatrix<double> m(sp);
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ m.set (i,j, i+2*j);
+
+ for (unsigned int i=0; i<v.size(); ++i)
+ v(i) = i;
+
+ v.compress ();
+
+ // <w,Mv>
+ const double s = m.matrix_norm_square (v);
+
+ // make sure we get the expected result
+ for (unsigned int i=0; i<v.size(); ++i)
+ Assert (v(i) == i, ExcInternalError());
+
+ double result = 0;
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ result += (i+2*j)*j*i;
+
+ Assert (s == result, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+ std::ofstream logfile("sparse_matrix_vector_06.output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+
+ try
+ {
+ Vector<double> v (100);
+ test (v);
+ }
+ catch (std::exception &exc)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Exception on processing: " << std::endl
+ << exc.what() << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+
+ return 1;
+ }
+ catch (...)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Unknown exception!" << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ return 1;
+ };
+}
--- /dev/null
+//---------------------------- sparse_matrix_vector_07.cc ---------------------------
+// vector_11.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+// Version:
+//
+// Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- sparse_matrix_vector_07.cc ---------------------------
+
+
+// check SparseMatrix::matrix_norm_square
+
+#include "../tests.h"
+#include <lac/vector.h>
+#include <lac/sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (Vector<double> &v,
+ Vector<double> &w,
+ Vector<double> &x)
+{
+ // set some entries in the
+ // matrix. actually, set them all
+ SparsityPattern sp (v.size(),v.size(),v.size());
+ for (unsigned int i=0; i<v.size(); ++i)
+ for (unsigned int j=0; j<v.size(); ++j)
+ sp.add (i,j);
+ sp.compress ();
+
+ // then create a matrix from that
+ SparseMatrix<double> m(sp);
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ m.set (i,j, i+2*j);
+
+ for (unsigned int i=0; i<v.size(); ++i)
+ {
+ v(i) = i;
+ w(i) = i+1;
+ }
+
+ v.compress ();
+ w.compress ();
+
+ // x=w-Mv
+ const double s = m.residual (x, v, w);
+
+ // make sure we get the expected result
+ for (unsigned int i=0; i<v.size(); ++i)
+ {
+ Assert (v(i) == i, ExcInternalError());
+ Assert (w(i) == i+1, ExcInternalError());
+
+ double result = i+1;
+ for (unsigned int j=0; j<m.m(); ++j)
+ result -= (i+2*j)*j;
+
+ Assert (x(i) == result, ExcInternalError());
+ }
+
+ Assert (s == x.l2_norm(), ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+ std::ofstream logfile("sparse_matrix_vector_07.output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+
+ try
+ {
+ Vector<double> v (100);
+ Vector<double> w (100);
+ Vector<double> x (100);
+ test (v,w,x);
+ }
+ catch (std::exception &exc)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Exception on processing: " << std::endl
+ << exc.what() << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+
+ return 1;
+ }
+ catch (...)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Unknown exception!" << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ return 1;
+ };
+}
--- /dev/null
+
+DEAL::OK
--- /dev/null
+
+DEAL::OK
--- /dev/null
+
+DEAL::OK
--- /dev/null
+
+DEAL::OK
--- /dev/null
+
+DEAL::OK
--- /dev/null
+
+DEAL::OK
--- /dev/null
+
+DEAL::OK