LinearForm.inc.hpp 2.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once

#include <utility>

#include <amdis/Assembler.hpp>
#include <amdis/LocalOperator.hpp>
#include <amdis/operations/Assigner.hpp>
#include <amdis/typetree/Traversal.hpp>
#include <amdis/utility/AssembleOperators.hpp>

namespace AMDiS {

Praetorius, Simon's avatar
Praetorius, Simon committed
13
template <class GB, class T, class Traits>
14
  template <class ContextTag, class Expr, class TreePath>
Praetorius, Simon's avatar
Praetorius, Simon committed
15
void LinearForm<GB,T,Traits>::
16
17
18
19
20
addOperator(ContextTag contextTag, Expr const& expr, TreePath path)
{
  static_assert( Concepts::PreTreePath<TreePath>,
      "path must be a valid treepath, or an integer/index-constant");

21
22
  auto i = makeTreePath(path);
  auto node = child(this->basis()->localView().tree(), i);
23
24

  using LocalContext = typename ContextTag::type;
Praetorius, Simon's avatar
Praetorius, Simon committed
25
  using Tr = DefaultAssemblerTraits<LocalContext, ElementVector>;
26
  auto op = makeLocalOperator<LocalContext>(expr, this->basis()->gridView());
27
  auto localAssembler = makeUniquePtr(makeAssembler<Tr>(std::move(op), node));
28
29
30
31
32

  operators_[i].push(contextTag, std::move(localAssembler));
}


Praetorius, Simon's avatar
Praetorius, Simon committed
33
template <class GB, class T, class Traits>
34
  template <class LocalView, REQUIRES_(Concepts::LocalView<LocalView>)>
Praetorius, Simon's avatar
Praetorius, Simon committed
35
void LinearForm<GB,T,Traits>::
36
assemble(LocalView const& localView)
37
38
39
40
41
42
43
44
{
  elementVector_.resize(localView.size());
  elementVector_ = 0;

  auto const& gv = this->basis()->gridView();
  auto const& element = localView.element();
  auto geometry = element.geometry();

45
46
  for_each_node(localView.tree(), [&](auto const& node, auto tp) {
    auto& rhsOp = operators_[tp];
47
48
49
50
51
52
53
54
55
56
57
    if (rhsOp) {
      rhsOp.bind(element, geometry);
      assembleOperators(gv, element, rhsOp, makeVectorAssembler(node, elementVector_));
      rhsOp.unbind();
    }
  });

  this->scatter(localView, elementVector_, Assigner::plus_assign{});
}


Praetorius, Simon's avatar
Praetorius, Simon committed
58
59
template <class GB, class T, class Traits>
void LinearForm<GB,T,Traits>::
60
61
62
63
assemble()
{
  auto localView = this->basis()->localView();

64
  this->init(sizeInfo(*this->basis()), true);
65
66
67
68
69
70
71
72
73
  for (auto const& element : elements(this->basis()->gridView(), typename Traits::PartitionSet{})) {
    localView.bind(element);
    this->assemble(localView);
    localView.unbind();
  }
  this->finish();
}

} // end namespace AMDiS