unitcube.hh 1.52 KB
Newer Older
1 2 3 4 5
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef UNITCUBE_HH
#define UNITCUBE_HH

6 7 8
#include <array>
#include <memory>

9
#include <dune/common/exceptions.hh>
10
#include <dune/common/fvector.hh>
11
#include <dune/grid/utility/structuredgridfactory.hh>
12

13
// default implementation for any template parameter
14
template<typename T, int variant>                      /*@\label{uc:uc0}@*/
15 16 17
class UnitCube
{
public:
18
  typedef T GridType;
19

20 21
  static const int dim = GridType::dimension;

22 23 24
  // constructor throwing exception
  UnitCube ()
  {
25 26
    Dune::FieldVector<typename GridType::ctype,dim> lowerLeft(0);
    Dune::FieldVector<typename GridType::ctype,dim> upperRight(1);
27
    std::array<unsigned int,dim> elements;
28 29 30 31 32 33 34 35 36 37 38 39 40
    std::fill(elements.begin(), elements.end(), 1);

    switch (variant) {
    case 1 :
      grid_ = Dune::StructuredGridFactory<GridType>::createCubeGrid(lowerLeft, upperRight, elements);
      break;
    case 2 :
      grid_ = Dune::StructuredGridFactory<GridType>::createSimplexGrid(lowerLeft, upperRight, elements);
      break;
    default :
      DUNE_THROW( Dune::NotImplemented, "Variant "
                  << variant << " of unit cube not implemented." );
    }
41 42
  }

43
  T& grid ()
44
  {
45
    return *grid_;
46 47 48 49
  }

private:
  // the constructed grid object
50
  std::shared_ptr<T> grid_;
51 52
};                                                     /*@\label{uc:uc1}@*/

53

54 55 56
// include specializations
#include "unitcube_yaspgrid.hh"
#include "unitcube_albertagrid.hh"
57
#include "unitcube_alugrid.hh"
58 59

#endif