vtkreader.cc 3.37 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
// -*- 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>
Praetorius, Simon's avatar
Praetorius, Simon committed
19
20
#include <dune/vtk/gridcreators/continuousgridcreator.hh>
#include <dune/vtk/gridcreators/discontinuousgridcreator.hh>
21
#include <dune/vtk/writers/vtkunstructuredgridwriter.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35

using namespace Dune;

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;
36
    auto numElements = filledArray<dim,unsigned int>(4);
Praetorius, Simon's avatar
Praetorius, Simon committed
37
38
39
40
41
    auto gridPtr = StructuredGridFactory<GridType>::createSimplexGrid(lowerLeft, upperRight, numElements);
    auto& grid = *gridPtr;

    GridView gridView = grid.leafGridView();

42
43
44
45
46
47
48
49
    VtkUnstructuredGridWriter<GridView> vtkWriter1(gridView, Vtk::ASCII);
    vtkWriter1.write("test_ascii_float32.vtu");

    VtkUnstructuredGridWriter<GridView> vtkWriter2(gridView, Vtk::BINARY);
    vtkWriter2.write("test_binary_float32.vtu");

    VtkUnstructuredGridWriter<GridView> vtkWriter3(gridView, Vtk::COMPRESSED, Vtk::FLOAT64);
    vtkWriter3.write("test_compressed_float64.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
50
51
52
  }

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

56
57
    VtkUnstructuredGridWriter<GridView> vtkWriter(grid.leafGridView(), Vtk::ASCII);
    vtkWriter.write("test_ascii_float32_2.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
58
59
60
  }

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

64
65
    VtkUnstructuredGridWriter<GridView> vtkWriter(grid.leafGridView(), Vtk::ASCII);
    vtkWriter.write("test_ascii_float32_3.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
66
67
68
  }

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

72
73
    VtkUnstructuredGridWriter<GridView> vtkWriter(grid.leafGridView(), Vtk::ASCII, Vtk::FLOAT64);
    vtkWriter.write("test_ascii_float64_3.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
74
  }
75

76
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
77
    auto gridPtr = VtkReader<GridType,DiscontinuousGridCreator<GridType>>::read("test_ascii_float32.vtu");
78
    auto& grid = *gridPtr;
79

80
81
    VtkUnstructuredGridWriter<GridView> vtkWriter(grid.leafGridView(), Vtk::ASCII);
    vtkWriter.write("test_ascii_float32_4.vtu");
82
83
  }

Praetorius, Simon's avatar
Praetorius, Simon committed
84
  if (filesystem::exists("paraview_3d.vtu")) {
85
86
87
88
89
    using GridType3d = UGGrid<3>;
    using GridView3d = typename GridType3d::LeafGridView;
    auto gridPtr = VtkReader<GridType3d>::read("paraview_3d.vtu");
    auto& grid = *gridPtr;

90
91
    VtkUnstructuredGridWriter<GridView3d> vtkWriter(grid.leafGridView(), Vtk::ASCII, Vtk::FLOAT64);
    vtkWriter.write("paraview_3d_ascii.vtu");
92
  }
93

Praetorius, Simon's avatar
Praetorius, Simon committed
94
95
96
97
98
99
  if (filesystem::exists("paraview_2d.vtu")) {
    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;
100

101
102
    VtkUnstructuredGridWriter<GridView2d> vtkWriter(grid.leafGridView(), Vtk::ASCII, Vtk::FLOAT64);
    vtkWriter.write("paraview_2d_ascii.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
103
  }
Praetorius, Simon's avatar
Praetorius, Simon committed
104
}