From 6dcf5eb3ca3f6e79fe964d9a2583912cce79c80f Mon Sep 17 00:00:00 2001 From: Uli Sack <usack@math.fu-berlin.de> Date: Mon, 22 Oct 2012 08:56:47 +0000 Subject: [PATCH] added test for static interlace/deinterlace methods in genericvectortools.hh [[Imported from SVN: r7054]] --- dune/solvers/test/Makefile.am | 8 ++- dune/solvers/test/genericvectortoolstest.cc | 80 +++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 dune/solvers/test/genericvectortoolstest.cc diff --git a/dune/solvers/test/Makefile.am b/dune/solvers/test/Makefile.am index 655f0be1..1254b8f6 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 00000000..fdf52fd5 --- /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; + + } + -- GitLab