]> https://gitweb.dealii.org/ - dealii.git/commitdiff
New test for previous commit.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 3 May 2011 22:51:59 +0000 (22:51 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 3 May 2011 22:51:59 +0000 (22:51 +0000)
git-svn-id: https://svn.dealii.org/trunk@23678 0785d39b-7218-0410-832d-ea1e28bc413d

tests/umfpack/umfpack_10.cc [new file with mode: 0644]
tests/umfpack/umfpack_10/cmp/generic [new file with mode: 0644]

diff --git a/tests/umfpack/umfpack_10.cc b/tests/umfpack/umfpack_10.cc
new file mode 100644 (file)
index 0000000..215dd03
--- /dev/null
@@ -0,0 +1,138 @@
+//----------------------------------------------------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010, 2011 by the deal.II authors
+//
+//    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.
+//
+//----------------------------------------------------------------------
+
+// test the umfpack sparse direct solver on a mass matrix that is slightly
+// modified to make it nonsymmetric.
+// this is essentially the same test as _03 but for a SparseMatrixEZ
+
+#include "../tests.h"
+#include <iostream>
+#include <fstream>
+#include <cstdlib>
+
+#include <base/quadrature_lib.h>
+#include <base/function.h>
+
+#include <fe/fe_q.h>
+#include <fe/fe_values.h>
+
+#include <dofs/dof_tools.h>
+
+#include <lac/sparse_matrix_ez.h>
+#include <lac/vector.h>
+#include <lac/sparse_direct.h>
+
+#include <grid/tria.h>
+#include <grid/grid_generator.h>
+
+#include <numerics/vectors.h>
+#include <numerics/matrices.h>
+
+
+template <int dim>
+void test ()
+{
+  deallog << dim << 'd' << std::endl;
+
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube (tria,0,1);
+  tria.refine_global (1);
+
+                                   // destroy the uniformity of the matrix by
+                                   // refining one cell
+  tria.begin_active()->set_refine_flag ();
+  tria.execute_coarsening_and_refinement ();
+  tria.refine_global(8-2*dim);
+
+  FE_Q<dim> fe (1);
+  DoFHandler<dim> dof_handler (tria);
+  dof_handler.distribute_dofs (fe);
+
+  deallog << "Number of dofs = " << dof_handler.n_dofs() << std::endl;
+
+  SparsityPattern sparsity_pattern;
+  sparsity_pattern.reinit (dof_handler.n_dofs(),
+                           dof_handler.n_dofs(),
+                           dof_handler.max_couplings_between_dofs());
+  DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern);
+  sparsity_pattern.compress ();
+
+  SparseMatrix<double> B;
+  B.reinit (sparsity_pattern);
+
+  QGauss<dim> qr (2);
+  MatrixTools::create_mass_matrix (dof_handler, qr, B);
+
+                                   // scale lower left part of the matrix by
+                                   // 1/2 and upper right part by 2 to make
+                                   // matrix nonsymmetric
+  for (SparseMatrix<double>::iterator p=B.begin();
+       p!=B.end(); ++p)
+    if (p->column() < p->row())
+      p->value() = p->value()/2;
+    else if (p->column() > p->row())
+      p->value() = p->value() * 2;
+
+                                   // check that we've done it right
+  for (SparseMatrix<double>::iterator p=B.begin();
+       p!=B.end(); ++p)
+    if (p->column() != p->row())
+      Assert (B(p->row(),p->column()) != B(p->column(),p->row()),
+              ExcInternalError());
+
+
+  SparseMatrixEZ<double> B_ez(dof_handler.n_dofs(),
+                             dof_handler.n_dofs());
+  B_ez.copy_from (B);
+  B.clear ();
+  
+                                   // for a number of different solution
+                                   // vectors, make up a matching rhs vector
+                                   // and check what the UMFPACK solver finds
+  for (unsigned int i=0; i<3; ++i)
+    {
+      Vector<double> solution (dof_handler.n_dofs());
+      Vector<double> x (dof_handler.n_dofs());
+      Vector<double> b (dof_handler.n_dofs());
+
+      for (unsigned int j=0; j<dof_handler.n_dofs(); ++j)
+        solution(j) = j+j*(i+1)*(i+1);
+
+      B_ez.vmult (b, solution);
+      x = b;
+      SparseDirectUMFPACK().solve (B_ez, x);
+
+      x -= solution;
+      deallog << "relative norm distance = "
+              << x.l2_norm() / solution.l2_norm()
+              << std::endl;
+      deallog << "absolute norms = "
+              << x.l2_norm() << ' ' << solution.l2_norm()
+              << std::endl;
+      Assert (x.l2_norm() / solution.l2_norm() < 1e-8,
+              ExcInternalError());
+    }
+}
+
+
+int main ()
+{
+  std::ofstream logfile("umfpack_10/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-8);
+
+  test<1> ();
+  test<2> ();
+  test<3> ();
+}
diff --git a/tests/umfpack/umfpack_10/cmp/generic b/tests/umfpack/umfpack_10/cmp/generic
new file mode 100644 (file)
index 0000000..8df3f88
--- /dev/null
@@ -0,0 +1,25 @@
+
+DEAL::1d
+DEAL::Number of dofs = 193
+DEAL::relative norm distance = 0
+DEAL::absolute norms = 0 3084.00
+DEAL::relative norm distance = 0
+DEAL::absolute norms = 0 7709.99
+DEAL::relative norm distance = 0
+DEAL::absolute norms = 0 15420.0
+DEAL::2d
+DEAL::Number of dofs = 1889
+DEAL::relative norm distance = 0
+DEAL::absolute norms = 0 94764.3
+DEAL::relative norm distance = 0
+DEAL::absolute norms = 0 236911.
+DEAL::relative norm distance = 0
+DEAL::absolute norms = 0 473822.
+DEAL::3d
+DEAL::Number of dofs = 1333
+DEAL::relative norm distance = 0
+DEAL::absolute norms = 0 56165.6
+DEAL::relative norm distance = 0
+DEAL::absolute norms = 0 140414.
+DEAL::relative norm distance = 0
+DEAL::absolute norms = 0 280828.

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.