DOFVectorTest.cpp 2.82 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
{
25
26
27
28
29
  using size_type = typename DOFVector<B,T>::GlobalBasis::LocalView::size_type;
  using value_type = typename DOFVector<B,T>::value_type;

  auto const& basis = *vec.basis();
  AMDIS_TEST( vec.localSize() == basis.dimension() );
30
31
  vec.resizeZero();

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  vec.init(false);
  vec.insert(0, value_type(1));
  vec.finish();

  value_type min(10);
  value_type max(-10);
  auto lv = basis.localView();
  auto const& gv = basis.gridView();
  for (auto const& e : elements(gv))
  {
    lv.bind(e);
    for (size_type i = 0; i < lv.size(); ++i)
    {
      auto value = vec.at(lv.index(i));
      min = std::min(min, value);
      max = std::max(max, value);
    }
  }
  AMDIS_TEST( min == T(0) || vec.localSize() == 1 );
  AMDIS_TEST( max == T(1) );
Praetorius, Simon's avatar
Praetorius, Simon committed
52
53
}

54
int main(int argc, char** argv)
Praetorius, Simon's avatar
Praetorius, Simon committed
55
{
56
  Environment env(argc, argv);
57

Praetorius, Simon's avatar
Praetorius, Simon committed
58
  // create grid
59
  using HostGrid = Dune::YaspGrid<2>;
Praetorius, Simon's avatar
Praetorius, Simon committed
60
61
  Dune::FieldVector<double, 2> L; L = 1.0;
  auto s = Dune::filledArray<2>(1);
62
63
64
  HostGrid hostGrid(L, s);
  auto grid = AdaptiveGrid<HostGrid>::instance(hostGrid);
  auto const& gridView = grid->leafGridView();
Praetorius, Simon's avatar
Praetorius, Simon committed
65
66

  // create basis
67
68
69
70
  auto preBasis = composite(power<2>(lagrange<2>(), flatInterleaved()),
                            lagrange<1>(),
                            flatLexicographic());
  auto basis = makeGlobalBasis(gridView, preBasis);
Praetorius, Simon's avatar
Praetorius, Simon committed
71

72
  using Basis = decltype(basis);
73

74
  {
75
76
    DOFVector<Basis> vec1(basis);
    test_dofvector(vec1);
77

78
79
    DOFVector<Basis, double> vec2(basis);
    test_dofvector(vec2);
Praetorius, Simon's avatar
Praetorius, Simon committed
80

81
82
    auto vec3 = makeDOFVector(basis);
    test_dofvector(vec3);
Praetorius, Simon's avatar
Praetorius, Simon committed
83

84
85
    auto vec4 = makeDOFVector<double>(basis);
    test_dofvector(vec4);
Praetorius, Simon's avatar
Praetorius, Simon committed
86
87

#if DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
88
89
    DOFVector vec5(basis);
    test_dofvector(vec5);
Praetorius, Simon's avatar
Praetorius, Simon committed
90
#endif
91
92
  }

93
  // test automatic updates
94
  {
95
96
97
98
99
100
    DOFVector<Basis> vec1(basis);

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

    test_dofvector(vec1);
101
    for (auto const& e : elements(gridView))
102
103
104
105
106
107
108
      grid->mark(1, e);
    grid->preAdapt();
    grid->adapt();
    grid->postAdapt();
    std::size_t newSize = basis.dimension();
    AMDIS_TEST_EQ(vec1.localSize(), newSize);
    AMDIS_TEST_EQ(vec2.localSize(), newSize);
109
110
111
112
  }

  report_errors();
}