Assembler.hpp 3.33 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


58
    template <class ElementContainer, class Container, class Operators, class Geometry, class Basis>
59
60
61
    void assembleElementOperators(
        ElementContainer& elementContainer,
        Container& container,
62
        Operators& operators,
63
        Geometry const& geometry,
64
        Basis const& subBasis) const;
65

66
67
68
69
70
71
72
73
    template <class ElementContainer, class Container, class Operators, class Geometry, class RowBasis, class ColBasis>
    void assembleElementOperators(
        ElementContainer& elementContainer,
        Container& container,
        Operators& operators,
        Geometry const& geometry,
        RowBasis const& rowBasis,
        ColBasis const& colBasis) const;
74
75
76

    /// Finish insertion into the matrix and assembles boundary conditions
    /// Return the number of nonzeros assembled into the matrix
77
    template <class SystemMatrixType, class SystemVectorType>
78
79
80
81
    std::size_t finishMatrixVector(
        SystemMatrixType& matrix,
        SystemVectorType& solution,
        SystemVectorType& rhs,
82
83
        bool asmMatrix, bool asmVector) const;

84

85
86
87
88
89
90
    /// 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();
    }
91
92

    /// Return whether the matrix-block needs to be assembled
93
94
    template <class LocalView0, class... LovalViews>
    auto const& getGridView(LocalView0 const& localView, LovalViews const&...) const
95
    {
96
      return globalBasis_.gridView();
97
    }
98

99

100
  private:
101

102
103
104
    GlobalBasis& globalBasis_;
    MatrixOperators<GlobalBasis>& matrixOperators_;
    VectorOperators<GlobalBasis>& rhsOperators_;
105
    Constraints<GlobalBasis>& constraints_;
106
107

    //TODO: add caching of localBases
108
109
110
  };

} // end namespace AMDiS
111
112

#include "Assembler.inc.hpp"