testiterator.cc 2.73 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1 2 3 4 5 6 7 8 9 10 11
// -*- 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 <iostream>
#include <dune/common/parallel/mpihelper.hh> // An initializer of MPI
#include <dune/common/exceptions.hh> // We use exceptions
#include <dune/common/timer.hh>

Praetorius, Simon's avatar
Praetorius, Simon committed
12
#if HAVE_ALBERTA
Praetorius, Simon's avatar
Praetorius, Simon committed
13
#include <dune/grid/albertagrid.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
14
#endif
Praetorius, Simon's avatar
Praetorius, Simon committed
15
#include <dune/grid/yaspgrid.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
16
#if HAVE_UG
17
#include <dune/grid/uggrid.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
18 19
#endif
#if HAVE_DUNE_ALUGRID
20
#include <dune/alugrid/grid.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
21
#endif
Praetorius, Simon's avatar
Praetorius, Simon committed
22 23

#include <dune/multimesh/multimesh.hh>
24
#include <dune/multimesh/mmgridfactory.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
25
#include <dune/multimesh/utility/structuredgridbuilder.hh>
26

27
#define GRID 2
Praetorius, Simon's avatar
Praetorius, Simon committed
28 29 30 31 32 33 34 35

using namespace Dune;

template <class Grid>
void printGrid(Grid const& grid)
{
  volatile std::size_t n = 0;
  Dune::Timer t;
36
  for (auto const& entities : elements(grid.leafGridView())) {
Praetorius, Simon's avatar
Praetorius, Simon committed
37
    n += grid.leafIndexSet(0).index(entities[0]);
38 39
    std::cout << "indices = [";
    for (std::size_t i = 0; i < entities.size(); ++i) {
Praetorius, Simon's avatar
Praetorius, Simon committed
40
      std::cout << (i > 0 ? ", " : "") << grid.leafIndexSet(i).index(entities[i]);
41 42 43 44
    }
    std::cout << "]\n";
  }
  std::cout << "n = " << n << "\n";
Praetorius, Simon's avatar
Praetorius, Simon committed
45 46 47 48 49 50 51 52 53
  std::cout << "time: " << t.elapsed() << "\n";
}

template <class Grid>
void printGrid2(Grid const& grid)
{
  volatile std::size_t n = 0;
  Dune::Timer t;
  for (auto const& entity : elements(grid.leafGridView()))
54
    n += grid.leafIndexSet().index(entity);
Praetorius, Simon's avatar
Praetorius, Simon committed
55 56 57 58 59 60 61 62 63
  std::cout << n << "\n";
  std::cout << "time: " << t.elapsed() << "\n";
}


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

Praetorius, Simon's avatar
Praetorius, Simon committed
64
#if GRID == 2 && HAVE_DUNE_ALUGRID
Praetorius, Simon's avatar
Praetorius, Simon committed
65

66 67 68 69
  FieldVector<double,2> lower_left = {-1.5, -1.5};
  FieldVector<double,2> bbox = {1.5, 1.5};
  std::array<unsigned int,2> num_elements = {2, 2};
  using HostGrid = Dune::ALUGrid<2, 2, Dune::simplex, Dune::conforming>;
70

Praetorius, Simon's avatar
Praetorius, Simon committed
71
  using Factory = StructuredGridBuilder<MultiMesh<HostGrid> >;
72
  GridFactory<MultiMesh<HostGrid> > gridFactory(3);
73 74 75

  auto gridPtr = Factory::createSimplexGrid(gridFactory, lower_left, bbox, num_elements);
  auto& grid = *gridPtr;
Praetorius, Simon's avatar
Praetorius, Simon committed
76

Praetorius, Simon's avatar
Praetorius, Simon committed
77
#elif GRID == 3 && HAVE_ALBERTA
Praetorius, Simon's avatar
Praetorius, Simon committed
78

Praetorius, Simon's avatar
Praetorius, Simon committed
79 80 81
  assert(argc > 1);
  std::string filename = argv[1];
  using HostGrid = Dune::AlbertaGrid<3,3>;
82 83 84
  MultiMesh<HostGrid> grid(3, filename);
  grid[0].globalRefine(8);
  grid[1].globalRefine(8);
85

Praetorius, Simon's avatar
Praetorius, Simon committed
86 87 88 89 90 91 92 93
#else

  FieldVector<double,3> lower_left = {-1.5, -1.5, -1.5};
  FieldVector<double,3> bbox = {1.5, 1.5, 1.5};
  std::array<int,3> num_elements = {2, 2, 2};
  using HostGrid = YaspGrid<3, EquidistantOffsetCoordinates<double,3>>;
  MultiMesh<HostGrid> grid(3, lower_left, bbox, num_elements);

Praetorius, Simon's avatar
Praetorius, Simon committed
94 95
#endif

96
  std::cout << "number of grids = " << grid.size() << "\n";
97

98
  printGrid2(grid[0]);
Praetorius, Simon's avatar
Praetorius, Simon committed
99
  printGrid(grid);
100 101 102
  grid[0].globalRefine(2);
  grid[1].globalRefine(1);
  printGrid2(grid[0]);
Praetorius, Simon's avatar
Praetorius, Simon committed
103 104
  printGrid(grid);
}