From 640e1a0c0ea42ae067df83cd6f6a412254d61c80 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 8 Jan 2013 03:35:51 +0000 Subject: [PATCH] Finally fix that bugger of a bug... git-svn-id: https://svn.dealii.org/trunk@27971 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/source/numerics/matrix_tools.cc | 2 +- tests/bits/apply_boundary_values_04.cc | 159 ++++++++++++++++++ .../bits/apply_boundary_values_04/cmp/generic | 19 +++ 3 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 tests/bits/apply_boundary_values_04.cc create mode 100644 tests/bits/apply_boundary_values_04/cmp/generic diff --git a/deal.II/source/numerics/matrix_tools.cc b/deal.II/source/numerics/matrix_tools.cc index 1c08b22e58..c207c009b1 100644 --- a/deal.II/source/numerics/matrix_tools.cc +++ b/deal.II/source/numerics/matrix_tools.cc @@ -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 index 0000000000..d14d4761d8 --- /dev/null +++ b/tests/bits/apply_boundary_values_04.cc @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +void test () +{ + const unsigned int N=4; + SparsityPattern sparsity (N,N,N); + for (unsigned int i=0; i A(sparsity), B(sparsity); + Vector b1 (N); + Vector 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 boundary_values; + boundary_values[N/2] = 42; + + // then fill the matrices + std::vector local_dofs (N); + FullMatrix local_matrix (N,N); + Vector local_vector (N); + { + for (unsigned int i=0; i 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 index 0000000000..71f7be2c03 --- /dev/null +++ b/tests/bits/apply_boundary_values_04/cmp/generic @@ -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 -- 2.39.5