DOFVectorTest.cpp 1.49 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
#include <dune/common/filledarray.hh>
#include <dune/grid/yaspgrid.hh>
#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);
  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) );
}

int main()
{
  // 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
}