error_estimator_* \
cylinder_shell_* \
grid_in_* \
- compressed_sparsity_pattern_*
+ compressed_sparsity_pattern_* \
+ point_difference_*
# tests for the hp branch:
# fe_collection_*
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
const BlockSparseMatrix<double>::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
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<double>::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;
}
--- /dev/null
+//---------------------------- 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 <lac/block_sparsity_pattern.h>
+#include <lac/block_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+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<double> 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<double>::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;
+ };
+}
--- /dev/null
+//---------------------------- 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 <base/logstream.h>
+#include <base/function_lib.h>
+#include <base/quadrature_lib.h>
+#include <lac/vector.h>
+#include <grid/tria.h>
+#include <grid/tria_iterator.h>
+#include <grid/tria_accessor.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_handler.h>
+#include <fe/fe_q.h>
+#include <numerics/vectors.h>
+
+#include <fstream>
+#include <cmath>
+#include <iostream>
+
+
+template<int dim>
+class MySquareFunction : public Function<dim>
+{
+ public:
+ virtual double value (const Point<dim> &p,
+ const unsigned int component) const
+ { return (component+1)*p.square()+1; };
+
+ virtual void vector_value (const Point<dim> &p,
+ Vector<double> &values) const
+ { values(0) = value(p,0); };
+};
+
+
+template<int dim>
+class MyExpFunction : public Function<dim>
+{
+ public:
+ virtual double value (const Point<dim> &p,
+ const unsigned int component) const
+ { return std::exp (p(0)); };
+
+ virtual void vector_value (const Point<dim> &p,
+ Vector<double> &values) const
+ { values(0) = value(p,0); };
+};
+
+
+
+template <int dim>
+void make_mesh (Triangulation<dim> &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<steps[dim]; ++i)
+ {
+ typename Triangulation<dim>::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 <int dim>
+void
+check ()
+{
+ Triangulation<dim> tria;
+ make_mesh (tria);
+
+ FE_Q<dim> element(3);
+ DoFHandler<dim> 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<dim> function_1;
+ static const Functions::CosineFunction<dim> function_2;
+
+ const Function<dim> &
+ function = (i==0 ?
+ static_cast<const Function<dim>&>(function_1) :
+ static_cast<const Function<dim>&>(function_2));
+
+ Vector<double> 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<dim> p[3];
+ for (unsigned int d=0; d<dim; ++d)
+ {
+ p[0][d] = 0;
+ p[1][d] = 0.5;
+ p[2][d] = 1./3.;
+ }
+ Vector<double> 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<dim>(),
+ 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 ();
+}