From: Wolfgang Bangerth Date: Mon, 12 Jul 2004 14:02:59 +0000 (+0000) Subject: New tests. Modify some tests so that they can work with the block iterators. X-Git-Tag: v8.0.0~14956 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c10803dff89851843aa9f6eb14d393106d404d93;p=dealii.git New tests. Modify some tests so that they can work with the block iterators. git-svn-id: https://svn.dealii.org/trunk@9509 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/bits/Makefile b/tests/bits/Makefile index 9838f14a33..b22a149976 100644 --- a/tests/bits/Makefile +++ b/tests/bits/Makefile @@ -61,7 +61,8 @@ tests_x = anna_? \ error_estimator_* \ cylinder_shell_* \ grid_in_* \ - compressed_sparsity_pattern_* + compressed_sparsity_pattern_* \ + point_difference_* # tests for the hp branch: # fe_collection_* diff --git a/tests/bits/block_sparse_matrix_iterator_02.cc b/tests/bits/block_sparse_matrix_iterator_02.cc index 65da36de6d..c8e7071888 100644 --- a/tests/bits/block_sparse_matrix_iterator_02.cc +++ b/tests/bits/block_sparse_matrix_iterator_02.cc @@ -74,13 +74,9 @@ void test () begin = A.begin(), end = A.end(); - deallog << begin->row() << ' ' << begin->index() << ' ' + deallog << begin->row() << ' ' << begin->column() << ' ' << begin->block_row() << ' ' << begin->block_column() - << std::endl; - deallog << end->row() << ' ' << end->index() << ' ' - << end->column() << ' ' << end->block_row() << ' ' - << end->block_column() << std::endl; // this matrix certainly has entries diff --git a/tests/bits/block_sparse_matrix_iterator_03.cc b/tests/bits/block_sparse_matrix_iterator_03.cc index 6e7ed93fca..ed237685ba 100644 --- a/tests/bits/block_sparse_matrix_iterator_03.cc +++ b/tests/bits/block_sparse_matrix_iterator_03.cc @@ -71,15 +71,11 @@ void test () const BlockSparseMatrix::const_iterator begin = A.begin(), - end = A.end(A.m()); + end = A.end(); - deallog << begin->row() << ' ' << begin->index() << ' ' + deallog << begin->row() << ' ' << begin->column() << ' ' << begin->block_row() << ' ' << begin->block_column() - << std::endl; - deallog << end->row() << ' ' << end->index() << ' ' - << end->column() << ' ' << end->block_row() << ' ' - << end->block_column() << std::endl; // this matrix certainly has entries diff --git a/tests/bits/block_sparse_matrix_iterator_04.cc b/tests/bits/block_sparse_matrix_iterator_04.cc index 772fdd544b..a45448c33e 100644 --- a/tests/bits/block_sparse_matrix_iterator_04.cc +++ b/tests/bits/block_sparse_matrix_iterator_04.cc @@ -39,30 +39,11 @@ void test () for (unsigned int i=0; i<4; ++i) ++it; - deallog << it->row() << ' ' << it->index() << ' ' - << it->column() << ' ' << it->block_row() << ' ' - << it->block_column() - << std::endl; - // now also get an end iterator BlockSparseMatrix::const_iterator it2 = m.end(); - deallog << it2->row() << ' ' << it2->index() << ' ' - << it2->column() << ' ' << it2->block_row() << ' ' - << it2->block_column() - << std::endl; // make sure that the two of them match Assert (it == it2, ExcInternalError()); - - // interestingly, at the time of writing - // this test, above assertion is ok, but an - // elementwise one is not (we fail in the - // first line) - Assert (it->row() == it2->row(), ExcInternalError()); - Assert (it->block_row() == it2->block_row(), ExcInternalError()); - Assert (it->column() == it2->column(), ExcInternalError()); - Assert (it->block_column() == it2->block_column(), ExcInternalError()); - Assert (it->index() == it2->index(), ExcInternalError()); deallog << "OK" << std::endl; } diff --git a/tests/bits/block_sparse_matrix_iterator_05.cc b/tests/bits/block_sparse_matrix_iterator_05.cc new file mode 100644 index 0000000000..9a15d3f3a8 --- /dev/null +++ b/tests/bits/block_sparse_matrix_iterator_05.cc @@ -0,0 +1,105 @@ +//---------------------------- block_sparse_matrix_iterator_05.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004 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. +// +//---------------------------- block_sparse_matrix_iterator_05.cc --------------------------- + + +// this tests a failure in the design of the block sparse matrix iterators: falling +// off the end of the matrix does not yield the iterator provided by the end() +// function + +#include "../tests.h" +#include +#include +#include +#include + + +void test () +{ + // create a 1x2 block matrix with + // non-quadratic blocks so as to make them + // not specially store the diagonal + BlockSparsityPattern bsp (1,2); + for (unsigned int j=0; j<2; ++j) + bsp.block(0,j).reinit (3,2,1); + bsp.collect_sizes (); + + // leave row 0 of block 0,0 empty, but have + // something in this row for block 0,1 + bsp.block(0,0).add (1,0); + bsp.block(0,1).add (0,0); + bsp.compress (); + + BlockSparseMatrix m(bsp); + + // get the start iterator. it should point + // to the first element of the first row, + // which happens to be in block 0,1 + BlockSparseMatrix::const_iterator it = m.begin(); + + deallog << it->row() << ' ' + << it->column() << ' ' << it->block_row() << ' ' + << it->block_column() + << std::endl; + + Assert (it->row() == 0, ExcInternalError()); + Assert (it->column() == 2, ExcInternalError()); + Assert (it->block_row() == 0, ExcInternalError()); + Assert (it->block_column() == 1, ExcInternalError()); + + // now advance by two (the only two + // elements of the matrix) and make sure + // that we equal the end iterator + ++it; + ++it; + Assert (it == m.end(), ExcInternalError()); + + deallog << "OK" << std::endl; +} + + + +int main () +{ + std::ofstream logfile("block_sparse_matrix_iterator_05.output"); + deallog.attach(logfile); + deallog.depth_console(0); + + try + { + test (); + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/bits/point_difference_01.cc b/tests/bits/point_difference_01.cc new file mode 100644 index 0000000000..971498f504 --- /dev/null +++ b/tests/bits/point_difference_01.cc @@ -0,0 +1,169 @@ +//---------------------------- point_difference_01.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004 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. +// +//---------------------------- point_difference_01.cc --------------------------- + +// check that VectorTools::point_difference returns the same before and after +// the change to a logarithmic algorithm + + + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +template +class MySquareFunction : public Function +{ + public: + virtual double value (const Point &p, + const unsigned int component) const + { return (component+1)*p.square()+1; }; + + virtual void vector_value (const Point &p, + Vector &values) const + { values(0) = value(p,0); }; +}; + + +template +class MyExpFunction : public Function +{ + public: + virtual double value (const Point &p, + const unsigned int component) const + { return std::exp (p(0)); }; + + virtual void vector_value (const Point &p, + Vector &values) const + { values(0) = value(p,0); }; +}; + + + +template +void make_mesh (Triangulation &tria) +{ + + GridGenerator::hyper_cube(tria, -1, 1); + + // refine the mesh in a random way so as to + // generate as many cells with + // hanging nodes as possible + tria.refine_global (4-dim); + const double steps[4] = { /*d=0*/ 0, 7, 3, 3 }; + for (unsigned int i=0; i::active_cell_iterator + cell = tria.begin_active(); + for (unsigned int index=0; cell != tria.end(); ++cell, ++index) + if (index % (3*dim) == 0) + cell->set_refine_flag(); + tria.execute_coarsening_and_refinement (); + } +} + + + + +template +void +check () +{ + Triangulation tria; + make_mesh (tria); + + FE_Q element(3); + DoFHandler dof(tria); + dof.distribute_dofs(element); + + // test with two different functions: one + // that is exactly representable on the + // chosen finite element space, and one + // that isn't + for (unsigned int i=0; i<2; ++i) + { + static const MySquareFunction function_1; + static const Functions::CosineFunction function_2; + + const Function & + function = (i==0 ? + static_cast&>(function_1) : + static_cast&>(function_2)); + + Vector v (dof.n_dofs()); + VectorTools::interpolate (dof, function, v); + + // for the following points, check the + // function value, output it, and + // verify that the value retrieved from + // the interpolated function is close + // enough to that of the real function + // + // also verify that the actual value is + // roughly correct + Point p[3]; + for (unsigned int d=0; d difference(1); + for (unsigned int i=0; i<3; ++i) + { + VectorTools::point_difference (dof, v, function, difference, p[i]); + deallog << difference(0) << std::endl; + Assert (difference(0) < 1e-4, ExcInternalError()); + + VectorTools::point_difference (dof, v, ZeroFunction(), + difference, p[i]); + deallog << difference(0) << std::endl; + Assert (std::abs(-difference(0) - function.value(p[i])) < 1e-4, + ExcInternalError()); + } + } + + deallog << "OK" << std::endl; +} + + +int main () +{ + std::ofstream logfile ("point_difference_01.output"); + logfile.precision (4); + deallog.attach(logfile); + deallog.depth_console (0); + + deallog.push ("1d"); + check<1> (); + deallog.pop (); + deallog.push ("2d"); + check<2> (); + deallog.pop (); + deallog.push ("3d"); + check<3> (); + deallog.pop (); +}