Assembler.hpp 3.1 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
18
19
  const Flag EQUAL_BASES      = 0x01L;
  const Flag EQUAL_LOCALBASES = 0x02L;

20
  template <class GlobalBasis>
21
22
  class Assembler
  {
23
    /// The grid view the global FE basis lives on
24
    using GridView = typename GlobalBasis::GridView;
25
26

  public:
27

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

39
40
41
42
43
    void update(GridView const& gv)
    {
      globalBasis_.update(gv);
    }

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

52

53
  private:
54

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


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


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

82

83
84
85
86
87
88
    /// 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();
    }
89
90

    /// Return whether the matrix-block needs to be assembled
91
92
    template <class LocalView0, class... LovalViews>
    auto const& getGridView(LocalView0 const& localView, LovalViews const&...) const
93
    {
94
      return globalBasis_.gridView();
95
    }
96

97

98
  private:
99

100
101
102
    GlobalBasis& globalBasis_;
    MatrixOperators<GlobalBasis>& matrixOperators_;
    VectorOperators<GlobalBasis>& rhsOperators_;
103
    Constraints<GlobalBasis>& constraints_;
104
105

    //TODO: add caching of localBases
106
107
108
  };

} // end namespace AMDiS
109
110

#include "Assembler.inc.hpp"