DOFVectorBase.inc.hpp 2.34 KB
Newer Older
1
2
3
4
#pragma once

#include <amdis/Assembler.hpp>
#include <amdis/LocalOperator.hpp>
5
6
#include <amdis/typetree/Visitor.hpp>
#include <amdis/utility/AssembleOperators.hpp>
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

namespace AMDiS {

template <class BS, class B>
void DOFVectorBase<BS,B>::
init(bool asmVector)
{
  backend_.resize(size());
  if (asmVector)
    backend_.set(0);

  auto const localSize = basis_->localView().maxSize();
  elementVector_.resize(localSize);
}


template <class BS, class B>
void DOFVectorBase<BS,B>::
25
26
finish(bool /*asmVector*/)
{}
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


template <class BS, class B>
void DOFVectorBase<BS,B>::
insert(LocalView const& localView, ElementVector const& elementVector)
{
  for (size_type i = 0; i < localView.size(); ++i) {
    if (std::abs(elementVector[i]) > threshold<double>) {
      size_type const idx = flatMultiIndex(localView.index(i));
      backend_[idx] += elementVector[i];
    }
  }
}


template <class BS, class B>
43
  template <class ContextTag, class PreOperator, class TreePath>
44
void DOFVectorBase<BS,B>::
45
addOperator(ContextTag contextTag, PreOperator const& preOp, TreePath path)
46
47
48
49
50
51
52
53
{
  static_assert( Concepts::PreTreePath<TreePath>,
      "path must be a valid treepath, or an integer/index-constant");

  auto i = child(basis_->localView().tree(), makeTreePath(path));

  using Context = typename ContextTag::type;
  auto op = makeLocalOperator<Context>(preOp, basis_->gridView());
54
  auto localAssembler = makeUniquePtr(makeAssembler<Context>(std::move(op), i));
55

56
  operators_[i].push(contextTag, std::move(localAssembler));
57
58
59
60
61
62
63
64
65
66
67
68
69
70
}


template <class BS, class B>
void DOFVectorBase<BS,B>::
assemble(LocalView const& localView)
{
  elementVector_ = 0;
  auto const& gv = basis_->gridView();
  auto const& element = localView.element();
  auto geometry = element.geometry();

  forEachNode_(localView.tree(), [&](auto const& node, auto) {
    auto& rhsOp = operators_[node];
Praetorius, Simon's avatar
Praetorius, Simon committed
71
    if (rhsOp) {
72
      rhsOp.bind(element, geometry);
73
      assembleOperators(gv, element, rhsOp, makeVectorAssembler(node, elementVector_));
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
      rhsOp.unbind();
    }
  });

  insert(localView, elementVector_);
}


template <class BS, class B>
void DOFVectorBase<BS,B>::
assemble()
{
  auto localView = basis_->localView();

  init(true);
  for (auto const& element : elements(basis_->gridView())) {
    localView.bind(element);
    assemble(localView);
    localView.unbind(element);
  }
  finish(true);
}

} // end namespace AMDiS