Assembler.hpp 3.41 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
39
40
41
42
    void update(GridView const& gv)
    {
      globalBasis_.update(gv);
    }

43
    /// Assemble the linear system
44
    template <class SystemMatrixType, class SystemVectorType>
45
46
47
48
    void assemble(
        SystemMatrixType& matrix,
        SystemVectorType& solution,
        SystemVectorType& rhs,
49
        bool asmMatrix, bool asmVector);
50

51

52
  private:
53

54
    /// Sets the system to zero and initializes all operators and boundary conditions
55
    template <class SystemMatrixType, class SystemVectorType>
56
57
58
59
    void initMatrixVector(
        SystemMatrixType& matrix,
        SystemVectorType& solution,
        SystemVectorType& rhs,
60
        bool asmMatrix, bool asmVector) const;
61
62


63
    template <class ElementContainer, class Container, class Operators, class Geometry, class Basis>
64
65
66
    void assembleElementOperators(
        ElementContainer& elementContainer,
        Container& container,
67
        Operators& operators,
68
        Geometry const& geometry,
69
        Basis const& subBasis) const;
70

71
72
73
74
75
76
77
78
    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;
79
80
81

    /// Finish insertion into the matrix and assembles boundary conditions
    /// Return the number of nonzeros assembled into the matrix
82
    template <class SystemMatrixType, class SystemVectorType>
83
84
85
86
    std::size_t finishMatrixVector(
        SystemMatrixType& matrix,
        SystemVectorType& solution,
        SystemVectorType& rhs,
87
88
        bool asmMatrix, bool asmVector) const;

89

90
91
92
93
94
95
    /// 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();
    }
96
97

    /// Return whether the matrix-block needs to be assembled
98
99
    template <class LocalView0, class... LovalViews>
    auto const& getGridView(LocalView0 const& localView, LovalViews const&...) const
100
    {
101
      return globalBasis_.gridView();
102
    }
103

104

105
  private:
106

107
108
109
    GlobalBasis& globalBasis_;
    MatrixOperators<GlobalBasis>& matrixOperators_;
    VectorOperators<GlobalBasis>& rhsOperators_;
110
    Constraints<GlobalBasis>& constraints_;
111
112

    //TODO: add caching of localBases
113
114
115
  };

} // end namespace AMDiS
116
117

#include "Assembler.inc.hpp"