DirichletBC.hpp 4.41 KB
Newer Older
1
2
3
#pragma once

#include <functional>
4
#include <list>
5
6
7
#include <type_traits>
#include <vector>

8
9
10
11
12
#include <amdis/Output.hpp>
#include <amdis/common/Concepts.hpp>
#include <amdis/common/ValueCategory.hpp>
#include <amdis/utility/RangeType.hpp>
#include <amdis/utility/TreeData.hpp>
13

14
15
namespace AMDiS
{
16
17
  /// Implements a boundary condition of Dirichlet-type.
  /**
18
   * By calling the methods \ref init() and \ref finish before and after
19
   * assembling the system-matrix, respectively, dirichlet boundary conditions
20
   * can be applied to the matrix and system vector. Therefore, a predicate
21
   * functions indicates the DOFs where values should be enforced and a second
22
   * functor provided in the constructor is responsible for determining the
23
   * values to be set at the DOFs.
24
25
26
27
   *
   * In the \ref finish method the matrix is called with \ref applyDirichletBC
   * to erase the corresponding rows and columns for the DOF indices. This
   * application of boundary conditions can be symmetric if the matrix does
28
29
30
   * support this symmetric modification. As a result, this method returns a list
   * of columns values, that should be subtracted from the rhs.
   **/
31
  template <class Domain, class Range = double>
32
33
34
35
  class DirichletBC
  {
  public:
    template <class Predicate, class Values,
36
37
      REQUIRES(Concepts::Functor<Predicate, bool(Domain)> &&
				       Concepts::Functor<Values,  Range(Domain)>) >
38
    DirichletBC(Predicate&& predicate, Values&& values)
39
40
      : predicate_(std::forward<Predicate>(predicate))
      , values_(std::forward<Values>(values))
41
    {}
42
43


44
45
46
    /// Prepare the matrix, rhs and solution block for assembling dirichlet
    /// boundary conditions, e.g. collect the corresponding indices of boundary
    /// DOFS for later elimination in \ref finish.
47
48
49
50
51
52
53
54
55
    template <class Matrix, class VectorX, class VectorB, class RowBasis, class ColBasis>
    void init(Matrix& /*matrix*/, VectorX& /*rhs*/, VectorB& /*solution*/,
              RowBasis const& rowBasis,
              ColBasis const& /*colBasis*/)
    {
      using RowNode = typename RowBasis::LocalView::Tree;
      initImpl(rowBasis, typename RowNode::NodeTag{});
    }

56
57


58
59
60
61
62
63
64
    /// \brief Apply dirichlet BC to matrix and vector, i.e., add a unit-row
    /// to the matrix and optionally delete the corresponding matrix-column.
    /** If DBC is set for matrix block {R,C}, then \p apply_row means that
      * the block-row R is assembled, and \p apply_col means that the block-col C
      * is assembled. The \p matrix, \p rhs, and \p solution correspond to the
      * currently visited blocks of system-matrix and system-vector.
      **/
65
66
    template <class Matrix, class VectorX, class VectorB, class RowBasis, class ColBasis>
    void finish(Matrix& matrix,
67
                VectorX& rhs,
68
69
                VectorB& solution,
                RowBasis const& rowBasis,
70
71
72
73
                ColBasis const& colBasis)
    {
      finishImpl(matrix, rhs, solution, rowBasis, colBasis, ValueCategory_t<Range>{});
    }
74
75
76
77
78
79
80
81
82
83

  protected:
    template <class RowBasis>
    void initImpl(RowBasis const& rowBasis, Dune::TypeTree::LeafNodeTag);

    template <class RowBasis>
    void initImpl(RowBasis const& rowBasis, Dune::TypeTree::PowerNodeTag);

    template <class RB, class RowNodeTag>
    void initImpl(RB const&, RowNodeTag) {}
84

85
86
87
88
89
90
91
92
93
94
    template <class Matrix, class VectorX, class VectorB, class RowBasis, class ColBasis, class ValueCat>
    void finishImpl(Matrix& matrix, VectorX& rhs, VectorB& solution,
                    RowBasis const& rowBasis, ColBasis const& colBasis,
                    ValueCat);

    template <class Matrix, class VectorX, class VectorB, class RowBasis, class ColBasis>
    void finishImpl(Matrix& matrix, VectorX& rhs, VectorB& solution,
                    RowBasis const& rowBasis, ColBasis const& colBasis,
                    tag::unknown) {}

95
  private:
96
97
    std::function<bool(Domain)> predicate_;
    std::function<Range(Domain)> values_;
98

99
100
    bool initialized_ = false;
    std::vector<char> dirichletNodes_;
101
102
  };

103
104
105
106
107
108

  template <class GlobalBasis>
  struct DirichletData
  {
    using WorldVector = typename GlobalBasis::GridView::template Codim<0>::Geometry::GlobalCoordinate;

109
    template <class RowNode, class ColNode>
110
    using type = std::list< std::shared_ptr<DirichletBC<WorldVector, RangeType_t<RowNode>>> >;
111
112
113
114
115
  };

  template <class GlobalBasis>
  using Constraints = MatrixData<GlobalBasis, DirichletData<GlobalBasis>::template type>;

116
117
118
} // end namespace AMDiS

#include "DirichletBC.inc.hpp"