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

3
4
#include <memory>

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

12
#include <amdis/AdaptiveGrid.hpp>
13
#include <amdis/AMDiS.hpp>
Praetorius, Simon's avatar
Praetorius, Simon committed
14
#include <amdis/LinearAlgebra.hpp>
15
#include <amdis/functions/ParallelGlobalBasis.hpp>
Praetorius, Simon's avatar
Praetorius, Simon committed
16
17
18
19
20
21
22

#include "Tests.hpp"

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

template <class B, class T>
23
void test_dofvector(DOFVector<B,T>& vec)
Praetorius, Simon's avatar
Praetorius, Simon committed
24
{
Praetorius, Simon's avatar
Praetorius, Simon committed
25
  using MultiIndex = typename B::MultiIndex;
26
27

  auto const& basis = *vec.basis();
28

29
  vec.init(sizeInfo(basis), true);
Praetorius, Simon's avatar
Praetorius, Simon committed
30
31
32
  AMDIS_TEST_EQ(vec.localSize(), basis.size());

  vec.insert(MultiIndex{0}, T(1));
33
34
  vec.finish();

Praetorius, Simon's avatar
Praetorius, Simon committed
35
36
37
38
39
40
41
42
43
  AMDIS_TEST_EQ(vec.at(MultiIndex{0}), T(1));

  T min(10);
  T max(-10);
  vec.forEach([&min,&max](auto, auto value) {
    min = std::min(min, value);
    max = std::max(max, value);
  });

44
  if (vec.localSize() > 1)
Praetorius, Simon's avatar
Praetorius, Simon committed
45
46
47
48
49
50
51
52
53
54
55
56
    AMDIS_TEST_EQ(min, T(0));
  AMDIS_TEST_EQ(max, T(1));

  // interpolate constant function on DOFVector
  vec << T(2);
  AMDIS_TEST_EQ(vec.at(MultiIndex{0}), T(2));

  vec.interpolate(T(3));
  AMDIS_TEST_EQ(vec.at(MultiIndex{0}), T(3));

  vec.interpolate_noalias(T(4));
  AMDIS_TEST_EQ(vec.at(MultiIndex{0}), T(4));
Praetorius, Simon's avatar
Praetorius, Simon committed
57
58
}

59
int main(int argc, char** argv)
Praetorius, Simon's avatar
Praetorius, Simon committed
60
{
61
  Environment env(argc, argv);
62

Praetorius, Simon's avatar
Praetorius, Simon committed
63
  // create grid
64
  using HostGrid = Dune::YaspGrid<2>;
Praetorius, Simon's avatar
Praetorius, Simon committed
65
66
  Dune::FieldVector<double, 2> L; L = 1.0;
  auto s = Dune::filledArray<2>(1);
67
  HostGrid hostGrid(L, s);
Praetorius, Simon's avatar
Praetorius, Simon committed
68
69
  AdaptiveGrid<HostGrid> grid(hostGrid);
  auto const& gridView = grid.leafGridView();
Praetorius, Simon's avatar
Praetorius, Simon committed
70
71

  // create basis
72
73
74
75
  auto preBasis = composite(power<2>(lagrange<2>(), flatInterleaved()),
                            lagrange<1>(),
                            flatLexicographic());
  auto basis = makeGlobalBasis(gridView, preBasis);
Praetorius, Simon's avatar
Praetorius, Simon committed
76

77
  using Basis = decltype(basis);
78

79
  {
80
81
    DOFVector<Basis> vec1(basis);
    test_dofvector(vec1);
82

83
84
    DOFVector<Basis, double> vec2(basis);
    test_dofvector(vec2);
Praetorius, Simon's avatar
Praetorius, Simon committed
85

86
87
    auto vec3 = makeDOFVector(basis);
    test_dofvector(vec3);
Praetorius, Simon's avatar
Praetorius, Simon committed
88

89
90
    auto vec4 = makeDOFVector<double>(basis);
    test_dofvector(vec4);
Praetorius, Simon's avatar
Praetorius, Simon committed
91

92
93
    DOFVector vec5(basis);
    test_dofvector(vec5);
94
95
  }

96
  // test automatic updates
97
  {
98
99
100
101
102
    DOFVector<Basis> vec1(basis);

    // Conversion from Dune::Functions::DefaultGlobalBasis
    auto vec2 = makeDOFVector(makeBasis(gridView, preBasis));

103
    for (auto const& e : elements(gridView))
Praetorius, Simon's avatar
Praetorius, Simon committed
104
      grid.mark(1, e);
Praetorius, Simon's avatar
Praetorius, Simon committed
105

Praetorius, Simon's avatar
Praetorius, Simon committed
106
107
108
    grid.preAdapt();
    grid.adapt();
    grid.postAdapt();
Praetorius, Simon's avatar
Praetorius, Simon committed
109
110
111

    test_dofvector(vec1);
    test_dofvector(vec2);
112
113
114
115
  }

  report_errors();
}