vtkreader.cc 2.95 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
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <iostream>
#include <vector>

#include <dune/common/parallel/mpihelper.hh> // An initializer of MPI
#include <dune/common/exceptions.hh> // We use exceptions
#include <dune/common/filledarray.hh>

#include <dune/grid/uggrid.hh>
#include <dune/grid/utility/structuredgridfactory.hh>

#include <dune/vtk/vtkreader.hh>
#include <dune/vtk/vtkwriter.hh>

using namespace Dune;
22
using namespace Dune::experimental;
Praetorius, Simon's avatar
Praetorius, Simon committed
23
24
25
26
27
28
29
30
31
32
33
34

int main(int argc, char** argv)
{
  Dune::MPIHelper::instance(argc, argv);

  const int dim = 3;

  using GridType = UGGrid<dim>;
  using GridView = typename GridType::LeafGridView;
  {
    FieldVector<double,dim> lowerLeft; lowerLeft = 0.0;
    FieldVector<double,dim> upperRight; upperRight = 1.0;
35
    auto numElements = filledArray<dim,unsigned int>(4);
Praetorius, Simon's avatar
Praetorius, Simon committed
36
37
38
39
40
41
42
43
44
45
46
47
    auto gridPtr = StructuredGridFactory<GridType>::createSimplexGrid(lowerLeft, upperRight, numElements);
    auto& grid = *gridPtr;

    GridView gridView = grid.leafGridView();

    VtkWriter<GridView> vtkWriter(gridView);
    vtkWriter.write("test_ascii_float32.vtu", Vtk::ASCII);
    vtkWriter.write("test_binary_float32.vtu", Vtk::BINARY);
    vtkWriter.write("test_compressed_float64.vtu", Vtk::COMPRESSED, Vtk::FLOAT64);
  }

  {
48
    auto gridPtr = VtkReader<GridType>::read("test_ascii_float32.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
49
50
51
52
53
54
55
    auto& grid = *gridPtr;

    VtkWriter<GridView> vtkWriter(grid.leafGridView());
    vtkWriter.write("test_ascii_float32_2.vtu", Vtk::ASCII);
  }

  {
56
    auto gridPtr = VtkReader<GridType>::read("test_binary_float32.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
57
58
59
60
61
62
63
    auto& grid = *gridPtr;

    VtkWriter<GridView> vtkWriter(grid.leafGridView());
    vtkWriter.write("test_ascii_float32_3.vtu", Vtk::ASCII);
  }

  {
64
    auto gridPtr = VtkReader<GridType>::read("test_compressed_float64.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
65
66
67
68
69
    auto& grid = *gridPtr;

    VtkWriter<GridView> vtkWriter(grid.leafGridView());
    vtkWriter.write("test_ascii_float64_3.vtu", Vtk::ASCII, Vtk::FLOAT64);
  }
70

71
72
73
  {
    auto gridPtr = VtkReader<GridType,ConnectedGridCreator>::read("test_ascii_float32.vtu");
    auto& grid = *gridPtr;
74

75
76
77
78
79
80
81
82
83
84
85
86
87
    VtkWriter<GridView> vtkWriter(grid.leafGridView());
    vtkWriter.write("test_ascii_float32_4.vtu", Vtk::ASCII);
  }

  {
    using GridType3d = UGGrid<3>;
    using GridView3d = typename GridType3d::LeafGridView;
    auto gridPtr = VtkReader<GridType3d>::read("paraview_3d.vtu");
    auto& grid = *gridPtr;

    VtkWriter<GridView3d> vtkWriter(grid.leafGridView());
    vtkWriter.write("paraview_3d_ascii.vtu", Vtk::ASCII, Vtk::FLOAT64);
  }
88
89
90
91
92
93
94
95
96
97
98

  // {
  //   std::cout << "paraview_2d_ascii...\n";
  //   using GridType2d = UGGrid<2>;
  //   using GridView2d = typename GridType2d::LeafGridView;
  //   auto gridPtr = VtkReader<GridType2d>::read("paraview_2d.vtu");
  //   auto& grid = *gridPtr;

  //   VtkWriter<GridView2d> vtkWriter(grid.leafGridView());
  //   vtkWriter.write("paraview_2d_ascii.vtu", Vtk::ASCII, Vtk::FLOAT64);
  // }
Praetorius, Simon's avatar
Praetorius, Simon committed
99
}