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

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

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

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

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

21
22
    using SystemMatrixType = SystemMatrix<GlobalBasis>;
    using SystemVectorType = SystemVector<GlobalBasis>;
23

24
25
    using TypeTree = typename GlobalBasis::LocalView::Tree;
    using
26

27
  public:
28
    /// Constructor, stores a shared-pointer to the feSpaces
29
30
    Assembler(std::shared_ptr<GlobalBasis> const& globalBasis, bool asmMatrix, bool asmVector)
      : globalBasis_(globalBasis)
31
32
33
      , asmMatrix_(asmMatrix)
      , asmVector_(asmVector)
    {}
34

35
    /// Assemble the linear system
36
    template <class MatrixOperators, class VectorOperators>
37
    void assemble(
38
        GridView const& gv,
39
40
41
        SystemMatrixType& matrix,
        SystemVectorType& solution,
        SystemVectorType& rhs,
42
43
        MatrixOperators& matrixOperators,
        VectorOperators& rhsOperators);
44
45

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


56
57
58
59
60
61
    template <class MatrixOperators, class VectorOperators>
    void assembleElement(
        SystemMatrixType& matrix,
        SystemVectorType& rhs,
        MatrixOperators& matrixOperators,
        VectorOperators& rhsOperators) const;
62
63


64
65
66
67
    template <class ElementContainer, class Container, class Operators, class... Bases>
    void assembleElementOperators(
        ElementContainer& elementContainer,
        Container& container,
68
        Operators& operators,
69
        Bases const&... subBases) const;
70
71
72
73


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


    /// Return whether the matrix-block needs to be assembled
84
85
    template <class Basis0, class... Bases>
    auto getElement(Basis0 const& basis0, Bases const&... bases) const
86
    {
87
      return basis0.localView().element();
88
    }
89
90

  private:
91
    std::shared_ptr<GlobalBasis> globalBasis_;
92
93
    bool asmMatrix_;
    bool asmVector_;
94
95
96
  };

} // end namespace AMDiS
97
98

#include "Assembler.inc.hpp"