]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
New test, to figure out what's going on in matrix_tools.cc these days...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 8 Jan 2013 03:21:43 +0000 (03:21 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 8 Jan 2013 03:21:43 +0000 (03:21 +0000)
git-svn-id: https://svn.dealii.org/trunk@27970 0785d39b-7218-0410-832d-ea1e28bc413d

tests/bits/apply_boundary_values_03.cc [new file with mode: 0644]
tests/bits/apply_boundary_values_03/cmp/generic [new file with mode: 0644]

diff --git a/tests/bits/apply_boundary_values_03.cc b/tests/bits/apply_boundary_values_03.cc
new file mode 100644 (file)
index 0000000..d491375
--- /dev/null
@@ -0,0 +1,159 @@
+//----------------------------  apply_boundary_values_03.cc  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2004, 2005, 2007, 2008, 2013 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.
+//
+//----------------------------  apply_boundary_values_03.cc  ---------------------------
+
+
+// check MatrixTools::local_apply_boundary_values without elimination of
+// columns
+
+#include "../tests.h"
+#include <deal.II/base/function_lib.h>
+#include <deal.II/lac/sparsity_pattern.h>
+#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/tria_iterator.h>
+#include <deal.II/grid/grid_tools.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/dofs/dof_tools.h>
+#include <deal.II/numerics/vector_tools.h>
+#include <deal.II/numerics/matrix_tools.h>
+#include <deal.II/fe/fe_q.h>
+#include <fstream>
+#include <iomanip>
+
+
+void test ()
+{
+  const unsigned int N=4;
+  SparsityPattern sparsity (N,N,N);
+  for (unsigned int i=0; i<N; ++i)
+    for (unsigned int j=0; j<N; ++j)
+      sparsity.add(i,j);
+  sparsity.compress ();
+  SparseMatrix<double> A(sparsity), B(sparsity);
+  Vector<double> b1 (N);
+  Vector<double> b2 (N);
+
+                                   // then fill the two matrices and vectors
+                                   // by setting up bogus matrix entries and
+                                   // (1) writing them into the matrix and
+                                   // applying boundary values later on, or
+                                   // (2) applying them right away
+  std::map<unsigned int, double> boundary_values;
+  boundary_values[N/2] = 42;
+
+  // then fill the matrices
+  std::vector<unsigned int> local_dofs (N);
+  FullMatrix<double> local_matrix (N,N);
+  Vector<double> local_vector (N);
+    {
+      for (unsigned int i=0; i<N; ++i)
+       local_dofs[i] = i;
+
+      local_matrix = 0;
+      for (unsigned int i=0; i<N; ++i)
+        for (unsigned int j=0; j<N; ++j)
+          local_matrix(i,j) = i*N+j;
+      for (unsigned int i=0; i<N; ++i)
+        local_vector(i) = i+1;
+
+      // copy local to global by ourselves
+      for (unsigned int i=0; i<N; ++i)
+        for (unsigned int j=0; j<N; ++j)
+          A.add (local_dofs[i], local_dofs[j], local_matrix(i,j));
+      for (unsigned int i=0; i<N; ++i)
+        b1(local_dofs[i]) += local_vector(i);
+
+                                       // or let other functions do that after
+                                       // removing boundary values
+      MatrixTools::local_apply_boundary_values (boundary_values, local_dofs,
+                                                local_matrix, local_vector,
+                                                false);
+      for (unsigned int i=0; i<N; ++i)
+        for (unsigned int j=0; j<N; ++j)
+          B.add (local_dofs[i], local_dofs[j], local_matrix(i,j));
+      for (unsigned int i=0; i<N; ++i)
+        b2(local_dofs[i]) += local_vector(i);
+    }
+
+                                   // for A, remove boundary values only now.
+  Vector<double> x (N);
+  MatrixTools::apply_boundary_values (boundary_values, A, x, b1, false);
+
+  deallog << "A=" << std::endl;
+  A.print_formatted (deallog.get_file_stream());
+  deallog << "B=" << std::endl;
+  B.print_formatted (deallog.get_file_stream());
+
+  deallog << "b1=" << std::endl;
+  b1.print (deallog.get_file_stream());
+  deallog << "b2=" << std::endl;
+  b2.print (deallog.get_file_stream());
+
+                                   // now comes the check: we subtract B from
+                                   // A, and make sure that the result is zero
+  A.add (-1., B);
+  deallog << "|A|=" << A.frobenius_norm() << std::endl;
+  deallog << "|B|=" << B.frobenius_norm() << std::endl;
+  Assert (A.frobenius_norm() < 1e-12*B.frobenius_norm(),
+          ExcInternalError());
+
+                                   // similar for b1 and b2
+  b1 -= b2;
+  deallog << "|b1|=" << b1.l2_norm() << std::endl;
+  deallog << "|b2|=" << b2.l2_norm() << std::endl;
+  Assert (b1.l2_norm() < 1e-12*b2.l2_norm(),
+          ExcInternalError());
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("apply_boundary_values_03/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  try
+    {
+      test ();
+    }
+  catch (std::exception &exc)
+    {
+      deallog << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      deallog << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      deallog << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      deallog << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/apply_boundary_values_03/cmp/generic b/tests/bits/apply_boundary_values_03/cmp/generic
new file mode 100644 (file)
index 0000000..92c69dc
--- /dev/null
@@ -0,0 +1,19 @@
+
+DEAL::A=
+0.000e+00  1.000e+00  2.000e+00  3.000e+00  
+4.000e+00  5.000e+00  6.000e+00  7.000e+00  
+0.000e+00  0.000e+00  1.000e+01  0.000e+00  
+1.200e+01  1.300e+01  1.400e+01  1.500e+01  
+DEAL::B=
+0.000e+00  1.000e+00  2.000e+00  3.000e+00  
+4.000e+00  5.000e+00  6.000e+00  7.000e+00  
+0.000e+00  0.000e+00  1.000e+01  0.000e+00  
+1.200e+01  1.300e+01  1.400e+01  1.500e+01  
+DEAL::b1=
+1.000e+00 2.000e+00 4.200e+02 4.000e+00 
+DEAL::b2=
+1.000e+00 2.000e+00 4.200e+02 4.000e+00 
+DEAL::|A|=0
+DEAL::|B|=31.2090
+DEAL::|b1|=0
+DEAL::|b2|=420.025

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.