Assembler.hpp 2.93 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
#include <dune/amdis/DirichletBC.hpp>
10
#include <dune/amdis/LinearAlgebra.hpp>
11
#include <dune/amdis/Operator.hpp>
12
#include <dune/amdis/common/Mpl.hpp>
13
#include <dune/amdis/common/TypeDefs.hpp>
14
15
16

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

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

35
36
37
38
39
    void update(GridView const& gv)
    {
      globalBasis_.update(gv);
    }

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

  private:
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
59
60
61
    template <class ElementContainer, class Container, class Operators, class... Bases>
    void assembleElementOperators(
        ElementContainer& elementContainer,
        Container& container,
62
        Operators& operators,
63
        Bases const&... subBases) const;
64
65
66
67


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

75

76
77
78
79
80
81
    /// 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();
    }
82
83

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

  private:
91
92
93
    GlobalBasis& globalBasis_;
    MatrixOperators<GlobalBasis>& matrixOperators_;
    VectorOperators<GlobalBasis>& rhsOperators_;
94
    Constraints<GlobalBasis>& constraints_;
95
96
97
  };

} // end namespace AMDiS
98
99

#include "Assembler.inc.hpp"