mmentity.hh 2.38 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_MULTIMESH_ENTITY_HH
#define DUNE_MULTIMESH_ENTITY_HH

#include <vector>

#include <dune/grid/common/geometry.hh>

#include "mmentityseed.hh"
#include "mmgeometry.hh"

namespace Dune
{
15
  template <class HostGrid>
Praetorius, Simon's avatar
Praetorius, Simon committed
16
  class MultiEntity
17
      : public std::vector<typename HostGrid::Traits::template Codim<0>::Entity>
Praetorius, Simon's avatar
Praetorius, Simon committed
18
19
  {
  private:
20
    using ctype = typename HostGrid::ctype;
Praetorius, Simon's avatar
Praetorius, Simon committed
21
22

  public:
23
    enum { dimension = HostGrid::dimension };
Praetorius, Simon's avatar
Praetorius, Simon committed
24
25

    /// The type of a local geometry
26
    using LocalGeometry = MultiMeshLocalGeometry<dimension, dimension, HostGrid>;
Praetorius, Simon's avatar
Praetorius, Simon committed
27

28
    using EntitySeed = MultiMeshEntitySeed<0, HostGrid>;
Praetorius, Simon's avatar
Praetorius, Simon committed
29
30

    /// Entity in the host grid
31
    using HostGridEntity = typename HostGrid::Traits::template Codim<0>::Entity;
Praetorius, Simon's avatar
Praetorius, Simon committed
32
33
34
35
36
37
38
39
40
41

    /// Containertype
    using Super = std::vector<HostGridEntity>;

    /// Constructor from std::vector
    using Super::vector;

    /// Return a local geometry of source in target
    static LocalGeometry localGeometry (HostGridEntity const& source, HostGridEntity const& target)
    {
42
      return {source, target};
Praetorius, Simon's avatar
Praetorius, Simon committed
43
44
45
46
47
    }

    /// Return a local geometry of source_i'th entity in target_t'th entity
    LocalGeometry localGeometry (std::size_t source_i, std::size_t target_i) const
    {
48
      return {(*this)[source_i], (*this)[target_i]};
Praetorius, Simon's avatar
Praetorius, Simon committed
49
50
51
52
53
54
55
56
57
58
    }

    /// \brief Return the entity seed which contains sufficient information
    /// to generate the entity again and uses as little memory as possible.
    /**
     * The MultiMeshEntitySeed contains the HostGridEntitySeed and the index of
     * the grid it is extracted from.
     **/
    EntitySeed seed (std::size_t entity_i) const
    {
59
      return {(*this)[entity_i], entity_i};
Praetorius, Simon's avatar
Praetorius, Simon committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
    }

    /// Return the entity with maximal level
    HostGridEntity const& max() const
    {
      // TODO: cache max-element
      auto it_max = std::max_element(this->begin(), this->end(),
        [](auto const& e1, auto const& e2) { return e1.level() < e2.level(); });
      return *it_max;
    }

    /// Return the entity with minimal level
    HostGridEntity const& min() const
    {
      // TODO: cache min-element
      auto it_min = std::min_element(this->begin(), this->end(),
        [](auto const& e1, auto const& e2) { return e1.level() < e2.level(); });
      return *it_min;
    }
  };

}  // end namespace Dune

#endif // DUNE_MULTIMESH_ENTITY_HH