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

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

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

#include <dune/amdis/LinearAlgebra.hpp>
10
#include <dune/amdis/Operator.hpp>
11
#include <dune/amdis/common/Mpl.hpp>
12
#include <dune/amdis/common/TypeDefs.hpp>
13
14
15

namespace AMDiS
{
16
  template <class GlobalBasis>
17
18
  class Assembler
  {
19
    /// The grid view the global FE basis lives on
20
    using GridView = typename GlobalBasis::GridView;
21
22

  public:
23
    /// Constructor, stores a shared-pointer to the feSpaces
24
25
26
    Assembler(GlobalBasis& globalBasis,
              MatrixOperators<GlobalBasis>& matrixOperators,
              VectorOperators<GlobalBasis>& rhsOperators)
27
      : globalBasis_(globalBasis)
28
29
      , matrixOperators_(matrixOperators)
      , rhsOperators_(rhsOperators)
30
    {}
31

32
33
34
35
36
    void update(GridView const& gv)
    {
      globalBasis_.update(gv);
    }

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

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


55
56
57
58
    template <class ElementContainer, class Container, class Operators, class... Bases>
    void assembleElementOperators(
        ElementContainer& elementContainer,
        Container& container,
59
        Operators& operators,
60
        Bases const&... subBases) const;
61
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

  private:
88
89
90
    GlobalBasis& globalBasis_;
    MatrixOperators<GlobalBasis>& matrixOperators_;
    VectorOperators<GlobalBasis>& rhsOperators_;
91
92
93
  };

} // end namespace AMDiS
94
95

#include "Assembler.inc.hpp"