Assembler.hpp 2.89 KB
Newer Older
1
2
3
#pragma once

#include <memory>
4
#include <tuple>
5

6
7
8
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>

9
10
11
12
13
#include <amdis/DirichletBC.hpp>
#include <amdis/LinearAlgebra.hpp>
#include <amdis/LocalAssemblerBase.hpp>
#include <amdis/common/Mpl.hpp>
#include <amdis/common/TypeDefs.hpp>
14
15
16

namespace AMDiS
{
17
  template <class Traits>
18
19
  class Assembler
  {
20
21
    using GlobalBasis = typename Traits::GlobalBasis;

22
    /// The grid view the global FE basis lives on
23
    using GridView = typename GlobalBasis::GridView;
24
25

  public:
26

27
    /// Constructor, stores a shared-pointer to the feSpaces
28
29
    Assembler(GlobalBasis& globalBasis,
              MatrixOperators<GlobalBasis>& matrixOperators,
30
31
              VectorOperators<GlobalBasis>& rhsOperators,
              Constraints<GlobalBasis>& constraints)
32
      : globalBasis_(globalBasis)
33
34
      , matrixOperators_(matrixOperators)
      , rhsOperators_(rhsOperators)
35
      , constraints_(constraints)
36
    {}
37

38
    /// Assemble the linear system
39
    template <class SystemMatrixType, class SystemVectorType>
40
41
42
43
    void assemble(
        SystemMatrixType& matrix,
        SystemVectorType& solution,
        SystemVectorType& rhs,
44
        bool asmMatrix, bool asmVector);
45

46

47
  private:
48

49
    /// Sets the system to zero and initializes all operators and boundary conditions
50
    template <class SystemMatrixType, class SystemVectorType>
51
52
53
54
    void initMatrixVector(
        SystemMatrixType& matrix,
        SystemVectorType& solution,
        SystemVectorType& rhs,
55
        bool asmMatrix, bool asmVector) const;
56

57
    template <class Element, class Operators, class ElementAssembler>
58
    void assembleElementOperators(
59
        Element const& element,
60
        Operators& operators,
61
        ElementAssembler const& elementAssembler) const;
62
63
64

    /// Finish insertion into the matrix and assembles boundary conditions
    /// Return the number of nonzeros assembled into the matrix
65
    template <class SystemMatrixType, class SystemVectorType>
66
67
68
69
    std::size_t finishMatrixVector(
        SystemMatrixType& matrix,
        SystemVectorType& solution,
        SystemVectorType& rhs,
70
71
        bool asmMatrix, bool asmVector) const;

72

73
74
75
76
77
78
    /// Return whether the matrix-block needs to be assembled
    template <class LocalView0, class... LovalViews>
    auto const& getElement(LocalView0 const& localView, LovalViews const&...) const
    {
      return localView.element();
    }
79
80

    /// Return whether the matrix-block needs to be assembled
81
82
    template <class LocalView0, class... LovalViews>
    auto const& getGridView(LocalView0 const& localView, LovalViews const&...) const
83
    {
84
      return globalBasis_.gridView();
85
    }
86

87

88
  private:
89

90
91
92
    GlobalBasis& globalBasis_;
    MatrixOperators<GlobalBasis>& matrixOperators_;
    VectorOperators<GlobalBasis>& rhsOperators_;
93
    Constraints<GlobalBasis>& constraints_;
94
95

    //TODO: add caching of localBases
96
97
98
  };

} // end namespace AMDiS
99
100

#include "Assembler.inc.hpp"