mmentity.hh 2.77 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
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 76 77 78 79 80 81 82 83 84 85 86
// -*- 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
{
  template <class GridImp>
  class MultiEntity
      : public std::vector<typename GridImp::HostGridType::Traits::template Codim<0>::Entity>
  {
  private:
    using ctype = typename GridImp::ctype;

  public:
    enum { dimension = GridImp::dimension };

    /// The type of a local geometry
    using LocalGeometry = Dune::Geometry<dimension, dimension, const GridImp, MultiMeshLocalGeometry>;

    using EntitySeed = typename GridImp::Traits::template Codim<0>::EntitySeed;

    /// Entity in the host grid
    using HostGridEntity = typename GridImp::HostGridType::Traits::template Codim<0>::Entity;

    /// 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)
    {
      using LocalGeometryImp = MultiMeshLocalGeometry<dimension, dimension, const GridImp>;
      return LocalGeometry{LocalGeometryImp{source, target}};
    }

    /// 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
    {
      using LocalGeometryImp = MultiMeshLocalGeometry<dimension, dimension, const GridImp>;
      return LocalGeometry{LocalGeometryImp{(*this)[source_i], (*this)[target_i]}};
    }

    /// \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
    {
      using EntitySeedImp = MultiMeshEntitySeed<0, const GridImp>;
      return EntitySeedImp{(*this)[entity_i], entity_i};
    }

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