DOFVectorTest.cpp 1.81 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
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <dune/functions/functionspacebases/compositebasis.hh>
#include <dune/functions/functionspacebases/powerbasis.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>

#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);
25
#if HAVE_MTL || HAVE_ISTL
Praetorius, Simon's avatar
Praetorius, Simon committed
26
27
28
29
  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) );
30
#endif
31
32
33

  // 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
34
35
}

36
int main(int argc, char** argv)
Praetorius, Simon's avatar
Praetorius, Simon committed
37
{
38
39
  Dune::MPIHelper::instance(argc, argv);

Praetorius, Simon's avatar
Praetorius, Simon committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  // create grid
  Dune::FieldVector<double, 2> L; L = 1.0;
  auto s = Dune::filledArray<2>(1);
  Dune::YaspGrid<2> grid(L, s);

  // create basis
  auto basis = makeBasis(grid.leafGridView(),
    composite(power<2>(lagrange<2>(), flatInterleaved()), lagrange<1>(), flatLexicographic()));

  using Basis = decltype(basis);
  DOFVector<Basis> vec1(basis);
  test_dofvector(basis, vec1);

  DOFVector<Basis, float> vec2(basis);
  test_dofvector(basis, vec2);

  auto vec3 = makeDOFVector(basis);
  test_dofvector(basis, vec3);

  auto vec4 = makeDOFVector<float>(basis);
  test_dofvector(basis, vec4);

#if DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
  DOFVector vec5(basis);
  test_dofvector(basis, vec5);
#endif
}