mmentity.hh 4.06 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

Praetorius, Simon's avatar
Praetorius, Simon committed
22 23 24
    /// Entity in the host grid
    using HostGridEntity = typename HostGrid::Traits::template Codim<0>::Entity;

Praetorius, Simon's avatar
Praetorius, Simon committed
25
  public:
Praetorius, Simon's avatar
Praetorius, Simon committed
26 27 28
    enum { codimension = 0 };
    enum { dimension = HostGridEntity::dimension };
    enum { mydimension = HostGridEntity::mydimension };
Praetorius, Simon's avatar
Praetorius, Simon committed
29 30

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

Praetorius, Simon's avatar
Praetorius, Simon committed
33 34
    /// Seed representing the vector of entities in the MultiMesh
    using EntitySeed = MultiEntitySeed<0, HostGrid>;
Praetorius, Simon's avatar
Praetorius, Simon committed
35

Praetorius, Simon's avatar
Praetorius, Simon committed
36
  public:
Praetorius, Simon's avatar
Praetorius, Simon committed
37
    /// Constructor from std::vector
38
    using std::vector<HostGridEntity>::vector;
Praetorius, Simon's avatar
Praetorius, Simon committed
39 40 41 42

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

    /// 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
    {
49
      return {(*this)[source_i], (*this)[target_i]};
Praetorius, Simon's avatar
Praetorius, Simon committed
50 51
    }

52 53 54 55 56 57 58 59 60 61 62 63 64 65
    /// Return coordinate `sourceLocal` in coordinates of target entity
    static typename LocalGeometry::GlobalCoordinate local (
        const HostGridEntity& source,
        const HostGridEntity& target,
        const typename LocalGeometry::LocalCoordinate& sourceLocal)
    {
      if (source.level() == target.level())
        return sourceLocal;
      else if (source.level() < target.level())
        return localGeometry(target, source).local(sourceLocal);
      else
        return localGeometry(source, target).global(sourceLocal);
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
66 67 68 69 70 71 72
    /// Return the partitionType of any entity in the multiEntity
    // [[ expects: all partitionType are the same ]]
    PartitionType partitionType () const
    {
      return max().partitionType();
    }

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    /// Return the geometry of the entity with maximal level
    typename HostGridEntity::Geometry geometry () const
    {
      return max().geometry();
    }

    /// Return the type of the entity with maximal level
    GeometryType type () const
    {
      return max().type();
    }

    /// The entities are always regular, since irregular entities are not allowed in multimesh
    bool isRegular() const { return true; }

    /// Return the maximal level
    int level () const
    {
      return max().level();
    }

    /// Return whether the entity with minimal level has boundary intersections
    bool hasBoundaryIntersections () const
    {
      return min().hasBoundaryIntersections();
    }
99

Praetorius, Simon's avatar
Praetorius, Simon committed
100 101 102 103 104 105
    /// \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.
     **/
Praetorius, Simon's avatar
Praetorius, Simon committed
106 107 108 109 110 111 112
    MultiMeshEntitySeed<0,HostGrid> seed (std::size_t idx) const
    {
      return {(*this)[idx], idx};
    }

    /// Return an entity seed to restore the multi-entity.
    EntitySeed seed () const
Praetorius, Simon's avatar
Praetorius, Simon committed
113
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
114
      return {*this};
Praetorius, Simon's avatar
Praetorius, Simon committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    }

    /// 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