diff --git a/dune/solvers/test/Makefile.am b/dune/solvers/test/Makefile.am index 655f0be1621684c018f19f52683051aca10b7006..1254b8f6c0f2c45536ff72a8cef3fbe90cafa33f 100644 --- a/dune/solvers/test/Makefile.am +++ b/dune/solvers/test/Makefile.am @@ -1,6 +1,7 @@ # list of tests to run -TESTS = lowrankoperatortest \ +TESTS = genericvectortoolstest \ + lowrankoperatortest \ nulloperatortest \ sumoperatortest \ obstacletnnmgtest @@ -21,6 +22,11 @@ GRID_LDFLAGS = $(UG_LDFLAGS) $(ALUGRID_LDFLAGS) # define the programs +genericvectortoolstest_SOURCES = genericvectortoolstest.cc +genericvectortoolstest_CPPFLAGS = $(COMMON_CPPFLAGS) $(GRID_CPPFLAGS) +genericvectortoolstest_LDADD = $(COMMON_LDADD) $(GRID_LDADD) +genericvectortoolstest_LDFLAGS = $(COMMON_LDFLAGS) $(GRID_LDFLAGS) + lowrankoperatortest_SOURCES = lowrankoperatortest.cc lowrankoperatortest_CPPFLAGS = $(COMMON_CPPFLAGS) $(GRID_CPPFLAGS) lowrankoperatortest_LDADD = $(COMMON_LDADD) $(GRID_LDADD) diff --git a/dune/solvers/test/genericvectortoolstest.cc b/dune/solvers/test/genericvectortoolstest.cc new file mode 100644 index 0000000000000000000000000000000000000000..fdf52fd512136144e18febb8f179c5407d9bd948 --- /dev/null +++ b/dune/solvers/test/genericvectortoolstest.cc @@ -0,0 +1,80 @@ +#include <config.h> + +#include <stdio.h> +#include <cmath> + +#include <dune/common/exceptions.hh> +#include <dune/common/fvector.hh> + +#include <dune/istl/bvector.hh> + +#include <dune/solvers/common/genericvectortools.hh> + + +// This tests the interlace/deinterlace methods for consistency, i.e. if (x==deinterlace(interlace(x))) +template <class VectorType, class LargeVectorType, size_t vec_size, size_t inner_size> +bool check() +{ + + bool passed = true; + static const size_t block_size = VectorType::block_type::block_type::dimension; + static const size_t large_block_size = LargeVectorType::block_type::dimension; + + VectorType x(vec_size), x_re(vec_size); + LargeVectorType y(inner_size); + + for (size_t i = 0; i<vec_size; ++i) + { + x[i].resize(inner_size); + for (size_t j=0; j<inner_size; ++j) + for (size_t k=0; k<block_size; ++k) + x[i][j][k] = (1.0*rand()) / RAND_MAX; + } + + GenericVector::interlace(x, y); + GenericVector::deinterlace(y, x_re); + + x_re -= x; + + if (x_re.two_norm()>1e-12) + { + std::cout << "Test failure: deinterlace(interlace(x)) != x." << std::endl; + passed = false; + } + +// if (passed) +// std::cout << "passed"; +// else +// std::cout << "failed."; +// std::cout << std::endl; + + return passed; +} + +int main(int argc, char** argv) try +{ + + bool passed(true); + + static const size_t vec_size = 7; + static const size_t inner_size = 4; + + typedef Dune::FieldVector<double,2> FV2; + typedef Dune::FieldVector<double,3> FV3; + typedef Dune::FieldVector<double,7> FV7; + typedef Dune::FieldVector<double,15> FV11; + + passed = check<Dune::BlockVector<Dune::BlockVector<FV2> >, Dune::BlockVector<Dune::FieldVector<double, vec_size*FV2::dimension> > , vec_size, inner_size>(); + passed = passed and check<Dune::BlockVector<Dune::BlockVector<FV3> >, Dune::BlockVector<Dune::FieldVector<double, vec_size*FV3::dimension> > , vec_size, inner_size>(); + passed = passed and check<Dune::BlockVector<Dune::BlockVector<FV7> >, Dune::BlockVector<Dune::FieldVector<double, vec_size*FV7::dimension> > , vec_size, inner_size>(); + passed = passed and check<Dune::BlockVector<Dune::BlockVector<FV11> >, Dune::BlockVector<Dune::FieldVector<double, vec_size*FV11::dimension> > , vec_size, inner_size>(); + + return passed ? 0 : 1; +} + +catch (Dune::Exception e) { + + std::cout << e << std::endl; + + } +