Assembler.hpp 2.99 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
#include <amdis/DirichletBC.hpp>
#include <amdis/LinearAlgebra.hpp>
11
#include <amdis/LocalAssemblerList.hpp>
12
13
#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
    /// Assemble operators on an element, by passing the element/intersection to
    /// `elementAssembler` functor.
59
    template <class Element, class Operators, class ElementAssembler>
60
    void assembleElementOperators(
61
        Element const& element,
62
        Operators& operators,
63
        ElementAssembler const& elementAssembler) const;
64
65
66

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

74

75
    /// Return the element the LocalViews are bound to
76
77
78
79
80
    template <class LocalView0, class... LovalViews>
    auto const& getElement(LocalView0 const& localView, LovalViews const&...) const
    {
      return localView.element();
    }
81

82
    /// Return the gridView the localViews are bound to
83
84
    template <class LocalView0, class... LovalViews>
    auto const& getGridView(LocalView0 const& localView, LovalViews const&...) const
85
    {
86
      return globalBasis_.gridView();
87
    }
88

89

90
  private:
91

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

    //TODO: add caching of localBases
98
99
100
  };

} // end namespace AMDiS
101
102

#include "Assembler.inc.hpp"