BiLinearForm.inc.hpp 2.73 KB
Newer Older
1
2
3
4
#pragma once

#include <utility>

5
6
#include <amdis/ContextGeometry.hpp>
#include <amdis/GridFunctionOperator.hpp>
7
8
9
10
11
#include <amdis/LocalOperator.hpp>
#include <amdis/typetree/Traversal.hpp>

namespace AMDiS {

Praetorius, Simon's avatar
Praetorius, Simon committed
12
template <class RB, class CB, class T, class Traits>
13
  template <class ContextTag, class Expr, class RowTreePath, class ColTreePath>
Praetorius, Simon's avatar
Praetorius, Simon committed
14
void BiLinearForm<RB,CB,T,Traits>::
15
16
17
18
19
20
21
22
addOperator(ContextTag contextTag, Expr const& expr,
            RowTreePath row, ColTreePath col)
{
  static_assert( Concepts::PreTreePath<RowTreePath>,
      "row must be a valid treepath, or an integer/index-constant");
  static_assert( Concepts::PreTreePath<ColTreePath>,
      "col must be a valid treepath, or an integer/index-constant");

23
24
  auto i = makeTreePath(row);
  auto j = makeTreePath(col);
25
26

  using LocalContext = typename ContextTag::type;
27
28
  auto op = makeOperator<LocalContext>(expr, this->rowBasis().gridView());
  operators_[i][j].push(contextTag, std::move(op));
29
  updatePattern_ = true;
30
31
32
}


Praetorius, Simon's avatar
Praetorius, Simon committed
33
template <class RB, class CB, class T, class Traits>
34
  template <class RowLocalView, class ColLocalView, class LocalOperators,
35
36
    REQUIRES_(Concepts::LocalView<RowLocalView>),
    REQUIRES_(Concepts::LocalView<ColLocalView>)>
Praetorius, Simon's avatar
Praetorius, Simon committed
37
void BiLinearForm<RB,CB,T,Traits>::
38
39
assemble(RowLocalView const& rowLocalView, ColLocalView const& colLocalView,
         LocalOperators& localOperators)
40
41
42
43
{
  elementMatrix_.resize(rowLocalView.size(), colLocalView.size());
  elementMatrix_ = 0;

44
  auto const& gv = this->rowBasis().gridView();
Praetorius, Simon's avatar
Praetorius, Simon committed
45
  GlobalContext<TYPEOF(gv)> context{gv, rowLocalView.element(), rowLocalView.element().geometry()};
46

47
48
  Traversal::forEachNode(rowLocalView.treeCache(), [&](auto const& rowNode, auto rowTp) {
    Traversal::forEachNode(colLocalView.treeCache(), [&](auto const& colNode, auto colTp) {
49
50
51
52
      auto& matOp = localOperators[rowTp][colTp];
      matOp.bind(context.element());
      matOp.assemble(context, rowNode, colNode, elementMatrix_);
      matOp.unbind();
53
54
55
56
57
58
59
    });
  });

  this->scatter(rowLocalView, colLocalView, elementMatrix_);
}


Praetorius, Simon's avatar
Praetorius, Simon committed
60
61
template <class RB, class CB, class T, class Traits>
void BiLinearForm<RB,CB,T,Traits>::
62
assemble()
63
{
64
65
  auto rowLocalView = this->rowBasis().localView();
  auto colLocalView = this->colBasis().localView();
66

67
  this->init();
68
  auto localOperators = AMDiS::localOperators(operators_);
69
  for (auto const& element : elements(this->rowBasis().gridView(), typename Traits::PartitionSet{})) {
70
    rowLocalView.bind(element);
Praetorius, Simon's avatar
Praetorius, Simon committed
71
    if (this->rowBasis_ == this->colBasis_)
72
      this->assemble(rowLocalView, rowLocalView, localOperators);
73
74
    else {
      colLocalView.bind(element);
75
      this->assemble(rowLocalView, colLocalView, localOperators);
76
77
      colLocalView.unbind();
    }
78
    rowLocalView.unbind();
79
80
81
82
83
84
  }
  this->finish();
}


} // end namespace AMDiS