TreeContainerTest.cpp 1.59 KB
Newer Older
1
#include "config.h"
2 3 4 5 6 7
#include <dune/grid/yaspgrid.hh>

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

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

#include "Tests.hpp"

using namespace AMDiS;

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

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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
  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();

  auto c1 = makeTreeContainer<double>(tree);
  auto c2 = makeTreeContainer<decltype(c1)>(tree);
  auto c3 = makeTreeContainer(tree, [&](auto const&) { return makeTreeContainer<double>(tree); });

  // 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();
}