testnumentities.cc 1.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <functional>
#include <iostream>
#include <numeric>

#include <dune/common/filledarray.hh>
#include <dune/common/test/testsuite.hh>
#include <dune/common/parallel/mpihelper.hh>

#include <dune/grid/yaspgrid.hh>

#include <dune/multimesh/multimesh.hh>

using namespace Dune;

template <std::size_t dim, class Test>
void test_dim(Test& test)
{
  FieldVector<double,dim> lower; lower = -1.5;
  FieldVector<double,dim> upper; upper =  1.5;
  auto num_elements = filledArray<dim>(2);

  using HostGrid = YaspGrid<dim, EquidistantOffsetCoordinates<double,dim>>;
  MultiMesh<HostGrid> grid(3, lower, upper, num_elements);

  grid[0].globalRefine(2);
  grid[1].globalRefine(1);
  grid[2].globalRefine(3);

  for (auto const& entities : elements(grid.leafGridView())) {
    test.check(entities.size() == grid.size());
    for (auto const& entity : entities)
      test.check(entity.isLeaf());
  }

  for (auto const& entities : elements(grid.levelGridView(1))) {
    test.check(entities.size() == grid.size());
    for (auto const& entity : entities)
      test.check(entity.level() == 1);
  }
}

int main(int argc, char** argv)
{
  MPIHelper::instance(argc, argv);

  Dune::TestSuite test;
  test_dim<1>(test);
  test_dim<2>(test);
  test_dim<3>(test);
  return test.exit();
}