From 564377f79ef510dc10481ff3b551f162bb417ef1 Mon Sep 17 00:00:00 2001 From: bangerth Date: Tue, 8 Jan 2013 03:21:43 +0000 Subject: [PATCH] New test, to figure out what's going on in matrix_tools.cc these days... git-svn-id: https://svn.dealii.org/trunk@27970 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/bits/apply_boundary_values_03.cc | 159 ++++++++++++++++++ .../bits/apply_boundary_values_03/cmp/generic | 19 +++ 2 files changed, 178 insertions(+) create mode 100644 tests/bits/apply_boundary_values_03.cc create mode 100644 tests/bits/apply_boundary_values_03/cmp/generic diff --git a/tests/bits/apply_boundary_values_03.cc b/tests/bits/apply_boundary_values_03.cc new file mode 100644 index 0000000000..d491375968 --- /dev/null +++ b/tests/bits/apply_boundary_values_03.cc @@ -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 +#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, 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 index 0000000000..92c69dce19 --- /dev/null +++ b/tests/bits/apply_boundary_values_03/cmp/generic @@ -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 -- 2.39.5