testiterator.cc 2.64 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
#include <dune/grid/albertagrid.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
13
#include <dune/grid/yaspgrid.hh>
14 15
#include <dune/grid/uggrid.hh>
#include <dune/alugrid/grid.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
16 17

#include <dune/multimesh/multimesh.hh>
18
#include <dune/multimesh/mmgridfactory.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
19
#include <dune/multimesh/utility/structuredgridbuilder.hh>
20

21
#define GRID 2
Praetorius, Simon's avatar
Praetorius, Simon committed
22 23 24 25 26 27 28 29

using namespace Dune;

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


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

58
#if GRID == 1
Praetorius, Simon's avatar
Praetorius, Simon committed
59

Praetorius, Simon's avatar
Praetorius, Simon committed
60 61
  FieldVector<double,3> lower_left = {-1.5, -1.5, -1.5};
  FieldVector<double,3> bbox = {1.5, 1.5, 1.5};
62
  std::array<int,3> num_elements = {2, 2, 2};
Praetorius, Simon's avatar
Praetorius, Simon committed
63
  using HostGrid = YaspGrid<3, EquidistantOffsetCoordinates<double,3>>;
64
  MultiMesh<HostGrid> grid(3, lower_left, bbox, num_elements);
Praetorius, Simon's avatar
Praetorius, Simon committed
65

Praetorius, Simon's avatar
Praetorius, Simon committed
66
#elif GRID == 2
Praetorius, Simon's avatar
Praetorius, Simon committed
67

68 69 70 71
  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>;
72

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

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

79
#elif GRID == 3
Praetorius, Simon's avatar
Praetorius, Simon committed
80

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

Praetorius, Simon's avatar
Praetorius, Simon committed
88 89
#endif

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

92
  printGrid2(grid[0]);
Praetorius, Simon's avatar
Praetorius, Simon committed
93
  printGrid(grid);
94 95 96
  grid[0].globalRefine(2);
  grid[1].globalRefine(1);
  printGrid2(grid[0]);
Praetorius, Simon's avatar
Praetorius, Simon committed
97 98
  printGrid(grid);
}