DOFVectorTest.cpp 2.22 KB
Newer Older
1
2
#include "config.h"

Praetorius, Simon's avatar
Praetorius, Simon committed
3
4
#include <dune/common/filledarray.hh>
#include <dune/grid/yaspgrid.hh>
5
#include <dune/functions/backends/concepts.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
6
7
8
9
#include <dune/functions/functionspacebases/compositebasis.hh>
#include <dune/functions/functionspacebases/powerbasis.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>

10
#include <amdis/AMDiS.hpp>
11
#include <amdis/GridTransferManager.hpp>
Praetorius, Simon's avatar
Praetorius, Simon committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <amdis/LinearAlgebra.hpp>

#include "Tests.hpp"

using namespace AMDiS;
using namespace Dune::Functions::BasisFactory;

template <class B, class T>
void test_dofvector(B const& basis, DOFVector<B,T>& vec)
{
  AMDIS_TEST( vec.size() == basis.dimension() );
  vec.compress();

  vec = T(0);
  vec[0] = T(1);
27
#if HAVE_MTL || HAVE_ISTL
Praetorius, Simon's avatar
Praetorius, Simon committed
28
29
30
31
  auto m0 = std::min_element(std::begin(vec.vector()), std::end(vec.vector()));
  auto m1 = std::max_element(std::begin(vec.vector()), std::end(vec.vector()));
  AMDIS_TEST( *m0 == T(0) );
  AMDIS_TEST( *m1 == T(1) );
32
#endif
33
34
35

  // DOFVector models the concept of a VectorBackend in Dune::Functions
  static_assert(Dune::models<Dune::Functions::Concept::VectorBackend<B>, decltype(vec)>(), "");
Praetorius, Simon's avatar
Praetorius, Simon committed
36
37
}

38
int main(int argc, char** argv)
Praetorius, Simon's avatar
Praetorius, Simon committed
39
{
40
  Environment env(argc, argv);
41

Praetorius, Simon's avatar
Praetorius, Simon committed
42
43
44
45
  // create grid
  Dune::FieldVector<double, 2> L; L = 1.0;
  auto s = Dune::filledArray<2>(1);
  Dune::YaspGrid<2> grid(L, s);
46
  auto const& gridView = grid.leafGridView();
Praetorius, Simon's avatar
Praetorius, Simon committed
47
48

  // create basis
49
  auto basis = makeBasis(gridView,
Praetorius, Simon's avatar
Praetorius, Simon committed
50
51
52
    composite(power<2>(lagrange<2>(), flatInterleaved()), lagrange<1>(), flatLexicographic()));
  using Basis = decltype(basis);

53
54
55
56
  {
    DOFVector<Basis> vec1(basis);
    test_dofvector(basis, vec1);

57
    DOFVector<Basis, double> vec2(basis);
58
    test_dofvector(basis, vec2);
Praetorius, Simon's avatar
Praetorius, Simon committed
59

60
61
    auto vec3 = makeDOFVector(basis);
    test_dofvector(basis, vec3);
Praetorius, Simon's avatar
Praetorius, Simon committed
62

63
    auto vec4 = makeDOFVector<double>(basis);
64
    test_dofvector(basis, vec4);
Praetorius, Simon's avatar
Praetorius, Simon committed
65
66

#if DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
67
68
    DOFVector vec5(basis);
    test_dofvector(basis, vec5);
Praetorius, Simon's avatar
Praetorius, Simon committed
69
#endif
70
71
72
73
74
75
76
77
  }

  // test GridTransferManager registration
  {
    DOFVector<Basis> vec1(basis);
    test_dofvector(basis, vec1);
    for (auto const& e : elements(gridView))
      grid.mark(1, e);
78
    GridTransferManager::adapt(grid);
79
80
81
82
83
    AMDIS_TEST_EQ(vec1.size(), basis.dimension());
  }

  report_errors();
}