sparse_matrix_03.exe : sparse_matrix_03.g.$(OBJEXT) $(libraries)
sparse_matrix_04.exe : sparse_matrix_04.g.$(OBJEXT) $(libraries)
sparse_matrix_05.exe : sparse_matrix_05.g.$(OBJEXT) $(libraries)
+sparse_matrix_05a.exe : sparse_matrix_05a.g.$(OBJEXT) $(libraries)
sparse_matrix_06.exe : sparse_matrix_06.g.$(OBJEXT) $(libraries)
sparse_matrix_07.exe : sparse_matrix_07.g.$(OBJEXT) $(libraries)
sparse_matrix_08.exe : sparse_matrix_08.g.$(OBJEXT) $(libraries)
mapping_q4_3d \
q_points find_cell_1 find_cell_2 find_cell_3 \
sparse_matrix_01 sparse_matrix_02 sparse_matrix_03 \
- sparse_matrix_04 sparse_matrix_05 sparse_matrix_06 \
+ sparse_matrix_04 sparse_matrix_05 sparse_matrix_05a \
+ sparse_matrix_06 \
sparse_matrix_07 sparse_matrix_08 sparse_matrix_09 \
sparse_matrix_10 sparse_matrix_11 sparse_matrix_12
SparseMatrix<double> m(sp);
// first set a few entries. count how many
- // entries we have
+ // entries we have. note that for square
+ // matrices we also always store the
+ // diagonal element, so add one per row,
+ // but don't count it when traversing the
+ // row
unsigned int counter = 0;
for (unsigned int i=0; i<m.m(); ++i)
- for (unsigned int j=0; j<m.m(); ++j)
- if ((i+2*j+1) % 3 == 0)
- {
- m.set (i,j, i*j*.5+.5);
- ++counter;
- }
+ {
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ m.set (i,j, i*j*.5+.5);
+ if (i!=j)
+ ++counter;
+ }
+ ++counter;
+ }
deallog << m.n_nonzero_elements() << std::endl;
Assert (m.n_nonzero_elements() == counter,
--- /dev/null
+//---------------------------- sparse_matrix_05a.cc ---------------------------
+// sparse_matrix_05.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_05a.cc ---------------------------
+
+
+// check querying the number of nonzero elements in
+// SparseMatrix when we don't store the diagonal elements explicitly
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>
+#include <fstream>
+
+
+void test ()
+{
+ SparsityPattern sp (5,5,3,false);
+ for (unsigned int i=0; i<5; ++i)
+ for (unsigned int j=0; j<5; ++j)
+ if ((i+2*j+1) % 3 == 0)
+ sp.add (i,j);
+ sp.compress ();
+
+ SparseMatrix<double> m(sp);
+
+ // first set a few entries. count how many
+ // entries we have. note that for square
+ // matrices we also always store the
+ // diagonal element, except when as above
+ // we set the special flag for the matrix
+ // sparsity pattern
+ unsigned int counter = 0;
+ for (unsigned int i=0; i<m.m(); ++i)
+ for (unsigned int j=0; j<m.m(); ++j)
+ if ((i+2*j+1) % 3 == 0)
+ {
+ m.set (i,j, i*j*.5+.5);
+ ++counter;
+ }
+
+ deallog << m.n_nonzero_elements() << std::endl;
+ Assert (m.n_nonzero_elements() == counter,
+ ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+ std::ofstream logfile("sparse_matrix_05a.output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+
+ try
+ {
+ test ();
+ }
+ 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;
+ };
+}