DOFVectorTest.cpp 2.53 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
#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)
{
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  // TODO:
  // AMDIS_TEST( vec.size() == basis.dimension() );
  vec.resizeZero();

//   vec = T(0);
//   vec[0] = T(1);
// #if HAVE_MTL || HAVE_ISTL
//   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) );
// #endif

//   // 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
37
38
}

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

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

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

54
55
56
57
58
59
60
61
62
  using Traits = BackendTraits<Basis>;
  auto comm = CommunicationCreator<typename Traits::Comm>::create(basis);

  GridTransferManager::attach(grid, *comm, [&]()
  {
    basis.update(gridView);
    comm->update(basis);
  });

63
  {
64
    DOFVector<Basis> vec1(basis, *comm);
65
66
    test_dofvector(basis, vec1);

67
    DOFVector<Basis, double> vec2(basis, *comm);
68
    test_dofvector(basis, vec2);
Praetorius, Simon's avatar
Praetorius, Simon committed
69

70
    auto vec3 = makeDOFVector(basis, *comm);
71
    test_dofvector(basis, vec3);
Praetorius, Simon's avatar
Praetorius, Simon committed
72

73
    auto vec4 = makeDOFVector<double>(basis, *comm);
74
    test_dofvector(basis, vec4);
Praetorius, Simon's avatar
Praetorius, Simon committed
75
76

#if DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
77
    DOFVector vec5(basis, *comm);
78
    test_dofvector(basis, vec5);
Praetorius, Simon's avatar
Praetorius, Simon committed
79
#endif
80
81
82
83
  }

  // test GridTransferManager registration
  {
84
    DOFVector<Basis> vec1(basis, *comm);
85
86
87
    test_dofvector(basis, vec1);
    for (auto const& e : elements(gridView))
      grid.mark(1, e);
88
    GridTransferManager::adapt(grid);
89
    // AMDIS_TEST_EQ(vec1.size(), basis.dimension());
90
91
92
93
  }

  report_errors();
}