TreeContainerTest.cpp 1.61 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
#include <config.h>

3
4
5
6
7
8
#include <dune/grid/yaspgrid.hh>

#include <dune/functions/functionspacebases/compositebasis.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
#include <dune/functions/functionspacebases/powerbasis.hh>

9
#include <amdis/Environment.hpp>
10
11
12
13
14
15
16
#include <amdis/typetree/Traversal.hpp>
#include <amdis/typetree/TreeContainer.hpp>

#include "Tests.hpp"

using namespace AMDiS;

17
int main (int argc, char** argv)
18
{
19
20
  Environment env(argc, argv);

21
22
23
24
25
26
27
28
29
30
31
32
33
  Dune::YaspGrid<2> grid({1.0,1.0}, {1,1});
  auto gridView = grid.leafGridView();

  using namespace Dune::Functions::BasisFactory;
  auto basis = makeBasis(gridView,
    composite(
      power<2>(lagrange<2>()),
      lagrange<1>()
    ));

  auto localView = basis.localView();
  auto const& tree = localView.tree();

34
35
36
  auto c1 = TypeTree::treeContainer<double>(tree);
  auto c2 = TypeTree::treeContainer<decltype(c1)>(tree);
  auto c3 = TypeTree::treeContainer(tree, [&](auto const&) { return TypeTree::treeContainer<double>(tree); });
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

  // fill 1d treeContainer with data
  for_each_leaf_node(tree, [&](auto const& node, auto tp) {
    c1[tp] = double(node.treeIndex());
  });

  // copy construction
  auto c4 = c1;
  AMDIS_TEST(c4 == c1);

  // fill 2d treeContainer with data
  for_each_leaf_node(tree, [&](auto const& row_node, auto row_tp) {
    for_each_leaf_node(tree, [&](auto const& col_node, auto col_tp) {
      c3[row_tp][col_tp] = double(row_node.treeIndex() + col_node.treeIndex());
    });
  });

  // copy construction
  auto c5 = c3;
  AMDIS_TEST(c5 == c3);

  // copy-assignment of container
  c2 = c3;
  AMDIS_TEST(c2 == c3);

  return report_errors();
}