SlotSize.hpp 1.99 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
#pragma once

#include <cassert>
#include <functional>
#include <memory>
#include <dune/common/math.hh>

#include <amdis/Observer.hpp>
#include <amdis/common/Index.hpp>
#include <amdis/common/Math.hpp>
11
#include <amdis/linearalgebra/SymmetryStructure.hpp>
Praetorius, Simon's avatar
Praetorius, Simon committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

namespace AMDiS
{
  class SlotSize
  {
  public:
    /// Number of rows in the matrix
    std::size_t rows() const
    {
      return rows_;
    }

    /// Number of columns in the matrix
    std::size_t cols() const
    {
      return cols_;
    }

    /// Average number of non-zeros per row
    /// In the first time this function is called, use the estRowSize,
32
    /// otherwise take `1.2 * nnz/rows`
Praetorius, Simon's avatar
Praetorius, Simon committed
33
34
35
36
37
38
39
    template <class Matrix>
    std::size_t avgRowSize(Matrix const& matrix) const
    {
      assert(rows_ > 0 && cols_ > 0);
      return matrix.nnz() > 0 ? 6*matrix.nnz() / (5*rows_) : estRowSize_;
    }

40
41
42
43
44
45
    /// Symmetry of the matrix entries
    SymmetryStructure symmetry() const
    {
      return symmetry_;
    }

46
47
    // estimate the number of columns by multiplying the maximal node size with the
    // number of element surrounding a vertex. This number is approximated by the
48
49
    // number of simplices surrounding a vertex in a kuhn triangulation
    template <class RowBasis, class ColBasis>
50
51
    void init(RowBasis const& rowBasis, ColBasis const& colBasis,
              SymmetryStructure symmetry = SymmetryStructure::unknown)
52
    {
53
      using GridView = typename RowBasis::GridView;
Müller, Felix's avatar
Müller, Felix committed
54
      // TODO(FM): Simplify using Dune::factorial with 2.7
55
      static std::size_t surrounding
Müller, Felix's avatar
Müller, Felix committed
56
        = Math::pow<GridView::dimension>(2) * Dune::Factorial<int(GridView::dimension)>::factorial;
57
58
59
60

      rows_ = rowBasis.dimension();
      cols_ = colBasis.dimension();
      estRowSize_ = std::min(cols_, colBasis.localView().maxSize() * surrounding);
61
      symmetry_ = symmetry;
Praetorius, Simon's avatar
Praetorius, Simon committed
62
63
64
    }

  private:
65
66
67
    std::size_t rows_ = 0;
    std::size_t cols_ = 0;
    std::size_t estRowSize_ = 50;
68
    SymmetryStructure symmetry_ = SymmetryStructure::unknown;
Praetorius, Simon's avatar
Praetorius, Simon committed
69
70
71
  };

} // end namespace AMDiS