]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Finally fix that bugger of a bug...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 8 Jan 2013 03:35:51 +0000 (03:35 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 8 Jan 2013 03:35:51 +0000 (03:35 +0000)
git-svn-id: https://svn.dealii.org/trunk@27971 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/source/numerics/matrix_tools.cc
tests/bits/apply_boundary_values_04.cc [new file with mode: 0644]
tests/bits/apply_boundary_values_04/cmp/generic [new file with mode: 0644]

index 1c08b22e5845075e63793d4af57edd99b2480cb4..c207c009b10aec65d7af570dbbc96ffbf14c3207 100644 (file)
@@ -2087,7 +2087,7 @@ namespace MatrixTools
                                         diagonal_entry * new_rhs;
 
                 // set matrix entry to zero
-                q->value() = 0.;
+                p->value() = 0.;
               }
           }
 
diff --git a/tests/bits/apply_boundary_values_04.cc b/tests/bits/apply_boundary_values_04.cc
new file mode 100644 (file)
index 0000000..d14d476
--- /dev/null
@@ -0,0 +1,159 @@
+//----------------------------  apply_boundary_values_04.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_04.cc  ---------------------------
+
+
+// check MatrixTools::local_apply_boundary_values with 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,
+                                                true);
+      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, true);
+
+  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_04/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_04/cmp/generic b/tests/bits/apply_boundary_values_04/cmp/generic
new file mode 100644 (file)
index 0000000..71f7be2
--- /dev/null
@@ -0,0 +1,19 @@
+
+DEAL::A=
+0.000e+00  1.000e+00  0.000e+00  3.000e+00  
+4.000e+00  5.000e+00  0.000e+00  7.000e+00  
+0.000e+00  0.000e+00  1.000e+01  0.000e+00  
+1.200e+01  1.300e+01  0.000e+00  1.500e+01  
+DEAL::B=
+0.000e+00  1.000e+00  0.000e+00  3.000e+00  
+4.000e+00  5.000e+00  0.000e+00  7.000e+00  
+0.000e+00  0.000e+00  1.000e+01  0.000e+00  
+1.200e+01  1.300e+01  0.000e+00  1.500e+01  
+DEAL::b1=
+-8.300e+01 -2.500e+02 4.200e+02 -5.840e+02 
+DEAL::b2=
+-8.300e+01 -2.500e+02 4.200e+02 -5.840e+02 
+DEAL::|A|=0
+DEAL::|B|=27.1662
+DEAL::|b1|=0
+DEAL::|b2|=766.058

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.