Assembler.hpp 2.48 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
#include <amdis/common/Mpl.hpp>
13
14
15

namespace AMDiS
{
16
  template <class Traits>
17
18
  class Assembler
  {
19
20
    using GlobalBasis = typename Traits::GlobalBasis;

21
    /// The grid view the global FE basis lives on
22
    using GridView = typename GlobalBasis::GridView;
23
24

  public:
25

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

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

46
  private:
47

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

56
57
    /// Assemble operators on an element, by passing the element/intersection to
    /// `elementAssembler` functor.
58
    template <class Element, class Operators, class ElementAssembler>
59
    void assembleElementOperators(
60
        Element const& element,
61
        Operators& operators,
62
        ElementAssembler const& elementAssembler) const;
63
64
65

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

73

74
  private:
75

76
77
78
    GlobalBasis& globalBasis_;
    MatrixOperators<GlobalBasis>& matrixOperators_;
    VectorOperators<GlobalBasis>& rhsOperators_;
79
    Constraints<GlobalBasis>& constraints_;
80
81

    //TODO: add caching of localBases
82
83
84
  };

} // end namespace AMDiS
85
86

#include "Assembler.inc.hpp"