BackupRestoreTest.cpp 1.62 KB
Newer Older
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <amdis/AMDiS.hpp>
#include <amdis/ProblemStat.hpp>

#include "Tests.hpp"

using namespace AMDiS;

template <class Grid, class Factory>
void test(Factory factory)
{
  using Param  = TaylorHoodBasis<Grid>;
  using Problem = ProblemStat<Param>;

  std::size_t num_elements = 0;
  std::size_t num_vertices = 0;

  // backup
  {
    std::unique_ptr<Grid> grid(factory());
    Problem prob("test", *grid);
    prob.initialize(INIT_ALL);
    prob.globalRefine(2);

    num_elements = prob.grid()->size(0);
    num_vertices = prob.grid()->size(Grid::dimension);

    AdaptInfo adaptInfo("adapt");
    prob.backup(adaptInfo);
  }

  // restore
  {
    Problem prob("test");
    prob.restore(INIT_ALL);

    AMDIS_TEST_EQ(num_elements, prob.grid()->size(0));
    AMDIS_TEST_EQ(num_vertices, prob.grid()->size(Grid::dimension));
  }
}

template <class Grid>
void test_cube()
{
  using Factory = Dune::StructuredGridFactory<Grid>;
  test<Grid>([]() { return Factory::createCubeGrid({0.0,0.0}, {1.0,1.0}, std::array<unsigned int,2>{2,2}); });
}

template <class Grid>
void test_simplex()
{
  using Factory = Dune::StructuredGridFactory<Grid>;
  test<Grid>([]() { return Factory::createSimplexGrid({0.0,0.0}, {1.0,1.0}, std::array<unsigned int,2>{2,2}); });
}

int main(int argc, char** argv)
{
  AMDiS::init(argc, argv);

  std::string filename = "test.backup";
  Parameters::set("test->backup filename", filename);
  Parameters::set("test->restore filename", filename);

  test_cube<Dune::YaspGrid<2>>();
  // test_cube<Dune::UGGrid<2>>();

  // test_simplex<Dune::AlbertaGrid<2,2>>();
  // test_simplex<Dune::UGGrid<2>>();

  AMDiS::finalize();
  return 0;
}