SlotSize.hpp 1.6 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
#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>

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,
31
    /// otherwise take `1.2 * nnz/rows`
Praetorius, Simon's avatar
Praetorius, Simon committed
32
33
34
35
36
37
38
    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_;
    }

39
40
    // 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
41
42
43
    // number of simplices surrounding a vertex in a kuhn triangulation
    template <class RowBasis, class ColBasis>
    void init(RowBasis const& rowBasis, ColBasis const& colBasis)
44
    {
45
46
47
48
49
50
51
      using GridView = typename RowBasis::GridView;
      static std::size_t surrounding
        = Math::pow<GridView::dimension>(2) * Dune::factorial(int(GridView::dimension));

      rows_ = rowBasis.dimension();
      cols_ = colBasis.dimension();
      estRowSize_ = std::min(cols_, colBasis.localView().maxSize() * surrounding);
Praetorius, Simon's avatar
Praetorius, Simon committed
52
53
54
    }

  private:
55
56
57
    std::size_t rows_ = 0;
    std::size_t cols_ = 0;
    std::size_t estRowSize_ = 50;
Praetorius, Simon's avatar
Praetorius, Simon committed
58
59
60
  };

} // end namespace AMDiS