multigridview.cc 1.92 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
// -*- 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>

#if HAVE_DUNE_ALUGRID
#include <dune/alugrid/grid.hh>
#endif

#include <dune/multimesh/multigridview.hh>
#include <dune/multimesh/utility/structuredgridbuilder.hh>


using namespace Dune;

template <class GridView>
void printGrid(GridView const& gv)
{
  volatile std::size_t n = 0;
  Dune::Timer t;
  for (auto const& entity : elements(gv))
    n += gv.indexSet().index(entity);
  std::cout << n << "\n";
  std::cout << "time: " << t.elapsed() << "\n";
}

template <class GridView>
void printGrid2(GridView const& gv)
{
  volatile std::size_t n = 0;
  Dune::Timer t;
  for (auto const& entities : elements(gv)) {
    n += gv.indexSet(0).index(entities[0]);
    std::cout << "indices = [";
    for (std::size_t i = 0; i < entities.size(); ++i) {
      std::cout << (i > 0 ? ", " : "") << gv.indexSet(i).index(entities[i]);
    }
    std::cout << "]\n";
  }
  std::cout << "n = " << n << "\n";
  std::cout << "time: " << t.elapsed() << "\n";
}

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

#if HAVE_DUNE_ALUGRID
  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 Grid = Dune::ALUGrid<2, 2, Dune::simplex, Dune::conforming>;

  using Factory = StructuredGridBuilder<Grid>;
  auto gridPtr = Factory::createSimplexGrid(lower_left, bbox, num_elements);
  auto& grid = *gridPtr;

  grid.globalRefine(4);

  printGrid(grid.leafGridView());
  printGrid(grid.levelGridView(2));

  using GridView = MultiGridView<Grid>;
  GridView gridView(grid.leafGridView(), grid.levelGridView(2));

  printGrid2(gridView);

#endif
}